1 /* Common tests for utimensat routines.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <array_length.h>
21 #include <support/support.h>
22 #include <support/temp_file.h>
25 static int temp_fd
= -1;
26 static char *testfile
;
27 static char *testlink
;
33 /* Some arbitrary date before Y2038. */
34 { 0x60ECA720LL
, 0x60eca721LL
},
35 /* Y2038 threshold minus 2 and 1 seconds. */
36 { 0x7FFFFFFELL
, 0x7FFFFFFFLL
},
37 /* Y2038 threshold plus 1 and 2 seconds. */
38 { 0x80000001LL
, 0x80000002LL
},
39 /* Around Y2038 threshold. */
40 { 0x7FFFFFFELL
, 0x80000002LL
},
41 /* Y2106 threshold minus 2 and 1 seconds. */
42 { 0x100000000LL
, 0xFFFFFFFELL
},
43 /* Y2106 threshold plus 1 and 2 seconds. */
44 { 0x100000001LL
, 0x100000002LL
},
45 /* Around Y2106 threshold. */
46 { 0xFFFFFFFELL
, 0xFFFFFFFELL
},
49 #define PREPARE do_prepare
51 do_prepare (int argc
, char *argv
[])
53 temp_fd
= create_temp_file ("utime", &testfile
);
54 TEST_VERIFY_EXIT (temp_fd
> 0);
56 testlink
= xasprintf ("%s-symlink", testfile
);
57 xsymlink (testfile
, testlink
);
58 add_temp_file (testlink
);
64 if (sizeof (time_t) == 8 && !support_path_support_time64 (testfile
))
65 FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps",
68 bool y2106
= support_path_support_time64_value (testfile
,
72 for (int i
= 0; i
< array_length (tests
); i
++)
74 /* Check if we run on port with 32 bit time_t size. */
76 if (__builtin_add_overflow (tests
[i
].v1
, 0, &t
)
77 || __builtin_add_overflow (tests
[i
].v2
, 0, &t
))
79 printf ("warning: skipping tests[%d] { %" PRIx64
", %" PRIx64
" }: "
80 "time_t overflows\n", i
, tests
[i
].v1
, tests
[i
].v2
);
84 if (tests
[i
].v1
>= 0x100000000LL
&& !y2106
)
86 printf ("warning: skipping tests[%d] { %" PRIx64
", %" PRIx64
" }: "
87 "unsupported timestamp value\n",
88 i
, tests
[i
].v1
, tests
[i
].v2
);
92 TEST_CALL (testfile
, temp_fd
, testlink
, tests
[i
].v1
, tests
[i
].v2
);
98 #include <support/test-driver.c>