[pulseaudio-commits] 11 commits - configure.ac src/Makefile.am src/pulsecore src/tests

Arun Raghavan arun at kemper.freedesktop.org
Fri Aug 3 23:33:59 PDT 2012


 configure.ac                |    6 
 src/Makefile.am             |   57 ++++++--
 src/pulsecore/cpu-orc.c     |    8 -
 src/pulsecore/cpu-orc.h     |    2 
 src/pulsecore/cpu-x86.c     |    8 +
 src/pulsecore/cpu-x86.h     |    1 
 src/pulsecore/sconv_sse.c   |   54 --------
 src/pulsecore/svolume_mmx.c |   90 -------------
 src/pulsecore/svolume_orc.c |   85 ------------
 src/pulsecore/svolume_sse.c |   85 ------------
 src/tests/cpu-test.c        |  249 +++++++++++++++++++++++++++++++++++++
 src/tests/mainloop-test.c   |   37 ++++-
 src/tests/mix-test.c        |  289 ++++++++++++++++++++++++++++++++++++++------
 src/tests/strlist-test.c    |   32 ++++
 src/tests/test-daemon.sh    |   70 ++++++++++
 src/tests/utf8-test.c       |   74 +++++++++--
 16 files changed, 754 insertions(+), 393 deletions(-)

New commits:
commit 0b7e128a52c3d8d80be31e7fbee072b694293b3c
Author: Sjoerd Simons <sjoerd at luon.net>
Date:   Fri Jul 20 19:18:26 2012 +0000

    build-sys: webrtc-utils needs to be installed before module-echo-cancel
    
    Like other plugin helper libraries these need to be installed
    before the plugins that use them..

diff --git a/src/Makefile.am b/src/Makefile.am
index aba850c..7f947bd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -917,6 +917,10 @@ modlibexec_LTLIBRARIES = \
 		libprotocol-http.la \
 		libprotocol-native.la
 
+if HAVE_WEBRTC
+modlibexec_LTLIBRARIES += libwebrtc-util.la
+endif
+
 if HAVE_ESOUND
 modlibexec_LTLIBRARIES += \
 		libprotocol-esound.la
@@ -1848,7 +1852,6 @@ if HAVE_WEBRTC
 # The webrtc code is split off into a helper library to avoid having automake
 # link module-echo-cancel with C++ (which it does if there are any C++ deps,
 # even conditional ones).
-modlibexec_LTLIBRARIES += libwebrtc-util.la
 
 libwebrtc_util_la_SOURCES = modules/echo-cancel/webrtc.cc
 libwebrtc_util_la_CXXFLAGS = $(AM_CXXFLAGS) $(SERVER_CFLAGS) $(WEBRTC_CFLAGS) -DHAVE_WEBRTC=1

commit 84ffc41bfb9c9f3c7eaa7ff6e106ee2fccb5ea81
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Mon Jul 23 13:12:46 2012 +0800

    tests: enable to test standalone pulseaudio daemon
    
    With this fix, `check-daemon` doesn't need a system-wide running pulseaudio
    anymore.
    
    The method to use is to invoke `make check-daemon` under `src/` and it just
    works! :)

diff --git a/src/Makefile.am b/src/Makefile.am
index 0957fb9..aba850c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -303,11 +303,11 @@ TESTS = $(TESTS_default)
 if BUILD_TESTS_DEFAULT
 noinst_PROGRAMS = $(TESTS_default) $(TESTS_norun) $(TESTS_daemon)
 else
-check_PROGRAMS = $(TESTS_default) $(TESTS_norun) $(TESTS_daemon)
+check_PROGRAMS = $(TESTS_default) $(TESTS_norun)
 endif
 
-check-daemon:
-	$(MAKE) check TESTS="$(TESTS_daemon)"
+check-daemon: $(TESTS_daemon)
+	PATH=$(builddir):${PATH} $(top_srcdir)/src/tests/test-daemon.sh $(TESTS_daemon)
 
 mainloop_test_SOURCES = tests/mainloop-test.c
 mainloop_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
diff --git a/src/tests/test-daemon.sh b/src/tests/test-daemon.sh
new file mode 100755
index 0000000..3347b42
--- /dev/null
+++ b/src/tests/test-daemon.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# This script is modified from dbus's run-with-temp-session-bus.sh.
+#
+
+SCRIPTNAME=$0
+
+die()
+{
+    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+        kill -9 $DBUS_SESSION_BUS_PID
+    fi
+    echo $SCRIPTNAME: $* >&2
+    exit 1
+}
+
+## convenient to be able to ctrl+C without leaking the message bus process
+trap 'die "Received SIGINT"' INT
+
+unset DBUS_SESSION_BUS_ADDRESS
+unset DBUS_SESSION_BUS_PID
+
+echo "Running dbus-launch --sh-syntax" >&2
+
+eval `dbus-launch --sh-syntax`
+
+if test -z "$DBUS_SESSION_BUS_PID" ; then
+    die "Failed to launch message bus for test script to run"
+fi
+
+echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
+
+TEMP_PULSE_DIR=`mktemp -d`
+export PULSE_RUNTIME_PATH=${TEMP_PULSE_DIR}
+
+# this script would be called inside src/ directory, so we need to use the correct path.
+# notice that for tests, we don't load ALSA related modules.
+pulseaudio -n \
+        --log-target=file:${PWD}/pulse-daemon.log \
+        --log-level=debug \
+        --load="module-null-sink" \
+        --load="module-null-source" \
+        --load="module-suspend-on-idle" \
+        --load="module-native-protocol-unix" \
+        --load="module-cli-protocol-unix" \
+        &
+
+# wait a few seconds to let the daemon start!
+sleep 5
+
+unset DISPLAY
+
+for ONE_TEST in $@; do
+    ${ONE_TEST}
+done
+
+# terminate the designated pulseaudio daemon
+pacmd exit
+
+wait
+
+kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
+
+sleep 2
+
+## be sure it really died
+kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
+
+exit 0

commit 89a6fd740fd28c538016cff74655121996c8bc85
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Fri Jul 20 14:32:35 2012 +0800

    build: add a target to ease the creation of coverage files

diff --git a/src/Makefile.am b/src/Makefile.am
index 46309a1..0957fb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2066,4 +2066,22 @@ $(installmodlibexecLTLIBRARIES): install-pkglibLTLIBRARIES
 installpadsplibLTLIBRARIES = install-padsplibLTLIBRARIES
 $(installpadsplibLTLIBRARIES): install-libLTLIBRARIES
 
-.PHONY: massif update-all update-ffmpeg update-sbc update-map-file
+if HAVE_GCOV
+coverage:
+	@echo ""
+	@echo "Don't forget to run 'make check' before generating coverage stats."
+	@echo ""
+	lcov --capture --directory . --output-file $(builddir)/gcov-all.info
+	-rm -r $(builddir)/coverage
+	genhtml --output-directory $(builddir)/coverage gcov-all.info
+	@echo ""
+	@echo "Coverage data now available at: $(abs_builddir)/coverage/index.html"
+else
+coverage:
+	@echo ""
+	@echo "To generate coverage stats, rerun configure with '--enable-gcov',"
+	@echo "and don't forget to disable it again for regular builds."
+	@echo ""
+endif
+
+.PHONY: massif update-all update-ffmpeg update-sbc update-map-file coverage

commit d53f16b6a22c82d81d683aae49f995af3d84ddb9
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Tue Jul 24 14:46:34 2012 +0530

    tests: Make cpu-test less verbose

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index a812db2..ac4312e 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -66,8 +66,8 @@ static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_f
         s1 += stop - start;
         s2 += (stop - start) * (stop - start);
     }
-    pa_log_info("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);
+    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;
@@ -84,8 +84,8 @@ static void run_volume_test(pa_do_volume_func_t func, pa_do_volume_func_t orig_f
         s1 += stop - start;
         s2 += (stop - start) * (stop - start);
     }
-    pa_log_info("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_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);
 
     fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0);
 }
@@ -149,8 +149,10 @@ START_TEST (svolume_orc_test) {
 
     orc_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
-    pa_log_debug("Checking SSE2 svolume");
-    run_volume_test(orc_func, orig_func, CHANNELS, SAMPLES, TIMES, TIMES2, PADDING);
+    pa_log_debug("Checking Orc svolume");
+    run_volume_test(orc_func, orig_func);
+}
+END_TEST
 
 #undef CHANNELS
 #undef SAMPLES
@@ -207,14 +209,14 @@ START_TEST (sconv_sse_test) {
         sse_func(SAMPLES, floats, samples);
     }
     stop = pa_rtclock_now();
