Module: xenomai-jki
Branch: for-forge
Commit: 083422c5084daa4bbdbff2a3fe7c1eb59168b4a2
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=083422c5084daa4bbdbff2a3fe7c1eb59168b4a2

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Mon Feb 29 16:54:26 2016 +0100

testsuite/smokey: Add test case for setschedparam & Co,

This performs basic checks on the correct execution of scheduling
parameter changes from primary mode.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 configure.ac                          |    1 +
 testsuite/smokey/Makefile.am          |    1 +
 testsuite/smokey/setsched/Makefile.am |    9 +++
 testsuite/smokey/setsched/setsched.c  |  137 +++++++++++++++++++++++++++++++++
 4 files changed, 148 insertions(+)

diff --git a/configure.ac b/configure.ac
index 42f2f5d..9680edb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -914,6 +914,7 @@ AC_CONFIG_FILES([ \
        testsuite/smokey/arith/Makefile \
        testsuite/smokey/sched-quota/Makefile \
        testsuite/smokey/sched-tp/Makefile \
+       testsuite/smokey/setsched/Makefile \
        testsuite/smokey/rtdm/Makefile \
        testsuite/smokey/vdso-access/Makefile \
        testsuite/smokey/posix-cond/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 51292f1..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -24,6 +24,7 @@ COBALT_SUBDIRS =      \
        rtdm            \
        sched-quota     \
        sched-tp        \
+       setsched        \
        sigdebug        \
        timerfd         \
        tsc             \
diff --git a/testsuite/smokey/setsched/Makefile.am 
b/testsuite/smokey/setsched/Makefile.am
new file mode 100644
index 0000000..8c0a59b
--- /dev/null
+++ b/testsuite/smokey/setsched/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_LIBRARIES = libsetsched.a
+
+libsetsched_a_SOURCES = setsched.c
+
+libsetsched_a_CPPFLAGS =       \
+       @XENO_USER_CFLAGS@      \
+       -I$(top_srcdir)         \
+       -I$(top_srcdir)/include
diff --git a/testsuite/smokey/setsched/setsched.c 
b/testsuite/smokey/setsched/setsched.c
new file mode 100644
index 0000000..359f190
--- /dev/null
+++ b/testsuite/smokey/setsched/setsched.c
@@ -0,0 +1,137 @@
+/*
+ * Scheduler live-adjustment test.
+ *
+ * Copyright (c) Siemens AG 2016
+ *
+ * Authors:
+ *  Jan Kiszka <jan.kis...@siemens.com>
+ *
+ * Released under the terms of GPLv2.
+ */
+#include <stdio.h>
+#include <stdbool.h>
+#include <pthread.h>
+#include <error.h>
+#include <semaphore.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <smokey/smokey.h>
+#include <sys/cobalt.h>
+
+smokey_test_plugin(setsched, SMOKEY_NOARGS,
+   "Validate correct application of scheduling parameters to running threads."
+);
+
+static pid_t thread_pid;
+
+static void __check_linux_schedparams(int expected_policy, int expected_prio,
+                                     int line)
+{
+       struct sched_param linux_param;
+       int linux_policy;
+
+       linux_policy = syscall(SYS_sched_getscheduler, thread_pid);
+       if (smokey_check_status(syscall(SYS_sched_getparam, thread_pid,
+                                       &linux_param)))
+               pthread_exit((void *)(long)-EINVAL);
+
+       if (!smokey_assert(linux_policy == expected_policy) ||
+           !smokey_assert(linux_param.sched_priority == expected_prio)) {
+               smokey_warning("called from line %d", line);
+               pthread_exit((void *)(long)-EINVAL);
+       }
+}
+
+#define check_linux_schedparams(pol, prio)     \
+       __check_linux_schedparams(pol, prio, __LINE__)
+
+static void __check_rt_schedparams(int expected_policy, int expected_prio,
+                                  int line)
+{
+       struct sched_param cobalt_param;
+       int cobalt_policy;
+
+       if (smokey_check_status(pthread_getschedparam(pthread_self(),
+                                                     &cobalt_policy,
+                                                     &cobalt_param)))
+               pthread_exit((void *)(long)-EINVAL);
+
+       if (!smokey_assert(cobalt_policy == expected_policy) ||
+           !smokey_assert(cobalt_param.sched_priority == expected_prio)) {
+               smokey_warning("called from line %d", line);
+               pthread_exit((void *)(long)-EINVAL);
+       }
+}
+
+#define check_rt_schedparams(pol, prio)        \
+       __check_rt_schedparams(pol, prio, __LINE__)
+
+static void *thread_body(void *arg)
+{
+       struct cobalt_threadstat stats;
+       struct sched_param param;
+       unsigned long long msw;
+
+       thread_pid = syscall(SYS_gettid);
+
+       check_rt_schedparams(SCHED_FIFO, 1);
+       check_linux_schedparams(SCHED_FIFO, 1);
+
+       if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+               pthread_exit((void *)(long)-EINVAL);
+       msw = stats.msw;
+
+       param.sched_priority = 2;
+       if (smokey_check_status(pthread_setschedparam(pthread_self(),
+                                                     SCHED_FIFO, &param)))
+               pthread_exit((void *)(long)-EINVAL);
+
+       check_rt_schedparams(SCHED_FIFO, 2);
+
+       if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)) ||
+           !smokey_assert(stats.msw == msw))
+               pthread_exit((void *)(long)-EINVAL);
+
+       check_linux_schedparams(SCHED_FIFO, 2);
+
+       cobalt_thread_harden();
+
+       if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+               pthread_exit((void *)(long)-EINVAL);
+       msw = stats.msw;
+
+       if (smokey_check_status(pthread_setschedprio(pthread_self(), 3)))
+               pthread_exit((void *)(long)-EINVAL);
+
+       check_rt_schedparams(SCHED_FIFO, 3);
+
+       if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)) ||
+           !smokey_assert(stats.msw == msw))
+               pthread_exit((void *)(long)-EINVAL);
+
+       check_linux_schedparams(SCHED_FIFO, 3);
+
+       return (void *)0L;
+}
+
+static int run_setsched(struct smokey_test *t, int argc, char *const argv[])
+{
+       struct sched_param param;
+       pthread_attr_t attr;
+       pthread_t thread;
+       void *retval;
+       int ret;
+
+       pthread_attr_init(&attr);
+       pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+       pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+       param.sched_priority = 1;
+       pthread_attr_setschedparam(&attr, &param);
+       ret = pthread_create(&thread, &attr, thread_body, NULL);
+       if (ret)
+               error(1, ret, "pthread_create");
+
+       pthread_join(thread, &retval);
+
+       return (long)retval;
+}


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

Reply via email to