source: rtems/testsuites/sptests/spcontext01/init.c @ a0b1b5ed

4.115
Last change on this file since a0b1b5ed was a0b1b5ed, checked in by Sebastian Huber <sebastian.huber@…>, on 12/15/14 at 13:19:43

Delete CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM

This define was superfluous, undocumented and used inconsistently.

  • Property mode set to 100644
File size: 5.0 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[] = "SPCONTEXT 1";
22
23#define ITERATION_COUNT 2000
24
25#define PRIORITY_HIGH 2
26
27#define PRIORITY_LOW 3
28
29#define FINISH_EVENT RTEMS_EVENT_0
30
31typedef struct {
32  rtems_id control_task;
33  rtems_id validate_tasks[2];
34  size_t task_index;
35  int iteration_counter;
36} test_context;
37
38static test_context test_instance;
39
40static void validate_task(rtems_task_argument arg)
41{
42  _CPU_Context_validate(arg);
43  rtems_test_assert(0);
44}
45
46static void start_validate_task(
47  rtems_id *id,
48  uintptr_t pattern,
49  rtems_task_priority priority
50)
51{
52  rtems_status_code sc;
53
54  sc = rtems_task_create(
55    rtems_build_name('V', 'A', 'L', 'I'),
56    priority,
57    RTEMS_MINIMUM_STACK_SIZE,
58    RTEMS_DEFAULT_MODES,
59    RTEMS_DEFAULT_ATTRIBUTES,
60    id
61  );
62  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
63
64  sc = rtems_task_start(*id, validate_task, pattern);
65  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
66}
67
68static void reset_timer_or_finish(test_context *self, rtems_id timer)
69{
70  rtems_status_code sc;
71  int i = self->iteration_counter;
72
73  if (i < ITERATION_COUNT) {
74    self->iteration_counter = i + 1;
75
76    sc = rtems_timer_reset(timer);
77    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
78  } else {
79    sc = rtems_event_send(self->control_task, FINISH_EVENT);
80    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
81  }
82}
83
84static void switch_priorities(test_context *self)
85{
86  rtems_status_code sc;
87  size_t index = self->task_index;
88  size_t next = (index + 1) & 0x1;
89  size_t task_high = index;
90  size_t task_low = next;
91  rtems_task_priority priority;
92
93  self->task_index = next;
94
95  sc = rtems_task_set_priority(
96    self->validate_tasks[task_high],
97    PRIORITY_HIGH,
98    &priority
99  );
100  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
101
102  sc = rtems_task_set_priority(
103    self->validate_tasks[task_low],
104    PRIORITY_LOW,
105    &priority
106  );
107  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
108}
109
110static void clobber_and_switch_timer(rtems_id timer, void *arg)
111{
112  uintptr_t pattern = (uintptr_t) 0xffffffffffffffffU;
113  test_context *self = arg;
114
115  reset_timer_or_finish(self, timer);
116  switch_priorities(self);
117
118  _CPU_Context_volatile_clobber(pattern);
119}
120
121static void start_timer(test_context *self)
122{
123  rtems_status_code sc;
124  rtems_id timer;
125
126  sc = rtems_timer_create(rtems_build_name('C', 'L', 'S', 'W'), &timer);
127  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
128
129  sc = rtems_timer_fire_after(timer, 2, clobber_and_switch_timer, self);
130  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
131}
132
133static void wait_for_finish(void)
134{
135  rtems_status_code sc;
136  rtems_event_set out;
137
138  sc = rtems_event_receive(
139    FINISH_EVENT,
140    RTEMS_WAIT | RTEMS_EVENT_ALL,
141    RTEMS_NO_TIMEOUT,
142    &out
143  );
144  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
145  rtems_test_assert(out == FINISH_EVENT);
146}
147
148static void test(test_context *self)
149{
150  uintptr_t pattern_0 = (uintptr_t) 0xaaaaaaaaaaaaaaaaU;
151  uintptr_t pattern_1 = (uintptr_t) 0x5555555555555555U;
152
153  memset(self, 0, sizeof(*self));
154
155  self->control_task = rtems_task_self();
156
157  start_validate_task(&self->validate_tasks[0], pattern_0, PRIORITY_LOW);
158  start_validate_task(&self->validate_tasks[1], pattern_1, PRIORITY_HIGH);
159  start_timer(self);
160  wait_for_finish();
161}
162
163static void test_context_is_executing(void)
164{
165#if defined(RTEMS_SMP)
166  /*
167   * Provide a stack area, since on some architectures the top/bottom of stack
168   * is initialized by _CPU_Context_Initialize().
169   */
170  static char stack[1024];
171
172  Context_Control context;
173  bool is_executing;
174
175  memset(&context, 0, sizeof(context));
176
177  is_executing = _CPU_Context_Get_is_executing(&context);
178  rtems_test_assert(!is_executing);
179
180  _CPU_Context_Set_is_executing(&context, true);
181  is_executing = _CPU_Context_Get_is_executing(&context);
182  rtems_test_assert(is_executing);
183
184  _CPU_Context_Set_is_executing(&context, false);
185  is_executing = _CPU_Context_Get_is_executing(&context);
186  rtems_test_assert(!is_executing);
187
188  _CPU_Context_Set_is_executing(&context, true);
189  _CPU_Context_Initialize(
190    &context,
191    (void *) &stack[0],
192    sizeof(stack),
193    0,
194    NULL,
195    false,
196    NULL
197  );
198  is_executing = _CPU_Context_Get_is_executing(&context);
199  rtems_test_assert(is_executing);
200#endif
201}
202
203static void Init(rtems_task_argument arg)
204{
205  test_context *self = &test_instance;
206
207  TEST_BEGIN();
208
209  test_context_is_executing();
210  test(self);
211
212  TEST_END();
213
214  rtems_test_exit(0);
215}
216
217#define CONFIGURE_MICROSECONDS_PER_TICK 1000
218
219#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
220#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
221
222#define CONFIGURE_MAXIMUM_TASKS 3
223#define CONFIGURE_MAXIMUM_TIMERS 1
224
225#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
226
227#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
228
229#define CONFIGURE_INIT
230
231#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.