-    pa_log_info("SSE: %llu usec.", (long long unsigned int)(stop - start));
+    pa_log_debug("SSE: %llu usec.", (long long unsigned int)(stop - start));
 
     start = pa_rtclock_now();
     for (i = 0; i < TIMES; i++) {
         orig_func(SAMPLES, floats, samples_ref);
     }
     stop = pa_rtclock_now();
-    pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
+    pa_log_debug("ref: %llu usec.", (long long unsigned int)(stop - start));
 
 #undef SAMPLES
 #undef TIMES

commit b6f2ccf194c40c840f9e2d248839749b1ebbecbf
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Tue Jul 24 14:37:54 2012 +0530

    tests: Factor out Orc test code into cpu-test
    
    Reorganises all the svolume core test code in cpu-test since it's the
    same across MMX/SSE/etc.

diff --git a/src/pulsecore/cpu-orc.c b/src/pulsecore/cpu-orc.c
index 21d49ed..d40c224 100644
--- a/src/pulsecore/cpu-orc.c
+++ b/src/pulsecore/cpu-orc.c
@@ -25,14 +25,18 @@
 
 #include "cpu-orc.h"
 
-void pa_cpu_init_orc(pa_cpu_info cpu_info)
+pa_bool_t pa_cpu_init_orc(pa_cpu_info cpu_info)
 {
 #ifndef DISABLE_ORC
     /* Update these as we test on more architectures */
     pa_cpu_x86_flag_t x86_want_flags = PA_CPU_X86_MMX | PA_CPU_X86_SSE | PA_CPU_X86_SSE2 | PA_CPU_X86_SSE3 | PA_CPU_X86_SSSE3 | PA_CPU_X86_SSE4_1 | PA_CPU_X86_SSE4_2;
 
     /* Enable Orc svolume optimizations */
-    if ((cpu_info.cpu_type == PA_CPU_X86) && (cpu_info.flags.x86 & x86_want_flags))
+    if ((cpu_info.cpu_type == PA_CPU_X86) && (cpu_info.flags.x86 & x86_want_flags)) {
         pa_volume_func_init_orc();
+        return TRUE;
+    }
 #endif
+
+    return FALSE;
 }
diff --git a/src/pulsecore/cpu-orc.h b/src/pulsecore/cpu-orc.h
index d236f7a..0bf81cb 100644
--- a/src/pulsecore/cpu-orc.h
+++ b/src/pulsecore/cpu-orc.h
@@ -26,7 +26,7 @@
 
 /* Orc-optimised bits */
 
-void pa_cpu_init_orc(pa_cpu_info cpu_info);
+pa_bool_t pa_cpu_init_orc(pa_cpu_info cpu_info);
 
 void pa_volume_func_init_orc(void);
 
diff --git a/src/pulsecore/svolume_orc.c b/src/pulsecore/svolume_orc.c
index d5bd5f2..37e6bf8 100644
--- a/src/pulsecore/svolume_orc.c
+++ b/src/pulsecore/svolume_orc.c
@@ -45,94 +45,9 @@ pa_volume_s16ne_orc(int16_t *samples, const int32_t *volumes, unsigned channels,
         fallback(samples, volumes, channels, length);
 }
 
