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