test: add ThreadSanitizer verification for lock-free Channel<T>
Add a contended SPSC stress suite (tests/test_channel_stress.cpp) that actually exercises the ring's memory-ordering pairing and spin/futex/ lost-wakeup logic, plus the CMake and CI plumbing to run it under TSan: - KPN_SANITIZER cache var + kpn_sanitizer_flags() helper (no-op when unset) - kpn_tests_stress executable, labelled "stress" for CTest - reusable tsan.yaml workflow (gcc:14 builder image, already ships libtsan) - ci.yaml gains a tsan job on the same code/dockerfile triggers as test Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,30 @@ option(KPN_BUILD_PYTHON "Build Python bindings (requires nanobind)" ON)
|
||||
option(KPN_BUILD_EXAMPLES "Build examples" ON)
|
||||
option(KPN_WEB_DEBUG "Enable web debug UI (cpp-httplib)" OFF)
|
||||
|
||||
# Sanitizer build. Empty = off. Accepts "thread", "address", "undefined",
|
||||
# or a combination like "address,undefined". Applied to all kpn targets via
|
||||
# the kpn_sanitizer_flags() helper below.
|
||||
#
|
||||
# The lock-free SPSC Channel<T> (include/kpn/channel.hpp) has hand-reasoned
|
||||
# acquire/release ordering; -DKPN_SANITIZER=thread + the channel stress test
|
||||
# (tests/test_channel_stress.cpp) is the dynamic half of verifying it. The
|
||||
# static half is the CDSChecker model-check harness (see verify/).
|
||||
set(KPN_SANITIZER "" CACHE STRING
|
||||
"Build with sanitizer: thread | address | undefined | <combo> (empty = off)")
|
||||
|
||||
# Translate KPN_SANITIZER into compile/link flags. No-op when empty.
|
||||
function(kpn_sanitizer_flags out_var)
|
||||
if(KPN_SANITIZER)
|
||||
set(${out_var}
|
||||
-fsanitize=${KPN_SANITIZER}
|
||||
-fno-omit-frame-pointer
|
||||
-g
|
||||
PARENT_SCOPE)
|
||||
else()
|
||||
set(${out_var} "" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# ── Core library (header-only) ────────────────────────────────────────────────
|
||||
add_library(kpn INTERFACE)
|
||||
target_include_directories(kpn INTERFACE
|
||||
|
||||
Reference in New Issue
Block a user