source: rtems/testsuites/sptests/sp2038/init.c @ 0d57369

4.115
Last change on this file since 0d57369 was 0d57369, checked in by Sebastian Huber <sebastian.huber@…>, on 09/28/11 at 16:01:53

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

  • sp2038/Makefile.am, sp2038/init.c, sp2038/sp2038.doc, sp2038/sp2038.scn: New files.
  • Makefile.am, configure.ac: Reflect changes above.
  • Property mode set to 100644
File size: 2.6 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 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
42static 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
51static 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
60static 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
69static 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
107rtems_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>
Note: See TracBrowser for help on using the repository browser.