]> code.delx.au - pulseaudio/commitdiff
tests: Run svolume on different channel counts
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Tue, 30 Oct 2012 06:00:16 +0000 (11:30 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Tue, 30 Oct 2012 09:30:45 +0000 (15:00 +0530)
This adds checks to run svolume tests with 1, 2 and 3 channels (we don't
run Orc with 3 channels since only 1/2-ch are implemented there).

src/tests/cpu-test.c

index 1b02ae1fbc7099e5e0abd05e28babe8648fa4315..924807d01ee94faa69465cdef054aa1d94948751 100644 (file)
 }
 
 /* Common defines for svolume tests */
-#define CHANNELS 2
 #define SAMPLES 1028
 #define TIMES 1000
 #define TIMES2 100
 #define PADDING 16
 
-static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_func, int align, pa_bool_t correct,
-        pa_bool_t perf) {
+static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_func, int align, int channels,
+        pa_bool_t correct, pa_bool_t perf) {
     PA_DECLARE_ALIGNED(8, int16_t, s[SAMPLES]) = { 0 };
     PA_DECLARE_ALIGNED(8, int16_t, s_ref[SAMPLES]) = { 0 };
     PA_DECLARE_ALIGNED(8, int16_t, s_orig[SAMPLES]) = { 0 };
-    int32_t volumes[CHANNELS + PADDING];
+    int32_t volumes[channels + PADDING];
     int16_t *samples, *samples_ref, *samples_orig;
     int i, padding, nsamples, size;
 
@@ -84,43 +83,43 @@ static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_f
     samples_ref = s_ref + (8 - align);
     samples_orig = s_orig + (8 - align);
     nsamples = SAMPLES - (8 - align);
-    nsamples += nsamples % CHANNELS;
+    nsamples += nsamples % channels;
     size = nsamples * sizeof(*samples);
 
     pa_random(samples, size);
     memcpy(samples_ref, samples, size);
     memcpy(samples_orig, samples, size);
 
-    for (i = 0; i < CHANNELS; i++)
+    for (i = 0; i < channels; i++)
         volumes[i] = PA_CLAMP_VOLUME((pa_volume_t)(rand() >> 15));
     for (padding = 0; padding < PADDING; padding++, i++)
         volumes[i] = volumes[padding];
 
     if (correct) {
-        orig_func(samples_ref, volumes, CHANNELS, size);
-        func(samples, volumes, CHANNELS, size);
+        orig_func(samples_ref, volumes, channels, size);
+        func(samples, volumes, channels, size);
 
         for (i = 0; i < nsamples; i++) {
             if (samples[i] != samples_ref[i]) {
-                pa_log_debug("Correctness test failed: align=%d", align);
+                pa_log_debug("Correctness test failed: align=%d, channels=%d", align, channels);
                 pa_log_debug("%d: %04x != %04x (%04x * %08x)\n", i, samples[i], samples_ref[i],
-                        samples_orig[i], volumes[i % CHANNELS]);
+                        samples_orig[i], volumes[i % channels]);
                 fail();
             }
         }
     }
 
     if (perf) {
-        pa_log_debug("Testing svolume performance with %d byte alignment", align);
+        pa_log_debug("Testing svolume %dch performance with %d byte alignment", channels, align);
 
         PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) {
             memcpy(samples, samples_orig, size);
-            func(samples, volumes, CHANNELS, size);
+            func(samples, volumes, channels, size);
         } PA_CPU_TEST_RUN_STOP
 
         PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) {
             memcpy(samples_ref, samples_orig, size);
-            orig_func(samples_ref, volumes, CHANNELS, size);
+            orig_func(samples_ref, volumes, channels, size);
         } PA_CPU_TEST_RUN_STOP
 
         fail_unless(memcmp(samples_ref, samples, size) == 0);
