From: Ethan Jackson Date: Wed, 29 Feb 2012 00:28:08 +0000 (-0800) Subject: tests: Add code coverage for Python. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79982e900ba733bc870e1516e46fdcda67cf9cc1;p=openvswitch tests: Add code coverage for Python. Adds support for Ned Batchelder's code coverage tool to the test suite. http://nedbatchelder.com/code/coverage/ Signed-off-by: Ethan Jackson --- diff --git a/.gitignore b/.gitignore index 851c391b..702cc6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -11,9 +11,11 @@ *.pyc *.so *~ +*,cover .#* .*.cmd .*.swp +.coverage .deps .dirstamp .libs diff --git a/Makefile.am b/Makefile.am index 46de7fb3..4eab72af 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/python/automake.mk b/python/automake.mk index 089ef365..d63eb4d5 100644 --- a/python/automake.mk +++ b/python/automake.mk @@ -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) diff --git a/tests/atlocal.in b/tests/atlocal.in index aa86251c..1d37b59a 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -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 diff --git a/tests/automake.mk b/tests/automake.mk index b133467c..a2ed7d76 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -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) +# 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 + # 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 = \