diff options
author | Paul Adenot <[email protected]> | 2022-12-08 17:39:01 +0100 |
---|---|---|
committer | Paul Adenot <[email protected]> | 2022-12-12 12:01:56 +0100 |
commit | d7fd1a456010bc932d8c77ad510a4031c9bfaa35 (patch) | |
tree | 845001cd02ac032eebba28828f6936bfe2ba8856 | |
parent | 35f4489ef4edd83f2207a5da0ab5f74e96ccede4 (diff) | |
download | cubeb-d7fd1a456010bc932d8c77ad510a4031c9bfaa35.tar.gz cubeb-d7fd1a456010bc932d8c77ad510a4031c9bfaa35.zip |
Add a test to stress test the asynchronous logging systemtsan-fixes
-rw-r--r-- | test/test_logging.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/test/test_logging.cpp b/test/test_logging.cpp index 2e206ae..5d9691d 100644 --- a/test/test_logging.cpp +++ b/test/test_logging.cpp @@ -11,11 +11,13 @@ #define _XOPEN_SOURCE 600 #endif #include "cubeb/cubeb.h" +#include "cubeb_log.h" #include <atomic> #include <math.h> #include <memory> #include <stdio.h> #include <stdlib.h> +#include <thread> #include "common.h" @@ -70,9 +72,11 @@ state_cb(cubeb_stream * stream, void * /*user*/, cubeb_state state) } // Waits for at least one audio callback to have occured. -void wait_for_audio_callback() { +void +wait_for_audio_callback() +{ uint32_t audio_callback_index = - data_callback_call_count.load(std::memory_order_acquire); + data_callback_call_count.load(std::memory_order_acquire); while (audio_callback_index == data_callback_call_count.load(std::memory_order_acquire)) { delay(100); @@ -153,3 +157,37 @@ TEST(cubeb, logging) cubeb_stream_stop(stream); } + +TEST(cubeb, logging_stress) +{ + cubeb_set_log_callback(CUBEB_LOG_NORMAL, test_logging_callback); + + std::atomic<bool> thread_done = {false}; + + auto t = std::thread([&thread_done]() { + uint32_t count = 0; + do { + while (rand() % 10) { + ALOG("Log message #%d!", count++); + } + } while (count < 1e4); + thread_done.store(true); + }); + + bool enabled = true; + while (!thread_done.load()) { + if (enabled) { + cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr); + enabled = false; + } else { + cubeb_set_log_callback(CUBEB_LOG_NORMAL, test_logging_callback); + enabled = true; + } + } + + cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr); + + t.join(); + + ASSERT_TRUE(true); +} |