here's a test that shows the memory leak
[dbsrgits/DBM-Deep.git] / t / 52_memory_leak.t
CommitLineData
b391d9ac 1
2use strict;
3use Test;
4use DBM::Deep;
5use t::common qw( new_fh );
6
7my ($fh, $filename) = new_fh();
8my $db = DBM::Deep->new( file => $filename, fh => $fh, );
9
10my $todo = 1000;
11
12$db->{randkey()} = 1 for 1 .. 1000;
13
14plan tests => $todo*2;
15
16my $error_count = 0;
17my @mem = (mem(0), mem(1));
18for my $i (1 .. $todo) {
19 $db->{randkey()} = [@mem];
20
21 print STDERR " @mem \r";
22
23 my @tm = (mem(0), mem(1));
24
25 skip( not($mem[0]), $tm[0] <= $mem[0] );
26 skip( not($mem[1]), $tm[1] <= $mem[1] );
27
28 $error_count ++ if $tm[0] > $mem[0] or $tm[1] > $mem[1];
29 die " ERROR: that's enough failures to prove the point ... " if $error_count > 20;
30
31 @mem = @tm;
32}
33
34sub randkey {
35 our $i ++;
36 my @k = map { int rand 100 } 1 .. 10;
37 local $" = "-";
38
39 return "$i-@k";
40}
41
42sub mem {
43 open my $in, "/proc/$$/statm" or return 0;
44 my $line = [ split m/\s+/, <$in> ];
45 close $in;
46
47 return $line->[shift];
48}
49
50__END__
51/proc/[number]/statm
52
53 Provides information about memory status in pages. The columns are:
54
55 size total program size
56 resident resident set size
57 share shared pages
58 text text (code)
59 lib library
60 data data/stack
61 dt dirty pages (unused in Linux 2.6)