[apparmor] [patch] utils: add python coverage generation
John Johansen
john.johansen at canonical.com
Sat Oct 25 20:23:38 UTC 2014
On 10/25/2014 04:18 PM, Steve Beattie wrote:
> 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>
nice
Acked-by: John Johansen <john.johansen at canonical.com>
> ---
> 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)
> +
>
>
>
More information about the AppArmor
mailing list