source: rtems/testsuites/sptests/sptimecounter02/init.c @ 80cf60e

5
Last change on this file since 80cf60e was 80cf60e, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/20 at 07:48:32

Canonicalize config.h include

Use the following variant which was already used by most source files:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Copyright (c) 2015 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 <sys/lock.h>
20
21#define _KERNEL
22
23#include <sys/time.h>
24#include <sys/timetc.h>
25
26#include <stdlib.h>
27#include <stdio.h>
28#include <inttypes.h>
29#include <unistd.h>
30
31#include <rtems.h>
32#include <rtems/counter.h>
33#include <rtems/test.h>
34
35#include <rtems/score/timecounterimpl.h>
36#include <rtems/timecounter.h>
37#include <rtems/bsd.h>
38
39#include <test_support.h>
40
41#include "tmacros.h"
42
43const char rtems_test_name[] = "SPTIMECOUNTER 2";
44
45#define CPU_COUNT 32
46
47#define DURATION_IN_SECONDS 1
48
49typedef struct {
50  rtems_test_parallel_context base;
51  struct timecounter tc_null;
52  uint32_t binuptime_per_job[CPU_COUNT];
53  sbintime_t duration_per_job[CPU_COUNT];
54  uint32_t rtemsuptime_per_job[CPU_COUNT];
55} timecounter_context;
56
57static timecounter_context test_instance;
58
59static rtems_interval test_duration(void)
60{
61  return DURATION_IN_SECONDS * rtems_clock_get_ticks_per_second();
62}
63
64static uint32_t test_get_timecount_null(struct timecounter *tc)
65{
66  return 0;
67}
68
69static void install_tc_null(timecounter_context *ctx)
70{
71  struct timecounter *tc_cpu = &ctx->tc_null;
72
73  tc_cpu->tc_get_timecount = test_get_timecount_null;
74  tc_cpu->tc_counter_mask = 0xffffffff;
75  tc_cpu->tc_frequency = rtems_counter_nanoseconds_to_ticks(1000000000);
76  tc_cpu->tc_quality = 2000;
77  rtems_timecounter_install(tc_cpu);
78}
79
80static rtems_interval test_bintime_init(
81  rtems_test_parallel_context *base,
82  void *arg,
83  size_t active_workers
84)
85{
86  rtems_test_spin_until_next_tick();
87
88  return test_duration();
89}
90
91static void test_bintime_body(
92  rtems_test_parallel_context *base,
93  void *arg,
94  size_t active_workers,
95  size_t worker_index
96)
97{
98  timecounter_context *ctx = (timecounter_context *) base;
99  uint32_t counter = 1;
100  struct bintime start;
101  struct bintime end;
102
103  rtems_bsd_binuptime(&start);
104
105  do {
106    ++counter;
107    rtems_bsd_binuptime(&end);
108  } while (!rtems_test_parallel_stop_job(&ctx->base));
109
110  ctx->binuptime_per_job[worker_index] = counter;
111  ctx->duration_per_job[worker_index] = bttosbt(end) - bttosbt(start);
112}
113
114static void test_bintime_fini(
115  rtems_test_parallel_context *base,
116  void *arg,
117  size_t active_workers
118)
119{
120  timecounter_context *ctx = (timecounter_context *) base;
121  size_t i;
122
123  printf("  <BinuptimeTest activeWorker=\"%zu\">\n", active_workers);
124
125  for (i = 0; i < active_workers; ++i) {
126    sbintime_t error;
127
128    printf(
129      "    <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n"
130      "    <Duration worker=\"%zu\" unit=\"sbintime\">%" PRId64 "</Duration>\n",
131      i + 1,
132      ctx->binuptime_per_job[i],
133      i + 1,
134      ctx->duration_per_job[i]
135    );
136
137    error = DURATION_IN_SECONDS * SBT_1S - ctx->duration_per_job[i];
138    rtems_test_assert(error * error < SBT_1MS * SBT_1MS);
139  }
140
141  printf("  </BinuptimeTest>\n");
142}
143
144static rtems_interval test_bintime_null_init(
145  rtems_test_parallel_context *base,
146  void *arg,
147  size_t active_workers
148)
149{
150  timecounter_context *ctx = &test_instance;
151
152  install_tc_null(ctx);
153
154  return test_duration();
155}
156
157static void test_bintime_null_body(
158  rtems_test_parallel_context *base,
159  void *arg,
160  size_t active_workers,
161  size_t worker_index
162)
163{
164  timecounter_context *ctx = (timecounter_context *) base;
165  struct bintime bt;
166  uint32_t counter = 0;
167
168  while (!rtems_test_parallel_stop_job(&ctx->base)) {
169    ++counter;
170    rtems_bsd_binuptime(&bt);
171  }
172
173  ctx->binuptime_per_job[worker_index] = counter;
174}
175
176static void test_bintime_null_fini(
177  rtems_test_parallel_context *base,
178  void *arg,
179  size_t active_workers
180)
181{
182  timecounter_context *ctx = (timecounter_context *) base;
183  size_t i;
184
185  printf("  <BinuptimeNullTest activeWorker=\"%zu\">\n", active_workers);
186
187  for (i = 0; i < active_workers; ++i) {
188    printf(
189      "    <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n",
190      i + 1,
191      ctx->binuptime_per_job[i]
192    );
193  }
194
195  printf("  </BinuptimeNullTest>\n");
196}
197
198static const rtems_test_parallel_job timecounter_jobs[] = {
199  {
200    .init = test_bintime_init,
201    .body = test_bintime_body,
202    .fini = test_bintime_fini,
203    .cascade = true
204  },{
205    .init = test_bintime_null_init,
206    .body = test_bintime_null_body,
207    .fini = test_bintime_null_fini,
208    .cascade = true
209  }
210};
211
212static void Init(rtems_task_argument arg)
213{
214  timecounter_context *ctx = &test_instance;
215  struct bintime bt;
216  struct timespec ts;
217  struct timeval tv;
218
219  TEST_BEGIN();
220
221  printf("<SPTimecounter01>\n");
222
223  rtems_test_parallel(
224    &ctx->base,
225    NULL,
226    &timecounter_jobs[0],
227    RTEMS_ARRAY_SIZE(timecounter_jobs)
228  );
229
230  /* Check for all functions available in the bsd.h user space */
231
232  rtems_bsd_bintime(&bt);
233  rtems_bsd_microtime(&tv);
234  rtems_bsd_nanotime(&ts);
235  rtems_bsd_binuptime(&bt);
236  rtems_bsd_microuptime(&tv);
237  rtems_bsd_nanouptime(&ts);
238  rtems_bsd_getbintime(&bt);
239  rtems_bsd_getmicrotime(&tv);
240  rtems_bsd_getnanotime(&ts);
241  rtems_bsd_getbinuptime(&bt);
242  rtems_bsd_getmicrouptime(&tv);
243  rtems_bsd_getnanouptime(&ts);
244
245  printf("</SPTimecounter01>\n");
246
247  TEST_END();
248  rtems_test_exit(0);
249}
250
251#define CONFIGURE_MICROSECONDS_PER_TICK 1000
252
253#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
254#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
255
256#define CONFIGURE_MAXIMUM_TASKS (2 + CPU_COUNT - 1)
257#define CONFIGURE_MAXIMUM_TIMERS 2
258#define CONFIGURE_MAXIMUM_PERIODS 1
259
260#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
261
262#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
263
264#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
265
266#define CONFIGURE_INIT
267
268#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.