Bug 946618 - Skip some cubeb tests on some platforms. r=kinetik
authorPaul Adenot <paul@paul.cx>
Mon, 24 Mar 2014 11:06:05 +0100
changeset 195198 758934b7d585da426682a05bfd3f04805067a8b7
parent 195197 109ba6e08a764cc431d5981eb4febd143cb5c343
child 195199 3aa0b31ea0ab42602e42cb3cf6631c119e6bb359
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs946618
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 946618 - Skip some cubeb tests on some platforms. r=kinetik For example, skip float tests on platform that don't support floating point audio, and skip timing test on platform where we don't honor latency request.
media/libcubeb/tests/test_audio.cpp
media/libcubeb/tests/test_sanity.cpp
--- a/media/libcubeb/tests/test_audio.cpp
+++ b/media/libcubeb/tests/test_audio.cpp
@@ -10,16 +10,17 @@
 #ifdef NDEBUG
 #undef NDEBUG
 #endif
 #define _XOPEN_SOURCE 500
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include <assert.h>
+#include <string.h>
 
 #include "cubeb/cubeb.h"
 #include "common.h"
 
 #define MAX_NUM_CHANNELS 32
 
 #if !defined(M_PI)
 #define M_PI 3.14159265358979323846
@@ -92,45 +93,68 @@ long data_cb_short(cubeb_stream *stream,
   synth_run_16bit(synth, (short*)buffer, nframes);
   return nframes;
 }
 
 void state_cb(cubeb_stream *stream, void *user, cubeb_state state)
 {
 }
 
+/* Our android backends don't support float, only int16. */
+int supports_float32(const char* backend_id)
+{
+  return (strcmp(backend_id, "opensl") != 0 &&
+          strcmp(backend_id, "audiotrack") != 0);
+}
+
+/* Some backends don't have code to deal with more than mono or stereo. */
+int supports_channel_count(const char* backend_id, int nchannels)
+{
+  return nchannels <= 2 ||
+    (strcmp(backend_id, "opensl") != 0 && strcmp(backend_id, "audiotrack") != 0);
+}
+
 int run_test(int num_channels, int sampling_rate, int is_float)
 {
   int ret = CUBEB_OK;
 
   cubeb *ctx = NULL;
   synth_state* synth = NULL;
   cubeb_stream *stream = NULL;
+  const char * backend_id = NULL;
 
   ret = cubeb_init(&ctx, "Cubeb audio test");
   if (ret != CUBEB_OK) {
     fprintf(stderr, "Error initializing cubeb library\n");
     goto cleanup;
   }
 
+  backend_id = cubeb_get_backend_id(ctx);
+
+  if ((is_float && !supports_float32(backend_id)) ||
+      !supports_channel_count(backend_id, num_channels)) {
+    /* don't treat this as a test failure. */
+    goto cleanup;
+  }
+
   fprintf(stderr, "Testing %d channel(s), %d Hz, %s (%s)\n", num_channels, sampling_rate, is_float ? "float" : "short", cubeb_get_backend_id(ctx));
 
   cubeb_stream_params params;
   params.format = is_float ? CUBEB_SAMPLE_FLOAT32NE : CUBEB_SAMPLE_S16NE;
   params.rate = sampling_rate;
   params.channels = num_channels;
 
   synth = synth_create(params.channels, params.rate);
   if (synth == NULL) {
     fprintf(stderr, "Out of memory\n");
     goto cleanup;
   }
 
   ret = cubeb_stream_init(ctx, &stream, "test tone", params,
-                          250, is_float ? data_cb_float : data_cb_short, state_cb, synth);
+                          100, is_float ? data_cb_float : data_cb_short, state_cb, synth);
   if (ret != CUBEB_OK) {
     fprintf(stderr, "Error initializing cubeb stream: %d\n", ret);
     goto cleanup;
   }
 
   cubeb_stream_start(stream);
   delay(200);
   cubeb_stream_stop(stream);
