[gtest][tsan] init

:Release Notes:
Trying to find sanitizer problem

:Detailed Notes:
-

:Testing Performed:
-

:QA Notes:
-

:Issues Addressed:
-
This commit is contained in:
Artur Mukhamadiev 2025-06-04 20:50:26 +03:00
commit 07508ba343
6 changed files with 69 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build
.cache

15
CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 4.0)
project(ltest)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(GTest REQUIRED)
find_package(readerwriterqueue)
add_executable(${PROJECT_NAME} main.cc)
target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=thread)
target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=thread -std=c++20)
target_link_libraries(${PROJECT_NAME} PRIVATE
readerwriterqueue::readerwriterqueue
gtest::gtest
)

9
CMakeUserPresets.json Normal file
View File

@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/Release/generators/CMakePresets.json"
]
}

1
compile_commands.json Symbolic link
View File

@ -0,0 +1 @@
build/Release/compile_commands.json

8
conanfile.txt Normal file
View File

@ -0,0 +1,8 @@
[requires]
readerwriterqueue/1.0.6
gtest/1.16.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout

34
main.cc Normal file
View File

@ -0,0 +1,34 @@
#include <gtest/gtest.h>
#include <readerwriterqueue/readerwriterqueue.h>
#include <thread>
static constexpr size_t repeat = 1 << 20;
void producer(moodycamel::ReaderWriterQueue<int>& queue) {
for(int i = 0; i < repeat; ++i) {
while(!queue.try_enqueue(i)) { std::this_thread::yield(); }
}
}
void consumer(moodycamel::ReaderWriterQueue<int>& queue) {
size_t counter = 0;
int val = 0;
while(counter < repeat) {
while(!queue.try_dequeue(val)) {
std::this_thread::yield();
}
++counter;
}
}
TEST(BASIC, rwq) {
moodycamel::ReaderWriterQueue<int> queue;
std::jthread t1{&producer, std::ref(queue)};
std::jthread t2{&consumer, std::ref(queue)};
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}