source: rtems/testsuites/smptests/smpsignal01/init.c @ cb5eaddf

4.115
Last change on this file since cb5eaddf was cb5eaddf, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 10, 2014 at 9:02:52 AM

rtems: Rename rtems_smp_get_current_processor()

Rename rtems_smp_get_current_processor() in
rtems_get_current_processor(). Make rtems_get_current_processor() a
function in uni-processor configurations to enable ABI compatibility
with SMP configurations.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2013 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
21const char rtems_test_name[] = "SMPSIGNAL 1";
22
23#define TEST_SIGNAL RTEMS_SIGNAL_0
24
25typedef 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
35typedef struct {
36  test_state state;
37  rtems_id consumer;
38  rtems_id producer;
39  uint32_t consumer_processor;
40  uint32_t producer_processor;
41} test_context;
42
43static void change_state(test_context *ctx, test_state new_state)
44{
45  ctx->state = new_state;
46  _CPU_SMP_Processor_event_broadcast();
47}
48
49static void wait_for_state(const test_context *ctx, test_state desired_state)
50{
51  while ( ctx->state != desired_state ) {
52    _CPU_SMP_Processor_event_receive();
53  }
54}
55
56static test_context ctx_instance = {
57  .state = SIG_0_READY
58};
59
60static void signal_handler(rtems_signal_set signal)
61{
62  test_context *ctx = &ctx_instance;
63
64  switch (ctx->state) {
65    case SIG_0_ENABLE:
66      change_state(ctx, SIG_0_PROCESSED);
67      break;
68    case SIG_1_SENT:
69      change_state(ctx, SIG_1_PROCESSED);
70      break;
71    default:
72      rtems_test_assert(0);
73  }
74}
75
76static void signal_send(test_context *ctx, test_state new_state)
77{
78  rtems_status_code sc;
79
80  sc = rtems_signal_send(ctx->consumer, TEST_SIGNAL);
81  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
82
83  change_state(ctx, new_state);
84}
85
86static void check_consumer_processor(const test_context *ctx)
87{
88  rtems_test_assert(
89    ctx->consumer_processor == rtems_get_current_processor()
90  );
91}
92
93static void check_producer_processor(const test_context *ctx)
94{
95  rtems_test_assert(
96    ctx->producer_processor == rtems_get_current_processor()
97  );
98}
99
100static void producer(rtems_task_argument arg)
101{
102  test_context *ctx = (test_context *) arg;
103
104  ctx->producer_processor = rtems_get_current_processor();
105
106  rtems_test_assert(ctx->consumer_processor != ctx->producer_processor);
107
108  wait_for_state(ctx, SIG_0_READY);
109  signal_send(ctx, SIG_0_SENT);
110
111  check_producer_processor(ctx);
112
113  wait_for_state(ctx, SIG_1_READY);
114  signal_send(ctx, SIG_1_SENT);
115
116  check_producer_processor(ctx);
117
118  rtems_task_suspend(RTEMS_SELF);
119  rtems_test_assert(0);
120}
121
122static void test(void)
123{
124  test_context *ctx = &ctx_instance;
125  rtems_status_code sc;
126  rtems_mode mode;
127
128  ctx->consumer = rtems_task_self();
129  ctx->consumer_processor = rtems_get_current_processor();
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
155  wait_for_state(ctx, SIG_0_PROCESSED);
156
157  check_consumer_processor(ctx);
158
159  change_state(ctx, SIG_1_READY);
160  wait_for_state(ctx, SIG_1_PROCESSED);
161
162  check_consumer_processor(ctx);
163}
164
165static void Init(rtems_task_argument arg)
166{
167  TEST_BEGIN();
168
169  if (rtems_get_processor_count() >= 2) {
170    test();
171  }
172
173  TEST_END();
174  rtems_test_exit(0);
175}
176
177#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
178#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
179
180#define CONFIGURE_SMP_APPLICATION
181
182#define CONFIGURE_SMP_MAXIMUM_PROCESSORS 2
183
184#define CONFIGURE_MAXIMUM_TASKS 2
185
186#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
187
188#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
189
190#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_NO_ASR
191
192#define CONFIGURE_INIT
193
194#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.