Skip to content

Commit 53a6ce8

Browse files
committed
lcov: Add self-tests
Add some tests for checking basic functionality of lcov. To run these tests, type: make test in either the top-level directory, or the test/ sub-directory. Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent 9753d5c commit 53a6ce8

File tree

19 files changed

+1951
-1
lines changed

19 files changed

+1951
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TMP_DIR := $(shell mktemp -d)
2424
FILES := $(wildcard bin/*) $(wildcard man/*) README Makefile \
2525
$(wildcard rpm/*) lcovrc
2626

27-
.PHONY: all info clean install uninstall rpms
27+
.PHONY: all info clean install uninstall rpms test
2828

2929
all: info
3030

@@ -33,11 +33,13 @@ info:
3333
@echo " install : install binaries and man pages in DESTDIR (default /)"
3434
@echo " uninstall : delete binaries and man pages from DESTDIR (default /)"
3535
@echo " dist : create packages (RPM, tarball) ready for distribution"
36+
@echo " test : perform self-tests"
3637

3738
clean:
3839
rm -f lcov-*.tar.gz
3940
rm -f lcov-*.rpm
4041
make -C example clean
42+
make -C test -s clean
4143

4244
install:
4345
bin/install.sh bin/lcov $(DESTDIR)$(BIN_DIR)/lcov -m 755
@@ -111,3 +113,6 @@ rpms: lcov-$(VERSION).tar.gz
111113
mv $(TMP_DIR)/RPMS/noarch/lcov-$(VERSION)-$(RELEASE).noarch.rpm .
112114
mv $(TMP_DIR)/SRPMS/lcov-$(VERSION)-$(RELEASE).src.rpm .
113115
rm -rf $(TMP_DIR)
116+
117+
test:
118+
@make -C test -s all

test/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
include common.mak
2+
3+
TESTDIRS := $(patsubst %/,%,$(dir $(wildcard */Makefile)))
4+
5+
help: info
6+
7+
info:
8+
echo "Available make targets:"
9+
echo " test : perform self-tests"
10+
echo " clean : remove all temporary files"
11+
echo ""
12+
echo "Available make variables:"
13+
echo " SIZE : specify size of test data (small, medium, large)"
14+
echo " V : specify level of verbosity (0, 1)"
15+
16+
test:
17+
for TEST in $(TESTDIRS) ; do \
18+
make -C $$TEST test ; \
19+
done
20+
21+
clean:
22+
rm -f *.info *.counts test.log
23+
for TEST in $(TESTDIRS) ; do \
24+
make -C $$TEST clean ; \
25+
done
26+
27+
.PHONY: help info test clean

test/bin/common

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
function elapsed_to_ms()
2+
{
3+
local ELAPSED=$1
4+
local IFS=:.
5+
local MS
6+
7+
set -- $ELAPSED
8+
if [ $# -eq 3 ] ; then
9+
let MS=${3#0}*10+${2#0}*1000+$1*60000
10+
else
11+
let MS=${4#0}*10+${3#0}*1000+${2#0}*60000+$1*3600000
12+
fi
13+
14+
echo $MS
15+
}
16+
17+
function t_timestamp()
18+
{
19+
date +"%Y-%m-%d %H:%M:%S %z"
20+
}
21+
22+
function t_marker()
23+
{
24+
echo
25+
echo "======================================================================"
26+
}
27+
28+
function t_detail()
29+
{
30+
local KEY=$1
31+
local VALUE=$2
32+
local DOTS=" ............"
33+
34+
printf "%-.12s: %s\n" "$KEY$DOTS" "$VALUE"
35+
}
36+
37+
function t_announce()
38+
{
39+
local TESTNAME="$1"
40+
41+
printf "$BOLD%-.30s$RESET " "$TESTNAME .............................."
42+
t_marker >> "$LOGFILE"
43+
t_detail "DATE" "$(t_timestamp)" >> "$LOGFILE"
44+
t_detail "TESTNAME" "$TESTNAME" >> "$LOGFILE"
45+
}
46+
47+
function t_result()
48+
{
49+
local COLOR="$1"
50+
local TEXT="$2"
51+
52+
printf "[$COLOR$TEXT$RESET]"
53+
}
54+
55+
function t_pass()
56+
{
57+
local TESTNAME="$1"
58+
59+
t_result "$GREEN" "pass"
60+
echo "pass $TESTNAME" >> "$COUNTFILE"
61+
}
62+
63+
function t_fail()
64+
{
65+
local TESTNAME="$1"
66+
67+
t_result "$RED" "fail"
68+
echo "fail $TESTNAME" >> "$COUNTFILE"
69+
}
70+
71+
function t_kill()
72+
{
73+
local TESTNAME="$1"
74+
75+
t_result "$RED" "kill"
76+
echo "fail $TESTNAME" >> "$COUNTFILE"
77+
}
78+
79+
function t_skip()
80+
{
81+
local TESTNAME="$1"
82+
83+
t_result "$BLUE" "skip"
84+
echo "skip $TESTNAME" >> "$COUNTFILE"
85+
}
86+
87+
function t_indent()
88+
{
89+
sed -e 's/^/ /'
90+
}
91+
92+
LOGFILE="$TOPDIR/test.log"
93+
COUNTFILE="$TOPDIR/test.counts"
94+
TIMEFILE="$TOPDIR/test.time"
95+
96+
if [ -t 1 ] ; then
97+
RED="\e[31m"
98+
GREEN="\e[32m"
99+
BLUE="\e[34m"
100+
BOLD="\e[1m"
101+
DEFAULT="\e[39m"
102+
RESET="\e[0m"
103+
fi

0 commit comments

Comments
 (0)