aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2022-12-08 17:39:01 +0100
committerPaul Adenot <[email protected]>2022-12-12 12:03:47 +0100
commit6a6113b6ff245cb6def00a92db3a35a26032dbea (patch)
tree845001cd02ac032eebba28828f6936bfe2ba8856 /test
parent8eedc123691ec5f2249f39071dd4e911a73e5a98 (diff)
downloadcubeb-6a6113b6ff245cb6def00a92db3a35a26032dbea.tar.gz
cubeb-6a6113b6ff245cb6def00a92db3a35a26032dbea.zip
Add a test to stress test the asynchronous logging system
Diffstat (limited to 'test')
-rw-r--r--test/test_logging.cpp42
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);
+}