diff --git a/.bazelrc b/.bazelrc index 0f4104e..06697f6 100644 --- a/.bazelrc +++ b/.bazelrc @@ -63,16 +63,16 @@ common:arm64-qnx --config=qnx_arm64 common --extra_toolchains=@gcc_toolchain//:host_gcc_12 common --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_x86_64_unknown_linux_gnu -# With this instrumentation filter for our two main components, we ensure that `bazel coverage //...` is yielding the correct results -coverage --instrumentation_filter="^//score/datarouter[/:],^//score/mw/log[/:],-//score/mw/.*/test[/:]" -coverage --experimental_generate_llvm_lcov -coverage --experimental_use_llvm_covmap +# Coverage configuration for C++ +coverage --features=coverage coverage --combined_report=lcov -coverage --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main -coverage --test_env=COVERAGE_GCOV_OPTIONS=-bcu -# TODO set toolchain feature once possible -# These compile time options are required to cover abnormal termination cases. In GCC one can use `__gcc_dump()`, but this does not work with LLVM -# LLVM provided these compile-time options in combination with a specific profile setting which is enabled in bazel via `LLVM_PROFILE_CONTINUOUS_MODE` -coverage --test_env=LLVM_PROFILE_CONTINUOUS_MODE=1 -coverage --cxxopt -mllvm -coverage --cxxopt -runtime-counter-relocation +coverage --cache_test_results=no +coverage --instrumentation_filter="^//score[/:]" + +# Coverage configuration +build:blcov-x86_64-linux --incompatible_strict_action_env +build:blcov-x86_64-linux --platforms=@score_bazel_platforms//:x86_64-linux-gcc_12.2.0-posix +build:blcov-x86_64-linux --extra_toolchains=@score_gcc_x86_64_toolchain//:x86_64-linux-gcc_12.2.0-posix +test:blcov-x86_64-linux --build_tests_only +test:blcov-x86_64-linux --test_tag_filters=-manual +test:blcov-x86_64-linux --test_output=errors diff --git a/.github/workflows/coverage_report.yml b/.github/workflows/coverage_report.yml new file mode 100644 index 0000000..aa29f24 --- /dev/null +++ b/.github/workflows/coverage_report.yml @@ -0,0 +1,65 @@ +# ******************************************************************************* +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +name: Code Coverage +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - main + merge_group: + types: [checks_requested] + +jobs: + coverage-report: + runs-on: ubuntu-22.04 + + permissions: + contents: read + + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + + - name: Install lcov + run: | + sudo apt-get update + sudo apt-get install -y lcov + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.18.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + cache-save: ${{ github.event_name != 'pull_request' }} + + - name: Run Bazel Coverage + run: | + bazel coverage --config=blcov-x86_64-linux -- //score/... //tests/... + - name: Generate HTML Coverage Report + run: | + genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat" \ + -o=cpp_coverage \ + --show-details \ + --legend \ + --function-coverage \ + --branch-coverage + shell: bash + + - name: Upload Coverage Artifacts + uses: actions/upload-artifact@v6 + with: + name: ${{ github.event.repository.name }}_coverage_report + path: cpp_coverage/ + retention-days: 30 diff --git a/MODULE.bazel b/MODULE.bazel index cfd7162..cb14c94 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -26,7 +26,7 @@ bazel_dep(name = "buildifier_prebuilt", version = "7.3.1") bazel_dep(name = "platforms", version = "1.0.0") # S-CORE process rules -bazel_dep(name = "score_bazel_platforms", version = "0.0.3") +bazel_dep(name = "score_bazel_platforms", version = "0.0.4") bazel_dep(name = "score_docs_as_code", version = "2.2.0") bazel_dep(name = "score_tooling", version = "1.0.4") bazel_dep(name = "score_rust_policies", version = "0.0.3") @@ -35,6 +35,7 @@ bazel_dep(name = "score_process", version = "1.4.0", dev_dependency = True) bazel_dep(name = "score_platform", version = "0.5.1", dev_dependency = True) # Toolchains and extensions +bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.2.0", dev_dependency = True) bazel_dep(name = "score_toolchains_gcc", version = "0.5", dev_dependency = True) bazel_dep(name = "score_toolchains_qnx", version = "0.0.6", dev_dependency = True) bazel_dep(name = "score_toolchains_rust", version = "0.4.0", dev_dependency = True) @@ -51,12 +52,23 @@ git_override( # Extensions +gcc_cpp = use_extension("@score_bazel_cpp_toolchains//extensions:gcc.bzl", "gcc", dev_dependency = True) +gcc_cpp.toolchain( + name = "score_gcc_x86_64_toolchain", + target_cpu = "x86_64", + target_os = "linux", + use_default_package = True, + version = "12.2.0", +) +use_repo(gcc_cpp, "score_gcc_x86_64_toolchain") + gcc = use_extension("@score_toolchains_gcc//extentions:gcc.bzl", "gcc", dev_dependency = True) gcc.toolchain( sha256 = "457f5f20f57528033cb840d708b507050d711ae93e009388847e113b11bf3600", strip_prefix = "x86_64-unknown-linux-gnu", url = "https://github.com/eclipse-score/toolchains_gcc_packages/releases/download/0.0.1/x86_64-unknown-linux-gnu_gcc12.tar.gz", ) +use_repo(gcc, "gcc_toolchain", "gcc_toolchain_gcc") # TRLC dependency for requirements traceability bazel_dep(name = "trlc", version = "0.0.0", dev_dependency = True) @@ -66,8 +78,6 @@ git_override( remote = "https://github.com/bmw-software-engineering/trlc.git", ) -use_repo(gcc, "gcc_toolchain", "gcc_toolchain_gcc") - toolchains_qnx = use_extension("@score_toolchains_qnx//:extensions.bzl", "toolchains_qnx", dev_dependency = True) toolchains_qnx.sdp( sha256 = "f2e0cb21c6baddbcb65f6a70610ce498e7685de8ea2e0f1648f01b327f6bac63",