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

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

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