Debian Codegraph @

easel/testsuite/coverage_report.pl

raw
1 #! /usr/bin/perl
2
3 # Measures testsuite coverage (as percentage of source lines),
4 # using gcov.
5 #
6 # Assumes you've already compiled the library, with test drivers only.
7 #
8 # Usage:
9 # coverage_report.pl <top_builddir> <top_srcdir>
10 #
11 # Example usage, in a single directory (source and build):
12 # ./configure --enable-gcov
13 # make tests
14 # testsuite/coverage_report.pl . .
15 #
16 # Example usage, in separate build dir
17 # mkdir build_dir
18 # cd build_dir
19 # ../configure --enable-gcov
20 # make tests
21 # ../testsuite/coverage_report.pl . ..
22 #
23 #
24 # It has to be 'make tests', not 'make dev'. The _utest driver must be
25 # the last executable compiled for each module .c file, or gcov will
26 # bitch about stamp mismatch between .gcno, .gcda files. (When you
27 # build esl_foo_utest, it generates a .gcno file for esl_foo.c. When
28 # you run esl_foo_utest, it generates a .gcda file for esl_foo.c. If
29 # you build esl_foo_example before you run esl_foo_utest, you get a
30 # mismatch.)
31 #
32 # It assumes you have 'sloccount' installed, so it can count
33 # ANSI C lines in files with no test driver. If you don't, use
34 # ./coverage_report.pl -s
35
36
37 use Getopt::Std;
38 use File::Basename;
39 $have_sloccount = 1;
40 getopts('s');
41 if ($opt_s) { $have_sloccount = 0; }
42
43 if ($#ARGV+1 != 2) { die("Usage: coverage_report.pl <top_builddir> <top_srcdir>"); }
44 $top_builddir = shift;
45 $top_srcdir = shift;
46
47
48 printf("Code coverage test for Easel, using gcov:\n\n");
49
50 @modules = <$top_srcdir/esl_*.c>;
51 unshift(@modules, "$top_srcdir/easel.c");
52
53 $nmodules = 0;
54 $npresent = 0;
55 $ncompiled = 0;
56 $nsuccess = 0;
57 $nlines = 0;
58 $nlines_covered = 0;
59 foreach $module (@modules) {
60 $basecfile = fileparse($module);
61 $nmodules++;
62
63 # create the eslDMATRIX_TESTDRIVE flag and dmatrix_utest program name from esl_dmatrix.c
64 if ($basecfile =~ /^(esl_)?(\S+).c/) {
65 $pfx = $1;
66 $base = $2;
67 $progname = $pfx.$base."_utest";
68 $base =~ tr/a-z/A-Z/;
69 $flag = "esl".$base."_TESTDRIVE";
70 }
71 printf("%-28s ", $basecfile);
72
73 # one way to fail: there isn't a test driver at all
74 `grep $flag $module`;
75 if ($? != 0) { printf("%40s[NO DRIVER]\n", ""); push @nodriverlist, $module; next; }
76 $npresent++;
77
78 # or: there's a test driver but it wasn't compiled. Sometimes normal, such as esl_mpi_utest on non-MPI
79 if (! -x "$top_builddir/$progname") { printf("%40s[UTEST NOT COMPILED]\n", ""); next; };
80 $ncompiled++;
81
82 `$top_builddir/$progname > /dev/null 2>&1`;
83 if ($? != 0) { printf("%40s[UTEST FAILED ]\n", ""); next; };
84 $nsuccess++;
85
86 $output = `(cd $top_builddir; gcov $basecfile)`;
87 if ($output =~ /File.*$basecfile.*\nLines executed:\s*(\d+\.\d+)% of\s+(\d+)/) {
88 $pct_cvg = $1;
89 $nlines += $2;
90 $nlines_covered += $1*$2/100;
91 printf("%6.2f%% ", $pct_cvg);
92 $nbar = int($pct_cvg * 20 / 100);
93 for ($i = 0; $i < $nbar; $i++) { printf("*"); }
94 printf("\n");
95 }
96 else { die "failed to parse gcov output";}
97 }
98
99 if ($have_sloccount) {
100 foreach $badmodule (@nodriverlist) {
101 $output = `sloccount $badmodule`;
102 if ($output =~ /ansic:\s+(\d+)/) { $nlines_nodrivers += $1; }
103 else { die("failed to parse sloccount output"); }
104 }
105 }
106
107 printf("\nOf %d total modules in Easel:\n", $nmodules);
108 if ($npresent != $nmodules) {
109 printf(" - %d have test drivers, %d do not\n", $npresent, $nmodules-$npresent);
110 } else {
111 printf(" - All %d have test drivers\n", $npresent);
112 }
113 if ($ncompiled != $npresent) {
114 printf(" - %d compiled, %d did not\n", $ncompiled, $npresent-$ncompiled);
115 } else {
116 printf(" - All %d compiled\n", $ncompiled);
117 }
118 if ($nsuccess != $ncompiled) {
119 printf(" - %d ran successfully, %d did not\n", $nsuccess, $ncompiled-$nsuccess);
120 } else {
121 printf(" - All %d ran successfully\n", $nsuccess);
122 }
123
124 print "\n";
125 printf("Total coverage (of modules with test drivers): %.2f%%\n", 100.*$nlines_covered / $nlines);
126 if ($have_sloccount) {
127 printf("Total coverage (including modules without drivers yet): %.2f%%\n", 100.*$nlines_covered / ($nlines+$nlines_nodrivers));
128 }
129
130
131
132 #
133 # SRE, Thu Mar 1 19:22:57 2007 (Janelia)