Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gcov coverage testing for C code #457

Merged
merged 3 commits into from Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -49,3 +49,15 @@ jobs:
- name: Tests
run: |
pytest

- name: Test with coverage
if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.python-version == '3.9' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
pip install -e .
pip install coverage
CFLAGS="--coverage -O0" python setup.py -q build_ext --inplace -f
coverage run -m pytest
./scripts/coverage.sh
bash <(curl -s https://codecov.io/bash) -X gcov
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -141,3 +141,9 @@ python/version.h
# Docker wheel build
pip-cache/
temp-wheels/

# gcov coverage files
cov
*.gcov
*.gcda
*.gcno
28 changes: 28 additions & 0 deletions scripts/coverage.sh
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Coverage for ultrajson's C code.
# Usage:
# CFLAGS="--coverage -O0" python setup.py -q build_ext --inplace -f
# pytest
# ./scripts/coverage.sh
# Then inspect the files in the `cov` folder.

# The exact arguments depend on whether we're using LLVM's gcov or GNU's.
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) gcov_options=(--relative-only);;
Darwin*) gcov_options=(--color);;
*) echo "Unsupported OS ${unameOut}"; exit 1;;
esac

# The actual gcov instructions:
gcov "${gcov_options[@]}" python/**.c -o build/temp.*/python
gcov "${gcov_options[@]}" lib/**.c -o build/temp.*/lib

# gcov dumps everything in the cwd without any option to change this.
# Manually move the .gcov files to a `cov` folder.
mkdir -p cov
rm -rf cov/*
mv ./**.gcov cov || exit 1

echo Written gcov files to ./cov