Skip to content

Commit 5b29265

Browse files
Modified gen_coverage.py to post-process profraw file generated by pytest
Modified workflow to use the script
1 parent 9167169 commit 5b29265

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

.github/workflows/generate-coverage.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ jobs:
102102
export PATH=${_SAVED_PATH}
103103
unset _SAVED_PATH
104104
python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()" || exit 1
105+
export LLVM_PROFILE_FILE="dpctl_pytest.profraw"
105106
pytest -q -ra --disable-warnings --cov-config pyproject.toml --cov dpctl \
106107
--cov-report term-missing --pyargs dpctl -vv \
107-
--ignore=dpctl/tensor/libtensor/tests
108+
--ignore=dpctl/tensor/libtensor/tests || exit 1
109+
$(dirname $(dirname $(which icx)))/bin-llvm/llvm-profdata merge \
110+
-sparse ${LLVM_PROFILE_FILE} -o dpctl_pytest.profdata || exit 1
111+
108112
109113
- name: Install coverall dependencies
110114
shell: bash -l {0}
@@ -115,7 +119,9 @@ jobs:
115119
- name: Upload coverage data to coveralls.io
116120
shell: bash -l {0}
117121
run: |
118-
coveralls-lcov -v -n $(find _skbuild -name dpctl.lcov) > dpctl-c-api-coverage.json
122+
coveralls-lcov -v -n \
123+
$(find _skbuild -name dpctl.lcov) \
124+
$(find . -name dpctl_pytest.lcov) > dpctl-c-api-coverage.json
119125
coveralls --service=github --merge=dpctl-c-api-coverage.json
120126
env:
121127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

scripts/gen_coverage.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def run(
8484
["cmake", "--build", ".", "--target", "lcov-genhtml"],
8585
cwd=cmake_build_dir,
8686
)
87+
env["LLVM_PROFILE_FILE"] = "dpctl_pytest.profraw"
8788
subprocess.check_call(
8889
[
8990
"pytest",
@@ -103,8 +104,49 @@ def run(
103104
],
104105
cwd=setup_dir,
105106
shell=False,
107+
env=env,
106108
)
107109

110+
def find_objects():
111+
import os
112+
113+
objects = []
114+
for root, _, files in os.walk("_skbuild"):
115+
for file in files:
116+
if not file.endswith(".o"):
117+
continue
118+
if os.path.join("libsyclinterface", "tests") in root:
119+
continue
120+
if any(match in root for match in ["libsyclinterface"]):
121+
objects.extend(["-object", os.path.join(root, file)])
122+
return objects
123+
124+
objects = find_objects()
125+
instr_profile_fn = "dpctl_pytest.profdata"
126+
# generate instrumentation profile data
127+
subprocess.check_call(
128+
[
129+
os.path.join(bin_llvm, "llvm-profdata"),
130+
"merge",
131+
"-sparse",
132+
env["LLVM_PROFILE_FILE"],
133+
"-o",
134+
instr_profile_fn,
135+
]
136+
)
137+
# export lcov
138+
with open("dpctl_pytest.lcov", "w") as fh:
139+
subprocess.check_call(
140+
[
141+
os.path.join(bin_llvm, "llvm-cov"),
142+
"export",
143+
"-format=lcov",
144+
"-instr-profile=" + instr_profile_fn,
145+
]
146+
+ objects,
147+
stdout=fh,
148+
)
149+
108150

109151
if __name__ == "__main__":
110152
import argparse

0 commit comments

Comments
 (0)