From patchwork Tue Mar 23 13:44:51 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: 42751 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 2A9C7385041F; Tue, 23 Mar 2021 13:45:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A9C7385041F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616507116; bh=NXLoWGYjyhtEfPiQq/GOnzGwsHebw6qxqubie6F6fVA=; 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=nr0TOOgf3m52p7FXyYkLI0S7ETW7a5LOoE6EZwAsOphAgDQef8cMiChJS4/LST9M+ gG9Gb0n1W1VVg93WvA2afE3rRX1FN8Y/cxpzWMenX4EyUGZi5JVhDpgWTGepMZ/8b0 gqidiyYD8PLY/J/3Lr9MG27AY7Uk6Av3S8K+sOLM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id A7308386103E for ; Tue, 23 Mar 2021 13:45:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A7308386103E Received: by mail-qk1-x733.google.com with SMTP id v70so14310739qkb.8 for ; Tue, 23 Mar 2021 06:45:12 -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=NXLoWGYjyhtEfPiQq/GOnzGwsHebw6qxqubie6F6fVA=; b=E92sMuQOkBeYTUCqNgKzjukg7j1Cw/6HptmEz+ATNknRCE4M0qL2crOu8SI8/bZw3B 1XeOvU3m5lxsndP/J/DNf44bTDF+VvTtHz3IDRPP83QDQue4lIiZX3VXosokJ2LpbkNN 1TxdBYLAUc9MOAQoTlcQYW86x6VwFFMbT+2IW7G6PqbVQ/e6EZZP9vxuMNa3QYMf6MLW SaYUbcyLJI8+aTDCXsHu5AxYuWjIABaAhsJ044/PQCPBnY5NX9liO17LSoTp0Bx7+/iQ Utrk88Tu92MkmL+30ownPH1Nxa6fDYZyy5IJHrmaSy4zSW0jjeKR/QXe+WzhMNls6Gzv aWYw== X-Gm-Message-State: AOAM530vaxwkA/VwSIQaYkjYUnsPcOXV9Sc8wokUnma3IOeFkB19bfr2 HOBJksf+XhGET/RApy004JusKGAq7I4odw== X-Google-Smtp-Source: ABdhPJy68fmaoNXeowiDbLCeafoB6HeRMXHd08omuhdiiGBddfTu2xbsDBiCq0EP+DPnaTxs3JZNug== X-Received: by 2002:ae9:ebc3:: with SMTP id b186mr5238718qkg.335.1616507111676; Tue, 23 Mar 2021 06:45:11 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id z24sm12783384qkz.65.2021.03.23.06.45.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 06:45:11 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 08/15] time: Add timegm/timelocal basic tests Date: Tue, 23 Mar 2021 10:44:51 -0300 Message-Id: <20210323134458.2563022-9-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.7 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 i686-linux-gnu and x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar --- time/Makefile | 2 +- time/tst-timegm.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 time/tst-timegm.c diff --git a/time/Makefile b/time/Makefile index a503297527..5fcd40ccbb 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-gmtime + tst-settimeofday tst-itimer tst-gmtime tst-timegm include ../Rules diff --git a/time/tst-timegm.c b/time/tst-timegm.c new file mode 100644 index 0000000000..3f4d21951a --- /dev/null +++ b/time/tst-timegm.c @@ -0,0 +1,95 @@ +/* Basic tests for timegm. + 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 void +do_test_func (time_t (*func)(struct tm *)) +{ + { + struct tm tmg = + { + .tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 0, + .tm_year = 70, + .tm_wday = 4, + .tm_yday = 0, + .tm_isdst = 0 + }; + time_t t = func (&tmg); + TEST_COMPARE (t, 0); + } + + { + struct tm tmg = + { + .tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = 0, + .tm_year = 138, + .tm_wday = 2, + .tm_yday = 18, + .tm_isdst = 0 + }; + time_t t = func (&tmg); + TEST_COMPARE (t, 0x7fffffff); + } + + if (sizeof (time_t) < 8) + return; + + { + struct tm tmg = + { + .tm_sec = 8, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = 0, + .tm_year = 138, + .tm_wday = 2, + .tm_yday = 18, + .tm_isdst = 0 + }; + time_t t = func (&tmg); + TEST_COMPARE (t, (time_t) 0x80000000ull); + } +} + +static int +do_test (void) +{ + do_test_func (timegm); + + /* timelocal is a alias to timegm with the only difference it takes local + timezone into account, while timegm takes the input value to be UTC. */ + TEST_VERIFY_EXIT (setenv ("TZ", ":", 1) == 0); + tzset (); + do_test_func (timelocal); + + return 0; +} + +#include