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 | |
---|
16 | const char rtems_test_name[] = "SP 51"; |
---|
17 | |
---|
18 | /* forward declarations to avoid warnings */ |
---|
19 | rtems_task Init(rtems_task_argument argument); |
---|
20 | |
---|
21 | static void test_create_initially_locked_prio_inherit_sema(void) |
---|
22 | { |
---|
23 | rtems_status_code sc; |
---|
24 | rtems_id id; |
---|
25 | rtems_task_priority prio_a; |
---|
26 | rtems_task_priority prio_b; |
---|
27 | rtems_task_priority prio_ceiling = 0; |
---|
28 | |
---|
29 | sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio_a); |
---|
30 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
31 | |
---|
32 | rtems_test_assert(prio_a != prio_ceiling); |
---|
33 | |
---|
34 | sc = rtems_semaphore_create( |
---|
35 | rtems_build_name( 'S', 'E', 'M', 'A' ), |
---|
36 | 0, |
---|
37 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY, |
---|
38 | prio_ceiling, |
---|
39 | &id |
---|
40 | ); |
---|
41 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
42 | |
---|
43 | sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio_b); |
---|
44 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
45 | |
---|
46 | rtems_test_assert(prio_a == prio_b); |
---|
47 | |
---|
48 | sc = rtems_semaphore_release(id); |
---|
49 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
50 | |
---|
51 | sc = rtems_semaphore_delete(id); |
---|
52 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
53 | } |
---|
54 | |
---|
55 | rtems_task Init( |
---|
56 | rtems_task_argument argument |
---|
57 | ) |
---|
58 | { |
---|
59 | rtems_status_code sc; |
---|
60 | rtems_id mutex; |
---|
61 | |
---|
62 | TEST_BEGIN(); |
---|
63 | |
---|
64 | puts( "Create semaphore - priority ceiling unlocked - invalid ceiling" ); |
---|
65 | sc = rtems_semaphore_create( |
---|
66 | rtems_build_name( 'S', 'E', 'M', '1' ), |
---|
67 | 0, |
---|
68 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY, |
---|
69 | UINT32_MAX, |
---|
70 | &mutex |
---|
71 | ); |
---|
72 | fatal_directive_status(sc, RTEMS_INVALID_PRIORITY, "rtems_semaphore_create"); |
---|
73 | |
---|
74 | puts( "Create semaphore - priority ceiling locked - violate ceiling" ); |
---|
75 | sc = rtems_semaphore_create( |
---|
76 | rtems_build_name( 'S', 'E', 'M', '1' ), |
---|
77 | 0, |
---|
78 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY, |
---|
79 | (RTEMS_MAXIMUM_PRIORITY - 4u), |
---|
80 | &mutex |
---|
81 | ); |
---|
82 | fatal_directive_status(sc, RTEMS_INVALID_PRIORITY, "rtems_semaphore_create"); |
---|
83 | |
---|
84 | puts( "Create semaphore - priority ceiling unlocked" ); |
---|
85 | sc = rtems_semaphore_create( |
---|
86 | rtems_build_name( 'S', 'E', 'M', '1' ), |
---|
87 | 1, |
---|
88 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY, |
---|
89 | (RTEMS_MAXIMUM_PRIORITY - 4u), |
---|
90 | &mutex |
---|
91 | ); |
---|
92 | directive_failed( sc, "rtems_semaphore_create" ); |
---|
93 | |
---|
94 | puts( "Obtain semaphore -- violate ceiling" ); |
---|
95 | sc = rtems_semaphore_obtain( mutex, RTEMS_DEFAULT_OPTIONS, 0 ); |
---|
96 | fatal_directive_status( |
---|
97 | sc, RTEMS_INVALID_PRIORITY, "rtems_semaphore_obtain" ); |
---|
98 | |
---|
99 | puts( "Release semaphore we did not obtain" ); |
---|
100 | sc = rtems_semaphore_release( mutex ); |
---|
101 | fatal_directive_status( |
---|
102 | sc, RTEMS_NOT_OWNER_OF_RESOURCE, "rtems_semaphore_release" ); |
---|
103 | |
---|
104 | sc = rtems_semaphore_delete( mutex ); |
---|
105 | directive_failed( sc, "rtems_semaphore_delete" ); |
---|
106 | |
---|
107 | test_create_initially_locked_prio_inherit_sema(); |
---|
108 | |
---|
109 | TEST_END(); |
---|
110 | rtems_test_exit( 0 ); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | /**************** START OF CONFIGURATION INFORMATION ****************/ |
---|
115 | |
---|
116 | #define CONFIGURE_INIT |
---|
117 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
118 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
119 | |
---|
120 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
121 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
122 | |
---|
123 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
124 | |
---|
125 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
126 | |
---|
127 | #include <rtems/confdefs.h> |
---|
128 | |
---|
129 | /**************** END OF CONFIGURATION INFORMATION ****************/ |
---|