|
| 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 |
0 commit comments