1 | /* |
---|
2 | * Copyright (c) 2013, 2017 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 "tmacros.h" |
---|
20 | |
---|
21 | const char rtems_test_name[] = "SMPSIGNAL 1"; |
---|
22 | |
---|
23 | #define TEST_SIGNAL RTEMS_SIGNAL_0 |
---|
24 | |
---|
25 | typedef enum { |
---|
26 | SIG_0_READY, |
---|
27 | SIG_0_SENT, |
---|
28 | SIG_0_ENABLE, |
---|
29 | SIG_0_PROCESSED, |
---|
30 | SIG_1_READY, |
---|
31 | SIG_1_SENT, |
---|
32 | SIG_1_PROCESSED |
---|
33 | } test_state; |
---|
34 | |
---|
35 | typedef struct { |
---|
36 | test_state state; |
---|
37 | rtems_id consumer; |
---|
38 | rtems_id producer; |
---|
39 | uint32_t consumer_processor; |
---|
40 | uint32_t producer_processor; |
---|
41 | rtems_id timer; |
---|
42 | volatile bool done; |
---|
43 | } test_context; |
---|
44 | |
---|
45 | static void change_state(test_context *ctx, test_state new_state) |
---|
46 | { |
---|
47 | ctx->state = new_state; |
---|
48 | _CPU_SMP_Processor_event_broadcast(); |
---|
49 | } |
---|
50 | |
---|
51 | static void wait_for_state(const test_context *ctx, test_state desired_state) |
---|
52 | { |
---|
53 | while ( ctx->state != desired_state ) { |
---|
54 | _CPU_SMP_Processor_event_receive(); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | static test_context ctx_instance = { |
---|
59 | .state = SIG_0_READY |
---|
60 | }; |
---|
61 | |
---|
62 | static void signal_handler(rtems_signal_set signal) |
---|
63 | { |
---|
64 | test_context *ctx = &ctx_instance; |
---|
65 | |
---|
66 | rtems_test_assert(_ISR_Get_level() == 0); |
---|
67 | |
---|
68 | switch (ctx->state) { |
---|
69 | case SIG_0_ENABLE: |
---|
70 | change_state(ctx, SIG_0_PROCESSED); |
---|
71 | break; |
---|
72 | case SIG_1_SENT: |
---|
73 | change_state(ctx, SIG_1_PROCESSED); |
---|
74 | break; |
---|
75 | default: |
---|
76 | rtems_test_assert(0); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | static void signal_send(test_context *ctx, test_state new_state) |
---|
81 | { |
---|
82 | rtems_status_code sc; |
---|
83 | |
---|
84 | sc = rtems_signal_send(ctx->consumer, TEST_SIGNAL); |
---|
85 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
86 | |
---|
87 | change_state(ctx, new_state); |
---|
88 | } |
---|
89 | |
---|
90 | static void check_consumer_processor(const test_context *ctx) |
---|
91 | { |
---|
92 | rtems_test_assert( |
---|
93 | ctx->consumer_processor == rtems_get_current_processor() |
---|
94 | ); |
---|
95 | } |
---|
96 | |
---|
97 | static void check_producer_processor(const test_context *ctx) |
---|
98 | { |
---|
99 | rtems_test_assert( |
---|
100 | ctx->producer_processor == rtems_get_current_processor() |
---|
101 | ); |
---|
102 | } |
---|
103 | |
---|
104 | static void producer(rtems_task_argument arg) |
---|
105 | { |
---|
106 | test_context *ctx = (test_context *) arg; |
---|
107 | |
---|
108 | ctx->producer_processor = rtems_get_current_processor(); |
---|
109 | |
---|
110 | rtems_test_assert(ctx->consumer_processor != ctx->producer_processor); |
---|
111 | |
---|
112 | wait_for_state(ctx, SIG_0_READY); |
---|
113 | signal_send(ctx, SIG_0_SENT); |
---|
114 | |
---|
115 | check_producer_processor(ctx); |
---|
116 | |
---|
117 | wait_for_state(ctx, SIG_1_READY); |
---|
118 | signal_send(ctx, SIG_1_SENT); |
---|
119 | |
---|
120 | check_producer_processor(ctx); |
---|
121 | |
---|
122 | rtems_task_suspend(RTEMS_SELF); |
---|
123 | rtems_test_assert(0); |
---|
124 | } |
---|
125 | |
---|
126 | static void test_two_processors(test_context *ctx) |
---|
127 | { |
---|
128 | rtems_status_code sc; |
---|
129 | rtems_mode mode; |
---|
130 | |
---|
131 | sc = rtems_signal_catch(signal_handler, RTEMS_DEFAULT_MODES); |
---|
132 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
133 | |
---|
134 | sc = rtems_task_create( |
---|
135 | rtems_build_name('P', 'R', 'O', 'D'), |
---|
136 | RTEMS_MINIMUM_PRIORITY, |
---|
137 | RTEMS_MINIMUM_STACK_SIZE, |
---|
138 | RTEMS_DEFAULT_MODES, |
---|
139 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
140 | &ctx->producer |
---|
141 | ); |
---|
142 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
143 | |
---|
144 | sc = rtems_task_start(ctx->producer, producer, (rtems_task_argument) ctx); |
---|
145 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
146 | |
---|
147 | check_consumer_processor(ctx); |
---|
148 | |
---|
149 | wait_for_state(ctx, SIG_0_SENT); |
---|
150 | change_state(ctx, SIG_0_ENABLE); |
---|
151 | |
---|
152 | sc = rtems_task_mode(RTEMS_ASR, RTEMS_ASR_MASK, &mode); |
---|
153 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
154 | rtems_test_assert(mode == RTEMS_NO_ASR); |
---|
155 | |
---|
156 | wait_for_state(ctx, SIG_0_PROCESSED); |
---|
157 | |
---|
158 | check_consumer_processor(ctx); |
---|
159 | |
---|
160 | change_state(ctx, SIG_1_READY); |
---|
161 | wait_for_state(ctx, SIG_1_PROCESSED); |
---|
162 | |
---|
163 | check_consumer_processor(ctx); |
---|
164 | } |
---|
165 | |
---|
166 | static void isr_level_timer(rtems_id timer, void *arg) |
---|
167 | { |
---|
168 | test_context *ctx = arg; |
---|
169 | rtems_status_code sc; |
---|
170 | |
---|
171 | sc = rtems_signal_send(ctx->consumer, TEST_SIGNAL); |
---|
172 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
173 | } |
---|
174 | |
---|
175 | static void isr_level_handler(rtems_signal_set signal) |
---|
176 | { |
---|
177 | test_context *ctx = &ctx_instance; |
---|
178 | |
---|
179 | rtems_test_assert(_ISR_Get_level() == 0); |
---|
180 | |
---|
181 | ctx->done = true; |
---|
182 | } |
---|
183 | |
---|
184 | static void test_isr_level(test_context *ctx) |
---|
185 | { |
---|
186 | rtems_status_code sc; |
---|
187 | rtems_mode mode; |
---|
188 | |
---|
189 | sc = rtems_task_mode(RTEMS_ASR, RTEMS_ASR_MASK, &mode); |
---|
190 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
191 | rtems_test_assert(mode == RTEMS_NO_ASR); |
---|
192 | |
---|
193 | sc = rtems_timer_create(rtems_build_name('T', 'I', 'M', 'R'), &ctx->timer); |
---|
194 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
195 | |
---|
196 | rtems_test_assert(!ctx->done); |
---|
197 | |
---|
198 | sc = rtems_signal_catch(isr_level_handler, RTEMS_DEFAULT_MODES); |
---|
199 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
200 | |
---|
201 | sc = rtems_timer_fire_after(ctx->timer, 1, isr_level_timer, ctx); |
---|
202 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
203 | |
---|
204 | while (!ctx->done) { |
---|
205 | /* Wait for timer */ |
---|
206 | } |
---|
207 | |
---|
208 | sc = rtems_timer_delete(ctx->timer); |
---|
209 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
210 | |
---|
211 | sc = rtems_task_mode(RTEMS_NO_ASR, RTEMS_ASR_MASK, &mode); |
---|
212 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
213 | rtems_test_assert(mode == RTEMS_ASR); |
---|
214 | } |
---|
215 | |
---|
216 | static void Init(rtems_task_argument arg) |
---|
217 | { |
---|
218 | test_context *ctx = &ctx_instance; |
---|
219 | |
---|
220 | TEST_BEGIN(); |
---|
221 | |
---|
222 | ctx->consumer = rtems_task_self(); |
---|
223 | ctx->consumer_processor = rtems_get_current_processor(); |
---|
224 | |
---|
225 | test_isr_level(ctx); |
---|
226 | |
---|
227 | if (rtems_get_processor_count() >= 2) { |
---|
228 | test_two_processors(ctx); |
---|
229 | } |
---|
230 | |
---|
231 | TEST_END(); |
---|
232 | rtems_test_exit(0); |
---|
233 | } |
---|
234 | |
---|
235 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
236 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
237 | |
---|
238 | #define CONFIGURE_MAXIMUM_PROCESSORS 2 |
---|
239 | |
---|
240 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
241 | |
---|
242 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
243 | |
---|
244 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
245 | |
---|
246 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
247 | |
---|
248 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_NO_ASR |
---|
249 | |
---|
250 | #define CONFIGURE_INIT |
---|
251 | |
---|
252 | #include <rtems/confdefs.h> |
---|