From 9749f9fb575cfc29dd592daee3c584ad97568645 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Fri, 6 Mar 2026 10:20:02 +0000 Subject: [PATCH 1/4] Modify Bazel build and test targets in workflow Updated Bazel build and test commands to include additional targets. Signed-off-by: Nikola Radakovic --- .github/workflows/x86_64-linux.yml | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/x86_64-linux.yml diff --git a/.github/workflows/x86_64-linux.yml b/.github/workflows/x86_64-linux.yml new file mode 100644 index 0000000..ab60606 --- /dev/null +++ b/.github/workflows/x86_64-linux.yml @@ -0,0 +1,45 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* +name: Bazel Build (Linux) +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - main + merge_group: + types: [checks_requested] + workflow_call: +jobs: + host_config_1: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./examples + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.18.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.job }} + repository-cache: true + cache-save: ${{ github.event_name == 'push' }} + - name: Bazel Build + run: | + bazel build --config host_config_1 -- //:main_cpp //:main_pthread_cpp //:math_lib //:math_lib_shared + - name: Bazel Test + run: | + bazel test --config host_config_1 -- //:math_lib_test //:math_lib_dyn_test //:asan_test + From cde33bc0869e0aff238625cf2b7ef6b6278baecf Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Fri, 6 Mar 2026 10:26:14 +0000 Subject: [PATCH 2/4] Update score_bazel_platforms dependency version Signed-off-by: Nikola Radakovic --- examples/MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index c9a958d..ae38379 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -25,7 +25,7 @@ bazel_dep(name = "bazel_skylib", version = "1.8.2") # Constraint values for specifying platforms and toolchains # ******************************************************************************* bazel_dep(name = "platforms", version = "1.0.0") -bazel_dep(name = "score_bazel_platforms", version = "0.1.0") +bazel_dep(name = "score_bazel_platforms", version = "0.1.1") # ******************************************************************************* # C++ Rules for Bazel From d25115d8c13c59fd12bdf83f06f6c90fca64d801 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Fri, 6 Mar 2026 10:31:40 +0000 Subject: [PATCH 3/4] Refactor Bazel build and test targets Updated Bazel build and test commands to remove unused targets. Signed-off-by: Nikola Radakovic --- .github/workflows/x86_64-linux.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/x86_64-linux.yml b/.github/workflows/x86_64-linux.yml index ab60606..7e959ac 100644 --- a/.github/workflows/x86_64-linux.yml +++ b/.github/workflows/x86_64-linux.yml @@ -36,10 +36,10 @@ jobs: disk-cache: ${{ github.job }} repository-cache: true cache-save: ${{ github.event_name == 'push' }} - - name: Bazel Build + - name: Bazel Build (basic) run: | - bazel build --config host_config_1 -- //:main_cpp //:main_pthread_cpp //:math_lib //:math_lib_shared + bazel build --config host_config_1 -- //:main_cpp //:main_pthread_cpp //:math_lib - name: Bazel Test run: | - bazel test --config host_config_1 -- //:math_lib_test //:math_lib_dyn_test //:asan_test + bazel test --config host_config_1 -- //:math_lib_test //:asan_test From 361d2c7a8c21cc7228f1e8e0944810f9b6051547 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Fri, 6 Mar 2026 10:39:10 +0000 Subject: [PATCH 4/4] Update Bazel version from 9.0.0 to 8.3.1 Signed-off-by: Nikola Radakovic --- .github/workflows/x86_64-linux.yml | 4 +-- examples/.bazelversion | 2 +- examples/BUILD | 46 +++++++++++++++++++++++++++++- examples/lsan_test.cpp | 32 +++++++++++++++++++++ examples/tsan_test.cpp | 41 ++++++++++++++++++++++++++ examples/ubsan_test.cpp | 28 ++++++++++++++++++ 6 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 examples/lsan_test.cpp create mode 100644 examples/tsan_test.cpp create mode 100644 examples/ubsan_test.cpp diff --git a/.github/workflows/x86_64-linux.yml b/.github/workflows/x86_64-linux.yml index 7e959ac..a6ab3da 100644 --- a/.github/workflows/x86_64-linux.yml +++ b/.github/workflows/x86_64-linux.yml @@ -38,8 +38,8 @@ jobs: cache-save: ${{ github.event_name == 'push' }} - name: Bazel Build (basic) run: | - bazel build --config host_config_1 -- //:main_cpp //:main_pthread_cpp //:math_lib + bazel build --config host_config_1 -- //... - name: Bazel Test run: | - bazel test --config host_config_1 -- //:math_lib_test //:asan_test + bazel test --config host_config_1 -- //... diff --git a/examples/.bazelversion b/examples/.bazelversion index c9277c5..56b6be4 100644 --- a/examples/.bazelversion +++ b/examples/.bazelversion @@ -1 +1 @@ -9.0.0 \ No newline at end of file +8.3.1 diff --git a/examples/BUILD b/examples/BUILD index 92232d3..f675bbd 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -40,7 +40,7 @@ cc_test( cc_shared_library( name = "math_lib_shared", - shared_lib_name = "libmath_lib.so", + shared_lib_name = "libmath_lib_shared.so", deps = [":math_lib"], ) @@ -61,3 +61,47 @@ cc_test( "@googletest//:gtest_main", ], ) + +# for some reason this test is very flaky. +# cc_test( +# name = "tsan_test", +# srcs = ["tsan_test.cpp"], +# features = ["tsan"], +# env = { +# "TSAN_OPTIONS": "halt_on_error=1", +# }, +# deps = [ +# "@googletest//:gtest", +# "@googletest//:gtest_main", +# ], +# ) + +cc_test( + name = "ubsan_test", + srcs = ["ubsan_test.cpp"], + features = ["ubsan"], + env = { + "UBSAN_OPTIONS": "halt_on_error=1", + }, + deps = [ + "@googletest//:gtest", + "@googletest//:gtest_main", + ], +) + +cc_test( + name = "lsan_test", + srcs = ["lsan_test.cpp"], + features = [ + "lsan", + "asan", + ], + env = { + "ASAN_OPTIONS": "detect_leaks=1", + "LSAN_OPTIONS": "exitcode=23", + }, + deps = [ + "@googletest//:gtest", + "@googletest//:gtest_main", + ], +) diff --git a/examples/lsan_test.cpp b/examples/lsan_test.cpp new file mode 100644 index 0000000..66eb34a --- /dev/null +++ b/examples/lsan_test.cpp @@ -0,0 +1,32 @@ +/******************************************************************************** +* 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 +********************************************************************************/ + +#include +#include + +static void lsan_buggy() { + int* leaked = new int[100]; + leaked[0] = 42; + + // Drop the last visible reference so LSan can't find it on the stack. + leaked = nullptr; + + std::exit(0); +} + +TEST(LsanBugReproTest, MemoryLeak_ShouldBeReportedByLeakSanitizer) { + EXPECT_EXIT( + { lsan_buggy(); }, + ::testing::ExitedWithCode(23), + ".*"); +} \ No newline at end of file diff --git a/examples/tsan_test.cpp b/examples/tsan_test.cpp new file mode 100644 index 0000000..21dc032 --- /dev/null +++ b/examples/tsan_test.cpp @@ -0,0 +1,41 @@ +/******************************************************************************** +* 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 +********************************************************************************/ + +#include +#include +#include + +static int shared_value = 0; + +static void tsan_buggy() { + std::thread writer([]() { + for (int i = 0; i < 100000; ++i) { + shared_value = i; // unsynchronized write + } + }); + + std::thread reader([]() { + int tmp = 0; + for (int i = 0; i < 100000; ++i) { + tmp = shared_value; // unsynchronized read + } + (void)tmp; + }); + + writer.join(); + reader.join(); +} + +TEST(TsanBugReproTest, ReadWriteRace_ShouldCrashUnderThreadSanitizer) { + ASSERT_DEATH({ tsan_buggy(); }, ".*"); +} \ No newline at end of file diff --git a/examples/ubsan_test.cpp b/examples/ubsan_test.cpp new file mode 100644 index 0000000..18ef3d8 --- /dev/null +++ b/examples/ubsan_test.cpp @@ -0,0 +1,28 @@ +/******************************************************************************** +* 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 +********************************************************************************/ + +#include +#include + +static int ubsan_buggy() { + volatile int x = INT_MAX; + volatile int y = 1; + + // Signed overflow is UB. + return x + y; +} + +TEST(UbsanBugReproTest, SignedOverflow_ShouldCrashUnderUndefinedBehaviorSanitizer) { + // Requires -fno-sanitize-recover=undefined or UBSAN_OPTIONS=halt_on_error=1 + ASSERT_DEATH({ (void)ubsan_buggy(); }, ".*"); +} \ No newline at end of file