1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include <unistd.h> |
---|
16 | |
---|
17 | /* forward declarations to avoid warnings */ |
---|
18 | rtems_task Init(rtems_task_argument argument); |
---|
19 | rtems_task Task_1(rtems_task_argument arg); |
---|
20 | |
---|
21 | #if defined(INHERIT_CEILING) |
---|
22 | #define TEST_NAME "66" |
---|
23 | #define TASK_PRIORITY 2 |
---|
24 | #else |
---|
25 | #define TEST_NAME "65" |
---|
26 | #define TASK_PRIORITY 1 |
---|
27 | #endif |
---|
28 | |
---|
29 | const char rtems_test_name[] = "SP " TEST_NAME; |
---|
30 | |
---|
31 | static void assert_priority(rtems_task_priority expected) |
---|
32 | { |
---|
33 | rtems_status_code sc; |
---|
34 | rtems_task_priority prio; |
---|
35 | |
---|
36 | sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio); |
---|
37 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
38 | |
---|
39 | rtems_test_assert(prio == expected); |
---|
40 | } |
---|
41 | |
---|
42 | rtems_task Init( |
---|
43 | rtems_task_argument ignored |
---|
44 | ) |
---|
45 | { |
---|
46 | int status; |
---|
47 | rtems_id Mutex_id, Task_id; |
---|
48 | |
---|
49 | TEST_BEGIN(); |
---|
50 | |
---|
51 | /* |
---|
52 | * Verify that an initially locked priority ceiling mutex elevates the |
---|
53 | * priority of the creating task. |
---|
54 | */ |
---|
55 | |
---|
56 | status = rtems_semaphore_create( |
---|
57 | rtems_build_name( 's','e','m','1' ), |
---|
58 | 0, |
---|
59 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING, |
---|
60 | 1, |
---|
61 | &Mutex_id |
---|
62 | ); |
---|
63 | rtems_test_assert(status == RTEMS_SUCCESSFUL); |
---|
64 | |
---|
65 | assert_priority(1); |
---|
66 | |
---|
67 | status = rtems_semaphore_release(Mutex_id); |
---|
68 | rtems_test_assert(status == RTEMS_SUCCESSFUL); |
---|
69 | |
---|
70 | assert_priority(TASK_PRIORITY); |
---|
71 | |
---|
72 | status = rtems_semaphore_delete(Mutex_id); |
---|
73 | rtems_test_assert(status == RTEMS_SUCCESSFUL); |
---|
74 | |
---|
75 | /* |
---|
76 | * Create binary semaphore (a.k.a. Mutex) with Priority Ceiling |
---|
77 | * attribute. |
---|
78 | */ |
---|
79 | |
---|
80 | puts( "Creating semaphore" ); |
---|
81 | status = rtems_semaphore_create( |
---|
82 | rtems_build_name( 's','e','m','1' ), |
---|
83 | 1, |
---|
84 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING, |
---|
85 | 1, |
---|
86 | &Mutex_id |
---|
87 | ); |
---|
88 | directive_failed( status, "rtems_semaphore_create" ); |
---|
89 | |
---|
90 | puts( "Calling rtems_semaphore_obtain" ); |
---|
91 | status = rtems_semaphore_obtain( Mutex_id, RTEMS_DEFAULT_OPTIONS, 0 ); |
---|
92 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
93 | |
---|
94 | puts( "Calling rtems_task_create" ); |
---|
95 | status = rtems_task_create( rtems_build_name( 'T', 'A', 'S', '1' ), |
---|
96 | TASK_PRIORITY, |
---|
97 | RTEMS_MINIMUM_STACK_SIZE, |
---|
98 | RTEMS_DEFAULT_MODES, |
---|
99 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
100 | &Task_id |
---|
101 | ); |
---|
102 | directive_failed( status, "rtems_task_create" ); |
---|
103 | |
---|
104 | puts( "Calling rtems_task_start" ); |
---|
105 | status = rtems_task_start( Task_id, Task_1, (rtems_task_argument)&Mutex_id ); |
---|
106 | directive_failed( status, "rtems_task_start" ); |
---|
107 | |
---|
108 | sleep(1); |
---|
109 | |
---|
110 | puts( "Calling semaphore release" ); |
---|
111 | status = rtems_semaphore_release( Mutex_id ); |
---|
112 | directive_failed( status, "rtems_semaphore_release" ); |
---|
113 | |
---|
114 | TEST_END(); |
---|
115 | |
---|
116 | rtems_test_exit(0); |
---|
117 | } |
---|
118 | |
---|
119 | rtems_task Task_1( |
---|
120 | rtems_task_argument arg |
---|
121 | ) |
---|
122 | { |
---|
123 | int status_in_task; |
---|
124 | rtems_id *Mutex_id = (rtems_id *)arg; |
---|
125 | |
---|
126 | puts( "Init Task_1: Obtaining semaphore" ); |
---|
127 | status_in_task = rtems_semaphore_obtain( |
---|
128 | *Mutex_id, |
---|
129 | RTEMS_DEFAULT_OPTIONS, |
---|
130 | 0 |
---|
131 | ); |
---|
132 | directive_failed( status_in_task, "Task_1 rtems_semaphore_obtain" ); |
---|
133 | return; |
---|
134 | } |
---|
135 | |
---|
136 | /* configuration information */ |
---|
137 | |
---|
138 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
139 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
140 | |
---|
141 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
142 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
143 | #define CONFIGURE_INIT_TASK_PRIORITY TASK_PRIORITY |
---|
144 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
145 | |
---|
146 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
147 | |
---|
148 | #define CONFIGURE_INIT |
---|
149 | #include <rtems/confdefs.h> |
---|
150 | |
---|
151 | /* global variables */ |
---|