Skip to content

Commit 7428fb6

Browse files
committed
Build: Add coverage workflow and Codecov configuration
Add a GitHub Actions coverage workflow for OpensslPkg host tests and add repository-level Codecov settings for project and patch status thresholds on pull requests. Signed-off-by: Doug Flick <dougflick@microsoft.com>
1 parent 3f3a8e0 commit 7428fb6

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Coverage workflow - builds host-based unit tests with gcov instrumentation
2+
# via the HostBasedUnitTestRunner plugin (CODE_COVERAGE=TRUE), then publishes
3+
# a Cobertura XML summary and optional HTML report.
4+
#
5+
# The plugin handles lcov capture, filtering, and XML generation automatically.
6+
# This workflow adds HTML report generation, baseline comparison, and PR comments.
7+
#
8+
##
9+
# Copyright (c) Microsoft Corporation.
10+
# SPDX-License-Identifier: BSD-2-Clause-Patent
11+
##
12+
13+
name: Coverage
14+
15+
on:
16+
workflow_dispatch:
17+
pull_request:
18+
paths:
19+
- '.pytool/**'
20+
- 'OpensslPkg/**'
21+
- 'MU_BASECORE/**'
22+
- '.github/workflows/coverage.yml'
23+
push:
24+
branches:
25+
- main
26+
paths:
27+
- '.pytool/**'
28+
- 'OpensslPkg/**'
29+
- 'MU_BASECORE/**'
30+
- '.github/workflows/coverage.yml'
31+
32+
env:
33+
TOOL_CHAIN_TAG: GCC5
34+
PACKAGE: OpensslPkg
35+
TARGET: NOOPT
36+
37+
jobs:
38+
coverage:
39+
runs-on: ubuntu-latest
40+
container:
41+
image: ghcr.io/microsoft/mu_devops/ubuntu-24-dev:8b4aa53
42+
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v6
46+
47+
- name: Set Safe Directory
48+
run: git config --global --add safe.directory '*'
49+
50+
- name: Install Python dependencies
51+
run: |
52+
python -m pip install --upgrade pip
53+
pip install -r pip-requirements.txt
54+
55+
- name: Install lcov
56+
run: apt-get install -y --no-install-recommends lcov
57+
58+
- name: Setup
59+
run: stuart_setup -c .pytool/CISettings.py -p ${{ env.PACKAGE }}
60+
61+
- name: CI Setup
62+
run: stuart_ci_setup -c .pytool/CISettings.py -p ${{ env.PACKAGE }}
63+
64+
- name: Update
65+
run: stuart_update -c .pytool/CISettings.py -p ${{ env.PACKAGE }}
66+
67+
- name: Build and Run Tests with Coverage
68+
run: >-
69+
stuart_ci_build
70+
-c .pytool/CISettings.py
71+
-p ${{ env.PACKAGE }}
72+
-t ${{ env.TARGET }}
73+
-d HostUnitTestCompilerPlugin=run
74+
TOOL_CHAIN_TAG=${{ env.TOOL_CHAIN_TAG }}
75+
CODE_COVERAGE=TRUE
76+
77+
- name: Filter Coverage to BaseCryptLib
78+
if: always()
79+
run: |
80+
BUILD_OUTPUT="Build/${{ env.PACKAGE }}/HostTest/${{ env.TARGET }}_${{ env.TOOL_CHAIN_TAG }}"
81+
COVERAGE_INFO="${BUILD_OUTPUT}/total-coverage.info"
82+
FILTERED_INFO="coverage_report/basecryptlib-coverage.info"
83+
FILTERED_XML="coverage_report/basecryptlib_coverage.xml"
84+
85+
mkdir -p coverage_report
86+
87+
if [[ ! -f "${COVERAGE_INFO}" ]]; then
88+
echo "Coverage tracefile not found: ${COVERAGE_INFO}"
89+
exit 1
90+
fi
91+
92+
# Keep all BaseCryptLib sources generically, then drop helper folders.
93+
lcov --extract "${COVERAGE_INFO}" \
94+
'*/OpensslPkg/Library/BaseCryptLib/*' \
95+
--output-file "${FILTERED_INFO}.tmp"
96+
97+
lcov --remove "${FILTERED_INFO}.tmp" \
98+
'*/OpensslPkg/Library/BaseCryptLib/Info/*' \
99+
'*/OpensslPkg/Library/BaseCryptLib/Setup/*' \
100+
'*/OpensslPkg/Library/BaseCryptLib/SysCall/*' \
101+
--ignore-errors unused \
102+
--output-file "${FILTERED_INFO}"
103+
104+
rm -f "${FILTERED_INFO}.tmp"
105+
106+
# Generate HTML and Cobertura from the filtered lcov tracefile.
107+
genhtml "${FILTERED_INFO}" \
108+
--output-directory coverage_report/html \
109+
--title "${{ env.PACKAGE }} BaseCryptLib Coverage" \
110+
--legend --quiet || true
111+
112+
python -m lcov_cobertura "${FILTERED_INFO}" \
113+
-b "${GITHUB_WORKSPACE}" \
114+
-o "${FILTERED_XML}"
115+
116+
- name: Upload coverage to codecov
117+
uses: codecov/codecov-action@v5
118+
with:
119+
files: coverage_report/basecryptlib_coverage.xml
120+
token: ${{ secrets.CODECOV_TOKEN }}
121+
fail_ci_if_error: true
122+
123+
- name: Upload HTML Coverage Report
124+
if: always()
125+
uses: actions/upload-artifact@v6
126+
with:
127+
name: ${{ env.PACKAGE }}-coverage-html
128+
path: coverage_report/html/
129+
retention-days: 7

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Features/MM_SUPV/
66
Common/MU/
77
__pycache__/
88
*.pyc
9+
coverage_report/

codecov.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# @file codecov.yml
2+
#
3+
# Codecov configuration file for mu_crypto_release repositories.
4+
#
5+
# Copyright (c) Microsoft Corporation
6+
# SPDX-License-Identifier: Apache-2.0
7+
##
8+
codecov:
9+
require_ci_to_pass: true
10+
coverage:
11+
precision: 2
12+
round: nearest
13+
range: 80..90 # 0-79% red, 80-89% yellow, 90-100% green
14+
status:
15+
project:
16+
default:
17+
target: 80% # Target 80% coverage for the project
18+
only_pulls: true
19+
patch:
20+
default:
21+
target: 80% # Target 80% coverage for the patch
22+
only_pulls: true
23+
comment:
24+
after_n_builds: 2
25+
layout: "condensed_header, condensed_files, condensed_footer"
26+
hide_project_coverage: true # Only show patch coverage in a PR comment

0 commit comments

Comments
 (0)