diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-01-11 05:00:30 -0500 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-01-11 06:36:50 -0500 |
commit | 916c8dfde6a4ee5b86af4d4db882c05c6bb08e9b (patch) | |
tree | 999bc71eb6238164f0e72a836676c2a9cee37d96 /tests | |
parent | 102b50373d656e42abbd1c953ce908e52f6e8706 (diff) |
Add tests for PCP/SRP ceiling blocking
Context: priority inheritance triggered a BUG_ON() in fp_common.c.
While at it, add a similar test for the SRP.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pcp.c | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/tests/pcp.c b/tests/pcp.c index 88d1be3..52ee959 100644 --- a/tests/pcp.c +++ b/tests/pcp.c | |||
@@ -1,6 +1,8 @@ | |||
1 | #include <fcntl.h> | 1 | #include <fcntl.h> |
2 | #include <unistd.h> | 2 | #include <unistd.h> |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <sys/wait.h> /* for waitpid() */ | ||
5 | |||
4 | 6 | ||
5 | #include "tests.h" | 7 | #include "tests.h" |
6 | #include "litmus.h" | 8 | #include "litmus.h" |
@@ -37,6 +39,212 @@ TESTCASE(lock_pcp, P_FP, | |||
37 | SYSCALL( remove(".pcp_locks") ); | 39 | SYSCALL( remove(".pcp_locks") ); |
38 | } | 40 | } |
39 | 41 | ||
42 | TESTCASE(pcp_inheritance, P_FP, | ||
43 | "PCP priority inheritance") | ||
44 | { | ||
45 | int fd, od, cpu = 0; | ||
46 | |||
47 | int child_hi, child_lo, child_middle, status, waiters; | ||
48 | lt_t delay = ms2lt(100); | ||
49 | double start, stop; | ||
50 | |||
51 | struct rt_task params; | ||
52 | params.cpu = 0; | ||
53 | params.exec_cost = ms2lt(10000); | ||
54 | params.period = ms2lt(100000); | ||
55 | params.relative_deadline = params.period; | ||
56 | params.phase = 0; | ||
57 | params.cls = RT_CLASS_HARD; | ||
58 | params.budget_policy = NO_ENFORCEMENT; | ||
59 | |||
60 | SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) ); | ||
61 | |||
62 | |||
63 | child_lo = FORK_TASK( | ||
64 | params.priority = LITMUS_LOWEST_PRIORITY; | ||
65 | params.phase = 0; | ||
66 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
67 | SYSCALL( be_migrate_to(params.cpu) ); | ||
68 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
69 | |||
70 | SYSCALL( od = open_pcp_sem(fd, 0, cpu) ); | ||
71 | |||
72 | SYSCALL( wait_for_ts_release() ); | ||
73 | |||
74 | SYSCALL( litmus_lock(od) ); | ||
75 | start = cputime(); | ||
76 | while (cputime() - start < 0.25) | ||
77 | ; | ||
78 | SYSCALL( litmus_unlock(od) ); | ||
79 | |||
80 | SYSCALL(sleep_next_period() ); | ||
81 | ); | ||
82 | |||
83 | child_middle = FORK_TASK( | ||
84 | params.priority = LITMUS_HIGHEST_PRIORITY + 1; | ||
85 | params.phase = ms2lt(100); | ||
86 | |||
87 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
88 | SYSCALL( be_migrate_to(params.cpu) ); | ||
89 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
90 | |||
91 | |||
92 | SYSCALL( wait_for_ts_release() ); | ||
93 | |||
94 | start = cputime(); | ||
95 | while (cputime() - start < 5) | ||
96 | ; | ||
97 | SYSCALL( sleep_next_period() ); | ||
98 | ); | ||
99 | |||
100 | child_hi = FORK_TASK( | ||
101 | params.priority = LITMUS_HIGHEST_PRIORITY; | ||
102 | params.phase = ms2lt(50); | ||
103 | |||
104 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
105 | SYSCALL( be_migrate_to(params.cpu) ); | ||
106 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
107 | |||
108 | SYSCALL( od = open_pcp_sem(fd, 0, cpu) ); | ||
109 | |||
110 | SYSCALL( wait_for_ts_release() ); | ||
111 | |||
112 | start = wctime(); | ||
113 | /* block on semaphore */ | ||
114 | SYSCALL( litmus_lock(od) ); | ||
115 | SYSCALL( litmus_unlock(od) ); | ||
116 | stop = wctime(); | ||
117 | |||
118 | /* Assert we had some blocking. */ | ||
119 | ASSERT( stop - start > 0.1); | ||
120 | |||
121 | /* Assert we woke up 'soonish' after the sleep. */ | ||
122 | ASSERT( stop - start < 1 ); | ||
123 | |||
124 | SYSCALL( kill(child_middle, SIGUSR2) ); | ||
125 | SYSCALL( kill(child_lo, SIGUSR2) ); | ||
126 | ); | ||
127 | |||
128 | do { | ||
129 | waiters = get_nr_ts_release_waiters(); | ||
130 | ASSERT( waiters >= 0 ); | ||
131 | } while (waiters != 3); | ||
132 | |||
133 | SYSCALL( be_migrate_to(1) ); | ||
134 | |||
135 | waiters = release_ts(&delay); | ||
136 | |||
137 | SYSCALL( waitpid(child_hi, &status, 0) ); | ||
138 | ASSERT( status == 0 ); | ||
139 | |||
140 | SYSCALL( waitpid(child_lo, &status, 0) ); | ||
141 | ASSERT( status == SIGUSR2); | ||
142 | |||
143 | SYSCALL( waitpid(child_middle, &status, 0) ); | ||
144 | ASSERT( status == SIGUSR2); | ||
145 | } | ||
146 | |||
147 | TESTCASE(srp_ceiling_blocking, P_FP | PSN_EDF, | ||
148 | "SRP ceiling blocking") | ||
149 | { | ||
150 | int fd, od; | ||
151 | |||
152 | int child_hi, child_lo, child_middle, status, waiters; | ||
153 | lt_t delay = ms2lt(100); | ||
154 | double start, stop; | ||
155 | |||
156 | struct rt_task params; | ||
157 | params.cpu = 0; | ||
158 | params.exec_cost = ms2lt(10000); | ||
159 | params.period = ms2lt(100000); | ||
160 | params.relative_deadline = params.period; | ||
161 | params.phase = 0; | ||
162 | params.cls = RT_CLASS_HARD; | ||
163 | params.budget_policy = NO_ENFORCEMENT; | ||
164 | |||
165 | SYSCALL( fd = open(".srp_locks", O_RDONLY | O_CREAT) ); | ||
166 | |||
167 | |||
168 | child_lo = FORK_TASK( | ||
169 | params.priority = LITMUS_LOWEST_PRIORITY; | ||
170 | params.phase = 0; | ||
171 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
172 | SYSCALL( be_migrate_to(params.cpu) ); | ||
173 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
174 | |||
175 | SYSCALL( od = open_srp_sem(fd, 0) ); | ||
176 | |||
177 | SYSCALL( wait_for_ts_release() ); | ||
178 | |||
179 | SYSCALL( litmus_lock(od) ); | ||
180 | start = cputime(); | ||
181 | while (cputime() - start < 0.25) | ||
182 | ; | ||
183 | SYSCALL( litmus_unlock(od) ); | ||
184 | ); | ||
185 | |||
186 | child_middle = FORK_TASK( | ||
187 | params.priority = LITMUS_HIGHEST_PRIORITY + 1; | ||
188 | params.phase = ms2lt(100); | ||
189 | params.relative_deadline -= ms2lt(110); | ||
190 | |||
191 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
192 | SYSCALL( be_migrate_to(params.cpu) ); | ||
193 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
194 | |||
195 | |||
196 | SYSCALL( wait_for_ts_release() ); | ||
197 | |||
198 | start = cputime(); | ||
199 | while (cputime() - start < 5) | ||
200 | ; | ||
201 | ); | ||
202 | |||
203 | child_hi = FORK_TASK( | ||
204 | params.priority = LITMUS_HIGHEST_PRIORITY; | ||
205 | params.phase = ms2lt(50); | ||
206 | params.relative_deadline -= ms2lt(200); | ||
207 | |||
208 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
209 | SYSCALL( be_migrate_to(params.cpu) ); | ||
210 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
211 | |||
212 | SYSCALL( od = open_srp_sem(fd, 0) ); | ||
213 | |||
214 | SYSCALL( wait_for_ts_release() ); | ||
215 | |||
216 | start = wctime(); | ||
217 | /* block on semaphore */ | ||
218 | SYSCALL( litmus_lock(od) ); | ||
219 | SYSCALL( litmus_unlock(od) ); | ||
220 | stop = wctime(); | ||
221 | |||
222 | /* Assert we had "no" blocking (modulo qemu overheads). */ | ||
223 | ASSERT( stop - start < 0.01); | ||
224 | |||
225 | SYSCALL( kill(child_middle, SIGUSR2) ); | ||
226 | SYSCALL( kill(child_lo, SIGUSR2) ); | ||
227 | ); | ||
228 | |||
229 | do { | ||
230 | waiters = get_nr_ts_release_waiters(); | ||
231 | ASSERT( waiters >= 0 ); | ||
232 | } while (waiters != 3); | ||
233 | |||
234 | SYSCALL( be_migrate_to(1) ); | ||
235 | |||
236 | waiters = release_ts(&delay); | ||
237 | |||
238 | SYSCALL( waitpid(child_hi, &status, 0) ); | ||
239 | ASSERT( status == 0 ); | ||
240 | |||
241 | SYSCALL( waitpid(child_lo, &status, 0) ); | ||
242 | ASSERT( status == SIGUSR2); | ||
243 | |||
244 | SYSCALL( waitpid(child_middle, &status, 0) ); | ||
245 | ASSERT( status == SIGUSR2); | ||
246 | } | ||
247 | |||
40 | TESTCASE(lock_dpcp, P_FP, | 248 | TESTCASE(lock_dpcp, P_FP, |
41 | "DPCP acquisition and release") | 249 | "DPCP acquisition and release") |
42 | { | 250 | { |