source: rtems/testsuites/smptests/smpschedule01/init.c @ 8b222be

4.115
Last change on this file since 8b222be was 8b222be, checked in by Sebastian Huber <sebastian.huber@…>, on 06/11/13 at 08:00:25

smptests/smpschedule01: New test

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