aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-08-14 14:32:15 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2012-08-14 14:46:16 -0400
commit3445e102f16ef5ef0ae0a1c78c16a98ce3d2e5b0 (patch)
treeb2503d29e233e5f6a0ae67a8f8008cbee23333d1
parent2312a91bde3baeb226ce78c444b18eaa7f80cf34 (diff)
Add testcase for preemptions on wakeup under P-EDF and P-FP
Resuming higher-priority tasks should of course preempt lower-priority tasks. This test case infers if higher-priority tasks are unreasonably delayed.
-rw-r--r--Makefile1
-rw-r--r--include/tests.h2
-rw-r--r--tests/sched.c82
3 files changed, 85 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 391dc65..4702f6e 100644
--- a/Makefile
+++ b/Makefile
@@ -185,6 +185,7 @@ vpath %.c tests/
185 185
186src-runtests = $(wildcard tests/*.c) 186src-runtests = $(wildcard tests/*.c)
187obj-runtests = $(patsubst tests/%.c,%.o,${src-runtests}) 187obj-runtests = $(patsubst tests/%.c,%.o,${src-runtests})
188lib-runtests = -lrt
188 189
189# generate list of tests automatically 190# generate list of tests automatically
190test_catalog.inc: $(filter-out tests/runner.c,${src-runtests}) 191test_catalog.inc: $(filter-out tests/runner.c,${src-runtests})
diff --git a/include/tests.h b/include/tests.h
index 79e1575..ed2b409 100644
--- a/include/tests.h
+++ b/include/tests.h
@@ -50,4 +50,6 @@ struct testsuite {
50 50
51#define TESTCASE(function, plugins, description) void test_ ## function (void) 51#define TESTCASE(function, plugins, description) void test_ ## function (void)
52 52
53#define FORK_TASK(code) ({int __pid = fork(); if (__pid == 0) {code; exit(0);}; __pid;})
54
53#endif 55#endif
diff --git a/tests/sched.c b/tests/sched.c
new file mode 100644
index 0000000..ab47a91
--- /dev/null
+++ b/tests/sched.c
@@ -0,0 +1,82 @@
1#include <sys/wait.h> /* for waitpid() */
2#include <unistd.h>
3#include <stdio.h>
4
5#include "tests.h"
6#include "litmus.h"
7
8TESTCASE(preempt_on_resume, P_FP | PSN_EDF,
9 "preempt lower-priority task when a higher-priority task resumes")
10{
11 int child_hi, child_lo, status, waiters;
12 lt_t delay = ms2lt(100);
13 double start, stop;
14
15 struct rt_task params;
16 params.cpu = 0;
17 params.exec_cost = ms2lt(10000);
18 params.period = ms2lt(100000);
19 params.relative_deadline = params.period;
20 params.phase = 0;
21 params.cls = RT_CLASS_HARD;
22 params.budget_policy = NO_ENFORCEMENT;
23
24 child_lo = FORK_TASK(
25 params.priority = LITMUS_LOWEST_PRIORITY;
26 SYSCALL( set_rt_task_param(gettid(), &params) );
27 SYSCALL( be_migrate_to(params.cpu) );
28 SYSCALL( task_mode(LITMUS_RT_TASK) );
29
30 SYSCALL( wait_for_ts_release() );
31
32 start = cputime();
33
34 while (cputime() - start < 10)
35 ;
36
37 );
38
39 child_hi = FORK_TASK(
40 params.priority = LITMUS_HIGHEST_PRIORITY;
41 params.relative_deadline -= 1000000;
42 SYSCALL( set_rt_task_param(gettid(), &params) );
43 SYSCALL( be_migrate_to(params.cpu) );
44 SYSCALL( task_mode(LITMUS_RT_TASK) );
45
46 SYSCALL( wait_for_ts_release() );
47
48 start = cputime();
49
50 while (cputime() - start < 0.1)
51 ;
52
53 start = wctime();
54 SYSCALL( lt_sleep(ms2lt(100)) );
55 stop = wctime();
56
57 SYSCALL( kill(child_lo, SIGUSR2) );
58
59 if (stop - start >= 0.2)
60 fprintf(stderr, "\nHi-prio delay = %fsec\n",
61 stop - start - (ms2lt(100) / 1E9));
62
63 /* Assert we woke up 'soonish' after the sleep. */
64 ASSERT( stop - start < 0.2 );
65 );
66
67
68 do {
69 waiters = get_nr_ts_release_waiters();
70 ASSERT( waiters >= 0 );
71 } while (waiters != 2);
72
73 waiters = release_ts(&delay);
74
75 SYSCALL( waitpid(child_hi, &status, 0) );
76 ASSERT( status == 0 );
77
78 SYSCALL( waitpid(child_lo, &status, 0) );
79 ASSERT( status == SIGUSR2);
80}
81
82