tests: Add code coverage for Python.
authorEthan Jackson <ethan@nicira.com>
Wed, 29 Feb 2012 00:28:08 +0000 (16:28 -0800)
committerEthan Jackson <ethan@nicira.com>
Fri, 2 Mar 2012 21:30:25 +0000 (13:30 -0800)
Adds support for Ned Batchelder's code coverage tool to the
test suite. http://nedbatchelder.com/code/coverage/

Signed-off-by: Ethan Jackson <ethan@nicira.com>
.gitignore
Makefile.am
python/automake.mk
tests/atlocal.in
tests/automake.mk

index 851c391bc1eee0377f4b56f3a9d7042e8ebafbf3..702cc6ca190d0c42b9ba4ad7623485dd47fff8c2 100644 (file)
 *.pyc
 *.so
 *~
+*,cover
 .#*
 .*.cmd
 .*.swp
+.coverage
 .deps
 .dirstamp
 .libs
index 46de7fb330db945cdeb4b7451192fe96b5e80acf..4eab72af07f9c6052cc61e64394ae0bb6b66a6d6 100644 (file)
@@ -29,6 +29,7 @@ BUILT_SOURCES =
 CLEANFILES =
 CLEAN_LOCAL =
 DISTCLEANFILES =
+PYCOV_CLEAN_FILES = build-aux/check-structs,cover
 EXTRA_DIST = \
        CodingStyle \
        DESIGN \
@@ -115,6 +116,11 @@ SUFFIXES += .in
        fi
        mv $@.tmp $@
 
+.PHONY: clean-pycov
+clean-pycov:
+       cd $(srcdir) && rm -f $(PYCOV_CLEAN_FILES)
+CLEAN_LOCAL += clean-pycov
+
 # If we're checked out from a Git repository, make sure that every
 # file that is in Git is distributed.
 ALL_LOCAL += dist-hook-git
index 089ef36531351aad3322a4c6cb5047aed74d8029..d63eb4d59f5a7cc52d7d2829eada84be93b9de20 100644 (file)
@@ -30,7 +30,9 @@ ovs_pyfiles = \
        python/ovs/timeval.py \
        python/ovs/vlog.py \
        python/ovs/util.py
-EXTRA_DIST += $(ovs_pyfiles) python/ovs/dirs.py $(ovstest_pyfiles)
+PYFILES = $(ovs_pyfiles) python/ovs/dirs.py $(ovstest_pyfiles)
+EXTRA_DIST += $(PYFILES)
+PYCOV_CLEAN_FILES += $(PYFILES:.py=.py,cover)
 
 if HAVE_PYTHON
 nobase_pkgdata_DATA = $(ovs_pyfiles) $(ovstest_pyfiles)
index aa86251cf8fa1409bad05f492f3b1e11a4fb634c..1d37b59a74aa18096cd461bdf54f4ad88a552aee 100644 (file)
@@ -2,7 +2,10 @@
 HAVE_OPENSSL='@HAVE_OPENSSL@'
 HAVE_PYTHON='@HAVE_PYTHON@'
 PERL='@PERL@'
-PYTHON='@PYTHON@'
+
+if test x"$PYTHON" = x; then
+    PYTHON='@PYTHON@'
+fi
 
 PYTHONPATH=$abs_top_srcdir/python:$abs_top_builddir/tests:$PYTHONPATH
 export PYTHONPATH
@@ -16,5 +19,5 @@ if test $HAVE_PYTHON = yes; then
     else
         PYTHONPATH=$PYTHONPATH:$abs_top_srcdir/python/compat
         export PYTHONPATH
-   fi
+    fi
 fi
index b133467c9613ab4b34d813e373d686ebfde71795..a2ed7d7680a242c5a3211257de758728a1a79bd1 100644 (file)
@@ -66,6 +66,21 @@ AUTOTEST_PATH = utilities:vswitchd:ovsdb:tests
 check-local: tests/atconfig tests/atlocal $(TESTSUITE)
        $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH) $(TESTSUITEFLAGS)
 \f
+# Python Coverage support.
+# Requires coverage.py http://nedbatchelder.com/code/coverage/.
+
+COVERAGE = coverage
+COVERAGE_FILE='$(abs_srcdir)/.coverage'
+check-pycov: all tests/atconfig tests/atlocal $(TESTSUITE) clean-pycov
+       COVERAGE_FILE=$(COVERAGE_FILE) PYTHON='$(COVERAGE) run -p' $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH) $(TESTSUITEFLAGS)
+       @cd $(srcdir) && $(COVERAGE) combine && COVERAGE_FILE=$(COVERAGE_FILE) $(COVERAGE) annotate
+       @echo
+       @echo '----------------------------------------------------------------------'
+       @echo 'Annotated coverage source has the ",cover" extension.'
+       @echo '----------------------------------------------------------------------'
+       @echo
+       @COVERAGE_FILE=$(COVERAGE_FILE) $(COVERAGE) report
+\f
 # lcov support
 
 lcov_wrappers = \
@@ -337,7 +352,7 @@ tests_test_byte_order_LDADD = lib/libopenvswitch.a
 EXTRA_DIST += tests/choose-port.pl
 
 # Python tests.
-EXTRA_DIST += \
+CHECK_PYFILES = \
        tests/test-daemon.py \
        tests/test-json.py \
        tests/test-jsonrpc.py \
@@ -345,6 +360,8 @@ EXTRA_DIST += \
        tests/test-reconnect.py \
        tests/MockXenAPI.py \
        tests/test-vlog.py
+EXTRA_DIST += $(CHECK_PYFILES)
+PYCOV_CLEAN_FILES += $(CHECK_PYFILES:.py=.py,cover) .coverage
 
 if HAVE_OPENSSL
 TESTPKI_FILES = \