| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# Copyright IBM Corp. 2017,2020 |
| 4 |
# |
| 5 |
# Usage: check_counts <counts_file> <output_file> |
| 6 |
# |
| 7 |
# Compare the lcov/genhtml summary output in <output_file> with the |
| 8 |
# coverage data counts specified in <counts_file>. This file has the following |
| 9 |
# format (all in a single line): |
| 10 |
# |
| 11 |
# lnhit lnfound fnhit fnfound brhit brfound2 |
| 12 |
# |
| 13 |
|
| 14 |
use strict; |
| 15 |
use warnings; |
| 16 |
|
| 17 |
sub do_cmp($$$) |
| 18 |
{ |
| 19 |
my ($title, $a, $b) = @_; |
| 20 |
|
| 21 |
if ($a == $b) { |
| 22 |
print("$title: $a == $b\n"); |
| 23 |
return 0; |
| 24 |
} else { |
| 25 |
print("$title: $a != $b => mismatch!\n"); |
| 26 |
return 1; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
my $lcov = $ENV{"LCOV"}; |
| 31 |
my ($counts, $output) = @ARGV; |
| 32 |
my $fd; |
| 33 |
my $cmdline; |
| 34 |
my ($lnhit, $lnfound, $fnhit, $fnfound, $brhit, $brfound) = (0, 0, 0, 0, 0, 0); |
| 35 |
my ($lnhit2, $lnfound2, $fnhit2, $fnfound2, $brhit2, $brfound2); |
| 36 |
my $rc = 0; |
| 37 |
|
| 38 |
if (!defined($counts) || !defined($output)) { |
| 39 |
die("Usage: $0 <counts_file> <coverage_data_file>\n"); |
| 40 |
} |
| 41 |
|
| 42 |
open($fd, "<", $output) or die("$0: Could not read $output: $!\n"); |
| 43 |
while (<$fd>) { |
| 44 |
($lnhit, $lnfound) = ($1, $2) if (/(\d+) of (\d+) lines/); |
| 45 |
($fnhit, $fnfound) = ($1, $2) if (/(\d+) of (\d+) functions/); |
| 46 |
($brhit, $brfound) = ($1, $2) if (/(\d+) of (\d+) branches/); |
| 47 |
} |
| 48 |
close($fd); |
| 49 |
|
| 50 |
die("$0: Non-zero result code ($?) of command: $cmdline\n") if ($? != 0); |
| 51 |
|
| 52 |
open($fd, "<", $counts) or die("$0: Could not open $counts: $!\n"); |
| 53 |
if (<$fd> !~ /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) { |
| 54 |
die("$0: Invalid count file: $counts\n"); |
| 55 |
} |
| 56 |
($lnhit2, $lnfound2, $fnhit2, $fnfound2, $brhit2, $brfound2) = |
| 57 |
($1, $2, $3, $4, $5, $6); |
| 58 |
close($fd); |
| 59 |
|
| 60 |
print("Comparing output for $output and $counts:\n"); |
| 61 |
$rc |= do_cmp("line hit", $lnhit, $lnhit2); |
| 62 |
$rc |= do_cmp("line found", $lnfound, $lnfound2); |
| 63 |
$rc |= do_cmp("functions hit", $fnhit, $fnhit2); |
| 64 |
$rc |= do_cmp("functions found", $fnfound, $fnfound2); |
| 65 |
$rc |= do_cmp("branches hit", $brhit, $brhit2); |
| 66 |
$rc |= do_cmp("branches found", $brfound, $brfound2); |
| 67 |
|
| 68 |
exit($rc); |