source: rtems/testsuites/sptests/sp2038/init.c @ fe7cc1ea

4.115
Last change on this file since fe7cc1ea was fe7cc1ea, checked in by Sebastian Huber <sebastian.huber@…>, on 09/29/11 at 09:40:32

2011-09-29 Sebastian Huber <sebastian.huber@…>

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