1 /* Time bounds setting test
2 * by: john stultz (johnstul@us.ibm.com)
3 * (C) Copyright IBM 2012
4 * Licensed under the GPLv2
6 * NOTE: This is a meta-test which sets the time to edge cases then
7 * uses other tests to detect problems. Thus this test requires that
8 * the inconsistency-check and nanosleep tests be present in the same
9 * directory it is run from.
12 * $ gcc set-2038.c -o set-2038 -lrt
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
30 #include "../kselftest.h"
32 #define NSEC_PER_SEC 1000000000LL
34 #define KTIME_MAX ((long long)~((unsigned long long)1 << 63))
35 #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
37 #define YEAR_1901 (-0x7fffffffL)
39 #define YEAR_2038 0x7fffffffL /*overflows 32bit time_t */
40 #define YEAR_2262 KTIME_SEC_MAX /*overflows 64bit ktime_t */
41 #define YEAR_MAX ((long long)((1ULL<<63)-1)) /*overflows 64bit time_t */
45 return (sizeof(long) == 4);
48 int settime(long long time
)
53 now
.tv_sec
= (time_t)time
;
56 ret
= settimeofday(&now
, NULL
);
58 printf("Setting time to 0x%lx: %d\n", (long)time
, ret
);
67 ret
= system("./inconsistency-check -c 0 -t 20");
68 ret
|= system("./nanosleep");
69 ret
|= system("./nsleep-lat");
74 int main(int argc
, char *argv
[])
77 int opt
, dangerous
= 0;
80 /* Process arguments */
81 while ((opt
= getopt(argc
, argv
, "d")) != -1) {
90 /* First test that crazy values don't work */
91 if (!settime(YEAR_1901
)) {
95 if (!settime(YEAR_MAX
)) {
99 if (!is32bits() && !settime(YEAR_2262
)) {
104 /* Now test behavior near edges */
110 settime(YEAR_2038
- 600);
115 /* The rest of the tests can blowup on 32bit systems */
116 if (is32bits() && !dangerous
)
118 /* Test rollover behavior 32bit edge */
119 settime(YEAR_2038
- 10);
124 settime(YEAR_2262
- 600);
131 return ksft_exit_fail();
132 return ksft_exit_pass();