/usr/bin/gcov2perl is in libdevel-cover-perl 1.21-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | #!/usr/bin/perl
# Copyright 2001-2015, Paul Johnson (paul@pjcj.net)
# This software is free. It is licensed under the same terms as Perl itself.
# The latest version of this software should be available from my homepage:
# http://www.pjcj.net
require 5.6.1;
use strict;
use warnings;
our $VERSION = '1.21'; # VERSION
use Devel::Cover::DB;
use File::Path;
use File::Spec;
use Getopt::Long;
use Pod::Usage;
my $Options = {
db => "cover_db",
};
sub get_options {
die "Bad option" unless
GetOptions($Options, # Store the options in the Options hash.
qw(
db=s
help|h!
info|i!
version|v!
));
print "$0 version " . __PACKAGE__->VERSION . "\n" and exit 0
if $Options->{version};
pod2usage(-exitval => 0, -verbose => 0) if $Options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $Options->{info};
}
sub add_cover {
my ($file) = @_;
my ($vol, $dir) = File::Spec->splitpath(File::Spec->rel2abs($file));
$dir = File::Spec->catpath($vol, $dir);
my $f = $file;
$f =~ s/.gcov$//;
my %run;
$run{collected} = ["statement"];
$run{start} = $run{finish} = time;
my $structure = Devel::Cover::DB::Structure->new;
$structure->add_criteria("statement");
$structure->add_criteria("branch");
my $statement_re = qr/^\s*([-0-9#]+):\s*(\d+):(.*)/;
my $branch_re = qr/^branch\s+(\d+)\s+(?:taken|never)\s+(\w+)/;
my ($line, $text);
open F, $file or die "Can't open $file: $!\n";
gcov_line: while (my $gcov_text = <F>) {
# print "Processing line [$gcov_text]\n";
if ($gcov_text =~ /^[^:]+:[^:]+:Source:(.*)$/) {
$f = $1;
$f = File::Spec->abs2rel(File::Spec->catfile($dir, $f))
unless File::Spec->file_name_is_absolute($f);
}
unless (defined $run{digests}{$f}) {
unless (-f $f) {
warn "no source $f found for $file\n";
close F or die "Can't close $file: $!\n";
return;
}
$run{digests}{$f} = $structure->set_file($f);
}
if ($gcov_text =~ $statement_re) {
my $count = $1;
$line = $2;
$text = $3;
next if $count eq "-";
$count = 0 if $count eq "#####";
# print "$f:$line - $count\n";
push @{$run{count}{$f}{statement}}, $count;
$structure->add_statement($f, $line);
} elsif ($gcov_text =~ $branch_re) {
my @branches;
# look for:
# branch 0 taken 0 (fallthrough)
# branch 1 taken 19
# branch 0 never executed
# branch 1 never executed
while ($gcov_text =~ $branch_re) {
push @branches, $2 eq "executed" ? 0 : $2;
$gcov_text = <F>;
}
# print "branches on $f:$line are: @branches\n";
if (@branches == 2) {
$structure->add_branch($f, [ $line, { text => $text } ]);
push @{$run{count}{$f}{branch}}, \@branches;
} else {
warn "gcov2perl: Warning: ignoring branch with ",
scalar @branches, " targets at $f:$line $text\n";
}
redo gcov_line; # process the line after the branch data
}
}
close F or die "Can't close $file: $!\n";
my $run = $run{start} . ".$$." . sprintf "%05d", rand 2 ** 16;
my $db = $Options->{db};
my $cover = Devel::Cover::DB->new(
base => $db,
runs => { $run => \%run },
structure => $structure,
);
$db .= "/runs";
mkpath $db unless -d $db;
$db .= "/$run";
$cover->{db} = $db;
print STDOUT "gcov2perl: Writing coverage database to $db\n";
$cover->write;
}
sub main {
get_options;
add_cover $_ for @ARGV;
}
main
__END__
=head1 NAME
gcov2perl - convert gcov files to Devel::Cover databases
=head1 VERSION
version 1.21
=head1 SYNOPSIS
gcov2perl -h -i -v -db database gcov_files
=head1 DESCRIPTION
Convert gcov files to Devel::Cover databases.
=head1 OPTIONS
The following command line options are supported:
-db database - specify the database to use
-h -help - show help
-i -info - show documentation
-v -version - show version
=head1 DETAILS
To obtain coverage of XS files they must first be compiled with the appropriate
options. In a standard Makefile environment, such as that created by
ExtUtils::MakeMaker, this can be accomplished with the command:
HARNESS_PERL_SWITCHES=-MDevel::Cover make test \
CCFLAGS=-O0\ -fprofile-arcs\ -ftest-coverage \
OTHERLDFLAGS=-fprofile-arcs\ -ftest-coverage
If you have already built your object files it may be necessary to run make
clean first, or to find some other way to ensure that they get rebuilt with the
options gcov requires.
Now the code coverage data has been collected C<gcov> needs to be run:
gcov Mylib.xs
This will create one or more gcov files on which you can run C<gcov2perl>:
gcov2perl Mylib.xs.gcov
Finally, C<cover> should be run as usual with any options required:
cover
If you are running everything with standard options, you can do all this with
one command:
cover -test
=head1 EXIT STATUS
The following exit values are returned:
0 All files converted successfully
>0 An error occurred.
=head1 SEE ALSO
Devel::Cover
=head1 BUGS
Huh?
=head1 LICENCE
Copyright 2001-2015, Paul Johnson (paul@pjcj.net)
This software is free. It is licensed under the same terms as Perl itself.
The latest version of this software should be available from my homepage:
http://www.pjcj.net
=cut
|