1 | /* |
---|
2 | * Copyright (c) 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <errno.h> |
---|
20 | #include <pthread.h> |
---|
21 | |
---|
22 | #include <rtems.h> |
---|
23 | #include <rtems/libcsupport.h> |
---|
24 | |
---|
25 | #include "tmacros.h" |
---|
26 | |
---|
27 | const char rtems_test_name[] = "SMPPSXMUTEX 1"; |
---|
28 | |
---|
29 | #define SCHED_A rtems_build_name(' ', ' ', ' ', 'A') |
---|
30 | |
---|
31 | #define SCHED_B rtems_build_name(' ', ' ', ' ', 'B') |
---|
32 | |
---|
33 | typedef struct { |
---|
34 | pthread_t thread_b; |
---|
35 | pthread_mutexattr_t mtx_attr; |
---|
36 | pthread_mutex_t mtx_a; |
---|
37 | pthread_mutex_t mtx_b; |
---|
38 | } test_context; |
---|
39 | |
---|
40 | static test_context test_instance; |
---|
41 | |
---|
42 | static void *thread_b(void *arg) |
---|
43 | { |
---|
44 | test_context *ctx; |
---|
45 | rtems_id scheduler_b_id; |
---|
46 | rtems_status_code sc; |
---|
47 | rtems_task_priority prio; |
---|
48 | int prio_ceiling; |
---|
49 | int eno; |
---|
50 | |
---|
51 | ctx = arg; |
---|
52 | |
---|
53 | rtems_test_assert(rtems_get_current_processor() == 0); |
---|
54 | |
---|
55 | sc = rtems_scheduler_ident(SCHED_B, &scheduler_b_id); |
---|
56 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
57 | |
---|
58 | sc = rtems_task_set_priority(pthread_self(), RTEMS_CURRENT_PRIORITY, &prio); |
---|
59 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
60 | |
---|
61 | sc = rtems_task_set_scheduler(pthread_self(), scheduler_b_id, prio); |
---|
62 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
63 | |
---|
64 | rtems_test_assert(rtems_get_current_processor() == 1); |
---|
65 | |
---|
66 | eno = pthread_mutex_init(&ctx->mtx_b, &ctx->mtx_attr); |
---|
67 | rtems_test_assert(eno == 0); |
---|
68 | |
---|
69 | eno = pthread_mutex_getprioceiling(&ctx->mtx_b, &prio_ceiling); |
---|
70 | rtems_test_assert(eno == 0); |
---|
71 | rtems_test_assert(prio_ceiling == 254); |
---|
72 | |
---|
73 | eno = pthread_mutex_lock(&ctx->mtx_b); |
---|
74 | rtems_test_assert(eno == 0); |
---|
75 | |
---|
76 | eno = pthread_mutex_unlock(&ctx->mtx_b); |
---|
77 | rtems_test_assert(eno == 0); |
---|
78 | |
---|
79 | eno = pthread_mutex_destroy(&ctx->mtx_b); |
---|
80 | rtems_test_assert(eno == 0); |
---|
81 | |
---|
82 | eno = pthread_mutex_getprioceiling(&ctx->mtx_a, &prio_ceiling); |
---|
83 | rtems_test_assert(eno == 0); |
---|
84 | rtems_test_assert(prio_ceiling == 126); |
---|
85 | |
---|
86 | eno = pthread_mutex_lock(&ctx->mtx_a); |
---|
87 | rtems_test_assert(eno == EINVAL); |
---|
88 | |
---|
89 | return ctx; |
---|
90 | } |
---|
91 | |
---|
92 | static void test(test_context *ctx) |
---|
93 | { |
---|
94 | uint32_t cpu_count; |
---|
95 | int prio_ceiling; |
---|
96 | int eno; |
---|
97 | |
---|
98 | cpu_count = rtems_get_processor_count(); |
---|
99 | |
---|
100 | rtems_test_assert(rtems_get_current_processor() == 0); |
---|
101 | |
---|
102 | eno = pthread_mutexattr_init(&ctx->mtx_attr); |
---|
103 | rtems_test_assert(eno == 0); |
---|
104 | |
---|
105 | eno = pthread_mutexattr_setprotocol(&ctx->mtx_attr, PTHREAD_PRIO_PROTECT); |
---|
106 | rtems_test_assert(eno == 0); |
---|
107 | |
---|
108 | eno = pthread_mutex_init(&ctx->mtx_a, &ctx->mtx_attr); |
---|
109 | rtems_test_assert(eno == 0); |
---|
110 | |
---|
111 | eno = pthread_mutex_getprioceiling(&ctx->mtx_a, &prio_ceiling); |
---|
112 | rtems_test_assert(eno == 0); |
---|
113 | rtems_test_assert(prio_ceiling == 126); |
---|
114 | |
---|
115 | eno = pthread_mutex_lock(&ctx->mtx_a); |
---|
116 | rtems_test_assert(eno == 0); |
---|
117 | |
---|
118 | eno = pthread_mutex_unlock(&ctx->mtx_a); |
---|
119 | rtems_test_assert(eno == 0); |
---|
120 | |
---|
121 | if (cpu_count > 1) { |
---|
122 | void *exit_code; |
---|
123 | |
---|
124 | eno = pthread_create(&ctx->thread_b, NULL, thread_b, ctx); |
---|
125 | rtems_test_assert(eno == 0); |
---|
126 | |
---|
127 | exit_code = NULL; |
---|
128 | eno = pthread_join(ctx->thread_b, &exit_code); |
---|
129 | rtems_test_assert(eno == 0); |
---|
130 | rtems_test_assert(exit_code == ctx); |
---|
131 | } |
---|
132 | |
---|
133 | eno = pthread_mutex_destroy(&ctx->mtx_a); |
---|
134 | rtems_test_assert(eno == 0); |
---|
135 | |
---|
136 | eno = pthread_mutexattr_destroy(&ctx->mtx_attr); |
---|
137 | rtems_test_assert(eno == 0); |
---|
138 | } |
---|
139 | |
---|
140 | static void *POSIX_Init(void *arg) |
---|
141 | { |
---|
142 | rtems_resource_snapshot snapshot; |
---|
143 | |
---|
144 | TEST_BEGIN(); |
---|
145 | |
---|
146 | rtems_resource_snapshot_take(&snapshot); |
---|
147 | |
---|
148 | test(&test_instance); |
---|
149 | |
---|
150 | rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); |
---|
151 | |
---|
152 | TEST_END(); |
---|
153 | rtems_test_exit(0); |
---|
154 | } |
---|
155 | |
---|
156 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
157 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
158 | |
---|
159 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
160 | #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2 |
---|
161 | |
---|
162 | #define CONFIGURE_SMP_MAXIMUM_PROCESSORS 2 |
---|
163 | |
---|
164 | #define CONFIGURE_SCHEDULER_PRIORITY_SMP |
---|
165 | |
---|
166 | #include <rtems/scheduler.h> |
---|
167 | |
---|
168 | RTEMS_SCHEDULER_CONTEXT_PRIORITY_SMP(a, 128); |
---|
169 | |
---|
170 | RTEMS_SCHEDULER_CONTEXT_PRIORITY_SMP(b, 256); |
---|
171 | |
---|
172 | #define CONFIGURE_SCHEDULER_CONTROLS \ |
---|
173 | RTEMS_SCHEDULER_CONTROL_PRIORITY_SMP(a, SCHED_A), \ |
---|
174 | RTEMS_SCHEDULER_CONTROL_PRIORITY_SMP(b, SCHED_B) \ |
---|
175 | |
---|
176 | #define CONFIGURE_SMP_SCHEDULER_ASSIGNMENTS \ |
---|
177 | RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \ |
---|
178 | RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL) |
---|
179 | |
---|
180 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
181 | |
---|
182 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
183 | |
---|
184 | #define CONFIGURE_INIT |
---|
185 | |
---|
186 | #include <rtems/confdefs.h> |
---|