source: rtems/testsuites/smptests/smpwakeafter01/init.c @ 6fadb7af

5
Last change on this file since 6fadb7af was 6fadb7af, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 8, 2018 at 5:33:24 AM

config: Use new scheduler configuration defines

Update #3325.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 * Copyright (c) 2014 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
21#include <stdio.h>
22#include <inttypes.h>
23
24#include <rtems.h>
25#include <rtems/libcsupport.h>
26
27const char rtems_test_name[] = "SMPWAKEAFTER 1";
28
29#define CPU_COUNT 32
30
31#define INTERVAL_COUNT 8
32
33#define SCHED_A rtems_build_name(' ', ' ', ' ', 'A')
34
35#define SCHED_B rtems_build_name(' ', ' ', ' ', 'B')
36
37static rtems_id task_ids[CPU_COUNT][INTERVAL_COUNT];
38
39static const rtems_interval intervals[INTERVAL_COUNT] =
40  { 1, 2, 3, 5, 7, 11, 13, 17 };
41
42static uint32_t counts[CPU_COUNT][INTERVAL_COUNT];
43
44static rtems_task_argument make_arg(uint32_t i, uint32_t j)
45{
46  return (i << 8) | (j << 0);
47}
48
49static void get_indices(rtems_task_argument arg, uint32_t *i, uint32_t *j)
50{
51  *i = (arg >> 8) & 0xff;
52  *j = (arg >> 0) & 0xff;
53}
54
55static void task(rtems_task_argument arg)
56{
57  uint32_t i;
58  uint32_t j;
59  rtems_interval ticks;
60
61  get_indices(arg, &i, &j);
62  ticks = intervals[j];
63
64  while (true) {
65    rtems_status_code sc;
66
67    ++counts[i][j];
68
69    sc = rtems_task_wake_after(ticks);
70    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
71  }
72}
73
74static void test(void)
75{
76  rtems_status_code sc;
77  uint32_t test_time_in_seconds = 10;
78  uint32_t cpu_count = rtems_get_processor_count();
79  uint32_t i;
80
81  for (i = 0; i < cpu_count; ++i) {
82    rtems_id scheduler_id;
83    uint32_t j;
84
85    if (i != 1) {
86      sc = rtems_scheduler_ident(SCHED_A, &scheduler_id);
87      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
88    } else {
89      sc = rtems_scheduler_ident(SCHED_B, &scheduler_id);
90      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
91    }
92
93    for (j = 0; j < INTERVAL_COUNT; ++j) {
94      sc = rtems_task_create(
95        rtems_build_name('T', 'A', 'S', 'K'),
96        255,
97        RTEMS_MINIMUM_STACK_SIZE,
98        RTEMS_DEFAULT_MODES,
99        RTEMS_DEFAULT_ATTRIBUTES,
100        &task_ids[i][j]
101      );
102      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
103
104      sc = rtems_task_set_scheduler(task_ids[i][j], scheduler_id, 2);
105      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
106
107      sc = rtems_task_start(task_ids[i][j], task, make_arg(i, j));
108      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
109    }
110  }
111
112  for (i = 0; i < test_time_in_seconds; ++i) {
113    printf("%" PRIu32 " seconds remaining\n", test_time_in_seconds - i);
114
115    sc = rtems_task_wake_after(rtems_clock_get_ticks_per_second());
116    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
117  }
118
119  for (i = 0; i < cpu_count; ++i) {
120    uint32_t j;
121
122    for (j = 0; j < INTERVAL_COUNT; ++j) {
123      sc = rtems_task_delete(task_ids[i][j]);
124      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
125
126      printf(
127        "counts[%" PRIu32 "][%" PRIu32 "] = %" PRIu32 "\n",
128        i,
129        j,
130        counts[i][j]
131      );
132    }
133  }
134}
135
136static void Init(rtems_task_argument arg)
137{
138  rtems_resource_snapshot snapshot;
139
140  TEST_BEGIN();
141
142  rtems_resource_snapshot_take(&snapshot);
143
144  test();
145
146  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
147
148  TEST_END();
149  rtems_test_exit(0);
150}
151
152#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
153#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
154
155#define CONFIGURE_MICROSECONDS_PER_TICK 1000
156
157#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
158
159#define CONFIGURE_MAXIMUM_PRIORITY 255
160
161#define CONFIGURE_SCHEDULER_PRIORITY_SMP
162
163#include <rtems/scheduler.h>
164
165RTEMS_SCHEDULER_PRIORITY_SMP(a, CONFIGURE_MAXIMUM_PRIORITY + 1);
166
167RTEMS_SCHEDULER_PRIORITY_SMP(b, CONFIGURE_MAXIMUM_PRIORITY + 1);
168
169#define CONFIGURE_SCHEDULER_TABLE_ENTRIES \
170  RTEMS_SCHEDULER_TABLE_PRIORITY_SMP(a, SCHED_A), \
171  RTEMS_SCHEDULER_TABLE_PRIORITY_SMP(b, SCHED_B)
172
173#define CONFIGURE_SCHEDULER_ASSIGNMENTS \
174  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \
175  RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
176  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
177  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
178  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
179  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
180  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
181  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
182  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
183  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
184  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
185  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
186  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
187  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
188  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
189  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
190  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
191  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
192  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
193  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
194  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
195  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
196  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
197  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
198  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
199  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
200  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
201  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
202  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
203  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
204  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
205  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL)
206
207#define CONFIGURE_MAXIMUM_TASKS (1 + CPU_COUNT * INTERVAL_COUNT)
208
209#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
210
211#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
212
213#define CONFIGURE_INIT
214
215#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.