Skip to content

Commit

Permalink
github: add code coverage script
Browse files Browse the repository at this point in the history
  • Loading branch information
dimmus committed Sep 14, 2023
1 parent b4f0df9 commit 95c7bd3
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,6 @@ jobs:
matrix:
os: [ubuntu-latest]
env:
build-folder: build
OS: ${{ matrix.os }}
# PYTHON: '3.10'
steps:
Expand All @@ -22,24 21,27 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y autopoint meson ninja-build gettext libunwind-dev libefl-all-dev libeet1 libeet-bin
sudo apt-get install -y check
- name: Setup python
uses: actions/setup-python@master
sudo apt-get install -y check lcov
# - name: Setup python
# uses: actions/setup-python@master
# with:
# python-version: 3.10
- name: Install coverage
run: |
pip install coverage -i ${{ env.build-folder }}
export PATH=~/.local/bin:"$PATH"
# - name: Install coverage
# run: |
# pip install coverage
# export PATH=~/.local/bin:"$PATH"
- name: Setup project (meson)
run: meson setup . build -Db_coverage=true -Dbuild-tests=true
- name: Build project (ninja)
run: ninja -C build
- name: Run tests (ninja)
run: ninja -C build test
- name: Generate coverage report
run: ninja -C build coverage
run: ./scripts/generate_coverage_report.sh
- name: Upload to Codecov
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
directory: ./build/meson-logs/
files: ./coverage.xml
verbose: true
75 changes: 75 additions & 0 deletions scripts/generate_coverage_report.sh
Original file line number Diff line number Diff line change
@@ -0,0 1,75 @@
#!/usr/bin/env python3

import os
import subprocess
from lxml import html

proj_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
print("Project root:", proj_root)

print("Generating coverage report...")
subprocess.call(["ninja", "-C", "build", "-j", "1", "clean"])
subprocess.call(["ninja", "-C", "build", "-j", "1", "test"])

# Run lcov
outfiles = []
build_root = os.path.join(proj_root, 'build')
log_dir = os.path.join(build_root, 'meson-logs')
source_root = os.path.join(proj_root, 'src')
subproject_root = os.path.join(proj_root, 'subprojects')
lcov_exe = 'lcov'
genhtml_exe = 'genhtml'
htmloutdir = os.path.join(log_dir, 'coveragereport')
html_index = os.path.join(htmloutdir, 'index.html')
covinfo = os.path.join(log_dir, 'coverage.info')
initial_tracefile = covinfo '.initial'
run_tracefile = covinfo '.run'
raw_tracefile = covinfo '.raw'
subprocess.check_call([lcov_exe,
'--directory', build_root,
'--capture',
'--initial',
'--output-file',
initial_tracefile])
subprocess.check_call([lcov_exe,
'--directory', build_root,
'--capture',
'--output-file', run_tracefile,
'--no-checksum',
'--rc', 'lcov_branch_coverage=1',
])
# Join initial and test results.
subprocess.check_call([lcov_exe,
'-a', initial_tracefile,
'-a', run_tracefile,
'--rc', 'lcov_branch_coverage=1',
'-o', raw_tracefile])
# Remove all directories outside the source_root from the covinfo
subprocess.check_call([lcov_exe,
'--extract', raw_tracefile,
os.path.join(source_root, '*'),
'--rc', 'lcov_branch_coverage=1',
'--output-file', covinfo])
# Remove all directories inside subproject dir
subprocess.check_call([lcov_exe,
'--remove', covinfo,
os.path.join(subproject_root, '*'),
'--rc', 'lcov_branch_coverage=1',
'--output-file', covinfo])
subprocess.check_call([genhtml_exe,
'--prefix', build_root,
'--prefix', source_root,
'--output-directory', htmloutdir,
'--title', 'Code coverage',
'--legend',
'--show-details',
'--branch-coverage',
covinfo])

outfiles.append(('Html', html_index))

if outfiles:
print('')
for (filetype, path) in outfiles:
print(filetype ' coverage report can be found at', path)

0 comments on commit 95c7bd3

Please sign in to comment.