Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@ build:arm64-qnx --extra_toolchains=@score_qcc_aarch64_toolchain//:aarch64-qnx-sd
# -------------------------------------------------------------------------------
# Import local user workspace file, if exists
# -------------------------------------------------------------------------------
try-import %workspace%/user.bazelrc
# Unified LLVM source-based coverage (C++), see tools/coverage/ and
# @score_tooling//coverage. Use: bazel coverage --config=llvm_cov //score/... --build_tests_only
import %workspace%/tools/coverage/coverage.bazelrc

# Coverage configuration for C++
coverage --features=coverage
coverage --combined_report=lcov
coverage --cache_test_results=no
# Atomic counter updates prevent data corruption when tests use multiple threads.
coverage --cxxopt=-fprofile-update=atomic
# Pass branch (-b), cumulative (-c), and unconditional (-u) flags to gcov.
coverage --test_env=COVERAGE_GCOV_OPTIONS=-bcu
# Local user overrides — kept LAST so they can override everything above.
try-import %workspace%/user.bazelrc

# -------------------------------------------------------------------------------
# Sanitizer configurations — powered by score_cpp_policies
Expand Down
47 changes: 38 additions & 9 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
name: Test / Code Coverage (>85%)
name: Test / Code Coverage (>=85%)

permissions:
contents: read
Expand All @@ -30,11 +30,40 @@ on:

jobs:
code-coverage:
uses: eclipse-score/cicd-workflows/.github/workflows/cpp-coverage.yml@93aac16ada7d247bbb6ae926509ddea74cf5213a # v0.0.2
with:
bazel-target: "//score/..."
bazel-config: "x86_64-linux"
extra-bazel-flags: "--test_output=errors --nocache_test_results"
artifact-name-suffix: "_cpp"
retention-days: 10
min-coverage: 85
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4.2.2

- 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 == 'push' }}

- name: Run coverage (LLVM source-based, @score_tooling//coverage)
run: |
set -euo pipefail
bazel coverage --lockfile_mode=error --config=llvm_cov \
//score/... --build_tests_only

- name: Generate coverage report and enforce threshold
env:
COVERAGE_THRESHOLD: "85"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it defined by the tooling or where?
is there also the definitin of the branch coverage threshold?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run: |
set -euo pipefail
bazel run --lockfile_mode=error @score_tooling//coverage:generate_coverage_html -- \
--testlogs-subdir score \
--archive-dir coverage_artifact \
--yaml tools/coverage/coverage_justifications.yaml

# upload-artifact zips its input itself; the script assembles an
# unzipped directory (--archive-dir) to avoid a zip inside a zip.
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}_coverage_report_cpp
path: coverage_artifact
retention-days: 10
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ rust-project.json

# CodeQL local analysis output (any --output-dir placed inside the repo)
codeql-*/
coverage_*/
summary.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summary.md?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be updated to github summary page of the coverage job

7 changes: 7 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ dash_license_checker(
visibility = ["//visibility:public"],
)

exports_files(
[
# Used by the @score_tooling coverage reporter to locate the workspace root.
"MODULE.bazel",
],
)

