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/>. */
21 #include <support/check.h>
35 const struct tm tmY2038
=
45 const struct tm tm32bitmax
=
56 int test_mktime_helper (struct tm
*tm
, long long int exp_val
, int line
)
60 /* Check if we run on port with 32 bit time_t size. */
61 if (__builtin_add_overflow (exp_val
, 0, &t
))
65 if (result
== (time_t) -1)
66 FAIL_RET ("*** mktime failed: %m in line: %d", line
);
68 if ((long long int) result
!= exp_val
)
69 FAIL_RET ("*** Result different than expected (%lld != %lld) in %d\n",
70 (long long int) result
, exp_val
, line
);
79 /* Use glibc time zone extension "TZ=:" to to guarantee that UTC
80 without leap seconds is used for the test. */
81 TEST_VERIFY_EXIT (setenv ("TZ", ":", 1) == 0);
83 /* Check that mktime (1970-01-01 00:00:00) returns 0. */
85 test_mktime_helper (&t
, 0, __LINE__
);
87 /* Check that mktime (2038-01-19 03:14:07) returns 0x7FFFFFFF. */
89 test_mktime_helper (&t
, 0x7fffffff, __LINE__
);
91 /* Check that mktime (2038-01-19 03:14:08) returns 0x80000000
95 test_mktime_helper (&t
, 0x80000000, __LINE__
);
97 /* Check that mktime (2106-02-07 06:28:15) returns 0xFFFFFFFF. */
99 test_mktime_helper (&t
, 0xFFFFFFFF, __LINE__
);
101 /* Check that mktime (2106-02-07 06:28:16) returns 0x100000000. */
104 test_mktime_helper (&t
, 0x100000000, __LINE__
);
109 #include <support/test-driver.c>