@@ -131,6 +130,7 @@ static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_f
 START_TEST (svolume_mmx_test) {
     pa_do_volume_func_t orig_func, mmx_func;
     pa_cpu_x86_flag_t flags = 0;
+    int i, j;
 
     pa_cpu_get_x86_flags(&flags);
 
@@ -144,20 +144,20 @@ START_TEST (svolume_mmx_test) {
     mmx_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
     pa_log_debug("Checking MMX svolume");
-    run_volume_test(mmx_func, orig_func, 0, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 1, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 2, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 3, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 4, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 5, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 6, TRUE, FALSE);
-    run_volume_test(mmx_func, orig_func, 7, TRUE, TRUE);
+    for (i = 1; i <= 3; i++) {
+        for (j = 0; j < 7; j++)
+            run_volume_test(mmx_func, orig_func, j, i, TRUE, FALSE);
+    }
+    run_volume_test(mmx_func, orig_func, 7, 1, TRUE, TRUE);
+    run_volume_test(mmx_func, orig_func, 7, 2, TRUE, TRUE);
+    run_volume_test(mmx_func, orig_func, 7, 3, TRUE, TRUE);
 }
 END_TEST
 
 START_TEST (svolume_sse_test) {
     pa_do_volume_func_t orig_func, sse_func;
     pa_cpu_x86_flag_t flags = 0;
+    int i, j;
 
     pa_cpu_get_x86_flags(&flags);
 
@@ -171,14 +171,13 @@ START_TEST (svolume_sse_test) {
     sse_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
     pa_log_debug("Checking SSE2 svolume");
-    run_volume_test(sse_func, orig_func, 0, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 1, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 2, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 3, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 4, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 5, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 6, TRUE, FALSE);
-    run_volume_test(sse_func, orig_func, 7, TRUE, TRUE);
+    for (i = 1; i <= 3; i++) {
+        for (j = 0; j < 7; j++)
+            run_volume_test(sse_func, orig_func, j, i, TRUE, FALSE);
+    }
+    run_volume_test(sse_func, orig_func, 7, 1, TRUE, TRUE);
+    run_volume_test(sse_func, orig_func, 7, 2, TRUE, TRUE);
+    run_volume_test(sse_func, orig_func, 7, 3, TRUE, TRUE);
 }
 END_TEST
 #endif /* defined (__i386__) || defined (__amd64__) */
@@ -187,6 +186,7 @@ END_TEST
 START_TEST (svolume_arm_test) {
     pa_do_volume_func_t orig_func, arm_func;
     pa_cpu_arm_flag_t flags = 0;
+    int i, j;
 
     pa_cpu_get_arm_flags(&flags);
 
@@ -200,14 +200,13 @@ START_TEST (svolume_arm_test) {
     arm_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
     pa_log_debug("Checking ARM svolume");
-    run_volume_test(arm_func, orig_func, 0, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 1, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 2, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 3, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 4, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 5, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 6, TRUE, TRUE);
-    run_volume_test(arm_func, orig_func, 7, TRUE, TRUE);
+    for (i = 1; i <= 3; i++) {
+        for (j = 0; j < 7; j++)
+            run_volume_test(arm_func, orig_func, j, i, TRUE, FALSE);
+    }
+    run_volume_test(arm_func, orig_func, 7, 1, TRUE, TRUE);
+    run_volume_test(arm_func, orig_func, 7, 2, TRUE, TRUE);
+    run_volume_test(arm_func, orig_func, 7, 3, TRUE, TRUE);
 }
 END_TEST
 #endif /* defined (__arm__) && defined (__linux__) */
@@ -215,6 +214,7 @@ END_TEST
 START_TEST (svolume_orc_test) {
     pa_do_volume_func_t orig_func, orc_func;
     pa_cpu_info cpu_info;
+    int i, j;
 
 #if defined (__i386__) || defined (__amd64__)
     pa_zero(cpu_info);
@@ -232,18 +232,15 @@ START_TEST (svolume_orc_test) {
     orc_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
     pa_log_debug("Checking Orc svolume");
-    run_volume_test(orc_func, orig_func, 0, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 1, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 2, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 3, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 4, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 5, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 6, TRUE, FALSE);
-    run_volume_test(orc_func, orig_func, 7, TRUE, TRUE);
+    for (i = 1; i <= 2; i++) {
+        for (j = 0; j < 7; j++)
+            run_volume_test(orc_func, orig_func, j, i, TRUE, FALSE);
+    }
+    run_volume_test(orc_func, orig_func, 7, 1, TRUE, TRUE);
+    run_volume_test(orc_func, orig_func, 7, 2, TRUE, TRUE);
 }
 END_TEST
 
-#undef CHANNELS
 #undef SAMPLES
 #undef TIMES
 #undef TIMES2