Skip to content

Commit 8d9caf2

Browse files
authored
Modify Bazel build and test targets in workflow (#38)
* Modify Bazel build and test targets in workflow Updated Bazel build and test commands to include additional targets. Signed-off-by: Nikola Radakovic <nikola.ra.radakovic@bmw.de> * Update score_bazel_platforms dependency version Signed-off-by: Nikola Radakovic <nikola.ra.radakovic@bmw.de> * Refactor Bazel build and test targets Updated Bazel build and test commands to remove unused targets. Signed-off-by: Nikola Radakovic <nikola.ra.radakovic@bmw.de> * Update Bazel version from 9.0.0 to 8.3.1 Signed-off-by: Nikola Radakovic <nikola.ra.radakovic@bmw.de> --------- Signed-off-by: Nikola Radakovic <nikola.ra.radakovic@bmw.de>
1 parent e1039bf commit 8d9caf2

7 files changed

Lines changed: 193 additions & 3 deletions

File tree

.github/workflows/x86_64-linux.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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: Bazel Build (Linux)
14+
on:
15+
pull_request:
16+
types: [opened, reopened, synchronize]
17+
push:
18+
branches:
19+
- main
20+
merge_group:
21+
types: [checks_requested]
22+
workflow_call:
23+
jobs:
24+
host_config_1:
25+
runs-on: ubuntu-latest
26+
defaults:
27+
run:
28+
working-directory: ./examples
29+
steps:
30+
- name: Checkout Repository
31+
uses: actions/checkout@v6
32+
- name: Setup Bazel
33+
uses: bazel-contrib/setup-bazel@0.18.0
34+
with:
35+
bazelisk-cache: true
36+
disk-cache: ${{ github.job }}
37+
repository-cache: true
38+
cache-save: ${{ github.event_name == 'push' }}
39+
- name: Bazel Build (basic)
40+
run: |
41+
bazel build --config host_config_1 -- //...
42+
- name: Bazel Test
43+
run: |
44+
bazel test --config host_config_1 -- //...
45+

examples/.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.0.0
1+
8.3.1

examples/BUILD

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cc_test(
4040

4141
cc_shared_library(
4242
name = "math_lib_shared",
43-
shared_lib_name = "libmath_lib.so",
43+
shared_lib_name = "libmath_lib_shared.so",
4444
deps = [":math_lib"],
4545
)
4646

@@ -61,3 +61,47 @@ cc_test(
6161
"@googletest//:gtest_main",
6262
],
6363
)
64+
65+
# for some reason this test is very flaky.
66+
# cc_test(
67+
# name = "tsan_test",
68+
# srcs = ["tsan_test.cpp"],
69+
# features = ["tsan"],
70+
# env = {
71+
# "TSAN_OPTIONS": "halt_on_error=1",
72+
# },
73+
# deps = [
74+
# "@googletest//:gtest",
75+
# "@googletest//:gtest_main",
76+
# ],
77+
# )
78+
79+
cc_test(
80+
name = "ubsan_test",
81+
srcs = ["ubsan_test.cpp"],
82+
features = ["ubsan"],
83+
env = {
84+
"UBSAN_OPTIONS": "halt_on_error=1",
85+
},
86+
deps = [
87+
"@googletest//:gtest",
88+
"@googletest//:gtest_main",
89+
],
90+
)
91+
92+
cc_test(
93+
name = "lsan_test",
94+
srcs = ["lsan_test.cpp"],
95+
features = [
96+
"lsan",
97+
"asan",
98+
],
99+
env = {
100+
"ASAN_OPTIONS": "detect_leaks=1",
101+
"LSAN_OPTIONS": "exitcode=23",
102+
},
103+
deps = [
104+
"@googletest//:gtest",
105+
"@googletest//:gtest_main",
106+
],
107+
)

examples/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bazel_dep(name = "bazel_skylib", version = "1.8.2")
2525
# Constraint values for specifying platforms and toolchains
2626
# *******************************************************************************
2727
bazel_dep(name = "platforms", version = "1.0.0")
28-
bazel_dep(name = "score_bazel_platforms", version = "0.1.0")
28+
bazel_dep(name = "score_bazel_platforms", version = "0.1.1")
2929

3030
# *******************************************************************************
3131
# C++ Rules for Bazel

examples/lsan_test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 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+
14+
#include <gtest/gtest.h>
15+
#include <cstdlib>
16+
17+
static void lsan_buggy() {
18+
int* leaked = new int[100];
19+
leaked[0] = 42;
20+
21+
// Drop the last visible reference so LSan can't find it on the stack.
22+
leaked = nullptr;
23+
24+
std::exit(0);
25+
}
26+
27+
TEST(LsanBugReproTest, MemoryLeak_ShouldBeReportedByLeakSanitizer) {
28+
EXPECT_EXIT(
29+
{ lsan_buggy(); },
30+
::testing::ExitedWithCode(23),
31+
".*");
32+
}

examples/tsan_test.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 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+
14+
#include <gtest/gtest.h>
15+
#include <thread>
16+
#include <chrono>
17+
18+
static int shared_value = 0;
19+
20+
static void tsan_buggy() {
21+
std::thread writer([]() {
22+
for (int i = 0; i < 100000; ++i) {
23+
shared_value = i; // unsynchronized write
24+
}
25+
});
26+
27+
std::thread reader([]() {
28+
int tmp = 0;
29+
for (int i = 0; i < 100000; ++i) {
30+
tmp = shared_value; // unsynchronized read
31+
}
32+
(void)tmp;
33+
});
34+
35+
writer.join();
36+
reader.join();
37+
}
38+
39+
TEST(TsanBugReproTest, ReadWriteRace_ShouldCrashUnderThreadSanitizer) {
40+
ASSERT_DEATH({ tsan_buggy(); }, ".*");
41+
}

examples/ubsan_test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 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+
14+
#include <gtest/gtest.h>
15+
#include <climits>
16+
17+
static int ubsan_buggy() {
18+
volatile int x = INT_MAX;
19+
volatile int y = 1;
20+
21+
// Signed overflow is UB.
22+
return x + y;
23+
}
24+
25+
TEST(UbsanBugReproTest, SignedOverflow_ShouldCrashUnderUndefinedBehaviorSanitizer) {
26+
// Requires -fno-sanitize-recover=undefined or UBSAN_OPTIONS=halt_on_error=1
27+
ASSERT_DEATH({ (void)ubsan_buggy(); }, ".*");
28+
}

0 commit comments

Comments
 (0)