src/tests/cpu-test.c | 155 +++++++++++++++++++++++++++------------------------ 1 file changed, 85 insertions(+), 70 deletions(-)
New commits: commit 7914e1286b32ab65896c382ea06d1903c6bc0bfe Author: Arun Raghavan <[email protected]> Date: Tue Oct 23 18:29:27 2012 +0530 tests: Add a basic sanity test to sconv cpu-test This seems redundant with the previous check in that function, but it makes sure that the result of the speed comparison is what we think it is. diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c index af5397a..f0ab56c 100644 --- a/src/tests/cpu-test.c +++ b/src/tests/cpu-test.c @@ -236,6 +236,8 @@ static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) { orig_func(SAMPLES, floats, samples_ref); } PA_CPU_TEST_RUN_STOP + + fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0); } #if defined (__i386__) || defined (__amd64__) commit 472fe05297649523a36f3af1ede8f964132d7fee Author: Arun Raghavan <[email protected]> Date: Tue Oct 23 18:26:39 2012 +0530 tests: Reorganise cpu-test to reuse code This factors out the basic measurement code for each test into a separate block so that each test can be broken down into a basic correctness test, and a performance comparison with minimum effort. diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c index 5a5f546..af5397a 100644 --- a/src/tests/cpu-test.c +++ b/src/tests/cpu-test.c @@ -34,6 +34,31 @@ #include <pulsecore/sconv.h> #include <pulsecore/sample-util.h> +#define PA_CPU_TEST_RUN_START(l, t1, t2) \ +{ \ + int _j, _k; \ + int _times = (t1), _times2 = (t2); \ + pa_usec_t _start, _stop; \ + pa_usec_t _min = INT_MAX, _max = 0; \ + double _s1 = 0, _s2 = 0; \ + const char *_label = (l); \ + \ + for (_k = 0; _k < _times2; _k++) { \ + _start = pa_rtclock_now(); \ + for (_j = 0; _j < _times; _j++) + +#define PA_CPU_TEST_RUN_STOP \ + _stop = pa_rtclock_now(); \ + \ + if (_min > (_stop - _start)) _min = _stop - _start; \ + if (_max < (_stop - _start)) _max = _stop - _start; \ + _s1 += _stop - _start; \ + _s2 += (_stop - _start) * (_stop - _start); \ + } \ + pa_log_debug("%s: %llu usec (min = %llu, max = %llu, stddev = %g).", _label, (long long unsigned int)_s1, \ + (long long unsigned int)_min, (long long unsigned int)_max, sqrt(_times2 * _s2 - _s1 * _s1) / _times2); \ +} + /* Common defines for svolume tests */ #define CHANNELS 2 #define SAMPLES 1022 @@ -46,12 +71,7 @@ static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_f int16_t samples_ref[SAMPLES]; int16_t samples_orig[SAMPLES]; int32_t volumes[CHANNELS + PADDING]; - int i, j, padding; - pa_usec_t start, stop; - int k; - pa_usec_t min = INT_MAX, max = 0; - double s1 = 0, s2 = 0; - + int i, padding; pa_random(samples, sizeof(samples)); memcpy(samples_ref, samples, sizeof(samples)); @@ -72,39 +92,15 @@ static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_f } } - for (k = 0; k < TIMES2; k++) { - start = pa_rtclock_now(); - for (j = 0; j < TIMES; j++) { - memcpy(samples, samples_orig, sizeof(samples)); - func(samples, volumes, CHANNELS, sizeof(samples)); - } - stop = pa_rtclock_now(); - - if (min > (stop - start)) min = stop - start; - if (max < (stop - start)) max = stop - start; - s1 += stop - start; - s2 += (stop - start) * (stop - start); - } - pa_log_debug("func: %llu usec (min = %llu, max = %llu, stddev = %g).", (long long unsigned int)s1, - (long long unsigned int)min, (long long unsigned int)max, sqrt(TIMES2 * s2 - s1 * s1) / TIMES2); - - min = INT_MAX; max = 0; - s1 = s2 = 0; - for (k = 0; k < TIMES2; k++) { - start = pa_rtclock_now(); - for (j = 0; j < TIMES; j++) { - memcpy(samples_ref, samples_orig, sizeof(samples)); - orig_func(samples_ref, volumes, CHANNELS, sizeof(samples)); - } - stop = pa_rtclock_now(); + PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) { + memcpy(samples, samples_orig, sizeof(samples)); + func(samples, volumes, CHANNELS, sizeof(samples)); + } PA_CPU_TEST_RUN_STOP - if (min > (stop - start)) min = stop - start; - if (max < (stop - start)) max = stop - start; - s1 += stop - start; - s2 += (stop - start) * (stop - start); - } - pa_log_debug("orig: %llu usec (min = %llu, max = %llu, stddev = %g).", (long long unsigned int)s1, - (long long unsigned int)min, (long long unsigned int)max, sqrt(TIMES2 * s2 - s1 * s1) / TIMES2); + PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) { + memcpy(samples_ref, samples_orig, sizeof(samples)); + orig_func(samples_ref, volumes, CHANNELS, sizeof(samples)); + } PA_CPU_TEST_RUN_STOP fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0); } @@ -206,14 +202,14 @@ END_TEST /* Start conversion tests */ #define SAMPLES 1022 -#define TIMES 10000 +#define TIMES 1000 +#define TIMES2 100 static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t orig_func) { int16_t samples[SAMPLES]; int16_t samples_ref[SAMPLES]; float floats[SAMPLES]; int i; - pa_usec_t start, stop; memset(samples_ref, 0, sizeof(samples_ref)); memset(samples, 0, sizeof(samples)); @@ -233,19 +229,13 @@ static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t } } - start = pa_rtclock_now(); - for (i = 0; i < TIMES; i++) { + PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) { func(SAMPLES, floats, samples); - } - stop = pa_rtclock_now(); - pa_log_debug("func: %llu usec.", (long long unsigned int)(stop - start)); + } PA_CPU_TEST_RUN_STOP - start = pa_rtclock_now(); - for (i = 0; i < TIMES; i++) { + PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) { orig_func(SAMPLES, floats, samples_ref); - } - stop = pa_rtclock_now(); - pa_log_debug("ref: %llu usec.", (long long unsigned int)(stop - start)); + } PA_CPU_TEST_RUN_STOP } #if defined (__i386__) || defined (__amd64__) commit 3f44eb0559619e275b5f4be1ef2f5198a360ea30 Author: Arun Raghavan <[email protected]> Date: Tue Oct 23 15:28:47 2012 +0530 tests: Factor out core sconv test code in cpu-test This will let us add tests for non-SSE sconv tests. diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c index f6d3c98..5a5f546 100644 --- a/src/tests/cpu-test.c +++ b/src/tests/cpu-test.c @@ -205,27 +205,15 @@ END_TEST /* End svolume tests */ /* Start conversion tests */ -#if defined (__i386__) || defined (__amd64__) -START_TEST (sconv_sse_test) { -#define SAMPLES 1019 -#define TIMES 1000 +#define SAMPLES 1022 +#define TIMES 10000 +static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t orig_func) { int16_t samples[SAMPLES]; int16_t samples_ref[SAMPLES]; float floats[SAMPLES]; int i; pa_usec_t start, stop; - pa_convert_func_t orig_func, sse_func; - pa_cpu_x86_flag_t flags = 0; - - pa_cpu_get_x86_flags(&flags); - - if (!(flags & PA_CPU_X86_SSE2)) { - pa_log_info("SSE2 not supported. Skipping"); - return; - } - - pa_log_debug("Checking SSE sconv (%zd)\n", sizeof(samples)); memset(samples_ref, 0, sizeof(samples_ref)); memset(samples, 0, sizeof(samples)); @@ -234,12 +222,8 @@ START_TEST (sconv_sse_test) { floats[i] = 2.1f * (rand()/(float) RAND_MAX - 0.5f); } - orig_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE); - pa_convert_func_init_sse(flags); - sse_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE); - orig_func(SAMPLES, floats, samples_ref); - sse_func(SAMPLES, floats, samples); + func(SAMPLES, floats, samples); for (i = 0; i < SAMPLES; i++) { if (samples[i] != samples_ref[i]) { @@ -251,10 +235,10 @@ START_TEST (sconv_sse_test) { start = pa_rtclock_now(); for (i = 0; i < TIMES; i++) { - sse_func(SAMPLES, floats, samples); + func(SAMPLES, floats, samples); } stop = pa_rtclock_now(); - pa_log_debug("SSE: %llu usec.", (long long unsigned int)(stop - start)); + pa_log_debug("func: %llu usec.", (long long unsigned int)(stop - start)); start = pa_rtclock_now(); for (i = 0; i < TIMES; i++) { @@ -262,12 +246,32 @@ START_TEST (sconv_sse_test) { } stop = pa_rtclock_now(); pa_log_debug("ref: %llu usec.", (long long unsigned int)(stop - start)); +} -#undef SAMPLES -#undef TIMES +#if defined (__i386__) || defined (__amd64__) +START_TEST (sconv_sse_test) { + pa_cpu_x86_flag_t flags = 0; + pa_convert_func_t orig_func, sse_func; + + pa_cpu_get_x86_flags(&flags); + + if (!(flags & PA_CPU_X86_SSE2)) { + pa_log_info("SSE2 not supported. Skipping"); + return; + } + + orig_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE); + pa_convert_func_init_sse(flags); + sse_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE); + + pa_log_debug("Checking SSE sconv (s16 -> float)"); + run_conv_test_float_to_s16(sse_func, orig_func); } END_TEST #endif /* defined (__i386__) || defined (__amd64__) */ + +#undef SAMPLES +#undef TIMES /* End conversion tests */ int main(int argc, char *argv[]) { commit 0d2bef6c781da3590f54677e17b9f7391094fa04 Author: Arun Raghavan <[email protected]> Date: Tue Oct 23 15:28:26 2012 +0530 tests: Add a copyright header to cpu-test diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c index e8ece7f..f6d3c98 100644 --- a/src/tests/cpu-test.c +++ b/src/tests/cpu-test.c @@ -1,3 +1,22 @@ +/*** + This file is part of PulseAudio. + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + #ifdef HAVE_CONFIG_H #include <config.h> #endif _______________________________________________ pulseaudio-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits
