Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 88 lines (79 sloc) 1.979 kB
1ef586b simpler creation of coverage reports
Tony Cook authored
1 #!perl -w
2 use strict;
3 use Config;
4 use ExtUtils::Manifest 'maniread';
86c50c4 @tonycoz try to generate all coverage into the one cover_db
authored
5 use Cwd;
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
6 use Getopt::Long;
7
8 my @tests;
9 my $verbose;
6aadff5 @tonycoz allow coverage testing to test only .c code coverage
authored
10 my $nodc;
40b0244 @tonycoz allow supplying make options to imcover.perl and abort on make failure
authored
11 my $make_opts = "";
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
12 GetOptions("t|test=s" => \@tests,
40b0244 @tonycoz allow supplying make options to imcover.perl and abort on make failure
authored
13 "m=s" => \$make_opts,
6aadff5 @tonycoz allow coverage testing to test only .c code coverage
authored
14 "n" => \$nodc,
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
15 "v" => \$verbose)
16 or die;
1ef586b simpler creation of coverage reports
Tony Cook authored
17
18 my $make = $Config{make};
19 # if there's a way to make with profiling for a recursive build like
20 # Imager I don't see how
21 if (-f 'Makefile') {
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
22 run("$make clean");
1ef586b simpler creation of coverage reports
Tony Cook authored
23 }
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
24 run("cover -delete");
25e6897 @tonycoz pass extra imcover.perl command-line options through to Makefile.PL
authored
25 run("perl Makefile.PL --coverage @ARGV")
40b0244 @tonycoz allow supplying make options to imcover.perl and abort on make failure
authored
26 and die "Makefile.PL failed\n";
27 run("$make $make_opts 'OTHERLDFLAGS=-ftest-coverage -fprofile-arcs'")
28 and die "build failed\n";
1ef586b simpler creation of coverage reports
Tony Cook authored
29
86c50c4 @tonycoz try to generate all coverage into the one cover_db
authored
30 {
bdea445 @tonycoz we don't use D::C's pod coverage, don't collect it
authored
31 local $ENV{DEVEL_COVER_OPTIONS} = "-db," . getcwd() . "/cover_db,-coverage,statement,branch,condition,subroutine";
6aadff5 @tonycoz allow coverage testing to test only .c code coverage
authored
32 my $makecmd = "$make test TEST_VERBOSE=1";
33 $makecmd .= " HARNESS_PERL_SWITCHES=-MDevel::Cover" unless $nodc;
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
34 if (@tests) {
35 $makecmd .= " TEST_FILES='@tests'";
36 }
40b0244 @tonycoz allow supplying make options to imcover.perl and abort on make failure
authored
37 run($makecmd)
38 and die "Test failed\n";
86c50c4 @tonycoz try to generate all coverage into the one cover_db
authored
39 }
1ef586b simpler creation of coverage reports
Tony Cook authored
40
41 # build gcov files
42 my $mani = maniread();
43 # split by directory
44 my %paths;
45 for my $filename (keys %$mani) {
46 next unless $filename =~ /\.(xs|c|im)$/;
778ca6e @tonycoz avoid trying to gcov unincluded files
authored
47 (my $gcda = $filename) =~ s/\.\w+$/.gcda/;
48 next unless -f $gcda;
1ef586b simpler creation of coverage reports
Tony Cook authored
49 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
50 push @{$paths{$1}}, $2;
51 }
52 else {
53 push @{$paths{''}}, $filename;
54 }
8091ecb @tonycoz gcov the derived .c file as well as the .xs or .im file
authored
55 if ($filename =~ s/\.(xs|im)$/.c/) {
56 if ($filename =~ m!^(\w+)/(\w+\.\w+)$!) {
57 push @{$paths{$1}}, $2;
58 }
59 else {
60 push @{$paths{''}}, $filename;
61 }
62 }
1ef586b simpler creation of coverage reports
Tony Cook authored
63 }
64
65 for my $path (keys %paths) {
66 if ($path) {
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
67 run("cd $path ; gcov -abc @{$paths{$path}} ; cd ..");
1ef586b simpler creation of coverage reports
Tony Cook authored
68 }
69 else {
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
70 run("gcov -abc @{$paths{$path}}");
1ef586b simpler creation of coverage reports
Tony Cook authored
71 }
72 my $dir = $path ? $path : '.';
73 for my $file (@{$paths{$path}}) {
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
74 run("gcov2perl $dir/$file.gcov");
1ef586b simpler creation of coverage reports
Tony Cook authored
75 }
76 }
77
78 my @dbs = "cover_db", map "$_/cover_db", grep $_, keys %paths;
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
79 # we already ran gcov
80 run("cover -nogcov -ignore_re '^t/'");
1ef586b simpler creation of coverage reports
Tony Cook authored
81
7fcc2ea @tonycoz allow imcover.perl to specify a subset of tests to run
authored
82 sub run {
83 my $cmd = shift;
84
85 print "Running: $cmd\n" if $verbose;
86 return system $cmd;
87 }
Something went wrong with that request. Please try again.