1 #! /bin/bash
2 #
3 # SysDB -- t/coverage.sh
4 #
5 # Create a test coverage report for the System DataBase.
7 set -e
9 if ! which lcov || ! which genhtml; then
10 echo "lcov is required in order to generate a test coverage report" >&2
11 exit 1
12 fi
14 cd $( dirname "$0" )/..
16 if test -e t/coverage; then
17 echo "t/coverage exists already; please remove manually" >&2
18 exit 1
19 fi
21 V=$( grep '^PACKAGE_VERSION' Makefile | cut -d' ' -f3 )
22 if test -z "$V"; then
23 echo "Unable to determine package version" >&2
24 exit 1
25 fi
27 make dist
29 tmpdir=$( mktemp -d -t )
30 trap "rm -rf $tmpdir" EXIT
32 srcdir=$( pwd )
34 cd $tmpdir
35 tar --strip-components=1 -zxf "$srcdir"/sysdb-$V.tar.gz
36 if test -d "$srcdir"/.git/; then
37 # copy Git database for version-gen.sh
38 cp -a "$srcdir"/.git .
40 # reset all files which are not part of the tarball
41 git checkout HEAD .gitignore .travis.yml t/cibuild.sh
42 fi
44 # rebuild build system to refresh version number, etc.
45 rm -f version
46 touch configure.ac && make configure
48 ./configure --enable-gcov CFLAGS="-O0 -g"
49 make
51 lcov --base-directory src --directory src --zerocount
52 make -j25 test || (status=$?; cat t/test-suite.log 2> /dev/null; exit $status)
54 # old versions of lcov don't support --no-external
55 lcov --base-directory src --directory src --no-external \
56 --capture -o sysdb_coverage.info \
57 || lcov --base-directory src --directory src \
58 --capture -o sysdb_coverage.info
59 for pattern in '*.y' '*.l' \
60 'sysdb/scanner.c' 'frontend/scanner.c' 'liboconfig/scanner.c' \
61 'frontend/grammar.c' 'liboconfig/parser.c'
62 do
63 lcov --remove sysdb_coverage.info "$pattern" -o sysdb_coverage.info
64 done
66 V=$( ./version-gen.sh )
67 genhtml -o "$srcdir"/t/coverage \
68 -t "SysDB $V test coverage" --num-spaces=4 --legend \
69 sysdb_coverage.info