This source file includes following definitions.
- is32bits
- settime
- do_tests
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <time.h>
29 #include <sys/time.h>
30 #include "../kselftest.h"
31
32 #define NSEC_PER_SEC 1000000000LL
33
34 #define KTIME_MAX ((long long)~((unsigned long long)1 << 63))
35 #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
36
37 #define YEAR_1901 (-0x7fffffffL)
38 #define YEAR_1970 1
39 #define YEAR_2038 0x7fffffffL
40 #define YEAR_2262 KTIME_SEC_MAX
41 #define YEAR_MAX ((long long)((1ULL<<63)-1))
42
43 int is32bits(void)
44 {
45 return (sizeof(long) == 4);
46 }
47
48 int settime(long long time)
49 {
50 struct timeval now;
51 int ret;
52
53 now.tv_sec = (time_t)time;
54 now.tv_usec = 0;
55
56 ret = settimeofday(&now, NULL);
57
58 printf("Setting time to 0x%lx: %d\n", (long)time, ret);
59 return ret;
60 }
61
62 int do_tests(void)
63 {
64 int ret;
65
66 ret = system("date");
67 ret = system("./inconsistency-check -c 0 -t 20");
68 ret |= system("./nanosleep");
69 ret |= system("./nsleep-lat");
70 return ret;
71
72 }
73
74 int main(int argc, char *argv[])
75 {
76 int ret = 0;
77 int opt, dangerous = 0;
78 time_t start;
79
80
81 while ((opt = getopt(argc, argv, "d")) != -1) {
82 switch (opt) {
83 case 'd':
84 dangerous = 1;
85 }
86 }
87
88 start = time(0);
89
90
91 if (!settime(YEAR_1901)) {
92 ret = -1;
93 goto out;
94 }
95 if (!settime(YEAR_MAX)) {
96 ret = -1;
97 goto out;
98 }
99 if (!is32bits() && !settime(YEAR_2262)) {
100 ret = -1;
101 goto out;
102 }
103
104
105 settime(YEAR_1970);
106 ret = do_tests();
107 if (ret)
108 goto out;
109
110 settime(YEAR_2038 - 600);
111 ret = do_tests();
112 if (ret)
113 goto out;
114
115
116 if (is32bits() && !dangerous)
117 goto out;
118
119 settime(YEAR_2038 - 10);
120 ret = do_tests();
121 if (ret)
122 goto out;
123
124 settime(YEAR_2262 - 600);
125 ret = do_tests();
126
127 out:
128
129 settime(start);
130 if (ret)
131 return ksft_exit_fail();
132 return ksft_exit_pass();
133 }