From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 31E1E39DC4CB; Thu, 4 Mar 2021 11:30:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31E1E39DC4CB Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/y2038] time: Add gmtime tests X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/y2038 X-Git-Oldrev: 5702e40ff7cc0fa7c33a5c29c26903ef36a9840a X-Git-Newrev: 12cbfc1aec600ecf75cbde98ddb7e8ae083d5831 Message-Id: <20210304113038.31E1E39DC4CB@sourceware.org> Date: Thu, 4 Mar 2021 11:30:38 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Mar 2021 11:30:38 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=12cbfc1aec600ecf75cbde98ddb7e8ae083d5831 commit 12cbfc1aec600ecf75cbde98ddb7e8ae083d5831 Author: Adhemerval Zanella Date: Mon Mar 1 11:14:45 2021 -0300 time: Add gmtime tests Checked on x86_64-linux-gnu and i686-linux-gnu. Diff: --- time/Makefile | 2 +- time/tst-gmtime.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) diff --git a/time/Makefile b/time/Makefile index 8fe439c5e0..ed79f1cdb6 100644 --- a/time/Makefile +++ b/time/Makefile @@ -49,7 +49,7 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \ tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \ - tst-itimer + tst-itimer tst-gmtime include ../Rules diff --git a/time/tst-gmtime.c b/time/tst-gmtime.c new file mode 100644 index 0000000000..4d09cade79 --- /dev/null +++ b/time/tst-gmtime.c @@ -0,0 +1,125 @@ +/* Basic tests for gmtime. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +static int +do_test (void) +{ + /* Check if the epoch time can be converted. */ + { + time_t t = 0; + struct tm *tmg = gmtime (&t); + TEST_COMPARE (tmg->tm_sec, 0); + TEST_COMPARE (tmg->tm_min, 0); + TEST_COMPARE (tmg->tm_hour, 0); + TEST_COMPARE (tmg->tm_mday, 1); + TEST_COMPARE (tmg->tm_mon, 0); + TEST_COMPARE (tmg->tm_year, 70); + TEST_COMPARE (tmg->tm_wday, 4); + TEST_COMPARE (tmg->tm_yday, 0); + TEST_COMPARE (tmg->tm_isdst, 0); + } + { + /* Same as before but with gmtime_r. */ + time_t t = 0; + struct tm tms; + struct tm *tmg = gmtime_r (&t, &tms); + TEST_VERIFY (tmg == &tms); + TEST_COMPARE (tmg->tm_year, 70); + TEST_COMPARE (tmg->tm_sec, 0); + TEST_COMPARE (tmg->tm_min, 0); + TEST_COMPARE (tmg->tm_hour, 0); + TEST_COMPARE (tmg->tm_mday, 1); + TEST_COMPARE (tmg->tm_mon, 0); + TEST_COMPARE (tmg->tm_year, 70); + TEST_COMPARE (tmg->tm_wday, 4); + TEST_COMPARE (tmg->tm_yday, 0); + TEST_COMPARE (tmg->tm_isdst, 0); + } + + /* Check if the max time value for 32 bit time_t can be converted. */ + { + time_t t = 0x7fffffff; + struct tm *tmg = gmtime (&t); + TEST_COMPARE (tmg->tm_sec, 7); + TEST_COMPARE (tmg->tm_min, 14); + TEST_COMPARE (tmg->tm_hour, 3); + TEST_COMPARE (tmg->tm_mday, 19); + TEST_COMPARE (tmg->tm_mon, 0); + TEST_COMPARE (tmg->tm_year, 138); + TEST_COMPARE (tmg->tm_wday, 2); + TEST_COMPARE (tmg->tm_yday, 18); + TEST_COMPARE (tmg->tm_isdst, 0); + } + { + /* Same as before but with ctime_r. */ + time_t t = 0x7fffffff; + struct tm tms; + struct tm *tmg = gmtime_r (&t, &tms); + TEST_VERIFY (tmg == &tms); + TEST_COMPARE (tmg->tm_sec, 7); + TEST_COMPARE (tmg->tm_min, 14); + TEST_COMPARE (tmg->tm_hour, 3); + TEST_COMPARE (tmg->tm_mday, 19); + TEST_COMPARE (tmg->tm_mon, 0); + TEST_COMPARE (tmg->tm_year, 138); + TEST_COMPARE (tmg->tm_wday, 2); + TEST_COMPARE (tmg->tm_yday, 18); + TEST_COMPARE (tmg->tm_isdst, 0); + } + + if (sizeof (time_t) < 8) + return 0; + + { + time_t t = (time_t) 0x80000000ull; + struct tm *tmg = gmtime (&t); + TEST_COMPARE (tmg->tm_sec, 8); + TEST_COMPARE (tmg->tm_min, 14); + TEST_COMPARE (tmg->tm_hour, 3); + TEST_COMPARE (tmg->tm_mday, 19); + TEST_COMPARE (tmg->tm_mon, 0); + TEST_COMPARE (tmg->tm_year, 138); + TEST_COMPARE (tmg->tm_wday, 2); + TEST_COMPARE (tmg->tm_yday, 18); + TEST_COMPARE (tmg->tm_isdst, 0); + } + + { + time_t t = (time_t) 0x80000000ull; + struct tm tms; + struct tm *tmg = gmtime_r (&t, &tms); + TEST_VERIFY (tmg == &tms); + TEST_COMPARE (tmg->tm_sec, 8); + TEST_COMPARE (tmg->tm_min, 14); + TEST_COMPARE (tmg->tm_hour, 3); + TEST_COMPARE (tmg->tm_mday, 19); + TEST_COMPARE (tmg->tm_mon, 0); + TEST_COMPARE (tmg->tm_year, 138); + TEST_COMPARE (tmg->tm_wday, 2); + TEST_COMPARE (tmg->tm_yday, 18); + TEST_COMPARE (tmg->tm_isdst, 0); + } + + return 0; +} + +#include