1 /* Common tests for utimensat routines.
2 Copyright (C) 2021 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 /* Y2038 threshold minus 2 and 1 seconds. */
34 { 0x7FFFFFFELL
, 0x7FFFFFFFLL
},
35 /* Y2038 threshold plus 1 and 2 seconds. */
36 { 0x80000001LL
, 0x80000002LL
},
37 /* Around Y2038 threshold. */
38 { 0x7FFFFFFELL
, 0x80000002LL
},
39 /* Y2106 threshold minus 2 and 1 seconds. */
40 { 0x100000000LL
, 0xFFFFFFFELL
},
41 /* Y2106 threshold plus 1 and 2 seconds. */
42 { 0x100000001LL
, 0x100000002LL
},
43 /* Around Y2106 threshold. */
44 { 0xFFFFFFFELL
, 0xFFFFFFFELL
},
47 #define PREPARE do_prepare
49 do_prepare (int argc
, char *argv
[])
51 temp_fd
= create_temp_file ("utime", &testfile
);
52 TEST_VERIFY_EXIT (temp_fd
> 0);
54 testlink
= xasprintf ("%s-symlink", testfile
);
55 xsymlink (testfile
, testlink
);
56 add_temp_file (testlink
);
62 if (!support_path_support_time64 (testfile
))
63 FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps",
66 bool y2106
= support_path_support_time64_value (testfile
,
70 for (int i
= 0; i
< array_length (tests
); i
++)
72 /* Check if we run on port with 32 bit time_t size. */
74 if (__builtin_add_overflow (tests
[i
].v1
, 0, &t
)
75 || __builtin_add_overflow (tests
[i
].v2
, 0, &t
))
77 printf ("warning: skipping tests[%d] { %" PRIx64
", %" PRIx64
" }: "
78 "time_t overflows\n", i
, tests
[i
].v1
, tests
[i
].v2
);
82 if (tests
[i
].v1
>= 0x100000000LL
&& !y2106
)
84 printf ("warning: skipping tests[%d] { %" PRIx64
", %" PRIx64
" }: "
85 "unsupported timestamp value\n",
86 i
, tests
[i
].v1
, tests
[i
].v2
);
90 TEST_CALL (testfile
, temp_fd
, testlink
, tests
[i
].v1
, tests
[i
].v2
);
96 #include <support/test-driver.c>