aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-07-27 16:42:51 -0700
committerBen Pfaff <blp@nicira.com>2009-07-29 12:33:32 -0700
commitc2b070214097fa40dc78252882d96babe7fab4b4 (patch)
treeba992f3264d556f3e376a1248d26fc800116590a
parent1b233b95b5907a242ee453cbea3ad4bc4cd4fec2 (diff)
Add support for code coverage analysis with gcov and lcov.
-rw-r--r--README-gcov31
-rw-r--r--configure.ac1
-rw-r--r--m4/openvswitch.m425
-rw-r--r--tests/atlocal.in1
-rw-r--r--tests/automake.mk4
-rw-r--r--tests/lcov-post.at6
-rw-r--r--tests/lcov-pre.at21
-rw-r--r--tests/library.at18
-rw-r--r--tests/stp.at26
-rw-r--r--tests/testsuite.at2
10 files changed, 112 insertions, 23 deletions
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 <flows 3<pcap], [0], [checked 247 packets, 0 errors
+OVS_CHECK_LCOV([test-flows <flows 3<pcap], [0], [checked 247 packets, 0 errors
])
AT_CLEANUP
AT_SETUP([test TCP/IP checksumming])
-AT_CHECK([test-csum], [0], [ignore])
+OVS_CHECK_LCOV([test-csum], [0], [ignore])
AT_CLEANUP
AT_SETUP([test flow classifier])
-AT_CHECK([test-classifier], [0], [ignore])
+OVS_CHECK_LCOV([test-classifier], [0], [ignore])
AT_CLEANUP
AT_SETUP([test hash functions])
-AT_CHECK([test-hash], [0], [ignore])
+OVS_CHECK_LCOV([test-hash], [0], [ignore])
AT_CLEANUP
AT_SETUP([test hash map])
-AT_CHECK([test-hmap], [0], [ignore])
+OVS_CHECK_LCOV([test-hmap], [0], [ignore])
AT_CLEANUP
AT_SETUP([test linked lists])
-AT_CHECK([test-list], [0], [ignore])
+OVS_CHECK_LCOV([test-list], [0], [ignore])
AT_CLEANUP
AT_SETUP([test SHA-1])
-AT_CHECK([test-sha1], [0], [ignore])
+OVS_CHECK_LCOV([test-sha1], [0], [ignore])
AT_CLEANUP
AT_SETUP([test type properties])
-AT_CHECK([test-type-props], [0], [ignore])
+OVS_CHECK_LCOV([test-type-props], [0], [ignore])
AT_CLEANUP
AT_SETUP([test vconn library])
-AT_CHECK([test-vconn], [0], [ignore])
+OVS_CHECK_LCOV([test-vconn], [0], [ignore])
AT_CLEANUP
diff --git a/tests/stp.at b/tests/stp.at
index 4e25af72..6e2bcf93 100644
--- a/tests/stp.at
+++ b/tests/stp.at
@@ -15,7 +15,7 @@ check 2 = F:10 B
check 3 = F:5 F
check 4 = F:5 B
])
-AT_CHECK([test-stp test-stp-ieee802.1d-1998])
+OVS_CHECK_LCOV([test-stp test-stp-ieee802.1d-1998])
AT_CLEANUP
AT_SETUP([STP example from IEEE 802.1D-2004 figures 17.4 and 17.5])
@@ -52,7 +52,7 @@ check 5 = F:20 B F F
check 6 = F:20 B F F
check 7 = F:20 B F B
])
-AT_CHECK([test-stp test-stp-ieee802.1d-2004-fig17.4])
+OVS_CHECK_LCOV([test-stp test-stp-ieee802.1d-2004-fig17.4])
AT_CLEANUP
AT_SETUP([STP example from IEEE 802.1D-2004 figure 17.6])
@@ -72,7 +72,7 @@ check 3 = F:30 F B
check 4 = F:20 F F
check 5 = F:10 F F
])
-AT_CHECK([test-stp test-stp-ieee802.1d-2004-fig17.6])
+OVS_CHECK_LCOV([test-stp test-stp-ieee802.1d-2004-fig17.6])
AT_CLEANUP
AT_SETUP([STP example from IEEE 802.1D-2004 figure 17.7])
@@ -95,7 +95,7 @@ check 0 = root
check 1 = F F:10 F F F F F F
check 2 = F:20 D F F F F F F
])
-AT_CHECK([test-stp test-stp-ieee802.1d-2004-fig17.7])
+OVS_CHECK_LCOV([test-stp test-stp-ieee802.1d-2004-fig17.7])
AT_CLEANUP
AT_SETUP([STP.io.1.1: Link Failure])
@@ -128,7 +128,7 @@ run 1000
check 0 = root
check 1 = D D F:10
])
-AT_CHECK([test-stp test-stp-iol-io-1.1])
+OVS_CHECK_LCOV([test-stp test-stp-iol-io-1.1])
AT_CLEANUP
AT_SETUP([STP.io.1.2: Repeated Network])
@@ -148,7 +148,7 @@ run 1000
check 0 = rootid:0x111 F B
check 1 = rootid:0x111 B F:10
])
-AT_CHECK([test-stp test-stp-iol-io-1.2])
+OVS_CHECK_LCOV([test-stp test-stp-iol-io-1.2])
AT_CLEANUP
AT_SETUP([STP.io.1.4: Network Initialization])
@@ -168,7 +168,7 @@ check 1 = F:10 F F
check 2 = F:10 B F
check 3 = F:10 B B
])
-AT_CHECK([test-stp test-stp-iol-io-1.4])
+OVS_CHECK_LCOV([test-stp test-stp-iol-io-1.4])
AT_CLEANUP
AT_SETUP([STP.io.1.5: Topology Change])
@@ -215,7 +215,7 @@ check 1 = F:10 B F F
check 2 = B F:10 F F
check 3 = B F:20 B B
])
-AT_CHECK([test-stp test-stp-iol-io-1.5])
+OVS_CHECK_LCOV([test-stp test-stp-iol-io-1.5])
AT_CLEANUP
AT_SETUP([STP.op.1.1 and STP.op.1.2])
@@ -229,7 +229,7 @@ AT_DATA([test-stp-iol-op-1.1],
bridge 0 0x123 =
check 0 = root
])
-AT_CHECK([test-stp test-stp-iol-op-1.1])
+OVS_CHECK_LCOV([test-stp test-stp-iol-op-1.1])
AT_CLEANUP
AT_SETUP([STP.op.1.4: All Ports Initialized to Designated Ports])
@@ -244,7 +244,7 @@ check 0 = Li Li Li Li Li Li
run 1000
check 0 = F F F F F F
])
-AT_CHECK([test-stp test-stp-iol-op-1.4])
+OVS_CHECK_LCOV([test-stp test-stp-iol-op-1.4])
AT_CLEANUP
AT_SETUP([STP.op.3.1: Root Bridge Selection: Root ID Values])
@@ -262,7 +262,7 @@ run 1000
check 0 = rootid:0x111 root
check 1 = rootid:0x111 F:10
])
-AT_CHECK([test-stp test-stp-iol-op-3.1])
+OVS_CHECK_LCOV([test-stp test-stp-iol-op-3.1])
AT_CLEANUP
AT_SETUP([STP.op.3.3: Root Bridge Selection: Bridge ID Values])
@@ -280,7 +280,7 @@ check 0 = rootid:0x333^0x6000 root
check 1 = rootid:0x333^0x6000 F:20
check 2 = rootid:0x333^0x6000 F:10 F
])
-AT_CHECK([test-stp test-stp-iol-op-3.3])
+OVS_CHECK_LCOV([test-stp test-stp-iol-op-3.3])
AT_CLEANUP
AT_SETUP([STP.op.3.3: Root Bridge Selection: Bridge ID Values])
@@ -298,6 +298,6 @@ check 0 = rootid:0x333^0x6000 root
check 1 = rootid:0x333^0x6000 F:20
check 2 = rootid:0x333^0x6000 F:10 F
])
-AT_CHECK([test-stp test-stp-iol-op-3.4])
+OVS_CHECK_LCOV([test-stp test-stp-iol-op-3.4])
AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 0ad34c2f..f894c2a7 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -16,5 +16,7 @@ limitations under the License.])
AT_TESTED([ovs-vswitchd])
+m4_include([tests/lcov-pre.at])
m4_include([tests/library.at])
m4_include([tests/stp.at])
+m4_include([tests/lcov-post.at])