From patchwork Tue Mar 23 13:44:50 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: 42750 X-Patchwork-Delegate: siddhesh@gotplt.org 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 96A3A385040A; Tue, 23 Mar 2021 13:45:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96A3A385040A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616507115; bh=e0j4mjqYNOP0rlyLNmxRznfrXQPveLBUa8/Xuis88Js=; 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=nd6o9MveSwTjfS8OPRR9HeRPi4sA650f2z3Xehk2+nUo/sDLKdJcNmd2dBxx5+8ge 8TSsHzM6/Uc/XcB57pEirlWrmwckoB9JFpdlZkXM7vKlfYYPKXPZo231cDooOPzayI mAuXsb0q3Xdp9uTk51dNSQHifGJ0jdwhVtGHU4M8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id 4C169385040A for ; Tue, 23 Mar 2021 13:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4C169385040A Received: by mail-qk1-x72c.google.com with SMTP id z10so14308887qkz.13 for ; Tue, 23 Mar 2021 06:45:11 -0700 (PDT) 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=e0j4mjqYNOP0rlyLNmxRznfrXQPveLBUa8/Xuis88Js=; b=Pq1FSo1M6Q/u9G8DNIrAEHH2m/juunS9trbjmvjTadvau/fIynXxCydYLylzS6rbja uROgEqMyHmWLbnvtHwt7gdHr8PQ96VuReK2NW865+EzvKSL10MreeBrd5oLd8PE3N/JG a9zpjY98X050+eXPlNf72eR7nwKvGCkcYMvxYJL+augzEvwA0a0RVQinHP3XigLIfOcK vK+SMf8hnojQg70ioJ7rCCzjd7vC4Hb8xRgd4YfZ85x5zGgB7PxmBssRyUbAiij/iMAl rouK9U/gROjFgeWhUQQw6WEX9KCVrfox+OdM0xuauK+1EicuG5jcGpkwOm68hyp7x55B RvPw== X-Gm-Message-State: AOAM533ewJffQOo/QfV9fa2REaMCXLPL27EgOOC4C2s5w9exWV/lMQg9 Nn9gepzzhX4EYczfozMx1ixm/5mwfkMGoQ== X-Google-Smtp-Source: ABdhPJyZWruMitI1OnowNyvmj2FYWknRjw6k8W9IbbfiqYpDiXOz2ccrbJ/a8ZSsIISLbpKTwI1OKA== X-Received: by 2002:a05:620a:22b5:: with SMTP id p21mr5568516qkh.196.1616507110397; Tue, 23 Mar 2021 06:45:10 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id z24sm12783384qkz.65.2021.03.23.06.45.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 06:45:10 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 07/15] time: Add gmtime/gmtime_r tests Date: Tue, 23 Mar 2021 10:44:50 -0300 Message-Id: <20210323134458.2563022-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210323134458.2563022-1-adhemerval.zanella@linaro.org> References: <20210323134458.2563022-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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. Reviewed-by: Siddhesh Poyarekar --- time/Makefile | 2 +- time/tst-gmtime.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 time/tst-gmtime.c diff --git a/time/Makefile b/time/Makefile index 91cb02a003..a503297527 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-settimeofday tst-itimer + tst-settimeofday 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