[74db82a] | 1 | /* |
---|
| 2 | * Test for rtems_semaphore_flush |
---|
| 3 | * |
---|
[b84f1fdc] | 4 | * COPYRIGHT (c) 1989-2009. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 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.com/license/LICENSE. |
---|
| 10 | * |
---|
[74db82a] | 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include <bsp.h> |
---|
[a5e620e8] | 15 | #include <tmacros.h> |
---|
[74db82a] | 16 | |
---|
[b84f1fdc] | 17 | void starttask(int arg); |
---|
| 18 | rtems_task subtask(rtems_task_argument arg); |
---|
[74db82a] | 19 | |
---|
| 20 | #include <stdio.h> |
---|
[18ee864] | 21 | #include <stdlib.h> |
---|
[74db82a] | 22 | |
---|
| 23 | #define NTASK 4 |
---|
| 24 | |
---|
[a5e620e8] | 25 | #if defined(USE_COUNTING_SEMAPHORE) |
---|
| 26 | #define TEST_NAME "27a" |
---|
| 27 | #define TEST_SEMAPHORE_TYPE "counting" |
---|
| 28 | #define TEST_SEMAPHORE_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES |
---|
| 29 | #else |
---|
| 30 | #define TEST_NAME "27" |
---|
| 31 | #define TEST_SEMAPHORE_TYPE "binary" |
---|
| 32 | #define TEST_SEMAPHORE_ATTRIBUTES (RTEMS_LOCAL| \ |
---|
| 33 | RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY| \ |
---|
| 34 | RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO) |
---|
| 35 | #endif |
---|
| 36 | |
---|
[74db82a] | 37 | rtems_id semaphore; |
---|
| 38 | volatile int flags[NTASK]; |
---|
| 39 | |
---|
[a5e620e8] | 40 | rtems_task subtask( |
---|
| 41 | rtems_task_argument arg |
---|
| 42 | ) |
---|
[74db82a] | 43 | { |
---|
| 44 | rtems_status_code sc; |
---|
| 45 | |
---|
| 46 | for (;;) { |
---|
| 47 | flags[arg]++; |
---|
[a5e620e8] | 48 | sc = rtems_semaphore_obtain(semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
[74db82a] | 49 | if (sc == RTEMS_SUCCESSFUL) |
---|
[a5e620e8] | 50 | puts("Obtained semaphore -- and should not have done so!"); |
---|
[74db82a] | 51 | else if (sc != RTEMS_UNSATISFIED) |
---|
[a5e620e8] | 52 | printf("Can't get semaphore: %s\n", rtems_status_text(sc)); |
---|
[74db82a] | 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
[a5e620e8] | 56 | void starttask( |
---|
| 57 | int arg |
---|
| 58 | ) |
---|
[74db82a] | 59 | { |
---|
| 60 | rtems_id tid; |
---|
| 61 | rtems_status_code sc; |
---|
| 62 | rtems_task_priority priority; |
---|
| 63 | |
---|
[a5e620e8] | 64 | rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority); |
---|
| 65 | sc = rtems_task_create(rtems_build_name('S', 'R', 'V', arg + 'A'), |
---|
[74db82a] | 66 | priority, |
---|
[df49c60] | 67 | RTEMS_MINIMUM_STACK_SIZE, |
---|
[74db82a] | 68 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
| 69 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
| 70 | &tid); |
---|
[a5e620e8] | 71 | directive_failed( sc, "task create" ); |
---|
| 72 | |
---|
| 73 | sc = rtems_task_start(tid, subtask, (rtems_task_argument) arg); |
---|
| 74 | directive_failed( sc, "task start" ); |
---|
[74db82a] | 75 | } |
---|
| 76 | |
---|
[a5e620e8] | 77 | void doTest() |
---|
[74db82a] | 78 | { |
---|
| 79 | rtems_status_code sc; |
---|
[a5e620e8] | 80 | rtems_attribute attr; |
---|
| 81 | int pass, i; |
---|
[74db82a] | 82 | |
---|
[a5e620e8] | 83 | sc = rtems_semaphore_create( |
---|
| 84 | rtems_build_name('S', 'E', 'M', 'F'), |
---|
[74db82a] | 85 | 0, |
---|
[a5e620e8] | 86 | TEST_SEMAPHORE_ATTRIBUTES, |
---|
[74db82a] | 87 | 0, |
---|
| 88 | &semaphore); |
---|
[a5e620e8] | 89 | directive_failed( sc, "semaphore create" ); |
---|
| 90 | |
---|
| 91 | for (i = 0 ; i < NTASK ; i++) |
---|
| 92 | flags[i] = 0; |
---|
| 93 | |
---|
[74db82a] | 94 | for (i = 0 ; i < NTASK ; i++) |
---|
[a5e620e8] | 95 | starttask(i); |
---|
| 96 | |
---|
[74db82a] | 97 | for (pass = 1 ; pass < 10 ; pass++) { |
---|
[a5e620e8] | 98 | rtems_task_wake_after(1); |
---|
[74db82a] | 99 | for (i = 0 ; i < NTASK ; i++) { |
---|
| 100 | if (flags[i] != pass) |
---|
[a5e620e8] | 101 | printf("flags[%d] = %d -- expected %d\n", i, flags[i], pass); |
---|
[74db82a] | 102 | } |
---|
[a5e620e8] | 103 | sc = rtems_semaphore_flush(semaphore); |
---|
| 104 | directive_failed( sc, "semaphore flush" ); |
---|
[74db82a] | 105 | } |
---|
[c338ae2] | 106 | |
---|
[a5e620e8] | 107 | printf("Flushed all waiting tasks\n", NTASK ); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | rtems_task Init( |
---|
| 111 | rtems_task_argument ignored |
---|
| 112 | ) |
---|
| 113 | { |
---|
| 114 | puts( "\n\n*** TEST " TEST_NAME " ***" ); |
---|
| 115 | puts( "Testing " TEST_SEMAPHORE_TYPE " semaphore flush" ); |
---|
| 116 | doTest(); |
---|
| 117 | puts( "*** END OF TEST " TEST_NAME " ***" ); |
---|
| 118 | |
---|
| 119 | rtems_test_exit(0); |
---|
[74db82a] | 120 | } |
---|
[a5e620e8] | 121 | |
---|
| 122 | /**************** START OF CONFIGURATION INFORMATION ****************/ |
---|
| 123 | |
---|
| 124 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 125 | |
---|
| 126 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 127 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 128 | |
---|
| 129 | #define CONFIGURE_MAXIMUM_TASKS 6 |
---|
| 130 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
| 131 | |
---|
| 132 | #define CONFIGURE_INIT |
---|
| 133 | |
---|
| 134 | #include <rtems/confdefs.h> |
---|
| 135 | |
---|
| 136 | /**************** END OF CONFIGURATION INFORMATION ****************/ |
---|
| 137 | |
---|