tests: Run svolume test for various sample alignments

Allows us to make sure that svolume works independently of sample
alignment, and that performance doesn't degrade based on this.
This commit is contained in:
Arun Raghavan 2012-10-30 09:30:32 +05:30
parent 6fe3bfe6df
commit a172db5c0d

View file

@ -65,48 +65,67 @@
/* Common defines for svolume tests */ /* Common defines for svolume tests */
#define CHANNELS 2 #define CHANNELS 2
#define SAMPLES 1022 #define SAMPLES 1028
#define TIMES 1000 #define TIMES 1000
#define TIMES2 100 #define TIMES2 100
#define PADDING 16 #define PADDING 16
static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_func) { static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_func, int align, pa_bool_t correct,
int16_t samples[SAMPLES]; pa_bool_t perf) {
int16_t samples_ref[SAMPLES]; PA_DECLARE_ALIGNED(8, int16_t, s[SAMPLES]) = { 0 };
int16_t samples_orig[SAMPLES]; 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];
int i, padding; int16_t *samples, *samples_ref, *samples_orig;
int i, padding, nsamples, size;
pa_random(samples, sizeof(samples)); /* Force sample alignment as requested */
memcpy(samples_ref, samples, sizeof(samples)); samples = s + (8 - align);
memcpy(samples_orig, samples, sizeof(samples)); samples_ref = s_ref + (8 - align);
samples_orig = s_orig + (8 - align);
nsamples = SAMPLES - (8 - align);
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)); volumes[i] = PA_CLAMP_VOLUME((pa_volume_t)(rand() >> 15));
for (padding = 0; padding < PADDING; padding++, i++) for (padding = 0; padding < PADDING; padding++, i++)
volumes[i] = volumes[padding]; volumes[i] = volumes[padding];
orig_func(samples_ref, volumes, CHANNELS, sizeof(samples)); if (correct) {
func(samples, volumes, CHANNELS, sizeof(samples)); pa_log_debug("Testing svolume correctness with %d byte alignment", align);
for (i = 0; i < SAMPLES; i++) {
if (samples[i] != samples_ref[i]) { orig_func(samples_ref, volumes, CHANNELS, size);
printf("%d: %04x != %04x (%04x * %08x)\n", i, samples[i], samples_ref[i], func(samples, volumes, CHANNELS, size);
samples_orig[i], volumes[i % CHANNELS]);
fail(); for (i = 0; i < nsamples; i++) {
if (samples[i] != samples_ref[i]) {
printf("%d: %04x != %04x (%04x * %08x)\n", i, samples[i], samples_ref[i],
samples_orig[i], volumes[i % CHANNELS]);
fail();
}
} }
} }
PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) { if (perf) {
memcpy(samples, samples_orig, sizeof(samples)); pa_log_debug("Testing svolume performance with %d byte alignment", align);
func(samples, volumes, CHANNELS, sizeof(samples));
} PA_CPU_TEST_RUN_STOP
PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) { PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) {
memcpy(samples_ref, samples_orig, sizeof(samples)); memcpy(samples, samples_orig, size);
orig_func(samples_ref, volumes, CHANNELS, sizeof(samples)); func(samples, volumes, CHANNELS, size);
} PA_CPU_TEST_RUN_STOP } PA_CPU_TEST_RUN_STOP
fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0); PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) {
memcpy(samples_ref, samples_orig, size);
orig_func(samples_ref, volumes, CHANNELS, size);
} PA_CPU_TEST_RUN_STOP
fail_unless(memcmp(samples_ref, samples, size) == 0);
}
} }
#if defined (__i386__) || defined (__amd64__) #if defined (__i386__) || defined (__amd64__)
@ -126,7 +145,14 @@ START_TEST (svolume_mmx_test) {
mmx_func = pa_get_volume_func(PA_SAMPLE_S16NE); mmx_func = pa_get_volume_func(PA_SAMPLE_S16NE);
pa_log_debug("Checking MMX svolume"); pa_log_debug("Checking MMX svolume");
run_volume_test(mmx_func, orig_func); 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);
} }
END_TEST END_TEST
@ -146,7 +172,14 @@ START_TEST (svolume_sse_test) {
sse_func = pa_get_volume_func(PA_SAMPLE_S16NE); sse_func = pa_get_volume_func(PA_SAMPLE_S16NE);
pa_log_debug("Checking SSE2 svolume"); pa_log_debug("Checking SSE2 svolume");
run_volume_test(sse_func, orig_func); 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);
} }
END_TEST END_TEST
#endif /* defined (__i386__) || defined (__amd64__) */ #endif /* defined (__i386__) || defined (__amd64__) */
@ -168,7 +201,14 @@ START_TEST (svolume_arm_test) {
arm_func = pa_get_volume_func(PA_SAMPLE_S16NE); arm_func = pa_get_volume_func(PA_SAMPLE_S16NE);
pa_log_debug("Checking ARM svolume"); pa_log_debug("Checking ARM svolume");
run_volume_test(arm_func, orig_func); 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);
} }
END_TEST END_TEST
#endif /* defined (__arm__) && defined (__linux__) */ #endif /* defined (__arm__) && defined (__linux__) */
@ -193,7 +233,14 @@ START_TEST (svolume_orc_test) {
orc_func = pa_get_volume_func(PA_SAMPLE_S16NE); orc_func = pa_get_volume_func(PA_SAMPLE_S16NE);
pa_log_debug("Checking Orc svolume"); pa_log_debug("Checking Orc svolume");
run_volume_test(orc_func, orig_func); 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);
} }
END_TEST END_TEST
@ -402,6 +449,7 @@ int main(int argc, char *argv[]) {
tcase_add_test(tc, svolume_arm_test); tcase_add_test(tc, svolume_arm_test);
#endif #endif
tcase_add_test(tc, svolume_orc_test); tcase_add_test(tc, svolume_orc_test);
tcase_set_timeout(tc, 120);
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
/* Converstion tests */ /* Converstion tests */