[apparmor] [patch] utils: add python coverage generation
Steve Beattie
steve at nxnw.org
Sat Oct 25 20:18:45 UTC 2014
This patch adds support for generating test coverage information for the
python utils.
To generate the coverage data, in the test subdirectory, do:
make coverage
This essentially runs make check, using a single python interpreter, and
records which lines and branches of the python code were exercised.
To view a text based report, after generating the coverage data, do:
make coverage-report
To generate detailed html reports, again after generating the coverage
data, do:
make coverage-html
And then point your web browser at
$(YOUR_CURRENT_WORKING_TREE)/utils/test/htmlcov/index.html .
An alternate output location can be specified by setting the
COVERAGE_OUT variable, e.g.
make coverage-html COVERAGE_OUT=/tmp/coverage/
(the output directory does not need to exist beforehand.)
Signed-off-by: Steve Beattie <steve at nxnw.org>
---
utils/test/Makefile | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
Index: b/utils/test/Makefile
===================================================================
--- a/utils/test/Makefile
+++ b/utils/test/Makefile
@@ -26,13 +26,29 @@ common/Make.rules: $(COMMONDIR)/Make.rul
ln -sf $(COMMONDIR) .
endif
-.PHONY: clean check
+COVERAGE_OMIT=test-*.py,common_test.py
+ifneq ($(COVERAGE_OUT), )
+HTML_COVR_ARGS=-d $(COVERAGE_OUT)
+endif
+
+.PHONY: clean check coverage coverage-report coverage-html
ifndef VERBOSE
-.SILENT: clean check
+.SILENT: clean check coverage coverage-report coverage-html
endif
clean: _clean
- rm -rf __pycache__/ common
+ rm -rf __pycache__/ common .coverage htmlcov
check:
export PYTHONPATH=.. ; $(foreach test, $(wildcard test-*.py), $(call pyalldo, $(test)))
+
+coverage:
+ export PYTHONPATH=.. ; $(foreach test, $(wildcard test-*.py), $(PYTHON) -m coverage run --branch -p $(test); )
+ $(PYTHON) -m coverage combine
+
+coverage-report:
+ $(PYTHON) -m coverage report --omit="$(COVERAGE_OMIT)"
+
+coverage-html:
+ $(PYTHON) -m coverage html --omit="$(COVERAGE_OMIT)" $(HTML_COVR_ARGS)
+
--
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20141025/2f7c9577/attachment.pgp>
More information about the AppArmor
mailing list