Skip to content

Commit 8805021

Browse files
committed
Collect C-level coverage using llvm-cov
1 parent 8d7089f commit 8805021

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

.github/workflows/c-coverage.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: C coverage
2+
3+
on:
4+
schedule:
5+
# Run this daily at 2400 UTC
6+
- cron: '0 0 * * *'
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
c-coverage:
13+
name: 'C-level coverage (using llvm-cov)'
14+
runs-on: ubuntu-20.04
15+
env:
16+
OPENSSL_VER: 1.1.1n
17+
PYTHONSTRICTEXTENSIONBUILD: 1
18+
steps:
19+
- name: Install Dependencies
20+
run: |
21+
sudo ./.github/workflows/posix-deps-apt.sh
22+
- name: Configure OpenSSL env vars
23+
run: |
24+
echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> $GITHUB_ENV
25+
echo "OPENSSL_DIR=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}" >> $GITHUB_ENV
26+
echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}/lib" >> $GITHUB_ENV
27+
- name: 'Restore OpenSSL build'
28+
id: cache-openssl
29+
uses: actions/cache@v3
30+
with:
31+
path: ./multissl/openssl/${{ env.OPENSSL_VER }}
32+
key: ${{ runner.os }}-multissl-openssl-${{ env.OPENSSL_VER }}
33+
- name: Install OpenSSL
34+
if: steps.cache-openssl.outputs.cache-hit != 'true'
35+
run: python3 Tools/ssl/multissltests.py --steps=library --base-directory $MULTISSL_DIR --openssl $OPENSSL_VER --system Linux
36+
- name: Add ccache to PATH
37+
run: |
38+
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
39+
- name: Configure ccache action
40+
uses: hendrikmuhs/ccache-action@v1
41+
- name: Configure clang (with coverage)
42+
run: |
43+
echo "CC=/usr/lib/ccache/clang-12 -fprofile-instr-generate -fcoverage-mapping" >> $GITHUB_ENV
44+
echo "CXX=/usr/lib/ccache/clang++-12 -fprofile-instr-generate -fcoverage-mapping" >> $GITHUB_ENV
45+
- name: Configure CPython
46+
run: ./configure --with-pydebug --with-openssl=$OPENSSL_DIR
47+
- name: Build CPython
48+
run: make -j4
49+
- name: Collect coverage data
50+
# Specify the LLVM_PROFILE_FILE using %m so multiple shared objects can write
51+
# in parallel. Set the full path to the directory so results aren't written
52+
# into temporary directories created by tests.
53+
# Using "-j 1" is important, or the Github Action runs out of memory
54+
run: LLVM_PROFILE_FILE=${PWD}/python%m.profraw xvfb-run ./python -m test -j 1
55+
- name: Generate coverage report
56+
run: |
57+
llvm-profdata-12 merge -sparse python*.profraw -o python.profdata
58+
llvm-cov-12 show -format=html -output-dir=cpython-coverage -instr-profile=python.profdata -show-branches=count -show-regions python .
59+
- name: Publish coverage-report
60+
uses: JamesIves/github-pages-deploy-action@v4
61+
with:
62+
folder: cpython-coverage
63+
repository-name: '' # TODO Destination
64+
token: ${{ secrets.COVERAGE_DEPLOY_TOKEN }} # TODO: Use an organization-level token
65+
single-commit: true

Lib/test/test_subprocess.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,11 @@ def is_env_var_to_ignore(n):
791791
# This excludes some __CF_* and VERSIONER_* keys MacOS insists
792792
# on adding even when the environment in exec is empty.
793793
# Gentoo sandboxes also force LD_PRELOAD and SANDBOX_* to exist.
794+
# LLVM coverage adds __LLVM_PROFILE_RT_INIT_ONCE variable.
794795
return ('VERSIONER' in n or '__CF' in n or # MacOS
795796
n == 'LD_PRELOAD' or n.startswith('SANDBOX') or # Gentoo
796-
n == 'LC_CTYPE') # Locale coercion triggered
797+
n == 'LC_CTYPE' or # Locale coercion triggered
798+
n == '__LLVM_PROFILE_RT_INIT_ONCE')
797799

798800
with subprocess.Popen([sys.executable, "-c",
799801
'import os; print(list(os.environ.keys()))'],

0 commit comments

Comments
 (0)