source: rtems/testsuites/tmtests/tmtimer01/init.c @ bbe71c61

Last change on this file since bbe71c61 was bbe71c61, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:40:17

bsps/testsuites/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#endif
12
13#include "tmacros.h"
14
15#include <stdio.h>
16#include <inttypes.h>
17
18#include <rtems.h>
19#include <rtems/counter.h>
20
21const char rtems_test_name[] = "TMTIMER 1";
22
23typedef struct {
24  size_t cache_line_size;
25  size_t data_cache_size;
26  int dummy_value;
27  volatile int *dummy_data;
28  rtems_id first;
29} test_context;
30
31static test_context test_instance;
32
33static void prepare_cache(test_context *ctx)
34{
35  volatile int *data = ctx->dummy_data;
36  size_t m = ctx->data_cache_size / sizeof(*data);
37  size_t k = ctx->cache_line_size / sizeof(*data);
38  size_t j = ctx->dummy_value;
39  size_t i;
40
41  for (i = 0; i < m; i += k) {
42    data[i] = i + j;
43  }
44
45  ctx->dummy_value = i + j;
46  rtems_cache_invalidate_entire_instruction();
47}
48
49static void never(rtems_id id, void *arg)
50{
51  rtems_test_assert(0);
52}
53
54static rtems_interval interval(size_t i)
55{
56  rtems_interval d = 50000;
57
58  return i * d + d;
59}
60
61static void test_fire_and_cancel(
62  test_context *ctx,
63  size_t i,
64  size_t j,
65  const char *name
66)
67{
68  rtems_status_code sc;
69  rtems_status_code sc2;
70  rtems_counter_ticks a;
71  rtems_counter_ticks b;
72  rtems_counter_ticks d;
73  rtems_id id;
74  rtems_interrupt_level level;
75
76  id = ctx->first + i;
77  prepare_cache(ctx);
78
79  rtems_interrupt_local_disable(level);
80  a = rtems_counter_read();
81  sc = rtems_timer_fire_after(id, interval(j), never, NULL);
82  sc2 = rtems_timer_cancel(id);
83  b = rtems_counter_read();
84  rtems_interrupt_local_enable(level);
85
86  d = rtems_counter_difference(b, a);
87
88  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
89  rtems_test_assert(sc2 == RTEMS_SUCCESSFUL);
90
91  printf(
92    "<%s unit=\"ns\">%" PRIu64 "</%s>",
93    name,
94    rtems_counter_ticks_to_nanoseconds(d),
95    name
96  );
97}
98
99static void test_case(test_context *ctx, size_t j, size_t k)
100{
101  rtems_status_code sc;
102  size_t s;
103  size_t t;
104
105  s = j - k;
106
107  for (t = 0; t < s; ++t) {
108    size_t u = k + t;
109
110    sc = rtems_timer_fire_after(ctx->first + u, interval(u + 1), never, NULL);
111    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
112  }
113
114  printf("  <Sample>\n    <ActiveTimers>%zu</ActiveTimers>", j);
115
116  test_fire_and_cancel(ctx, j, 0, "First");
117  test_fire_and_cancel(ctx, j, j / 2, "Middle");
118  test_fire_and_cancel(ctx, j, j + 1, "Last");
119
120  printf("\n  </Sample>\n");
121}
122
123static void test(void)
124{
125  test_context *ctx = &test_instance;
126  rtems_status_code sc;
127  rtems_id id;
128  rtems_name n;
129  size_t j;
130  size_t k;
131  size_t timer_count;
132
133  ctx->cache_line_size = rtems_cache_get_data_line_size();
134  if (ctx->cache_line_size == 0) {
135    ctx->cache_line_size = 32;
136  }
137
138  ctx->data_cache_size = rtems_cache_get_data_cache_size(0);
139  if (ctx->data_cache_size == 0) {
140    ctx->data_cache_size = ctx->cache_line_size;
141  }
142
143  ctx->dummy_data = malloc(ctx->data_cache_size);
144  rtems_test_assert(ctx->dummy_data != NULL);
145
146  n = 1;
147  timer_count = 1;
148
149  sc = rtems_timer_create(n, &ctx->first);
150  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
151  rtems_test_assert(rtems_object_id_get_index(ctx->first) == n);
152
153  while (true) {
154    ++n;
155
156    sc = rtems_timer_create(n, &id);
157    if (sc != RTEMS_SUCCESSFUL) {
158      break;
159    }
160
161    rtems_test_assert(rtems_object_id_get_index(id) == n);
162    timer_count = n;
163  }
164
165  printf("<TMTimer01 timerCount=\"%zu\">\n", timer_count);
166
167  k = 0;
168  j = 0;
169
170  while (j < timer_count) {
171    test_case(ctx, j, k);
172    k = j;
173    j = (123 * (j + 1) + 99) / 100;
174  }
175
176  test_case(ctx, n - 2, k);
177
178  printf("</TMTimer01>\n");
179}
180
181static void Init(rtems_task_argument arg)
182{
183  TEST_BEGIN();
184
185  test();
186
187  TEST_END();
188  rtems_test_exit(0);
189}
190
191#define CONFIGURE_MICROSECONDS_PER_TICK 50000
192
193#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
194#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
195
196#define CONFIGURE_UNIFIED_WORK_AREAS
197
198#define CONFIGURE_MAXIMUM_TASKS 1
199#define CONFIGURE_MAXIMUM_TIMERS rtems_resource_unlimited(32)
200
201#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
202
203#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
204
205#define CONFIGURE_INIT
206
207#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.