-
Notifications
You must be signed in to change notification settings - Fork 241
/
genhtml
executable file
·12818 lines (11576 loc) · 450 KB
/
genhtml
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)
# April/May 2020 / Henry Cox/Steven Dovich - Mediatek, inc
# Add support for differential line coverage categorization,
# date- and owner- binning.
# June/July 2020 / Henry Cox - Mediatek, inc
# Add support for differential branch coverage categorization,
# Add a bunch of navigation features - href to next code block
# of type T, of type T in date- or owner bin B, etc.
# Add sorted tables for date/owner bin summaries.
# Ocober 2020 / Henry Cox - Mediatek, inc
# Add "--hierarchical" display option.
#
use strict;
use warnings;
use File::Basename;
use File::Copy;
use File::Path;
use File::Spec;
use File::Temp;
use Scalar::Util qw/looks_like_number/;
use Digest::MD5 qw(md5_base64);
use Cwd qw/abs_path realpath cwd/;
use DateTime;
#use Regexp::Common qw(time); # damn - not installed
use Date::Parse;
use FileHandle;
use Carp;
use Storable qw(dclone);
use FindBin;
use Time::HiRes; # for profiling
use Storable;
use POSIX;
use Data::Dumper;
use lib "$FindBin::RealBin/../lib";
use lcovutil qw (set_tool_name define_errors parse_ignore_errors
$tool_name $tool_dir $lcov_version $lcov_url
ignorable_error
$ERROR_MISMATCH $ERROR_SOURCE $ERROR_BRANCH $ERROR_FORMAT
$ERROR_EMPTY $ERROR_VERSION $ERROR_UNUSED $ERROR_PACKAGE
$ERROR_CORRUPT $ERROR_NEGATIVE $ERROR_COUNT $ERROR_UNSUPPORTED
$ERROR_DEPRECATED $ERROR_INCONSISTENT_DATA $ERROR_CALLBACK
$ERROR_RANGE $ERROR_PATH
$ERROR_PARALLEL $ERROR_CHILD report_parallel_error
report_exit_status
summarize_messages
$br_coverage $func_coverage
info $verbose init_verbose_flag debug $debug $devnull
parseOptions
strip_directories
parse_cov_filters summarize_cov_filters
$FILTER_BRANCH_NO_COND $FILTER_LINE_CLOSE_BRACE @cov_filter
rate get_overall_line $default_precision check_precision
die_handler warn_handler parse_w3cdtf);
# Global constants
our $title = "LCOV - differential code coverage report";
lcovutil::set_tool_name(basename($0));
our $debugScheduler = 0;
# if false, then keep track of only enough information to be able to
# produce a valid HTML report.
# - Do not keep track of everything - say, to enable serialize/deserialize
# of the complete coverage DB.
# - In practice: this means to throw away the 'FileDetails' structure after
# the source file HTML has been constructed. 'FileDetails' is the lion's
# share of the memory footprint.
# This has the effect of reducing memory footprint and improving parallel
# performance.
our $buildSerializableDatabase = 0;
# 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 line coverage
our $ln_hi_limit;
our $ln_med_limit;
# 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;
# Width for owner name in the source code view
our $owner_field_width = 20;
# Width for block age in the source code view
our $age_field_width = 5;
# Width for TLA entry in the source code view
our $tla_field_width = 3;
# 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;
# function detail sort types
our $SORT_MISSING_LINE = 4; # by number of not-hit lines in function
our $SORT_MISSING_BRANCH = 5; # by number of not-hit branches in function
# 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;
# Data related prototypes
sub print_usage(*);
sub gen_html();
sub html_create($$);
sub process_file($$$$$);
sub compute_title($$);
sub get_prefix($@);
sub shorten_prefix($);
sub get_relative_base_path($);
sub read_testfile($);
sub get_date_string($);
sub remove_unused_descriptions();
sub get_affecting_tests($$$);
sub apply_prefix($@);
sub get_html_prolog($);
sub get_html_epilog($);
#sub write_dir_page($$$$$$$;$);
sub write_summary_pages($$$$$$$$);
sub classify_rate($$$$);
sub parse_dir_prefix(@);
# HTML related prototypes
sub escape_html($);
sub escape_id($);
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($$$$$@);
package SummaryInfo;
our @selectCallbackScript;
our $selectCallback;
our @cleanDirectoryList;
our @tlaPriorityOrder = ("UNC",
"LBC",
"UIC",
"UBC",
"GBC",
"GIC",
"GNC",
"CBC",
"EUB",
"ECB",
"DUB",
"DCB",);
our %tlaLocation = ("UNC" => 1,
"LBC" => 3,
"UIC" => 3,
"UBC" => 3,
"GBC" => 3,
"GIC" => 3,
"GNC" => 1,
"CBC" => 3,
"EUB" => 3,
"ECB" => 3,
"DUB" => 2,
"DCB" => 2,);
our %tlaToTitle = ("UNC" => "Uncovered New Code (+ => 0):\n" .
"Newly added code is not tested",
"LBC" => "Lost Baseline Coverage (1 => 0):\n" .
"Unchanged code is no longer tested",
"UIC" => "Uncovered Included Code (# => 0):\n" .
"Previously unused code is untested",
"UBC" => "Uncovered Baseline Code (0 => 0):\n" .
"Unchanged code was untested before, is untested now",
"GBC" => "Gained Baseline Coverage (0 => 1):\n" .
"Unchanged code is tested now",
"GIC" => "Gained Included Coverage (# => 1):\n" .
"Previously unused code is tested now",
"GNC" => "Gained New Coverage (+ => 1):\n" .
"Newly added code is tested",
"CBC" => "Covered Baseline Code (1 => 1):\n" .
"Unchanged code was tested before and is still tested",
"EUB" => "Excluded Uncovered Baseline (0 => #):\n" .
"Previously untested code is unused now",
"ECB" => "Excluded Covered Baseline (1 => #):\n" .
"Previously tested code is unused now",
"DUB" => "Deleted Uncovered Baseline (0 => -):\n" .
"Previously untested code has been deleted",
"DCB" => "Deleted Covered Baseline (1 => -):\n" .
"Previously tested code has been deleted",);
our %tlaToLegacy = ("UNC" => "Missed",
"GNC" => "Hit",);
our %tlaToLegacySrcLabel = ("UNC" => "MIS",
"GNC" => "HIT",);
our @defaultCutpoints = (7, 30, 180);
our @cutpoints;
our @ageGroupHeader;
our %ageHeaderToBin;
our @truncateOwnerTableLevels; # default: truncate everywhere if enabled
our $ownerTableElements; # default: do not truncate
our $compactSummaryTables = 1; # on by default
use constant {
TYPE => 0,
NAME => 1,
PARENT => 2,
RELATIVE_DIR => 3,
FULL_DIR => 4,
LINE_DATA => 5,
BRANCH_DATA => 6,
FUNCTION_DATA => 7,
FILE_DETAILS => 8, # SourceFile struct - only used for 'file' type
SOURCES => 8, # used by top and directory types
IS_ABSOLUTE => 9, # used by directory type only
# coverage data list for type
DATA => 0,
AGE => 1,
OWNERS => 2, # not used by Function coverage - no owner
};
sub type2str
{
my $t = shift;
return 'line' if ($t == LINE_DATA);
return 'branch' if ($t == BRANCH_DATA);
die("unexpected type '$t'") unless ($t == FUNCTION_DATA);
return 'function';
}
sub _initCounts
{
my %hash;
foreach my $key ('found', 'hit', 'GNC', 'UNC', 'CBC', 'GBC',
'LBC', 'UBC', 'ECB', 'EUB', 'GIC', 'UIC',
'DCB', 'DUB'
) {
$hash{$key} = 0;
}
return \%hash;
}
sub noBaseline
{
# no baseline - so we will have only 'UIC' and 'GIC' code
# legacy display order is 'hit' followed by 'not hit'
@tlaPriorityOrder = ('GNC', 'UNC');
%tlaToTitle = ('UNC' => 'Not Hit',
'GNC' => 'Hit',);
}
sub setAgeGroups
{
#my $numGroups = scalar(@_) + 1;
@cutpoints = sort({ $a <=> $b } @_);
@ageGroupHeader = ();
%ageHeaderToBin = ();
my $prefix = "[..";
foreach my $days (@cutpoints) {
my $header = $prefix . $days . "] days";
push(@ageGroupHeader, $header);
$prefix = "(" . $days . ",";
}
push(@ageGroupHeader, "(" . $cutpoints[-1] . "..) days");
my $bin = 0;
foreach my $header (@ageGroupHeader) {
$ageHeaderToBin{$header} = $bin;
++$bin;
}
}
sub findAgeBin
{
my $age = shift;
defined($age) or die("undefined age");
my $bin;
for ($bin = 0; $bin <= $#cutpoints; $bin++) {
last
if ($age <= $cutpoints[$bin]);
}
return $bin;
}
sub new
{
my ($class, $type, $name, $is_absolute_dir) = @_;
defined($name) || $type eq 'top' or
die("SummaryInfo name should be defined, except at top-level");
my $self = [$type, # 'type' expected to be one of 'file', 'directory', 'top'
$name,
undef, # parent
undef, # relative dir,
undef, # full directory path,
[undef, [], {}], # line data
[undef, [], {}], # branch data
[undef, []] # function data
];
if ($type eq 'file') {
$self->[FILE_DETAILS] = undef; # will be SourceFile object
} else {
$self->[SOURCES] = {};
$self->[IS_ABSOLUTE] = $is_absolute_dir
if ($type eq 'directory');
}
for my $type (LINE_DATA, BRANCH_DATA, FUNCTION_DATA) {
$self->[$type]->[DATA] = _initCounts();
# no age data unless annotations are enabled
next unless @SourceFile::annotateScript;
my $ageList = $self->[$type]->[AGE];
foreach my $i (0 .. $#cutpoints + 1) {
my $h = _initCounts();
$h->{_LB} = ($i == 0) ? undef : $cutpoints[$i - 1];
$h->{_UB} = ($i == $#cutpoints + 1) ? undef : $cutpoints[$i];
$h->{_INDEX} = $i;
push(@$ageList, $h);
}
}
bless $self, $class;
return $self;
}
# deserialization: copy the coverage portion of the undumped data
sub copyGuts
{
my ($self, $that) = @_;
my @copy = (RELATIVE_DIR, FULL_DIR, LINE_DATA, BRANCH_DATA, FUNCTION_DATA);
if ($that->[TYPE] eq 'file') {
push(@copy, FILE_DETAILS);
} elsif ($that->[TYPE] eq 'directory') {
push(@copy, IS_ABSOLUTE);
}
for my $key (@copy) {
$self->[$key] = $that->[$key];
}
}
sub name
{
my $self = shift;
return $self->[NAME];
}
sub unsetDirs
{
my $self = shift;
# need to reset after fork failure - we set the values
# just before forking, but now have to put them back.
die('bad usage: unsetDirs()')
unless (defined($self->[FULL_DIR]) &&
defined($self->[RELATIVE_DIR]));
$self->[FULL_DIR] = undef;
$self->[RELATIVE_DIR] = undef;
}
sub relativeDir
{
my ($self, $dir_string) = @_;
die("bad usage: relativeDir(" .
(defined($dir_string) ? $dir_string : '') . ') current: '
.
(defined($self->[RELATIVE_DIR]) ? $self->[RELATIVE_DIR] : '<undef>')
)
unless ((!defined($dir_string) && defined($self->[RELATIVE_DIR])) ||
(defined($dir_string) && !defined($self->[RELATIVE_DIR])));
$self->[RELATIVE_DIR] = $dir_string
if defined($dir_string);
return $self->[RELATIVE_DIR];
}
sub fullDir
{
my ($self, $dir_string) = @_;
die("bad usage fullDir()")
unless ((!defined($dir_string) && defined($self->[FULL_DIR])) ||
(defined($dir_string) && !defined($self->[FULL_DIR])));
$self->[FULL_DIR] = $dir_string
if defined($dir_string);
return $self->[FULL_DIR];
}
sub type
{
my $self = shift;
return $self->[TYPE];
}
sub is_directory
{
my ($self, $is_absolute) = @_;
return (
$self->type() eq 'directory' ?
((defined($is_absolute) && $is_absolute) ? $self->[IS_ABSOLUTE] : 1)
:
0);
}
sub parent
{
my $self = shift;
return $self->[PARENT];
}
sub setParent
{
my ($self, $parent) = @_;
die("expected parent dir")
unless (ref($parent) eq "SummaryInfo" &&
($main::flat ? 'top' : 'directory') eq $parent->type());
$self->[PARENT] = $parent;
}
sub sources
{
my $self = shift;
die("bad usage") if $self->type() eq 'file';
return keys(%{$self->[SOURCES]});
}
sub fileDetails
{
my ($self, $data) = @_;
$self->type() eq 'file' or die("source details only available for file");
!(defined($data) && defined($self->[FILE_DETAILS])) or
die("attempt to set details in initialized struct");
!defined($data) || ref($data) eq 'SourceFile' or
die("unexpected data arg " . ref($data));
$self->[FILE_DETAILS] = $data
if defined($data);
return $self->[FILE_DETAILS];
}
sub get_sorted_keys
{
# sort_type in ($SORT_FILE, $SORT_LINE, $SORT_FUNC, $SORT_BRANCH)
my ($self, $sort_type, $include_dirs) = @_;
die("invalid usage") if $self->type() eq 'file';
my $sources = $self->[SOURCES];
my @keys = $self->sources();
my @l;
foreach my $k (@keys) {
my $data = $sources->{$k};
next
if ($data->type() eq 'directory' &&
(!defined($include_dirs) ||
0 == $include_dirs));
push(@l, $k);
}
if ($sort_type == $SORT_FILE) {
# alphabetic
return sort(@l);
}
my $covtype;
if ($sort_type == $SORT_LINE) {
# Sort by number of instrumented lines without coverage
$covtype = LINE_DATA;
} elsif ($sort_type == $SORT_FUNC) {
# Sort by number of instrumented functions without coverage
$covtype = FUNCTION_DATA;
} else {
die("unexpected sort type $sort_type")
unless ($sort_type == $SORT_BRANCH);
# Sort by number of instrumented branches without coverage
$covtype = BRANCH_DATA;
}
if ($main::opt_missed) {
# sort by directory first then secondary key
return
sort({
my $da = $sources->{$a};
my $db = $sources->{$b};
# directories then files if list includes both
$da->type() cmp $db->type() or
$db->get_missed($covtype)
<=> $da->get_missed($covtype) or
# sort alphabetically in case of tie
$da->name() cmp $db->name()
} @l);
} else {
return
sort({
my $da = $sources->{$a};
my $db = $sources->{$b};
$da->type() cmp $db->type() or
$da->get_rate($covtype) <=> $db->get_rate($covtype) or
$da->name() cmp $db->name()
} @l);
}
}
sub get_source
{
my ($self, $name) = @_;
die("bad usage") if $self->type() eq 'file';
return
exists($self->[SOURCES]->{$name}) ? $self->[SOURCES]->{$name} : undef;
}
sub remove_source
{
my ($self, $name) = @_;
die("bad usage") if $self->type() eq 'file';
delete $self->[SOURCES]->{$name};
}
sub get
{
my ($self, $key, $type) = @_;
$type = LINE_DATA
if !defined($type);
my $hash = $self->[$type]->[DATA];
if ($key eq "missed") {
my $missed = 0;
foreach my $k ('UBC', 'UNC', 'UIC', 'LBC') {
$missed += $hash->{$k}
if (exists($hash->{$k}));
}
return $missed;
} else {
die("unexpected 'get' key $key")
unless exists($hash->{$key});
return $hash->{$key};
}
}
# 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 ($self, $covtype) = @_;
my $hash = $self->[$covtype]->[DATA];
my $found = $hash->{found};
my $hit = $hash->{hit};
if ($found == 0) {
#return 100;
return 1000;
}
#return (100.0 * $hit) / $found;
return int($hit * 1000 / $found) * 10 + 2 - (1 / $found);
}
sub get_missed
{
my ($self, $covtype) = @_;
my $hash = $self->[$covtype]->[DATA];
my $found = $hash->{found};
my $hit = $hash->{hit};
return $found - $hit;
}
sub contains_owner
{
my ($self, $owner) = @_;
return exists($self->[LINE_DATA]->[OWNERS]->{$owner});
}
sub owners
{
# return possibly empty list of line owners in this file
# - filter only those which have 'missed' lines
my ($self, $showAll, $covType) = @_;
(!defined($covType) || $covType == LINE_DATA || $covType == BRANCH_DATA) or
die("unsupported coverage type '$covType'");
my $hash = $self->[defined($covType) ? $covType : LINE_DATA]->[OWNERS];
return keys(%$hash)
if $showAll;
my @rtn;
OWNER:
foreach my $name (keys(%$hash)) {
my $h = $hash->{$name};
foreach my $tla ('UNC', 'UBC', 'UIC', 'LBC') {
if (exists($h->{$tla})) {
die("unexpected 0 (zero) value for $tla of $name in $self->path()"
) if (0 == $h->{$tla});
push(@rtn, $name);
next OWNER;
}
}
}
return @rtn;
}
sub owner_tlaCount
{
my ($self, $name, $tla, $covType) = @_;
die("$name not found in owner data for $self->path()")
unless exists($self->[LINE_DATA]->[OWNERS]->{$name});
return 0 # not supported, yet
if $covType == FUNCTION_DATA;
(!defined($covType) || $covType == LINE_DATA || $covType == BRANCH_DATA) or
die("unsupported coverage type '$covType'");
my $hash =
$self->[defined($covType) ? $covType : LINE_DATA]->[OWNERS]->{$name};
return $hash->{$tla}
if (exists($hash->{$tla}));
if ($tla eq "found") {
my $total = 0;
foreach my $k (keys(%$hash)) {
# count only code that can be hit (ie., not excluded)
$total += $hash->{$k}
if ('EUB' ne $k &&
'ECB' ne $k);
}
return $total;
} elsif ($tla eq "hit") {
my $hit = 0;
foreach my $k ('CBC', 'GBC', 'GIC', 'GNC') {
$hit += $hash->{$k}
if (exists($hash->{$k}));
}
return $hit;
} elsif ($tla eq "missed") {
my $missed = 0;
foreach my $k ('UBC', 'UNC', 'UIC', 'LBC') {
$missed += $hash->{$k}
if (exists($hash->{$k}));
}
return $tla eq "missed" ? $missed : -$missed;
}
die("unexpected TLA $tla")
unless exists($tlaLocation{$tla});
return 0;
}
sub hasOwnerInfo
{
my $self = shift;
return %{$self->[LINE_DATA]->[OWNERS]} ? 1 : 0;
}
sub hasDateInfo
{
my $self = shift;
# we get date- and owner information at the same time from the
# annotation-script - so, if we have owner info, then we have date info too.
return %{$self->[LINE_DATA]->[OWNERS]} ? 1 : 0;
}
sub findOwnerList
{
# return [ [owner, lineCovData, branchCovData, functionCov]] for each owner
# where lineCovData = [missedCount, totalCount]
# branchCovData = [missed, total] or undef if not enabled
# functionCov = [missed, total] or undef if not enabled
# - sorted in descending order number of missed lines
my ($self, $callback_type, $truncate_me, $all) = @_;
my @owners;
foreach my $owner (keys(%{$self->[LINE_DATA]->[OWNERS]})) {
my $lineMissed = $self->owner_tlaCount($owner, 'missed', LINE_DATA);
my $branchMissed =
$lcovutil::br_coverage ?
$self->owner_tlaCount($owner, 'missed', BRANCH_DATA) :
0;
my $funcMissed =
$lcovutil::func_coverage ?
$self->owner_tlaCount($owner, 'missed', FUNCTION_DATA) :
0;
# filter owners who have unexercised code, if requested
if ($all ||
(0 != $lineMissed || 0 != $branchMissed || 0 != $funcMissed)) {
my $lineCb = OwnerDetailCallback->new($self, $owner, LINE_DATA);
my $branchCb = OwnerDetailCallback->new($self, $owner, BRANCH_DATA);
my $functionCb =
OwnerDetailCallback->new($self, $owner, FUNCTION_DATA);
my $lineTotal = $self->owner_tlaCount($owner, 'found', LINE_DATA);
my $branchTotal =
$lcovutil::br_coverage ?
$self->owner_tlaCount($owner, 'found', BRANCH_DATA) :
0;
my $funcTotal =
$lcovutil::func_coverage ?
$self->owner_tlaCount($owner, 'found', FUNCTION_DATA) :
0;
push(@owners,
[$owner,
[$lineMissed, $lineTotal, $lineCb],
[$branchMissed, $branchTotal, $branchCb],
[$funcMissed, $funcTotal, $functionCb]
]);
}
}
@owners = sort({
$b->[1]->[0] <=> $a->[1]->[0] || # missed
$b->[1]->[1] <=> $a->[1]->[1] || # then total
$a->[0] cmp $b->[0]
} @owners); # then by name
my $truncated;
if ($truncate_me &&
defined($ownerTableElements) &&
$ownerTableElements < scalar(@owners) &&
(0 == scalar(@truncateOwnerTableLevels) ||
grep(/$callback_type/, @truncateOwnerTableLevels))
) {
# don't truncate the 'primary' key owner table
$truncated = (scalar(@owners) - $ownerTableElements);
#lcovutil::info("truncating $truncated elements in header table\n");
splice(@owners, $ownerTableElements);
} else {
$truncated = 0;
}
return (scalar(@owners) ? \@owners : undef, $truncated);
}
sub append
{
my ($self, $record) = @_;
# keep track of the records that get merged into me..
defined($record->[NAME]) or
die("attempt to anonymous SummaryInfo record");
!exists($self->[SOURCES]->{$record->[NAME]}) or
die("duplicate merge record " . $record->[NAME]);
$self->[SOURCES]->{$record->[NAME]} = $record;
die($record->name() . " already has parent " . $record->parent()->name())
if (defined($record->parent()) && $record->[PARENT] != $self);
$record->[PARENT] = $self
if !defined($record->parent());
foreach my $group (LINE_DATA, FUNCTION_DATA, BRANCH_DATA) {
my $mine = $self->[$group]->[DATA];
my $yours = $record->[$group]->[DATA];
while (my ($key, $value) = each(%$yours)) {
$mine->{$key} += $yours->{$key};
}
}
# there will be no date info if we didn't also collect owner data
# merge the date- and owner data, if if we aren't going to display it
# (In future, probably want to serialize the data for future processing)
if (%{$record->[LINE_DATA]->[OWNERS]}) {
foreach my $covType (LINE_DATA, FUNCTION_DATA, BRANCH_DATA) {
for (my $bin = 0; $bin <= $#ageGroupHeader; ++$bin) {
foreach my $key (keys %{$self->[$covType]->[DATA]}) {
# duplicate line-coverage buckets
my $ageval = $self->age_sample($bin);
if ($covType == LINE_DATA) {
$self->lineCovCount($key, "age", $ageval,
$record->lineCovCount($key, "age", $ageval));
} elsif ($covType == BRANCH_DATA) {
$self->branchCovCount($key, "age", $ageval,
$record->branchCovCount($key, "age", $ageval));
} else {
$self->functionCovCount($key, 'age', $ageval,
$record->functionCovCount($key, "age", $ageval));
}
}
}
my $ownerList = $self->[$covType]->[OWNERS];
while (my ($name, $yours) = each(%{$record->[$covType]->[OWNERS]}))
{
if (!exists($ownerList->{$name})) {
$ownerList->{$name} = {};
}
my $mine = $ownerList->{$name};
while (my ($tla, $count) = each(%$yours)) {
if (exists($mine->{$tla})) {
$mine->{$tla} += $count;
} else {
$mine->{$tla} = $count;
}
}
}
}
}
return $self;
}
sub age_sample
{
my ($self, $i) = @_;
my $bin = $self->[LINE_DATA]->[AGE]->[$i];
return ($i < $#ageGroupHeader) ? $bin->{_UB} : ($bin->{_LB} + 1);
}
sub lineCovCount
{
my ($self, $key, $group, $age, $delta) = @_;
$delta = 0 unless defined($delta);
if ($key eq 'missed') {
my $found = $self->lineCovCount('found', $group, $age);
my $hit = $self->lineCovCount('hit', $group, $age);
return $found - $hit;
}
if ($group eq "age") {
my $a = $self->[LINE_DATA]->[AGE];
my $bin = SummaryInfo::findAgeBin($age);
exists($a->[$bin]) && exists($a->[$bin]->{$key}) or
die("unexpected key '$key' for bin '$bin'");
$a->[$bin]->{$key} += $delta;
return $a->[$bin]->{$key};
}
my $d = $self->[$group]->[DATA];
defined($d) or
die("SummaryInfo::value: unrecognized group $group\n");
defined($d->{$key}) or
die("SummaryInfo::value: unrecognized key $key\n");
$d->{$key} += $delta;
return $d->{$key};
}
sub branchCovCount
{
my ($self, $key, $group, $age, $delta) = @_;