From 497d40b19b6b95dd2f8f555108e7f86269514857 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 22 Oct 2015 11:26:21 -0700 Subject: [PATCH] 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 --- .gitignore | 2 ++ CONFIG | 3 +++ autobuild.sh | 4 ++-- autotest.sh | 18 ++++++++++++++++++ mk/spdk.common.mk | 8 ++++++++ scripts/autotest_common.sh | 3 +++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cecf57b30..57f8be55b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.a *.d +*.gcda +*.gcno *.o *~ *.swp diff --git a/CONFIG b/CONFIG index df48319a7..2e6984674 100644 --- a/CONFIG +++ b/CONFIG @@ -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'. diff --git a/autobuild.sh b/autobuild.sh index 4e0860d54..e28eaf7ee 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -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 diff --git a/autotest.sh b/autotest.sh index 846ac85fb..a78a24120 100755 --- a/autotest.sh +++ b/autotest.sh @@ -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 diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index b95521663..4b7c31fde 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -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 diff --git a/scripts/autotest_common.sh b/scripts/autotest_common.sh index 964f46338..ec9cfe10c 100755 --- a/scripts/autotest_common.sh +++ b/scripts/autotest_common.sh @@ -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"