tests: Run sconv tests with multiple alignments

This allows us to test the sconv code with the incoming samples at
various byte alignments. The test is also now split into correctness and
performance checks.
This commit is contained in:
Arun Raghavan 2012-10-24 12:48:02 +05:30
parent 63ddc0e426
commit fe0ba245e5

View file

@ -201,43 +201,56 @@ END_TEST
/* End svolume tests */ /* End svolume tests */
/* Start conversion tests */ /* Start conversion tests */
#define SAMPLES 1022 #define SAMPLES 1028
#define TIMES 1000 #define TIMES 1000
#define TIMES2 100 #define TIMES2 100
static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t orig_func) { static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_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 };
float floats[SAMPLES]; PA_DECLARE_ALIGNED(8, int16_t, s_ref[SAMPLES]) = { 0 };
int i; PA_DECLARE_ALIGNED(8, float, f[SAMPLES]);
int16_t *samples, *samples_ref;
float *floats;
int i, nsamples;
memset(samples_ref, 0, sizeof(samples_ref)); /* Force sample alignment as requested */
memset(samples, 0, sizeof(samples)); samples = s + (8 - align);
samples_ref = s_ref + (8 - align);
floats = f + (8 - align);
nsamples = SAMPLES - (8 - align);
for (i = 0; i < SAMPLES; i++) { for (i = 0; i < nsamples; i++) {
floats[i] = 2.1f * (rand()/(float) RAND_MAX - 0.5f); floats[i] = 2.1f * (rand()/(float) RAND_MAX - 0.5f);
} }
orig_func(SAMPLES, floats, samples_ref); if (correct) {
func(SAMPLES, floats, samples); pa_log_debug("Testing sconv correctness with %d byte alignment", align);
for (i = 0; i < SAMPLES; i++) { orig_func(nsamples, floats, samples_ref);
if (samples[i] != samples_ref[i]) { func(nsamples, floats, samples);
printf ("%d: %04x != %04x (%f)\n", i, samples[i], samples_ref[i],
floats[i]); for (i = 0; i < nsamples; i++) {
fail(); if (samples[i] != samples_ref[i]) {
pa_log_debug("%d: %04x != %04x (%f)\n", i, samples[i], samples_ref[i], floats[i]);
fail();
}
} }
} }
PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) { if (perf) {
func(SAMPLES, floats, samples); pa_log_debug("Testing sconv performance with %d byte alignment", align);
} PA_CPU_TEST_RUN_STOP
PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) { PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) {
orig_func(SAMPLES, floats, samples_ref); func(nsamples, floats, samples);
} 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) {
orig_func(nsamples, floats, samples_ref);
} PA_CPU_TEST_RUN_STOP
fail_unless(memcmp(samples_ref, samples, sizeof(nsamples)) == 0);
}
} }
#if defined (__i386__) || defined (__amd64__) #if defined (__i386__) || defined (__amd64__)
@ -257,7 +270,14 @@ START_TEST (sconv_sse_test) {
sse_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE); sse_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
pa_log_debug("Checking SSE sconv (s16 -> float)"); pa_log_debug("Checking SSE sconv (s16 -> float)");
run_conv_test_float_to_s16(sse_func, orig_func); run_conv_test_float_to_s16(sse_func, orig_func, 0, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 1, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 2, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 3, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 4, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 5, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 6, TRUE, FALSE);
run_conv_test_float_to_s16(sse_func, orig_func, 7, TRUE, TRUE);
} }
END_TEST END_TEST
#endif /* defined (__i386__) || defined (__amd64__) */ #endif /* defined (__i386__) || defined (__amd64__) */