Skip to content

[#258] MCDC Test

[#258] MCDC Test #38

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:20240814
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
env:
DEBIAN_FRONTEND: noninteractive
TZ: Etc/UTC
run: |
apt-get update
apt-get install -y lcov libcurl4-openssl-dev libmariadb-dev libmariadb-dev-compat python3 gcovr bc docker.io
pip install pycryptodome
curl -LS https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.50.tar.bz2 -o /tmp/libgpg-error-1.50.tar.bz2
tar -xjf /tmp/libgpg-error-1.50.tar.bz2 -C /tmp/
cd /tmp/libgpg-error-1.50 && ./configure && make install
curl -LS https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.11.0.tar.bz2 -o /tmp/libgcrypt-1.11.0.tar.bz2
tar -xjf /tmp/libgcrypt-1.11.0.tar.bz2 -C /tmp/
cd /tmp/libgcrypt-1.11.0 && ./configure && make install
ldconfig
- name: Build with Coverage Flags
run: |
export CFLAGS="-fprofile-arcs -ftest-coverage -g"
export CXXFLAGS="-fprofile-arcs -ftest-coverage -g"
bash ${GITHUB_WORKSPACE}/support/scripts/build_internal.sh
- name: Generate Coverage Report and Badges
run: |
mkdir -p doc/coverage
gcovr --branches --xml-pretty --exclude-unreachable-branches -o doc/coverage/coverage_report.xml
gcovr --branches --html --html-details -o doc/coverage/coverage_report.html
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 Coverage Badges
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add doc/coverage/line-coverage-badge.svg
git add doc/coverage/branch-coverage-badge.svg
git commit -m "Update coverage badges" || echo "No changes to commit"
git push origin HEAD
- name: Run MC/DC Analysis
run: |
# Pull the mcdc_checker Docker image
docker pull registry.gitlab.com/gtd-gmbh/mcdc-checker/mcdc-checker:latest
# Run mcdc_checker on source files
docker run --rm -v $GITHUB_WORKSPACE:/workspace -w /workspace registry.gitlab.com/gtd-gmbh/mcdc-checker/mcdc-checker \
mcdc_checker -a -j /workspace/doc/coverage/mcdc_report.json /workspace/src
- name: Upload All Artifacts
uses: actions/upload-artifact@v3
with:
name: all-artifacts
path: doc/coverage/