Skip to content

Commit 4e4dc0f

Browse files
committed
Sort input files during data capture and/or aggregation - so certain artifacts which depend on processing order come out in a (more) consistent way.
Continue to support the 'genhtml --sort ...' flag - but with 'deprecated' warning. Remove support in later release. See the discussion in #402 Signed-off-by: Henry Cox <[email protected]>
1 parent 3910185 commit 4e4dc0f

File tree

10 files changed

+186
-89
lines changed

10 files changed

+186
-89
lines changed

bin/genhtml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6817,7 +6817,7 @@ our $hierarchical = 0; # if true: show directory hierarchy
68176817
# default: legacy two-level report
68186818
our $flat = 0; # if true: single table of all files in top level
68196819

6820-
our $sort = 1; # If set, provide directory listings with sorted entries
6820+
our $sort_tables = 1; # If set, provide directory listings with sorted entries
68216821
our $no_sort; # Disable sort
68226822
our $frames; # If set, use frames for source code view
68236823
our $keep_descriptions; # If set, do not remove unused test case descriptions
@@ -6899,7 +6899,7 @@ my %genhtml_rc_opts = (
68996899
"genhtml_mcdc_field_width" => \$mcdc_field_width,
69006900
"genhtml_owner_field_width" => \$owner_field_width,
69016901
"genhtml_age_field_width" => \$age_field_width,
6902-
"genhtml_sort" => \$sort,
6902+
"genhtml_sort" => \$sort_tables,
69036903
"genhtml_charset" => \$charset,
69046904
"genhtml_desc_html" => \$rc_desc_html,
69056905
'merge_function_aliases' => \$merge_function_aliases,
@@ -6975,7 +6975,7 @@ my %genhtml_options = ("output-directory|o=s" => \$output_directory,
69756975
"html-gzip" => \$html_gzip,
69766976
"hierarchical" => \$hierarchical,
69776977
"flat" => \$flat,
6978-
"sort" => \$sort,
6978+
"sort-tables" => \$sort_tables,
69796979
"no-sort" => \$no_sort,
69806980
"precision=i" => \$lcovutil::default_precision,
69816981
"missed" => \$opt_missed,
@@ -6985,6 +6985,15 @@ my %genhtml_options = ("output-directory|o=s" => \$output_directory,
69856985
"merge-aliases" => \$merge_function_aliases,
69866986
"suppress-aliases" => \$suppress_function_aliases,
69876987
'validate' => \$validateHTML,);
6988+
6989+
# remove ambiguous entry from common table -
6990+
# (genhtml has '--sort-inputs' and '--sort-tables')
6991+
# handle the (no obsolete) '--sort' option
6992+
Getopt::Long::Configure("pass_through", "no_auto_abbrev");
6993+
my $obsoleteSort;
6994+
Getopt::Long::GetOptions('sort' => \$obsoleteSort);
6995+
Getopt::Long::Configure('default');
6996+
69886997
# Parse command line options
69896998
if (
69906999
!lcovutil::parseOptions(\%genhtml_rc_opts, \%genhtml_options,
@@ -6994,6 +7003,13 @@ if (
69947003
exit(1);
69957004
}
69967005

7006+
if (defined($obsoleteSort)) {
7007+
$sort_tables = $obsoleteSort;
7008+
lcovutil::ignorable_warning($lcovutil::ERROR_DEPRECATED,
7009+
"option '--sort' is deprecated and will be removed in a future release; please use '--sort-tables' instead."
7010+
);
7011+
}
7012+
69977013
$merge_function_aliases = 1
69987014
if ($suppress_function_aliases ||
69997015
defined($lcovutil::cov_filter[$lcovutil::FILTER_FUNCTION_ALIAS]));
@@ -7037,7 +7053,7 @@ if (defined($lcovutil::stop_on_error) &&
70377053
}
70387054

70397055
# Merge sort options
7040-
$sort = 0
7056+
$sort_tables = 0
70417057
if ($no_sort);
70427058
die(
70437059
"unsupported use of mutually exclusive '--flat' and '--hierachical' options")
@@ -7244,7 +7260,7 @@ if ($no_prefix && @dir_prefix) {
72447260
@fileview_sortlist = ($SORT_FILE);
72457261
@funcview_sortlist = ($SORT_FILE);
72467262

7247-
if ($sort) {
7263+
if ($sort_tables) {
72487264
push(@fileview_sortlist, $SORT_LINE);
72497265
push(@fileview_sortlist, $SORT_FUNC) if ($lcovutil::func_coverage);
72507266
push(@fileview_sortlist, $SORT_BRANCH) if ($lcovutil::br_coverage);
@@ -8659,7 +8675,7 @@ sub write_png_files()
86598675
0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
86608676
];
86618677

8662-
if ($sort) {
8678+
if ($sort_tables) {
86638679
$data{"updown.png"} =
86648680
$dark_mode ?
86658681
[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
@@ -11960,7 +11976,7 @@ sub write_header(*$$$$$$$)
1196011976
%$differentialFunctionMap) {
1196111977
$view .= "<span style=\"font-size: 80%;\">";
1196211978
if ($type == $HDR_SOURCE) {
11963-
my $suffix = $sort ? '-c' : '';
11979+
my $suffix = $sort_tables ? '-c' : '';
1196411980
$view .=
1196511981
" (source / <a href=\"$base_name.func$suffix.$html_ext\" title=\"Click to go to function table\">functions</a>)";
1196611982
} elsif ($type == $HDR_FUNC) {
@@ -12652,7 +12668,7 @@ sub write_file_table(*$$$$$$)
1265212668
}
1265312669
my $file_col_title = ($fileview || $main::flat) ? 'File' : 'Directory';
1265412670
# don't insert the 'sort' controls if there is just a single source file
12655-
my $use_sort_button = $sort && 1 < scalar($dirSummary->sources());
12671+
my $use_sort_button = $sort_tables && 1 < scalar($dirSummary->sources());
1265612672
my $file_code =
1265712673
get_file_code($hide, $file_col_title,
1265812674
$use_sort_button && $sort_type != $SORT_FILE,
@@ -13372,23 +13388,23 @@ sub funcview_get_label($$$$)
1337213388
my $link;
1337313389

1337413390
if (!defined($col)) {
13375-
if ($sort && $sort_type != $SORT_FILE) {
13391+
if ($sort_tables && $sort_type != $SORT_FILE) {
1337613392
$link = "$name.func.$html_ext";
1337713393
}
1337813394
return "Function Name" . get_sort_code($link, "function name", $base);
1337913395
} elsif ($col eq 'hit') {
13380-
if ($sort && $sort_type != $SORT_LINE) {
13396+
if ($sort_tables && $sort_type != $SORT_LINE) {
1338113397
$link = "$name.func-c.$html_ext";
1338213398
}
1338313399
return "Hit count" . get_sort_code($link, "function hit count", $base);
1338413400
} elsif ($col eq 'missed_line') {
13385-
if ($sort && $sort_type != $SORT_MISSING_LINE) {
13401+
if ($sort_tables && $sort_type != $SORT_MISSING_LINE) {
1338613402
$link = "$name.func-l.$html_ext";
1338713403
}
1338813404
return "Lines" .
1338913405
get_sort_code($link, "unexercised lines in function", $base);
1339013406
} elsif ($col eq 'missed_mcdc') {
13391-
if ($sort && $sort_type != $SORT_MISSING_MCDC) {
13407+
if ($sort_tables && $sort_type != $SORT_MISSING_MCDC) {
1339213408
$link = "$name.func-m.$html_ext";
1339313409
}
1339413410
return "MC/DC"
@@ -13397,7 +13413,7 @@ sub funcview_get_label($$$$)
1339713413
$base);
1339813414
} else {
1339913415
die("unexpected sort $col") unless ($col eq 'missed_branch');
13400-
if ($sort && $sort_type != $SORT_MISSING_BRANCH) {
13416+
if ($sort_tables && $sort_type != $SORT_MISSING_BRANCH) {
1340113417
$link = "$name.func-b.$html_ext";
1340213418
}
1340313419
return "Branches" .

bin/geninfo

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,18 @@ sub gen_info(@)
12881288
$builder->find_files(2, @_);
12891289
}
12901290
my $filelist = $builder->worklist();
1291-
my $total = scalar(@$filelist);
1291+
my @sorted_filelist;
1292+
if ($lcovutil::sort_inputs) {
1293+
@sorted_filelist = sort({
1294+
my $na = $a->[0] .
1295+
(defined($a->[1]) ? $a->[1] : $a->[2]);
1296+
my $nb = $b->[0] .
1297+
(defined($b->[1]) ? $b->[1] : $b->[2]);
1298+
$na cmp $nb
1299+
} @$filelist);
1300+
$filelist = \@sorted_filelist;
1301+
}
1302+
my $total = scalar(@$filelist);
12921303
if (1 < $lcovutil::maxParallelism) {
12931304
my $floor =
12941305
$lcovutil::maxParallelism ?
@@ -1326,7 +1337,7 @@ sub gen_info(@)
13261337
FILE: foreach my $j (@$filelist) {
13271338
my ($dir, $gcda, $gcno) = @$j;
13281339
foreach my $f ($gcda, $gcno) {
1329-
next unless defined($f); # might not be a GCDA file
1340+
next unless defined($f); # might not be a GCDA file
13301341
my $filename = $dir . $lcovutil::dirseparator . $f;
13311342
if (grep({ $filename =~ $_ } @main::large_files)) {
13321343
lcovutil::info(1, "large file: $filename\n");

lcovrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ lcov_json_module = auto
490490
# directives, etc
491491
#case_insensitive = 0
492492

493+
# sort file names before capture and/or aggregation - to reduce certain
494+
# types of processing order dependencies which can affect coverage results.
495+
# see the lcovrc man page for more details.
496+
#sort_input = 1
497+
493498
# override line default line exclusion regexp
494499
#lcov_excl_line = LCOV_EXCL_LINE
495500

lib/lcovutil.pm

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ our $lcov_url = "https://github.com//linux-test-project/lcov";
117117
our @temp_dirs;
118118
our $tmp_dir = '/tmp'; # where to put temporary/intermediate files
119119
our $preserve_intermediates; # this is useful only for debugging
120+
our $sort_inputs; # sort input file lists - to reduce unpredictability
120121
our $devnull = File::Spec->devnull(); # portable way to do it
121122
our $dirseparator = ($^O =~ /Win/) ? '\\' : '/';
122123
our $interp = ($^O =~ /Win/) ? $^X : undef;
@@ -1126,7 +1127,8 @@ my %rc_common = (
11261127
"demangle_cpp" => \@lcovutil::cpp_demangle,
11271128
'excessive_count_threshold' => \$excessive_count_threshold,
11281129

1129-
,
1130+
'sort_input' => \$lcovutil::sort_inputs,
1131+
11301132
"fail_under_lines" => \$fail_under_lines,
11311133
"fail_under_branches" => \$fail_under_branches,
11321134
'lcov_filter_parallel' => \$lcovutil::lcov_filter_parallel,
@@ -1214,7 +1216,8 @@ our %argCommon = ("tempdir=s" => \$tempdirname,
12141216
"parallel|j:i" => \$lcovutil::maxParallelism,
12151217
"memory=i" => \$lcovutil::maxMemory,
12161218
"forget-test-names" => \$TraceFile::ignore_testcase_name,
1217-
"preserve" => \$lcovutil::preserve_intermediates,);
1219+
"preserve" => \$lcovutil::preserve_intermediates,
1220+
'sort-input' => \$lcovutil::sort_inputs,);
12181221

12191222
sub warnDeprecated
12201223
{
@@ -9248,6 +9251,13 @@ sub merge
92489251
$lcovutil::maxParallelism = $num;
92499252
}
92509253
}
9254+
# use a particular file sort order - to somewhat minimize order effects
9255+
my $filelist = \@_;
9256+
my @sorted_filelist;
9257+
if ($lcovutil::sort_inputs) {
9258+
@sorted_filelist = sort({ $a cmp $b } @_);
9259+
$filelist = \@sorted_filelist;
9260+
}
92519261

92529262
if (1 != $lcovutil::maxParallelism &&
92539263
(exists($ENV{LCOV_FORCE_PARALLEL}) ||
@@ -9277,7 +9287,7 @@ sub merge
92779287
$lcovutil::maxParallelism) :
92789288
1;
92799289
my $idx = 0;
9280-
foreach my $tracefile (@_) {
9290+
foreach my $tracefile (@$filelist) {
92819291
my $seg = $idx / $testsPerSegment;
92829292
$seg -= 1 if $seg == $lcovutil::maxParallelism;
92839293
push(@segments, [])
@@ -9524,7 +9534,7 @@ sub merge
95249534
} while (@segments);
95259535
} else {
95269536
# sequential
9527-
@effective = _process_segment($total_trace, $readSourceFile, \@_);
9537+
@effective = _process_segment($total_trace, $readSourceFile, $filelist);
95289538
}
95299539
if (defined($lcovutil::tempdirname) &&
95309540
!$lcovutil::preserve_intermediates) {

man/genhtml.1

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ genhtml \- Generate HTML view from LCOV coverage data files
7171
.IR extension ]
7272
.br
7373
.RB [ \-\-html\-gzip ]
74-
.RB [ \-\-sort ]
74+
.RB [ \-\-sort\-tables ]
7575
.RB [ \-\-no\-sort ]
7676
.br
7777
.RB [ \-\-function\-coverage ]
@@ -213,6 +213,8 @@ genhtml \- Generate HTML view from LCOV coverage data files
213213
.br
214214
.RB [ \-\-save ]
215215
.br
216+
.RB [ \-\-sort\-input ]
217+
.br
216218
.RB [ \-\-serialize
217219
.IR serialize_output_file ]
218220
.br
@@ -2671,14 +2673,22 @@ option
26712673
.IR genhtml_html_gzip .
26722674

26732675
.RE
2674-
.B \-\-sort
2676+
.B \-\-sort-tables
26752677
.br
26762678
.B \-\-no\-sort
26772679
.RS
26782680
Specify whether to include sorted views of file and directory overviews.
26792681

2682+
This option replaces the deprecated
2683+
.I "\-\-sort"
2684+
option.
2685+
.I "\-\-sort"
2686+
is still supported and is treated as an alias of
2687+
.I "\-\-sort\-tables"
2688+
but will be removed in a subsequent LCOV release.
2689+
26802690
Use
2681-
.B \-\-sort
2691+
.B \-\-sort-tables
26822692
to include sorted views or
26832693
.B \-\-no\-sort
26842694
to not include them.
@@ -3356,7 +3366,7 @@ Show counts of missed lines, functions, branches, and MC/DC expressions.
33563366
Use this option to change overview pages to show the count of lines, functions,
33573367
branches, or MC/DC expressions that were not hit. These counts are represented by negative numbers.
33583368

3359-
When specified together with \-\-sort, file and directory views will be sorted
3369+
When specified together with \-\-sort\-tables, file and directory views will be sorted
33603370
by missed counts.
33613371

33623372
This option can also be configured permanently using the configuration file
@@ -3397,6 +3407,19 @@ Keeping copies of the input data files may help to debug any issues or to regene
33973407

33983408
.RE
33993409

3410+
.B \-\-sort\-input
3411+
.br
3412+
.RS
3413+
Specify whether to sort file names before capture and/or aggregation.
3414+
Sorting reduces certain types of processing order-dependent output differences.
3415+
See the
3416+
.BI sort_input
3417+
section in
3418+
man
3419+
.B lcovrc(5).
3420+
3421+
.RE
3422+
34003423
.BI "\-\-serialize " file_name
34013424
.RS
34023425
Save coverage database to

man/geninfo.1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ geninfo \- Generate tracefiles from GCOV coverage data files
7979
.RB [ \-\-external ]
8080
.RB [ \-\-no\-external ]
8181
.br
82+
.RB [ \-\-sort\-input ]
83+
.br
8284
.RB [ \-\-config\-file
8385
.IR config\-file ]
8486
.RB [ \-\-no\-markers ]
@@ -677,6 +679,21 @@ config file option. See man
677679
.B lcovrc(5) for more information.
678680
.RE
679681

682+
.RE
683+
684+
.B \-\-sort\-input
685+
.br
686+
.RS
687+
Specify whether to sort file names before capture and/or aggregation.
688+
Sorting reduces certain types of processing order-dependent output differences.
689+
See the
690+
.BI sort_input
691+
section in
692+
man
693+
.B lcovrc(5).
694+
695+
.RE
696+
680697
.B \-\-gcov\-tool
681698
.I tool
682699
.br

man/lcov.1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ format is described in man
5858
.RB [ \-\-no\-recursion ]
5959
.RB [ \-f | \-\-follow ]
6060
.br
61+
.RB [ \-\-sort\-input ]
62+
.br
6163
.RB [ \-\-compat\-libtool ]
6264
.RB [ \-\-no\-compat\-libtool ]
6365
.br
@@ -159,6 +161,8 @@ Aggregate multiple coverage tracefiles into one:
159161
.RB [ \-\-checksum ]
160162
.RB [ \-\-no\-checksum ]
161163
.br
164+
.RB [ \-\-sort\-input ]
165+
.br
162166
.RE
163167

164168
Depending on your use model, it may not be necessary to create aggregate coverage data files.
@@ -1213,6 +1217,19 @@ want to perform the .info file creation on the build machine. See
12131217
\-\-to\-package for more information.
12141218
.RE
12151219

1220+
.B \-\-sort\-input
1221+
.br
1222+
.RS
1223+
Specify whether to sort file names before capture and/or aggregation.
1224+
Sorting reduces certain types of processing order-dependent output differences.
1225+
See the
1226+
.BI sort_input
1227+
section in
1228+
man
1229+
.B lcovrc(5).
1230+
1231+
.RE
1232+
12161233
.B \-\-gcov\-tool
12171234
.I tool
12181235
.br

0 commit comments

Comments
 (0)