diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-14 14:32:15 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-14 14:46:16 -0400 |
commit | 3445e102f16ef5ef0ae0a1c78c16a98ce3d2e5b0 (patch) | |
tree | b2503d29e233e5f6a0ae67a8f8008cbee23333d1 /tests | |
parent | 2312a91bde3baeb226ce78c444b18eaa7f80cf34 (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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sched.c | 82 |
1 files changed, 82 insertions, 0 deletions
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 | |||
8 | TESTCASE(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(), ¶ms) ); | ||
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(), ¶ms) ); | ||
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 | |||