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
45 changes: 45 additions & 0 deletions .github/workflows/x86_64-linux.yml
Original file line number Diff line number Diff line change
@@ -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 (basic)
run: |
bazel build --config host_config_1 -- //...
- name: Bazel Test
run: |
bazel test --config host_config_1 -- //...

2 changes: 1 addition & 1 deletion examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.0
8.3.1
46 changes: 45 additions & 1 deletion examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand All @@ -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",
],
)
2 changes: 1 addition & 1 deletion examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions examples/lsan_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <cstdlib>

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),
".*");
}
41 changes: 41 additions & 0 deletions examples/tsan_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <thread>
#include <chrono>

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(); }, ".*");
}
28 changes: 28 additions & 0 deletions examples/ubsan_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <climits>

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(); }, ".*");
}