build: add CONFIG_COVERAGE code coverage option

Collect coverage information for use with gcov.

Coverage is disabled on FreeBSD because the current version of clang
provided by FreeBSD can't successfully link with -ftest-coverage enabled
(the compiler-rt support libs are too old).

Change-Id: Icc444936caa852bfb9a02b37223209319a27a770
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2015-10-22 11:26:21 -07:00 committed by Gerrit Code Review
parent ae80d88bcb
commit 497d40b19b
6 changed files with 36 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
*.a
*.d
*.gcda
*.gcno
*.o
*~
*.swp

3
CONFIG
View File

@ -34,6 +34,9 @@
# Build with debug logging. Turn off for performance testing and normal usage
CONFIG_DEBUG?=y
# Build with code coverage instrumentation.
CONFIG_COVERAGE=n
# This directory should contain 'include' and 'lib' directories for your DPDK
# installation. Alternatively you can specify this on the command line
# with 'make DPDK_DIR=/path/to/dpdk'.

View File

@ -26,7 +26,7 @@ $MAKE $MAKEFLAGS clean
timing_enter scanbuild_make
fail=0
time $scanbuild $MAKE $MAKEFLAGS DPDK_DIR=$DPDK_DIR CONFIG_DEBUG=y || fail=1
time $scanbuild $MAKE $MAKEFLAGS DPDK_DIR=$DPDK_DIR $MAKECONFIG || fail=1
timing_exit scanbuild_make
# Check that header file dependencies are working correctly by
@ -34,7 +34,7 @@ timing_exit scanbuild_make
# header file and re-making.
STAT1=`stat examples/nvme/identify/identify`
touch lib/nvme/nvme_internal.h
$MAKE $MAKEFLAGS DPDK_DIR=$DPDK_DIR CONFIG_DEBUG=y || fail=1
$MAKE $MAKEFLAGS DPDK_DIR=$DPDK_DIR $MAKECONFIG || fail=1
STAT2=`stat examples/nvme/identify/identify`
if [ "$STAT1" == "$STAT2" ]; then

View File

@ -18,6 +18,11 @@ src=$(readlink -f $(dirname $0))
out=$PWD
cd $src
if hash lcov; then
# zero out coverage data
lcov -q -c -i -d $src -o cov_base.info
fi
# set up huge pages
timing_enter afterboot
./scripts/configure_hugepages.sh 3072
@ -45,3 +50,16 @@ trap - SIGINT SIGTERM EXIT
# catch any stray core files
process_core
if hash lcov; then
# generate coverage data and combine with baseline
lcov -q -c -d $src -o cov_test.info
lcov -q -a cov_base.info -a cov_test.info -o cov_total.info
lcov -q -r cov_total.info '/usr/*' -o cov_total.info
lcov -q -r cov_total.info 'test/*' -o cov_total.info
genhtml cov_total.info --legend -t "SPDK" -o $out/coverage
chmod -R a+rX $out/coverage
rm cov_base.info cov_test.info
mv cov_total.info $out/cov_total.info
find . -name "*.gcda" -delete
fi

View File

@ -76,6 +76,14 @@ COMMON_CFLAGS += -DNDEBUG -O2
COMMON_CFLAGS += -D_FORTIFY_SOURCE=2
endif
ifeq ($(CONFIG_COVERAGE), y)
COMMON_CFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += -fprofile-arcs -ftest-coverage
ifeq ($(OS),FreeBSD)
LDFLAGS += --coverage
endif
endif
CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -std=gnu11
MAKEFLAGS += --no-print-directory

View File

@ -1,6 +1,8 @@
set -xe
ulimit -c unlimited
MAKECONFIG='CONFIG_DEBUG=y'
case `uname` in
FreeBSD)
DPDK_DIR=/usr/local/share/dpdk/x86_64-native-bsdapp-clang
@ -9,6 +11,7 @@ case `uname` in
Linux)
DPDK_DIR=/usr/local/dpdk-2.1.0/x86_64-native-linuxapp-gcc
MAKE=make
MAKECONFIG="$MAKECONFIG CONFIG_COVERAGE=y"
;;
*)
echo "Unknown OS in $0"