Navigation Menu

Skip to content

Commit

Permalink
[connman] Allow to compile unit tests with coverage enabled
Browse files Browse the repository at this point in the history
... and added unit/coverage script which runs the tests and
generates html report.

Code coverage has to be enabled with --enable-test-coverage
configure switch
  • Loading branch information
monich committed Dec 2, 2016
1 parent 564df5f commit ec5c013
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions connman/.gitignore
Expand Up @@ -65,6 +65,11 @@ unit/test-nat
unit/test-dnsproxy
unit/test-sailfish_wakeup_timer

*.gcda
*.gcno
unit/html
unit/*.gcov

doc/*.bak
doc/*.stamp
doc/connman.*
Expand Down
6 changes: 6 additions & 0 deletions connman/Makefile.am
Expand Up @@ -263,11 +263,17 @@ endif
noinst_PROGRAMS += unit/test-ippool \
unit/test-sailfish_wakeup_timer unit/test-dnsproxy

if TEST_COVERAGE
COVERAGE_OPT = --coverage
endif

unit_test_ippool_SOURCES = src/log.c src/dbus.c src/error.c \
src/ippool.c unit/test-ippool.c
unit_test_ippool_CFLAGS = $(COVERAGE_OPT) $(AM_CFLAGS)
unit_test_ippool_LDADD = gdbus/libgdbus-internal.la \
@GLIB_LIBS@ @DBUS_LIBS@ -ldl

unit_test_sailfish_wakeup_timer_CFLAGS = $(COVERAGE_OPT) $(AM_CFLAGS)
unit_test_sailfish_wakeup_timer_SOURCES = unit/test-sailfish_wakeup_timer.c \
src/log.c src/wakeup_timer.c \
plugins/sailfish_wakeup_timer.c
Expand Down
5 changes: 5 additions & 0 deletions connman/configure.ac
Expand Up @@ -417,6 +417,11 @@ if (test "${need_glibutil}" = "yes"); then
LIBS="$LIBS $GLIBUTIL_LIBS"
fi

AC_ARG_ENABLE(test-coverage,
AC_HELP_STRING([--enable-test-coverage], [enable test code coverage]),
[enable_test_coverage=${enableval}], [enable_test_coverage="no"])
AM_CONDITIONAL(TEST_COVERAGE, test "${enable_test_coverage}" != "no")

AC_ARG_ENABLE(tools, AC_HELP_STRING([--disable-tools],
[disable testing tools]),
[enable_tools=${enableval}])
Expand Down
46 changes: 46 additions & 0 deletions connman/unit/coverage
@@ -0,0 +1,46 @@
#!/bin/bash
#
# Script to generate unit test coverage report, requires lcov:
#
# http://ltp.sourceforge.net/coverage/lcov.php
#

# Tests with coverage enabled:
TESTS="test-ippool test-sailfish_wakeup_timer"

pushd `dirname $0` > /dev/null
TEST_DIR="$PWD"
pushd .. > /dev/null
BASE_DIR="$PWD"
popd > /dev/null
popd > /dev/null

FULL_COV="$TEST_DIR/full.gcov"
PLUGINS_COV="$TEST_DIR/plugins.gcov"
SRC_COV="$TEST_DIR/src.gcov"
OUT="$TEST_DIR/html"

# Clean everything up
find "$BASE_DIR" -name "*.gcda" -exec rm {} \;
rm -f "$FULL_COV" "$PLUGINS_COV" "$SRC_COV"
rm -fr "$OUT"

# Run the tests
for t in $TESTS ; do
pushd "$TEST_DIR" > /dev/null
"$TEST_DIR/$t"
RC=$?
popd > /dev/null
[ $RC = 0 ] || exit 1
done

# LCOV 1.10 has branch coverage disabled per default
LCOV_OPT="--rc lcov_branch_coverage=1"
GENHTML_OPT="--branch-coverage"

lcov $LCOV_OPT -c -d "$BASE_DIR" -o "$FULL_COV" || exit 1
lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/plugins/*" -o "$PLUGINS_COV" || exit 1
lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/src/*" -o "$SRC_COV" || exit 1
genhtml $GENHTML_OPT -t connman "$PLUGINS_COV" "$SRC_COV" --output-directory "$OUT" || exit 1

echo Coverage report: $OUT/index.html

0 comments on commit ec5c013

Please sign in to comment.