Commit 3010b7cc authored by Jan Kiszka's avatar Jan Kiszka Committed by Philippe Gerum

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's avatarJan Kiszka <jan.kiszka@siemens.com>
parent ff70dfde
......@@ -882,6 +882,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 \
......
......@@ -23,6 +23,7 @@ COBALT_SUBDIRS = \
rtdm \
sched-quota \
sched-tp \
setsched \
sigdebug \
timerfd \
tsc \
......
noinst_LIBRARIES = libsetsched.a
libsetsched_a_SOURCES = setsched.c
libsetsched_a_CPPFLAGS = \
@XENO_USER_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/include
/*
* Scheduler live-adjustment test.
*
* Copyright (c) Siemens AG 2016
*
* Authors:
* Jan Kiszka <jan.kiszka@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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment