Skip to content

Commit 9a4d674

Browse files
committed
Additional gcda/gcno file existence checking - better
diagnostic for broken links or missing files. Signed-off-by: Henry Cox <henry.cox@mediatek.com>
1 parent 8124d12 commit 9a4d674

File tree

3 files changed

+71
-26
lines changed

3 files changed

+71
-26
lines changed

bin/geninfo

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,10 @@ if (0 == $exit_code) {
575575
$exit_code = 1;
576576
}
577577
}
578+
# $trace_data may be undef if no non-empty GCDA files found and the
579+
# 'empty' warning is ignored
578580
if (0 == $exit_code &&
581+
defined($trace_data) &&
579582
$single_file) {
580583

581584
$trace_data->checkCoverageCriteria();
@@ -595,7 +598,8 @@ lcovutil::save_profile(
595598
# exit with non-zero status if --keep-going and some errors detected
596599
$exit_code = 1
597600
if (0 == $exit_code &&
598-
lcovutil::saw_error());
601+
(!(defined($trace_data) && $single_file) ||
602+
lcovutil::saw_error()));
599603
exit($exit_code);
600604

601605
#
@@ -2783,6 +2787,7 @@ sub process_intermediate($$$$)
27832787
my ($fdir, $fbase, $fext);
27842788
my $data_file;
27852789
my $errmsg;
2790+
my $errorType = $lcovutil::ERROR_GCOV;
27862791
my %data;
27872792
my $fd;
27882793
my $base;
@@ -2802,34 +2807,38 @@ sub process_intermediate($$$$)
28022807
$data_file =
28032808
File::Spec->catfile($tempdir, "$fbase$graph_file_extension");
28042809
if (!copy($file, $data_file)) {
2805-
$errmsg = "ERROR: Could not copy file $file: $!";
2810+
$errmsg = "ERROR: Could not copy file $file: $!";
2811+
$errorType = $lcovutil::ERROR_PATH;
28062812
goto err;
28072813
}
28082814
} else {
2815+
$gcno_file = solve_relative_path($cwd, $gcno_file);
2816+
foreach my $f ($file, $gcno_file) {
2817+
my $p = -l $f ? Cwd::abs_path($f) : $f;
2818+
if (!-r $p) {
2819+
$errmsg = "$f does not exist/is not readable";
2820+
$errorType = $lcovutil::ERROR_PATH;
2821+
goto err;
2822+
}
2823+
}
28092824
# if .gcda and .gcno files are in the same directory, then simply
28102825
# process in place - otherwise, link the .gcda and .gcno files
28112826
# into tempdir and run from here
2812-
if (dirname($filename) eq dirname($gcno_file)) {
2827+
if (dirname($file) eq dirname($gcno_file)) {
28132828
# Process data file in place
28142829
$data_file = $file;
28152830
} else {
28162831
$data_file = basename($file);
2817-
my $gcda = File::Spec->catfile($tempdir, $data_file);
2818-
debug("create links to process $filename in $tempdir\n");
2819-
symlink($file, $gcda);
2820-
# unclear why symlink returns an error code when it actually
2821-
# created the link
2822-
if ($? && !-l $gcda) {
2823-
$errmsg = "unable to create link $data_file: $!";
2824-
goto err;
2825-
}
2826-
# and the gcno file
2827-
my $g = solve_relative_path($cwd, $gcno_file);
2828-
my $gcno = File::Spec->catfile($tempdir, basename($gcno_file));
2829-
symlink($g, $gcno);
2830-
if ($? && !-l $gcda) {
2831-
$errmsg = "unable to create link $gcno: $!";
2832-
goto err;
2832+
foreach my $f ($file, $gcno_file) {
2833+
my $l = File::Spec->catfile($tempdir, basename($f));
2834+
debug("create links to process $f in $tempdir\n");
2835+
symlink($f, $l);
2836+
# unclear why symlink returns an error code when it actually
2837+
# created the link
2838+
if ($? && !-l $l) {
2839+
$errmsg = "unable to create link for $f: $!";
2840+
goto err;
2841+
}
28332842
}
28342843
}
28352844
}
@@ -2863,8 +2872,6 @@ sub process_intermediate($$$$)
28632872
if (check_gcov_fail($err, $file)) {
28642873
return;
28652874
}
2866-
}
2867-
if ($rc) {
28682875
$errmsg = "GCOV failed for $file";
28692876
goto err;
28702877
}
@@ -2940,7 +2947,7 @@ sub process_intermediate($$$$)
29402947
return $trace;
29412948

29422949
err:
2943-
ignorable_error($ERROR_GCOV, "$errmsg!");
2950+
ignorable_error($errorType, "$errmsg!");
29442951
return undef;
29452952
}
29462953

