source: rtems/testsuites/sptests/sptimecounter01/init.c @ 8d989c5

5
Last change on this file since 8d989c5 was 8d989c5, checked in by Sebastian Huber <sebastian.huber@…>, on 10/01/19 at 11:48:27

score: Install timecounter according to quality

This makes it possible to install higher quality timecounter in
plug-and-play systems and helps to override the clock driver provided
timecounter in some test scenarios.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2015, 2019 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 <assert.h>
22
23#include <bsp/bootcard.h>
24
25#include <rtems/score/timecounterimpl.h>
26#include <rtems/score/todimpl.h>
27#include <rtems/timecounter.h>
28#include <rtems/bsd.h>
29
30const char rtems_test_name[] = "SPTIMECOUNTER 1";
31
32#define TEST_QUAL 1234
33
34#define TEST_FREQ 1000000
35
36typedef struct {
37  struct timecounter tc;
38  uint32_t counter;
39  struct timecounter tc_2;
40  uint32_t counter_2;
41} test_context;
42
43static test_context test_instance;
44
45static uint32_t test_get_timecount(struct timecounter *tc)
46{
47  test_context *ctx;
48
49  ctx = RTEMS_CONTAINER_OF(tc, test_context, tc);
50  ++ctx->counter;
51
52  return ctx->counter;
53}
54
55static uint32_t test_get_timecount_2(struct timecounter *tc)
56{
57  test_context *ctx;
58
59  ctx = RTEMS_CONTAINER_OF(tc, test_context, tc_2);
60  ++ctx->counter_2;
61
62  return ctx->counter_2;
63}
64
65static void test_install(test_context *ctx)
66{
67  struct timecounter *tc;
68  struct timecounter *tc_2;
69  uint32_t c;
70  uint32_t c_2;
71
72  tc = &ctx->tc;
73  tc_2 = &ctx->tc_2;
74  c = ctx->counter;
75  c_2 = ctx->counter_2;
76
77  tc_2->tc_get_timecount = test_get_timecount_2;
78  tc_2->tc_counter_mask = 0x0fffffff;
79  tc_2->tc_frequency = TEST_FREQ - 1;
80  tc_2->tc_quality = TEST_QUAL;
81  _Timecounter_Install(tc_2);
82  assert(ctx->counter == c);
83  assert(ctx->counter_2 == c_2);
84
85  tc_2->tc_get_timecount = test_get_timecount_2;
86  tc_2->tc_counter_mask = 0x0fffffff;
87  tc_2->tc_frequency = TEST_FREQ - 1;
88  tc_2->tc_quality = TEST_QUAL + 1;
89  _Timecounter_Install(tc_2);
90  assert(ctx->counter == c + 1);
91  assert(ctx->counter_2 == c_2 + 1);
92
93  tc->tc_get_timecount = test_get_timecount;
94  tc->tc_counter_mask = 0x0fffffff;
95  tc->tc_frequency = TEST_FREQ;
96  tc->tc_quality = TEST_QUAL + 1;
97  _Timecounter_Install(tc);
98  assert(ctx->counter == c + 2);
99  assert(ctx->counter_2 == c_2 + 2);
100}
101
102void boot_card(const char *cmdline)
103{
104  test_context *ctx;
105  struct timecounter *tc;
106  struct bintime bt;
107  struct timeval tv;
108  struct timespec ts;
109
110  ctx = &test_instance;
111  tc = &ctx->tc;
112
113  TEST_BEGIN();
114
115  assert(time(NULL) == TOD_SECONDS_1970_THROUGH_1988);
116
117  rtems_bsd_bintime(&bt);
118  assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988);
119  assert(bt.frac == 0);
120
121  rtems_bsd_getbintime(&bt);
122  assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988);
123  assert(bt.frac == 0);
124
125  rtems_bsd_microtime(&tv);
126  assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
127  assert(tv.tv_usec == 0);
128
129  rtems_bsd_getmicrotime(&tv);
130  assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
131  assert(tv.tv_usec == 0);
132
133  rtems_bsd_nanotime(&ts);
134  assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
135  assert(ts.tv_nsec == 0);
136
137  rtems_bsd_getnanotime(&ts);
138  assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
139  assert(ts.tv_nsec == 0);
140
141  assert(rtems_clock_get_uptime_seconds() == 0);
142  assert(rtems_clock_get_uptime_nanoseconds() == 0);
143
144  rtems_bsd_binuptime(&bt);
145  assert(bt.sec == 1);
146  assert(bt.frac == 0);
147
148  rtems_bsd_getbinuptime(&bt);
149  assert(bt.sec == 1);
150  assert(bt.frac == 0);
151
152  rtems_bsd_microuptime(&tv);
153  assert(tv.tv_sec == 1);
154  assert(tv.tv_usec == 0);
155
156  rtems_bsd_getmicrouptime(&tv);
157  assert(tv.tv_sec == 1);
158  assert(tv.tv_usec == 0);
159
160  rtems_bsd_nanouptime(&ts);
161  assert(ts.tv_sec == 1);
162  assert(ts.tv_nsec == 0);
163
164  rtems_bsd_getnanouptime(&ts);
165  assert(ts.tv_sec == 1);
166  assert(ts.tv_nsec == 0);
167
168  /* On RTEMS time does not advance using the dummy timecounter */
169  rtems_bsd_binuptime(&bt);
170  assert(bt.sec == 1);
171  assert(bt.frac == 0);
172
173  rtems_timecounter_tick();
174  rtems_bsd_binuptime(&bt);
175  assert(bt.sec == 1);
176  assert(bt.frac == 0);
177
178  ctx->counter = 0;
179  tc->tc_get_timecount = test_get_timecount;
180  tc->tc_counter_mask = 0x0fffffff;
181  tc->tc_frequency = TEST_FREQ;
182  tc->tc_quality = TEST_QUAL;
183  _Timecounter_Install(tc);
184  assert(ctx->counter == 1);
185
186  rtems_bsd_binuptime(&bt);
187  assert(ctx->counter == 2);
188
189  assert(bt.sec == 1);
190  assert(bt.frac == 18446744073708);
191
192  ctx->counter = 0xf0000000 | 1;
193  rtems_bsd_binuptime(&bt);
194  assert(ctx->counter == (0xf0000000 | 2));
195
196  assert(bt.sec == 1);
197  assert(bt.frac == 18446744073708);
198
199  /* Ensure that the fraction overflows and the second remains constant */
200  ctx->counter = (0xf0000000 | 1) + TEST_FREQ;
201  rtems_bsd_binuptime(&bt);
202  assert(ctx->counter == (0xf0000000 | 2) + TEST_FREQ);
203  assert(bt.sec == 1);
204  assert(bt.frac == 18446742522092);
205
206  test_install(ctx);
207
208  TEST_END();
209
210  _Terminate(RTEMS_FATAL_SOURCE_EXIT, 0);
211}
212
213#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
214
215#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
216
217#define CONFIGURE_DISABLE_NEWLIB_REENTRANCY
218
219#define CONFIGURE_SCHEDULER_USER
220
221#define CONFIGURE_SCHEDULER
222
223#define CONFIGURE_SCHEDULER_TABLE_ENTRIES { }
224
225#define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER 0
226
227#define CONFIGURE_TASK_STACK_ALLOCATOR NULL
228
229#define CONFIGURE_TASK_STACK_DEALLOCATOR NULL
230
231#define CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION
232
233#define CONFIGURE_IDLE_TASK_BODY NULL
234
235#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
236
237#define CONFIGURE_INIT
238
239#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.