Skip to content

Commit 0784bff

Browse files
committed
test: Add coverage support into the testsuite
Through CODE_COVERAGE variable
1 parent f8f7790 commit 0784bff

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

test/httpd/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ else
1111
exit 1
1212
fi
1313

14+
mkdir /coverage
15+
1416
# start apache httpd server in foreground
1517
echo "Starting httpd..."
1618
/usr/local/apache2/bin/apachectl start

test/includes/common.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ IMG=${IMG:-mod_proxy_cluster-testsuite-tomcat}
44
HTTPD_IMG=${HTTPD_IMG:-mod_proxy_cluster-testsuite-httpd}
55
MPC_NAME=${MPC_NAME:-httpd-mod_proxy_cluster}
66

7+
if [ $CODE_COVERAGE ]; then
8+
MPC_CFLAGS="$MPC_CFLAGS --coverage -fprofile-arcs -ftest-coverage -g -O0"
9+
MPC_LDFLAGS="$MPC_LDFLAGS -lgcov"
10+
HTTPD_EXTRA_FLAGS="$HTTPD_EXTRA_FLAGS --enable-debugger-mode"
11+
fi
12+
713
# Runs a test file ($1) under given name ($2, if given)
814
run_test() {
915
local ret=0
@@ -23,13 +29,26 @@ run_test() {
2329
echo " NOK"
2430
ret=1
2531
fi
32+
33+
local httpd_cont=$(docker ps -a | grep $HTTPD_IMG | cut -f 1 -d' ')
2634
# preserve httpd's logs too if DEBUG
2735
if [ $DEBUG ]; then
28-
local httpd_cont=$(docker ps -a | grep $HTTPD_IMG | cut -f 1 -d' ')
29-
docker logs $httpd_cont > "logs/${2:-$1}-httpd.log" 2>&1
36+
docker logs ${httpd_cont} > "logs/${2:-$1}-httpd.log" 2>&1
3037
docker cp ${httpd_cont}:/usr/local/apache2/logs/access_log "logs/${2:-$1}-httpd_access.log" 2> /dev/null || true
3138
fi
3239

40+
if [ $CODE_COVERAGE ]; then
41+
docker exec ${httpd_cont} /usr/local/apache2/bin/apachectl stop
42+
# preserve the coverage files
43+
# docker has problems with names containing spaces
44+
f=$(echo ${2:-1} | sed 's/ /-/g')
45+
docker exec ${httpd_cont} sh -c "cd /native; gcovr --gcov-ignore-errors=no_working_dir_found --json /coverage/coverage-$f.json"
46+
47+
for f in $(docker exec ${httpd_cont} ls /coverage/); do
48+
docker cp -q ${httpd_cont}:/coverage/$f $PWD/coverage/$f
49+
done
50+
fi
51+
3352
# Clean all after run
3453
httpd_remove > /dev/null 2>&1
3554
tomcat_all_remove > /dev/null 2>&1

test/testsuite.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ if [ ! -d logs ]; then
3636
mkdir logs
3737
fi
3838

39+
if [ $CODE_COVERAGE ]; then
40+
if [ ! -d coverage ]; then
41+
mkdir coverage
42+
fi
43+
44+
rm coverage/*
45+
fi
46+
3947
. includes/common.sh
4048

4149
if [ ! -d tomcat/target ]; then
@@ -114,4 +122,18 @@ else
114122
res=1
115123
fi
116124

125+
# if we're interessed in code coverage, run an httpd container with the already obtained
126+
# coverage files and generate the report from within the container with all the sources
127+
if [ $CODE_COVERAGE ]; then
128+
echo "Generating test coverage..."
129+
httpd_start > /dev/null 2>&1
130+
docker exec $MPC_NAME /usr/local/apache2/bin/apachectl stop
131+
for f in $(ls coverage/*.json); do
132+
docker cp -q $f $MPC_NAME:/coverage/
133+
done
134+
docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html'
135+
docker cp $MPC_NAME:/coverage/ .
136+
httpd_remove
137+
fi
138+
117139
exit $res

0 commit comments

Comments
 (0)