Skip to content

Commit 57bd0fc

Browse files
ScottToddclaude
andauthored
Add coverage reporting to unit tests workflow (#3359)
## Motivation Fixes #3356 (though we could keep that issue open to track improvements) This collects some simple coverage metrics for our Python unit tests using [pytest-cov](https://pypi.org/project/pytest-cov/). ## Technical Details * Coverage files are written into the `build/` directory, which is already covered by `.gitignore` * I experimented with using [diff-cover](https://pypi.org/project/diff-cover/) to surface the coverage diff from a PR in the github step summary but the output wasn't very useful (see https://github.com/ScottTodd/TheRock/actions/runs/21885368772#summary-63178759561 for example) * The workflow uploads test reports to github artifacts for now. That goes against conventions in this project to upload to AWS S3, but the files are small and I consider this a trial. If we do upload to S3 then the HTML reports would be easier to view (no local download needed) * We can also set up something more production-grade like https://about.codecov.io/ ## Test Plan * Tested in my fork at ScottTodd#6 * Tests ran on this PR: https://github.com/ROCm/TheRock/actions/runs/21885999701?pr=3359 ## Test Result Coverage reports on e.g. https://github.com/ScottTodd/TheRock/actions/runs/21885474484 * Sample text output: ``` ---------- coverage: platform linux, python 3.12.12-final-0 ---------- Name Stmts Miss Cover Missing ----------------------------------------------------------------------------------- analyze_build_times.py 219 219 0.00% 27-490 build_python_packages.py 46 46 0.00% 20-185 buildctl.py 206 206 0.00% 77-426 bump_submodules.py 83 83 0.00% 24-213 configure_stage.py 85 85 0.00% 29-242 export_source_archive.py 93 93 0.00% 43-206 fetch_repo.py 53 53 0.00% 7-135 fetch_sources.py 226 226 0.00% 14-600 generate_therock_manifest.py 81 81 0.00% 2-182 health_status.py 32 32 0.00% 12-88 index_generation_s3_tar.py 81 81 0.00% 23-230 install_rocm_from_artifacts.py 257 257 0.00% 107-745 linux_portable_build.py 65 65 0.00% 25-186 merge_compile_commands.py 18 18 0.00% 9-30 patch_linux_so.py 58 58 0.00% 4-109 patch_rocm_libraries.py 53 53 0.00% 23-155 patch_third_party_source.py 36 36 0.00% 12-58 posix_ccache_compiler_check.py 52 52 0.00% 31-116 print_driver_gpu_info.py 53 53 0.00% 15-137 resource_info.py 334 334 0.00% 31-774 setup_ccache.py 72 72 0.00% 24-200 teatime.py 121 121 0.00% 35-214 topology_to_cmake.py 189 189 0.00% 37-367 validate_shared_library.py 13 13 0.00% 4-20 setup_venv.py 136 93 31.62% 61-63, 68-72, 80-102, 106-113, 123-145, 183, 203, 212-217, 221-247, 255-275, 279-359 fetch_artifacts.py 122 78 36.07% 76, 113-117, 136-157, 161-249, 253-345 find_latest_artifacts.py 41 23 43.90% 76, 83, 98, 102, 113-186 find_artifacts_for_commit.py 88 45 48.86% 63, 71, 75, 79-95, 143-150, 190, 211-271 github_actions/configure_target_run.py 46 23 50.00% 52-82, 86-91 _therock_utils/hash_util.py 19 9 52.63% 8-16 github_actions/python_to_cp_version.py 21 8 61.90% 39-58 artifact_manager.py 394 149 62.18% 62, 67-72, 80-87, 92-94, 104, 106, 151, 162, 180-183, 188-205, 210-246, 256-257, 261-263, 268-269, 278, 280, 318-319, 337-340, 388, 442-480, 513, 522-524, 529-530, 547-548, 566, 568, 586, 588, 600-601, 633-634, 672-709, 714-724 github_actions/configure_ci_path_filters.py 56 20 64.29% 38-52, 66-88, 110-111, 205, 223 github_actions/configure_ci.py 275 86 68.73% 92, 120-121, 178, 213, 301, 338-340, 345, 380-383, 385-388, 491, 499, 542-676 github_actions/determine_version.py 30 9 70.00% 81-106 _therock_utils/artifacts.py 163 45 72.39% 35-40, 49-51, 55, 71, 85, 89, 114-136, 140, 144, 196, 201, 217, 231, 239, 273, 281-285, 288 _therock_utils/build_topology.py 293 76 74.06% 27, 30-32, 116-118, 126-128, 158, 189-192, 196-199, 230, 266, 287, 330, 334, 342, 346, 354, 358, 365, 372, 377, 382-383, 390-392, 483-488, 576, 588-590, 610-632, 641-646, 661-676 _therock_utils/pattern_match.py 124 30 75.81% 120-140, 149, 154, 157, 178-184, 188, 196, 203-205, 210-216, 219 fileset_tool.py 135 31 77.04% 30-31, 35-37, 58, 68, 73-74, 81, 94, 97, 111-116, 126-130, 133-134, 141-142, 147, 173-179 compute_rocm_package_version.py 92 21 77.17% 86, 151, 194, 206-266 github_actions/github_actions_utils.py 221 47 78.73% 109-110, 209-210, 268, 289-290, 301-309, 320-328, 340-350, 362-371, 496, 600, 615, 617, 650, 654-668 github_actions/fetch_package_targets.py 34 4 88.24% 91, 110, 128-129 _therock_utils/artifact_builder.py 231 16 93.07% 25, 30, 129, 135-137, 140, 159-161, 168-169, 214, 220, 325-328, 385, 470 github_actions/amdgpu_family_matrix.py 29 2 93.10% 250, 258 _therock_utils/artifact_backend.py 142 9 93.66% 49, 59, 69, 74, 80, 107, 212, 219, 287 github_actions/benchmarks/__init__.py 0 0 100.00% github_actions/benchmarks/benchmark_test_matrix.py 7 0 100.00% github_actions/fetch_test_configurations.py 56 0 100.00% ----------------------------------------------------------------------------------- TOTAL 5281 3350 36.57% Coverage HTML written to dir ../build/coverage-html ============================= 217 passed in 17.64s ============================= ``` * Sample HTML output (with interactive sorting): <img width="729" height="741" alt="image" src="https://github.com/user-attachments/assets/ee0b821e-e4c9-4b38-81e0-cf0ca442564c" /> ## Submission Checklist - [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests. --------- Co-authored-by: Claude <[email protected]>
1 parent a658818 commit 57bd0fc

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

.github/workflows/unit_tests.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,21 @@ jobs:
3939
# build_tools/github_actions/benchmarks/scripts/
4040
# build_tools/github_actions/test_executable_scripts/
4141
# We could move them if we want a simple `pytest build_tools/` to work.
42-
# TODO(scotttodd): enable code coverage collection/reporting here
4342
- name: Test build_tools
43+
working-directory: build_tools
4444
run: |
4545
python -m pytest -vv \
46-
build_tools/tests \
47-
build_tools/github_actions/tests
46+
--cov --cov-report=term-missing --cov-report=html
47+
48+
# TODO: upload to AWS S3 instead (so reports are hosted and don't require
49+
# a download step to view).
50+
# We could also use https://about.codecov.io/ instead of custom infra.
51+
- name: Upload coverage report
52+
if: always()
53+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
54+
with:
55+
name: coverage-report-${{ matrix.runs-on }}
56+
path: build/coverage-html/
4857

4958
# TODO(scotttodd): share code with ci_summary in ci.yml
5059
# Could reuse this from prior projects:

build_tools/pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[tool.pytest.ini_options]
2+
testpaths = [
3+
"tests",
4+
"github_actions/tests",
5+
]
6+
python_files = ["*_test.py"]
7+
addopts = "-ra"
8+
9+
[tool.coverage.run]
10+
data_file = "../build/.coverage"
11+
source = ["."]
12+
omit = [
13+
"tests/*",
14+
"github_actions/tests/*",
15+
"*/__pycache__/*",
16+
]
17+
18+
[tool.coverage.report]
19+
show_missing = true
20+
precision = 2
21+
sort = "Cover"
22+
exclude_lines = [
23+
"pragma: no cover",
24+
"raise NotImplementedError",
25+
"if __name__ == .__main__.:",
26+
]
27+
28+
[tool.coverage.html]
29+
directory = "../build/coverage-html"

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
boto3==1.39.15
22
pytest==8.3.5
33
pytest-check==2.5.3
4+
pytest-cov==6.0.0
45
pytest-timeout==2.4.0
56
PyYAML==6.0.2
67
pyzstd>=0.16.0

0 commit comments

Comments
 (0)