# Add targets for formatting checks
use_format_targets(languages = [
"python",
Expand Down
15 changes: 14 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,20 @@ llvm = use_extension(
llvm.toolchain(
llvm_version = "19.1.7",
)
use_repo(llvm, "llvm_toolchain")

# Coverage-only Clang instance (covmap instrumentation for the LLVM coverage
# pipeline from @score_tooling//coverage; active only under --config=llvm_cov).
# Separate from the 19.1.7 instance above so clang-tidy behavior is untouched.
llvm.toolchain(
name = "llvm_toolchain_coverage",
cxx_standard = {"": "c++17"},
extra_known_features = [
"@score_tooling//coverage:enable_llvm_coverage_for_death_tests",
],
llvm_version = "22.1.7",
stdlib = {"": "stdc++"},
)
use_repo(llvm, "llvm_toolchain", "llvm_toolchain_coverage", "llvm_toolchain_coverage_llvm")

# grpc-java@1.66.0 has a BCR bug (extension no longer generates
# com_envoyproxy_protoc_gen_validate). Pulled transitively via
Expand Down
50 changes: 50 additions & 0 deletions tools/coverage/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# *******************************************************************************
# Copyright (c) 2026 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
# *******************************************************************************

load("@score_tooling//coverage:defs.bzl", "score_coverage_reporter", "score_coverage_scope")

# The production components of this module (the public faces the old
# cpp-coverage workflow also targeted via //score/...). The scope aspect walks
# their transitive in-workspace deps; test suites, mocks (*_mock,
# *_test_utils) and external deps are not reachable from these roots and stay
# out of the report. Untested in-scope files appear at exact 0% via the
# --empty-profile baseline. Keep this list in sync with the module's shipped
# components.
score_coverage_scope(
name = "coverage_scope",
testonly = True,
visibility = ["//visibility:private"],
deps = [
# Standalone public clock APIs, not reachable through the daemons:
"//score/time/steady_time",
"//score/time/system_time",
"//score/time/vehicle_time",
# The daemons transitively bring in clock_core, high_res_steady_clock
# and ts_client's gptp_ipc (verified via bazel query deps()).
# KNOWN GAP: the cc_binary entry-point sources themselves (main.cpp,
# time_daemon.cpp, time_slave.cpp) are not collected — cc_binary
# provides no CcInfo for the scope aspect. Entry-point wiring is not
# unit-testable; tracked as a scope-aspect enhancement in score_tooling.
"//score/time_daemon",
"//score/time_slave",
],
)

score_coverage_reporter(
name = "reporter_wrapper",
testonly = True,
coverage_scope = ":coverage_scope",
llvm_cov = "@llvm_toolchain_coverage//:llvm-cov",
llvm_cxxfilt = "@llvm_toolchain_coverage_llvm//:bin/llvm-cxxfilt",
llvm_profdata = "@llvm_toolchain_coverage//:llvm-profdata",
)
51 changes: 51 additions & 0 deletions tools/coverage/coverage.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# *******************************************************************************
# Copyright (c) 2026 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
# *******************************************************************************

# ============================================================================
# LLVM source-based coverage (Linux, Clang covmap) — C++
# Pipeline: @score_tooling//coverage (see its README.md for the guide).
# Use with: bazel coverage --config=llvm_cov //score/... --build_tests_only
#
# Do NOT combine with configs that register other C++ toolchains: the last
# --extra_toolchains wins resolution and a GCC toolchain produces no covmap.
# ============================================================================

coverage:llvm_cov --nocache_test_results
coverage:llvm_cov --cxxopt=-O0
coverage:llvm_cov --combined_report=lcov
coverage:llvm_cov --experimental_fetch_all_coverage_outputs

# Per-test .so files can carry clashing instrumentation between production and
# test code; the first object loaded wins, causing flaky coverage gaps.
coverage:llvm_cov --dynamic_mode=off

coverage:llvm_cov --experimental_generate_llvm_lcov
# NOTE: --experimental_use_llvm_covmap instruments ALL targets; source
# filtering happens at report time via the score_coverage_scope allowlist.
coverage:llvm_cov --experimental_use_llvm_covmap
coverage:llvm_cov --extra_toolchains=@llvm_toolchain_coverage//:cc-toolchain-x86_64-linux

coverage:llvm_cov --coverage_output_generator=@score_tooling//coverage:merger
coverage:llvm_cov --coverage_report_generator=//tools/coverage:reporter_wrapper

# Keep raw profraw files; the merger handles profraw -> profdata directly.
coverage:llvm_cov --test_env=GENERATE_LLVM_LCOV=0
coverage:llvm_cov --test_env=COVERAGE_GCOV_PATH=/usr/bin/true

# Continuous-mode profiling: covers abnormal termination (death tests).
coverage:llvm_cov --test_env=LLVM_PROFILE_CONTINUOUS_MODE=1
coverage:llvm_cov --features=enable_llvm_coverage_for_death_tests

# Under the LLVM toolchain the `coverage` feature expands to
# -fprofile-instr-generate -fcoverage-mapping (the covmap instrumentation).
coverage:llvm_cov --features=coverage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about destingwishing between qnx and host build?
how is it configured now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as written in PR body, QNX is tracked as no functional yet

72 changes: 72 additions & 0 deletions tools/coverage/coverage_justifications.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# *******************************************************************************
# Copyright (c) 2026 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
# *******************************************************************************
#
# Coverage Justification Database
# ================================
#
# This file defines justified non-covered lines for achieving 100% effective coverage.
#
# Each justification has:
# - id: Unique kebab-case identifier
# - category: One of: defensive_programming, tool_false_positive, platform_specific, other
# - reason: Explanation why the line(s) cannot be covered
# - platforms: (optional) List of platforms this justification applies to: [linux], [qnx], or [linux, qnx]
# When omitted, the justification applies to all platforms.
# - locations: (optional) File + line specifications where justification applies
#
# Lines can also be justified via in-code markers referencing the ID:
# // COV_JUSTIFIED <id> — justifies the current line
# // COV_JUSTIFIED_START <id> — starts a justified region
# // COV_JUSTIFIED_STOP — ends the justified region
#
# Validation rules:
# - IDs must be unique and kebab-case (lowercase + hyphens)
# - Every justification needs a non-empty reason
# - Stale justifications (line is actually covered) produce warnings
# - References to non-existent IDs produce errors
#

version: 1

justifications:
# Example entries (uncomment and adapt as needed):
#
# - id: config-parser-defensive-switch
# category: defensive_programming
# reason: >
# Default case in switch over fully-handled enum. All enum values are explicitly
# handled with a static_assert guard. Kept as defensive programming against
# future enum additions.
# locations:
# - file: score/mw/com/impl/configuration/config_parser.cpp
# line_start: 1201
# line_end: 1203
#
# - id: runtime-tool-false-positive
# category: tool_false_positive
# platforms: [linux] # only applies to Linux coverage
# reason: >
# Coverage tool incorrectly marks this line as not covered. Lines immediately
# before and after are covered, indicating a tool bug.
# locations:
# - file: score/mw/com/impl/runtime.cpp
# lines: [191]
#
- id: time-jumps-validator-time-jump-state-default
category: defensive_programming
platforms: [linux, qnx]
reason: >
Default case in switch over TimeJumpState, a private enum with exactly three values (kJumpToFuture, kJumpToPast, kNoTimeJump), all of which are explicitly handled above. Kept as defensive programming against future enum additions.
locations:
- file: score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really have the suppression there?
the file os not changed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand you can do in source code also but You dont have to. I see this justification is in report

Coverage Justification Summary

Total instrumented lines: 2682
Covered lines: 2323
Justified lines: 2
Unjustified uncovered: 357

Raw line coverage: 86.61%
Effective line coverage: 86.68%

Total branches: 796
Covered branches: 554
Justified branches: 1
Raw branch coverage: 69.59%
Effective branch coverage: 69.72%

lines: [172, 173]
Loading