source: rtems/testsuites/smptests/smpswitchextension01/init.c @ d1c5c01f

4.115
Last change on this file since d1c5c01f was 806f84c8, checked in by Sebastian Huber <sebastian.huber@…>, on 08/08/13 at 14:34:19

smptests/smpswitchextension01: Fix start sequence

Start the toggler after the context is initialized.

  • Property mode set to 100644
File size: 5.5 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.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <stdio.h>
22#include <inttypes.h>
23
24#define CPU_COUNT 2
25
26#define TOGGLER_COUNT 2
27
28#define EXTENSION_COUNT 3
29
30#define PRIO_STOP 2
31
32#define PRIO_SWITCH 3
33
34#define PRIO_HIGH 4
35
36#define PRIO_NORMAL 5
37
38#define PRIO_LOW 6
39
40typedef struct {
41  uint32_t toggles;
42  uint32_t unused_space_for_cache_line_alignment[7];
43} test_toggler_counters;
44
45typedef struct {
46  test_toggler_counters counters[TOGGLER_COUNT];
47  rtems_id toggler_ids[TOGGLER_COUNT];
48  rtems_id extension_ids[EXTENSION_COUNT];
49  uint32_t extension_switches;
50  uint32_t context_switches[EXTENSION_COUNT];
51} test_context;
52
53CPU_STRUCTURE_ALIGNMENT static test_context ctx_instance;
54
55static void switch_0(Thread_Control *executing, Thread_Control *heir)
56{
57  test_context *ctx = &ctx_instance;
58
59  (void) executing;
60  (void) heir;
61
62  ++ctx->context_switches[0];
63}
64
65static void switch_1(Thread_Control *executing, Thread_Control *heir)
66{
67  test_context *ctx = &ctx_instance;
68
69  (void) executing;
70  (void) heir;
71
72  ++ctx->context_switches[1];
73}
74
75static void switch_2(Thread_Control *executing, Thread_Control *heir)
76{
77  test_context *ctx = &ctx_instance;
78
79  (void) executing;
80  (void) heir;
81
82  ++ctx->context_switches[2];
83}
84
85static const rtems_extensions_table extensions[EXTENSION_COUNT] = {
86  { .thread_switch = switch_0 },
87  { .thread_switch = switch_1 },
88  { .thread_switch = switch_2 }
89};
90
91static void toggler(rtems_task_argument self)
92{
93  test_context *ctx = &ctx_instance;
94  test_toggler_counters *counters = &ctx->counters[self];
95
96  while (true) {
97    rtems_status_code sc;
98
99    ++counters->toggles;
100
101    sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
102    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
103  }
104}
105
106static void switcher(rtems_task_argument self)
107{
108  test_context *ctx = &ctx_instance;
109
110  while (true) {
111    size_t ext_index;
112    rtems_status_code sc;
113
114    ++ctx->extension_switches;
115
116    for (ext_index = 0; ext_index < EXTENSION_COUNT; ++ext_index) {
117      sc = rtems_extension_create(
118        rtems_build_name('E', 'X', 'T', (char) ('0' + ext_index)),
119        &extensions[ext_index],
120        &ctx->extension_ids[ext_index]
121      );
122      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
123    }
124
125    for (ext_index = 0; ext_index < EXTENSION_COUNT; ++ext_index) {
126      sc = rtems_extension_delete(ctx->extension_ids[ext_index]);
127      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
128    }
129  }
130}
131
132static void stopper(rtems_task_argument arg)
133{
134  (void) arg;
135
136  while (true) {
137    /* Do nothing */
138  }
139}
140
141static void test(void)
142{
143  test_context *ctx = &ctx_instance;
144  rtems_status_code sc;
145  rtems_task_argument toggler_index;
146  rtems_id stopper_id;
147  rtems_id switcher_id;
148  size_t ext_index;
149
150  sc = rtems_task_create(
151    rtems_build_name('S', 'T', 'O', 'P'),
152    PRIO_STOP,
153    RTEMS_MINIMUM_STACK_SIZE,
154    RTEMS_DEFAULT_MODES,
155    RTEMS_DEFAULT_ATTRIBUTES,
156    &stopper_id
157  );
158  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
159
160  sc = rtems_task_create(
161    rtems_build_name('E', 'X', 'S', 'W'),
162    PRIO_SWITCH,
163    RTEMS_MINIMUM_STACK_SIZE,
164    RTEMS_DEFAULT_MODES,
165    RTEMS_DEFAULT_ATTRIBUTES,
166    &switcher_id
167  );
168  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
169
170  for (toggler_index = 0; toggler_index < TOGGLER_COUNT; ++toggler_index) {
171    sc = rtems_task_create(
172      rtems_build_name('T', 'O', 'G', (char) ('0' + toggler_index)),
173      PRIO_NORMAL,
174      RTEMS_MINIMUM_STACK_SIZE,
175      RTEMS_DEFAULT_MODES,
176      RTEMS_DEFAULT_ATTRIBUTES,
177      &ctx->toggler_ids[toggler_index]
178    );
179    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
180  }
181
182  for (toggler_index = 0; toggler_index < TOGGLER_COUNT; ++toggler_index) {
183    sc = rtems_task_start(ctx->toggler_ids[toggler_index], toggler, toggler_index);
184    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
185  }
186
187  sc = rtems_task_start(switcher_id, switcher, 0);
188  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
189
190  sc = rtems_task_wake_after(10 * rtems_clock_get_ticks_per_second());
191  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
192
193  sc = rtems_task_start(stopper_id, stopper, 0);
194  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
195
196  for (toggler_index = 0; toggler_index < TOGGLER_COUNT; ++toggler_index) {
197    test_toggler_counters *counters = &ctx->counters[toggler_index];
198
199    printf(
200      "toggler %" PRIuPTR "\n"
201        "\ttoggles %" PRIu32 "\n",
202      toggler_index,
203      counters->toggles
204    );
205  }
206
207  for (ext_index = 0; ext_index < EXTENSION_COUNT; ++ext_index) {
208    printf(
209      "extension %" PRIuPTR "\n"
210        "\tcontext switches %" PRIu32 "\n",
211      ext_index,
212      ctx->context_switches[ext_index]
213    );
214  }
215
216  printf(
217    "extension switches %" PRIu32 "\n",
218    ctx->extension_switches
219  );
220}
221
222static void Init(rtems_task_argument arg)
223{
224  puts("\n\n*** TEST SMPSWITCHEXTENSION 1 ***");
225
226  if (rtems_smp_get_processor_count() >= 2) {
227    test();
228  }
229
230  puts("*** END OF TEST SMPSWITCHEXTENSION 1 ***");
231
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_SMP_APPLICATION
239
240#define CONFIGURE_SMP_MAXIMUM_PROCESSORS CPU_COUNT
241
242#define CONFIGURE_MAXIMUM_TASKS (3 + TOGGLER_COUNT)
243
244#define CONFIGURE_MAXIMUM_USER_EXTENSIONS EXTENSION_COUNT
245
246#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
247
248#define CONFIGURE_INIT
249
250#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.