Skip to content

Commit 14ee704

Browse files
authored
Merge pull request #80 from qorix-group/piotrkorkus_code_coverage
Code coverage
2 parents fe768bc + 45c44b2 commit 14ee704

5 files changed

Lines changed: 145 additions & 2 deletions

File tree

.bazelrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ test --@score_baselibs//score/mw/log/flags:KRemote_Logging=False
2626
test --@score_baselibs//score/json:base_library=nlohmann
2727
test --cxxopt=-Wno-deprecated-declarations
2828

29+
# Coverage configuration for C++
30+
coverage --features=coverage
31+
coverage --combined_report=lcov
32+
coverage --cache_test_results=no
33+
2934
# Common Lifecycle Toolchain flags for build (do not use it in case of system toolchains!)
3035
build:toolchain_common --incompatible_strict_action_env
3136
build:toolchain_common --host_platform=@score_bazel_platforms//:x86_64-linux
@@ -58,6 +63,17 @@ build:arm64-qnx --platforms=@score_bazel_platforms//:aarch64-qnx-sdp_8.0.0-posix
5863
build:arm64-qnx --extra_toolchains=@score_qcc_aarch64_toolchain//:aarch64-qnx-sdp_8.0.0-posix
5964
build:arm64-qnx --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_aarch64_unknown_nto_qnx800
6065

66+
# Ferrocene Rust coverage config
67+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_rustc_flag=-Cinstrument-coverage
68+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_rustc_flag=-Clink-dead-code
69+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_rustc_flag=-Ccodegen-units=1
70+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_rustc_flag=-Cdebuginfo=2
71+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_exec_rustc_flag=-Cinstrument-coverage
72+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_exec_rustc_flag=-Clink-dead-code
73+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_exec_rustc_flag=-Ccodegen-units=1
74+
build:ferrocene-coverage --@rules_rust//rust/settings:extra_exec_rustc_flag=-Cdebuginfo=2
75+
test:ferrocene-coverage --run_under=@score_tooling//coverage:llvm_profile_wrapper
76+
6177
# to be removed
6278
build:build_qnx8 --config=arm64-qnx
6379

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
name: Code Coverage
14+
on:
15+
pull_request:
16+
types: [opened, reopened, synchronize]
17+
push:
18+
branches:
19+
- main
20+
merge_group:
21+
types: [checks_requested]
22+
release:
23+
types: [created]
24+
25+
jobs:
26+
cpp:
27+
runs-on: ubuntu-22.04
28+
steps:
29+
- name: Checkout Repository
30+
uses: actions/checkout@v6
31+
32+
- name: Install lcov
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y lcov
36+
37+
- name: Setup Bazel
38+
uses: bazel-contrib/setup-bazel@0.18.0
39+
with:
40+
bazelisk-cache: true
41+
disk-cache: ${{ github.job }}
42+
repository-cache: true
43+
cache-save: ${{ github.event_name == 'push' }}
44+
45+
- name: Run Bazel Coverage
46+
run: |
47+
bazel coverage \
48+
--test_output=errors \
49+
--nocache_test_results \
50+
--config=x86_64-linux \
51+
//src/...
52+
53+
- name: Generate HTML Coverage Report
54+
shell: bash
55+
run: |
56+
genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat" \
57+
-o=cpp_coverage \
58+
--show-details \
59+
--legend \
60+
--function-coverage \
61+
--branch-coverage
62+
63+
- name: Upload Coverage Artifacts
64+
uses: actions/upload-artifact@v6
65+
with:
66+
name: ${{ github.event.repository.name }}_cpp_coverage_report
67+
path: cpp_coverage/
68+
retention-days: 10
69+
rust:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Checkout Repository
73+
uses: actions/checkout@v6
74+
75+
- name: Setup Bazel
76+
uses: bazel-contrib/setup-bazel@0.18.0
77+
with:
78+
bazelisk-cache: true
79+
disk-cache: ${{ github.job }}
80+
repository-cache: true
81+
cache-save: ${{ github.event_name == 'push' }}
82+
83+
- name: Run Rust tests with coverage instrumentation
84+
run: |
85+
set -euo pipefail
86+
bazel test \
87+
--config=x86_64-linux \
88+
--config=ferrocene-coverage \
89+
--nocache_test_results \
90+
"$(bazel query 'kind(rust_test, //src/...)')"
91+
92+
- name: Generate Ferrocene coverage reports
93+
run: |
94+
set -euo pipefail
95+
bazel run //:rust_coverage -- --min-line-coverage 66
96+
97+
- name: Locate coverage artifacts
98+
run: |
99+
echo "COVERAGE_DIR=$(bazel info bazel-bin)/coverage/rust-tests" >> "${GITHUB_ENV}"
100+
101+
- name: Upload coverage HTML
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: ${{ github.event.repository.name }}_rust_coverage_report
105+
path: ${{ env.COVERAGE_DIR }}
106+
retention-days: 10

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
contents: read
2626
pull-requests: read
2727
with:
28-
bazel-target: 'test //src/...'
28+
bazel-target: 'test //src/... --config=x86_64-linux'

