Skip to content

Commit ae2dbb4

Browse files
committed
Add 'spreadsheet.py' to coverage report.
Enable coverage collection for more tests/more test types. Feature to force parallel execution - even if there is only one task - to improve testability. Signed-off-by: Henry Cox <[email protected]>
1 parent afb0565 commit ae2dbb4

File tree

9 files changed

+88
-50
lines changed

9 files changed

+88
-50
lines changed

bin/geninfo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,10 @@ sub gen_info(@)
12561256
my $filelist = $builder->worklist();
12571257
my $total = scalar(@$filelist);
12581258
if (1 < $lcovutil::maxParallelism) {
1259-
my $floor = int($total / $lcovutil::maxParallelism);
1259+
my $floor =
1260+
$lcovutil::maxParallelism ?
1261+
(int($total / $lcovutil::maxParallelism)) :
1262+
1;
12601263
if (defined($defaultChunkSize)) {
12611264
if ($defaultChunkSize =~ /^(\d+)\s*(%?)$/) {
12621265
if (defined($2) && $2) {

lib/lcovutil.pm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6025,9 +6025,11 @@ sub _processFilterWorklist
60256025
my $parallel = $lcovutil::lcov_filter_parallel;
60266026
# not much point in parallel calculation if the number of files is small
60276027
my $workList = $fileList;
6028-
if ((exists($ENV{LCOV_FORCE_PARALLEL}) || scalar(@$fileList) > 50) &&
6029-
$parallel &&
6030-
1 < $lcovutil::maxParallelism) {
6028+
if (exists($ENV{LCOV_FORCE_PARALLEL}) ||
6029+
(scalar(@$fileList) > 50 &&
6030+
$parallel &&
6031+
1 < $lcovutil::maxParallelism)
6032+
) {
60316033

60326034
$parallel = $lcovutil::maxParallelism;
60336035

@@ -6049,14 +6051,17 @@ sub _processFilterWorklist
60496051

60506052
if (!defined($chunkSize)) {
60516053
$chunkSize =
6052-
int(0.8 * scalar(@$fileList) / $lcovutil::maxParallelism);
6054+
$maxParallelism ?
6055+
(int(0.8 * scalar(@$fileList) / $lcovutil::maxParallelism)) :
6056+
1;
60536057
if ($chunkSize > 100) {
60546058
$chunkSize = 100;
60556059
} elsif ($chunkSize < 2) {
60566060
$chunkSize = 1;
60576061
}
60586062
}
6059-
if ($chunkSize != 1) {
6063+
if ($chunkSize != 1 ||
6064+
exists($ENV{LCOV_FORCE_PARALLEL})) {
60606065
$workList = [];
60616066
my $idx = 0;
60626067
my $current = [];
@@ -6092,7 +6097,9 @@ sub _processFilterWorklist
60926097
"filter_datXXXX",
60936098
DIR => $lcovutil::tmp_dir,
60946099
CLEANUP => !defined($lcovutil::preserve_intermediates)
6095-
) if $parallel > 1;
6100+
)
6101+
if (exists($ENV{LCOV_FORCE_PARALLEL}) ||
6102+
$parallel > 1);
60966103

60976104
CHUNK: foreach my $d (@$workList) {
60986105
++$processedChunks;

tests/Makefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ TESTS := genhtml lcov gendiffcov py2lcov perl2lcov
2020
# ignore the potential 'empty glob pattern' error message and a
2121
# potential remote repo timestamp issue
2222
report:
23+
$(SPREADSHEET_TOOL) -o report.xlsx `find . -name "*.json"`
2324
if [ "x$(COVERAGE)" != 'x' ] ; then \
24-
cover ; \
25+
cover $(COVER_DB) ; \
2526
$(BINDIR)/perl2lcov -o perlcov.info $(COVER_DB) --version-script $(VERSION_SCRIPT) ; \
2627
if [ -f $(PYCOV_DB) ] ; then \
2728
$(BINDIR)/py2lcov -o pycov.info $(PYCOV_DB) --version-script $(VERSION_SCRIPT) ; \
2829
fi ; \
29-
$(BINDIR)/genhtml -o $(HTML_RPT) perlcov.info pycov.i* $(COVER_DB)/*.info --show-navigation --flat --branch --show-proportion --version-script $(VERSION_SCRIPT) --annotate-script $(ANNOTATE_SCRIPT) --ignore empty,inconsistent ; \
30+
$(BINDIR)/genhtml --parallel -o $(HTML_RPT) perlcov.info pycov.i* $(COVER_DB)/*.info --show-navigation --flat --branch --show-proportion --version-script $(VERSION_SCRIPT) --annotate-script $(ANNOTATE_SCRIPT) --ignore empty,inconsistent ; \
3031
echo "Wrote HTML report to ${HTML_RPT}" ; \
3132
fi
3233

3334
clean:
34-
rm -rf *.info *.counts test.log src
35-
ifeq ($(COVERAGE), 1)
36-
if [ "x$(COVER_DB)" != 'x' ] ; then rm -rf $(COVER_DB) ; fi
37-
if [ "x$(HTML_RPT)" != 'x' ] ; then rm -rf $(HTML_RPT) ; fi
38-
endif
35+
rm -rf *.info *.counts test.log src report.xlsx \
36+
$(COVER_DB) $(HTML_RPT) $(PYCOV_DB)

tests/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ This directory contains a number of regression tests for LCOV. To start it:
4343
variable:
4444
$ make [HTML_RPT=path/to/my/html] COVERAGE=1 ... test
4545

46+
- environment variables:
47+
48+
- LCOV_SHOW_LOCATION:
49+
if set, show location on die() or warn()
50+
51+
- LCOV_FORCE_PARALLEL:
52+
if set, force parallel processing, regardless of number of tasks -
53+
even if only one. This is useful for regression testing - to make
54+
sure that we cover both serial and parallel execution.
4655

4756
You can modify some aspects of testing by specifying additional parameters on
4857
`make` invocation:

tests/bin/test_run

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ while [ $# -gt 0 ] ; do
3535

3636
--coverage )
3737
COVER_DB=$1
38+
export PERL_COVER_ARGS="-MDevel::Cover=-db,$(COVER_DB),-coverage,statement,branch,condition,subroutine,-silent,1"
3839
shift
3940
OPTS="$OPTS $OPT $COVER_DB --keep-going"
4041
;;
@@ -47,6 +48,10 @@ while [ $# -gt 0 ] ; do
4748
esac
4849
done
4950

51+
if [[ "$SCRIPT" =~ '.pl' ]] ; then
52+
INVOKE_COVER="perl ${PERL_COVER_ARGS}"
53+
fi
54+
5055
TIME=$(type -P time 2>/dev/null)
5156
if [ ! -z "$TIME" ] ; then
5257
TIME="$TIME -v -o $TIMEFILE"
@@ -70,7 +75,7 @@ t_detail "COMMAND" "\"$SCRIPT $OPTS*\"" >>"$LOGFILE"
7075
t_detail "OUTPUT" "" >>"$LOGFILE"
7176

7277
# Run command
73-
$TIME bash -c "$SCRIPT $OPTS" 2>&1 | t_indent >>"$LOGFILE"
78+
$TIME bash -c "$INVOKE_COVER $SCRIPT $OPTS" 2>&1 | t_indent >>"$LOGFILE"
7479
RC=$?
7580

7681
# Evaluate output of time command

tests/common.mak

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ VERSION_SCRIPT=$(SCRIPTDIR)/getp4version
3737
endif
3838

3939
ifneq ($(COVER_DB),)
40-
EXEC_COVER := perl -MDevel::Cover=-db,$(COVER_DB),-coverage,statement,branch,condition,subroutine,-silent,1
40+
export PERL_COVER_ARGS := -MDevel::Cover=-db,$(COVER_DB),-coverage,statement,branch,condition,subroutine,-silent,1
41+
EXEC_COVER := perl ${PERL_COVER_ARGS}
4142
PYCOVER = COVERAGE_FILE=$(PYCOV_DB) coverage run --branch --append
4243
endif
4344

@@ -74,6 +75,7 @@ export GENHTML_TOOL := $(EXEC_COVER) $(BINDIR)/genhtml
7475
export GENINFO_TOOL := $(EXEC_COVER) $(BINDIR)/geninfo
7576
export PERL2LCOV_TOOL := $(EXEC_COVER) $(BINDIR)/perl2lcov
7677
export PY2LCOV_TOOL := $(PYCOVER) $(BINDIR)/py2lcov
78+
export SPREADSHEET_TOOL := $(PYCOVER) $(SCRIPTDIR)/spreadsheet.py
7779

7880
# Specify programs under test
7981
export PATH := $(BINDIR):$(TESTBINDIR):$(PATH)

tests/gendiffcov/filter/filter.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use lib "$ENV{LCOV_HOME}/lib/lcov"; # install testcase
99
use lcovutil;
1010

11+
lcovutil::parseOptions({},{});
12+
1113
foreach my $example (glob('expr*.c')) {
1214
print("checking conditional in $example\n");
1315
my $file = ReadCurrentSource->new($example);

tests/gendiffcov/simple/script.sh

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CXX='g++'
1010
LOCAL_COVERAGE=1
1111
KEEP_GOING=0
1212

13+
#echo "CMD: $0 $@"
14+
1315
while [ $# -gt 0 ] ; do
1416

1517
OPT=$1
@@ -91,12 +93,6 @@ fi
9193
export PATH=${LCOV_HOME}/bin:${LCOV_HOME}/share:${PATH}
9294
export MANPATH=${MANPATH}:${LCOV_HOME}/man
9395

94-
if [ 'x' == "x$GENHTML_TOOL" ] ; then
95-
GENHTML_TOOL=${LCOV_HOME}/bin/genhtml
96-
LCOV_TOOL=${LCOV_HOME}/bin/lcov
97-
GENINFO_TOOL=${LCOV_HOME}/bin/geninfo
98-
fi
99-
10096
ROOT=`pwd`
10197
PARENT=`(cd .. ; pwd)`
10298
if [ -f $LCOV_HOME/scripts/getp4version ] ; then
@@ -106,6 +102,13 @@ else
106102
SCRIPT_DIR=$LCOV_HOME/share/lcov/support-scripts
107103
MD5_OPT='--version-script --md5'
108104
fi
105+
if [ 'x' == "x$GENHTML_TOOL" ] ; then
106+
GENHTML_TOOL=${LCOV_HOME}/bin/genhtml
107+
LCOV_TOOL=${LCOV_HOME}/bin/lcov
108+
GENINFO_TOOL=${LCOV_HOME}/bin/geninfo
109+
SPREADSHEET_TOOL=${SCRIPT_DIR}/spreadsheet.py
110+
fi
111+
109112
# is this git or P4?
110113
git -C . rev-parse > /dev/null 2>&1
111114
if [ 0 == $? ] ; then
@@ -144,14 +147,19 @@ if ! type "${CXX}" >/dev/null 2>&1 ; then
144147
echo "Missing tool: $CXX" >&2
145148
exit 2
146149
fi
147-
150+
1
148151
if ! python3 -c "import xlsxwriter" >/dev/null 2>&1 ; then
149152
echo "Missing python module: xlsxwriter" >&2
150153
exit 2
151154
fi
152155

153156
echo *
154157

158+
echo "COVER = '$COVER'"
159+
echo "COVER_DB = '$COVER_DB'"
160+
echo "PYCOVER = '$PYCOVER'"
161+
echo "PYCOV_DB = '$PYCOV_DB'"
162+
155163
status=0
156164
ln -s simple.cpp test.cpp
157165
${CXX} --coverage test.cpp
@@ -1002,8 +1010,8 @@ if [ 0 != $? ] ; then
10021010
fi
10031011
fi
10041012
1005-
NAME=`(cd select2 ; ls /*.html)`
1006-
if [ "index.html" != $NAME ] ; then
1013+
NAME=`(cd select2 ; ls *.html)`
1014+
if [ "index.html" != "$NAME" ] ; then
10071015
echo "ERROR: expected to find only one HTML file"
10081016
status=1
10091017
if [ 0 == $KEEP_GOING ] ; then
@@ -1274,21 +1282,11 @@ if [ 0 != $? ] ; then
12741282
fi
12751283
12761284
1277-
# and generate a spreadsheet..check that we don't crash
1278-
SPREADSHEET=$LCOV_HOME/scripts/spreadsheet.py
1279-
if [ ! -f $SPREADSHEET ] ; then
1280-
SPREADSHEET=$LCOV_HOME/share/lcov/support-scripts/spreadsheet.py
1281-
fi
1282-
if [ -f $SPREADSHEET ] ; then
1283-
eval $PYCOVER $SPREADSHEET -o results.xlsx `find . -name "*.json"`
1284-
if [ 0 != $? ] ; then
1285-
status=1
1286-
echo "ERROR: spreadsheet generation failed"
1287-
exit 1
1288-
fi
1289-
else
1290-
echo "Did not find $SPREADSHEET to run test"
1285+
echo $SPREADSHEET_TOOL -o results.xlsx `find . -name "*.json"`
1286+
eval $SPREADSHEET_TOOL -o results.xlsx `find . -name "*.json"`
1287+
if [ 0 != $? ] ; then
12911288
status=1
1289+
echo "ERROR: spreadsheet generation failed"
12921290
exit 1
12931291
fi
12941292
@@ -1298,12 +1296,20 @@ else
12981296
echo "Tests failed"
12991297
fi
13001298
1301-
if [ "x$COVER" != "x" ] && [ 0 != $LOCAL_COVERAGE ] ; then
1302-
cover
1303-
${LCOV_HOME}/bin/perl2lcov -o perlcov.info --testname simple --version-script $GET_VERSION $COVER_DB
1299+
if [ "x$COVER" != "x" ] ; then
1300+
echo "Generating coverage report"
1301+
echo ${LCOV_HOME}/bin/py2lcov -o pycov.info --testname simple --version-script $GET_VERSION $PYCOV_DB
13041302
${LCOV_HOME}/bin/py2lcov -o pycov.info --testname simple --version-script $GET_VERSION $PYCOV_DB
1305-
${LCOV_HOME}/bin/genhtml -o html_report perlcov.info pycov.info --branch --flat --show-navigation --show-proportion --version-script $GET_VERSION --annotate-script $P4ANNOTATE --parallel --ignore empty,usage
1306-
echo "see HTML report 'html_report'"
1303+
1304+
if [ 0 != $LOCAL_COVERAGE ] ; then
1305+
cover $COVER_DB
1306+
${LCOV_HOME}/bin/perl2lcov -o perlcov.info --testname simple --version-script $GET_VERSION $COVER_DB
1307+
${LCOV_HOME}/bin/genhtml -o html_report perlcov.info pycov.info --branch --flat --show-navigation --show-proportion --version-script $GET_VERSION --annotate-script $P4ANNOTATE --parallel --ignore empty,usage
1308+
echo "see HTML report 'html_report'"
1309+
else
1310+
echo cp pycov.info $COVER_DB/spreadsheet.info
1311+
cp pycov.info $COVER_DB/spreadsheet.info
1312+
fi
13071313
fi
13081314
13091315
exit $status

tests/lcov/merge/merge.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ fi
8080
export PATH=${LCOV_HOME}/bin:${LCOV_HOME}/share:${PATH}
8181
export MANPATH=${MANPATH}:${LCOV_HOME}/man
8282

83+
if [ 'x' == "x$GENHTML_TOOL" ] ; then
84+
GENHTML_TOOL=${LCOV_HOME}/bin/genhtml
85+
LCOV_TOOL=${LCOV_HOME}/bin/lcov
86+
GENINFO_TOOL=${LCOV_HOME}/bin/geninfo
87+
fi
88+
8389
ROOT=`pwd`
8490
PARENT=`(cd .. ; pwd)`
8591

@@ -108,15 +114,15 @@ if ! type g++ >/dev/null 2>&1 ; then
108114
fi
109115
110116
status=0
111-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS -o intersect.info a.info --intersect b.info
117+
$COVER $LCOV_TOOL $LCOV_OPTS -o intersect.info a.info --intersect b.info
112118
if [ 0 != $? ] ; then
113119
echo "Error: unexpected error code from intersect"
114120
status=1
115121
if [ $KEEP_GOING == 0 ] ; then
116122
exit 1
117123
fi
118124
fi
119-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS -o intersect_2.info b.info --intersect a.info
125+
$COVER $LCOV_TOOL $LCOV_OPTS -o intersect_2.info b.info --intersect a.info
120126
if [ 0 != $? ] ; then
121127
echo "Error: unexpected error code from intersect"
122128
status=1
@@ -144,7 +150,7 @@ if [ 0 != $? ] ; then
144150
fi
145151
146152
147-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS -o diff.info a.info --subtract b.info
153+
$COVER $LCOV_TOOL $LCOV_OPTS -o diff.info a.info --subtract b.info
148154
if [ 0 != $? ] ; then
149155
echo "Error: unexpected error code from subtract"
150156
status=1
@@ -161,7 +167,7 @@ if [ 0 != $? ] ; then
161167
fi
162168
fi
163169
164-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS -o diff2.info b.info --subtract a.info
170+
$COVER $LCOV_TOOL $LCOV_OPTS -o diff2.info b.info --subtract a.info
165171
if [ 0 != $? ] ; then
166172
echo "Error: unexpected error code from subtract 2"
167173
status=1
@@ -180,15 +186,15 @@ fi
180186
181187
182188
# test some error messages...
183-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS -o x.info 'y.?info' --intersect a.info
189+
$COVER $LCOV_TOOL $LCOV_OPTS -o x.info 'y.?info' --intersect a.info
184190
if [ 0 == $? ] ; then
185191
echo "Error: expected error but did not see one"
186192
status=1
187193
if [ $KEEP_GOING == 0 ] ; then
188194
exit 1
189195
fi
190196
fi
191-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS -o x.info a.info --intersect 'z.?info'
197+
$COVER $LCOV_TOOL $LCOV_OPTS -o x.info a.info --intersect 'z.?info'
192198
if [ 0 == $? ] ; then
193199
echo "Error: expected error but did not see one"
194200
status=1

0 commit comments

Comments
 (0)