1 | /* |
---|
2 | * Copyright (c) 2011 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Obere Lagerstr. 30 |
---|
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.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <tmacros.h> |
---|
20 | |
---|
21 | #include <time.h> |
---|
22 | #include <string.h> |
---|
23 | |
---|
24 | #include <rtems.h> |
---|
25 | |
---|
26 | /* forward declarations to avoid warnings */ |
---|
27 | rtems_task Init(rtems_task_argument argument); |
---|
28 | |
---|
29 | #define TEST_APPLICABLE \ |
---|
30 | (CPU_TIMESTAMP_USE_INT64 == TRUE || CPU_TIMESTAMP_USE_INT64_INLINE == TRUE) |
---|
31 | |
---|
32 | #define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL) |
---|
33 | |
---|
34 | static const uint32_t sample_seconds [] = { |
---|
35 | 571213695UL, |
---|
36 | 602836095UL, |
---|
37 | 634372095UL, |
---|
38 | 665908095UL, |
---|
39 | 697444095UL, |
---|
40 | 729066495UL, |
---|
41 | 760602495UL, |
---|
42 | 792138495UL, |
---|
43 | 823674495UL, |
---|
44 | 855296895UL, |
---|
45 | 886832895UL, |
---|
46 | 918368895UL, |
---|
47 | 949904895UL, |
---|
48 | 981527295UL, |
---|
49 | 1013063295UL, |
---|
50 | 1044599295UL, |
---|
51 | 1076135295UL, |
---|
52 | 1107757695UL, |
---|
53 | 1139293695UL, |
---|
54 | 1170829695UL, |
---|
55 | 1202365695UL, |
---|
56 | 1233988095UL, |
---|
57 | 1265524095UL, |
---|
58 | 1297060095UL, |
---|
59 | 1328596095UL, |
---|
60 | 1360218495UL, |
---|
61 | 1391754495UL, |
---|
62 | 1423290495UL, |
---|
63 | 1454826495UL, |
---|
64 | 1486448895UL, |
---|
65 | 1517984895UL, |
---|
66 | 1549520895UL, |
---|
67 | 1581056895UL, |
---|
68 | 1612679295UL, |
---|
69 | 1644215295UL, |
---|
70 | 1675751295UL, |
---|
71 | 1707287295UL, |
---|
72 | 1738909695UL, |
---|
73 | 1770445695UL, |
---|
74 | 1801981695UL, |
---|
75 | 1833517695UL, |
---|
76 | 1865140095UL, |
---|
77 | 1896676095UL, |
---|
78 | 1928212095UL, |
---|
79 | 1959748095UL, |
---|
80 | 1991370495UL, |
---|
81 | 2022906495UL, |
---|
82 | 2054442495UL, |
---|
83 | 2085978495UL, |
---|
84 | 2117600895UL, |
---|
85 | 2149136895UL, |
---|
86 | 2180672895UL, |
---|
87 | 2212208895UL, |
---|
88 | 2243831295UL, |
---|
89 | 2275367295UL, |
---|
90 | 2306903295UL, |
---|
91 | 2338439295UL, |
---|
92 | 2370061695UL, |
---|
93 | 2401597695UL, |
---|
94 | 2433133695UL, |
---|
95 | 2464669695UL, |
---|
96 | 2496292095UL, |
---|
97 | 2527828095UL, |
---|
98 | 2559364095UL, |
---|
99 | 2590900095UL, |
---|
100 | 2622522495UL, |
---|
101 | 2654058495UL, |
---|
102 | 2685594495UL, |
---|
103 | 2717130495UL, |
---|
104 | 2748752895UL, |
---|
105 | 2780288895UL, |
---|
106 | 2811824895UL, |
---|
107 | 2843360895UL, |
---|
108 | 2874983295UL, |
---|
109 | 2906519295UL, |
---|
110 | 2938055295UL, |
---|
111 | 2969591295UL, |
---|
112 | 3001213695UL, |
---|
113 | 3032749695UL, |
---|
114 | 3064285695UL, |
---|
115 | 3095821695UL, |
---|
116 | 3127444095UL, |
---|
117 | 3158980095UL, |
---|
118 | 3190516095UL, |
---|
119 | 3222052095UL, |
---|
120 | 3253674495UL, |
---|
121 | 3285210495UL, |
---|
122 | 3316746495UL, |
---|
123 | 3348282495UL, |
---|
124 | 3379904895UL, |
---|
125 | 3411440895UL, |
---|
126 | 3442976895UL, |
---|
127 | 3474512895UL, |
---|
128 | 3506135295UL, |
---|
129 | 3537671295UL, |
---|
130 | 3569207295UL, |
---|
131 | 3600743295UL, |
---|
132 | 3632365695UL, |
---|
133 | 3663901695UL, |
---|
134 | 3695437695UL, |
---|
135 | 3726973695UL, |
---|
136 | 3758596095UL, |
---|
137 | 3790132095UL, |
---|
138 | 3821668095UL, |
---|
139 | 3853204095UL, |
---|
140 | 3884826495UL, |
---|
141 | 3916362495UL, |
---|
142 | 3947898495UL, |
---|
143 | 3979434495UL, |
---|
144 | 4011056895UL, |
---|
145 | 4042592895UL, |
---|
146 | 4074128895UL, |
---|
147 | 4105664895UL, |
---|
148 | 4137200895UL, |
---|
149 | 4168736895UL, |
---|
150 | 4200272895UL, |
---|
151 | 4231808895UL, |
---|
152 | 4263431295UL, |
---|
153 | 4294967295UL |
---|
154 | }; |
---|
155 | |
---|
156 | static const rtems_time_of_day nearly_problem_2038 = { |
---|
157 | .year = 2038, |
---|
158 | .month = 1, |
---|
159 | .day = 19, |
---|
160 | .hour = 3, |
---|
161 | .minute = 14, |
---|
162 | .second = 7 |
---|
163 | }; |
---|
164 | |
---|
165 | static const rtems_time_of_day problem_2038 = { |
---|
166 | .year = 2038, |
---|
167 | .month = 1, |
---|
168 | .day = 19, |
---|
169 | .hour = 3, |
---|
170 | .minute = 14, |
---|
171 | .second = 8 |
---|
172 | }; |
---|
173 | |
---|
174 | static const rtems_time_of_day nearly_problem_2106 = { |
---|
175 | .year = 2106, |
---|
176 | .month = 2, |
---|
177 | .day = 7, |
---|
178 | .hour = 6, |
---|
179 | .minute = 28, |
---|
180 | .second = 15 |
---|
181 | }; |
---|
182 | |
---|
183 | static const rtems_time_of_day problem_2106 = { |
---|
184 | .year = 2106, |
---|
185 | .month = 2, |
---|
186 | .day = 7, |
---|
187 | .hour = 6, |
---|
188 | .minute = 28, |
---|
189 | .second = 16 |
---|
190 | }; |
---|
191 | |
---|
192 | static void test_tod_to_seconds(void) |
---|
193 | { |
---|
194 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
195 | size_t i = 0; |
---|
196 | size_t n = sizeof(sample_seconds) / sizeof(sample_seconds [0]); |
---|
197 | |
---|
198 | for (i = 0; i < n; ++i) { |
---|
199 | rtems_time_of_day tod = nearly_problem_2106; |
---|
200 | uint32_t seconds = 0; |
---|
201 | rtems_interval seconds_as_interval = 0; |
---|
202 | |
---|
203 | tod.year = 1988 + i; |
---|
204 | seconds = _TOD_To_seconds(&tod); |
---|
205 | rtems_test_assert(seconds == sample_seconds [i]); |
---|
206 | |
---|
207 | sc = rtems_clock_set(&tod); |
---|
208 | ASSERT_SC(sc); |
---|
209 | |
---|
210 | sc = rtems_clock_get_seconds_since_epoch(&seconds_as_interval); |
---|
211 | ASSERT_SC(sc); |
---|
212 | rtems_test_assert(seconds_as_interval == sample_seconds [i]); |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | static void test_problem_year(void) |
---|
217 | { |
---|
218 | #if TEST_APPLICABLE |
---|
219 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
220 | time_t zero = 0; |
---|
221 | time_t one = 1; |
---|
222 | time_t maybe_negative = zero - one; |
---|
223 | bool time_t_is_32_bit = sizeof(time_t) == 4; |
---|
224 | bool time_t_is_signed = maybe_negative < zero; |
---|
225 | |
---|
226 | if (time_t_is_32_bit) { |
---|
227 | const rtems_time_of_day *nearly_problem = NULL; |
---|
228 | const rtems_time_of_day *problem = NULL; |
---|
229 | rtems_time_of_day now; |
---|
230 | |
---|
231 | if (time_t_is_signed) { |
---|
232 | nearly_problem = &nearly_problem_2038; |
---|
233 | problem = &problem_2038; |
---|
234 | } else { |
---|
235 | nearly_problem = &nearly_problem_2106; |
---|
236 | problem = &problem_2106; |
---|
237 | } |
---|
238 | |
---|
239 | sc = rtems_clock_set(nearly_problem); |
---|
240 | ASSERT_SC(sc); |
---|
241 | sc = rtems_clock_get_tod(&now); |
---|
242 | ASSERT_SC(sc); |
---|
243 | rtems_test_assert(memcmp(&now, nearly_problem, sizeof(now)) == 0); |
---|
244 | |
---|
245 | sc = rtems_clock_set(problem); |
---|
246 | ASSERT_SC(sc); |
---|
247 | sc = rtems_clock_get_tod(&now); |
---|
248 | ASSERT_SC(sc); |
---|
249 | rtems_test_assert(memcmp(&now, problem, sizeof(now)) == 0); |
---|
250 | } |
---|
251 | #endif /* TEST_APPLICABLE */ |
---|
252 | } |
---|
253 | |
---|
254 | rtems_task Init(rtems_task_argument argument) |
---|
255 | { |
---|
256 | puts("\n\n*** TEST 2038 ***"); |
---|
257 | |
---|
258 | test_tod_to_seconds(); |
---|
259 | test_problem_year(); |
---|
260 | |
---|
261 | puts("*** END OF TEST 2038 ***"); |
---|
262 | |
---|
263 | rtems_test_exit(0); |
---|
264 | } |
---|
265 | |
---|
266 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
267 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
268 | |
---|
269 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
270 | |
---|
271 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
272 | |
---|
273 | #define CONFIGURE_INIT |
---|
274 | |
---|
275 | #include <rtems/confdefs.h> |
---|