-#undef RUN_TEST
-
-#ifdef RUN_TEST
-#define CHANNELS 2
-#define SAMPLES 1022
-#define TIMES 1000
-#define TIMES2 100
-#define PADDING 16
-
-static void run_test(void) {
-    int16_t samples[SAMPLES];
-    int16_t samples_ref[SAMPLES];
-    int16_t samples_orig[SAMPLES];
-    int32_t volumes[CHANNELS + PADDING];
-    int i, j, padding;
-    pa_do_volume_func_t func;
-    pa_usec_t start, stop;
-    int k;
-    pa_usec_t min = INT_MAX, max = 0;
-    double s1 = 0, s2 = 0;
-
-    func = pa_get_volume_func(PA_SAMPLE_S16NE);
-
-    printf("checking ORC %zd\n", sizeof(samples));
-
-    pa_random(samples, sizeof(samples));
-    memcpy(samples_ref, samples, sizeof(samples));
-    memcpy(samples_orig, samples, sizeof(samples));
-
-    for (i = 0; i < CHANNELS; i++)
-        volumes[i] = PA_CLAMP_VOLUME(rand() >> 15);
-    for (padding = 0; padding < PADDING; padding++, i++)
-        volumes[i] = volumes[padding];
-
-    func(samples_ref, volumes, CHANNELS, sizeof(samples));
-    pa_volume_s16ne_orc(samples, volumes, CHANNELS, sizeof(samples));
-    for (i = 0; i < SAMPLES; i++) {
-        if (samples[i] != samples_ref[i]) {
-            printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i],
-                      samples_orig[i], volumes[i % CHANNELS]);
-        }
-    }
-
-    for (k = 0; k < TIMES2; k++) {
-        start = pa_rtclock_now();
-        for (j = 0; j < TIMES; j++) {
-            memcpy(samples, samples_orig, sizeof(samples));
-            pa_volume_s16ne_orc(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_info("ORC: %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));
-            func(samples_ref, 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_info("ref: %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_assert_se(memcmp(samples_ref, samples, sizeof(samples)) == 0);
-}
-#endif
-
 void pa_volume_func_init_orc(void) {
     pa_log_info("Initialising ORC optimized volume functions.");
 
-#ifdef RUN_TEST
-    run_test();
-#endif
-
     fallback = pa_get_volume_func(PA_SAMPLE_S16NE);
     pa_set_volume_func(PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_orc);
 }
diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index de25bc6..a812db2 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -8,44 +8,31 @@
 
 #include <pulse/rtclock.h>
 #include <pulsecore/cpu-x86.h>
+#include <pulsecore/cpu-orc.h>
 #include <pulsecore/random.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/endianmacros.h>
 #include <pulsecore/sconv.h>
 #include <pulsecore/sample-util.h>
 
-START_TEST (svolume_mmx_test) {
+/* Common defines for svolume tests */
 #define CHANNELS 2
 #define SAMPLES 1022
 #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) {
     int16_t samples[SAMPLES];
     int16_t samples_ref[SAMPLES];
     int16_t samples_orig[SAMPLES];
     int32_t volumes[CHANNELS + PADDING];
     int i, j, padding;
-    pa_do_volume_func_t orig_func, mmx_func;
     pa_usec_t start, stop;
     int k;
     pa_usec_t min = INT_MAX, max = 0;
     double s1 = 0, s2 = 0;
 
-    pa_cpu_x86_flag_t flags = 0;
-
-    pa_cpu_get_x86_flags(&flags);
-
-    if (!((flags & PA_CPU_X86_MMX) && (flags & PA_CPU_X86_CMOV))) {
-        pa_log_info("MMX/CMOV not supported. Skipping");
-        return;
-    }
-
-    orig_func = pa_get_volume_func(PA_SAMPLE_S16NE);
-    pa_volume_func_init_mmx(flags);
-    mmx_func = pa_get_volume_func(PA_SAMPLE_S16NE);
-
-    pa_log_debug("Checking MMX svolume (%zd)\n", sizeof(samples));
 
     pa_random(samples, sizeof(samples));
     memcpy(samples_ref, samples, sizeof(samples));
@@ -57,7 +44,7 @@ START_TEST (svolume_mmx_test) {
         volumes[i] = volumes[padding];
 
     orig_func(samples_ref, volumes, CHANNELS, sizeof(samples));
-    mmx_func(samples, volumes, CHANNELS, sizeof(samples));
+    func(samples, volumes, CHANNELS, sizeof(samples));
     for (i = 0; i < SAMPLES; i++) {
         if (samples[i] != samples_ref[i]) {
             printf("%d: %04x != %04x (%04x * %08x)\n", i, samples[i], samples_ref[i],
@@ -70,7 +57,7 @@ START_TEST (svolume_mmx_test) {
         start = pa_rtclock_now();
         for (j = 0; j < TIMES; j++) {
             memcpy(samples, samples_orig, sizeof(samples));
-            mmx_func(samples, volumes, CHANNELS, sizeof(samples));
+            func(samples, volumes, CHANNELS, sizeof(samples));
         }
         stop = pa_rtclock_now();
 
@@ -79,8 +66,8 @@ START_TEST (svolume_mmx_test) {
         s1 += stop - start;
         s2 += (stop - start) * (stop - start);
     }
-    pa_log_info("MMX: %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_log_info("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;
@@ -97,36 +84,34 @@ START_TEST (svolume_mmx_test) {
         s1 += stop - start;
         s2 += (stop - start) * (stop - start);
     }
-    pa_log_info("ref: %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_log_info("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);
 
     fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0);
+}
 
-#undef CHANNELS
-#undef SAMPLES
-#undef TIMES
-#undef TIMES2
-#undef PADDING
+START_TEST (svolume_mmx_test) {
+    pa_do_volume_func_t orig_func, mmx_func;
+    pa_cpu_x86_flag_t flags = 0;
+
+    pa_cpu_get_x86_flags(&flags);
+
+    if (!((flags & PA_CPU_X86_MMX) && (flags & PA_CPU_X86_CMOV))) {
+        pa_log_info("MMX/CMOV not supported. Skipping");
+        return;
+    }
+
+    orig_func = pa_get_volume_func(PA_SAMPLE_S16NE);
+    pa_volume_func_init_mmx(flags);
+    mmx_func = pa_get_volume_func(PA_SAMPLE_S16NE);
+
+    pa_log_debug("Checking MMX svolume");
+    run_volume_test(mmx_func, orig_func);
 }
 END_TEST
 
 START_TEST (svolume_sse_test) {
-#define CHANNELS 2
-#define SAMPLES 1022
-#define TIMES 1000
-#define TIMES2 100
-#define PADDING 16
-
-    int16_t samples[SAMPLES];
-    int16_t samples_ref[SAMPLES];
-    int16_t samples_orig[SAMPLES];
-    int32_t volumes[CHANNELS + PADDING];
-    int i, j, padding;
     pa_do_volume_func_t orig_func, sse_func;
-    pa_usec_t start, stop;
-    int k;
-    pa_usec_t min = INT_MAX, max = 0;
-    double s1 = 0, s2 = 0;
     pa_cpu_x86_flag_t flags = 0;
 
     pa_cpu_get_x86_flags(&flags);
@@ -140,70 +125,39 @@ START_TEST (svolume_sse_test) {
     pa_volume_func_init_sse(flags);
     sse_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
-    pa_log_debug("Checking SSE2 svolume (%zd)\n", sizeof(samples));
-
-    pa_random(samples, sizeof(samples));
-    memcpy(samples_ref, samples, sizeof(samples));
-    memcpy(samples_orig, samples, sizeof(samples));
+    pa_log_debug("Checking SSE2 svolume");
+    run_volume_test(sse_func, orig_func);
+}
+END_TEST
 
-    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];
+START_TEST (svolume_orc_test) {
+    pa_do_volume_func_t orig_func, orc_func;
+    pa_cpu_info cpu_info;
 
-    orig_func(samples_ref, volumes, CHANNELS, sizeof(samples));
-    sse_func(samples, volumes, CHANNELS, sizeof(samples));
-    for (i = 0; i < SAMPLES; i++) {
-        if (samples[i] != samples_ref[i]) {
-            printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i],
-                      samples_orig[i], volumes[i % CHANNELS]);
-            fail();
-        }
-    }
+#if defined (__i386__) || defined (__amd64__)
+    pa_zero(cpu_info);
+    cpu_info.cpu_type = PA_CPU_X86;
+    pa_cpu_get_x86_flags(&cpu_info.flags.x86);
+#endif
 
-    for (k = 0; k < TIMES2; k++) {
-        start = pa_rtclock_now();
-        for (j = 0; j < TIMES; j++) {
-            memcpy(samples, samples_orig, sizeof(samples));
-            sse_func(samples, volumes, CHANNELS, sizeof(samples));
-        }
-        stop = pa_rtclock_now();
+    orig_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
-        if (min > (stop - start)) min = stop - start;
-        if (max < (stop - start)) max = stop - start;
-        s1 += stop - start;
-        s2 += (stop - start) * (stop - start);
+    if (!pa_cpu_init_orc(cpu_info)) {
+        pa_log_info("Orc not supported. Skipping");
+        return;
     }
-    pa_log_info("SSE: %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();
 
-        if (min > (stop - start)) min = stop - start;
-        if (max < (stop - start)) max = stop - start;
-        s1 += stop - start;
-        s2 += (stop - start) * (stop - start);
-    }
-    pa_log_info("ref: %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);
+    orc_func = pa_get_volume_func(PA_SAMPLE_S16NE);
 
-    fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0);
+    pa_log_debug("Checking SSE2 svolume");
+    run_volume_test(orc_func, orig_func, CHANNELS, SAMPLES, TIMES, TIMES2, PADDING);
 
 #undef CHANNELS
 #undef SAMPLES
 #undef TIMES
 #undef TIMES2
 #undef PADDING
-}
-END_TEST
+/* End svolume tests */
 
 START_TEST (sconv_sse_test) {
 #define SAMPLES 1019
@@ -280,6 +234,7 @@ int main(int argc, char *argv[]) {
     tc = tcase_create("x86");
     tcase_add_test(tc, svolume_mmx_test);
     tcase_add_test(tc, svolume_sse_test);
+    tcase_add_test(tc, svolume_orc_test);
     tcase_add_test(tc, sconv_sse_test);
     suite_add_tcase(s, tc);
 

commit c2f7987f09fac8041e881bedd5a788152a0916c8
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Tue Jul 17 14:45:55 2012 +0800

    tests: modify strlist-test to use new 'check' framework

diff --git a/src/Makefile.am b/src/Makefile.am
index 0132274..46309a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -405,9 +405,9 @@ extended_test_CFLAGS = $(AM_CFLAGS)
 extended_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 strlist_test_SOURCES = tests/strlist-test.c
-strlist_test_CFLAGS = $(AM_CFLAGS)
+strlist_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
 strlist_test_LDADD = $(AM_LDADD) $(WINSOCK_LIBS) libpulsecore- at PA_MAJORMINOR@.la libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
-strlist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+strlist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 close_test_SOURCES = tests/close-test.c
 close_test_CFLAGS = $(AM_CFLAGS)
diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c
index 86f4f07..6a4f4bb 100644
--- a/src/tests/strlist-test.c
+++ b/src/tests/strlist-test.c
@@ -1,10 +1,16 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
+#include <check.h>
 
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/strlist.h>
+#include <pulsecore/core-util.h>
 
-int main(int argc, char* argv[]) {
+START_TEST (strlist_test) {
     char *t, *u;
     pa_strlist *l = NULL;
 
@@ -18,25 +24,47 @@ int main(int argc, char* argv[]) {
     pa_strlist_free(l);
 
     fprintf(stderr, "1: %s\n", t);
+    fail_unless(pa_streq(t, "a b c d e"));
 
     l = pa_strlist_parse(t);
     pa_xfree(t);
 
     t = pa_strlist_tostring(l);
     fprintf(stderr, "2: %s\n", t);
+    fail_unless(pa_streq(t, "a b c d e"));
     pa_xfree(t);
 
     l = pa_strlist_pop(l, &u);
     fprintf(stderr, "3: %s\n", u);
+    fail_unless(pa_streq(u, "a"));
     pa_xfree(u);
 
     l = pa_strlist_remove(l, "c");
 
     t = pa_strlist_tostring(l);
     fprintf(stderr, "4: %s\n", t);
+    fail_unless(pa_streq(t, "b d e"));
     pa_xfree(t);
 
     pa_strlist_free(l);
+}
+END_TEST
+
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    s = suite_create("StrList");
+    tc = tcase_create("strlist");
+    tcase_add_test(tc, strlist_test);
+    suite_add_tcase(s, tc);
+
+    sr = srunner_create(s);
+    srunner_run_all(sr, CK_NORMAL);
+    failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
 
-    return 0;
+    return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }

commit 27f6065a3c52775678b47b20a6b7c08bb7c0e8e5
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Tue Jul 17 14:45:54 2012 +0800

    tests: modify utf8-test to use new 'check' test framework

diff --git a/src/Makefile.am b/src/Makefile.am
index 970db4e..0132274 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -320,9 +320,9 @@ thread_mainloop_test_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpuls
 thread_mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 utf8_test_SOURCES = tests/utf8-test.c
-utf8_test_CFLAGS = $(AM_CFLAGS)
+utf8_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
 utf8_test_LDADD = $(AM_LDADD) libpulse.la
-utf8_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+utf8_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 format_test_SOURCES = tests/format-test.c
 format_test_CFLAGS = $(AM_CFLAGS)
diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c
index 6dc5b50..22a58c0 100644
--- a/src/tests/utf8-test.c
+++ b/src/tests/utf8-test.c
@@ -1,24 +1,72 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <assert.h>
+#include <check.h>
 
 #include <pulse/utf8.h>
 #include <pulse/xmalloc.h>
+#include <pulsecore/core-util.h>
 
-int main(int argc, char *argv[]) {
+START_TEST (utf8_valid) {
+    fail_unless(pa_utf8_valid("hallo") != NULL);
+    fail_unless(pa_utf8_valid("hallo\n") != NULL);
+    fail_unless(pa_utf8_valid("hüpfburg\n") == NULL);
+    fail_unless(pa_utf8_valid("hallo\n") != NULL);
+    fail_unless(pa_utf8_valid("hüpfburg\n") != NULL);
+}
+END_TEST
+
+START_TEST (utf8_filter) {
     char *c;
 
-    assert(pa_utf8_valid("hallo"));
-    assert(pa_utf8_valid("hallo\n"));
-    assert(!pa_utf8_valid("hüpfburg\n"));
-    assert(pa_utf8_valid("hallo\n"));
-    assert(pa_utf8_valid("hüpfburg\n"));
+    {
+        char res1[] = { 0x68, 0x5f, 0x70, 0x66, 0x62, 0x75, 0x72, 0x67, '\0' };
+        c = pa_utf8_filter("hüpfburg");
+        pa_log_debug("%s %s\n", res1, c);
+        fail_unless(pa_streq(c, res1));
+        pa_xfree(c);
+    }
+
+    {
+        char res2[] = { 0x68, 0xc3, 0xbc, 0x70, 0x66, 0x62, 0x75, 0x72, 0x67, '\0' };
+        c = pa_utf8_filter("hüpfburg");
+        fail_unless(pa_streq(c, res2));
+        pa_log_debug("%s %s\n", res2, c);
+        pa_xfree(c);
+    }
+
+    {
+        char res3[] = { 0x5f, 0x78, 0x6b, 0x6e, 0x5f, 0x72, 0x7a, 0x6d, 0x5f, 0x72, 0x7a, 0x65, 0x6c, 0x74, 0x5f, 0x72, 0x73, 0x7a, 0xdf, 0xb3, 0x5f, 0x64, 0x73, 0x6a, 0x6b, 0x66, 0x68, '\0' };
+        c = pa_utf8_filter("üxknärzmörzeltörszß³§dsjkfh");
+        pa_log_debug("%s %s\n", res3, c);
+        fail_unless(pa_streq(c, res3));
+        pa_xfree(c);
+    }
+}
+END_TEST
+
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    if (!getenv("MAKE_CHECK"))
+        pa_log_set_level(PA_LOG_DEBUG);
+
+    s = suite_create("UTF8");
+    tc = tcase_create("utf8");
+    tcase_add_test(tc, utf8_valid);
+    tcase_add_test(tc, utf8_filter);
+    suite_add_tcase(s, tc);
 
-    fprintf(stderr, "LATIN1: %s\n", c = pa_utf8_filter("hüpfburg"));
-    pa_xfree(c);
-    fprintf(stderr, "UTF8: %sx\n", c = pa_utf8_filter("hüpfburg"));
-    pa_xfree(c);
-    fprintf(stderr, "LATIN1: %sx\n", c = pa_utf8_filter("üxknärzmörzeltörszß³§dsjkfh"));
-    pa_xfree(c);
+    sr = srunner_create(s);
+    srunner_run_all(sr, CK_NORMAL);
+    failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
 
-    return 0;
+    return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }

commit 11d2bf787fdb77c981e1337fa4d8c2221926a5e6
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Tue Jul 17 14:45:53 2012 +0800

    tests: modify mainloop-test to use new 'check' framework

diff --git a/src/Makefile.am b/src/Makefile.am
index 06bc5db..970db4e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -310,9 +310,9 @@ check-daemon:
 	$(MAKE) check TESTS="$(TESTS_daemon)"
 
 mainloop_test_SOURCES = tests/mainloop-test.c
-mainloop_test_CFLAGS = $(AM_CFLAGS)
+mainloop_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
 mainloop_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
-mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 thread_mainloop_test_SOURCES = tests/thread-mainloop-test.c
 thread_mainloop_test_CFLAGS = $(AM_CFLAGS)
@@ -435,9 +435,9 @@ cpulimit_test2_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la l
 cpulimit_test2_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 mainloop_test_glib_SOURCES = $(mainloop_test_SOURCES)
-mainloop_test_glib_CFLAGS = $(mainloop_test_CFLAGS) $(GLIB20_CFLAGS) -DGLIB_MAIN_LOOP
+mainloop_test_glib_CFLAGS = $(mainloop_test_CFLAGS) $(LIBCHECK_CFLAGS) $(GLIB20_CFLAGS) -DGLIB_MAIN_LOOP
 mainloop_test_glib_LDADD = $(mainloop_test_LDADD) $(GLIB20_LIBS) libpulse-mainloop-glib.la
-mainloop_test_glib_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+mainloop_test_glib_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 memblockq_test_SOURCES = tests/memblockq-test.c
 memblockq_test_CFLAGS = $(AM_CFLAGS)
diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c
index ab23de4..3b062f8 100644
--- a/src/tests/mainloop-test.c
+++ b/src/tests/mainloop-test.c
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <assert.h>
+#include <check.h>
 
 #include <pulse/rtclock.h>
 #include <pulse/timeval.h>
@@ -67,7 +68,7 @@ static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, v
 #endif
 }
 
-int main(int argc, char *argv[]) {
+START_TEST (mainloop_test) {
     pa_mainloop_api *a;
     pa_io_event *ioe;
     pa_time_event *te;
@@ -77,28 +78,28 @@ int main(int argc, char *argv[]) {
     pa_glib_mainloop *g;
 
     glib_main_loop = g_main_loop_new(NULL, FALSE);
-    assert(glib_main_loop);
+    fail_if(!glib_main_loop);
 
     g = pa_glib_mainloop_new(NULL);
-    assert(g);
+    fail_if(!g);
 
     a = pa_glib_mainloop_get_api(g);
-    assert(a);
+    fail_if(!a);
 #else /* GLIB_MAIN_LOOP */
     pa_mainloop *m;
 
     m = pa_mainloop_new();
-    assert(m);
+    fail_if(!m);
 
     a = pa_mainloop_get_api(m);
-    assert(a);
+    fail_if(!a);
 #endif /* GLIB_MAIN_LOOP */
 
     ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL);
-    assert(ioe);
+    fail_if(!ioe);
 
     de = a->defer_new(a, dcb, NULL);
-    assert(de);
+    fail_if(!de);
 
     te = a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 2 * PA_USEC_PER_SEC, TRUE), tcb, NULL);
 
@@ -118,6 +119,24 @@ int main(int argc, char *argv[]) {
 #else
     pa_mainloop_free(m);
 #endif
+}
+END_TEST
 
-    return 0;
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    s = suite_create("MainLoop");
+    tc = tcase_create("mainloop");
+    tcase_add_test(tc, mainloop_test);
+    suite_add_tcase(s, tc);
+
+    sr = srunner_create(s);
+    srunner_run_all(sr, CK_NORMAL);
+    failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+
+    return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }

commit c8cd89a7cb7aaa715bbdcde4e246b0bbf4f2ab64
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Tue Jul 17 14:45:52 2012 +0800

    tests: add cpu test
    
    It tests only x86 architecture right now.

diff --git a/src/Makefile.am b/src/Makefile.am
index 8f54b1d..06bc5db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -244,6 +244,7 @@ TESTS_default = \
 		volume-test \
 		mix-test \
 		proplist-test \
+		cpu-test \
 		lock-autospawn-test
 
 TESTS_norun = \
@@ -483,6 +484,11 @@ proplist_test_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la li
 proplist_test_CFLAGS = $(AM_CFLAGS)
 proplist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
+cpu_test_SOURCES = tests/cpu-test.c
+cpu_test_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
+cpu_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
+cpu_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
+
 rtstutter_SOURCES = tests/rtstutter.c
 rtstutter_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
 rtstutter_CFLAGS = $(AM_CFLAGS)
diff --git a/src/pulsecore/cpu-x86.c b/src/pulsecore/cpu-x86.c
index 05a4b2f..b2a558a 100644
--- a/src/pulsecore/cpu-x86.c
+++ b/src/pulsecore/cpu-x86.c
@@ -44,7 +44,7 @@ static void get_cpuid(uint32_t op, uint32_t *a, uint32_t *b, uint32_t *c, uint32
 }
 #endif
 
-pa_bool_t pa_cpu_init_x86(pa_cpu_x86_flag_t *flags) {
+void pa_cpu_get_x86_flags(pa_cpu_x86_flag_t *flags) {
 #if defined (__i386__) || defined (__amd64__)
     uint32_t eax, ebx, ecx, edx;
     uint32_t level;
@@ -111,6 +111,12 @@ pa_bool_t pa_cpu_init_x86(pa_cpu_x86_flag_t *flags) {
     (*flags & PA_CPU_X86_MMXEXT) ? "MMXEXT " : "",
     (*flags & PA_CPU_X86_3DNOW) ? "3DNOW " : "",
     (*flags & PA_CPU_X86_3DNOWEXT) ? "3DNOWEXT " : "");
+#endif /* defined (__i386__) || defined (__amd64__) */
+}
+
+pa_bool_t pa_cpu_init_x86(pa_cpu_x86_flag_t *flags) {
+#if defined (__i386__) || defined (__amd64__)
+    pa_cpu_get_x86_flags(flags);
 
     /* activate various optimisations */
     if (*flags & PA_CPU_X86_MMX) {
diff --git a/src/pulsecore/cpu-x86.h b/src/pulsecore/cpu-x86.h
index 0045ef6..9a9f3a1 100644
--- a/src/pulsecore/cpu-x86.h
+++ b/src/pulsecore/cpu-x86.h
@@ -40,6 +40,7 @@ typedef enum pa_cpu_x86_flag {
     PA_CPU_X86_CMOV      = (1 << 10)
 } pa_cpu_x86_flag_t;
 
+void pa_cpu_get_x86_flags(pa_cpu_x86_flag_t *flags);
 pa_bool_t pa_cpu_init_x86 (pa_cpu_x86_flag_t *flags);
 
 #if defined (__i386__)
diff --git a/src/pulsecore/sconv_sse.c b/src/pulsecore/sconv_sse.c
index 3c9a809..19de6fd 100644
--- a/src/pulsecore/sconv_sse.c
+++ b/src/pulsecore/sconv_sse.c
@@ -162,65 +162,11 @@ static void pa_sconv_s16le_from_f32ne_sse2(unsigned n, const float *a, int16_t *
     );
 }
 
-#undef RUN_TEST
-
-#ifdef RUN_TEST
-#define SAMPLES 1019
-#define TIMES 1000
-
-static void run_test(void) {
-    int16_t samples[SAMPLES];
-    int16_t samples_ref[SAMPLES];
-    float floats[SAMPLES];
-    int i;
-    pa_usec_t start, stop;
-    pa_convert_func_t func;
-
-    printf("checking SSE %zd\n", sizeof(samples));
-
-    memset(samples_ref, 0, sizeof(samples_ref));
-    memset(samples, 0, sizeof(samples));
-
-    for (i = 0; i < SAMPLES; i++) {
-        floats[i] = 2.1f * (rand()/(float) RAND_MAX - 0.5f);
-    }
-
-    func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
-    func(SAMPLES, floats, samples_ref);
-    pa_sconv_s16le_from_f32ne_sse2(SAMPLES, floats, samples);
-
-    for (i = 0; i < SAMPLES; i++) {
-        if (samples[i] != samples_ref[i]) {
-            printf ("%d: %04x != %04x (%f)\n", i, samples[i], samples_ref[i],
-                      floats[i]);
-        }
-    }
-
-    start = pa_rtclock_now();
-    for (i = 0; i < TIMES; i++) {
-        pa_sconv_s16le_from_f32ne_sse2(SAMPLES, floats, samples);
-    }
-    stop = pa_rtclock_now();
-    pa_log_info("SSE: %llu usec.", (long long unsigned int)(stop - start));
-
-    start = pa_rtclock_now();
-    for (i = 0; i < TIMES; i++) {
-        func(SAMPLES, floats, samples_ref);
-    }
-    stop = pa_rtclock_now();
-    pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
-}
-#endif
 #endif /* defined (__i386__) || defined (__amd64__) */
 
-
 void pa_convert_func_init_sse(pa_cpu_x86_flag_t flags) {
 #if !defined(__APPLE__) && defined (__i386__) || defined (__amd64__)
 
-#ifdef RUN_TEST
-    run_test();
-#endif
-
     if (flags & PA_CPU_X86_SSE2) {
         pa_log_info("Initialising SSE2 optimized conversions.");
         pa_set_convert_from_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse2);
diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c
index c470ffb..d68a105 100644
--- a/src/pulsecore/svolume_mmx.c
+++ b/src/pulsecore/svolume_mmx.c
@@ -240,100 +240,10 @@ static void pa_volume_s16re_mmx(int16_t *samples, const int32_t *volumes, unsign
     );
 }
 
-#undef RUN_TEST
-
-#ifdef RUN_TEST
-#define CHANNELS 2
-#define SAMPLES 1022
-#define TIMES 1000
-#define TIMES2 100
-#define PADDING 16
-
-static void run_test(void) {
-    int16_t samples[SAMPLES];
-    int16_t samples_ref[SAMPLES];
-    int16_t samples_orig[SAMPLES];
-    int32_t volumes[CHANNELS + PADDING];
-    int i, j, padding;
-    pa_do_volume_func_t func;
-    pa_usec_t start, stop;
-    int k;
-    pa_usec_t min = INT_MAX, max = 0;
-    double s1 = 0, s2 = 0;
-
-    func = pa_get_volume_func(PA_SAMPLE_S16NE);
-
-    printf("checking MMX %zd\n", sizeof(samples));
-
-    pa_random(samples, sizeof(samples));
-    /* for (i = 0; i < SAMPLES; i++)
-       samples[i] = -1; */
-    memcpy(samples_ref, samples, sizeof(samples));
-    memcpy(samples_orig, samples, sizeof(samples));
-
-    for (i = 0; i < CHANNELS; i++)
-        volumes[i] = PA_CLAMP_VOLUME(rand() >> 15);
-        /* volumes[i] = 0x0000ffff; */
-    for (padding = 0; padding < PADDING; padding++, i++)
-        volumes[i] = volumes[padding];
-
-    func(samples_ref, volumes, CHANNELS, sizeof(samples));
-    pa_volume_s16ne_mmx(samples, volumes, CHANNELS, sizeof(samples));
-    for (i = 0; i < SAMPLES; 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]);
-        }
-    }
-
-    for (k = 0; k < TIMES2; k++) {
-        start = pa_rtclock_now();
-        for (j = 0; j < TIMES; j++) {
-            memcpy(samples, samples_orig, sizeof(samples));
-            pa_volume_s16ne_mmx(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_info("MMX: %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));
-            func(samples_ref, 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_info("ref: %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_assert_se(memcmp(samples_ref, samples, sizeof(samples)) == 0);
-}
-#endif
-
 #endif /* defined (__i386__) || defined (__amd64__) */
 
-
 void pa_volume_func_init_mmx(pa_cpu_x86_flag_t flags) {
 #if defined (__i386__) || defined (__amd64__)
-
-#ifdef RUN_TEST
-    run_test();
-#endif
-
     if ((flags & PA_CPU_X86_MMX) && (flags & PA_CPU_X86_CMOV)) {
         pa_log_info("Initialising MMX optimized volume functions.");
 
diff --git a/src/pulsecore/svolume_sse.c b/src/pulsecore/svolume_sse.c
index 771bf53..daa87ca 100644
--- a/src/pulsecore/svolume_sse.c
+++ b/src/pulsecore/svolume_sse.c
@@ -252,95 +252,10 @@ static void pa_volume_s16re_sse2(int16_t *samples, const int32_t *volumes, unsig
     );
 }
 
-#undef RUN_TEST
-
-#ifdef RUN_TEST
-#define CHANNELS 2
-#define SAMPLES 1022
-#define TIMES 1000
-#define TIMES2 100
-#define PADDING 16
-
-static void run_test(void) {
-    int16_t samples[SAMPLES];
-    int16_t samples_ref[SAMPLES];
-    int16_t samples_orig[SAMPLES];
-    int32_t volumes[CHANNELS + PADDING];
-    int i, j, padding;
-    pa_do_volume_func_t func;
-    pa_usec_t start, stop;
-    int k;
-    pa_usec_t min = INT_MAX, max = 0;
-    double s1 = 0, s2 = 0;
-
-    func = pa_get_volume_func(PA_SAMPLE_S16NE);
-
-    printf("checking SSE2 %zd\n", sizeof(samples));
-
-    pa_random(samples, sizeof(samples));
-    memcpy(samples_ref, samples, sizeof(samples));
-    memcpy(samples_orig, samples, sizeof(samples));
-
-    for (i = 0; i < CHANNELS; i++)
-        volumes[i] = PA_CLAMP_VOLUME(rand() >> 15);
-    for (padding = 0; padding < PADDING; padding++, i++)
-        volumes[i] = volumes[padding];
-
-    func(samples_ref, volumes, CHANNELS, sizeof(samples));
-    pa_volume_s16ne_sse2(samples, volumes, CHANNELS, sizeof(samples));
-    for (i = 0; i < SAMPLES; i++) {
-        if (samples[i] != samples_ref[i]) {
-            printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i],
-                      samples_orig[i], volumes[i % CHANNELS]);
-        }
-    }
-
-    for (k = 0; k < TIMES2; k++) {
-        start = pa_rtclock_now();
-        for (j = 0; j < TIMES; j++) {
-            memcpy(samples, samples_orig, sizeof(samples));
-            pa_volume_s16ne_sse2(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_info("SSE: %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));
-            func(samples_ref, 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_info("ref: %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_assert_se(memcmp(samples_ref, samples, sizeof(samples)) == 0);
-}
-#endif
 #endif /* defined (__i386__) || defined (__amd64__) */
 
 void pa_volume_func_init_sse(pa_cpu_x86_flag_t flags) {
 #if defined (__i386__) || defined (__amd64__)
-
-#ifdef RUN_TEST
-    run_test();
-#endif
-
     if (flags & PA_CPU_X86_SSE2) {
         pa_log_info("Initialising SSE2 optimized volume functions.");
 
diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
new file mode 100644
index 0000000..de25bc6
--- /dev/null
+++ b/src/tests/cpu-test.c
@@ -0,0 +1,292 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <check.h>
+#include <unistd.h>
+#include <math.h>
+
+#include <pulse/rtclock.h>
+#include <pulsecore/cpu-x86.h>
+#include <pulsecore/random.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/endianmacros.h>
+#include <pulsecore/sconv.h>
+#include <pulsecore/sample-util.h>
+
+START_TEST (svolume_mmx_test) {
+#define CHANNELS 2
+#define SAMPLES 1022
+#define TIMES 1000
+#define TIMES2 100
+#define PADDING 16
+
+    int16_t samples[SAMPLES];
+    int16_t samples_ref[SAMPLES];
+    int16_t samples_orig[SAMPLES];
+    int32_t volumes[CHANNELS + PADDING];
+    int i, j, padding;
+    pa_do_volume_func_t orig_func, mmx_func;
+    pa_usec_t start, stop;
+    int k;
+    pa_usec_t min = INT_MAX, max = 0;
+    double s1 = 0, s2 = 0;
+
+    pa_cpu_x86_flag_t flags = 0;
+
+    pa_cpu_get_x86_flags(&flags);
+
+    if (!((flags & PA_CPU_X86_MMX) && (flags & PA_CPU_X86_CMOV))) {
+        pa_log_info("MMX/CMOV not supported. Skipping");
+        return;
+    }
+
+    orig_func = pa_get_volume_func(PA_SAMPLE_S16NE);
+    pa_volume_func_init_mmx(flags);
+    mmx_func = pa_get_volume_func(PA_SAMPLE_S16NE);
+
+    pa_log_debug("Checking MMX svolume (%zd)\n", sizeof(samples));
+
+    pa_random(samples, sizeof(samples));
+    memcpy(samples_ref, samples, sizeof(samples));
+    memcpy(samples_orig, samples, sizeof(samples));
+
+    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];
+
+    orig_func(samples_ref, volumes, CHANNELS, sizeof(samples));
+    mmx_func(samples, volumes, CHANNELS, sizeof(samples));
+    for (i = 0; i < SAMPLES; 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();
+        }
+    }
+
+    for (k = 0; k < TIMES2; k++) {
+        start = pa_rtclock_now();
+        for (j = 0; j < TIMES; j++) {
+            memcpy(samples, samples_orig, sizeof(samples));
+            mmx_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_info("MMX: %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();
+
+        if (min > (stop - start)) min = stop - start;
+        if (max < (stop - start)) max = stop - start;
+        s1 += stop - start;
+        s2 += (stop - start) * (stop - start);
+    }
+    pa_log_info("ref: %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);
+
+    fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0);
+
+#undef CHANNELS
+#undef SAMPLES
+#undef TIMES
+#undef TIMES2
+#undef PADDING
+}
+END_TEST
+
+START_TEST (svolume_sse_test) {
+#define CHANNELS 2
+#define SAMPLES 1022
+#define TIMES 1000
+#define TIMES2 100
+#define PADDING 16
+
+    int16_t samples[SAMPLES];
+    int16_t samples_ref[SAMPLES];
+    int16_t samples_orig[SAMPLES];
+    int32_t volumes[CHANNELS + PADDING];
+    int i, j, padding;
+    pa_do_volume_func_t orig_func, sse_func;
+    pa_usec_t start, stop;
+    int k;
+    pa_usec_t min = INT_MAX, max = 0;
+    double s1 = 0, s2 = 0;
+    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;
+    }
+
+    orig_func = pa_get_volume_func(PA_SAMPLE_S16NE);
+    pa_volume_func_init_sse(flags);
+    sse_func = pa_get_volume_func(PA_SAMPLE_S16NE);
+
+    pa_log_debug("Checking SSE2 svolume (%zd)\n", sizeof(samples));
+
+    pa_random(samples, sizeof(samples));
+    memcpy(samples_ref, samples, sizeof(samples));
+    memcpy(samples_orig, samples, sizeof(samples));
+
+    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];
+
+    orig_func(samples_ref, volumes, CHANNELS, sizeof(samples));
+    sse_func(samples, volumes, CHANNELS, sizeof(samples));
+    for (i = 0; i < SAMPLES; i++) {
+        if (samples[i] != samples_ref[i]) {
+            printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i],
+                      samples_orig[i], volumes[i % CHANNELS]);
+            fail();
+        }
+    }
+
+    for (k = 0; k < TIMES2; k++) {
+        start = pa_rtclock_now();
+        for (j = 0; j < TIMES; j++) {
+            memcpy(samples, samples_orig, sizeof(samples));
+            sse_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_info("SSE: %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();
+
+        if (min > (stop - start)) min = stop - start;
+        if (max < (stop - start)) max = stop - start;
+        s1 += stop - start;
+        s2 += (stop - start) * (stop - start);
+    }
+    pa_log_info("ref: %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);
+
+    fail_unless(memcmp(samples_ref, samples, sizeof(samples)) == 0);
+
+#undef CHANNELS
+#undef SAMPLES
+#undef TIMES
+#undef TIMES2
+#undef PADDING
+}
+END_TEST
+
+START_TEST (sconv_sse_test) {
+#define SAMPLES 1019
+#define TIMES 1000
+
+    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));
+
+    for (i = 0; i < SAMPLES; i++) {
+        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);
+
+    for (i = 0; i < SAMPLES; i++) {
+        if (samples[i] != samples_ref[i]) {
+            printf ("%d: %04x != %04x (%f)\n", i, samples[i], samples_ref[i],
+                      floats[i]);
+            fail();
+        }
+    }
+
+    start = pa_rtclock_now();
+    for (i = 0; i < TIMES; i++) {
+        sse_func(SAMPLES, floats, samples);
+    }
+    stop = pa_rtclock_now();
+    pa_log_info("SSE: %llu usec.", (long long unsigned int)(stop - start));
+
+    start = pa_rtclock_now();
+    for (i = 0; i < TIMES; i++) {
+        orig_func(SAMPLES, floats, samples_ref);
+    }
+    stop = pa_rtclock_now();
+    pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
+
+#undef SAMPLES
+#undef TIMES
+}
+END_TEST
+
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    if (!getenv("MAKE_CHECK"))
+        pa_log_set_level(PA_LOG_DEBUG);
+
+    s = suite_create("CPU");
+    tc = tcase_create("x86");
+    tcase_add_test(tc, svolume_mmx_test);
+    tcase_add_test(tc, svolume_sse_test);
+    tcase_add_test(tc, sconv_sse_test);
+    suite_add_tcase(s, tc);
+
+    sr = srunner_create(s);
+    srunner_run_all(sr, CK_NORMAL);
+    failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+
+    return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}

commit 6e33eb00737087ecc165ce3d8d20f48ae771a541
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Tue Jul 17 14:45:51 2012 +0800

    tests: modify mix-test to use new 'check' test framework

diff --git a/src/Makefile.am b/src/Makefile.am
index 79d5922..8f54b1d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -465,8 +465,8 @@ resampler_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 mix_test_SOURCES = tests/mix-test.c
 mix_test_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
-mix_test_CFLAGS = $(AM_CFLAGS)
-mix_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+mix_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
+mix_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 remix_test_SOURCES = tests/remix-test.c
 remix_test_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
diff --git a/src/tests/mix-test.c b/src/tests/mix-test.c
index 19b5ea5..d797a68 100644
--- a/src/tests/mix-test.c
+++ b/src/tests/mix-test.c
@@ -22,6 +22,9 @@
 #endif
 
 #include <stdio.h>
+#include <math.h>
+
+#include <check.h>
 
 #include <pulse/sample.h>
 #include <pulse/volume.h>
@@ -31,71 +34,269 @@
 #include <pulsecore/memblock.h>
 #include <pulsecore/sample-util.h>
 
-static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
+
+/* PA_SAMPLE_U8 */
+static const uint8_t u8_result[3][10] = {
+{ 0x00, 0xff, 0x7f, 0x80, 0x9f, 0x3f, 0x01, 0xf0, 0x20, 0x21 },
+{ 0x0c, 0xf2, 0x7f, 0x80, 0x9b, 0x45, 0x0d, 0xe4, 0x29, 0x2a },
+{ 0x00, 0xff, 0x7e, 0x80, 0xba, 0x04, 0x00, 0xff, 0x00, 0x00 },
+};
+
+/* PA_SAMPLE_ALAW */
+static const uint8_t alaw_result[3][10] = {
+{ 0x00, 0xff, 0x7f, 0x80, 0x9f, 0x3f, 0x01, 0xf0, 0x20, 0x21 },
+{ 0x06, 0xf2, 0x72, 0x86, 0x92, 0x32, 0x07, 0xf6, 0x26, 0x27 },
+{ 0x31, 0xec, 0x6d, 0xb1, 0x8c, 0x2d, 0x36, 0xe1, 0x2a, 0x2a },
+};
+
+/* PA_SAMPLE_ULAW */
+static const uint8_t ulaw_result[3][10] = {
+{ 0x00, 0xff, 0x7f, 0x80, 0x9f, 0x3f, 0x01, 0xf0, 0x20, 0x21 },
+{ 0x03, 0xff, 0xff, 0x83, 0xa2, 0x42, 0x04, 0xf2, 0x23, 0x24 },
+{ 0x00, 0xff, 0xff, 0x80, 0x91, 0x31, 0x00, 0xe9, 0x12, 0x13 },
+};
+
+/* PA_SAMPLE_S16LE */
+static const uint16_t s16le_result[3][10] = {
+{ 0x0000, 0xffff, 0x7fff, 0x8000, 0x9fff, 0x3fff, 0x0001, 0xf000, 0x0020, 0x0021 },
+{ 0x0000, 0xffff, 0x7332, 0x8ccd, 0xa998, 0x3998, 0x0000, 0xf199, 0x001c, 0x001d },
+{ 0x0000, 0xfffe, 0x7fff, 0x8000, 0x8000, 0x7997, 0x0001, 0xe199, 0x003c, 0x003e },
+};
+
+/* PA_SAMPLE_S16BE */
+static const uint16_t s16be_result[3][10] = {
+{ 0x0000, 0xffff, 0x7fff, 0x8000, 0x9fff, 0x3fff, 0x0001, 0xf000, 0x0020, 0x0021 },
+{ 0x0000, 0xffff, 0x8bff, 0x7300, 0xa8ff, 0x52ff, 0xe600, 0xd700, 0xcc1c, 0xb31d },
+{ 0x0000, 0xfeff, 0x0aff, 0xf300, 0x47ff, 0x91fe, 0xe601, 0xc701, 0xcc3c, 0xb33e },
+};
+
+/* PA_SAMPLE_FLOAT32LE */
+static const float float32le_result[3][10] = {
+{ 0.000000, -1.000000, 1.000000, 4711.000000, 0.222000, 0.330000, -0.300000, 99.000000, -0.555000, -0.123000 },
+{ 0.000000, -0.899987, 0.899987, 4239.837402, 0.199797, 0.296996, -0.269996, 89.098679, -0.499493, -0.110698 },
+{ 0.000000, -1.899987, 1.899987, 8950.837891, 0.421797, 0.626996, -0.569996, 188.098679, -1.054493, -0.233698 },
+};
+
+/* PA_SAMPLE_FLOAT32BE */
+static const float float32be_result[3][10] = {
+{ 0.000000, -1.000000, 1.000000, 4711.000000, 0.222000, 0.330000, -0.300000, 99.000000, -0.555000, -0.123000 },
+{ 0.000000, -0.899987, 0.899987, 4239.837402, 0.199797, 0.296996, -0.269996, 89.098679, -0.499493, -0.110698 },
+{ 0.000000, -1.899987, 1.899987, 8950.837891, 0.421797, 0.626996, -0.569996, 188.098679, -1.054493, -0.233698 },
+};
+
+/* PA_SAMPLE_S32LE */
+static const uint32_t s32le_result[3][10] = {
+{ 0x00000001, 0xffff0002, 0x7fff0003, 0x80000004, 0x9fff0005, 0x3fff0006, 0x00010007, 0xf0000008, 0x00200009, 0x0021000a },
+{ 0x00000000, 0xffff199b, 0x7332199c, 0x8ccd0003, 0xa998d99e, 0x3998999f, 0x0000e66c, 0xf199a007, 0x001cccc8, 0x001db32e },
+{ 0x00000001, 0xfffe199d, 0x7fffffff, 0x80000000, 0x80000000, 0x799799a5, 0x0001e673, 0xe199a00f, 0x003cccd1, 0x003eb338 },
+};
+
+/* PA_SAMPLE_S32BE */
+static const uint32_t s32be_result[3][10] = {
+{ 0x00000001, 0xffff0002, 0x7fff0003, 0x80000004, 0x9fff0005, 0x3fff0006, 0x00010007, 0xf0000008, 0x00200009, 0x0021000a },
+{ 0x0066e600, 0x65b2cd01, 0xf117b402, 0x73989903, 0x0ee48004, 0xb8496705, 0xe6ca4c06, 0xd7303307, 0xccb21908, 0xb3190009 },
+{ 0x0066e601, 0x64b2ce03, 0x7017b505, 0xf3989907, 0xade38109, 0xf748680b, 0xe6cb4c0d, 0xc731330f, 0xccd21911, 0xb33a0013 },
+};
+
+/* PA_SAMPLE_S24LE */
+static const uint8_t s24le_result[3][30] = {
+{ 0x00, 0x00, 0x01, 0xff, 0xff, 0x02, 0x7f, 0xff, 0x03, 0x80, 0x00, 0x04, 0x9f, 0xff, 0x05, 0x3f, 0xff, 0x06, 0x01, 0x00, 0x07, 0xf0, 0x00, 0x08, 0x20, 0x00, 0x09, 0x21, 0x00, 0x0a },
+{ 0x66, 0xe6, 0x00, 0x31, 0xb3, 0x02, 0x23, 0x99, 0x03, 0x0b, 0x9a, 0x03, 0x0c, 0x66, 0x05, 0x1c, 0x4c, 0x06, 0xca, 0x4c, 0x06, 0x07, 0x34, 0x07, 0xb2, 0x19, 0x08, 0x19, 0x00, 0x09 },
+{ 0x66, 0xe6, 0x01, 0x30, 0xb3, 0x05, 0xa2, 0x98, 0x07, 0x8b, 0x9a, 0x07, 0xab, 0x65, 0x0b, 0x5b, 0x4b, 0x0d, 0xcb, 0x4c, 0x0d, 0xf7, 0x34, 0x0f, 0xd2, 0x19, 0x11, 0x3a, 0x00, 0x13 },
+};
+
+/* PA_SAMPLE_S24BE */
+static const uint8_t s24be_result[3][30] = {
+{ 0x00, 0x00, 0x01, 0xff, 0xff, 0x02, 0x7f, 0xff, 0x03, 0x80, 0x00, 0x04, 0x9f, 0xff, 0x05, 0x3f, 0xff, 0x06, 0x01, 0x00, 0x07,
+    0xf0, 0x00, 0x08, 0x20, 0x00, 0x09, 0x21, 0x00, 0x0a },
+{ 0x00, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x73, 0x32, 0x1c, 0x8c, 0xcd, 0x03, 0xa9, 0x98, 0xde, 0x39, 0x98, 0x9f, 0x00, 0xe6, 0x6c,
+    0xf1, 0x99, 0xa7, 0x1c, 0xcc, 0xc8, 0x1d, 0xb3, 0x2e },
+{ 0x00, 0x00, 0x01, 0xff, 0xfe, 0x1d, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x79, 0x97, 0xa5, 0x01, 0xe6, 0x73,
+    0xe1, 0x99, 0xaf, 0x3c, 0xcc, 0xd1, 0x3e, 0xb3, 0x38 },
+};
+
+/* PA_SAMPLE_S24_32LE */
+static const uint32_t s24_32le_result[3][10] = {
+{ 0x00000001, 0xffff0002, 0x7fff0003, 0x80000004, 0x9fff0005, 0x3fff0006, 0x00010007, 0xf0000008, 0x00200009, 0x0021000a },
+{ 0x00000000, 0x00ff199b, 0x00ff199c, 0x00000003, 0x00ff199e, 0x00ff199f, 0x0000e66c, 0x00000007, 0x001cccc8, 0x001db32e },
+{ 0x00000001, 0x00fe199d, 0x00fe199f, 0x00000007, 0x00fe19a3, 0x00fe19a5, 0x0001e673, 0x0000000f, 0x003cccd1, 0x003eb338 },
+};
+
+/* PA_SAMPLE_S24_32BE */
+static const uint32_t s24_32be_result[3][10] = {
+{ 0x00000001, 0xffff0002, 0x7fff0003, 0x80000004, 0x9fff0005, 0x3fff0006, 0x00010007, 0xf0000008, 0x00200009, 0x0021000a },
+{ 0x00000000, 0x65e60000, 0xf1e50000, 0x73000000, 0x0ee60000, 0xb8e50000, 0xe6000000, 0xd7000000, 0xcc1c0000, 0xb31d0000 },
+{ 0x00000000, 0xe5010200, 0x00036400, 0x0470e500, 0xf3000000, 0xe5010500, 0x0006ad00, 0x07f7e400, 0xe6010000, 0x00000800 },
+};
+
+static void compare_block(const pa_sample_spec *ss, const pa_memchunk *chunk, int iter) {
     void *d;
     unsigned i;
 
-    if (getenv("MAKE_CHECK"))
-        return;
-
     d = pa_memblock_acquire(chunk->memblock);
 
     switch (ss->format) {
+        case PA_SAMPLE_U8: {
+            const uint8_t *v = u8_result[iter];
+            uint8_t *u = d;
+
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
+            break;
+        }
 
-        case PA_SAMPLE_U8:
-        case PA_SAMPLE_ULAW:
         case PA_SAMPLE_ALAW: {
+            const uint8_t *v = alaw_result[iter];
             uint8_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
-                printf("0x%02x ", *(u++));
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
+            break;
+        }
+
+        case PA_SAMPLE_ULAW: {
+            const uint8_t *v = ulaw_result[iter];
+            uint8_t *u = d;
 
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
             break;
         }
 
-        case PA_SAMPLE_S16NE:
-        case PA_SAMPLE_S16RE: {
+        case PA_SAMPLE_S16LE: {
+            const uint16_t *v = s16le_result[iter];
             uint16_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
-                printf("0x%04x ", *(u++));
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
+            break;
+        }
+
+        case PA_SAMPLE_S16BE: {
+            const uint16_t *v = s16be_result[iter];
+            uint16_t *u = d;
 
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
             break;
         }
 
-        case PA_SAMPLE_S24_32NE:
-        case PA_SAMPLE_S24_32RE:
-        case PA_SAMPLE_S32NE:
-        case PA_SAMPLE_S32RE: {
+        case PA_SAMPLE_FLOAT32LE: {
+            const float *v = float32le_result[iter];
+            float *u = d;
+
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                float uu = ss->format == PA_SAMPLE_FLOAT32NE ? *u : PA_FLOAT32_SWAP(*u);
+                fail_unless(fabs(uu - *v) <= 1e-6, NULL);
+                ++u;
+                ++v;
+            }
+            break;
+        }
+
+        case PA_SAMPLE_FLOAT32BE: {
+            const float *v = float32be_result[iter];
+            float *u = d;
+
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                float uu = ss->format == PA_SAMPLE_FLOAT32NE ? *u : PA_FLOAT32_SWAP(*u);
+                fail_unless(fabs(uu - *v) <= 1e-6, NULL);
+                ++u;
+                ++v;
+            }
+            break;
+        }
+
+        case PA_SAMPLE_S32LE: {
+            const uint32_t *v = s32le_result[iter];
             uint32_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
-                printf("0x%08x ", *(u++));
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
+            break;
+        }
+
+        case PA_SAMPLE_S32BE: {
+            const uint32_t *v = s32be_result[iter];
+            uint32_t *u = d;
 
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
             break;
         }
 
-        case PA_SAMPLE_S24NE:
-        case PA_SAMPLE_S24RE: {
-            uint8_t *u = d;
+        case PA_SAMPLE_S24_32LE: {
+            const uint32_t *v = s24_32le_result[iter];
+            uint32_t *u = d;
 
             for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
-                printf("0x%02x%02x%02xx ", *u, *(u+1), *(u+2));
-                u += 3;
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
             }
+            break;
+        }
+
+        case PA_SAMPLE_S24_32BE: {
+            const uint32_t *v = s24_32be_result[iter];
+            uint32_t *u = d;
 
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                ++u;
+                ++v;
+            }
             break;
         }
 
-        case PA_SAMPLE_FLOAT32NE:
-        case PA_SAMPLE_FLOAT32RE: {
-            float *u = d;
+        case PA_SAMPLE_S24LE: {
+            const uint8_t *v = s24le_result[iter];
+            uint8_t *u = d;
 
             for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
-                printf("%1.5f ",  ss->format == PA_SAMPLE_FLOAT32NE ? *u : PA_FLOAT32_SWAP(*u));
-                u++;
+                fail_unless(*u == *v, NULL);
+                fail_unless(*(u+1) == *(v+1), NULL);
+                fail_unless(*(u+2) == *(v+2), NULL);
+
+                u += 3;
+                v += 3;
             }
+            break;
+        }
 
+        case PA_SAMPLE_S24BE: {
+            const uint8_t *v = s24be_result[iter];
+            uint8_t *u = d;
+
+            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+                fail_unless(*u == *v, NULL);
+                fail_unless(*(u+1) == *(v+1), NULL);
+                fail_unless(*(u+2) == *(v+2), NULL);
+
+                u += 3;
+                v += 3;
+            }
             break;
         }
 
@@ -103,8 +304,6 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
             pa_assert_not_reached();
     }
 
-    printf("\n");
-
     pa_memblock_release(chunk->memblock);
 }
 
@@ -200,7 +399,7 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
     return r;
 }
 
-int main(int argc, char *argv[]) {
+START_TEST (mix_test) {
     pa_mempool *pool;
     pa_sample_spec a;
     pa_cvolume v;
@@ -208,7 +407,7 @@ int main(int argc, char *argv[]) {
     if (!getenv("MAKE_CHECK"))
         pa_log_set_level(PA_LOG_DEBUG);
 
-    pa_assert_se(pool = pa_mempool_new(FALSE, 0));
+    fail_unless((pool = pa_mempool_new(FALSE, 0)) != NULL, NULL);
 
     a.channels = 1;
     a.rate = 44100;
@@ -228,7 +427,7 @@ int main(int argc, char *argv[]) {
         i.length = pa_memblock_get_length(i.memblock);
         i.index = 0;
 
-        dump_block(&a, &i);
+        compare_block(&a, &i, 0);
 
         /* Make a copy */
         j = i;
@@ -238,7 +437,7 @@ int main(int argc, char *argv[]) {
         /* Adjust volume of the copy */
         pa_volume_memchunk(&j, &a, &v);
 
-        dump_block(&a, &j);
+        compare_block(&a, &j, 1);
 
         m[0].chunk = i;
         m[0].volume.values[0] = PA_VOLUME_NORM;
@@ -255,7 +454,7 @@ int main(int argc, char *argv[]) {
         pa_mix(m, 2, ptr, k.length, &a, NULL, FALSE);
         pa_memblock_release(k.memblock);
 
-        dump_block(&a, &k);
+        compare_block(&a, &k, 2);
 
         pa_memblock_unref(i.memblock);
         pa_memblock_unref(j.memblock);
@@ -263,6 +462,24 @@ int main(int argc, char *argv[]) {
     }
 
     pa_mempool_free(pool);
+}
+END_TEST
 
-    return 0;
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    s = suite_create("Mix");
+    tc = tcase_create("mix");
+    tcase_add_test(tc, mix_test);
+    suite_add_tcase(s, tc);
+
+    sr = srunner_create(s);
+    srunner_run_all(sr, CK_NORMAL);
+    failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+
+    return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }

commit 1025fa08bea99b8358b3ed924574c6b6fb55f6f0
Author: Deng Zhengrong <dzrongg at gmail.com>
Date:   Tue Jul 17 14:45:50 2012 +0800

    build-sys: add `check` test framework

diff --git a/configure.ac b/configure.ac
index 0290fa0..ffb2a35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -579,6 +579,12 @@ fi
 
 AC_CHECK_HEADERS_ONCE([valgrind/memcheck.h])
 
+#### check test framework ####
+
+PKG_CHECK_MODULES(LIBCHECK, [ check ])
+AC_SUBST(LIBCHECK_CFLAGS)
+AC_SUBST(LIBCHECK_LIBS)
+
 #### json parsing ####
 
 PKG_CHECK_MODULES(LIBJSON, [ json >= 0.9 ])



More information about the pulseaudio-commits mailing list