diff options
-rw-r--r-- | test/common.h | 12 | ||||
-rw-r--r-- | test/test_audio.cpp | 5 | ||||
-rw-r--r-- | test/test_callback_ret.cpp | 5 | ||||
-rw-r--r-- | test/test_deadlock.cpp | 2 | ||||
-rw-r--r-- | test/test_devices.cpp | 3 | ||||
-rw-r--r-- | test/test_duplex.cpp | 44 | ||||
-rw-r--r-- | test/test_latency.cpp | 2 | ||||
-rw-r--r-- | test/test_loopback.cpp | 3 | ||||
-rw-r--r-- | test/test_overload_callback.cpp | 2 | ||||
-rw-r--r-- | test/test_record.cpp | 16 | ||||
-rw-r--r-- | test/test_sanity.cpp | 3 | ||||
-rw-r--r-- | test/test_tone.cpp | 6 |
12 files changed, 71 insertions, 32 deletions
diff --git a/test/common.h b/test/common.h index 43af6a9..f085d81 100644 --- a/test/common.h +++ b/test/common.h @@ -93,6 +93,18 @@ void print_log(const char * msg, ...) * override. */ int common_init(cubeb ** ctx, char const * ctx_name) { +#ifdef ENABLE_NORMAL_LOG + if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, print_log) != CUBEB_OK) { + fprintf(stderr, "Set normal log callback failed\n"); + } +#endif + +#ifdef ENABLE_VERBOSE_LOG + if (cubeb_set_log_callback(CUBEB_LOG_VERBOSE, print_log) != CUBEB_OK) { + fprintf(stderr, "Set verbose log callback failed\n"); + } +#endif + int r; char const * backend; char const * ctx_backend; diff --git a/test/test_audio.cpp b/test/test_audio.cpp index 2e6c34a..98ba197 100644 --- a/test/test_audio.cpp +++ b/test/test_audio.cpp @@ -17,9 +17,12 @@ #include <memory> #include <string.h> #include "cubeb/cubeb.h" -#include "common.h" #include <string> +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG +#include "common.h" + using namespace std; #define MAX_NUM_CHANNELS 32 diff --git a/test/test_callback_ret.cpp b/test/test_callback_ret.cpp index bc0a89e..517d847 100644 --- a/test/test_callback_ret.cpp +++ b/test/test_callback_ret.cpp @@ -1,5 +1,5 @@ /* -* Copyright � 2017 Mozilla Foundation +* Copyright � 2017 Mozilla Foundation * * This program is made available under an ISC-style license. See the * accompanying file LICENSE for details. @@ -15,6 +15,9 @@ #include <atomic> #include <string> #include "cubeb/cubeb.h" + +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" const uint32_t SAMPLE_FREQUENCY = 48000; diff --git a/test/test_deadlock.cpp b/test/test_deadlock.cpp index bc572af..0d4d7f5 100644 --- a/test/test_deadlock.cpp +++ b/test/test_deadlock.cpp @@ -43,6 +43,8 @@ */ #include "gtest/gtest.h" +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" // for layout_infos #include "cubeb/cubeb.h" // for cubeb utils #include "cubeb_utils.h" // for owned_critical_section, auto_lock diff --git a/test/test_devices.cpp b/test/test_devices.cpp index f9df89f..73af3c1 100644 --- a/test/test_devices.cpp +++ b/test/test_devices.cpp @@ -13,6 +13,9 @@ #include <string.h> #include <memory> #include "cubeb/cubeb.h" + +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes) diff --git a/test/test_duplex.cpp b/test/test_duplex.cpp index 9fb3e8f..bc71431 100644 --- a/test/test_duplex.cpp +++ b/test/test_duplex.cpp @@ -16,15 +16,22 @@ #include <math.h> #include <memory> #include "cubeb/cubeb.h" -#include "common.h" #include <atomic> +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG +#include "common.h" + #define SAMPLE_FREQUENCY 48000 #define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE +#define INPUT_CHANNELS 1 +#define INPUT_LAYOUT CUBEB_LAYOUT_MONO +#define OUTPUT_CHANNELS 2 +#define OUTPUT_LAYOUT CUBEB_LAYOUT_STEREO struct user_state_duplex { - std::atomic<int> seen_audio{ 0 }; + std::atomic<int> invalid_audio_value{ 0 }; }; long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes) @@ -32,7 +39,6 @@ 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 = 1; if (stream == NULL || inputbuffer == NULL || outputbuffer == NULL) { return CUBEB_ERROR; @@ -42,16 +48,14 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer // checking if there is noise in the process. long output_index = 0; for (long i = 0; i < nframes; i++) { - if (ib[i] <= -1.0 && ib[i] >= 1.0) { - seen_audio = 0; + if (ib[i] <= -1.0 || ib[i] >= 1.0) { + u->invalid_audio_value = 1; break; } ob[output_index] = ob[output_index + 1] = ib[i]; output_index += 2; } - u->seen_audio |= seen_audio; - return nframes; } @@ -98,14 +102,14 @@ TEST(cubeb, duplex) /* typical user-case: mono input, stereo output, low latency. */ input_params.format = STREAM_FORMAT; - input_params.rate = 48000; - input_params.channels = 1; - input_params.layout = CUBEB_LAYOUT_MONO; + input_params.rate = SAMPLE_FREQUENCY; + input_params.channels = INPUT_CHANNELS; + input_params.layout = INPUT_LAYOUT; input_params.prefs = CUBEB_STREAM_PREF_NONE; output_params.format = STREAM_FORMAT; - output_params.rate = 48000; - output_params.channels = 2; - output_params.layout = CUBEB_LAYOUT_STEREO; + output_params.rate = SAMPLE_FREQUENCY; + output_params.channels = OUTPUT_CHANNELS; + output_params.layout = OUTPUT_LAYOUT; output_params.prefs = CUBEB_STREAM_PREF_NONE; r = cubeb_get_min_latency(ctx, &output_params, &latency_frames); @@ -123,7 +127,7 @@ TEST(cubeb, duplex) delay(500); cubeb_stream_stop(stream); - ASSERT_TRUE(stream_state.seen_audio.load()); + ASSERT_FALSE(stream_state.invalid_audio_value.load()); } void device_collection_changed_callback(cubeb * context, void * user) @@ -156,14 +160,14 @@ TEST(cubeb, duplex_collection_change) /* typical user-case: mono input, stereo output, low latency. */ input_params.format = STREAM_FORMAT; - input_params.rate = 48000; - input_params.channels = 1; - input_params.layout = CUBEB_LAYOUT_MONO; + input_params.rate = SAMPLE_FREQUENCY; + input_params.channels = INPUT_CHANNELS; + input_params.layout = INPUT_LAYOUT; input_params.prefs = CUBEB_STREAM_PREF_NONE; output_params.format = STREAM_FORMAT; - output_params.rate = 48000; - output_params.channels = 2; - output_params.layout = CUBEB_LAYOUT_STEREO; + output_params.rate = SAMPLE_FREQUENCY; + output_params.channels = OUTPUT_CHANNELS; + output_params.layout = OUTPUT_LAYOUT; output_params.prefs = CUBEB_STREAM_PREF_NONE; r = cubeb_get_min_latency(ctx, &output_params, &latency_frames); diff --git a/test/test_latency.cpp b/test/test_latency.cpp index f4aa6b0..5228510 100644 --- a/test/test_latency.cpp +++ b/test/test_latency.cpp @@ -2,6 +2,8 @@ #include <stdlib.h> #include <memory> #include "cubeb/cubeb.h" +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" TEST(cubeb, latency) diff --git a/test/test_loopback.cpp b/test/test_loopback.cpp index 260eb31..2c600ee 100644 --- a/test/test_loopback.cpp +++ b/test/test_loopback.cpp @@ -20,8 +20,9 @@ #include <mutex> #include <string> #include "cubeb/cubeb.h" +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" - const uint32_t SAMPLE_FREQUENCY = 48000; const uint32_t TONE_FREQUENCY = 440; const double OUTPUT_AMPLITUDE = 0.25; diff --git a/test/test_overload_callback.cpp b/test/test_overload_callback.cpp index 05c01e8..4a19ce9 100644 --- a/test/test_overload_callback.cpp +++ b/test/test_overload_callback.cpp @@ -15,6 +15,8 @@ #include <memory> #include <atomic> #include "cubeb/cubeb.h" +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" #define SAMPLE_FREQUENCY 48000 diff --git a/test/test_record.cpp b/test/test_record.cpp index 635beee..ed40a2c 100644 --- a/test/test_record.cpp +++ b/test/test_record.cpp @@ -15,15 +15,18 @@ #include <math.h> #include <memory> #include "cubeb/cubeb.h" -#include "common.h" #include <atomic> +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG +#include "common.h" + #define SAMPLE_FREQUENCY 48000 #define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE struct user_state_record { - std::atomic<int> seen_audio{ 0 }; + std::atomic<int> invalid_audio_value{ 0 }; }; long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes) @@ -35,16 +38,13 @@ long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer return CUBEB_ERROR; } - bool seen_audio = 1; for (long i = 0; i < nframes; i++) { - if (b[i] <= -1.0 && b[i] >= 1.0) { - seen_audio = 0; + if (b[i] <= -1.0 || b[i] >= 1.0) { + u->invalid_audio_value = 1; break; } } - u->seen_audio |= seen_audio; - return nframes; } @@ -111,6 +111,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.load()); + ASSERT_FALSE(stream_state.invalid_audio_value.load()); #endif } diff --git a/test/test_sanity.cpp b/test/test_sanity.cpp index d33666f..5c89617 100644 --- a/test/test_sanity.cpp +++ b/test/test_sanity.cpp @@ -13,6 +13,9 @@ #include <stdio.h> #include <string.h> #include <math.h> + +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG #include "common.h" #define STREAM_RATE 44100 diff --git a/test/test_tone.cpp b/test/test_tone.cpp index 09bc2a7..de4c526 100644 --- a/test/test_tone.cpp +++ b/test/test_tone.cpp @@ -16,9 +16,13 @@ #include <memory> #include <limits.h> #include "cubeb/cubeb.h" -#include "common.h" #include <atomic> +//#define ENABLE_NORMAL_LOG +//#define ENABLE_VERBOSE_LOG +#include "common.h" + + #define SAMPLE_FREQUENCY 48000 #define STREAM_FORMAT CUBEB_SAMPLE_S16LE |