forked from valbok/lcov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcov.perl
4327 lines (3787 loc) · 114 KB
/
lcov.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/perl -w
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# lcov
#
# This is a wrapper script which provides a single interface for accessing
# LCOV coverage data.
#
#
# History:
# 2002-08-29 created by Peter Oberparleiter <[email protected]>
# IBM Lab Boeblingen
# 2002-09-05 / Peter Oberparleiter: implemented --kernel-directory +
# multiple directories
# 2002-10-16 / Peter Oberparleiter: implemented --add-tracefile option
# 2002-10-17 / Peter Oberparleiter: implemented --extract option
# 2002-11-04 / Peter Oberparleiter: implemented --list option
# 2003-03-07 / Paul Larson: Changed to make it work with the latest gcov
# kernel patch. This will break it with older gcov-kernel
# patches unless you change the value of $gcovmod in this script
# 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 Paul's change so that LCOV
# works both with the new and the old gcov-kernel patch
# 2003-04-10 / Peter Oberparleiter: added $gcov_dir constant in anticipation
# of a possible move of the gcov kernel directory to another
# file system in a future version of the gcov-kernel patch
# 2003-04-15 / Paul Larson: make info write to STDERR, not STDOUT
# 2003-04-15 / Paul Larson: added --remove option
# 2003-04-30 / Peter Oberparleiter: renamed --reset to --zerocounters
# to remove naming ambiguity with --remove
# 2003-04-30 / Peter Oberparleiter: adjusted help text to include --remove
# 2003-06-27 / Peter Oberparleiter: implemented --diff
# 2003-07-03 / Peter Oberparleiter: added line checksum support, added
# --no-checksum
# 2003-12-11 / Laurent Deniel: added --follow option
# 2004-03-29 / Peter Oberparleiter: modified --diff option to better cope with
# ambiguous patch file entries, modified --capture option to use
# modprobe before insmod (needed for 2.6)
# 2004-03-30 / Peter Oberparleiter: added --path option
# 2004-08-09 / Peter Oberparleiter: added configuration file support
# 2008-08-13 / Peter Oberparleiter: added function coverage support
# 2014-09-12 / VaL Doroshchuk: ported to Windows
#
use strict;
use File::Basename;
use File::Path;
use File::Find;
use File::Temp qw /tempdir/;
use File::Spec::Functions qw /abs2rel canonpath catdir catfile catpath
file_name_is_absolute rootdir splitdir splitpath/;
use Getopt::Long;
use Cwd qw /abs_path getcwd/;
# Global constants
our $lcov_version = 'LCOV version 1.11';
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
our $tool_name = basename($0);
# Directory containing gcov kernel files
our $gcov_dir;
# Where to create temporary directories
our $tmp_dir;
# Internal constants
our $GKV_PROC = 0; # gcov-kernel data in /proc via external patch
our $GKV_SYS = 1; # gcov-kernel data in /sys via vanilla 2.6.31+
our @GKV_NAME = ( "external", "upstream" );
our $pkg_gkv_file = ".gcov_kernel_version";
our $pkg_build_file = ".build_directory";
our $BR_BLOCK = 0;
our $BR_BRANCH = 1;
our $BR_TAKEN = 2;
our $BR_VEC_ENTRIES = 3;
our $BR_VEC_WIDTH = 32;
our $BR_VEC_MAX = vec(pack('b*', 1 x $BR_VEC_WIDTH), 0, $BR_VEC_WIDTH);
# Branch data combination types
our $BR_SUB = 0;
our $BR_ADD = 1;
# Prototypes
sub print_usage(*);
sub check_options();
sub userspace_reset();
sub userspace_capture();
sub kernel_reset();
sub kernel_capture();
sub kernel_capture_initial();
sub package_capture();
sub add_traces();
sub read_info_file($);
sub get_info_entry($);
sub set_info_entry($$$$$$$$$;$$$$$$);
sub add_counts($$);
sub merge_checksums($$$);
sub combine_info_entries($$$);
sub combine_info_files($$);
sub write_info_file(*$);
sub extract();
sub remove();
sub list();
sub get_common_filename($$);
sub read_diff($);
sub diff();
sub system_no_output($@);
sub read_config($);
sub apply_config($);
sub info(@);
sub create_temp_dir();
sub transform_pattern($);
sub warn_handler($);
sub die_handler($);
sub abort_handler($);
sub temp_cleanup();
sub setup_gkv();
sub get_overall_line($$$$);
sub print_overall_rate($$$$$$$$$);
sub lcov_geninfo(@);
sub create_package($$$;$);
sub get_func_found_and_hit($);
sub br_ivec_get($$);
sub summary();
sub rate($$;$$$);
# Global variables & initialization
our @directory; # Specifies where to get coverage data from
our @kernel_directory; # If set, captures only from specified kernel subdirs
our @add_tracefile; # If set, reads in and combines all files in list
our $list; # If set, list contents of tracefile
our $extract; # If set, extracts parts of tracefile
our $remove; # If set, removes parts of tracefile
our $diff; # If set, modifies tracefile according to diff
our $reset; # If set, reset all coverage data to zero
our $capture; # If set, capture data
our $output_filename; # Name for file to write coverage data to
our $test_name = ""; # Test case name
our $quiet = ""; # If set, suppress information messages
our $help; # Help option flag
our $version; # Version option flag
our $convert_filenames; # If set, convert filenames when applying diff
our $strip; # If set, strip leading directories when applying diff
our $temp_dir_name; # Name of temporary directory
our $cwd = `pwd`; # Current working directory
our $to_file; # If set, indicates that output is written to a file
our $follow; # If set, indicates that find shall follow links
our $diff_path = ""; # Path removed from tracefile when applying diff
our $base_directory; # Base directory (cwd of gcc during compilation)
our $checksum; # If set, calculate a checksum for each line
our $no_checksum; # If set, don't calculate a checksum for each line
our $compat_libtool; # If set, indicates that libtool mode is to be enabled
our $no_compat_libtool; # If set, indicates that libtool mode is to be disabled
our $gcov_tool;
our @opt_ignore_errors;
our $initial;
our $no_recursion = 0;
our $to_package;
our $from_package;
our $maxdepth;
our $no_markers;
our $config; # Configuration file contents
chomp($cwd);
our $tool_dir = dirname($0); # Directory where genhtml tool is installed
our @temp_dirs;
our $gcov_gkv; # gcov kernel support version found on machine
our $opt_derive_func_data;
our $opt_debug;
our $opt_list_full_path;
our $opt_no_list_full_path;
our $opt_list_width = 80;
our $opt_list_truncate_max = 20;
our $opt_external;
our $opt_no_external;
our $opt_config_file;
our %opt_rc;
our @opt_summary;
our $opt_compat;
our $ln_overall_found;
our $ln_overall_hit;
our $fn_overall_found;
our $fn_overall_hit;
our $br_overall_found;
our $br_overall_hit;
our $func_coverage = 1;
our $br_coverage = 0;
#
# Code entry point
#
$SIG{__WARN__} = \&warn_handler;
$SIG{__DIE__} = \&die_handler;
$SIG{'INT'} = \&abort_handler;
$SIG{'QUIT'} = \&abort_handler;
# Prettify version string
$lcov_version =~ s/\$\s*Revision\s*:?\s*(\S+)\s*\$/$1/;
# Add current working directory if $tool_dir is not already an absolute path
if (!($tool_dir =~ /^\/(.*)$/) && !($tool_dir =~ /[a-zA-Z]:\\/))
{
$tool_dir = "$cwd/$tool_dir";
}
# 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
while (my ($key, $value) = each(%opt_rc)) {
delete($opt_rc{$key});
$key =~ s/^\s+|\s+$//g;
$value =~ s/^\s+|\s+$//g;
$opt_rc{$key} = $value;
}
# 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");
}
if ($config || %opt_rc)
{
# Copy configuration file and --rc values to variables
apply_config({
"lcov_gcov_dir" => \$gcov_dir,
"lcov_tmp_dir" => \$tmp_dir,
"lcov_list_full_path" => \$opt_list_full_path,
"lcov_list_width" => \$opt_list_width,
"lcov_list_truncate_max"=> \$opt_list_truncate_max,
"lcov_branch_coverage" => \$br_coverage,
"lcov_function_coverage"=> \$func_coverage,
});
}
# Parse command line options
if (!GetOptions("directory|d|di=s" => \@directory,
"add-tracefile|a=s" => \@add_tracefile,
"list|l=s" => \$list,
"kernel-directory|k=s" => \@kernel_directory,
"extract|e=s" => \$extract,
"remove|r=s" => \$remove,
"diff=s" => \$diff,
"convert-filenames" => \$convert_filenames,
"strip=i" => \$strip,
"capture|c" => \$capture,
"output-file|o=s" => \$output_filename,
"test-name|t=s" => \$test_name,
"zerocounters|z" => \$reset,
"quiet|q" => \$quiet,
"help|h|?" => \$help,
"version|v" => \$version,
"follow|f" => \$follow,
"path=s" => \$diff_path,
"base-directory|b=s" => \$base_directory,
"checksum" => \$checksum,
"no-checksum" => \$no_checksum,
"compat-libtool" => \$compat_libtool,
"no-compat-libtool" => \$no_compat_libtool,
"gcov-tool=s" => \$gcov_tool,
"ignore-errors=s" => \@opt_ignore_errors,
"initial|i" => \$initial,
"no-recursion" => \$no_recursion,
"to-package=s" => \$to_package,
"from-package=s" => \$from_package,
"no-markers" => \$no_markers,
"derive-func-data" => \$opt_derive_func_data,
"debug" => \$opt_debug,
"list-full-path" => \$opt_list_full_path,
"no-list-full-path" => \$opt_no_list_full_path,
"external" => \$opt_external,
"no-external" => \$opt_no_external,
"summary=s" => \@opt_summary,
"compat=s" => \$opt_compat,
"config-file=s" => \$opt_config_file,
"rc=s%" => \%opt_rc,
))
{
print(STDERR "Use $tool_name --help to get usage information\n");
exit(1);
}
else
{
# Merge options
if (defined($no_checksum))
{
$checksum = ($no_checksum ? 0 : 1);
$no_checksum = undef;
}
if (defined($no_compat_libtool))
{
$compat_libtool = ($no_compat_libtool ? 0 : 1);
$no_compat_libtool = undef;
}
if (defined($opt_no_list_full_path))
{
$opt_list_full_path = ($opt_no_list_full_path ? 0 : 1);
$opt_no_list_full_path = undef;
}
if (defined($opt_no_external)) {
$opt_external = 0;
$opt_no_external = undef;
}
}
# 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);
}
# Check list width option
if ($opt_list_width <= 40) {
die("ERROR: lcov_list_width parameter out of range (needs to be ".
"larger than 40)\n");
}
# Normalize --path text
$diff_path =~ s/\/$//;
if ($follow)
{
$follow = "-follow";
}
else
{
$follow = "";
}
if ($no_recursion)
{
$maxdepth = "-maxdepth 1";
}
else
{
$maxdepth = "";
}
# Check for valid options
check_options();
# Only --extract, --remove and --diff allow unnamed parameters
if (@ARGV && !($extract || $remove || $diff || @opt_summary))
{
die("Extra parameter found: '".join(" ", @ARGV)."'\n".
"Use $tool_name --help to get usage information\n");
}
# Check for output filename
$to_file = ($output_filename && ($output_filename ne "-"));
if ($capture)
{
if (!$to_file)
{
# Option that tells geninfo to write to stdout
$output_filename = "-";
}
}
# Determine kernel directory for gcov data
if (!$from_package && !@directory && ($capture || $reset)) {
($gcov_gkv, $gcov_dir) = setup_gkv();
}
# Check for requested functionality
if ($reset)
{
# Differentiate between user space and kernel reset
if (@directory)
{
userspace_reset();
}
else
{
kernel_reset();
}
}
elsif ($capture)
{
# Capture source can be user space, kernel or package
if ($from_package) {
package_capture();
} elsif (@directory) {
userspace_capture();
} else {
if ($initial) {
if (defined($to_package)) {
die("ERROR: --initial cannot be used together ".
"with --to-package\n");
}
kernel_capture_initial();
} else {
kernel_capture();
}
}
}
elsif (@add_tracefile)
{
($ln_overall_found, $ln_overall_hit,
$fn_overall_found, $fn_overall_hit,
$br_overall_found, $br_overall_hit) = add_traces();
}
elsif ($remove)
{
($ln_overall_found, $ln_overall_hit,
$fn_overall_found, $fn_overall_hit,
$br_overall_found, $br_overall_hit) = remove();
}
elsif ($extract)
{
($ln_overall_found, $ln_overall_hit,
$fn_overall_found, $fn_overall_hit,
$br_overall_found, $br_overall_hit) = extract();
}
elsif ($list)
{
list();
}
elsif ($diff)
{
if (scalar(@ARGV) != 1)
{
die("ERROR: option --diff requires one additional argument!\n".
"Use $tool_name --help to get usage information\n");
}
($ln_overall_found, $ln_overall_hit,
$fn_overall_found, $fn_overall_hit,
$br_overall_found, $br_overall_hit) = diff();
}
elsif (@opt_summary)
{
($ln_overall_found, $ln_overall_hit,
$fn_overall_found, $fn_overall_hit,
$br_overall_found, $br_overall_hit) = summary();
}
temp_cleanup();
if (defined($ln_overall_found)) {
print_overall_rate(1, $ln_overall_found, $ln_overall_hit,
1, $fn_overall_found, $fn_overall_hit,
1, $br_overall_found, $br_overall_hit);
} else {
info("Done.\n") if (!$list && !$capture);
}
exit(0);
#
# print_usage(handle)
#
# Print usage information.
#
sub print_usage(*)
{
local *HANDLE = $_[0];
print(HANDLE <<END_OF_USAGE);
Usage: $tool_name [OPTIONS]
Use lcov to collect coverage data from either the currently running Linux
kernel or from a user space application. Specify the --directory option to
get coverage data for a user space program.
Misc:
-h, --help Print this help, then exit
-v, --version Print version number, then exit
-q, --quiet Do not print progress messages
Operation:
-z, --zerocounters Reset all execution counts to zero
-c, --capture Capture coverage data
-a, --add-tracefile FILE Add contents of tracefiles
-e, --extract FILE PATTERN Extract files matching PATTERN from FILE
-r, --remove FILE PATTERN Remove files matching PATTERN from FILE
-l, --list FILE List contents of tracefile FILE
--diff FILE DIFF Transform tracefile FILE according to DIFF
--summary FILE Show summary coverage data for tracefiles
Options:
-i, --initial Capture initial zero coverage data
-t, --test-name NAME Specify test name to be stored with data
-o, --output-file FILENAME Write data to FILENAME instead of stdout
-d, --directory DIR Use .da files in DIR instead of kernel
-f, --follow Follow links when searching .da files
-k, --kernel-directory KDIR Capture kernel coverage data only from KDIR
-b, --base-directory DIR Use DIR as base directory for relative paths
--convert-filenames Convert filenames when applying diff
--strip DEPTH Strip initial DEPTH directory levels in diff
--path PATH Strip PATH from tracefile when applying diff
--(no-)checksum Enable (disable) line checksumming
--(no-)compat-libtool Enable (disable) libtool compatibility mode
--gcov-tool TOOL Specify gcov tool location
--ignore-errors ERRORS Continue after ERRORS (gcov, source, graph)
--no-recursion Exclude subdirectories from processing
--to-package FILENAME Store unprocessed coverage data in FILENAME
--from-package FILENAME Capture from unprocessed data in FILENAME
--no-markers Ignore exclusion markers in source code
--derive-func-data Generate function data from line data
--list-full-path Print full path during a list operation
--(no-)external Include (ignore) data for external files
--config-file FILENAME Specify configuration file location
--rc SETTING=VALUE Override configuration file setting
--compat MODE=on|off|auto Set compat MODE (libtool, hammer, split_crc)
For more information see: $lcov_url
END_OF_USAGE
;
}
#
# check_options()
#
# Check for valid combination of command line options. Die on error.
#
sub check_options()
{
my $i = 0;
# Count occurrence of mutually exclusive options
$reset && $i++;
$capture && $i++;
@add_tracefile && $i++;
$extract && $i++;
$remove && $i++;
$list && $i++;
$diff && $i++;
@opt_summary && $i++;
if ($i == 0)
{
die("Need one of options -z, -c, -a, -e, -r, -l, ".
"--diff or --summary\n".
"Use $tool_name --help to get usage information\n");
}
elsif ($i > 1)
{
die("ERROR: only one of -z, -c, -a, -e, -r, -l, ".
"--diff or --summary allowed!\n".
"Use $tool_name --help to get usage information\n");
}
}
#
# userspace_reset()
#
# Reset coverage data found in DIRECTORY by deleting all contained .da files.
#
# Die on error.
#
sub userspace_reset()
{
my $current_dir;
my @file_list;
foreach $current_dir (@directory)
{
info("Deleting all .da files in $current_dir".
($no_recursion?"\n":" and subdirectories\n"));
@file_list = `find "$current_dir" $maxdepth $follow -name \\*\\.da -o -name \\*\\.gcda -type f 2>/dev/null`;
chomp(@file_list);
foreach (@file_list)
{
unlink($_) or die("ERROR: cannot remove file $_!\n");
}
}
}
#
# userspace_capture()
#
# Capture coverage data found in DIRECTORY and write it to a package (if
# TO_PACKAGE specified) or to OUTPUT_FILENAME or STDOUT.
#
# Die on error.
#
sub userspace_capture()
{
my $dir;
my $build;
if (!defined($to_package)) {
lcov_geninfo(@directory);
return;
}
if (scalar(@directory) != 1) {
die("ERROR: -d may be specified only once with --to-package\n");
}
$dir = $directory[0];
if (defined($base_directory)) {
$build = $base_directory;
} else {
$build = $dir;
}
create_package($to_package, $dir, $build);
}
#
# kernel_reset()
#
# Reset kernel coverage.
#
# Die on error.
#
sub kernel_reset()
{
local *HANDLE;
my $reset_file;
info("Resetting kernel execution counters\n");
if (-e "$gcov_dir/vmlinux") {
$reset_file = "$gcov_dir/vmlinux";
} elsif (-e "$gcov_dir/reset") {
$reset_file = "$gcov_dir/reset";
} else {
die("ERROR: no reset control found in $gcov_dir\n");
}
open(HANDLE, ">", $reset_file) or
die("ERROR: cannot write to $reset_file!\n");
print(HANDLE "0");
close(HANDLE);
}
#
# lcov_copy_single(from, to)
#
# Copy single regular file FROM to TO without checking its size. This is
# required to work with special files generated by the kernel
# seq_file-interface.
#
#
sub lcov_copy_single($$)
{
my ($from, $to) = @_;
my $content;
local $/;
local *HANDLE;
open(HANDLE, "<", $from) or die("ERROR: cannot read $from: $!\n");
$content = <HANDLE>;
close(HANDLE);
open(HANDLE, ">", $to) or die("ERROR: cannot write $from: $!\n");
if (defined($content)) {
print(HANDLE $content);
}
close(HANDLE);
}
#
# lcov_find(dir, function, data[, extension, ...)])
#
# Search DIR for files and directories whose name matches PATTERN and run
# FUNCTION for each match. If not pattern is specified, match all names.
#
# FUNCTION has the following prototype:
# function(dir, relative_name, data)
#
# Where:
# dir: the base directory for this search
# relative_name: the name relative to the base directory of this entry
# data: the DATA variable passed to lcov_find
#
sub lcov_find($$$;@)
{
my ($dir, $fn, $data, @pattern) = @_;
my $result;
my $_fn = sub {
my $filename = $File::Find::name;
if (defined($result)) {
return;
}
$filename = abs2rel($filename, $dir);
foreach (@pattern) {
if ($filename =~ /$_/) {
goto ok;
}
}
return;
ok:
$result = &$fn($dir, $filename, $data);
};
if (scalar(@pattern) == 0) {
@pattern = ".*";
}
find( { wanted => $_fn, no_chdir => 1 }, $dir);
return $result;
}
#
# lcov_copy_fn(from, rel, to)
#
# Copy directories, files and links from/rel to to/rel.
#
sub lcov_copy_fn($$$)
{
my ($from, $rel, $to) = @_;
my $absfrom = canonpath(catfile($from, $rel));
my $absto = canonpath(catfile($to, $rel));
if (-d) {
if (! -d $absto) {
mkpath($absto) or
die("ERROR: cannot create directory $absto\n");
chmod(0700, $absto);
}
} elsif (-l) {
# Copy symbolic link
my $link = readlink($absfrom);
if (!defined($link)) {
die("ERROR: cannot read link $absfrom: $!\n");
}
symlink($link, $absto) or
die("ERROR: cannot create link $absto: $!\n");
} else {
lcov_copy_single($absfrom, $absto);
chmod(0600, $absto);
}
return undef;
}
#
# lcov_copy(from, to, subdirs)
#
# Copy all specified SUBDIRS and files from directory FROM to directory TO. For
# regular files, copy file contents without checking its size. This is required
# to work with seq_file-generated files.
#
sub lcov_copy($$;@)
{
my ($from, $to, @subdirs) = @_;
my @pattern;
foreach (@subdirs) {
push(@pattern, "^$_");
}
lcov_find($from, \&lcov_copy_fn, $to, @pattern);
}
#
# lcov_geninfo(directory)
#
# Call geninfo for the specified directory and with the parameters specified
# at the command line.
#
sub lcov_geninfo(@)
{
my (@dir) = @_;
my @param;
# Capture data
info("Capturing coverage data from ".join(" ", @dir)."\n");
# FR changed path from "$tool_dir/geninfo"
@param = ("$tool_dir/geninfo.perl", @dir);
if ($output_filename)
{
@param = (@param, "--output-filename", $output_filename);
}
if ($test_name)
{
@param = (@param, "--test-name", $test_name);
}
if ($follow)
{
@param = (@param, "--follow");
}
if ($quiet)
{
@param = (@param, "--quiet");
}
if (defined($checksum))
{
if ($checksum)
{
@param = (@param, "--checksum");
}
else
{
@param = (@param, "--no-checksum");
}
}
if ($base_directory)
{
@param = (@param, "--base-directory", $base_directory);
}
if ($no_compat_libtool)
{
@param = (@param, "--no-compat-libtool");
}
elsif ($compat_libtool)
{
@param = (@param, "--compat-libtool");
}
if ($gcov_tool)
{
@param = (@param, "--gcov-tool", $gcov_tool);
}
foreach (@opt_ignore_errors) {
@param = (@param, "--ignore-errors", $_);
}
if ($no_recursion) {
@param = (@param, "--no-recursion");
}
if ($initial)
{
@param = (@param, "--initial");
}
if ($no_markers)
{
@param = (@param, "--no-markers");
}
if ($opt_derive_func_data)
{
@param = (@param, "--derive-func-data");
}
if ($opt_debug)
{
@param = (@param, "--debug");
}
if (defined($opt_external) && $opt_external)
{
@param = (@param, "--external");
}
if (defined($opt_external) && !$opt_external)
{
@param = (@param, "--no-external");
}
if (defined($opt_compat)) {
@param = (@param, "--compat", $opt_compat);
}
if (%opt_rc) {
foreach my $key (keys(%opt_rc)) {
@param = (@param, "--rc", "$key=".$opt_rc{$key});
}
}
if (defined($opt_config_file)) {
@param = (@param, "--config-file", $opt_config_file);
}
printf "@param";
system(@param) and exit($? >> 8);
}
#
# read_file(filename)
#
# Return the contents of the file defined by filename.
#
sub read_file($)
{
my ($filename) = @_;
my $content;
local $\;
local *HANDLE;
open(HANDLE, "<", $filename) || return undef;
$content = <HANDLE>;
close(HANDLE);
return $content;
}
#
# get_package(package_file)
#
# Unpack unprocessed coverage data files from package_file to a temporary
# directory and return directory name, build directory and gcov kernel version
# as found in package.
#
sub get_package($)
{
my ($file) = @_;
my $dir = create_temp_dir();
my $gkv;
my $build;
my $cwd = getcwd();
my $count;
local *HANDLE;
info("Reading package $file:\n");
info(" data directory .......: $dir\n");
$file = abs_path($file);
chdir($dir);
open(HANDLE, "-|", "tar xvfz '$file' 2>/dev/null")
or die("ERROR: could not process package $file\n");
while (<HANDLE>) {
if (/\.da$/ || /\.gcda$/) {
$count++;
}
}
close(HANDLE);
$build = read_file("$dir/$pkg_build_file");
if (defined($build)) {
info(" build directory ......: $build\n");
}
$gkv = read_file("$dir/$pkg_gkv_file");
if (defined($gkv)) {
$gkv = int($gkv);
if ($gkv != $GKV_PROC && $gkv != $GKV_SYS) {
die("ERROR: unsupported gcov kernel version found ".
"($gkv)\n");
}
info(" content type .........: kernel data\n");
info(" gcov kernel version ..: %s\n", $GKV_NAME[$gkv]);
} else {
info(" content type .........: application data\n");
}
info(" data files ...........: $count\n");
chdir($cwd);
return ($dir, $build, $gkv);
}
#
# write_file(filename, $content)
#
# Create a file named filename and write the specified content to it.
#
sub write_file($$)
{
my ($filename, $content) = @_;
local *HANDLE;
open(HANDLE, ">", $filename) || return 0;
print(HANDLE $content);
close(HANDLE) || return 0;
return 1;
}
# count_package_data(filename)
#
# Count the number of coverage data files in the specified package file.
#
sub count_package_data($)
{
my ($filename) = @_;
local *HANDLE;