File tree Expand file tree Collapse file tree 6 files changed +61
-4
lines changed
Expand file tree Collapse file tree 6 files changed +61
-4
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ common --@score_baselibs//score/json:base_library=nlohmann
1818common --//score/mw/com/flags:tracing_library=stub
1919common --extra_toolchains=@gcc_toolchain//:host_gcc_12
2020build --incompatible_strict_action_env
21- test --test_tag_filters=-manual
2221test --test_output=errors
2322build --experimental_retain_test_configuration_across_testonly #https://github.com/bazelbuild/bazel/issues/6842
2423
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ sh_test(
1919 "test_workspace/BUILD.tpl" ,
2020 "test_workspace/MODULE.bazel" ,
2121 "test_workspace/asan_fail_heap_out_of_bounds.cpp" ,
22+ "test_workspace/tsan_fail_data_race.cpp" ,
2223 ],
2324 env_inherit = [
2425 "PATH" ,
@@ -27,7 +28,7 @@ sh_test(
2728 ],
2829 tags = [
2930 "local" , # Test marked local because it uses bazel.
30- "manual" , # Due to long-runtime and local dependencies
31+ "manual" , # Due to long-runtime and local dependencies
3132 ],
3233 deps = ["@bazel_tools//tools/bash/runfiles" ],
3334)
Original file line number Diff line number Diff line change @@ -24,3 +24,12 @@ test:asan_ubsan --test_env=ASAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity
2424test:asan_ubsan --test_env=UBSAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity=1 coverage=1 print_stacktrace=1 halt_on_error=1"
2525
2626test:asan --config=asan_ubsan
27+
28+ test:tsan --cxxopt -O0
29+ test:tsan --cxxopt -Og
30+ test:tsan --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
31+ test:tsan --cxxopt -fsanitize=thread
32+ test:tsan --linkopt -fsanitize=thread
33+ test:tsan --linkopt -fsanitize-link-c++-runtime
34+ test:tsan --platform_suffix=tsan
35+ test:tsan --test_env=TSAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity=1 coverage=1 detect_deadlocks=1 second_deadlock_stack=1 halt_on_error=0"
Original file line number Diff line number Diff line change @@ -47,11 +47,16 @@ ln -sf "$(rlocation $TEST_WORKSPACE/quality/sanitizer/sanitizer.bazelrc)" "test_
4747ln -sf " $( rlocation $TEST_WORKSPACE /quality/sanitizer/test_workspace/MODULE.bazel) " " test_workspace/MODULE.bazel"
4848ln -sf " $( rlocation $TEST_WORKSPACE /quality/sanitizer/test_workspace/BUILD.tpl) " " test_workspace/BUILD"
4949ln -sf " $( rlocation $TEST_WORKSPACE /quality/sanitizer/test_workspace/asan_fail_heap_out_of_bounds.cpp) " " test_workspace/asan_fail_heap_out_of_bounds.cpp"
50+ ln -sf " $( rlocation $TEST_WORKSPACE /quality/sanitizer/test_workspace/tsan_fail_data_race.cpp) " " test_workspace/tsan_fail_data_race.cpp"
5051
5152cd test_workspace
5253
5354if bazel test --config=asan //...; then
5455 exit 1;
55- else
56- exit 0;
5756fi
57+
58+ if bazel test --config=tsan //...; then
59+ exit 1;
60+ fi
61+
62+ exit 0;
Original file line number Diff line number Diff line change @@ -15,3 +15,8 @@ cc_test(
1515 name = " asan_fail_heap_out_of_bounds" ,
1616 srcs = [" asan_fail_heap_out_of_bounds.cpp" ],
1717)
18+
19+ cc_test(
20+ name = " tsan_fail_data_race" ,
21+ srcs = [" tsan_fail_data_race.cpp" ],
22+ )
Original file line number Diff line number Diff line change 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+ #include < cstdint>
14+ #include < thread>
15+
16+ // This is a very basic example of a data-race condition, which should be found by a thread-sanitizer
17+ int main ()
18+ {
19+ std::uint32_t some_number{0 };
20+
21+ std::thread first_thread{[&some_number]() {
22+ for (int i = 0 ; i < 100 ; i++)
23+ {
24+ some_number++;
25+ }
26+ }};
27+
28+ std::thread second_thread{[&some_number]() {
29+ for (int i = 0 ; i < 100 ; i++)
30+ {
31+ some_number++;
32+ }
33+ }};
34+
35+ first_thread.join ();
36+ second_thread.join ();
37+ return 0 ;
38+ }
You can’t perform that action at this time.
0 commit comments