Skip to content

Commit 5bdf2f5

Browse files
authored
'genhtml --date-labels string[,string...]' option - to specify label for corresponding 'date' table entries in HTML report. (#363)
Signed-off-by: Henry Cox <[email protected]>
1 parent 5f3bd92 commit 5bdf2f5

File tree

6 files changed

+92
-13
lines changed

6 files changed

+92
-13
lines changed

README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-------------------------------------------------
22
- README file for the LTP GCOV extension (LCOV) -
3-
- Last changes: 2024-11-26
3+
- Last changes: 2024-12-16
44
-------------------------------------------------
55

66
Description
@@ -313,7 +313,8 @@ LCOV features and capabilities fall into 7 major categories:
313313

314314
Related options:
315315
--baseline-file, --diff-file, --annotate-script, --select-script
316-
--date-bins, --new-file-as-baseline, --elide-path-mismatch
316+
--date-bins, --date-labels --new-file-as-baseline,
317+
--elide-path-mismatch
317318

318319
b) Error handling
319320

bin/genhtml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,28 @@ sub noBaseline
424424
sub setAgeGroups
425425
{
426426
#my $numGroups = scalar(@_) + 1;
427-
@cutpoints = sort({ $a <=> $b } @_);
427+
@cutpoints = sort({ $a <=> $b } @_);
428+
if (@ageGroupHeader) {
429+
# labels were specified by user
430+
@ageGroupHeader = split($lcovutil::split_char,
431+
join($lcovutil::split_char, @ageGroupHeader));
432+
goto done
433+
if (scalar(@ageGroupHeader) == scalar(@cutpoints) + 1);
434+
# mismatched number - generate warning
435+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
436+
"expected number of 'age' labels to match 'date-bin' cutpoints");
437+
# if message ignored, then assign default labels
438+
}
428439
@ageGroupHeader = ();
429-
%ageHeaderToBin = ();
430440
my $prefix = "[..";
431441
foreach my $days (@cutpoints) {
432442
my $header = $prefix . $days . "] days";
433443
push(@ageGroupHeader, $header);
434444
$prefix = "(" . $days . ",";
435445
}
436446
push(@ageGroupHeader, "(" . $cutpoints[-1] . "..) days");
447+
done:
448+
%ageHeaderToBin = ();
437449
my $bin = 0;
438450
foreach my $header (@ageGroupHeader) {
439451
$ageHeaderToBin{$header} = $bin;
@@ -6851,7 +6863,7 @@ STDERR->autoflush;
68516863
STDOUT->autoflush;
68526864

68536865
my @datebins;
6854-
my (@rc_date_bins, @rc_annotate_script, @rc_select_script);
6866+
my (@rc_date_bins, @rc_annotate_script, @rc_select_script, @rc_date_labels);
68556867

68566868
my %genhtml_rc_opts = (
68576869
"genhtml_css_file" => \$css_filename,
@@ -6909,6 +6921,7 @@ my %genhtml_rc_opts = (
69096921
"select_script" => \@rc_select_script,
69106922
'num_context_lines' => \$InInterestingRegion::num_context_lines,
69116923
'genhtml_date_bins' => \@rc_date_bins,
6924+
'genhtml_date_labels' => \@rc_date_labels,
69126925
'truncate_owner_table' => \@truncateOwnerTableLevels,
69136926
'owner_table_entries' => \$ownerTableElements,
69146927
'compact_summary_tables' => \$compactSummaryTables,
@@ -6944,6 +6957,7 @@ my %genhtml_options = ("output-directory|o=s" => \$output_directory,
69446957
'show-zero-columns' => \$show_zeroTlaColumns,
69456958
'simplified-colors' => \$show_simplifiedColors,
69466959
"date-bins=s" => \@datebins,
6960+
'date-labels=s' => \@SummaryInfo::ageGroupHeader,
69476961
"prefix|p=s" => \@opt_dir_prefix,
69486962
"num-spaces=i" => \$tab_size,
69496963
"no-prefix" => \$no_prefix,
@@ -7003,6 +7017,7 @@ $mcdc_med_limit = $med_limit if (!defined($mcdc_med_limit));
70037017
$frames = undef unless (defined($frames) && $frames);
70047018

70057019
foreach my $rc ([\@datebins, \@rc_date_bins],
7020+
[\@SummaryInfo::ageGroupHeader, \@rc_date_labels],
70067021
[\@SourceFile::annotateScript, \@rc_annotate_script],
70077022
[\@selectCallbackScript, \@rc_select_script]
70087023

bin/geninfo

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,12 +1905,10 @@ sub process_dafile($$$$)
19051905
);
19061906
if ($lcovutil::opt_adjust_unexecuted_blocks) {
19071907
$hit = 0;
1908-
} elsif (
1909-
lcovutil::warn_once(
1908+
} elsif (lcovutil::warn_once(
19101909
"unexecuted block",
19111910
$ERROR_INCONSISTENT_DATA
1912-
)
1913-
) {
1911+
)) {
19141912
lcovutil::ignorable_warning(
19151913
$ERROR_INCONSISTENT_DATA,
19161914
"$source_filename:$line_number: unexecuted block on non-branch line with non-zero hit count. Use \"geninfo --rc geninfo_unexecuted_blocks=1 to set count to zero."

man/genhtml.1

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ genhtml \- Generate HTML view from LCOV coverage data files
163163
.RB [ \-\-date\-bins
164164
.IR day[,day,...]]
165165
.br
166+
.RB [ \-\-date\-labels
167+
.IR string[,string,...]]
168+
.br
166169
.RB [ \-\-show\-owners
167170
.IR [ all ] ]
168171
.br
@@ -1937,7 +1940,39 @@ for details.
19371940
.RS
19381941
The
19391942
.B \-\-date\-bins
1940-
option is used to specify age boundaries (cutpoints) for date\-binning classification. If not specified, the default is to use 4 age ranges: less than 7 days, 7 to 30 days, 30 to 180 days, and more than 180 days.
1943+
option is used to specify age boundaries (cutpoints) for date\-binning classification. Each
1944+
.I age
1945+
element is expected to be an integer number of days prior to today (or SOURCE_DATE_EPOCH, if specified). If not specified, the default is to use 4 age ranges: less than 7 days, 7 to 30 days, 30 to 180 days, and more than 180 days.
1946+
This option is equivalent to the
1947+
.I genhtml_date_bins
1948+
config file option. See man
1949+
.B lcovrc(5).
1950+
1951+
This argument has no effect if there is no
1952+
.I source\-annotation\-script .
1953+
1954+
.RE
1955+
.BI "\-\-date\-labels " string[,string,...]
1956+
.RS
1957+
The
1958+
.B \-\-date\-labels
1959+
option is used to specify labels used for the 'date\-bin' table entries in the HTML report.
1960+
.br
1961+
The number of labels should be one greater than the number of cutpoints.
1962+
.br
1963+
If not specified, the default is to use label strings which specify the
1964+
.I [from ..to)
1965+
range of ages held by the corresponding bin.
1966+
1967+
One possible use of this option is to use release names in the tables -
1968+
.I i.e.,
1969+
to indicate the release in which each particular line first appeared.
1970+
1971+
This option is equivalent to the
1972+
.I genhtml_date_labels
1973+
config file option. See man
1974+
.B lcovrc(5).
1975+
19411976
This argument has no effect if there is no
19421977
.I source\-annotation\-script .
19431978

man/lcovrc.5

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,10 +2647,24 @@ The default is 20.
26472647
.IR integer[,integer..]
26482648
.IP
26492649
This option is equivalent to the "genhtml \-\-date\-bins" option.
2650-
See the genhtml man page for details.
2650+
See man
2651+
.B genhtml(1)
2652+
for details.
26512653

26522654
This option can be used multiple times in the lcovrc file to set multiple cutpoints.
2653-
The cutpoints specified in the lcovrc file are appended to the cutpoints (if any) specified on the command line.
2655+
2656+
.PP
2657+
2658+
.BR genhtml_datelabels " ="
2659+
.IR string[,string..]
2660+
.IP
2661+
This option is equivalent to the "genhtml \-\-date\-labels" option.
2662+
See man
2663+
.B genhtml(1)
2664+
for details.
2665+
2666+
This option can be used multiple times in the lcovrc file to set multiple labels.
2667+
The number of labels should equal one greater than number of cutpoints.
26542668

26552669
.PP
26562670

tests/gendiffcov/errs/msgtest.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ LCOV_OPTS="$LCOV_BASE"
133133
DIFFCOV_OPTS="--filter line,branch,function --function-coverage --branch-coverage --demangle-cpp --prefix $PARENT_VERSION $PROFILE "
134134

135135
rm -f test.cpp *.gcno *.gcda a.out *.info *.log *.json diff.txt
136-
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed epoch inconsistent highlight etc mycache cacheFail expect subset context
136+
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed epoch inconsistent highlight etc mycache cacheFail expect subset context labels
137137

138138
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
139139
cover -delete
@@ -787,6 +787,22 @@ if [ 0 != $? ] ; then
787787
fi
788788
fi
789789
790+
# generate error for case that number of date labels doesn't match
791+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS initial.info -o labels --annotate $ANNOTATE_SCRIPT --baseline-file initial.info --title 'context' --header-title 'this is the header' --date-bins 1,5,22 --date-labels a,b,c,d,e --baseline-date "$NOW" --msg-log labels.log
792+
if [ 0 == $? ] ; then
793+
echo "ERROR: genhtml --date-labels didn't fail"
794+
if [ 0 == $KEEP_GOING ] ; then
795+
exit 1
796+
fi
797+
fi
798+
grep -E "ERROR: .*usage.* expected number of 'age' labels to match" labels.log
799+
if [ 0 != $? ] ; then
800+
echo "ERROR: didn't find expected labels message"
801+
if [ 0 == $KEEP_GOING ] ; then
802+
exit 1
803+
fi
804+
fi
805+
790806
if [ "$ENABLE_MCDC" != 1 ] ; then
791807
$COVER $GENINFO_TOOL . -o mccd --mcdc-coverage $LCOV_OPTS --msg-log mcdc_errs.log
792808
if [ 0 == $? ] ; then

0 commit comments

Comments
 (0)