X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=perl-module%2Ft%2FPspp.t;h=5d0789af9d431f4a8ccec93a14a01aaf0253bc86;hb=84e927df0b9a1686e9ea32f3327ea04312bbc348;hp=c31458dbe1f350e193ea27c07e3c865e541a4ce6;hpb=f8cba0fb13cceeac43fe4b15e2d5b48798ab1a6e;p=pspp diff --git a/perl-module/t/Pspp.t b/perl-module/t/Pspp.t index c31458dbe1..5d0789af9d 100644 --- a/perl-module/t/Pspp.t +++ b/perl-module/t/Pspp.t @@ -1,7 +1,7 @@ ## -*-perl-*- ## PSPP - a program for statistical analysis. -## Copyright (C) 2019 Free Software Foundation, Inc. +## Copyright (C) 2019, 2020 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -25,9 +25,10 @@ # change 'tests => 1' to 'tests => last_test_to_print'; -use Test::More tests => 37; +use Test::More tests => 38; use Text::Diff; use File::Temp qw/ tempfile tempdir /; +use Memory::Usage; BEGIN { use_ok('PSPP') }; ######################### @@ -623,3 +624,48 @@ EOF ok ($n == 5, "Case count"); } + + +# Check for a leak in append_case +{ + my $record_count = 10_000; + my $var_count = 10; + + # Record amount of memory used by current process + my $mu = Memory::Usage->new(); + + my $dict = PSPP::Dict->new(); + foreach my $i (1..$var_count) + { + my $var = PSPP::Var->new ($dict, "var$i", fmt => 12, width => 2); + $var->set_label ("var $i"); + } + + my $sysfile = PSPP::Sysfile->new ('testfile.sav', $dict, compress => 1); + + $mu->record(''); + + foreach my $i (1..$record_count) + { + my @data = map { int(rand() * 100) } (1..$var_count); + $sysfile->append_case (\@data); + } + + $mu->record(''); + + $sysfile->close; + + my @memstate = @{$mu->state()}; + + my @array0 = @{$memstate[0]}; + my @array1 = @{$memstate[1]}; + + # ignore the timestamps + $array0[0] = 0; + $array1[0] = 0; + + my $result0 = join(",",@array0); + my $result1 = join(",",@array1); + + ok (($result0 eq $result1), "Memory management of append_case"); +}