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 <assert.h> |
---|
20 | |
---|
21 | #include <bsp/bootcard.h> |
---|
22 | |
---|
23 | #include <rtems/test.h> |
---|
24 | |
---|
25 | #include <rtems/score/timecounterimpl.h> |
---|
26 | #include <rtems/score/todimpl.h> |
---|
27 | #include <rtems/score/watchdogimpl.h> |
---|
28 | #include <rtems/timecounter.h> |
---|
29 | #include <rtems/bsd.h> |
---|
30 | |
---|
31 | const char rtems_test_name[] = "SPTIMECOUNTER 1"; |
---|
32 | |
---|
33 | typedef struct { |
---|
34 | struct timecounter tc_soft; |
---|
35 | u_int tc_soft_counter; |
---|
36 | } test_context; |
---|
37 | |
---|
38 | static test_context test_instance; |
---|
39 | |
---|
40 | static uint32_t test_get_timecount_soft(struct timecounter *tc) |
---|
41 | { |
---|
42 | test_context *ctx = tc->tc_priv; |
---|
43 | |
---|
44 | ++ctx->tc_soft_counter; |
---|
45 | |
---|
46 | return ctx->tc_soft_counter; |
---|
47 | } |
---|
48 | |
---|
49 | void boot_card(const char *cmdline) |
---|
50 | { |
---|
51 | test_context *ctx = &test_instance; |
---|
52 | struct timecounter *tc_soft = &ctx->tc_soft; |
---|
53 | uint64_t soft_freq = 1000000; |
---|
54 | struct bintime bt; |
---|
55 | struct timeval tv; |
---|
56 | struct timespec ts; |
---|
57 | |
---|
58 | rtems_test_begink(); |
---|
59 | |
---|
60 | _Watchdog_Handler_initialization(); |
---|
61 | |
---|
62 | assert(time(NULL) == TOD_SECONDS_1970_THROUGH_1988); |
---|
63 | |
---|
64 | rtems_bsd_bintime(&bt); |
---|
65 | assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
66 | assert(bt.frac == 0); |
---|
67 | |
---|
68 | rtems_bsd_getbintime(&bt); |
---|
69 | assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
70 | assert(bt.frac == 0); |
---|
71 | |
---|
72 | rtems_bsd_microtime(&tv); |
---|
73 | assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
74 | assert(tv.tv_usec == 0); |
---|
75 | |
---|
76 | rtems_bsd_getmicrotime(&tv); |
---|
77 | assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
78 | assert(tv.tv_usec == 0); |
---|
79 | |
---|
80 | rtems_bsd_nanotime(&ts); |
---|
81 | assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
82 | assert(ts.tv_nsec == 0); |
---|
83 | |
---|
84 | rtems_bsd_getnanotime(&ts); |
---|
85 | assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
86 | assert(ts.tv_nsec == 0); |
---|
87 | |
---|
88 | assert(rtems_clock_get_uptime_seconds() == 0); |
---|
89 | assert(rtems_clock_get_uptime_nanoseconds() == 0); |
---|
90 | |
---|
91 | rtems_bsd_binuptime(&bt); |
---|
92 | assert(bt.sec == 1); |
---|
93 | assert(bt.frac == 0); |
---|
94 | |
---|
95 | rtems_bsd_getbinuptime(&bt); |
---|
96 | assert(bt.sec == 1); |
---|
97 | assert(bt.frac == 0); |
---|
98 | |
---|
99 | rtems_bsd_microuptime(&tv); |
---|
100 | assert(tv.tv_sec == 1); |
---|
101 | assert(tv.tv_usec == 0); |
---|
102 | |
---|
103 | rtems_bsd_getmicrouptime(&tv); |
---|
104 | assert(tv.tv_sec == 1); |
---|
105 | assert(tv.tv_usec == 0); |
---|
106 | |
---|
107 | rtems_bsd_nanouptime(&ts); |
---|
108 | assert(ts.tv_sec == 1); |
---|
109 | assert(ts.tv_nsec == 0); |
---|
110 | |
---|
111 | rtems_bsd_getnanouptime(&ts); |
---|
112 | assert(ts.tv_sec == 1); |
---|
113 | assert(ts.tv_nsec == 0); |
---|
114 | |
---|
115 | /* On RTEMS time does not advance using the dummy timecounter */ |
---|
116 | rtems_bsd_binuptime(&bt); |
---|
117 | assert(bt.sec == 1); |
---|
118 | assert(bt.frac == 0); |
---|
119 | |
---|
120 | rtems_timecounter_tick(); |
---|
121 | rtems_bsd_binuptime(&bt); |
---|
122 | assert(bt.sec == 1); |
---|
123 | assert(bt.frac == 0); |
---|
124 | |
---|
125 | ctx->tc_soft_counter = 0; |
---|
126 | tc_soft->tc_get_timecount = test_get_timecount_soft; |
---|
127 | tc_soft->tc_counter_mask = 0x0fffffff; |
---|
128 | tc_soft->tc_frequency = soft_freq; |
---|
129 | tc_soft->tc_quality = 1234; |
---|
130 | tc_soft->tc_priv = ctx; |
---|
131 | _Timecounter_Install(tc_soft); |
---|
132 | assert(ctx->tc_soft_counter == 3); |
---|
133 | |
---|
134 | rtems_bsd_binuptime(&bt); |
---|
135 | assert(ctx->tc_soft_counter == 4); |
---|
136 | |
---|
137 | assert(bt.sec == 1); |
---|
138 | assert(bt.frac == 18446744073708); |
---|
139 | |
---|
140 | ctx->tc_soft_counter = 0xf0000000 | 3; |
---|
141 | rtems_bsd_binuptime(&bt); |
---|
142 | assert(ctx->tc_soft_counter == (0xf0000000 | 4)); |
---|
143 | |
---|
144 | assert(bt.sec == 1); |
---|
145 | assert(bt.frac == 18446744073708); |
---|
146 | |
---|
147 | /* Ensure that the fraction overflows and the second remains constant */ |
---|
148 | ctx->tc_soft_counter = (0xf0000000 | 3) + soft_freq; |
---|
149 | rtems_bsd_binuptime(&bt); |
---|
150 | assert(ctx->tc_soft_counter == (0xf0000000 | 4) + soft_freq); |
---|
151 | assert(bt.sec == 1); |
---|
152 | assert(bt.frac == 18446742522092); |
---|
153 | |
---|
154 | rtems_test_endk(); |
---|
155 | |
---|
156 | _Terminate(RTEMS_FATAL_SOURCE_EXIT, false, 0); |
---|
157 | } |
---|
158 | |
---|
159 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
160 | |
---|
161 | #define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM |
---|
162 | |
---|
163 | #define CONFIGURE_DISABLE_NEWLIB_REENTRANCY |
---|
164 | |
---|
165 | #define CONFIGURE_SCHEDULER_USER |
---|
166 | |
---|
167 | #define CONFIGURE_SCHEDULER_CONTEXT |
---|
168 | |
---|
169 | #define CONFIGURE_SCHEDULER_CONTROLS { } |
---|
170 | |
---|
171 | #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER 0 |
---|
172 | |
---|
173 | #define CONFIGURE_TASK_STACK_ALLOCATOR NULL |
---|
174 | |
---|
175 | #define CONFIGURE_TASK_STACK_DEALLOCATOR NULL |
---|
176 | |
---|
177 | #define CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION |
---|
178 | |
---|
179 | #define CONFIGURE_IDLE_TASK_BODY NULL |
---|
180 | |
---|
181 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
182 | |
---|
183 | #define CONFIGURE_INIT |
---|
184 | |
---|
185 | #include <rtems/confdefs.h> |
---|