source: rtems/testsuites/smptests/smpscheduler01/init.c @ c3cd7e7

4.11
Last change on this file since c3cd7e7 was c3cd7e7, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 9, 2014 at 1:26:17 PM

smptests/smpschedule01: Rename in smpscheduler01

  • Property mode set to 100644
File size: 4.2 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 <rtems.h>
20
21#include "tmacros.h"
22
23const char rtems_test_name[] = "SMPSCHEDULER 1";
24
25#define CPU_COUNT 2
26
27#define TASK_COUNT 4
28
29#define FIRST_TASK_PRIORITY 1
30
31#define SECOND_TASK_READY RTEMS_EVENT_0
32
33static rtems_id task_ids[TASK_COUNT];
34
35static void suspend(size_t i)
36{
37  rtems_status_code sc = rtems_task_suspend(task_ids[i]);
38  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
39}
40
41static void resume(size_t i)
42{
43  rtems_status_code sc = rtems_task_resume(task_ids[i]);
44  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
45}
46
47static void task(rtems_task_argument arg)
48{
49  rtems_task_priority task_priority;
50  rtems_status_code sc;
51
52  sc = rtems_task_set_priority(
53    RTEMS_SELF,
54    RTEMS_CURRENT_PRIORITY,
55    &task_priority
56  );
57  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
58
59  if (arg == 1) {
60    sc = rtems_event_send(task_ids[0], SECOND_TASK_READY);
61    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
62  }
63
64  while (true) {
65    /* Do nothing */
66  }
67}
68
69static bool is_per_cpu_state_ok(void)
70{
71  bool ok = true;
72  uint32_t n = rtems_smp_get_processor_count();
73  uint32_t i;
74
75  for (i = 0; i < n; ++i) {
76    const Thread_Control *thread = _Per_CPU_Get_by_index(i)->executing;
77    uint32_t count = 0;
78    uint32_t j;
79
80    for (j = 0; j < n; ++j) {
81      const Per_CPU_Control *cpu = _Per_CPU_Get_by_index(j);
82      const Thread_Control *executing = cpu->executing;
83      const Thread_Control *heir = cpu->heir;
84
85      if (i != j) {
86        count += executing == thread;
87        count += heir == thread;
88      } else {
89        ++count;
90      }
91
92      ok = ok && executing->cpu == cpu;
93      ok = ok && heir->cpu == cpu;
94    }
95
96    ok = ok && (count == 1);
97  }
98
99  return ok;
100}
101
102static void test_scheduler_cross(void)
103{
104  bool per_cpu_state_ok;
105
106  _Thread_Disable_dispatch();
107
108  suspend(0);
109  suspend(1);
110  resume(0);
111  resume(1);
112
113  per_cpu_state_ok = is_per_cpu_state_ok();
114
115  _Thread_Enable_dispatch();
116
117  rtems_test_assert(per_cpu_state_ok);
118}
119
120static void test_scheduler_move_heir(void)
121{
122  bool per_cpu_state_ok;
123
124  _Thread_Disable_dispatch();
125
126  suspend(2);
127  suspend(3);
128  suspend(0);
129  resume(2);
130  suspend(1);
131  resume(3);
132  resume(0);
133
134  per_cpu_state_ok = is_per_cpu_state_ok();
135
136  resume(1);
137
138  _Thread_Enable_dispatch();
139
140  rtems_test_assert(per_cpu_state_ok);
141}
142
143static void test(void)
144{
145  rtems_event_set events;
146  rtems_status_code sc;
147  rtems_task_argument task_index;
148
149  task_ids[0] = rtems_task_self();
150
151  for (task_index = 1; task_index < TASK_COUNT; ++task_index) {
152      rtems_id task_id;
153
154      sc = rtems_task_create(
155        rtems_build_name('T', 'A', 'S', 'K'),
156        FIRST_TASK_PRIORITY + task_index,
157        RTEMS_MINIMUM_STACK_SIZE,
158        RTEMS_DEFAULT_MODES,
159        RTEMS_DEFAULT_ATTRIBUTES,
160        &task_id
161      );
162      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
163
164      sc = rtems_task_start(task_id, task, task_index);
165      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
166
167      task_ids[task_index] = task_id;
168  }
169
170  sc = rtems_event_receive(
171    SECOND_TASK_READY,
172    RTEMS_EVENT_ALL | RTEMS_WAIT,
173    RTEMS_NO_TIMEOUT,
174    &events
175  );
176  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
177  rtems_test_assert(events == SECOND_TASK_READY);
178
179  test_scheduler_cross();
180  test_scheduler_move_heir();
181}
182
183static void Init(rtems_task_argument arg)
184{
185  TEST_BEGIN();
186
187  test();
188
189  TEST_END();
190  rtems_test_exit(0);
191}
192
193#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
194#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
195
196#define CONFIGURE_SMP_APPLICATION
197
198#define CONFIGURE_SMP_MAXIMUM_PROCESSORS CPU_COUNT
199
200#define CONFIGURE_MAXIMUM_TASKS TASK_COUNT
201
202#define CONFIGURE_INIT_TASK_PRIORITY FIRST_TASK_PRIORITY
203#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
204#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
205
206#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
207
208#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
209
210#define CONFIGURE_INIT
211
212#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.