[#258] MCDC Test #54
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: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 python3-pip python3-venv gcovr bc pipx | |
pipx install --system-site-packages mcdc-checker | |
- name: Install Clang Dependencies | |
run: | | |
echo "Installing Clang libraries and Python bindings..." | |
apt-get update | |
apt-get install -y clang libclang-dev | |
pip install clang | |
- name: Build with Coverage Flags | |
run: | | |
export CFLAGS="-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: Run MC/DC Analysis | |
run: | | |
# Ensure the output directory exists | |
echo "Creating coverage directory..." | |
mkdir -p $GITHUB_WORKSPACE/doc/coverage | |
# Add pipx installation path to PATH | |
echo "Adding pipx path to PATH..." | |
export PATH=$PATH:/github/home/.local/bin | |
# Ensure pipx path is properly set up | |
echo "Ensuring pipx path is added..." | |
pipx ensurepath || true | |
export PATH=$PATH:/github/home/.local/bin # Re-export PATH for good measure | |
# Debug: Check pipx installation | |
echo "Checking pipx-installed binaries in /github/home/.local/bin" | |
ls -la /github/home/.local/bin || true | |
echo "Checking pipx environment:" | |
pipx list || true | |
# Debug: Confirm mcdc-checker is available | |
echo "Checking if mcdc-checker is available..." | |
which mcdc-checker || { echo "mcdc-checker not found in PATH"; exit 1; } | |
echo "mcdc-checker is available; checking usage information..." | |
mcdc-checker --help || { echo "mcdc-checker usage check failed"; exit 1; } | |
# Debug: List all C source files | |
echo "Listing C source files:" | |
find $GITHUB_WORKSPACE/src -type f -name '*.c' -exec echo {} \; | |
# Run mcdc-checker without failing the step | |
echo "Running mcdc-checker..." | |
mcdc-checker -a -j $GITHUB_WORKSPACE/doc/coverage/mcdc_report.json \ | |
-I $GITHUB_WORKSPACE/include $(find $GITHUB_WORKSPACE/src -type f -name '*.c' | tr '\n' ' ') \ | |
> $GITHUB_WORKSPACE/doc/coverage/mcdc_checker_output.log 2>&1 || true | |
shell: bash | |
- name: Display MC/DC Checker Output | |
run: | | |
echo "Displaying MC/DC Checker Output:" | |
cat $GITHUB_WORKSPACE/doc/coverage/mcdc_checker_output.log | |
shell: bash | |
- name: Display MC/DC Checker Output | |
run: | | |
echo "Displaying MC/DC Checker Output:" | |
cat $GITHUB_WORKSPACE/doc/coverage/mcdc_checker_output.log | |
shell: bash | |
- name: Upload All Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: all-artifacts | |
path: doc/coverage/ |