@@ -143,32 +167,33 @@ cleanup:
   return ret;
 }
 
 int main(int argc, char *argv[])
 {
   int channel_values[] = {
     1,
     2,
+    3,
     4,
-    5,
     6,
   };
 
   int freq_values[] = {
+    16000,
     24000,
     44100,
     48000,
   };
 
-  for(int j=0;j < NELEMS(channel_values);++j) {
-    for(int i=0;i < NELEMS(freq_values);++i) {
+  for(int j = 0; j < NELEMS(channel_values); ++j) {
+    for(int i = 0; i < NELEMS(freq_values); ++i) {
       assert(channel_values[j] < MAX_NUM_CHANNELS);
       fprintf(stderr, "--------------------------\n");
-      run_test(channel_values[j], freq_values[i], 0);
-      run_test(channel_values[j], freq_values[i], 1);
+      assert(run_test(channel_values[j], freq_values[i], 0) == CUBEB_OK);
+      assert(run_test(channel_values[j], freq_values[i], 1) == CUBEB_OK);
     }
   }
 
   return CUBEB_OK;
 }
 
 
--- a/media/libcubeb/tests/test_sanity.cpp
+++ b/media/libcubeb/tests/test_sanity.cpp
@@ -10,16 +10,24 @@
 #define _XOPEN_SOURCE 500
 #include "cubeb/cubeb.h"
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 #include "common.h"
 
+#if defined ( WIN32 )
+#define __func__ __FUNCTION__
+#endif
+
+#define ARRAY_LENGTH(_x) (sizeof(_x) / sizeof(_x[0]))
+#define BEGIN_TEST fprintf(stderr, "START %s\n", __func__);
+#define END_TEST fprintf(stderr, "END %s\n", __func__);
+
 #define STREAM_LATENCY 100
 #define STREAM_RATE 44100
 #define STREAM_CHANNELS 1
 #define STREAM_FORMAT CUBEB_SAMPLE_S16LE
 
 static int dummy;
 static uint64_t total_frames_written;
 static int delay_callback;
@@ -42,113 +50,133 @@ test_state_callback(cubeb_stream * stm, 
 }
 
 static void
 test_init_destroy_context(void)
 {
   int r;
   cubeb * ctx;
 
+  BEGIN_TEST
+
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   cubeb_destroy(ctx);
+
+  END_TEST
 }
 
 static void
 test_init_destroy_multiple_contexts(void)
 {
   int i;
   int r;
   cubeb * ctx[4];
 
+  BEGIN_TEST
+
   for (i = 0; i < 4; ++i) {
     r = cubeb_init(&ctx[i], NULL);
     assert(r == 0 && ctx[i]);
   }
 
   /* destroy in a different order */
   cubeb_destroy(ctx[2]);
   cubeb_destroy(ctx[0]);
   cubeb_destroy(ctx[3]);
   cubeb_destroy(ctx[1]);
+
+  END_TEST
 }
 
 static void
 test_init_destroy_stream(void)
 {
   int r;
   cubeb * ctx;
   cubeb_stream * stream;
   cubeb_stream_params params;
 
+  BEGIN_TEST
+
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
   r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY,
                         test_data_callback, test_state_callback, &dummy);
   assert(r == 0 && stream);
 
   cubeb_stream_destroy(stream);
   cubeb_destroy(ctx);
+
+  END_TEST
 }
 
 static void
 test_init_destroy_multiple_streams(void)
 {
   int i;
   int r;
   cubeb * ctx;
   cubeb_stream * stream[16];
   cubeb_stream_params params;
 
+  BEGIN_TEST
+
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
   for (i = 0; i < 16; ++i) {
     r = cubeb_stream_init(ctx, &stream[i], "test", params, STREAM_LATENCY,
                           test_data_callback, test_state_callback, &dummy);
-    assert(r == 0 && stream[i]);
+    assert(r == 0);
+    assert(stream[i]);
   }
 
   for (i = 0; i < 16; ++i) {
     cubeb_stream_destroy(stream[i]);
   }
 
   cubeb_destroy(ctx);
+
+  END_TEST
 }
 
 static void
 test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
 {
   int i;
   int r;
   cubeb * ctx;
   cubeb_stream * stream[16];
   cubeb_stream_params params;
 
+  BEGIN_TEST
+
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
   for (i = 0; i < 16; ++i) {
     r = cubeb_stream_init(ctx, &stream[i], "test", params, STREAM_LATENCY,
                           test_data_callback, test_state_callback, &dummy);
-    assert(r == 0 && stream[i]);
+    assert(r == 0);
+    assert(stream[i]);
     if (early) {
       r = cubeb_stream_start(stream[i]);
       assert(r == 0);
     }
   }
 
 
   if (!early) {
@@ -173,59 +201,68 @@ test_init_start_stop_destroy_multiple_st
     if (early) {
       r = cubeb_stream_stop(stream[i]);
       assert(r == 0);
     }
     cubeb_stream_destroy(stream[i]);
   }
 
   cubeb_destroy(ctx);
+
+  END_TEST
 }
 
 static void
 test_init_destroy_multiple_contexts_and_streams(void)
 {
   int i, j;
   int r;
   cubeb * ctx[4];
   cubeb_stream * stream[16];
   cubeb_stream_params params;
 
+  BEGIN_TEST
+
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
   for (i = 0; i < 4; ++i) {
     r = cubeb_init(&ctx[i], "test_sanity");
     assert(r == 0 && ctx[i]);
 
     for (j = 0; j < 4; ++j) {
       r = cubeb_stream_init(ctx[i], &stream[i * 4 + j], "test", params, STREAM_LATENCY,
                             test_data_callback, test_state_callback, &dummy);
-      assert(r == 0 && stream[i * 4 + j]);
+      assert(r == 0);
+      assert(stream[i * 4 + j]);
     }
   }
 
   for (i = 0; i < 4; ++i) {
     for (j = 0; j < 4; ++j) {
       cubeb_stream_destroy(stream[i * 4 + j]);
     }
     cubeb_destroy(ctx[i]);
   }
+
+  END_TEST
 }
 
 static void
 test_basic_stream_operations(void)
 {
   int r;
   cubeb * ctx;
   cubeb_stream * stream;
   cubeb_stream_params params;
   uint64_t position;
 
+  BEGIN_TEST
+
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
   r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY,
@@ -247,28 +284,32 @@ test_basic_stream_operations(void)
   assert(r == 0);
 
   /* position and volume after stream has stopped */
   r = cubeb_stream_get_position(stream, &position);
   assert(r == 0);
 
   cubeb_stream_destroy(stream);
   cubeb_destroy(ctx);
+
+  END_TEST
 }
 
 static void
 test_stream_position(void)
 {
   int i;
   int r;
   cubeb * ctx;
   cubeb_stream * stream;
   cubeb_stream_params params;
   uint64_t position, last_position;
 
+  BEGIN_TEST
+
   total_frames_written = 0;
 
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
@@ -333,16 +374,18 @@ test_stream_position(void)
   delay(500);
 
   r = cubeb_stream_get_position(stream, &position);
   assert(r == 0);
   assert(position == last_position);
 
   cubeb_stream_destroy(stream);
   cubeb_destroy(ctx);
+
+  END_TEST
 }
 
 static int do_drain;
 static int got_drain;
 
 static long
 test_drain_data_callback(cubeb_stream * stm, void * user_ptr, void * p, long nframes)
 {
@@ -371,16 +414,18 @@ static void
 test_drain(void)
 {
   int r;
   cubeb * ctx;
   cubeb_stream * stream;
   cubeb_stream_params params;
   uint64_t position;
 
+  BEGIN_TEST
+
   total_frames_written = 0;
 
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
@@ -397,21 +442,33 @@ test_drain(void)
   do_drain = 1;
 
   for (;;) {
     r = cubeb_stream_get_position(stream, &position);
     assert(r == 0);
     if (got_drain) {
       break;
     } else {
-      // Latency passed to cubeb_stream_init is not really honored on OSX and
-      // winmm, skip this test.
+      uint32_t i, skip = 0;
+      /* Latency passed to cubeb_stream_init is not really honored on OSX,
+         win32/winmm and android, skip this test. */
       const char * backend_id = cubeb_get_backend_id(ctx);
-      if (strcmp(backend_id, "audiounit") != 0 &&
-          strcmp(backend_id, "winmm") != 0) {
+      const char * latency_not_honored_bakends[] = {
+        "audiounit",
+        "winmm",
+        "audiotrack",
+        "opensl"
+      };
+
+      for (i = 0; i < ARRAY_LENGTH(latency_not_honored_bakends); i++) {
+        if (!strcmp(backend_id, latency_not_honored_bakends[i])) {
+          skip = 1;
+        }
+      }
+      if (!skip) {
         /* Position should roughly be equal to the number of written frames. We
          * need to take the latency into account. */
         int latency = (STREAM_LATENCY * STREAM_RATE) / 1000;
         assert(position + latency <= total_frames_written);
       }
     }
     delay(500);
   }
@@ -420,45 +477,40 @@ test_drain(void)
   assert(r == 0);
   assert(got_drain);
 
   // Disabled due to failures in the ALSA backend.
   //assert(position == total_frames_written);
 
   cubeb_stream_destroy(stream);
   cubeb_destroy(ctx);
-}
 
-static void
-progress(void)
-{
-  printf(".");
-  fflush(stdout);
+  END_TEST
 }
 
 int
 main(int argc, char * argv[])
 {
-  test_init_destroy_context(); progress();
-  test_init_destroy_multiple_contexts(); progress();
-  test_init_destroy_stream(); progress();
-  test_init_destroy_multiple_streams(); progress();
-  test_init_destroy_multiple_contexts_and_streams(); progress();
-  test_basic_stream_operations(); progress();
-  test_stream_position(); progress();
+  test_init_destroy_context();
+  test_init_destroy_multiple_contexts();
+  test_init_destroy_stream();
+  test_init_destroy_multiple_streams();
+  test_init_destroy_multiple_contexts_and_streams();
+  test_basic_stream_operations();
+  test_stream_position();
   delay_callback = 0;
-  test_init_start_stop_destroy_multiple_streams(0, 0); progress();
-  test_init_start_stop_destroy_multiple_streams(1, 0); progress();
-  test_init_start_stop_destroy_multiple_streams(0, 150); progress();
-  test_init_start_stop_destroy_multiple_streams(1, 150); progress();
+  test_init_start_stop_destroy_multiple_streams(0, 0);
+  test_init_start_stop_destroy_multiple_streams(1, 0);
+  test_init_start_stop_destroy_multiple_streams(0, 150);
+  test_init_start_stop_destroy_multiple_streams(1, 150);
   delay_callback = 1;
-  test_init_start_stop_destroy_multiple_streams(0, 0); progress();
-  test_init_start_stop_destroy_multiple_streams(1, 0); progress();
-  test_init_start_stop_destroy_multiple_streams(0, 150); progress();
-  test_init_start_stop_destroy_multiple_streams(1, 150); progress();
+  test_init_start_stop_destroy_multiple_streams(0, 0);
+  test_init_start_stop_destroy_multiple_streams(1, 0);
+  test_init_start_stop_destroy_multiple_streams(0, 150);
+  test_init_start_stop_destroy_multiple_streams(1, 150);
   delay_callback = 0;
   test_drain();
 /*
   to implement:
   test_eos_during_prefill();
   test_stream_destroy_pending_drain();
 */
   printf("\n");