diff --git a/.travis.yml b/.travis.yml index 48f09be..14c0965 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,9 @@ addons: - ldap-utils - slapd +env: + - WITH_GCOV=1 + install: - pip install "pip>=7.1.0" - pip install tox-travis tox codecov coverage @@ -25,5 +28,7 @@ install: script: tox after_success: + # gather Python coverage - python -m coverage combine + # send Python and GCOV coverage - codecov diff --git a/Makefile b/Makefile index 56aaa8c..13d4b8b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ +LCOV_INFO=build/lcov.info +LCOV_REPORT=build/lcov_report +LCOV_REPORT_OPTIONS=--show-details -no-branch-coverage \ + --title "python-ldap LCOV report" + .NOTPARALLEL: .PHONY: all @@ -9,3 +14,28 @@ clean: rm -f .coverage .coverage.* find . -name '*.py[co]' -or -name '*.so*' -or -name '*.dylib' -delete find . -depth -name __pycache__ -exec rm -rf {} \; + +# LCOV report (measuring test coverage for C code) +.PHONY: lcov-clean lcov-coverage lcov-report lcov-open lcov +lcov-clean: + rm -rf $(LCOV_INFO) $(LCOV_REPORT) + find build -name '*.gc??' -delete + +lcov-coverage: + WITH_GCOV=1 tox -e py27,py36 + +$(LCOV_INFO): + lcov --capture --directory build --output-file $(LCOV_INFO) + +$(LCOV_REPORT): $(LCOV_INFO) + genhtml --output-directory $(LCOV_REPORT) \ + $(LCOV_REPORT_OPTIONS) $(LCOV_INFO) + +lcov-report: $(LCOV_REPORT) + +lcov-open: $(LCOV_REPORT) + xdg-open $(LCOV_REPORT)/index.html + +lcov: lcov-clean + $(MAKE) lcov-coverage + $(MAKE) lcov-report diff --git a/setup.py b/setup.py index 89351b5..f210c16 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ class OpenLDAP2: extra_link_args = [] extra_objects = [] libs = ['ldap', 'lber'] - defines = [ ] + defines = [] extra_files = [] LDAP_CLASS = OpenLDAP2 @@ -55,6 +55,14 @@ class OpenLDAP2: origfileslist = origfiles.split(',') LDAP_CLASS.extra_files[i]=(destdir, origfileslist) +if os.environ.get('WITH_GCOV'): + # Insrumentation for measuring code coverage + LDAP_CLASS.extra_compile_args.extend( + ['-O0', '-pg', '-fprofile-arcs', '-ftest-coverage'] + ) + LDAP_CLASS.extra_link_args.append('-pg') + LDAP_CLASS.libs.append('gcov') + #-- Let distutils/setuptools do the rest name = 'python-ldap' diff --git a/tox.ini b/tox.ini index 417c7aa..84002a4 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,7 @@ deps = pyasn1 pyasn1_modules commands = {envpython} -m coverage run --parallel setup.py test +passenv = WITH_GCOV [testenv:coverage-report] deps = coverage