Skip to content

Commit

Permalink
Show basseline count for LBC and ECB lines and branches.
Browse files Browse the repository at this point in the history
We know that the current count is zero (LCB) or undefined (ECB).
Having the baseline count is useful, especially in the context of random
tests as it can tell us if we lost a low probability event (baseline
count was "small") or we did something bad and no longer reach what had
been a high probability event.
For line coverpoints:  show baseline count in parens in source detail pane.
For branch coverpoints:  include baseline count in tooltip popup.


Signed-off-by: Henry Cox <[email protected]>
  • Loading branch information
henry2cox committed Aug 3, 2023
1 parent f12aff5 commit f440ab4
Showing 1 changed file with 58 additions and 16 deletions.
74 changes: 58 additions & 16 deletions bin/genhtml
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,13 @@ sub _categorizeBranchCov

my %branchCovLines;
# look through the 'current' data, to find all the branch data

# keep track of hit count in baseline, current - in element 2 of the
# retained branch data. These counts are useful - for example, to report
# the hit count in the baseline for LBC branches:
# - e.g., in random testing: is this branch lost because it was a
# low probablilty event (..baselinecount is a small number)>
# Or because we did something bad and no longer reach what had been
# a high probability event?
foreach my $line ($branchCurrent->keylist()) {
my $type = $linemap->type($filename, $linemap->NEW, $line);
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
Expand Down Expand Up @@ -2582,7 +2588,7 @@ sub _categorizeBranchCov
foreach my $br (@{$curr->getBlock($branchId)}) {
my $count = $br->count();
my $tla = (0 == $count) ? 'UNC' : 'GNC';
push(@$block, [$br, $tla]);
push(@$block, [$br, $tla, [undef, $count]]);
}
}
} elsif ($type eq 'delete') {
Expand All @@ -2594,7 +2600,7 @@ sub _categorizeBranchCov
foreach my $br (@{$base->getBlock($branchId)}) {
my $count = $br->count();
my $tla = (0 == $count) ? 'DUB' : 'DCB';
push(@$block, [$br, $tla]);
push(@$block, [$br, $tla, [$count, undef]]);
}
}
} else {
Expand Down Expand Up @@ -2622,22 +2628,28 @@ sub _categorizeBranchCov
$tla =
_categorize($base_br->count(),
$curr_br->count());
push(@$branchData, [$curr_br, $tla]);
push(@$branchData,
[$curr_br, $tla,
[$base_br->count(), $curr_br->count()]
]);
} elsif ($i < $num_base) {
my $base_br = $b->[$i];
$tla = (0 == $base_br->count()) ? 'EUB' : 'ECB';
push(@$branchData, [$base_br, $tla]);
push(@$branchData,
[$base_br, $tla, [$base_br->count(), undef]]);
} else {
my $curr_br = $c->[$i];
$tla = (0 == $curr_br->count()) ? 'UIC' : 'GIC';
push(@$branchData, [$curr_br, $tla]);
push(@$branchData,
[$curr_br, $tla, [undef, $curr_br->count()]]);
}
}
} else {
# branch not found in current...
foreach my $base_br (@$b) {
my $tla = (0 == $base_br->count()) ? 'EUB' : 'ECB';
push(@$branchData, [$base_br, $tla]);
push(@$branchData,
[$base_br, $tla, [$base_br->count(), undef]]);
}
}
}
Expand All @@ -2650,7 +2662,8 @@ sub _categorizeBranchCov
my $branchData = $categorized->addBlock($branchId);
foreach my $curr_br (@$c) {
my $tla = (0 == $curr_br->count()) ? 'UIC' : 'GIC';
push(@$branchData, [$curr_br, $tla]);
push(@$branchData,
[$curr_br, $tla, [undef, $curr_br->count()]]);
}
} # foreach branchId in current that isn't in base
}
Expand Down Expand Up @@ -8448,6 +8461,7 @@ sub get_branch_html($$)
my $class;
my $prefix;
my $tla;
my $base_count;
if ('ARRAY' ne ref($br)) {
# vanilla case - no differential coverage info
die("differential branch coverage but no TLA")
Expand All @@ -8463,9 +8477,10 @@ sub get_branch_html($$)
} else {
die("differential branch coverage but no TLA")
unless defined($differentialBranch);
$tla = $br->[1];
$br = $br->[0];
$class = "tla$tla";
$tla = $br->[1];
$base_count = $br->[2]->[0];
$br = $br->[0];
$class = "tla$tla";
my $label =
$main::use_legacyLabels ?
$SummaryInfo::tlaToLegacySrcLabel{$tla} :
Expand All @@ -8480,9 +8495,19 @@ sub get_branch_html($$)
if ($taken eq '-') {
$char = "#";
$title = "${prefix}Branch $br_name was not executed";
$title .=
" (previously taken $base_count time" .
(1 == $base_count ? '' : 's') . ')'
if (defined($tla) &&
($tla eq 'LBC' || $tla eq 'ECB'));
} elsif ($taken == 0) {
$char = "-";
$title = "${prefix}Branch $br_name was not taken";
$title .=
" (previously taken $base_count time" .
(1 == $base_count ? '' : 's') . ')'
if (defined($tla) &&
($tla eq 'LBC' || $tla eq 'ECB'));
} else {
$char = "+";
$title = "${prefix}Branch $br_name was taken $taken time" .
Expand Down Expand Up @@ -8535,6 +8560,11 @@ sub format_count($$)
my ($count, $width) = @_;
my $result;
my $exp;
my $negative = 0 > $count;
if ($negative) {
$width -= 2;
$count = -$count;
}

$result = sprintf("%*.0f", $width, $count);
while (length($result) > $width) {
Expand All @@ -8543,6 +8573,10 @@ sub format_count($$)
$count = int($count / 10);
$result = sprintf("%*s", $width, ">$count*10^$exp");
}
if ($negative) {
# surround number with parens
$result =~ s/^( *)(\S+)$/$1\($2\)/;
}
return $result;
}

Expand Down Expand Up @@ -8637,18 +8671,26 @@ sub write_source_line(*$$$$)
$bucket eq "EUB") {
!defined($count) or
die("excluded code should have undefined count");
# don't show count for excluded code
$count_format = " " x $count_field_width;
$result = $pchar . $base_count;
# show previous count for excluded code that had been hit
if ($bucket eq "ECB") {
$count_format = format_count(-$base_count, $count_field_width);
} else {
$count_format = " " x $count_field_width;
}
$result = $pchar . $base_count;
} else {
if (!defined($count)) {
# this is manufactured data...make something up
$count = $curr_count;
}
defined($count) && "" ne $count or
die("code should have defined count");
$count_format = format_count($count, $count_field_width);
$result = $pchar . $count;
if ($bucket eq 'LBC') {
$count_format = format_count(-$base_count, $count_field_width);
} else {
$count_format = format_count($count, $count_field_width);
}
$result = $pchar . $count;
}
# '$result' is used to generate the PNG frame
info(2,
Expand Down

0 comments on commit f440ab4

Please sign in to comment.