Module: xenomai-3
Branch: next
Commit: 6cfca2ba8df5f1885da7e19d3e6b34f2159db578
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=6cfca2ba8df5f1885da7e19d3e6b34f2159db578

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Oct 24 15:52:48 2015 +0200

testsuite/smokey: add basic FPU stress test

---

 configure.ac                             |    6 +-
 testsuite/smokey/Makefile.am             |    1 +
 testsuite/smokey/fpu-stress/Makefile.am  |    8 +++
 testsuite/smokey/fpu-stress/fpu-stress.c |   95 ++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5b2a074..bbaf4a7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -905,11 +905,7 @@ AC_CONFIG_FILES([ \
        testsuite/smokey/timerfd/Makefile \
        testsuite/smokey/tsc/Makefile \
        testsuite/smokey/leaks/Makefile \
-       testsuite/smokey/net_udp/Makefile \
-       testsuite/smokey/net_packet_dgram/Makefile \
-       testsuite/smokey/net_packet_raw/Makefile \
-       testsuite/smokey/net_common/Makefile \
-       testsuite/smokey/cpu-affinity/Makefile \
+       testsuite/smokey/fpu-stress/Makefile \
        testsuite/clocktest/Makefile \
        testsuite/xeno-test/Makefile \
        utils/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index b0904d2..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -9,6 +9,7 @@ COBALT_SUBDIRS =        \
        arith           \
        bufp            \
        cpu-affinity    \
+       fpu-stress      \
        iddp            \
        leaks           \
        net_packet_dgram\
diff --git a/testsuite/smokey/fpu-stress/Makefile.am 
b/testsuite/smokey/fpu-stress/Makefile.am
new file mode 100644
index 0000000..c90d0dd
--- /dev/null
+++ b/testsuite/smokey/fpu-stress/Makefile.am
@@ -0,0 +1,8 @@
+
+noinst_LIBRARIES = libfpu-stress.a
+
+libfpu_stress_a_SOURCES = fpu-stress.c
+
+libfpu_stress_a_CPPFLAGS =     \
+       @XENO_USER_CFLAGS@      \
+       -I$(top_srcdir)/include
diff --git a/testsuite/smokey/fpu-stress/fpu-stress.c 
b/testsuite/smokey/fpu-stress/fpu-stress.c
new file mode 100644
index 0000000..59383c9
--- /dev/null
+++ b/testsuite/smokey/fpu-stress/fpu-stress.c
@@ -0,0 +1,95 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <smokey/smokey.h>
+#include <asm/xenomai/features.h>
+#include <asm/xenomai/uapi/fptest.h>
+
+smokey_test_plugin(fpu_stress,
+                  SMOKEY_ARGLIST(
+                          SMOKEY_INT(duration),
+                  ),
+                  "Check FPU context sanity during real-time stress\n"
+                  "\tduration=<seconds>\thow long to run the stress loop 
(0=indefinitely)"
+);
+
+static int fp_features;
+
+static void *stress_loop(void *arg)
+{
+       struct timespec rqt = {
+               .tv_sec = 0,
+               .tv_nsec = CONFIG_XENO_DEFAULT_PERIOD
+       };
+       
+       for (;;) {
+               fp_regs_set(fp_features, 0xf1f5f1f5);
+               clock_nanosleep(CLOCK_MONOTONIC, 0, &rqt, NULL);
+       }
+
+       return NULL;
+}
+
+static int report_error(const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       smokey_vatrace(fmt, ap);
+       va_end(ap);
+
+       return 0;
+}
+
+static int run_fpu_stress(struct smokey_test *t,
+                         int argc, char *const argv[])
+{
+       unsigned sleep_ms, n, rounds, duration = 3;
+       struct sched_param param;
+       pthread_attr_t attr;
+       struct timespec rqt;
+       pthread_t tid;
+       int ret;
+
+       fp_features = cobalt_fp_detect();
+       if (fp_features == 0)
+               return -ENOSYS;
+
+       smokey_parse_args(t, argc, argv);
+       
+       if (SMOKEY_ARG_ISSET(fpu_stress, duration))
+               duration = SMOKEY_ARG_INT(fpu_stress, duration);
+       
+       rqt.tv_sec = 0;
+       rqt.tv_nsec = CONFIG_XENO_DEFAULT_PERIOD;
+       sleep_ms = 1000000UL / rqt.tv_nsec; /* wake up each ms */
+       rounds = duration * 1000UL / sleep_ms;
+
+       pthread_attr_init(&attr);
+       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+       pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+       pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+       param.sched_priority = 10;
+       pthread_attr_setschedparam(&attr, &param);
+       ret = pthread_create(&tid, &attr, stress_loop, NULL);
+       if (ret)
+               return -ret;
+
+       if (rounds)
+               smokey_trace("running for %d seconds", duration);
+       else
+               smokey_trace("running indefinitely...");
+
+       for (n = 0; rounds == 0 || n < rounds; n++) {
+               fp_regs_set(fp_features, n);
+               __STD(clock_nanosleep(CLOCK_MONOTONIC, 0, &rqt, NULL));
+               if (fp_regs_check(fp_features, n, report_error) != n) {
+                       ret = -EINVAL;
+                       break;
+               }
+       }
+
+       pthread_cancel(tid);
+       pthread_join(tid, NULL);
+
+       return ret;
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to