From bd032c08ce3ddb7e035a97e816ff25e1eae1f4ec Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sun, 9 Nov 2025 20:19:54 +0100 Subject: [PATCH] adds TSAN/ASAN buid settings --- .gitignore | 3 ++- CMakeLists.txt | 18 +++++++++++++++--- scc | 2 +- tests/ace_pin_level/CMakeLists.txt | 5 +++-- tests/ahb_pin_level/CMakeLists.txt | 4 +++- tests/apb_pin_level/CMakeLists.txt | 4 +++- tests/axi4_pin_level/CMakeLists.txt | 5 +++-- tests/cci_param_restricted/CMakeLists.txt | 4 +++- tests/cxs_tlm/CMakeLists.txt | 4 +++- tests/memory_subsys/CMakeLists.txt | 4 +++- tests/ordered_semaphore/CMakeLists.txt | 4 +++- tests/quantum_keeper_mt/CMakeLists.txt | 5 +---- tests/quantum_keeper_mt/top_module.h | 4 ++-- tests/tlm_memory/CMakeLists.txt | 4 +++- 14 files changed, 48 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index f9f9210..6bdbe0f 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,5 @@ /.cache /CMakeUserPresets.json /*.scview -/*.log \ No newline at end of file +/*.log +/config \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8be6969..7c6b7fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ project(SCC_Test) option(FULL_TEST_SUITE "enable also long-running tests" OFF) option(ENABLE_SCV "Enable use of SCV" OFF) option(ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF) +option(ENABLE_CLANG_FORMAT "Enable clang-format targets" OFF) +option(THREAD_SANITIZER "Enable thread sanitizer TSan" OFF) +option(ADDR_SANITIZER "Enable address sanitizer ASan" OFF) include(GNUInstallDirs) include(BuildType) @@ -30,7 +33,15 @@ if(ENABLE_COVERAGE) include(CodeCoverage) append_coverage_compiler_flags() endif() - +if (THREAD_SANITIZER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -O0 -g") +elseif(ADDR_SANITIZER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O0 -g") +else() + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) + endif() +endif() if(ENABLE_CLANG_TIDY) find_program(CLANG_TIDY_EXE NAMES "clang-tidy") if(CLANG_TIDY_EXE) @@ -44,7 +55,9 @@ if(ENABLE_CLANG_TIDY) endif() set(CLANG_FORMAT_EXCLUDE_PATTERNS "/third_party/" "/build/") -find_package(ClangFormat) +if(ENABLE_CLANG_FORMAT) + find_package(ClangFormat) +endif() find_package(ZLIB) find_package(lz4) # This line finds the boost lib and headers. @@ -57,7 +70,6 @@ find_package(Catch2) include(SystemCPackage) include(CTest) include(Catch) - enable_testing() set(WITH_SCP4SCC ON) add_subdirectory(scc) diff --git a/scc b/scc index 0a3b269..cc35ebf 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit 0a3b2697a5cc9c5d6d10bf41c721dd666e5ba841 +Subproject commit cc35ebf490cf314972fde6570673c5ba40eb7b23 diff --git a/tests/ace_pin_level/CMakeLists.txt b/tests/ace_pin_level/CMakeLists.txt index 78d5cf1..f16e4c4 100644 --- a/tests/ace_pin_level/CMakeLists.txt +++ b/tests/ace_pin_level/CMakeLists.txt @@ -5,5 +5,6 @@ add_executable(${PROJECT_NAME} ${test_util_SOURCE_DIR}/sc_main.cpp ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) - -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/ahb_pin_level/CMakeLists.txt b/tests/ahb_pin_level/CMakeLists.txt index 621893d..d13d684 100644 --- a/tests/ahb_pin_level/CMakeLists.txt +++ b/tests/ahb_pin_level/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/apb_pin_level/CMakeLists.txt b/tests/apb_pin_level/CMakeLists.txt index bd52313..085edec 100644 --- a/tests/apb_pin_level/CMakeLists.txt +++ b/tests/apb_pin_level/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/axi4_pin_level/CMakeLists.txt b/tests/axi4_pin_level/CMakeLists.txt index 53ff21a..a16c2db 100644 --- a/tests/axi4_pin_level/CMakeLists.txt +++ b/tests/axi4_pin_level/CMakeLists.txt @@ -5,5 +5,6 @@ add_executable(${PROJECT_NAME} ${test_util_SOURCE_DIR}/sc_main.cpp ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) - -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/cci_param_restricted/CMakeLists.txt b/tests/cci_param_restricted/CMakeLists.txt index 6ac195e..9d85664 100644 --- a/tests/cci_param_restricted/CMakeLists.txt +++ b/tests/cci_param_restricted/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/cxs_tlm/CMakeLists.txt b/tests/cxs_tlm/CMakeLists.txt index ede8eff..d5c1190 100644 --- a/tests/cxs_tlm/CMakeLists.txt +++ b/tests/cxs_tlm/CMakeLists.txt @@ -5,4 +5,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC scc::busses test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/memory_subsys/CMakeLists.txt b/tests/memory_subsys/CMakeLists.txt index dcb948a..92ebe28 100644 --- a/tests/memory_subsys/CMakeLists.txt +++ b/tests/memory_subsys/CMakeLists.txt @@ -5,4 +5,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC scc::components test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/ordered_semaphore/CMakeLists.txt b/tests/ordered_semaphore/CMakeLists.txt index cf2d27d..334a28f 100644 --- a/tests/ordered_semaphore/CMakeLists.txt +++ b/tests/ordered_semaphore/CMakeLists.txt @@ -6,4 +6,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/tests/quantum_keeper_mt/CMakeLists.txt b/tests/quantum_keeper_mt/CMakeLists.txt index 9bcf71e..5666264 100644 --- a/tests/quantum_keeper_mt/CMakeLists.txt +++ b/tests/quantum_keeper_mt/CMakeLists.txt @@ -1,8 +1,5 @@ -message(STATUS "SC_VERSION is ${SC_VERSION_MAJOR}.${SC_VERSION_MINOR}.${SC_VERSION_PATCH}") if(SC_VERSION_MAJOR GREATER 2) - add_executable (quantum_keeper_mt - sc_main.cpp - ) + add_executable (quantum_keeper_mt sc_main.cpp) target_link_libraries (quantum_keeper_mt LINK_PUBLIC scc-sysc) add_test(NAME quantum_keeper_mt COMMAND quantum_keeper_mt) endif() \ No newline at end of file diff --git a/tests/quantum_keeper_mt/top_module.h b/tests/quantum_keeper_mt/top_module.h index eba9521..10fd595 100644 --- a/tests/quantum_keeper_mt/top_module.h +++ b/tests/quantum_keeper_mt/top_module.h @@ -27,7 +27,7 @@ struct initiator : ::sc_core ::sc_module { SC_THREAD(run); } - ~initiator() {} + ~initiator() = default; private: void run() { @@ -79,7 +79,7 @@ struct top_module : ::sc_core ::sc_module { SC_THREAD(run); } - ~top_module() {} + ~top_module() = default; void b_transport(tlm::tlm_generic_payload& gp, sc_core::sc_time& t) { SCCDEBUG(SCMOD) << "Received b_transport call at local time " << t; diff --git a/tests/tlm_memory/CMakeLists.txt b/tests/tlm_memory/CMakeLists.txt index ec5fda1..31e2864 100644 --- a/tests/tlm_memory/CMakeLists.txt +++ b/tests/tlm_memory/CMakeLists.txt @@ -5,4 +5,6 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC scc::components test_util) -catch_discover_tests(${PROJECT_NAME}) +if(NOT THREAD_SANITIZER) + catch_discover_tests(${PROJECT_NAME}) +endif() \ No newline at end of file