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 | |
---|
33 | static const rtems_time_of_day nearly_problem_2038 = { |
---|
34 | .year = 2038, |
---|
35 | .month = 1, |
---|
36 | .day = 19, |
---|
37 | .hour = 3, |
---|
38 | .minute = 14, |
---|
39 | .second = 7 |
---|
40 | }; |
---|
41 | |
---|
42 | static const rtems_time_of_day problem_2038 = { |
---|
43 | .year = 2038, |
---|
44 | .month = 1, |
---|
45 | .day = 19, |
---|
46 | .hour = 3, |
---|
47 | .minute = 14, |
---|
48 | .second = 8 |
---|
49 | }; |
---|
50 | |
---|
51 | static const rtems_time_of_day nearly_problem_2106 = { |
---|
52 | .year = 2106, |
---|
53 | .month = 2, |
---|
54 | .day = 7, |
---|
55 | .hour = 6, |
---|
56 | .minute = 28, |
---|
57 | .second = 15 |
---|
58 | }; |
---|
59 | |
---|
60 | static const rtems_time_of_day problem_2106 = { |
---|
61 | .year = 2106, |
---|
62 | .month = 2, |
---|
63 | .day = 7, |
---|
64 | .hour = 6, |
---|
65 | .minute = 28, |
---|
66 | .second = 16 |
---|
67 | }; |
---|
68 | |
---|
69 | static void test_case(void) |
---|
70 | { |
---|
71 | #if TEST_APPLICABLE |
---|
72 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
73 | int64_t one = 1; |
---|
74 | int64_t large = one << 32; |
---|
75 | time_t time_t_large = (time_t) large; |
---|
76 | bool time_t_is_32_bit = time_t_large != large; |
---|
77 | bool time_t_is_signed = (((time_t) 0) - ((time_t) 1)) < 0; |
---|
78 | |
---|
79 | if (time_t_is_32_bit) { |
---|
80 | const rtems_time_of_day *nearly_problem = NULL; |
---|
81 | const rtems_time_of_day *problem = NULL; |
---|
82 | rtems_time_of_day now; |
---|
83 | |
---|
84 | if (time_t_is_signed) { |
---|
85 | nearly_problem = &nearly_problem_2038; |
---|
86 | problem = &problem_2038; |
---|
87 | } else { |
---|
88 | nearly_problem = &nearly_problem_2106; |
---|
89 | problem = &problem_2106; |
---|
90 | } |
---|
91 | |
---|
92 | sc = rtems_clock_set(nearly_problem); |
---|
93 | ASSERT_SC(sc); |
---|
94 | sc = rtems_clock_get_tod(&now); |
---|
95 | ASSERT_SC(sc); |
---|
96 | rtems_test_assert(memcmp(&now, nearly_problem, sizeof(now)) == 0); |
---|
97 | |
---|
98 | sc = rtems_clock_set(problem); |
---|
99 | ASSERT_SC(sc); |
---|
100 | sc = rtems_clock_get_tod(&now); |
---|
101 | ASSERT_SC(sc); |
---|
102 | rtems_test_assert(memcmp(&now, problem, sizeof(now)) == 0); |
---|
103 | } |
---|
104 | #endif /* TEST_APPLICABLE */ |
---|
105 | } |
---|
106 | |
---|
107 | rtems_task Init(rtems_task_argument argument) |
---|
108 | { |
---|
109 | puts("\n\n*** TEST 2038 ***"); |
---|
110 | |
---|
111 | test_case(); |
---|
112 | |
---|
113 | puts("*** END OF TEST 2038 ***"); |
---|
114 | |
---|
115 | rtems_test_exit(0); |
---|
116 | } |
---|
117 | |
---|
118 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
119 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
120 | |
---|
121 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
122 | |
---|
123 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
124 | |
---|
125 | #define CONFIGURE_INIT |
---|
126 | |
---|
127 | #include <rtems/confdefs.h> |
---|