1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * Copyright (c) 2013 embedded brains GmbH. |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <tmacros.h> |
---|
17 | #include <intrcritical.h> |
---|
18 | |
---|
19 | #include <rtems/rtems/eventimpl.h> |
---|
20 | |
---|
21 | const char rtems_test_name[] = "SPINTRCRITICAL 10"; |
---|
22 | |
---|
23 | #define GREEN RTEMS_EVENT_0 |
---|
24 | |
---|
25 | #define RED RTEMS_EVENT_1 |
---|
26 | |
---|
27 | #define EVENTS (GREEN | RED) |
---|
28 | |
---|
29 | #define DEADBEEF 0xdeadbeef |
---|
30 | |
---|
31 | typedef struct { |
---|
32 | rtems_id timer; |
---|
33 | Thread_Control *thread; |
---|
34 | bool hit; |
---|
35 | } test_context; |
---|
36 | |
---|
37 | static void any_satisfy_before_timeout(rtems_id timer, void *arg) |
---|
38 | { |
---|
39 | rtems_status_code sc; |
---|
40 | test_context *ctx = arg; |
---|
41 | const Thread_Control *thread = ctx->thread; |
---|
42 | |
---|
43 | if (thread->Wait.count != 0) { |
---|
44 | ctx->hit = _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED; |
---|
45 | |
---|
46 | rtems_test_assert(thread->Wait.count == EVENTS); |
---|
47 | rtems_test_assert( |
---|
48 | *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF |
---|
49 | ); |
---|
50 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
51 | |
---|
52 | sc = rtems_event_send(thread->Object.id, GREEN); |
---|
53 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
54 | |
---|
55 | rtems_test_assert(thread->Wait.count == 0); |
---|
56 | rtems_test_assert( |
---|
57 | *(rtems_event_set *) thread->Wait.return_argument == GREEN |
---|
58 | ); |
---|
59 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
60 | |
---|
61 | sc = rtems_event_send(thread->Object.id, RED); |
---|
62 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
63 | |
---|
64 | rtems_test_assert(thread->Wait.count == 0); |
---|
65 | rtems_test_assert( |
---|
66 | *(rtems_event_set *) thread->Wait.return_argument == GREEN |
---|
67 | ); |
---|
68 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
69 | |
---|
70 | _Event_Timeout(thread->Object.id, &_Event_Sync_state); |
---|
71 | |
---|
72 | rtems_test_assert(thread->Wait.count == 0); |
---|
73 | rtems_test_assert( |
---|
74 | *(rtems_event_set *) thread->Wait.return_argument == GREEN |
---|
75 | ); |
---|
76 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
77 | |
---|
78 | if (ctx->hit) { |
---|
79 | rtems_test_assert( |
---|
80 | _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED |
---|
81 | ); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | sc = rtems_timer_reset(timer); |
---|
86 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
87 | } |
---|
88 | |
---|
89 | static bool test_body_any_satisfy_before_timeout(void *arg) |
---|
90 | { |
---|
91 | test_context *ctx = arg; |
---|
92 | rtems_status_code sc; |
---|
93 | rtems_event_set out; |
---|
94 | |
---|
95 | out = DEADBEEF; |
---|
96 | sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ANY | RTEMS_WAIT, 1, &out); |
---|
97 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
98 | rtems_test_assert(out == GREEN); |
---|
99 | |
---|
100 | out = DEADBEEF; |
---|
101 | sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, 0, &out); |
---|
102 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
103 | rtems_test_assert(out == RED); |
---|
104 | |
---|
105 | return ctx->hit; |
---|
106 | } |
---|
107 | |
---|
108 | static void test_any_satisfy_before_timeout(test_context *ctx) |
---|
109 | { |
---|
110 | rtems_status_code sc; |
---|
111 | |
---|
112 | puts( |
---|
113 | "Init - Trying to generate any satisfied before timeout " |
---|
114 | "while blocking on event" |
---|
115 | ); |
---|
116 | |
---|
117 | ctx->hit = false; |
---|
118 | ctx->thread->Wait.count = 0; |
---|
119 | |
---|
120 | sc = rtems_timer_fire_after(ctx->timer, 1, any_satisfy_before_timeout, ctx); |
---|
121 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
122 | |
---|
123 | interrupt_critical_section_test( |
---|
124 | test_body_any_satisfy_before_timeout, |
---|
125 | ctx, |
---|
126 | NULL |
---|
127 | ); |
---|
128 | |
---|
129 | sc = rtems_timer_cancel(ctx->timer); |
---|
130 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
131 | |
---|
132 | rtems_test_assert(ctx->hit); |
---|
133 | } |
---|
134 | |
---|
135 | static void all_satisfy_before_timeout(rtems_id timer, void *arg) |
---|
136 | { |
---|
137 | rtems_status_code sc; |
---|
138 | test_context *ctx = arg; |
---|
139 | const Thread_Control *thread = ctx->thread; |
---|
140 | |
---|
141 | if (thread->Wait.count != 0) { |
---|
142 | ctx->hit = _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED; |
---|
143 | |
---|
144 | rtems_test_assert(thread->Wait.count == EVENTS); |
---|
145 | rtems_test_assert( |
---|
146 | *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF |
---|
147 | ); |
---|
148 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
149 | |
---|
150 | sc = rtems_event_send(thread->Object.id, GREEN); |
---|
151 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
152 | |
---|
153 | rtems_test_assert(thread->Wait.count == EVENTS); |
---|
154 | rtems_test_assert( |
---|
155 | *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF |
---|
156 | ); |
---|
157 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
158 | |
---|
159 | sc = rtems_event_send(thread->Object.id, RED); |
---|
160 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
161 | |
---|
162 | rtems_test_assert(thread->Wait.count == 0); |
---|
163 | rtems_test_assert( |
---|
164 | *(rtems_event_set *) thread->Wait.return_argument == EVENTS |
---|
165 | ); |
---|
166 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
167 | |
---|
168 | _Event_Timeout(thread->Object.id, &_Event_Sync_state); |
---|
169 | |
---|
170 | rtems_test_assert(thread->Wait.count == 0); |
---|
171 | rtems_test_assert( |
---|
172 | *(rtems_event_set *) thread->Wait.return_argument == EVENTS |
---|
173 | ); |
---|
174 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
175 | |
---|
176 | if (ctx->hit) { |
---|
177 | rtems_test_assert( |
---|
178 | _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED |
---|
179 | ); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | sc = rtems_timer_reset(timer); |
---|
184 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
185 | } |
---|
186 | |
---|
187 | static bool test_body_all_satisfy_before_timeout(void *arg) |
---|
188 | { |
---|
189 | test_context *ctx = arg; |
---|
190 | rtems_status_code sc; |
---|
191 | rtems_event_set out; |
---|
192 | |
---|
193 | out = DEADBEEF; |
---|
194 | sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ALL | RTEMS_WAIT, 1, &out); |
---|
195 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
196 | rtems_test_assert(out == EVENTS); |
---|
197 | |
---|
198 | return ctx->hit; |
---|
199 | } |
---|
200 | |
---|
201 | static void test_all_satisfy_before_timeout(test_context *ctx) |
---|
202 | { |
---|
203 | rtems_status_code sc; |
---|
204 | |
---|
205 | puts( |
---|
206 | "Init - Trying to generate all satisfied before timeout " |
---|
207 | "while blocking on event" |
---|
208 | ); |
---|
209 | |
---|
210 | ctx->hit = false; |
---|
211 | ctx->thread->Wait.count = 0; |
---|
212 | |
---|
213 | sc = rtems_timer_fire_after(ctx->timer, 1, all_satisfy_before_timeout, ctx); |
---|
214 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
215 | |
---|
216 | interrupt_critical_section_test( |
---|
217 | test_body_all_satisfy_before_timeout, |
---|
218 | ctx, |
---|
219 | NULL |
---|
220 | ); |
---|
221 | |
---|
222 | sc = rtems_timer_cancel(ctx->timer); |
---|
223 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
224 | |
---|
225 | rtems_test_assert(ctx->hit); |
---|
226 | } |
---|
227 | |
---|
228 | static void timeout_before_satisfied(rtems_id timer, void *arg) |
---|
229 | { |
---|
230 | rtems_status_code sc; |
---|
231 | test_context *ctx = arg; |
---|
232 | const Thread_Control *thread = ctx->thread; |
---|
233 | |
---|
234 | if (thread->Wait.count != 0) { |
---|
235 | ctx->hit = |
---|
236 | _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED; |
---|
237 | |
---|
238 | rtems_test_assert(thread->Wait.count == EVENTS); |
---|
239 | rtems_test_assert( |
---|
240 | *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF |
---|
241 | ); |
---|
242 | rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL); |
---|
243 | |
---|
244 | _Event_Timeout(thread->Object.id, &_Event_Sync_state); |
---|
245 | |
---|
246 | rtems_test_assert(thread->Wait.count == 0); |
---|
247 | rtems_test_assert( |
---|
248 | *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF |
---|
249 | ); |
---|
250 | rtems_test_assert(thread->Wait.return_code == RTEMS_TIMEOUT); |
---|
251 | |
---|
252 | sc = rtems_event_send(thread->Object.id, EVENTS); |
---|
253 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
254 | |
---|
255 | rtems_test_assert(thread->Wait.count == 0); |
---|
256 | rtems_test_assert( |
---|
257 | *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF |
---|
258 | ); |
---|
259 | rtems_test_assert(thread->Wait.return_code == RTEMS_TIMEOUT); |
---|
260 | |
---|
261 | if (ctx->hit) { |
---|
262 | rtems_test_assert( |
---|
263 | _Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT |
---|
264 | ); |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | sc = rtems_timer_reset(timer); |
---|
269 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
270 | } |
---|
271 | |
---|
272 | static bool test_body_timeout_before_all_satisfy(void *arg) |
---|
273 | { |
---|
274 | test_context *ctx = arg; |
---|
275 | rtems_event_set out; |
---|
276 | rtems_status_code sc; |
---|
277 | |
---|
278 | out = DEADBEEF; |
---|
279 | sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ALL | RTEMS_WAIT, 1, &out); |
---|
280 | rtems_test_assert(sc == RTEMS_TIMEOUT); |
---|
281 | rtems_test_assert(out == DEADBEEF); |
---|
282 | |
---|
283 | out = DEADBEEF; |
---|
284 | sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ALL | RTEMS_NO_WAIT, 0, &out); |
---|
285 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
286 | rtems_test_assert(out == EVENTS); |
---|
287 | |
---|
288 | return ctx->hit; |
---|
289 | } |
---|
290 | |
---|
291 | static void test_timeout_before_all_satisfy(test_context *ctx) |
---|
292 | { |
---|
293 | rtems_status_code sc; |
---|
294 | |
---|
295 | puts( |
---|
296 | "Init - Trying to generate timeout before all satisfied " |
---|
297 | "while blocking on event" |
---|
298 | ); |
---|
299 | |
---|
300 | ctx->hit = false; |
---|
301 | ctx->thread->Wait.count = 0; |
---|
302 | |
---|
303 | sc = rtems_timer_fire_after(ctx->timer, 1, timeout_before_satisfied, ctx); |
---|
304 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
305 | |
---|
306 | interrupt_critical_section_test( |
---|
307 | test_body_timeout_before_all_satisfy, |
---|
308 | ctx, |
---|
309 | NULL |
---|
310 | ); |
---|
311 | |
---|
312 | sc = rtems_timer_cancel(ctx->timer); |
---|
313 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
314 | |
---|
315 | rtems_test_assert(ctx->hit); |
---|
316 | } |
---|
317 | |
---|
318 | static rtems_task Init( |
---|
319 | rtems_task_argument ignored |
---|
320 | ) |
---|
321 | { |
---|
322 | rtems_status_code sc; |
---|
323 | test_context ctx = { |
---|
324 | .thread = _Thread_Get_executing() |
---|
325 | }; |
---|
326 | |
---|
327 | TEST_BEGIN(); |
---|
328 | |
---|
329 | sc = rtems_timer_create(rtems_build_name('T', 'I', 'M', 'R'), &ctx.timer); |
---|
330 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
331 | |
---|
332 | test_any_satisfy_before_timeout(&ctx); |
---|
333 | test_all_satisfy_before_timeout(&ctx); |
---|
334 | test_timeout_before_all_satisfy(&ctx); |
---|
335 | |
---|
336 | TEST_END(); |
---|
337 | rtems_test_exit(0); |
---|
338 | } |
---|
339 | |
---|
340 | /* configuration information */ |
---|
341 | |
---|
342 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
343 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
344 | |
---|
345 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
346 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
347 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
348 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
349 | |
---|
350 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
351 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
352 | |
---|
353 | #define CONFIGURE_INIT |
---|
354 | #include <rtems/confdefs.h> |
---|