-
Notifications
You must be signed in to change notification settings - Fork 0
/
genhtml.perl
5861 lines (5055 loc) · 169 KB
/
genhtml.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
#
# Copyright (c) International Business Machines Corp., 2002,2012
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# <http://www.gnu.org/licenses/>.
#
#
# genhtml
#
# This script generates HTML output from .info files as created by the
# geninfo script. Call it with --help and refer to the genhtml man page
# to get information on usage and available options.
#
#
# History:
# 2002-08-23 created by Peter Oberparleiter <[email protected]>
# IBM Lab Boeblingen
# based on code by Manoj Iyer <[email protected]> and
# Megan Bock <[email protected]>
# IBM Austin
# 2002-08-27 / Peter Oberparleiter: implemented frame view
# 2002-08-29 / Peter Oberparleiter: implemented test description filtering
# so that by default only descriptions for test cases which
# actually hit some source lines are kept
# 2002-09-05 / Peter Oberparleiter: implemented --no-sourceview
# 2002-09-05 / Mike Kobler: One of my source file paths includes a "+" in
# the directory name. I found that genhtml.pl died when it
# encountered it. I was able to fix the problem by modifying
# the string with the escape character before parsing it.
# 2002-10-26 / Peter Oberparleiter: implemented --num-spaces
# 2003-04-07 / Peter Oberparleiter: fixed bug which resulted in an error
# when trying to combine .info files containing data without
# a test name
# 2003-04-10 / Peter Oberparleiter: extended fix by Mike to also cover
# other special characters
# 2003-04-30 / Peter Oberparleiter: made info write to STDERR, not STDOUT
# 2003-07-10 / Peter Oberparleiter: added line checksum support
# 2004-08-09 / Peter Oberparleiter: added configuration file support
# 2005-03-04 / Cal Pierog: added legend to HTML output, fixed coloring of
# "good coverage" background
# 2006-03-18 / Marcus Boerger: added --custom-intro, --custom-outro and
# overwrite --no-prefix if --prefix is present
# 2006-03-20 / Peter Oberparleiter: changes to custom_* function (rename
# to html_prolog/_epilog, minor modifications to implementation),
# changed prefix/noprefix handling to be consistent with current
# logic
# 2006-03-20 / Peter Oberparleiter: added --html-extension option
# 2008-07-14 / Tom Zoerner: added --function-coverage command line option;
# added function table to source file page
# 2008-08-13 / Peter Oberparleiter: modified function coverage
# implementation (now enabled per default),
# introduced sorting option (enabled per default)
#
use strict;
use warnings;
use File::Basename;
use File::Temp qw(tempfile);
use Getopt::Long;
use Digest::MD5 qw(md5_base64);
use Cwd qw/abs_path cwd/;
# Global constants
our $title = "LCOV - code coverage report";
our $tool_dir = abs_path(dirname($0));
our $lcov_version = 'LCOV version '.`"$tool_dir"/get_version.sh --full`;
our $lcov_url = "https://github.com/linux-test-project/lcov";
our $tool_name = basename($0);
# Specify coverage rate default precision
our $default_precision = 1;
# Specify coverage rate limits (in %) for classifying file entries
# HI: $hi_limit <= rate <= 100 graph color: green
# MED: $med_limit <= rate < $hi_limit graph color: orange
# LO: 0 <= rate < $med_limit graph color: red
# For line coverage/all coverage types if not specified
our $hi_limit = 90;
our $med_limit = 75;
# For function coverage
our $fn_hi_limit;
our $fn_med_limit;
# For branch coverage
our $br_hi_limit;
our $br_med_limit;
# Width of overview image
our $overview_width = 80;
# Resolution of overview navigation: this number specifies the maximum
# difference in lines between the position a user selected from the overview
# and the position the source code window is scrolled to.
our $nav_resolution = 4;
# Clicking a line in the overview image should show the source code view at
# a position a bit further up so that the requested line is not the first
# line in the window. This number specifies that offset in lines.
our $nav_offset = 10;
# Clicking on a function name should show the source code at a position a
# few lines before the first line of code of that function. This number
# specifies that offset in lines.
our $func_offset = 2;
our $overview_title = "top level";
# Width for line coverage information in the source code view
our $line_field_width = 12;
# Width for branch coverage information in the source code view
our $br_field_width = 16;
# Internal Constants
# Header types
our $HDR_DIR = 0;
our $HDR_FILE = 1;
our $HDR_SOURCE = 2;
our $HDR_TESTDESC = 3;
our $HDR_FUNC = 4;
# Sort types
our $SORT_FILE = 0;
our $SORT_LINE = 1;
our $SORT_FUNC = 2;
our $SORT_BRANCH = 3;
# Fileview heading types
our $HEAD_NO_DETAIL = 1;
our $HEAD_DETAIL_HIDDEN = 2;
our $HEAD_DETAIL_SHOWN = 3;
# Additional offsets used when converting branch coverage data to HTML
our $BR_LEN = 3;
our $BR_OPEN = 4;
our $BR_CLOSE = 5;
# Branch data combination types
our $BR_SUB = 0;
our $BR_ADD = 1;
# Block value used for unnamed blocks
our $UNNAMED_BLOCK = vec(pack('b*', 1 x 32), 0, 32);
# Error classes which users may specify to ignore during processing
our $ERROR_SOURCE = 0;
our %ERROR_ID = ("source" => $ERROR_SOURCE,);
# Data related prototypes
sub print_usage(*);
sub gen_html();
sub html_create($$);
sub process_dir($);
sub process_file($$$);
sub info(@);
sub read_info_file($);
sub get_info_entry($);
sub set_info_entry($$$$$$$$$;$$$$$$);
sub get_prefix($@);
sub shorten_prefix($);
sub get_dir_list(@);
sub get_relative_base_path($);
sub read_testfile($);
sub get_date_string();
sub create_sub_dir($);
sub subtract_counts($$);
sub add_counts($$);
sub apply_baseline($$);
sub remove_unused_descriptions();
sub get_found_and_hit($);
sub get_affecting_tests($$$);
sub combine_info_files($$);
sub merge_checksums($$$);
sub combine_info_entries($$$);
sub apply_prefix($@);
sub system_no_output($@);
sub read_config($);
sub apply_config($);
sub get_html_prolog($);
sub get_html_epilog($);
sub write_dir_page($$$$$$$$$$$$$$$$$);
sub classify_rate($$$$);
sub combine_brcount($$$;$);
sub get_br_found_and_hit($);
sub warn_handler($);
sub die_handler($);
sub parse_ignore_errors(@);
sub parse_dir_prefix(@);
sub rate($$;$$$);
# HTML related prototypes
sub escape_html($);
sub get_bar_graph_code($$$);
sub write_png_files();
sub write_htaccess_file();
sub write_css_file();
sub write_description_file($$$$$$$);
sub write_function_table(*$$$$$$$$$$);
sub write_html(*$);
sub write_html_prolog(*$$);
sub write_html_epilog(*$;$);
sub write_header(*$$$$$$$$$$);
sub write_header_prolog(*$);
sub write_header_line(*@);
sub write_header_epilog(*$);
sub write_file_table(*$$$$$$$);
sub write_file_table_prolog(*$@);
sub write_file_table_entry(*$$$@);
sub write_file_table_detail_entry(*$@);
sub write_file_table_epilog(*);
sub write_test_table_prolog(*$);
sub write_test_table_entry(*$$);
sub write_test_table_epilog(*);
sub write_source($$$$$$$);
sub write_source_prolog(*);
sub write_source_line(*$$$$$);
sub write_source_epilog(*);
sub write_frameset(*$$$);
sub write_overview_line(*$$$);
sub write_overview(*$$$$);
# External prototype (defined in genpng)
sub gen_png($$$$@);
# Global variables & initialization
our %info_data; # Hash containing all data from .info file
our @opt_dir_prefix; # Array of prefixes to remove from all sub directories
our @dir_prefix;
our %test_description; # Hash containing test descriptions if available
our $date = get_date_string();
our @info_filenames; # List of .info files to use as data source
our $header_title; # Title at top of HTML report page (above table)
our $footer; # String at bottom of HTML report page
our $test_title; # Title shown in header table of each page
our $output_directory; # Name of directory in which to store output
our $base_filename; # Optional name of file containing baseline data
our $desc_filename; # Name of file containing test descriptions
our $css_filename; # Optional name of external stylesheet file to use
our $quiet; # If set, suppress information messages
our $help; # Help option flag
our $version; # Version option flag
our $show_details; # If set, generate detailed directory view
our $no_prefix; # If set, do not remove filename prefix
our $func_coverage; # If set, generate function coverage statistics
our $no_func_coverage; # Disable func_coverage
our $br_coverage; # If set, generate branch coverage statistics
our $no_br_coverage; # Disable br_coverage
our $sort = 1; # If set, provide directory listings with sorted entries
our $no_sort; # Disable sort
our $frames; # If set, use frames for source code view
our $keep_descriptions; # If set, do not remove unused test case descriptions
our $no_sourceview; # If set, do not create a source code view for each file
our $highlight; # If set, highlight lines covered by converted data only
our $legend; # If set, include legend in output
our $tab_size = 8; # Number of spaces to use in place of tab
our $config; # Configuration file contents
our $html_prolog_file; # Custom HTML prolog file (up to and including <body>)
our $html_epilog_file; # Custom HTML epilog file (from </body> onwards)
our $html_prolog; # Actual HTML prolog
our $html_epilog; # Actual HTML epilog
our $html_ext = "html"; # Extension for generated HTML files
our $html_gzip = 0; # Compress with gzip
our $demangle_cpp = 0; # Demangle C++ function names
our $demangle_cpp_tool = "c++filt"; # Default demangler for C++ function names
our $demangle_cpp_params = ""; # Extra parameters for demangling
our @opt_ignore_errors; # Ignore certain error classes during processing
our @ignore;
our $opt_config_file; # User-specified configuration file location
our %opt_rc;
our $opt_missed; # List/sort lines by missed counts
our $dark_mode; # Use dark mode palette or normal
our $charset = "UTF-8"; # Default charset for HTML pages
our @fileview_sortlist;
our @fileview_sortname = ("", "-sort-l", "-sort-f", "-sort-b");
our @funcview_sortlist;
our @rate_name = ("Lo", "Med", "Hi");
our @rate_png = ("ruby.png", "amber.png", "emerald.png");
our $lcov_func_coverage = 1;
our $lcov_branch_coverage = 0;
our $rc_desc_html = 0; # lcovrc: genhtml_desc_html
our $cwd = cwd(); # Current working directory
#
# Code entry point
#
$SIG{__WARN__} = \&warn_handler;
$SIG{__DIE__} = \&die_handler;
# Check command line for a configuration file name
Getopt::Long::Configure("pass_through", "no_auto_abbrev");
GetOptions("config-file=s" => \$opt_config_file,
"rc=s%" => \%opt_rc);
Getopt::Long::Configure("default");
{
# Remove spaces around rc options
my %new_opt_rc;
while (my ($key, $value) = each(%opt_rc)) {
$key =~ s/^\s+|\s+$//g;
$value =~ s/^\s+|\s+$//g;
$new_opt_rc{$key} = $value;
}
%opt_rc = %new_opt_rc;
}
# Read configuration file if available
if (defined($opt_config_file)) {
$config = read_config($opt_config_file);
} elsif (defined($ENV{"HOME"}) && (-r $ENV{"HOME"}."/.lcovrc")) {
$config = read_config($ENV{"HOME"}."/.lcovrc");
} elsif (-r "/etc/lcovrc") {
$config = read_config("/etc/lcovrc");
} elsif (-r "/usr/local/etc/lcovrc") {
$config = read_config("/usr/local/etc/lcovrc");
}
if ($config || %opt_rc) {
# Copy configuration file and --rc values to variables
apply_config({
"genhtml_css_file" => \$css_filename,
"genhtml_header" => \$header_title,
"genhtml_footer" => \$footer,
"genhtml_hi_limit" => \$hi_limit,
"genhtml_med_limit" => \$med_limit,
"genhtml_line_field_width" => \$line_field_width,
"genhtml_overview_width" => \$overview_width,
"genhtml_nav_resolution" => \$nav_resolution,
"genhtml_nav_offset" => \$nav_offset,
"genhtml_keep_descriptions" => \$keep_descriptions,
"genhtml_no_prefix" => \$no_prefix,
"genhtml_no_source" => \$no_sourceview,
"genhtml_num_spaces" => \$tab_size,
"genhtml_highlight" => \$highlight,
"genhtml_legend" => \$legend,
"genhtml_html_prolog" => \$html_prolog_file,
"genhtml_html_epilog" => \$html_epilog_file,
"genhtml_html_extension" => \$html_ext,
"genhtml_html_gzip" => \$html_gzip,
"genhtml_precision" => \$default_precision,
"genhtml_function_hi_limit" => \$fn_hi_limit,
"genhtml_function_med_limit" => \$fn_med_limit,
"genhtml_function_coverage" => \$func_coverage,
"genhtml_branch_hi_limit" => \$br_hi_limit,
"genhtml_branch_med_limit" => \$br_med_limit,
"genhtml_branch_coverage" => \$br_coverage,
"genhtml_branch_field_width" => \$br_field_width,
"genhtml_sort" => \$sort,
"genhtml_charset" => \$charset,
"genhtml_desc_html" => \$rc_desc_html,
"genhtml_demangle_cpp" => \$demangle_cpp,
"genhtml_demangle_cpp_tool" => \$demangle_cpp_tool,
"genhtml_demangle_cpp_params" => \$demangle_cpp_params,
"genhtml_dark_mode" => \$dark_mode,
"genhtml_missed" => \$opt_missed,
"lcov_function_coverage" => \$lcov_func_coverage,
"lcov_branch_coverage" => \$lcov_branch_coverage,
});
}
# Copy related values if not specified
$fn_hi_limit = $hi_limit if (!defined($fn_hi_limit));
$fn_med_limit = $med_limit if (!defined($fn_med_limit));
$br_hi_limit = $hi_limit if (!defined($br_hi_limit));
$br_med_limit = $med_limit if (!defined($br_med_limit));
$func_coverage = $lcov_func_coverage if (!defined($func_coverage));
$br_coverage = $lcov_branch_coverage if (!defined($br_coverage));
# Parse command line options
if (!GetOptions("output-directory|o=s" => \$output_directory,
"header-title=s" => \$header_title,
"footer=s" => \$footer,
"title|t=s" => \$test_title,
"description-file|d=s" => \$desc_filename,
"keep-descriptions|k" => \$keep_descriptions,
"css-file|c=s" => \$css_filename,
"baseline-file|b=s" => \$base_filename,
"prefix|p=s" => \@opt_dir_prefix,
"num-spaces=i" => \$tab_size,
"no-prefix" => \$no_prefix,
"no-sourceview" => \$no_sourceview,
"show-details|s" => \$show_details,
"frames|f" => \$frames,
"highlight" => \$highlight,
"legend" => \$legend,
"quiet|q" => \$quiet,
"help|h|?" => \$help,
"version|v" => \$version,
"html-prolog=s" => \$html_prolog_file,
"html-epilog=s" => \$html_epilog_file,
"html-extension=s" => \$html_ext,
"html-gzip" => \$html_gzip,
"function-coverage" => \$func_coverage,
"no-function-coverage" => \$no_func_coverage,
"branch-coverage" => \$br_coverage,
"no-branch-coverage" => \$no_br_coverage,
"sort" => \$sort,
"no-sort" => \$no_sort,
"demangle-cpp" => \$demangle_cpp,
"ignore-errors=s" => \@opt_ignore_errors,
"config-file=s" => \$opt_config_file,
"rc=s%" => \%opt_rc,
"precision=i" => \$default_precision,
"missed" => \$opt_missed,
"dark-mode" => \$dark_mode,
)) {
print(STDERR "Use $tool_name --help to get usage information\n");
exit(1);
} else {
# Merge options
if ($no_func_coverage) {
$func_coverage = 0;
}
if ($no_br_coverage) {
$br_coverage = 0;
}
# Merge sort options
if ($no_sort) {
$sort = 0;
}
if (defined($header_title)) {
$title = $header_title;
}
}
@info_filenames = @ARGV;
# Check for help option
if ($help) {
print_usage(*STDOUT);
exit(0);
}
# Check for version option
if ($version) {
print("$tool_name: $lcov_version\n");
exit(0);
}
# Determine which errors the user wants us to ignore
parse_ignore_errors(@opt_ignore_errors);
# Split the list of prefixes if needed
parse_dir_prefix(@opt_dir_prefix);
# Check for info filename
if (!@info_filenames) {
die("No filename specified\n".
"Use $tool_name --help to get usage information\n");
}
# Generate a title if none is specified
if (!$test_title) {
if (scalar(@info_filenames) == 1) {
# Only one filename specified, use it as title
$test_title = basename($info_filenames[0]);
} else {
# More than one filename specified, used default title
$test_title = "unnamed";
}
}
# Make sure css_filename is an absolute path (in case we're changing
# directories)
if ($css_filename) {
if (!($css_filename =~ /^\/(.*)$/)) {
$css_filename = $cwd."/".$css_filename;
}
}
# Make sure tab_size is within valid range
if ($tab_size < 1) {
print(STDERR "ERROR: invalid number of spaces specified: $tab_size!\n");
exit(1);
}
# Get HTML prolog and epilog
$html_prolog = get_html_prolog($html_prolog_file);
$html_epilog = get_html_epilog($html_epilog_file);
# Issue a warning if --no-sourceview is enabled together with --frames
if ($no_sourceview && defined($frames)) {
warn("WARNING: option --frames disabled because --no-sourceview ".
"was specified!\n");
$frames = undef;
}
# Issue a warning if --no-prefix is enabled together with --prefix
if ($no_prefix && @dir_prefix) {
warn("WARNING: option --prefix disabled because --no-prefix was ".
"specified!\n");
@dir_prefix = undef;
}
@fileview_sortlist = ($SORT_FILE);
@funcview_sortlist = ($SORT_FILE);
if ($sort) {
push(@fileview_sortlist, $SORT_LINE);
push(@fileview_sortlist, $SORT_FUNC) if ($func_coverage);
push(@fileview_sortlist, $SORT_BRANCH) if ($br_coverage);
push(@funcview_sortlist, $SORT_LINE);
}
if ($frames) {
# Include genpng code needed for overview image generation
do("$tool_dir/genpng");
}
# Ensure that the c++filt tool is available when using --demangle-cpp
if ($demangle_cpp) {
if (system_no_output(3, $demangle_cpp_tool, "--version")) {
die("ERROR: could not find $demangle_cpp_tool tool needed for ".
"--demangle-cpp\n");
}
}
# Make sure precision is within valid range
if ($default_precision < 1 || $default_precision > 4) {
die("ERROR: specified precision is out of range (1 to 4)\n");
}
# Make sure output_directory exists, create it if necessary
if ($output_directory) {
stat($output_directory);
if (!-e _) {
create_sub_dir($output_directory);
}
}
# Do something
gen_html();
exit(0);
#
# print_usage(handle)
#
# Print usage information.
#
sub print_usage(*)
{
local *HANDLE = $_[0];
print(HANDLE <<END_OF_USAGE);
Usage: $tool_name [OPTIONS] INFOFILE(S)
Create HTML output for coverage data found in INFOFILE. Note that INFOFILE
may also be a list of filenames.
Misc:
-h, --help Print this help, then exit
-v, --version Print version number, then exit
-q, --quiet Do not print progress messages
--config-file FILENAME Specify configuration file location
--rc SETTING=VALUE Override configuration file setting
--ignore-errors ERRORS Continue after ERRORS (source)
Operation:
-o, --output-directory OUTDIR Write HTML output to OUTDIR
-s, --show-details Generate detailed directory view
-d, --description-file DESCFILE Read test case descriptions from DESCFILE
-k, --keep-descriptions Do not remove unused test descriptions
-b, --baseline-file BASEFILE Use BASEFILE as baseline file
-p, --prefix PREFIX Remove PREFIX from all directory names
--no-prefix Do not remove prefix from directory names
--(no-)function-coverage Enable (disable) function coverage display
--(no-)branch-coverage Enable (disable) branch coverage display
HTML output:
-f, --frames Use HTML frames for source code view
-t, --title TITLE Show TITLE in header table of each page
-c, --css-file CSSFILE Use external style sheet file CSSFILE
--header-title BANNER Banner text at top of each HTML page
--footer FOOTER Footer text at bottom of each HTML page
--no-source Do not create source code view
--num-spaces NUM Replace tabs with NUM spaces in source view
--highlight Highlight lines with converted-only data
--legend Include color legend in HTML output
--html-prolog FILE Use FILE as HTML prolog for generated pages
--html-epilog FILE Use FILE as HTML epilog for generated pages
--html-extension EXT Use EXT as filename extension for pages
--html-gzip Use gzip to compress HTML
--(no-)sort Enable (disable) sorted coverage views
--demangle-cpp Demangle C++ function names
--precision NUM Set precision of coverage rate
--missed Show miss counts as negative numbers
--dark-mode Use the dark-mode CSS
For more information see: $lcov_url
END_OF_USAGE
}
#
# get_rate(found, hit)
#
# Return a relative value for the specified found&hit values
# which is used for sorting the corresponding entries in a
# file list.
#
sub get_rate($$)
{
my ($found, $hit) = @_;
if ($found == 0) {
return 10000;
}
return int($hit * 1000 / $found) * 10 + 2 - (1 / $found);
}
#
# get_overall_line(found, hit, name_singular, name_plural)
#
# Return a string containing overall information for the specified
# found/hit data.
#
sub get_overall_line($$$$)
{
my ($found, $hit, $name_sn, $name_pl) = @_;
my $name;
return "no data found" if (!defined($found) || $found == 0);
$name = ($found == 1) ? $name_sn : $name_pl;
return rate($hit, $found, "% ($hit of $found $name)");
}
#
# print_overall_rate(ln_do, ln_found, ln_hit, fn_do, fn_found, fn_hit, br_do
# br_found, br_hit)
#
# Print overall coverage rates for the specified coverage types.
#
sub print_overall_rate($$$$$$$$$)
{
my ($ln_do, $ln_found, $ln_hit, $fn_do, $fn_found,
$fn_hit, $br_do, $br_found, $br_hit) = @_;
info("Overall coverage rate:\n");
info(" lines......: %s\n",
get_overall_line($ln_found, $ln_hit, "line", "lines"))
if ($ln_do);
info(" functions..: %s\n",
get_overall_line($fn_found, $fn_hit, "function", "functions"))
if ($fn_do);
info(" branches...: %s\n",
get_overall_line($br_found, $br_hit, "branch", "branches"))
if ($br_do);
}
sub get_fn_list($)
{
my ($info) = @_;
my %fns;
my @result;
foreach my $filename (keys(%{$info})) {
my $data = $info->{$filename};
my $funcdata = $data->{"func"};
my $sumfnccount = $data->{"sumfnc"};
if (defined($funcdata)) {
foreach my $func_name (keys(%{$funcdata})) {
$fns{$func_name} = 1;
}
}
if (defined($sumfnccount)) {
foreach my $func_name (keys(%{$sumfnccount})) {
$fns{$func_name} = 1;
}
}
}
@result = keys(%fns);
return \@result;
}
#
# rename_functions(info, conv)
#
# Rename all function names in INFO according to CONV: OLD_NAME -> NEW_NAME.
# In case two functions demangle to the same name, assume that they are
# different object code implementations for the same source function.
#
sub rename_functions($$)
{
my ($info, $conv) = @_;
foreach my $filename (keys(%{$info})) {
my $data = $info->{$filename};
my $funcdata;
my $testfncdata;
my $sumfnccount;
my %newfuncdata;
my %newsumfnccount;
my $f_found;
my $f_hit;
# funcdata: function name -> line number
$funcdata = $data->{"func"};
foreach my $fn (keys(%{$funcdata})) {
my $cn = $conv->{$fn};
# Abort if two functions on different lines map to the
# same demangled name.
if (defined($newfuncdata{$cn}) &&
$newfuncdata{$cn} != $funcdata->{$fn}) {
die("ERROR: Demangled function name $cn ".
"maps to different lines ("
.
$newfuncdata{
$cn}.
" vs ".$funcdata->{$fn}.") in $filename\n");
}
$newfuncdata{$cn} = $funcdata->{$fn};
}
$data->{"func"} = \%newfuncdata;
# testfncdata: test name -> testfnccount
# testfnccount: function name -> execution count
$testfncdata = $data->{"testfnc"};
foreach my $tn (keys(%{$testfncdata})) {
my $testfnccount = $testfncdata->{$tn};
my %newtestfnccount;
foreach my $fn (keys(%{$testfnccount})) {
my $cn = $conv->{$fn};
# Add counts for different functions that map
# to the same name.
$newtestfnccount{$cn} += $testfnccount->{$fn};
}
$testfncdata->{$tn} = \%newtestfnccount;
}
# sumfnccount: function name -> execution count
$sumfnccount = $data->{"sumfnc"};
foreach my $fn (keys(%{$sumfnccount})) {
my $cn = $conv->{$fn};
# Add counts for different functions that map
# to the same name.
$newsumfnccount{$cn} += $sumfnccount->{$fn};
}
$data->{"sumfnc"} = \%newsumfnccount;
# Update function found and hit counts since they may have
# changed
$f_found = 0;
$f_hit = 0;
foreach my $fn (keys(%newsumfnccount)) {
$f_found++;
$f_hit++ if ($newsumfnccount{$fn} > 0);
}
$data->{"f_found"} = $f_found;
$data->{"f_hit"} = $f_hit;
}
}
#
# gen_html()
#
# Generate a set of HTML pages from contents of .info file INFO_FILENAME.
# Files will be written to the current directory. If provided, test case
# descriptions will be read from .tests file TEST_FILENAME and included
# in ouput.
#
# Die on error.
#
sub gen_html()
{
local *HTML_HANDLE;
my %overview;
my %base_data;
my $lines_found;
my $lines_hit;
my $fn_found;
my $fn_hit;
my $br_found;
my $br_hit;
my $overall_found = 0;
my $overall_hit = 0;
my $total_fn_found = 0;
my $total_fn_hit = 0;
my $total_br_found = 0;
my $total_br_hit = 0;
my $dir_name;
my $link_name;
my @dir_list;
my %new_info;
# Read in all specified .info files
foreach (@info_filenames) {
%new_info = %{read_info_file($_)};
# Combine %new_info with %info_data
%info_data = %{combine_info_files(\%info_data, \%new_info)};
}
info("Found %d entries.\n", scalar(keys(%info_data)));
# Read and apply baseline data if specified
if ($base_filename) {
# Read baseline file
info("Reading baseline file $base_filename\n");
%base_data = %{read_info_file($base_filename)};
info("Found %d entries.\n", scalar(keys(%base_data)));
# Apply baseline
info("Subtracting baseline data.\n");
%info_data = %{apply_baseline(\%info_data, \%base_data)};
}
@dir_list = get_dir_list(keys(%info_data));
if ($no_prefix) {
# User requested that we leave filenames alone
info("User asked not to remove filename prefix\n");
} elsif (!@dir_prefix) {
# Get prefix common to most directories in list
my $prefix = get_prefix(1, keys(%info_data));
if ($prefix) {
info("Found common filename prefix \"$prefix\"\n");
$dir_prefix[0] = $prefix;
} else {
info("No common filename prefix found!\n");
$no_prefix = 1;
}
} else {
my $msg = "Using user-specified filename prefix ";
for my $i (0 .. $#dir_prefix) {
$dir_prefix[$i] =~ s/\/+$//;
$msg .= ", " unless 0 == $i;
$msg .= "\"".$dir_prefix[$i]."\"";
}
info($msg."\n");
}
# Read in test description file if specified
if ($desc_filename) {
info("Reading test description file $desc_filename\n");
%test_description = %{read_testfile($desc_filename)};
# Remove test descriptions which are not referenced
# from %info_data if user didn't tell us otherwise
if (!$keep_descriptions) {
remove_unused_descriptions();
}
}
# Change to output directory if specified
if ($output_directory) {
chdir($output_directory) or
die("ERROR: cannot change to directory $output_directory!\n");
}
info("Writing .css and .png files.\n");
write_css_file();
write_png_files();
if ($html_gzip) {
info("Writing .htaccess file.\n");
write_htaccess_file();
}
info("Generating output.\n");
# Process each subdirectory and collect overview information
foreach $dir_name (@dir_list) {
($lines_found, $lines_hit, $fn_found, $fn_hit, $br_found, $br_hit) =
process_dir($dir_name);
# Handle files in root directory gracefully
$dir_name = "root" if ($dir_name eq "");
# Remove prefix if applicable
if (!$no_prefix && @dir_prefix) {
# Match directory names beginning with one of @dir_prefix
$dir_name = apply_prefix($dir_name, @dir_prefix);
}
# Generate name for directory overview HTML page
if ($dir_name =~ /^\/(.*)$/) {
$link_name = substr($dir_name, 1)."/index.$html_ext";
} else {
$link_name = $dir_name."/index.$html_ext";
}
$overview{$dir_name} = [$lines_found,
$lines_hit,
$fn_found,
$fn_hit,
$br_found,
$br_hit,
$link_name,
get_rate($lines_found, $lines_hit),
get_rate($fn_found, $fn_hit),
get_rate($br_found, $br_hit)
];
$overall_found += $lines_found;
$overall_hit += $lines_hit;
$total_fn_found += $fn_found;
$total_fn_hit += $fn_hit;
$total_br_found += $br_found;
$total_br_hit += $br_hit;
}
# Generate overview page
info("Writing directory view page.\n");
# Create sorted pages
foreach (@fileview_sortlist) {
write_dir_page($fileview_sortname[$_], ".",
"", $test_title,
undef, $overall_found,
$overall_hit, $total_fn_found,
$total_fn_hit, $total_br_found,
$total_br_hit, \%overview,
{}, {},
{}, 0,
$_);
}
# Check if there are any test case descriptions to write out
if (%test_description) {
info("Writing test case description file.\n");
write_description_file(\%test_description, $overall_found,
$overall_hit, $total_fn_found,
$total_fn_hit, $total_br_found,
$total_br_hit);
}
print_overall_rate(1, $overall_found, $overall_hit,
$func_coverage, $total_fn_found, $total_fn_hit,
$br_coverage, $total_br_found, $total_br_hit);
chdir($cwd);
}
#
# html_create(handle, filename)
#
sub html_create($$)
{
my $handle = $_[0];
my $filename = $_[1];
if ($html_gzip) {
open($handle, "|-", "gzip -c >'$filename'") or
die("ERROR: cannot open $filename for writing (gzip)!\n");
} else {
open($handle, ">", $filename) or
die("ERROR: cannot open $filename for writing!\n");
}
}
sub write_dir_page($$$$$$$$$$$$$$$$$)
{
my ($name, $rel_dir, $base_dir, $title,
$trunc_dir, $overall_found, $overall_hit, $total_fn_found,