Skip to content

Commit

Permalink
Add GCOV / LCOV C coverage support
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Nov 25, 2017
1 parent 52077e8 commit b91e5d2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ addons:
- ldap-utils
- slapd

env:
- WITH_GCOV=1

install:
- pip install "pip>=7.1.0"
- pip install tox-travis tox codecov coverage

script: tox

after_success:
# gather Python coverage
- python -m coverage combine
# send Python and GCOV coverage
- codecov
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand 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
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OpenLDAP2:
extra_link_args = []
extra_objects = []
libs = ['ldap', 'lber']
defines = [ ]
defines = []
extra_files = []

LDAP_CLASS = OpenLDAP2
Expand All @@ -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'

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b91e5d2

Please sign in to comment.