[#258] MCDC-Star Testing #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CryptoLib Coverage and MC/DC Analysis | |
on: | |
push: | |
branches: | |
- 258-cyclomatic-complexity-and-mcdc-in-ci | |
paths-ignore: | |
- 'doc/coverage/line-coverage-badge.svg' | |
- 'doc/coverage/branch-coverage-badge.svg' | |
pull_request: | |
branches: | |
- 258-cyclomatic-complexity-and-mcdc-in-ci | |
jobs: | |
coverage: | |
runs-on: ubuntu-latest | |
container: | |
image: ivvitc/cryptolib:20250102 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch full history for branch operations | |
- name: Configure Safe Directory | |
run: git config --global --add safe.directory $GITHUB_WORKSPACE | |
- name: Install Dependencies and MCDC-Star | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
echo "Installing project dependencies and MCDC-Star..." | |
apt-get update | |
apt-get install -y \ | |
lcov libcurl4-openssl-dev libmariadb-dev libmariadb-dev-compat \ | |
python3 bc build-essential cmake git | |
git clone https://github.com/nist-sws/mcdc-star.git | |
cd mcdc-star | |
mkdir build | |
cd build | |
cmake .. | |
make | |
echo "Dependencies and MCDC-Star installed successfully." | |
- name: Build and Run Tests with Instrumentation | |
run: | | |
echo "Building the project and running tests with instrumentation..." | |
export CFLAGS="-fprofile-arcs -ftest-coverage -g" | |
bash ${GITHUB_WORKSPACE}/support/scripts/build_internal.sh | |
echo "Build and test execution completed." | |
- name: Analyze MC/DC Coverage with MCDC-Star | |
run: | | |
echo "Analyzing MC/DC coverage using MCDC-Star..." | |
mkdir -p doc/coverage | |
cd mcdc-star/build | |
./mcdc_star --input $GITHUB_WORKSPACE --output $GITHUB_WORKSPACE/doc/coverage/mcdc_report.txt | |
echo "MC/DC analysis completed. Report available at doc/coverage/mcdc_report.txt" | |
- name: Generate Line and Branch Coverage Reports | |
run: | | |
echo "Generating line and branch coverage reports..." | |
mkdir -p doc/coverage | |
gcovr --xml-pretty -o doc/coverage/coverage_report.xml | |
gcovr --html --html-details -o doc/coverage/coverage_report.html | |
echo "Coverage reports generated." | |
- name: Generate Coverage Badges | |
run: | | |
echo "Generating coverage badges..." | |
LINE_COVERAGE=$(grep -oP '(?<=<coverage line-rate=")[0-9.]+(?=")' doc/coverage/coverage_report.xml | head -n 1) | |
BRANCH_COVERAGE=$(grep -oP '(?<=branch-rate=")[0-9.]+(?=")' doc/coverage/coverage_report.xml | head -n 1) | |
LINE_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$LINE_COVERAGE * 100" | bc)) | |
BRANCH_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$BRANCH_COVERAGE * 100" | bc)) | |
if [ "$LINE_COVERAGE_PERCENT" -ge 80 ]; then LINE_COLOR="brightgreen"; elif [ "$LINE_COVERAGE_PERCENT" -ge 50 ]; then LINE_COLOR="yellow"; else LINE_COLOR="red"; fi | |
if [ "$BRANCH_COVERAGE_PERCENT" -ge 80 ]; then BRANCH_COLOR="brightgreen"; elif [ "$BRANCH_COVERAGE_PERCENT" -ge 50 ]; then BRANCH_COLOR="yellow"; else BRANCH_COLOR="red"; fi | |
curl -o doc/coverage/line-coverage-badge.svg "https://img.shields.io/badge/line%20coverage-${LINE_COVERAGE_PERCENT}%25-${LINE_COLOR}" | |
curl -o doc/coverage/branch-coverage-badge.svg "https://img.shields.io/badge/branch%20coverage-${BRANCH_COVERAGE_PERCENT}%25-${BRANCH_COLOR}" | |
- name: Commit and Upload Coverage Reports | |
run: | | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
git add doc/coverage/ | |
git commit -m "Update MC/DC coverage reports and badges" || echo "No changes to commit" | |
git push origin HEAD | |
- name: Archive Coverage Reports | |
uses: actions/upload-artifact@v3 | |
with: | |
name: mcdc-coverage-reports | |
path: doc/coverage |