From 72835b53c2c292dba84e252e46d7f88534af710b Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Tue, 20 Jan 2026 11:10:28 +0600 Subject: [PATCH 01/10] ignore `coverage` directory from vcs (#270) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 98212bce0..ebf4519e8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ doc/api/ # Other stuff tmp_test/ +coverage/ *.sv *.vcd *_fsm.md From 46c035d45cc7cb17912600d5327873ee67ee0111 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Tue, 20 Jan 2026 11:10:56 +0600 Subject: [PATCH 02/10] added `coverage` as dev deps (#270) --- pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/pubspec.yaml b/pubspec.yaml index f9672b2c4..a0f3395ad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,4 +17,5 @@ dependencies: dev_dependencies: benchmark_harness: ^2.2.0 + coverage: ^1.10.0 yaml: ^3.1.1 From 78cebdf8fab82fd17ca02f90df47c085841fde85 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Tue, 20 Jan 2026 11:16:49 +0600 Subject: [PATCH 03/10] script to generate badge for coverage (#270) --- tool/gh_actions/generate_coverage.sh | 99 ++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 tool/gh_actions/generate_coverage.sh diff --git a/tool/gh_actions/generate_coverage.sh b/tool/gh_actions/generate_coverage.sh new file mode 100755 index 000000000..ce9ce5584 --- /dev/null +++ b/tool/gh_actions/generate_coverage.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +# +# generate_coverage.sh +# Generate code coverage and SVG badge +# +# 2026 January 20 +# Author: Maifee Ul Asad + +set -euo pipefail + +# Remove old coverage data +rm -rf coverage + +# Run tests with coverage +dart test --coverage=coverage || true + +# Check if coverage was generated +if [ ! -d "coverage" ]; then + echo "Error: Coverage directory not created" + exit 1 +fi + +# Format to LCOV +dart run coverage:format_coverage \ + --lcov \ + --in=coverage \ + --out=coverage/lcov.info \ + --packages=.dart_tool/package_config.json \ + --report-on=lib + +# Install lcov if needed +if ! command -v lcov &> /dev/null; then + if [ -n "${CI:-}" ] || [ -n "${GITHUB_ACTIONS:-}" ]; then + sudo apt update -y + sudo apt install -y lcov + fi +fi + +# Extract coverage percentage +if command -v lcov &> /dev/null; then + SUMMARY=$(lcov --summary coverage/lcov.info 2>&1 | grep -E "lines\.*:") + PERCENT=$(echo "$SUMMARY" | grep -oP '\d+\.\d+' | head -1) + echo "Coverage: ${PERCENT}%" +else + PERCENT="0.0" + echo "Coverage: 0.0%" +fi + +# Determine color +if (( $(echo "$PERCENT >= 90" | bc -l) )); then + COLOR="#4c1" # bright green +elif (( $(echo "$PERCENT >= 80" | bc -l) )); then + COLOR="#97ca00" # green +elif (( $(echo "$PERCENT >= 70" | bc -l) )); then + COLOR="#dfb317" # yellow +elif (( $(echo "$PERCENT >= 60" | bc -l) )); then + COLOR="#fe7d37" # orange +else + COLOR="#e05d44" # red +fi + +# Calculate dimensions +TEXT="${PERCENT}%" +TEXT_LEN=${#TEXT} +TEXT_WIDTH=$((TEXT_LEN * 63)) +LABEL_WIDTH=63 +VALUE_WIDTH=$((TEXT_WIDTH / 10 + 10)) +TOTAL_WIDTH=$((LABEL_WIDTH + VALUE_WIDTH)) + +# Generate SVG badge +# Style credit goes to shields.io +cat > /tmp/coverage-badge.svg << EOFSVG + + coverage: ${TEXT} + + + + + + + + + + + + + + + coverage + + ${TEXT} + + +EOFSVG + +echo "Generated SVG badge at /tmp/coverage-badge.svg" From 875a0bf72cec1e14f164cef10262b404e88771fd Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Tue, 20 Jan 2026 11:17:16 +0600 Subject: [PATCH 04/10] action to generate and push coverage badge (#270) --- .github/workflows/coverage.yml | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..d09bf9ae7 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,52 @@ +name: Coverage + +on: + push: + branches: + - main + - ci-repo-stat-maifee + workflow_dispatch: + +permissions: + contents: write + +jobs: + coverage: + name: Code Coverage + timeout-minutes: 60 + runs-on: ${{ (github.repository_owner == 'intel' || github.repository_owner == 'maifeeulasad') && ('intel-ubuntu-latest' || 'ubuntu-latest') }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Dart + uses: dart-lang/setup-dart@v1 + + - name: Install dependencies + run: tool/gh_actions/install_dependencies.sh + + - name: Install Icarus Verilog + run: tool/gh_actions/install_iverilog.sh + + - name: Generate coverage and badge + run: tool/gh_actions/generate_coverage.sh + + - name: Commit coverage badge + run: | + BRANCH_NAME="${{ github.ref_name }}" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + # Fetch and checkout badges branch + git fetch origin badges:badges 2>/dev/null || git checkout --orphan badges + git checkout badges 2>/dev/null || true + + # Clean and copy badge + git rm -rf . 2>/dev/null || true + mkdir -p coverage + cp /tmp/coverage-badge.svg "coverage/${BRANCH_NAME}.svg" + + git add "coverage/${BRANCH_NAME}.svg" + git diff --staged --quiet || git commit -m "Update coverage badge for ${BRANCH_NAME} [skip ci]" + + git push origin badges --force From 17cd653dcd83f503c77b9dedd3841a3ea83e3def Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Tue, 20 Jan 2026 11:20:22 +0600 Subject: [PATCH 05/10] render coverage badge in readme (#270) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 823200b36..457505dc3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ # Rapid Open Hardware Development (ROHD) Framework [![Tests](https://github.com/intel/rohd/actions/workflows/general.yml/badge.svg?event=push)](https://github.com/intel/rohd/actions/workflows/general.yml) +[![Coverage](https://raw.githubusercontent.com/intel/rohd/badges/coverage/main.svg)](https://github.com/intel/rohd/actions/workflows/coverage.yml) [![API Docs](https://img.shields.io/badge/API%20Docs-generated-success)](https://intel.github.io/rohd/rohd/rohd-library.html) [![Chat](https://img.shields.io/discord/1001179329411166267?label=Chat)](https://discord.gg/jubxF84yGw) [![License](https://img.shields.io/badge/License-BSD--3-blue)](https://github.com/intel/rohd/blob/main/LICENSE) From da68e63156369f386bbe7e27d0888399d963df90 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Tue, 20 Jan 2026 11:21:49 +0600 Subject: [PATCH 06/10] cleanup author specific contrib (#270) --- .github/workflows/coverage.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d09bf9ae7..ecc52164d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - ci-repo-stat-maifee workflow_dispatch: permissions: @@ -14,7 +13,7 @@ jobs: coverage: name: Code Coverage timeout-minutes: 60 - runs-on: ${{ (github.repository_owner == 'intel' || github.repository_owner == 'maifeeulasad') && ('intel-ubuntu-latest' || 'ubuntu-latest') }} + runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }} steps: - name: Checkout uses: actions/checkout@v4 From e86d5d89d54a37dd81c0f690ad042d08f68d4df5 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Sun, 8 Feb 2026 16:11:05 +0600 Subject: [PATCH 07/10] refactor merge cov gen script w svg gen script (#270) --- tool/generate_coverage.sh | 122 ++++++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 10 deletions(-) diff --git a/tool/generate_coverage.sh b/tool/generate_coverage.sh index d217179cb..0ab202ff3 100755 --- a/tool/generate_coverage.sh +++ b/tool/generate_coverage.sh @@ -1,13 +1,15 @@ #!/bin/bash -# Copyright (C) 2022-2023 Intel Corporation +# Copyright (C) 2022-2026 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause # # generate_coverage.sh # Determines code coverage by tests and generates an HTML representation. +# and SVG badge with additional arguments for CI integration. # # 2022 May 5 # Author: Max Korbel +# Author: Maifee Ul Asad ### WARNING ### # The "x" option outputs all script commands. This allows you to track @@ -16,15 +18,115 @@ set -euxo pipefail #=============# -declare -r coverage_dir='build/coverage' -declare -r html_dir="${coverage_dir}/genhtml" +# Parse arguments +GENERATE_SVG=false +for arg in "$@"; do + case $arg in + --generate-svg) + GENERATE_SVG=true + shift + ;; + *) + ;; + esac +done -# requires enabling "coverage": -# > dart pub global activate coverage -dart pub global run coverage:test_with_coverage --branch-coverage --out=${coverage_dir} +# Remove old coverage data +rm -rf coverage -# requires installing "lcov": -# > sudo apt install lcov -genhtml --output-directory=${html_dir} --rc lcov_branch_coverage=1 ${coverage_dir}/lcov.info +# Run tests with coverage +dart test --coverage=coverage || true -printf '\n%s\n\n' "Open ${html_dir}/index.html to review code coverage results." +# Check if coverage was generated +if [ ! -d "coverage" ]; then + echo "Error: Coverage directory not created" + exit 1 +fi + +# Format to LCOV +dart run coverage:format_coverage \ + --lcov \ + --in=coverage \ + --out=coverage/lcov.info \ + --packages=.dart_tool/package_config.json \ + --report-on=lib + +# Generate HTML report +genhtml -o coverage/html coverage/lcov.info --branch-coverage +printf '\n%s\n\n' "Open coverage/html/index.html to review code coverage results." + +# Install lcov if needed +if ! command -v lcov &> /dev/null; then + if [ -n "${CI:-}" ] || [ -n "${GITHUB_ACTIONS:-}" ]; then + sudo apt update -y + sudo apt install -y lcov + fi +fi + +# Extract coverage percentage +if command -v lcov &> /dev/null; then + SUMMARY=$(lcov --summary coverage/lcov.info 2>&1 | grep -E "lines\.*:") + PERCENT=$(echo "$SUMMARY" | grep -oP '\d+\.\d+' | head -1) + echo "Coverage: ${PERCENT}%" +else + PERCENT="Generation Failed" + echo "Coverage generation failed" +fi + +# Determine color +if (( $(echo "$PERCENT >= 90" | bc -l) )); then + COLOR="#4c1" # bright green +elif (( $(echo "$PERCENT >= 80" | bc -l) )); then + COLOR="#97ca00" # green +elif (( $(echo "$PERCENT >= 70" | bc -l) )); then + COLOR="#dfb317" # yellow +elif (( $(echo "$PERCENT >= 60" | bc -l) )); then + COLOR="#fe7d37" # orange +else + COLOR="#e05d44" # red +fi +if [ "$PERCENT" = "Generation Failed" ]; then + COLOR="#e05d44" # red +fi + +# Calculate dimensions +if [ "$PERCENT" = "Generation Failed" ]; then + TEXT="Error: coverage collection failed!" +else + TEXT="${PERCENT}%" +fi +TEXT_LEN=${#TEXT} +TEXT_WIDTH=$((TEXT_LEN * 63)) +LABEL_WIDTH=63 +VALUE_WIDTH=$((TEXT_WIDTH / 10 + 10)) +TOTAL_WIDTH=$((LABEL_WIDTH + VALUE_WIDTH)) + +# Generate SVG badge only if requested +if [ "$GENERATE_SVG" = true ]; then + # Style credit goes to shields.io + cat > /tmp/coverage-badge.svg << EOFSVG + + coverage: ${TEXT} + + + + + + + + + + + + + + + coverage + + ${TEXT} + + +EOFSVG + + echo "Generated SVG badge at /tmp/coverage-badge.svg" +fi From 67bf6aaff4f1442d811f7ee920cd5835acdabf91 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Sun, 8 Feb 2026 16:11:32 +0600 Subject: [PATCH 08/10] refactor use `--generate-svg` to generate svg from coverage (#270) --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ecc52164d..9a2362674 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -28,7 +28,7 @@ jobs: run: tool/gh_actions/install_iverilog.sh - name: Generate coverage and badge - run: tool/gh_actions/generate_coverage.sh + run: tool/generate_coverage.sh --generate-svg - name: Commit coverage badge run: | From 02bd45bba0eea1db211d74d267406b4f74bf3f07 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Sun, 8 Feb 2026 16:11:55 +0600 Subject: [PATCH 09/10] cleanup of merged unused script (#270) --- tool/gh_actions/generate_coverage.sh | 99 ---------------------------- 1 file changed, 99 deletions(-) delete mode 100755 tool/gh_actions/generate_coverage.sh diff --git a/tool/gh_actions/generate_coverage.sh b/tool/gh_actions/generate_coverage.sh deleted file mode 100755 index ce9ce5584..000000000 --- a/tool/gh_actions/generate_coverage.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2026 Intel Corporation -# SPDX-License-Identifier: BSD-3-Clause -# -# generate_coverage.sh -# Generate code coverage and SVG badge -# -# 2026 January 20 -# Author: Maifee Ul Asad - -set -euo pipefail - -# Remove old coverage data -rm -rf coverage - -# Run tests with coverage -dart test --coverage=coverage || true - -# Check if coverage was generated -if [ ! -d "coverage" ]; then - echo "Error: Coverage directory not created" - exit 1 -fi - -# Format to LCOV -dart run coverage:format_coverage \ - --lcov \ - --in=coverage \ - --out=coverage/lcov.info \ - --packages=.dart_tool/package_config.json \ - --report-on=lib - -# Install lcov if needed -if ! command -v lcov &> /dev/null; then - if [ -n "${CI:-}" ] || [ -n "${GITHUB_ACTIONS:-}" ]; then - sudo apt update -y - sudo apt install -y lcov - fi -fi - -# Extract coverage percentage -if command -v lcov &> /dev/null; then - SUMMARY=$(lcov --summary coverage/lcov.info 2>&1 | grep -E "lines\.*:") - PERCENT=$(echo "$SUMMARY" | grep -oP '\d+\.\d+' | head -1) - echo "Coverage: ${PERCENT}%" -else - PERCENT="0.0" - echo "Coverage: 0.0%" -fi - -# Determine color -if (( $(echo "$PERCENT >= 90" | bc -l) )); then - COLOR="#4c1" # bright green -elif (( $(echo "$PERCENT >= 80" | bc -l) )); then - COLOR="#97ca00" # green -elif (( $(echo "$PERCENT >= 70" | bc -l) )); then - COLOR="#dfb317" # yellow -elif (( $(echo "$PERCENT >= 60" | bc -l) )); then - COLOR="#fe7d37" # orange -else - COLOR="#e05d44" # red -fi - -# Calculate dimensions -TEXT="${PERCENT}%" -TEXT_LEN=${#TEXT} -TEXT_WIDTH=$((TEXT_LEN * 63)) -LABEL_WIDTH=63 -VALUE_WIDTH=$((TEXT_WIDTH / 10 + 10)) -TOTAL_WIDTH=$((LABEL_WIDTH + VALUE_WIDTH)) - -# Generate SVG badge -# Style credit goes to shields.io -cat > /tmp/coverage-badge.svg << EOFSVG - - coverage: ${TEXT} - - - - - - - - - - - - - - - coverage - - ${TEXT} - - -EOFSVG - -echo "Generated SVG badge at /tmp/coverage-badge.svg" From cf3c3b057b240c58f3b17dc99a707de8a666bfc8 Mon Sep 17 00:00:00 2001 From: Maifee Ul Asad Date: Sun, 8 Feb 2026 16:16:02 +0600 Subject: [PATCH 10/10] remove coverage badge as it is not generated yet (#270) --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 457505dc3..823200b36 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ # Rapid Open Hardware Development (ROHD) Framework [![Tests](https://github.com/intel/rohd/actions/workflows/general.yml/badge.svg?event=push)](https://github.com/intel/rohd/actions/workflows/general.yml) -[![Coverage](https://raw.githubusercontent.com/intel/rohd/badges/coverage/main.svg)](https://github.com/intel/rohd/actions/workflows/coverage.yml) [![API Docs](https://img.shields.io/badge/API%20Docs-generated-success)](https://intel.github.io/rohd/rohd/rohd-library.html) [![Chat](https://img.shields.io/discord/1001179329411166267?label=Chat)](https://discord.gg/jubxF84yGw) [![License](https://img.shields.io/badge/License-BSD--3-blue)](https://github.com/intel/rohd/blob/main/LICENSE)