source: rtems/testsuites/smptests/smpswitchextension01/init.c @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

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