-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path80memory.t
86 lines (69 loc) · 1.84 KB
/
80memory.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl -w
use strict;
use SVK::Test;
BEGIN {
plan skip_all => "doesn't work on macosx"
if $^O eq 'darwin';
-d '/proc' or
eval { require BSD::Resource; } or
plan( skip_all => "No /proc and no BSD::Resources" );
}
plan tests => 6;
my $curr_mem = sub { -1 };
if( -d '/proc' ) {
$curr_mem = sub {
open STAT, "grep '^VmRSS' /proc/$$/status|";
my $ret = $1 if( <STAT> =~ /:\s*([^\s]*)/ );
close STAT;
return $ret;
}
} else {
require BSD::Resource;
$curr_mem = sub {
my @r = BSD::Resource::getrusage();
return $r[2];
}
}
sub no_leak {
my ($action, $block) = @_;
my $before = &$curr_mem;
#diag("$before before $action");
&$block;
my $after = &$curr_mem;
#diag("$after after $action");
my $diff = $after - $before;
cmp_ok($diff, '<', $before * 0.03, "Memory use shouldn't increase during $action") and
$diff > 0 and diag("Memory use grew by $diff during $action");
}
our ($output, $answer);
my ($xd, $svk) = build_test('foo');
$svk->mkdir ('-pm', 'init src', '//mem-src/container');
$svk->mkdir ('-m', 'init dest', '//mem-dest');
$svk->smerge ('-Bm', 'merge init', '//mem-src', '//mem-dest');
our ($copath, $corpath) = get_copath ('memory');
TODO: {
local $TODO = "Fix more leaks";
no_leak('svk co', sub {
$svk->checkout ('//mem-src', $copath);
});
my $max = 350;
my @names = (1..$max);
for my $name (@names) {
append_file ("$copath/container/f-$name", "file $name");
}
no_leak('svk add', sub {
$svk->add ("$copath/container");
});
no_leak('svk ci', sub {
$svk->commit ('-m', 'add', "$copath/container");
});
no_leak('merge add', sub {
$svk->smerge ('-Bm', 'merge add', '//mem-src', '//mem-dest');
});
}
no_leak('svk rm', sub {
$svk->delete ('-m', 'del', "//mem-src/container");
});
no_leak('merge delete', sub {
$svk->smerge ('-Bm', 'merge del', '//mem-src', '//mem-dest');
});