aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-26 22:13:52 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-26 22:13:52 +0200
commit705c98d47937d603e3ad569cc2ade12fa1df3677 (patch)
tree6cd980e01943a87126ec51a248ffc4f03a195e5f
parent4b28e4626e744ac9b779a680f8e9647014956dda (diff)
downloadkernel-705c98d47937d603e3ad569cc2ade12fa1df3677.tar.xz
kernel-705c98d47937d603e3ad569cc2ade12fa1df3677.zip
build: add tsan build
-rw-r--r--CMakeLists.txt8
-rw-r--r--CMakePresets.json24
-rw-r--r--kapi/kapi/devices/bus.hpp4
-rw-r--r--kernel/CMakeLists.txt2
-rw-r--r--kernel/kapi/devices/bus.cpp12
-rw-r--r--kernel/kapi/devices/bus.stress.cpp2
-rw-r--r--libs/acpi/CMakeLists.txt2
-rw-r--r--libs/kstd/CMakeLists.txt2
8 files changed, 44 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5f2ae141..8ac8dc04 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@ endif()
option(TEACHOS_ENABLE_LINTING "Enable linting during build" ON)
option(TEACHOS_GENERATE_DOCS "Generate documentation during build" ON)
option(TEACHOS_ENABLE_TEST_SANITIZERS "Enable sanitizers for test executables" ON)
+option(TEACHOS_ENABLE_TEST_TSAN "Enable TSan for the test executable" OFF)
#[============================================================================[
# Global Build System Configuration
@@ -107,9 +108,14 @@ if(BUILD_TESTING)
)
endif()
- if(TEACHOS_ENABLE_TEST_SANITIZERS)
+ if(TEACHOS_ENABLE_TEST_SANITIZERS AND TEACHOS_ENABLE_TEST_TSAN)
+ message(FATAL_ERROR "TEACHOS_ENABLE_TEST_SANITIZERS and TEACHOS_ENABLE_TEST_TSAN are mutually exclusive")
+ elseif(TEACHOS_ENABLE_TEST_SANITIZERS)
add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=undefined,address>")
add_link_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=undefined,address,leak>")
+ elseif(TEACHOS_ENABLE_TEST_TSAN)
+ add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=thread;-g>")
+ add_link_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=thread>")
endif()
endif()
diff --git a/CMakePresets.json b/CMakePresets.json
index 0e70d1a9..1d75402d 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -25,6 +25,15 @@
"name": "bht",
"inherits": "base",
"description": "Build-host Testing"
+ },
+ {
+ "name": "bht-tsan",
+ "inherits": "bht",
+ "description": "Build-host Testing with ThreadSanitizer",
+ "cacheVariables": {
+ "TEACHOS_ENABLE_TEST_SANITIZERS": false,
+ "TEACHOS_ENABLE_TEST_TSAN": true
+ }
}
],
"buildPresets": [
@@ -42,6 +51,11 @@
"name": "bht-dbg",
"configurePreset": "bht",
"configuration": "Debug"
+ },
+ {
+ "name": "bht-tsan-dbg",
+ "configurePreset": "bht-tsan",
+ "configuration": "Debug"
}
],
"testPresets": [
@@ -54,6 +68,16 @@
"execution": {
"jobs": 0
}
+ },
+ {
+ "name": "bht-tsan-dbg",
+ "configurePreset": "bht-tsan",
+ "output": {
+ "outputOnFailure": true
+ },
+ "execution": {
+ "jobs": 1
+ }
}
]
} \ No newline at end of file
diff --git a/kapi/kapi/devices/bus.hpp b/kapi/kapi/devices/bus.hpp
index 2ee12628..3a0ba6a6 100644
--- a/kapi/kapi/devices/bus.hpp
+++ b/kapi/kapi/devices/bus.hpp
@@ -13,8 +13,6 @@
#include <kstd/string.hpp>
#include <kstd/vector.hpp>
-#include <span>
-
namespace kapi::devices
{
@@ -57,7 +55,7 @@ namespace kapi::devices
//! Get the children attached to this bus.
//!
//! @return A vector of all children attached to this bus.
- [[nodiscard]] auto children() const -> std::span<kstd::shared_ptr<device> const>;
+ [[nodiscard]] auto children() const -> kstd::vector<kstd::shared_ptr<device>>;
protected:
//! All busses have the "bus" facet.
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index a97c1e4a..c93fe9c9 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -191,7 +191,7 @@ if(BUILD_TESTING)
CXX_CLANG_TIDY ""
)
- if(COMMAND "enable_coverage")
+ if(COMMAND "enable_coverage" AND NOT TEACHOS_ENABLE_TEST_TSAN)
enable_coverage("kernel_lib")
enable_coverage("kernel_tests")
endif()
diff --git a/kernel/kapi/devices/bus.cpp b/kernel/kapi/devices/bus.cpp
index 71dd01e6..2b94e486 100644
--- a/kernel/kapi/devices/bus.cpp
+++ b/kernel/kapi/devices/bus.cpp
@@ -11,7 +11,6 @@
#include <kstd/vector.hpp>
#include <algorithm>
-#include <span>
#include <utility>
namespace kapi::devices
@@ -36,7 +35,10 @@ namespace kapi::devices
auto bus::add_child(kstd::shared_ptr<device> child) -> void
{
- child->set_parent(kstd::static_pointer_cast<bus>(shared_from_this()));
+ {
+ auto guard = kstd::lock_guard{m_lock};
+ child->set_parent(kstd::static_pointer_cast<bus>(shared_from_this()));
+ }
if (!kapi::devices::device_registry::get().add(child))
{
@@ -74,9 +76,11 @@ namespace kapi::devices
return true;
}
- [[nodiscard]] auto bus::children() const -> std::span<kstd::shared_ptr<device> const>
+ [[nodiscard]] auto bus::children() const -> kstd::vector<kstd::shared_ptr<device>>
{
- return {m_devices.data(), m_devices.size()};
+ auto guard = kstd::lock_guard{m_lock};
+
+ return m_devices;
}
auto bus::query_facet(kapi::capabilities::facet_id facet) -> void *
diff --git a/kernel/kapi/devices/bus.stress.cpp b/kernel/kapi/devices/bus.stress.cpp
index 226b0296..3fefc892 100644
--- a/kernel/kapi/devices/bus.stress.cpp
+++ b/kernel/kapi/devices/bus.stress.cpp
@@ -21,7 +21,7 @@ namespace
} // namespace
-constexpr auto thread_count = 32;
+constexpr auto thread_count = 8;
constexpr auto devices_per_thread = 200;
SCENARIO("Concurrent attach/detach/lookup on a bus is race-free")
diff --git a/libs/acpi/CMakeLists.txt b/libs/acpi/CMakeLists.txt
index caffa1c9..4bd23d47 100644
--- a/libs/acpi/CMakeLists.txt
+++ b/libs/acpi/CMakeLists.txt
@@ -85,7 +85,7 @@ if(BUILD_TESTING)
set_source_files_properties("acpi/test_data/tables.S" PROPERTIES OBJECT_DEPENDS "${GENERATED_TABLE_BLOBS}")
- if(COMMAND "enable_coverage")
+ if(COMMAND "enable_coverage" AND NOT TEACHOS_ENABLE_TEST_TSAN)
enable_coverage("acpi")
endif()
diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt
index 63428c4b..379ca7d0 100644
--- a/libs/kstd/CMakeLists.txt
+++ b/libs/kstd/CMakeLists.txt
@@ -74,7 +74,7 @@ if(BUILD_TESTING)
teachos_add_tests("kstd")
- if(COMMAND "enable_coverage")
+ if(COMMAND "enable_coverage" AND NOT TEACHOS_ENABLE_TEST_TSAN)
enable_coverage("kstd")
enable_coverage("kstd_tests")
endif()