scripts/spreadsheet.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def insertStats(keys, sawData, sumRow, avgRow, devRow, beginRow, endRow, col):
141141
continue
142142
if key not in sawData:
143143
continue
144-
144+
145145
f = xl_rowcol_to_cell(beginRow, col)
146146
t = xl_rowcol_to_cell(endRow, col)
147147

@@ -475,8 +475,12 @@ def cmpFile(a, b):
475475
else:
476476
return 0 if idA == idB else -1
477477

478-
row = dataSection('files', sorted(data['file'].keys(), key=cmp_to_key(cmpFile)),
479-
geninfoKeys, fileDataRow, fileStatsRow)
478+
try:
479+
row = dataSection('files', sorted(data['file'].keys(), key=cmp_to_key(cmpFile)),
480+
geninfoKeys, fileDataRow, fileStatsRow)
481+
except:
482+
# there may be no files - if dataset was empty
483+
print("No 'file' data in %s" % (name))
480484

481485
# now the filter data - if any
482486
if args.show_filter:

tests/lcov/extract/extract.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ if [ "${VER[0]}" -lt 5 ] ; then
107107
FILTER='--filter branch'
108108
fi
109109
110-
rm -rf *.gcda *.gcno a.out *.info* *.txt* *.json dumper* testRC *.gcov *.gcov.* *.log *.o
110+
rm -rf *.gcda *.gcno a.out *.info* *.txt* *.json dumper* testRC *.gcov *.gcov.* *.log *.o errs
111111
rm -rf rcOptBug
112112
113113
if [ -d separate ] ; then
@@ -231,6 +231,7 @@ if [ 0 != $? ] ; then
231231
fi
232232
fi
233233
234+
234235
echo $COVER $LCOV_TOOL $LCOV_OPTS -o aggregata.info -a callback.info $FILTER $IGNORE --criteria $SCRIPTS/threshold.pm,--line,90,--branch,65,--function,100
235236
$COVER $LCOV_TOOL $LCOV_OPTS -o aggregata.info -a callback.info $FILTER $IGNORE --criteria $SCRIPTS/threshold.pm,--line,90,--branch,65,--function,100 2>&1 | tee callback_fail2.log
236237
if [ 0 == ${PIPESTATUS[0]} ] ; then
@@ -840,6 +841,39 @@ if [ 0 != $? ] ; then
840841
fi
841842
fi
842843
844+
# try to produce some errors that were hit by user :-(
845+
mkdir -p errs
846+
rm -f errs/*
847+
( cd errs ; ln -s ../extract.gcda ; ln -s ../missing.gcno extract.gcno )
848+
$COVER $CAPTURE errs $LCOV_OPTS -o err1.info $FILTER $IGNORE
849+
if [ 0 == $? ] ; then
850+
echo "Error: expected error code from lcov --capture"
851+
if [ $KEEP_GOING == 0 ] ; then
852+
exit 1
853+
fi
854+
fi
855+
$COVER $CAPTURE errs $LCOV_OPTS -o err2.info $FILTER $IGNORE --initial
856+
if [ 0 == $? ] ; then
857+
echo "Error: expected error code from lcov --capture --initial"
858+
if [ $KEEP_GOING == 0 ] ; then
859+
exit 1
860+
fi
861+
fi
862+
$COVER $CAPTURE errs $LCOV_OPTS -o err3.info $FILTER $IGNORE --initial --ignore path
863+
if [ 0 == $? ] ; then
864+
echo "Error: expected error code from lcov --capture --initial --ignore"
865+
if [ $KEEP_GOING == 0 ] ; then
866+
exit 1
867+
fi
868+
fi
869+
$COVER $CAPTURE errs $LCOV_OPTS -o err4.info $FILTER $IGNORE --initial --keep-going
870+
if [ 0 == $? ] ; then
871+
echo "Error: expected error code from lcov --capture --initial --keep-going"
872+
if [ $KEEP_GOING == 0 ] ; then
873+
exit 1
874+
fi
875+
fi
876+
843877
844878
echo "Tests passed"
845879

0 commit comments

Comments
 (0)