[gtest][tsan] init
:Release Notes: Trying to find sanitizer problem :Detailed Notes: - :Testing Performed: - :QA Notes: - :Issues Addressed: -
This commit is contained in:
commit
07508ba343
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build
|
||||
.cache
|
||||
15
CMakeLists.txt
Normal file
15
CMakeLists.txt
Normal 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
9
CMakeUserPresets.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 4,
|
||||
"vendor": {
|
||||
"conan": {}
|
||||
},
|
||||
"include": [
|
||||
"build/Release/generators/CMakePresets.json"
|
||||
]
|
||||
}
|
||||
1
compile_commands.json
Symbolic link
1
compile_commands.json
Symbolic link
@ -0,0 +1 @@
|
||||
build/Release/compile_commands.json
|
||||
8
conanfile.txt
Normal file
8
conanfile.txt
Normal 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
34
main.cc
Normal 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();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user