From patchwork Fri Mar 5 20:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42287 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92318382D437; Fri, 5 Mar 2021 20:15:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92318382D437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975334; bh=Mhok5SGKH7UQlPXI+b3WKoGEwF/VT4G1cvuUvu3HP4c=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LedO+tywS6KfdKIaforzIvKItflCNoKoeUwx4A+RFutMWlPwomcIbi3gP6WkabKa0 veS+nAJr60E0X7LFWogM4fbIM7+2lc0Pq7Hnosg3wW6tO2Iuf5GLW+1qgvoMYlj5PV xYbI7fYctlqDHlNJJxT1MrGr/pmih6ShFuBG0qsc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id B02C1382D435 for ; Fri, 5 Mar 2021 20:15:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B02C1382D435 Received: by mail-qv1-xf2f.google.com with SMTP id s17so1608101qvr.12 for ; Fri, 05 Mar 2021 12:15:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mhok5SGKH7UQlPXI+b3WKoGEwF/VT4G1cvuUvu3HP4c=; b=oGjll6ofkl+N2GV7eWRc2DvAvDU+w37mJ427rRbuiHwYwMnZDa8oc1+P+40apNf4C/ oH5bL8I+qOM+M8vTAmpiChl6HXRPrcjNX/Kfg2q6AGKUs0YdmSQa3WTFv+DI4vmsuVeB CEtCgncEMEnniwGIuBXJ3z15fjdlc6bM5nJtPuioZmbh5/wVhHXa1PQjMSmxr6KJcrds 3OQWaKKS9bigXSdG2cPzBEJiP3un8WzBtXi869m5C2cW9OU9v1Y5hkINulx1X8x6UKQ7 FUkNXWJfBa3SJd/DdsiY4A6GGYf69rQiuen4Gz5U5y/QDmPChXau0NtXMRnrxnh3htuM mzdg== X-Gm-Message-State: AOAM530o8Cedu1YlIJZxcEF/h17yJA9dVReziYTyi3gub2kHwSxq8sOV DwK8VELww/Zlm9zdHwECwkWgY81mp9QPow== X-Google-Smtp-Source: ABdhPJwzDle8u6vdEMibOd77yBRsWzsDbCIBHSTkMplHrG5XIw12kNcz0rQmjWO+LeUOxdlmvorZEw== X-Received: by 2002:a05:6214:194f:: with SMTP id q15mr10723973qvk.46.1614975329081; Fri, 05 Mar 2021 12:15:29 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:28 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 05/52] time: Add gmtime/gmtime_r tests Date: Fri, 5 Mar 2021 17:14:31 -0300 Message-Id: <20210305201518.798584-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210305201518.798584-1-adhemerval.zanella@linaro.org> References: <20210305201518.798584-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Checked on x86_64-linux-gnu and i686-linux-gnu. --- time/Makefile | 3 +- time/tst-gmtime.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 time/tst-gmtime.c diff --git a/time/Makefile b/time/Makefile index ccc9eefd61..d52454bddc 100644 --- a/time/Makefile +++ b/time/Makefile @@ -48,7 +48,8 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \ 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-itimer + tst-adjtime tst-ctime tst-difftime tst-mktime4 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