From 4928cb8f9b596dde0f977bd8924a28dd38541f5f Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Sat, 8 Jun 2013 20:05:29 +0200 Subject: Add testcase for admission of suspended tasks The kernel needs to be able to deal with tasks that do not make themselves a real-time task, but get configured by some other task instead. --- include/litmus.h | 2 ++ src/task.c | 1 - tests/core_api.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/include/litmus.h b/include/litmus.h index 1009805..ef3fef3 100644 --- a/include/litmus.h +++ b/include/litmus.h @@ -18,6 +18,8 @@ extern "C" { #include "migration.h" +#define SCHED_LITMUS 6 + void init_rt_task_param(struct rt_task* param); int set_rt_task_param(pid_t pid, struct rt_task* param); int get_rt_task_param(pid_t pid, struct rt_task* param); diff --git a/src/task.c b/src/task.c index 9121f0c..5f2fa26 100644 --- a/src/task.c +++ b/src/task.c @@ -66,7 +66,6 @@ int create_rt_task(rt_fn_t rt_prog, void *arg, int cluster, int cluster_size, #define SCHED_NORMAL 0 -#define SCHED_LITMUS 6 int task_mode(int mode) { diff --git a/tests/core_api.c b/tests/core_api.c index fc4deb9..42529ce 100644 --- a/tests/core_api.c +++ b/tests/core_api.c @@ -1,6 +1,8 @@ #include /* for waitpid() */ #include #include +#include +#include #include "tests.h" #include "litmus.h" @@ -169,3 +171,61 @@ TESTCASE(ctrl_page_writable, ALL, ctrl_page[32] = 0x12345678; } + + +TESTCASE(suspended_admission, LITMUS, + "admission control handles suspended tasks correctly") +{ + int child_rt, status; + struct sched_param param; + + int pipefd[2], err, token = 0; + struct rt_task params; + + SYSCALL( pipe(pipefd) ); + + child_rt = FORK_TASK( + child_rt = gettid(); + /* make sure we are on the right CPU */ + be_migrate_to_cpu(0); + + /* carry out a blocking read to suspend */ + err = read(pipefd[0], &token, sizeof(token)); + ASSERT(err = sizeof(token)); + ASSERT(token == 1234); + + /* when we wake up, we should be a real-time task */ + ASSERT( sched_getscheduler(child_rt) == SCHED_LITMUS ); + + SYSCALL( sleep_next_period() ); + SYSCALL( sleep_next_period() ); + + exit(0); + ); + + /* give child some time to suspend */ + SYSCALL( lt_sleep(ms2ns(100)) ); + + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10); + params.period = ms2ns(100); + + /* configure parameters of child */ + SYSCALL( set_rt_task_param(child_rt, ¶ms) ); + + /* make it a real-time task */ + param.sched_priority = 0; + SYSCALL( sched_setscheduler(child_rt, SCHED_LITMUS, ¶m) ); + + /* should be a real-time task now */ + ASSERT( sched_getscheduler(child_rt) == SCHED_LITMUS ); + + /* unblock it */ + token = 1234; + ASSERT( write(pipefd[1], &token, sizeof(token)) == sizeof(token) ); + + /* wait for child to exit */ + SYSCALL( waitpid(child_rt, &status, 0) ); + ASSERT( status == 0 ); +} -- cgit v1.2.2