source: rtems/testsuites/smptests/smpschededf01/init.c @ cf56b18a

5
Last change on this file since cf56b18a was cf56b18a, checked in by Sebastian Huber <sebastian.huber@…>, on 02/02/18 at 06:48:08

smpschededf01: Use rtems_test_busy_cpu_usage()

The rtems_test_busy() is not accurate enough and may lead to sporadic
test failures.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2017, 2018 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/cpuuse.h>
21
22#include "tmacros.h"
23
24const char rtems_test_name[] = "SMPSCHEDEDF 1";
25
26typedef struct {
27  rtems_id task[2];
28} test_context;
29
30static test_context test_instance;
31
32static void t(test_context *ctx, rtems_interval p, long nanoseconds)
33{
34  rtems_status_code sc;
35  rtems_id period;
36  rtems_name name;
37
38  sc = rtems_object_get_classic_name(rtems_task_self(), &name);
39  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
40
41  sc = rtems_rate_monotonic_create(name, &period);
42  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
43
44  while (true) {
45    rtems_test_busy_cpu_usage(0, nanoseconds);
46
47    sc = rtems_rate_monotonic_period(period, p);
48    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
49  }
50}
51
52static void t1(rtems_task_argument arg)
53{
54  test_context *ctx = (test_context *) arg;
55
56  t(ctx, 50, 25000000);
57}
58
59static void t2(rtems_task_argument arg)
60{
61  test_context *ctx = (test_context *) arg;
62
63  t(ctx, 75, 30000000);
64}
65
66static void test(test_context *ctx)
67{
68  rtems_status_code sc;
69
70  sc = rtems_task_create(
71    rtems_build_name('T', '1', ' ', ' '),
72    2,
73    RTEMS_MINIMUM_STACK_SIZE,
74    RTEMS_DEFAULT_MODES,
75    RTEMS_DEFAULT_ATTRIBUTES,
76    &ctx->task[0]
77  );
78  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
79
80  sc = rtems_task_create(
81    rtems_build_name('T', '2', ' ', ' '),
82    2,
83    RTEMS_MINIMUM_STACK_SIZE,
84    RTEMS_DEFAULT_MODES,
85    RTEMS_DEFAULT_ATTRIBUTES,
86    &ctx->task[1]
87  );
88  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
89
90  sc = rtems_task_wake_after(1);
91  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
92
93  sc = rtems_task_start(ctx->task[0], t1, (rtems_task_argument) ctx);
94  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
95
96  sc = rtems_task_start(ctx->task[1], t2, (rtems_task_argument) ctx);
97  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
98
99  rtems_cpu_usage_reset();
100
101  sc = rtems_task_wake_after(50 * 75);
102  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
103
104  sc = rtems_task_suspend(ctx->task[0]);
105  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
106
107  sc = rtems_task_suspend(ctx->task[1]);
108  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
109
110  rtems_cpu_usage_report_with_plugin(&rtems_test_printer);
111  rtems_rate_monotonic_report_statistics_with_plugin(&rtems_test_printer);
112}
113
114static void Init(rtems_task_argument arg)
115{
116  test_context *ctx = &test_instance;
117
118  TEST_BEGIN();
119
120  test(ctx);
121
122  TEST_END();
123  rtems_test_exit(0);
124}
125
126#define CONFIGURE_MICROSECONDS_PER_TICK 1000
127
128#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
129#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
130
131#define CONFIGURE_MAXIMUM_TASKS 3
132#define CONFIGURE_MAXIMUM_PERIODS 2
133
134#define CONFIGURE_MAXIMUM_PROCESSORS 1
135
136#define CONFIGURE_SCHEDULER_EDF_SMP
137
138#include <rtems/scheduler.h>
139
140RTEMS_SCHEDULER_CONTEXT_EDF_SMP(a, CONFIGURE_MAXIMUM_PROCESSORS);
141
142#define CONFIGURE_SCHEDULER_CONTROLS \
143  RTEMS_SCHEDULER_CONTROL_EDF_SMP(a, rtems_build_name('E', 'D', 'F', ' '))
144
145#define CONFIGURE_SMP_SCHEDULER_ASSIGNMENTS \
146  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY)
147
148#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
149
150#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
151
152#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
153
154#define CONFIGURE_INIT
155
156#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.