BUILD

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# *******************************************************************************
1313

1414
load("@score_docs_as_code//:docs.bzl", "docs")
15-
load("@score_tooling//:defs.bzl", "copyright_checker", "dash_license_checker", "setup_starpls", "use_format_targets")
15+
load("@score_tooling//:defs.bzl", "copyright_checker", "dash_license_checker", "rust_coverage_report", "setup_starpls", "use_format_targets")
1616
load("//:project_config.bzl", "PROJECT_CONFIG")
1717

1818
setup_starpls(
@@ -52,6 +52,24 @@ dash_license_checker(
5252
# Add target for formatting checks
5353
use_format_targets()
5454

55+
# Rust coverage report generation target
56+
rust_coverage_report(
57+
name = "rust_coverage",
58+
bazel_configs = [
59+
"x86_64-linux",
60+
"ferrocene-coverage",
61+
],
62+
query = 'kind("rust_test", //src/...)',
63+
visibility = ["//visibility:public"],
64+
)
65+
66+
alias(
67+
name = "rust_coverage_report",
68+
actual = ":rust_coverage",
69+
visibility = ["//visibility:public"],
70+
)
71+
72+
# Docs
5573
docs(
5674
data = [
5775
"@score_process//:needs_json", # This allows linking to requirements (wp__requirements_comp, etc.) from the process_description repository.

src/health_monitoring_lib/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ CC_HDRS = [
4242
rust_library(
4343
name = "health_monitoring_lib",
4444
srcs = glob(["rust/**/*.rs"]),
45+
crate_root = "rust/lib.rs",
4546
proc_macro_deps = PROC_MACRO_DEPS,
4647
visibility = ["//visibility:public"],
4748
deps = COMMON_DEPS,
@@ -65,6 +66,7 @@ rust_static_library(
6566
name = "health_monitoring_lib_ffi",
6667
srcs = glob(["rust/**/*.rs"]),
6768
crate_name = "health_monitoring_lib",
69+
crate_root = "rust/lib.rs",
6870
proc_macro_deps = [
6971
"@score_baselibs_rust//src/testing_macros:score_testing_macros",
7072
],
@@ -77,6 +79,7 @@ rust_static_library(
7779
name = "health_monitoring_lib_stub_supervisor",
7880
srcs = glob(["rust/**/*.rs"]),
7981
crate_features = ["stub_supervisor_api_client"], # Uses the stub supervisor API client, used for C++ testing
82+
crate_root = "rust/lib.rs",
8083
proc_macro_deps = PROC_MACRO_DEPS,
8184
visibility = ["//visibility:private"],
8285
deps = COMMON_DEPS,

0 commit comments

Comments
 (0)