aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_deadlock.cpp11
-rw-r--r--test/test_duplex.cpp11
-rw-r--r--test/test_record.cpp11
-rw-r--r--test/test_tone.cpp5
4 files changed, 21 insertions, 17 deletions
diff --git a/test/test_deadlock.cpp b/test/test_deadlock.cpp
index 64ca6e7..42301ac 100644
--- a/test/test_deadlock.cpp
+++ b/test/test_deadlock.cpp
@@ -52,6 +52,7 @@
#include <stdexcept> // for std::logic_error
#include <string> // for std::string
#include <unistd.h> // for sleep, usleep
+#include <atomic> // for std::atomic
// The signal alias for calling our thread killer.
#define CALL_THREAD_KILLER SIGUSR1
@@ -61,7 +62,7 @@
bool killed = false;
// This indicator will become true when the assigned task is done.
-bool task_done = false;
+std::atomic<bool> task_done{ false };
// Indicating the data callback is fired or not.
bool called = false;
@@ -69,7 +70,7 @@ bool called = false;
// Toggle to true when running data callback. Before data callback gets
// the mutex for cubeb context, it toggles back to false.
// The task to get channel layout should be executed when this is true.
-bool callbacking_before_getting_context = false;
+std::atomic<bool> callbacking_before_getting_context{ false };
owned_critical_section context_mutex;
cubeb * context = nullptr;
@@ -242,11 +243,11 @@ TEST(cubeb, run_deadlock_test)
ASSERT_TRUE(called);
- fprintf(stderr, "\n%sDeadlock detected!\n", (called && !task_done) ? "" : "No ");
+ fprintf(stderr, "\n%sDeadlock detected!\n", (called && !task_done.load()) ? "" : "No ");
// Check the task is killed by ourselves if deadlock happends.
// Otherwise, thread_killer should not be triggered.
- ASSERT_NE(task_done, killed);
+ ASSERT_NE(task_done.load(), killed);
- ASSERT_TRUE(task_done);
+ ASSERT_TRUE(task_done.load());
}
diff --git a/test/test_duplex.cpp b/test/test_duplex.cpp
index 3437762..6237c1a 100644
--- a/test/test_duplex.cpp
+++ b/test/test_duplex.cpp
@@ -17,13 +17,14 @@
#include <memory>
#include "cubeb/cubeb.h"
#include "common.h"
+#include <atomic>
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
struct user_state_duplex
{
- bool seen_audio;
+ std::atomic<int> seen_audio{ 0 };
};
long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
@@ -31,7 +32,7 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
user_state_duplex * u = reinterpret_cast<user_state_duplex*>(user);
float *ib = (float *)inputbuffer;
float *ob = (float *)outputbuffer;
- bool seen_audio = true;
+ bool seen_audio = 1;
if (stream == NULL || inputbuffer == NULL || outputbuffer == NULL) {
return CUBEB_ERROR;
@@ -42,7 +43,7 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
long output_index = 0;
for (long i = 0; i < nframes; i++) {
if (ib[i] <= -1.0 && ib[i] >= 1.0) {
- seen_audio = false;
+ seen_audio = 0;
break;
}
ob[output_index] = ob[output_index + 1] = ib[i];
@@ -80,7 +81,7 @@ TEST(cubeb, duplex)
cubeb_stream_params input_params;
cubeb_stream_params output_params;
int r;
- user_state_duplex stream_state = { false };
+ user_state_duplex stream_state;
uint32_t latency_frames = 0;
r = common_init(&ctx, "Cubeb duplex example");
@@ -120,5 +121,5 @@ TEST(cubeb, duplex)
delay(500);
cubeb_stream_stop(stream);
- ASSERT_TRUE(stream_state.seen_audio);
+ ASSERT_TRUE(stream_state.seen_audio.load());
}
diff --git a/test/test_record.cpp b/test/test_record.cpp
index 9a65d3b..b25eb8a 100644
--- a/test/test_record.cpp
+++ b/test/test_record.cpp
@@ -16,13 +16,14 @@
#include <memory>
#include "cubeb/cubeb.h"
#include "common.h"
+#include <atomic>
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
struct user_state_record
{
- bool seen_audio;
+ std::atomic<int> seen_audio{ 0 };
};
long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
@@ -34,10 +35,10 @@ long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer
return CUBEB_ERROR;
}
- bool seen_audio = true;
+ bool seen_audio = 1;
for (long i = 0; i < nframes; i++) {
if (b[i] <= -1.0 && b[i] >= 1.0) {
- seen_audio = false;
+ seen_audio = 0;
break;
}
}
@@ -75,7 +76,7 @@ TEST(cubeb, record)
cubeb_stream *stream;
cubeb_stream_params params;
int r;
- user_state_record stream_state = { false };
+ user_state_record stream_state;
r = common_init(&ctx, "Cubeb record example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
@@ -109,6 +110,6 @@ TEST(cubeb, record)
// user callback does not arrive in Linux, silence the error
fprintf(stderr, "Check is disabled in Linux\n");
#else
- ASSERT_TRUE(stream_state.seen_audio);
+ ASSERT_TRUE(stream_state.seen_audio.load());
#endif
}
diff --git a/test/test_tone.cpp b/test/test_tone.cpp
index 47d9675..3cfc0b0 100644
--- a/test/test_tone.cpp
+++ b/test/test_tone.cpp
@@ -17,13 +17,14 @@
#include <limits.h>
#include "cubeb/cubeb.h"
#include "common.h"
+#include <atomic>
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_S16LE
/* store the phase of the generated waveform */
struct cb_user_data {
- long position;
+ std::atomic<long> position;
};
long data_cb_tone(cubeb_stream *stream, void *user, const void* /*inputbuffer*/, void *outputbuffer, long nframes)
@@ -111,5 +112,5 @@ TEST(cubeb, tone)
delay(500);
cubeb_stream_stop(stream);
- ASSERT_TRUE(user_data->position);
+ ASSERT_TRUE(user_data->position.load());
}