mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-26102 dgcov: add support for *.gcda.gcov.json.gz files of gcov 9.1+
- Script covers situation for gcov (gcc) < 9 with non-json format of generated files as well as for gcov (gcc) >=8 with json generated format Reviewed by: serg@mariadb.com
This commit is contained in:
parent
1547e55489
commit
43173ef261
1 changed files with 37 additions and 19 deletions
|
@ -62,13 +62,16 @@ my $res;
|
|||
my $cmd;
|
||||
if ($opt_purge)
|
||||
{
|
||||
$cmd= "find . -name '*.da' -o -name '*.gcda' -o -name '*.gcov' -o ".
|
||||
$cmd= "find . -name '*.da' -o -name '*.gcda*' -o -name '*.gcov' -o ".
|
||||
"-name '*.dgcov' | grep -v 'README\.gcov' | xargs rm -f ''";
|
||||
logv "Running: $cmd";
|
||||
system($cmd)==0 or die "system($cmd): $? $!";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $gcc_version= `gcc -dumpversion`;
|
||||
$gcc_version=~ s/(\d).*$/$1/;
|
||||
|
||||
find(\&gcov_one_file, $root);
|
||||
find(\&write_coverage, $root) if $opt_generate;
|
||||
exit 0 if $opt_only_gcov;
|
||||
|
@ -162,26 +165,41 @@ sub gcov_one_file {
|
|||
}
|
||||
|
||||
# now, read the generated file
|
||||
for my $gcov_file (<$_*.gcov>) {
|
||||
open FH, '<', "$gcov_file" or die "open(<$gcov_file): $!";
|
||||
my $fname;
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
if (/^function:/) {
|
||||
next;
|
||||
if ($gcc_version <9){
|
||||
for my $gcov_file (<$_*.gcov>) {
|
||||
open FH, '<', "$gcov_file" or die "open(<$gcov_file): $!";
|
||||
my $fname;
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
if (/^function:/) {
|
||||
next;
|
||||
}
|
||||
if (/^file:/) {
|
||||
$fname=realpath(-f $' ? $' : $root.$');
|
||||
next;
|
||||
}
|
||||
next if /^lcount:\d+,-\d+/; # whatever that means
|
||||
unless (/^lcount:(\d+),(\d+)/ and $fname) {
|
||||
warn "unknown line '$_' in $gcov_file";
|
||||
next;
|
||||
}
|
||||
$cov{$fname}->{$1}+=$2;
|
||||
}
|
||||
close(FH);
|
||||
}
|
||||
} else {
|
||||
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
|
||||
use JSON::PP;
|
||||
my $gcov_file_json;
|
||||
my $fname;
|
||||
gunzip "$_.gcov.json.gz" => \$gcov_file_json or die "gunzip($_.gcov.json.gz): $GunzipError";
|
||||
my $obj= decode_json $gcov_file_json;
|
||||
for my $file (@{$obj->{files}}) {
|
||||
$fname= $file->{file};
|
||||
for my $line (@{$file->{lines}}){
|
||||
$cov{$fname}->{$line->{line_number}}+= $line->{count};
|
||||
}
|
||||
if (/^file:/) {
|
||||
$fname=realpath(-f $' ? $' : $root.$');
|
||||
next;
|
||||
}
|
||||
next if /^lcount:\d+,-\d+/; # whatever that means
|
||||
unless (/^lcount:(\d+),(\d+)/ and $fname) {
|
||||
warn "unknown line '$_' in $gcov_file";
|
||||
next;
|
||||
}
|
||||
$cov{$fname}->{$1}+=$2;
|
||||
}
|
||||
close(FH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue