Skip to content

Commit d1f9d85

Browse files
committed
Add '--msg-log [filename]' option - to save error and warning
messages to another location - to simplify debugging. Signed-off-by: Henry Cox <henry.cox@mediatek.com>
1 parent 9a4d674 commit d1f9d85

File tree

10 files changed

+118
-17
lines changed

10 files changed

+118
-17
lines changed

README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-------------------------------------------------
22
- README file for the LTP GCOV extension (LCOV) -
3-
- Last changes: 2024-09-13
3+
- Last changes: 2024-10-03
44
-------------------------------------------------
55

66
Description
@@ -317,7 +317,7 @@ New features and capabilities fall into 7 major categories:
317317
ignored.
318318

319319
Related options:
320-
--ignore-error, --expect-message-count, --keep-going
320+
--ignore-error, --expect-message-count, --keep-going, --msg-log
321321

322322
c) Navigation and display:
323323

bin/genhtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6420,7 +6420,10 @@ my %genhtml_options = ("output-directory|o=s" => \$output_directory,
64206420
"suppress-aliases" => \$suppress_function_aliases,
64216421
'validate' => \$validateHTML,);
64226422
# Parse command line options
6423-
if (!lcovutil::parseOptions(\%genhtml_rc_opts, \%genhtml_options)) {
6423+
if (
6424+
!lcovutil::parseOptions(\%genhtml_rc_opts, \%genhtml_options,
6425+
\$output_directory)
6426+
) {
64246427
print(STDERR "Use $tool_name --help to get usage information\n");
64256428
exit(1);
64266429
}

bin/geninfo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ my %geninfo_opts = ("test-name|t=s" => \$test_name,
260260
"compat=s" => \$lcovutil::geninfo_opt_compat,);
261261

262262
# Parse command line options
263-
if (!lcovutil::parseOptions(\%lcovutil::geninfo_rc_opts, \%geninfo_opts)) {
263+
if (!lcovutil::parseOptions(\%lcovutil::geninfo_rc_opts, \%geninfo_opts,
264+
\$output_filename)) {
264265
print(STDERR "Use $tool_name --help to get usage information\n");
265266
exit(1);
266267
}

bin/lcov

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ my %lcov_options = ("directory|d|di=s" => \@directory,
244244
my %mergedRcOpts = (%lcov_rc_params, %lcovutil::geninfo_rc_opts);
245245

246246
# Parse command line options
247-
if (!lcovutil::parseOptions(\%mergedRcOpts, \%lcov_options)) {
247+
if (!lcovutil::parseOptions(\%mergedRcOpts, \%lcov_options, \$output_filename))
248+
{
248249
print(STDERR "Use $tool_name --help to get usage information\n");
249250
exit(1);
250251
}

lib/lcovutil.pm

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use Getopt::Long;
2121
use DateTime;
2222
use Config;
2323
use POSIX;
24+
use Fcntl qw(:flock SEEK_END);
2425

2526
our @ISA = qw(Exporter);
2627
our @EXPORT_OK = qw($tool_name $tool_dir $lcov_version $lcov_url $VERSION
@@ -102,6 +103,7 @@ our @ignore;
102103
our @message_count;
103104
our @expected_message_count;
104105
our %message_types;
106+
our $message_log;
105107
our $suppressAfter = 100; # stop warning after this number of messages
106108
our %ERROR_ID;
107109
our %ERROR_NAME;
@@ -595,7 +597,15 @@ sub _msg_handler
595597
$msg =~ s/^(error|warning):\s+//i;
596598
my $type = $error ? 'ERROR' : 'WARNING';
597599

598-
return "$tool_name: $type: $msg";
600+
my $txt = "$tool_name: $type: $msg";
601+
if ($message_log && 'GLOB' eq ref($message_log)) {
602+
flock($message_log, LOCK_EX);
603+
# don't bother to seek...assume modern O_APPEND semantics
604+
#seek($message_log, 0, SEEK_END);
605+
print $message_log $txt;
606+
flock($message_log, LOCK_UN);
607+
}
608+
return $txt;
599609
}
600610

601611
sub warn_handler($$)
@@ -1230,6 +1240,7 @@ our %argCommon = ("tempdir=s" => \$tempdirname,
12301240
"demangle-cpp:s" => \@lcovutil::cpp_demangle,
12311241
"ignore-errors=s" => \@opt_ignore_errors,
12321242
"expect-message-count=s" => \@opt_expected_message_counts,
1243+
'msg-log:s' => \$message_log,
12331244
"keep-going" => \$keepGoing,
12341245
"config-file=s" => \@unsupported_config,
12351246
"rc=s%" => \%unsupported_rc,
@@ -1429,7 +1440,7 @@ sub apply_rc_params($)
14291440

14301441
sub parseOptions
14311442
{
1432-
my ($rcOptions, $cmdLineOpts) = @_;
1443+
my ($rcOptions, $cmdLineOpts, $output_arg) = @_;
14331444

14341445
apply_rc_params($rcOptions);
14351446

@@ -1442,7 +1453,6 @@ sub parseOptions
14421453
die("'" . $d->[0] . "' option name cannot be abbreviated\n")
14431454
if ($d->[1]);
14441455
}
1445-
14461456
if ($help) {
14471457
main::print_usage(*STDOUT);
14481458
exit(0);
@@ -1452,6 +1462,19 @@ sub parseOptions
14521462
print("$tool_name: $lcov_version\n");
14531463
exit(0);
14541464
}
1465+
if (defined($message_log)) {
1466+
if (!$message_log) {
1467+
# base log file name on output arg (if specified) or tool name otherwise
1468+
$message_log = (
1469+
defined($$output_arg) ?
1470+
substr($$output_arg, 0, rindex($$output_arg, '.')) :
1471+
$tool_name) .
1472+
".msg";
1473+
}
1474+
open(LOG, ">", $message_log) or
1475+
die("unable to write message log '$message_log': $!");
1476+
$message_log = \*LOG;
1477+
}
14551478

14561479
lcovutil::init_verbose_flag($quiet);
14571480
# apply the RC file settings if no command line arg

man/genhtml.1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ genhtml \- Generate HTML view from LCOV coverage data files
8383
.RB [ \-\-demangle\-cpp
8484
.IR [ param ] ]
8585
.br
86+
.RB [ \-\-msg\-log
87+
.IR [ log_file_name ] ]
88+
.br
8689
.RB [ \-\-ignore\-errors
8790
.IR errors ]
8891
.br
@@ -2717,6 +2720,17 @@ parameter works. In that case, you callback will be executed as:
27172720
.I | demangle_param0 demangle_param1 ...
27182721
Note that the demangle tool is called as a pipe and is expected to read from stdin and write to stdout.
27192722

2723+
.RE
2724+
.B \-\-msg\-log
2725+
.I [ log_file_name ]
2726+
.br
2727+
.RS
2728+
Specify location to store error and warning messages (in addition to writing to STDERR).
2729+
If
2730+
.I log_file_name
2731+
is not specified, then default location is used.
2732+
.RE
2733+
27202734
.RE
27212735
.B \-\-ignore\-errors
27222736
.I errors

man/geninfo.1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ geninfo \- Generate tracefiles from GCOV coverage data files
5252
.RB [ \-\-memory
5353
.IR integer_num_Mb ]
5454
.br
55+
.RB [ \-\-msg\-log
56+
.IR [ log_file_name ] ]
57+
.br
5558
.RB [ \-\-ignore\-errors
5659
.IR errors ]
5760
.br
@@ -786,6 +789,16 @@ option
786789
.IR forget_testcase_names .
787790
.RE
788791

792+
.B \-\-msg\-log
793+
.I [ log_file_name ]
794+
.br
795+
.RS
796+
Specify location to store error and warning messages (in addition to writing to STDERR).
797+
If
798+
.I log_file_name
799+
is not specified, then default location is used.
800+
.RE
801+
789802
.B \-\-ignore\-errors
790803
.I errors
791804
.br

man/lcov.1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Capture coverage data tracefile (from compiler-generated data):
5353
.RB [ \-\-compat\-libtool ]
5454
.RB [ \-\-no\-compat\-libtool ]
5555
.br
56+
.RB [ \-\-msg\-log
57+
.IR [ log_file_name ] ]
58+
.br
5659
.RB [ \-\-ignore\-errors
5760
.IR errors ]
5861
.br
@@ -1276,6 +1279,16 @@ path of each source file.
12761279
If you specify a pattern which does not seem to be correctly applied - files that you expected to be included in the output do not appear - lcov will generate an error message of type 'unused'. See the \-\-ignore\-errors option for how to make lcov ignore the error or turn it into a warning.
12771280
.RE
12781281

1282+
.B \-\-msg\-log
1283+
.I [ log_file_name ]
1284+
.br
1285+
.RS
1286+
Specify location to store error and warning messages (in addition to writing to STDERR).
1287+
If
1288+
.I log_file_name
1289+
is not specified, then default location is used.
1290+
.RE
1291+
12791292
.B \-\-ignore\-errors
12801293
.I errors
12811294
.br

tests/gendiffcov/simple/script.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ DIFFCOV_OPTS="$DIFFCOV_NOFRAME_OPTS --frame"
133133
#DIFFCOV_OPTS="--function-coverage --branch-coverage --demangle-cpp --frame"
134134
#DIFFCOV_OPTS='--function-coverage --branch-coverage --demangle-cpp'
135135

136-
rm -f test.cpp *.gcno *.gcda a.out *.info *.info.gz diff.txt diff_r.txt diff_broken.txt *.log *.err *.json dumper* results.xlsx annotate.{cpp,exe} c d ./cover_db_py names.data linked.cpp linked_diff.txt
136+
rm -f test.cpp *.gcno *.gcda a.out *.info *.info.gz diff.txt diff_r.txt diff_broken.txt *.log *.err *.json dumper* results.xlsx annotate.{cpp,exe} c d ./cover_db_py names.data linked.cpp linked_diff.txt *.msg
137137
rm -rf ./baseline ./current ./differential* ./reverse ./diff_no_baseline ./no_baseline ./no_annotation ./no_owners differential_nobranch reverse_nobranch baseline-filter* noncode_differential* broken mismatchPath elidePath ./cover_db ./criteria* ./mismatched ./navigation differential_prop proportion ./annotate ./current-* ./current_prefix* select select2 html_report ./usage ./errOut ./noNames no_source linked linked_err linked_elide linked_dir failUnder expect_err expect
138138

139139
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
@@ -1606,16 +1606,25 @@ fi
16061606
grep -E "ERROR:.*count.*'usage' contraint .+ is not true" expect_err.log
16071607
16081608
# now skip the count message too
1609-
echo genhtml $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage,count --rc expect_message_count=usage:1
1610-
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage,count $IGNORE --rc expect_message_count=usage:1 2>&1 | tee expect.log
1609+
echo genhtml $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage,count --rc expect_message_count=usage:1 --msg-log
1610+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage,count $IGNORE --rc expect_message_count=usage:1 --msg-log 2>&1 | tee expect.log
16111611
if [ 0 != ${PIPESTATUS[0]} ] ; then
16121612
echo "ERROR: didn't skip expect count error"
16131613
status=1
16141614
if [ 0 == $KEEP_GOING ] ; then
16151615
exit 1
16161616
fi
16171617
fi
1618-
grep -E "WARNING:.*count.*'usage' contraint .+ is not true" expect_err.log
1618+
1619+
grep -E "WARNING:.*count.*'usage' contraint .+ is not true" expect.msg
1620+
if [ 0 == $? ] ; then
1621+
echo "ERROR: didn't find expected msg in log"
1622+
status=1
1623+
if [ 0 == $KEEP_GOING ] ; then
1624+
exit 1
1625+
fi
1626+
fi
1627+
16191628
16201629
16211630
echo $SPREADSHEET_TOOL -o results.xlsx `find . -name "*.json"`

tests/lcov/extract/extract.sh

Lines changed: 29 additions & 5 deletions
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 errs
110+
rm -rf *.gcda *.gcno a.out *.info* *.txt* *.json dumper* testRC *.gcov *.gcov.* *.log *.o errs *.msg
111111
rm -rf rcOptBug
112112

113113
if [ -d separate ] ; then
@@ -845,28 +845,52 @@ fi
845845
mkdir -p errs
846846
rm -f errs/*
847847
( cd errs ; ln -s ../extract.gcda ; ln -s ../missing.gcno extract.gcno )
848-
$COVER $CAPTURE errs $LCOV_OPTS -o err1.info $FILTER $IGNORE
848+
$COVER $CAPTURE errs $LCOV_OPTS -o err1.info $FILTER $IGNORE --msg-log
849849
if [ 0 == $? ] ; then
850850
echo "Error: expected error code from lcov --capture"
851851
if [ $KEEP_GOING == 0 ] ; then
852852
exit 1
853853
fi
854854
fi
855-
$COVER $CAPTURE errs $LCOV_OPTS -o err2.info $FILTER $IGNORE --initial
855+
grep ERROR: err1.msg
856+
if [ 0 != $? ] ; then
857+
echo "Error: expected error message not foune"
858+
if [ $KEEP_GOING == 0 ] ; then
859+
exit 1
860+
fi
861+
fi
862+
863+
$COVER $CAPTURE errs $LCOV_OPTS -o err2.info $FILTER $IGNORE --initial --msg-log
856864
if [ 0 == $? ] ; then
857865
echo "Error: expected error code from lcov --capture --initial"
858866
if [ $KEEP_GOING == 0 ] ; then
859867
exit 1
860868
fi
861869
fi
862-
$COVER $CAPTURE errs $LCOV_OPTS -o err3.info $FILTER $IGNORE --initial --ignore path
870+
grep ERROR: err2.msg
871+
if [ 0 != $? ] ; then
872+
echo "Error: expected error message 2 not foune"
873+
if [ $KEEP_GOING == 0 ] ; then
874+
exit 1
875+
fi
876+
fi
877+
878+
$COVER $CAPTURE errs $LCOV_OPTS -o err3.info $FILTER $IGNORE --initial --ignore path --msg-log err.3.msg
863879
if [ 0 == $? ] ; then
864880
echo "Error: expected error code from lcov --capture --initial --ignore"
865881
if [ $KEEP_GOING == 0 ] ; then
866882
exit 1
867883
fi
868884
fi
869-
$COVER $CAPTURE errs $LCOV_OPTS -o err4.info $FILTER $IGNORE --initial --keep-going
885+
grep ERROR: err.3.msg
886+
if [ 0 != $? ] ; then
887+
echo "Error: expected error message 3 not foune"
888+
if [ $KEEP_GOING == 0 ] ; then
889+
exit 1
890+
fi
891+
fi
892+
893+
$COVER $CAPTURE errs $LCOV_OPTS -o err4.info $FILTER $IGNORE --initial --keep-going --msg-log
870894
if [ 0 == $? ] ; then
871895
echo "Error: expected error code from lcov --capture --initial --keep-going"
872896
if [ $KEEP_GOING == 0 ] ; then

0 commit comments

Comments
 (0)