File: memory.t

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (78 lines) | stat: -rw-r--r-- 1,614 bytes parent folder | download | duplicates (2)
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
use Test2::V0 -no_srand => 1;
use Config;
use Capture::Tiny qw( capture_merged );
use FFI::Temp;

# libexpat1-dev

skip_all 'tested only in CI' if ($ENV{CIPSOMETHING}||'') ne 'true';
skip_all 'tested only in CI -debug' if $Config{ccflags} !~ /-DDEBUG_LEAKING_SCALARS/;

my %exfail = map { $_ => 1 } qw( attach.pl );

# you can run this on just one (or more) test file in corpus/memory by
#  perl -Mblib t/memory.t foo.pl

my @list = @ARGV ? @ARGV : do {
  my $dh;
  opendir $dh, 'corpus/memory';
  grep /\.pl$/, sort readdir $dh;
};

my @supp = do {
  my $dh;
  opendir $dh, 'corpus/memory/supp';
  map { "--suppressions=corpus/memory/supp/$_" } grep /\.supp/, sort readdir $dh;
};

foreach my $name (@list)
{
  subtest $name => sub {

    local $ENV{PERL_DESTRUCT_LEVEL} = 2;

    my $log = FFI::Temp->new;

    my @command = (
      'valgrind',
      '--leak-check=yes',
      "--log-file=$log",
      '--error-exitcode=2',
      #'--gen-suppressions=all',
      #'-v',
      @supp,
      $^X,
      '-Mblib',
      "corpus/memory/$name",
    );

    my($out, $exit) = capture_merged {
      print "+ @command\n";
      system @command;
      $?;
    };

    if($exfail{$name})
    {
      note "expected fail";
      {
        my $todo = todo 'expected fail';
        is($exit, 0, 'valgrind') or do {
          note "[output]\n$out";
          note "[log]\n", do { local $/; <$log> };
        };
      };
    }
    else
    {
      note "expected pass";
      is($exit, 0, 'valgrind') or do {
        diag "[output]\n$out";
        diag "[log]\n", do { local $/; <$log> };
      };
    }

  };
}

done_testing;