diff --git a/.github/workflows/llvm_cov.yml b/.github/workflows/coverage.yml similarity index 71% rename from .github/workflows/llvm_cov.yml rename to .github/workflows/coverage.yml index 0299600..25723b0 100644 --- a/.github/workflows/llvm_cov.yml +++ b/.github/workflows/coverage.yml @@ -6,7 +6,7 @@ on: # yamllint disable-line rule:truthy branches: ['*'] jobs: - llvm-cov: + lcov: runs-on: ubuntu-latest container: image: dtors/base-cpp:latest @@ -16,5 +16,5 @@ jobs: uses: actions/checkout@v4 - name: Run Coverage Script - run: bazelisk run //tools/coverage:llvm_cov --platforms=//bazel/platforms:x86_64_linux -- -t //examples/cpp:test -s + run: bazelisk run //tools/coverage:lcov --platforms=//bazel/platforms:x86_64_linux -- -t //examples/cpp:test shell: bash diff --git a/tools/coverage/BUILD b/tools/coverage/BUILD index d176355..49af797 100644 --- a/tools/coverage/BUILD +++ b/tools/coverage/BUILD @@ -2,3 +2,8 @@ sh_binary( name = "llvm_cov", srcs = ["llvm_cov.sh"], ) + +sh_binary( + name = "lcov", + srcs = ["lcov.sh"], +) diff --git a/tools/coverage/lcov.sh b/tools/coverage/lcov.sh new file mode 100755 index 0000000..7b59e37 --- /dev/null +++ b/tools/coverage/lcov.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -e + +usage() { + echo " -t BAZEL_TESTS The test target (e.g., //path/to/test-target)" + echo " -o OUTPUT_DIR Directory for output (default is temp directory)" + echo " -h Display this help message" +} + +while getopts "t:o:h" option; do + case "${option}" in + t) BAZEL_TESTS=${OPTARG} ;; + o) OUTPUT_DIR=${OPTARG} ;; + h | *) + usage + exit 1 + ;; + esac +done + +if [[ -z "${BAZEL_TESTS}" ]]; then + echo "ERROR: Missing required arguments." + usage + exit 1 +fi + +OUTPUT_DIR="${OUTPUT_DIR:-"$(mktemp -d)/cov_report"}" + +echo "INFO: Tests target: ${BAZEL_TESTS}" +echo "INFO: Output directory: ${OUTPUT_DIR}" + +readonly WORKSPACE=$(cd "$(dirname "$(readlink -f "${0}")")" && bazel info workspace) + +function run_coverage_tests() { + echo -e "\nINFO: Run test targets\n" + bazel coverage \ + --nocache_test_results \ + --experimental_fetch_all_coverage_outputs \ + --experimental_split_coverage_postprocessing \ + --strategy=CoverageReport=local \ + --combined_report=lcov \ + -- ${BAZEL_TESTS} +} + +function calculate_coverage() { + echo -e "\nINFO: Generating HTML coverage report\n" + genhtml --branch-coverage --output genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat" +} + +function main() { + pushd "${WORKSPACE}" || return + run_coverage_tests + calculate_coverage + popd || return +} + +main