[pulseaudio-discuss] [PATCH 5/5] tests: add cpu test

Deng Zhengrong dzrongg at gmail.com
Wed Jul 11 07:25:18 PDT 2012


It tests only x86 architecture right now.
---
 src/Makefile.am         |  6 ++++++
 src/pulsecore/cpu-x86.c |  9 ++++++++-
 src/pulsecore/cpu-x86.h |  1 +
 src/tests/cpu-test.c    | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 src/tests/cpu-test.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 521b353..6168858 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -245,6 +245,7 @@ TESTS_default = \
 		volume-test \
 		mix-test \
 		proplist-test \
+		cpu-test \
 		lock-autospawn-test
 
 TESTS_norun = \
@@ -484,6 +485,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)
+cpu_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+
 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..b778de2 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;
@@ -98,6 +98,13 @@ pa_bool_t pa_cpu_init_x86(pa_cpu_x86_flag_t *flags) {
         if (edx & (1<<31))
           *flags |= PA_CPU_X86_3DNOW;
     }
+#endif
+}
+
+pa_bool_t pa_cpu_init_x86(pa_cpu_x86_flag_t *flags) {
+    pa_cpu_get_x86_flags(flags);
+
+#if defined (__i386__) || defined (__amd64__)
 
     pa_log_info("CPU flags: %s%s%s%s%s%s%s%s%s%s%s",
     (*flags & PA_CPU_X86_CMOV) ? "CMOV " : "",
diff --git a/src/pulsecore/cpu-x86.h b/src/pulsecore/cpu-x86.h
index 52adea7..38b55e5 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/tests/cpu-test.c b/src/tests/cpu-test.c
new file mode 100644
index 0000000..07018c3
--- /dev/null
+++ b/src/tests/cpu-test.c
@@ -0,0 +1,50 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <check.h>
+#include <unistd.h>
+
+#include <pulsecore/cpu-x86.h>
+
+START_TEST (svolume_mmx_test)
+{
+    svolume_mmx_unit_test();
+}
+END_TEST
+
+START_TEST (svolume_sse_test)
+{
+    svolume_sse_unit_test();
+}
+END_TEST
+
+START_TEST (sconv_sse_test)
+{
+    sconv_sse_unit_test();
+}
+END_TEST
+
+int main(int argc, char *argv[]) {
+    pa_cpu_x86_flag_t flags = 0;
+    int failed = 0;
+
+    pa_cpu_get_x86_flags(&flags);
+
+    Suite *s = suite_create("CPU");
+    TCase *tc = tcase_create("x86");
+    if (flags & PA_CPU_X86_MMX)
+        tcase_add_test(tc, svolume_mmx_test);
+    if (flags & (PA_CPU_X86_SSE | PA_CPU_X86_SSE2)) {
+        tcase_add_test(tc, svolume_sse_test);
+        tcase_add_test(tc, sconv_sse_test);
+    }
+    suite_add_tcase(s, tc);
+
+    SRunner *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;
+}
-- 
1.7.11.1



More information about the pulseaudio-discuss mailing list