Skip to content

Commit 98f1779

Browse files
committed
Add tests to installed release. They are potentially useful examples,
despite being written to test functionality rather than to serve as tutorial eamples. Enable coverage data collection for the LCOV implementation - for both developer and module user. To run them from the release: $ cp -r $LCOV_HOME/share/lcov/tests path/to/my/tests $ cd path/to/my/tests $ make [COVERAGE=1] If eabled, point your browser to path/to/my/tests/cover_db/coverage.html to view coverage result. Signed-off-by: Henry Cox <[email protected]>
1 parent ccd7608 commit 98f1779

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+876
-293
lines changed

Makefile

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,13 @@ install:
147147
done ; \
148148
done
149149
mkdir -p $(SHARE_DIR)
150-
find example -type d -exec mkdir -p "$(SHARE_DIR)/{}" \;
151-
find example -type f -exec $(INSTALL) -Dm 644 "{}" "$(SHARE_DIR)/{}" \;
150+
for d in example tests ; do \
151+
( cd $$d ; make clean ) ; \
152+
find $$d -type d -exec mkdir -p "$(SHARE_DIR)/{}" \; ; \
153+
find $$d -type f -exec $(INSTALL) -Dm 644 "{}" "$(SHARE_DIR)/{}" \; ; \
154+
done
155+
@chmod -R ugo+x $(SHARE_DIR)/tests/bin
156+
@find $(SHARE_DIR)/tests \( -name '*.sh' -o -name '*.pl' \) -exec chmod ugo+x {} \;
152157
$(INSTALL) -d -m 755 $(CFG_DIR)
153158
$(call echocmd," INSTALL $(CFG_DIR)/lcovrc")
154159
$(INSTALL) -m 644 lcovrc $(CFG_DIR)/lcovrc
@@ -158,29 +163,32 @@ uninstall:
158163
$(call echocmd," UNINST $(BIN_DIR)/$$b") \
159164
$(RM) -f $(BIN_DIR)/$$b ; \
160165
done
161-
for s in $(SCRIPTS) ; do \
162-
$(call echocmd," UNINST $(SCRIPT_DIR)/$$s") \
163-
$(RM) -f $(SCRIPT_DIR)/$$s ; \
164-
done
165-
rmdir --ignore-fail-on-non-empty $(SCRIPT_DIR)
166+
rmdir --ignore-fail-on-non-empty $(BIN_DIR) || true
166167
for l in $(LIBS) ; do \
167168
$(call echocmd," UNINST $(LIB_DIR)/$$l") \
168169
$(RM) -f $(LIB_DIR)/$$l ; \
169170
done
171+
rmdir --ignore-fail-on-non-empty $(LIB_DIR) || true
172+
rmdir --ignore-fail-on-non-empty $(DESTDIR)/lib || true
170173
for section in 1 5 ; do \
171174
DEST=$(MAN_DIR)/man$$section ; \
172175
for m in man/*.$$section ; do \
173176
F=`basename $$m` ; \
174-
$(call echocmd," UNINST $$DEST/$$F") \
175-
$(RM) -f $$DEST/$$F ; \
177+
if [ -e man/$$F ] ; then \
178+
$(call echocmd," UNINST $$DEST/$$F") \
179+
$(RM) -f $$DEST/$$F ; \
180+
fi ; \
176181
done ; \
177-
rmdir --ignore-fail-on-non-empty $$DEST ; \
182+
rmdir --ignore-fail-on-non-empty $$DEST || true ; \
178183
done ; \
179-
rmdir --ignore-fail-on-non-empty $(MAN_DIR)
180-
$(RM) -rf $(SHARE_DIR)/example
181-
184+
rmdir --ignore-fail-on-non-empty $(MAN_DIR) || true
185+
rm -rf $(SHARE_DIR)
186+
rmdir --ignore-fail-on-non-empty $(DESTDIR)/share
182187
$(call echocmd," UNINST $(CFG_DIR)/lcovrc")
183188
$(RM) -f $(CFG_DIR)/lcovrc
189+
rmdir --ignore-fail-on-non-empty $(CFG_DIR) || true
190+
rmdir --ignore-fail-on-non-empty $(DESTDIR) || true
191+
184192

185193
dist: lcov-$(VERSION).tar.gz lcov-$(VERSION)-$(RELEASE).noarch.rpm \
186194
lcov-$(VERSION)-$(RELEASE).src.rpm
@@ -233,17 +241,17 @@ ifeq ($(COVERAGE), 1)
233241
# write to .../tests/cover_db
234242
export COVER_DB := ./cover_db
235243
endif
236-
export TESTCASE_ARGS COVER_DB
244+
export TESTCASE_ARGS
237245

238246
test: check
239247

240248
check:
241249
if [ "x$(COVERAGE)" != 'x' ] && [ ! -d tests/$(COVER_DB) ]; then \
242250
mkdir tests/$(COVER_DB) ; \
243251
fi
244-
@$(MAKE) -s -C tests check
245-
if [ "x$(COVERAGE)" != 'x' ] ; then \
246-
( cd tests ; cover ) ; \
252+
@$(MAKE) -s -C tests check LCOV_HOME=`pwd`
253+
@if [ "x$(COVERAGE)" != 'x' ] ; then \
254+
$(MAKE) -s -C tests report ; \
247255
fi
248256

249257
# Files to be checked for coding style issue issues -

README

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ To install in a different location - for example, your home directory, run:
8989

9090
your PREFIX should be an absolute path.
9191

92+
To run the LCOV regression test suite on your installation:
93+
94+
$ cp -r $LCOV_HOME/share/test path/to/myTestDir
95+
$ cd path/to/myTestDir
96+
$ make [COVERAGE=1]
97+
98+
If desired, you can collect coverage data for the LCOV module by setting
99+
the COVERAGE makefile variable.
100+
Note that the Devel::Cover package must be installed if COVERAGE is enabled
101+
To view the collected coverage information, point your browser to
102+
.../cover_db/coverage.html after running the tests.
103+
104+
Note that the testcases are intended to test LCOV functionality and
105+
not to be easily readable tutorial examples.
92106

93107
3. Dependencies:
94108
----------------

tests/Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
ifeq ($(COVERAGE), 1)
2+
ifeq ($(COVER_DB),)
3+
export COVER_DB := ./cover_db
4+
endif
5+
endif
6+
7+
.PHONY: report
8+
9+
all: check report
10+
111
include common.mak
212

313
TESTS := genhtml/ lcov/ gendiffcov/ py2lcov
414

15+
report:
16+
if [ "x$(COVERAGE)" != 'x' ] ; then \
17+
cover ; \
18+
fi
19+
520
clean:
6-
rm -rf *.info *.counts test.log src/ ./cover_db
21+
rm -rf *.info *.counts test.log src
22+
ifeq ($(COVERAGE), 1)
23+
if [ "x$(COVER_DB)" != 'x' ] ; then rm -rf $(COVER_DB) ; fi
24+
endif

tests/README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
LCOV test suite
22
===============
33

4-
This directory contains a number of regression tests for LCOV. To start it,
5-
simply run `make check`. The resulting output is written to the terminal and
6-
stored in a log file.
4+
This directory contains a number of regression tests for LCOV. To start it:
5+
6+
- if you are running in a build/development directory:
7+
8+
- run `make check`
9+
10+
- The resulting output is written to the terminal and
11+
stored in a log file.
12+
13+
- if you are running in or from an installed 'release' (e.g., from
14+
$LCOV_HOME/share/lcov/tests):
15+
16+
- (optional): cp -r $LCOV_HOME/share/lcov/tests myTestDir ; cd myTestDir
17+
18+
- make [COVERAGE=1]
19+
20+
- results will be written to the terminal and stored in 'test.log'
21+
If enabled, coverage data can be viewed by pointing your browser
22+
to .../cover_db/coverage.html. The coverage data can be redirected
23+
to a different location via the COVER_DB variable.
24+
25+
- to generate coverage data for the lcov module, the 'Devel::Cover'
26+
perl package must be available.
27+
728

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

tests/bin/common

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ function t_detail()
3737
function t_announce()
3838
{
3939
local TESTNAME="$1"
40+
local len=`echo "$1" | wc -c`
41+
local start=`expr $len - 31`
42+
if [[ $len > 32 ]] ; then
43+
# test name too long - trim from left
44+
TESTNAME="...`echo $TESTNAME | cut -c ${start}-`"
45+
fi
4046

4147
printf "$BOLD%-.35s$RESET " "$TESTNAME .............................."
4248
t_marker >> "$LOGFILE"

tests/bin/test_run

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ while [ $# -gt 0 ] ; do
2828
shift
2929
case $OPT in
3030

31-
--script-args )
32-
OPTS="$OPTS $1"
33-
shift
34-
;;
35-
36-
--coverage )
37-
COVER_DB=$1
38-
shift
39-
OPTS="$OPTS $OPT $COVER_DB"
40-
;;
41-
42-
* )
43-
echo "Error: test_run: unexpected option '$OPT'"
44-
exit 1
45-
;;
31+
--script-args )
32+
OPTS="$OPTS $1"
33+
shift
34+
;;
35+
36+
--coverage )
37+
COVER_DB=$1
38+
shift
39+
OPTS="$OPTS $OPT $COVER_DB --keep-going"
40+
;;
41+
42+
* )
43+
echo "Error: test_run: unexpected option '$OPT'"
44+
exit 1
45+
;;
4646

4747
esac
4848
done
4949

5050
TIME=$(type -P time 2>/dev/null)
5151
if [ ! -z "$TIME" ] ; then
52-
TIME="$TIME -v -o $TIMEFILE"
53-
if ! $TIME true 2>/dev/null ; then
54-
TIME=""
55-
fi
52+
TIME="$TIME -v -o $TIMEFILE"
53+
if ! $TIME true 2>/dev/null ; then
54+
TIME=""
55+
fi
5656
fi
5757

5858
t_announce "$TESTNAME"
@@ -78,15 +78,15 @@ ELAPSED=
7878
RESIDENT=
7979
SIGNAL=
8080
if [ ! -z "$TIME" ] ; then
81-
while read LINE ; do
82-
case "$LINE" in
83-
"Command terminated by signal"*) SIGNAL=${LINE##* } ;;
84-
"Elapsed"*) ELAPSED=$(elapsed_to_ms ${LINE##* }) ;;
85-
"Maximum resident"*) RESIDENT=${LINE##* } ;;
86-
"Exit status"*) RC=${LINE##* } ;;
87-
esac
88-
done < "$TIMEFILE"
89-
rm -f "$TIMEFILE"
81+
while read LINE ; do
82+
case "$LINE" in
83+
"Command terminated by signal"*) SIGNAL=${LINE##* } ;;
84+
"Elapsed"*) ELAPSED=$(elapsed_to_ms ${LINE##* }) ;;
85+
"Maximum resident"*) RESIDENT=${LINE##* } ;;
86+
"Exit status"*) RC=${LINE##* } ;;
87+
esac
88+
done < "$TIMEFILE"
89+
rm -f "$TIMEFILE"
9090
fi
9191

9292
# Save last output line as reason in case of skip result
@@ -96,56 +96,56 @@ t_detail "EXITCODE" "$RC" >>"$LOGFILE"
9696

9797
# Show result
9898
if [ $RC -eq 0 -a -z "$SIGNAL" ] ; then
99-
RESULT="pass"
100-
t_pass "$TESTNAME"
99+
RESULT="pass"
100+
t_pass "$TESTNAME"
101101
else
102-
if [ $RC -eq 2 ] ; then
103-
RESULT="skip"
104-
t_skip "$TESTNAME"
105-
else
106-
if [ -z "$SIGNAL" ] ; then
107-
RESULT="fail"
108-
t_fail "$TESTNAME"
109-
else
110-
RESULT="kill"
111-
t_kill "$TESTNAME"
112-
fi
113-
fi
102+
if [ $RC -eq 2 ] ; then
103+
RESULT="skip"
104+
t_skip "$TESTNAME"
105+
else
106+
if [ -z "$SIGNAL" ] ; then
107+
RESULT="fail"
108+
t_fail "$TESTNAME"
109+
else
110+
RESULT="kill"
111+
t_kill "$TESTNAME"
112+
fi
113+
fi
114114
fi
115115

116116
if [ ! -z "$SIGNAL" ] ; then
117-
t_detail "SIGNAL" "$SIGNAL" >>"$LOGFILE"
117+
t_detail "SIGNAL" "$SIGNAL" >>"$LOGFILE"
118118
fi
119119

120120
if [ ! -z "$ELAPSED" ] ; then
121-
echo -n " (time $(($ELAPSED/1000)).$(($ELAPSED%1000/100))s, "
122-
echo "elapsed $TESTNAME $ELAPSED" >> "$COUNTFILE"
121+
echo -n " (time $(($ELAPSED/1000)).$(($ELAPSED%1000/100))s, "
122+
echo "elapsed $TESTNAME $ELAPSED" >> "$COUNTFILE"
123123
fi
124124

125125
if [ ! -z "$RESIDENT" ] ; then
126-
echo -n "mem $(($RESIDENT/1024)).$((($RESIDENT%1024)/100))MB)"
127-
echo "resident $TESTNAME $RESIDENT" >> "$COUNTFILE"
126+
echo -n "mem $(($RESIDENT/1024)).$((($RESIDENT%1024)/100))MB)"
127+
echo "resident $TESTNAME $RESIDENT" >> "$COUNTFILE"
128128
fi
129129

130130
echo
131131

132132
# Show skip reason
133133
if [ $RC -eq 2 ] ; then
134-
t_detail "REASON" "$LAST" | t_indent
135-
t_detail "REASON" "$LAST" >>"$LOGFILE"
134+
t_detail "REASON" "$LAST" | t_indent
135+
t_detail "REASON" "$LAST" >>"$LOGFILE"
136136
fi
137137

138138
# Show log excerpt on failure or if requested
139139
if [ $RC -ne 0 -a $RC -ne 2 -o "$V" == "1" ] ; then
140-
LEN=$(tail -c "+$POS" "$LOGFILE" | wc -l)
141-
if [ "$LEN" -gt "$EXCERPTLEN" -a "$V" != "1" ] ; then
142-
echo " Skipping $LEN previous lines (see $LOGFILE)"
143-
echo " ..."
144-
tail -c "+$POS" "$LOGFILE" | tail -n $EXCERPTLEN | t_indent
145-
let LEN=$LEN-$EXCERPTLEN
146-
else
147-
tail -c "+$POS" "$LOGFILE" | t_indent
148-
fi
140+
LEN=$(tail -c "+$POS" "$LOGFILE" | wc -l)
141+
if [ "$LEN" -gt "$EXCERPTLEN" -a "$V" != "1" ] ; then
142+
echo " Skipping $LEN previous lines (see $LOGFILE)"
143+
echo " ..."
144+
tail -c "+$POS" "$LOGFILE" | tail -n $EXCERPTLEN | t_indent
145+
let LEN=$LEN-$EXCERPTLEN
146+
else
147+
tail -c "+$POS" "$LOGFILE" | t_indent
148+
fi
149149
fi
150150

151151
# Log more details

tests/common.mak

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
export TOPDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
2-
export TESTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
1+
2+
# TOPDIR == root of test directory - either build dir or copied from share/lcov
3+
TOPDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
4+
# TESTDIR == path to this particular testcase
5+
TESTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
6+
7+
ifeq ($(LCOV_HOME),)
8+
BINDIR = $(realpath $(TOPDIR)/../bin)
9+
else
10+
BINDIR := $(LCOV_HOME)/bin
11+
endif
12+
13+
ifeq ($(DEBUG),1)
14+
$(warning TOPDIR = $(TOPDIR))
15+
$(warning TESTDIR = $(TESTDIR))
16+
$(warning BINDIR = $(BINDIR))
17+
endif
18+
19+
TESTBINDIR := $(TOPDIR)bin
20+
21+
export TOPDIR TESTDIR
322
export PARENTDIR := $(dir $(patsubst %/,%,$(TOPDIR)))
423
export RELDIR := $(TESTDIR:$(PARENTDIR)%=%)
524

@@ -27,9 +46,9 @@ SIZE := small
2746
CC := gcc
2847

2948
# Specify programs under test
30-
export PATH := $(realpath $(TOPDIR)/../bin):$(realpath $(TOPDIR)/bin):$(PATH)
31-
export LCOV := $(realpath $(TOPDIR)/../bin/lcov) --config-file $(LCOVRC) $(LCOVFLAGS)
32-
export GENHTML := $(realpath $(TOPDIR)/../bin/genhtml) --config-file $(LCOVRC) $(GENHTMLFLAGS)
49+
export PATH := $(BINDIR):$(TESTBINDIR):$(PATH)
50+
export LCOV := $(BINDIR)/lcov --config-file $(LCOVRC) $(LCOVFLAGS)
51+
export GENHTML := $(BINDIR)/genhtml --config-file $(LCOVRC) $(GENHTMLFLAGS)
3352

3453
# Ensure stable output
3554
export LANG := C
@@ -66,7 +85,7 @@ export _ONCE := 1
6685
check: checkdeps prepare
6786

6887
checkdeps:
69-
checkdeps $(TOPDIR)/../bin/* $(TOPDIR)/bin/*
88+
checkdeps $(BINDIR)/* $(TESTBINDIR)/*
7089

7190
prepare: $(INFOFILES) $(COUNTFILES)
7291

tests/gendiffcov/filter/filter.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
use warnings;
55
use FindBin;
66

7-
use lib "$FindBin::RealBin/../../../lib";
7+
use lib "$FindBin::RealBin/../../../lib"; # build dir testcase
8+
use lib "$ENV{LCOV_HOME}/lib/lcov"; # install testcase
89
use lcovutil;
910

1011
foreach my $example (glob('expr*.c')) {

0 commit comments

Comments
 (0)