From c2b070214097fa40dc78252882d96babe7fab4b4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 27 Jul 2009 16:42:51 -0700 Subject: [PATCH] Add support for code coverage analysis with gcov and lcov. --- README-gcov | 31 +++++++++++++++++++++++++++++++ configure.ac | 1 + m4/openvswitch.m4 | 25 +++++++++++++++++++++++++ tests/atlocal.in | 1 + tests/automake.mk | 4 +++- tests/lcov-post.at | 6 ++++++ tests/lcov-pre.at | 21 +++++++++++++++++++++ tests/library.at | 18 +++++++++--------- tests/stp.at | 26 +++++++++++++------------- tests/testsuite.at | 2 ++ 10 files changed, 112 insertions(+), 23 deletions(-) create mode 100644 README-gcov create mode 100644 tests/lcov-post.at create mode 100644 tests/lcov-pre.at diff --git a/README-gcov b/README-gcov new file mode 100644 index 00000000..665a1ec1 --- /dev/null +++ b/README-gcov @@ -0,0 +1,31 @@ +Building with gcov support +========================== + +The Open vSwitch "configure" script supports the following +code-coverage related options: + + --disable-coverage + --enable-coverage=no + + Do not build with gcov code coverage support. + + This is the default if no coverage option is passed to + "configure". + + --enable-coverage + --enable-coverage=yes + + Build with gcov code coverage support, but do not assume that any + coverage-related tools are installed and do not add special + coverage support to the test suite. + + --enable-coverage=lcov + + Build with gcov code coverage support, as above, but also add + support for coverage analysis to the test suite. Running "make + check" will produce a directory "tests/coverage.html" in the build + directory with an analysis of the test suite's coverage. + + This setting requires the lcov suite of utilities to be installed. + The "lcov" and "genhtml" programs from lcov must be in PATH. lcov + is available at: http://ltp.sourceforge.net/coverage/lcov.php diff --git a/configure.ac b/configure.ac index 16281463..ad38ea79 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,7 @@ AC_C_BIGENDIAN AC_SYS_LARGEFILE OVS_CHECK_USERSPACE +OVS_CHECK_COVERAGE OVS_CHECK_NDEBUG OVS_CHECK_NETLINK OVS_CHECK_OPENSSL diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4 index ce55311a..3fe053b0 100644 --- a/m4/openvswitch.m4 +++ b/m4/openvswitch.m4 @@ -14,6 +14,31 @@ # See the License for the specific language governing permissions and # limitations under the License. +dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately. +AC_DEFUN([OVS_CHECK_COVERAGE], + [AC_REQUIRE([AC_PROG_CC]) + AC_ARG_ENABLE( + [coverage], + [AC_HELP_STRING([--enable-coverage], + [Enable gcov coverage tool.])], + [case "${enableval}" in + (lcov) coverage=true lcov=true ;; + (yes) coverage=true lcov=false ;; + (no) coverage=false lcov=false ;; + (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;; + esac], + [coverage=false lcov=false]) + if $coverage; then + CFLAGS="$CFLAGS -O0 --coverage" + LDFLAGS="$LDFLAGS --coverage" + fi + if $lcov; then + if lcov --version >/dev/null 2>&1; then :; else + AC_MSG_ERROR([--enable-coverage=lcov was specified but lcov is not in \$PATH]) + fi + fi + AC_SUBST([LCOV], [$lcov])]) + dnl Checks for --enable-ndebug and defines NDEBUG if it is specified. AC_DEFUN([OVS_CHECK_NDEBUG], [AC_ARG_ENABLE( diff --git a/tests/atlocal.in b/tests/atlocal.in index 1328d4a4..d0ca7048 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -1,2 +1,3 @@ # -*- shell-script -*- PERL='@PERL@' +LCOV='@LCOV@' diff --git a/tests/automake.mk b/tests/automake.mk index 6dc109d6..07e56ffc 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -6,8 +6,10 @@ EXTRA_DIST += \ $(srcdir)/tests/testsuite TESTSUITE_AT = \ tests/testsuite.at \ + tests/lcov-pre.at \ tests/library.at \ - tests/stp.at + tests/stp.at \ + tests/lcov-post.at TESTSUITE = $(srcdir)/tests/testsuite DISTCLEANFILES += tests/atconfig tests/atlocal $(TESTSUITE) diff --git a/tests/lcov-post.at b/tests/lcov-post.at new file mode 100644 index 00000000..957cdfa4 --- /dev/null +++ b/tests/lcov-post.at @@ -0,0 +1,6 @@ +AT_BANNER([code coverage]) + +AT_SETUP([generate coverage.html with lcov]) +AT_CHECK([$LCOV || exit 77]) +AT_CHECK([cd $abs_builddir && genhtml -o coverage.html coverage.info], [0], [ignore], [ignore]) +AT_CLEANUP diff --git a/tests/lcov-pre.at b/tests/lcov-pre.at new file mode 100644 index 00000000..1ecfeb16 --- /dev/null +++ b/tests/lcov-pre.at @@ -0,0 +1,21 @@ +AT_BANNER([code coverage]) + +m4_define([_OVS_RUN_LCOV], [test $LCOV = false || lcov -b $abs_top_builddir -d $abs_top_builddir $1]) + +AT_SETUP([initialize lcov]) +AT_CHECK([rm -fr $abs_builddir/coverage.html]) +AT_CHECK([rm -f $abs_builddir/coverage.info]) +AT_CHECK([$LCOV || exit 77]) +AT_CHECK([_OVS_RUN_LCOV([-c -i -o - > $abs_builddir/coverage.info])], [0], [ignore], [ignore]) +AT_CLEANUP + +# OVS_CHECK_LCOV(COMMAND, [STATUS = `0'], [STDOUT = `'], [STDERR = `'], +# [RUN-IF-FAIL], [RUN-IF-PASS]) +# +# This macro is equivalent to AT_CHECK, except that COMMAND should be a single +# shell command that invokes a program whose code coverage is to be measured +# (if configure was invoked with --coverage). +m4_define([OVS_CHECK_LCOV], + [AT_CHECK([_OVS_RUN_LCOV([-z])], [0], [ignore], [ignore]) + AT_CHECK($@) + AT_CHECK([_OVS_RUN_LCOV([-c -o - >> $abs_builddir/coverage.info])], [0], [ignore], [ignore])]) diff --git a/tests/library.at b/tests/library.at index c7032418..c48828e9 100644 --- a/tests/library.at +++ b/tests/library.at @@ -2,38 +2,38 @@ AT_BANNER([library unit tests]) AT_SETUP([test flow extractor]) AT_CHECK([$PERL `which flowgen.pl` >/dev/null 3>flows 4>pcap]) -AT_CHECK([test-flows