Debian Codegraph @

easel/testsuite/valgrind_report.pl

raw
1 #! /usr/bin/perl
2
3 # Run the testsuite under Valgrind, to check for memory leakage.
4 #
5 # First you have to do a 'make dev' or 'make check', or equiv;
6 # all the unit test drivers need to be compiled and present.
7 #
8 # Usage:
9 # valgrind_report.pl <top_builddir> <top_srcdir>
10 #
11 # Example, in a single directory (source+build):
12 # ./configure --enable-debugging
13 # make dev
14 # testsuite/valgrind_report.pl . .
15 #
16 # Example, in separate build dir:
17 # mkdir build_dir
18 # cd build_dir
19 # ../configure --enable-debugging
20 # make dev
21 # ../testsuite/valgrind_report.pl . ..
22 #
23
24 use File::Basename;
25
26 if ($#ARGV+1 != 2) { die("Usage: valgrind_report.pl <top_builddir> <top_srcdir>"); }
27 $top_builddir = shift;
28 $top_srcdir = shift;
29
30 printf("Memory leak testing for Easel, using valgrind:\n\n");
31
32 @modules = <$top_srcdir/esl_*.c>;
33 unshift(@modules, "$top_srcdir/easel.c");
34
35 $nmodules = 0;
36 $npresent = 0;
37 $ncompiled = 0;
38 $nsuccess = 0;
39 $nleaking = 0;
40 foreach $module (@modules) {
41 $basecfile = fileparse($module);
42 $nmodules++;
43
44 # create the eslDMATRIX_TESTDRIVE flag and esl_dmatrix_utest program name from esl_dmatrix.c
45 if ($basecfile =~ /^(esl_)?(\S+).c/) {
46 $pfx = $1;
47 $base = $2;
48 $progname = $pfx.$base."_utest";
49 $base =~ tr/a-z/A-Z/;
50 $flag = "esl".$base."_TESTDRIVE";
51 }
52
53 printf("%-28s ", $basecfile);
54
55 # one way to fail: there isn't a test driver at all
56 `grep $flag $module`;
57 if ($? != 0) { printf(" [NO DRIVER]\n"); next; }
58 $npresent++;
59
60 # Some unit tests aren't compiled.
61 # That can be normal: for example, esl_mpi_utest on a non-MPI system
62 if (! -x "$top_builddir/$progname") { printf(" [UTEST NOT COMPILED]\n"); next; }
63 $ncompiled++;
64
65 $output = `valgrind $top_builddir/$progname 2>&1`;
66 if ($? != 0) { printf(" [VALGRIND FAILED]\n"); next; };
67 $nsuccess++;
68
69 if ($output =~ / definitely lost: (\S+) bytes in (\S+) blocks/)
70 {
71 if ($1 > 0) {
72 $nleaking++;
73 print("[LEAK DETECTED ]\n");
74 } else {
75 print("ok.\n");
76 }
77 }
78 elsif ($output =~ /All heap blocks were freed -- no leaks are possible/)
79 {
80 print("ok.\n");
81 }
82 else
83 {
84 print "<< problem parsing valgrind output >>\n";
85 }
86 }
87
88 printf("\nOf %d total modules in Easel:\n", $nmodules);
89 if ($npresent != $nmodules) {
90 printf(" - %d have test drivers written, %d do not\n", $npresent, $nmodules-$npresent);
91 } else {
92 printf(" - All %d have test drivers written\n", $npresent);
93 }
94 if ($ncompiled != $npresent) {
95 printf(" - %d test drivers were found compiled; %d were not\n", $ncompiled, $npresent-$ncompiled);
96 } else {
97 printf(" - All %d test drivers were found compiled\n", $ncompiled);
98 }
99 if ($nsuccess != $ncompiled) {
100 printf(" - %d ran successfully, %d did not\n", $nsuccess, $ncompiled-$nsuccess);
101 } else {
102 printf(" - All %d ran successfully\n", $nsuccess);
103 }
104
105 print "\n";
106 if ($nleaking == 0) {
107 printf("None of %d modules with running test drivers show memory leaks\n", $nsuccess);
108 } else {
109 printf("%d of %d modules with running test drivers are leaking.\n", $nleaking, $nsuccess);
110 }
111
112
113 # SRE, Fri Mar 2 08:37:48 2007 [Janelia]