]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/tst-utimensat-skeleton.c
linux: Add y2106 support on utimensat tests
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / tst-utimensat-skeleton.c
1 /* Common tests for utimensat routines.
2 Copyright (C) 2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <array_length.h>
20 #include <inttypes.h>
21 #include <support/support.h>
22 #include <support/temp_file.h>
23 #include <stdio.h>
24
25 static int temp_fd = -1;
26 static char *testfile;
27
28 const static struct {
29 int64_t v1;
30 int64_t v2;
31 } tests[] = {
32 /* Y2038 threshold minus 2 and 1 seconds. */
33 { 0x7FFFFFFELL, 0x7FFFFFFFLL },
34 /* Y2038 threshold plus 1 and 2 seconds. */
35 { 0x80000001LL, 0x80000002LL },
36 /* Around Y2038 threshold. */
37 { 0x7FFFFFFELL, 0x80000002LL },
38 /* Y2106 threshold minus 2 and 1 seconds. */
39 { 0x100000000LL, 0xFFFFFFFELL },
40 /* Y2106 threshold plus 1 and 2 seconds. */
41 { 0x100000001LL, 0x100000002LL },
42 /* Around Y2106 threshold. */
43 { 0xFFFFFFFELL, 0xFFFFFFFELL },
44 };
45
46 #define PREPARE do_prepare
47 static void
48 do_prepare (int argc, char *argv[])
49 {
50 temp_fd = create_temp_file ("utime", &testfile);
51 TEST_VERIFY_EXIT (temp_fd > 0);
52 }
53
54 static int
55 do_test (void)
56 {
57 if (!support_path_support_time64 (testfile))
58 FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps",
59 testfile);
60
61 bool y2106 = support_path_support_time64_value (testfile,
62 0x100000001LL,
63 0x100000002LL);
64
65 for (int i = 0; i < array_length (tests); i++)
66 {
67 /* Check if we run on port with 32 bit time_t size. */
68 time_t t;
69 if (__builtin_add_overflow (tests[i].v1, 0, &t)
70 || __builtin_add_overflow (tests[i].v2, 0, &t))
71 {
72 printf ("warning: skipping tests[%d] { %" PRIx64 ", %" PRIx64 " }: "
73 "time_t overflows\n", i, tests[i].v1, tests[i].v2);
74 continue;
75 }
76
77 if (tests[i].v1 >= 0x100000000LL && !y2106)
78 {
79 printf ("warning: skipping tests[%d] { %" PRIx64 ", %" PRIx64 " }: "
80 "unsupported timestamp value\n",
81 i, tests[i].v1, tests[i].v2);
82 continue;
83 }
84
85 TEST_CALL (testfile, temp_fd, tests[i].v1, tests[i].v2);
86 }
87
88 return 0;
89 }
90
91 #include <support/test-driver.c>