From patchwork Fri Mar 5 20:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 42288 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 218DF3897812; Fri, 5 Mar 2021 20:15:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 218DF3897812 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975335; bh=Y1qv7+DMtn3vv+ujV19+ylGnf9KPP/KI/e34g10ZqMg=; 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=gliYav27svSTkHdpT4sN22HlW0mu8HWtQquW/vdRE7/uWa1W1ZD2okw2Co5lK2NIp 8KlggQ2u1+YXSIt9GofcG7JR8unB9peaL2YA8O+gQrQl9w1ru9NxnCO8+fWa3GwvTP 5aXOHsPPzJL2WbTtjadxOXt19Neo19zy34TgejqY= 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 B4828386F83C for ; Fri, 5 Mar 2021 20:15:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B4828386F83C Received: by mail-qv1-xf2f.google.com with SMTP id gi9so1615644qvb.10 for ; Fri, 05 Mar 2021 12:15:30 -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=Y1qv7+DMtn3vv+ujV19+ylGnf9KPP/KI/e34g10ZqMg=; b=E9istlE2dmY0RvXf6Jaf1/wKcMZ8XbdPVSyApBMWaJXoIh5gl2CIsLqigEYdy2Vrde CGRD9w/3SWhtzdE1ltBMusYPTfeDJklFWHdFyD0lxDHBlWz4Zy9MYHYaLJtPhmnHhp23 jSZLrKqfBQyGdBIgw5+4CkQaB4Q4YtsAhiPZbvWJLhEYNy2FZbb6+W3ud7Jhc/PgXLJn PzbtR8YVc4q/6xUfDTEVSzDOmdBenyN9vgyigNDS1oSeaB++ed/9zMt6POmbRCuR7yqJ 3gygODm/hxcEFZfzFyvzt75uHFm7Grz2esyiEyBBdhhyDj2vznM82C7MaWkzI23ithSd VD9A== X-Gm-Message-State: AOAM5321HXaZkp4Grhgf1L/HOEuMbTgY+aj/u4vDHIz0ElFXa2enbJIZ EMIx6Q3MNbuXpqmcAW8vAIyqpCIJ7x18bw== X-Google-Smtp-Source: ABdhPJx8EMcVXuSf3FwE9jTTuzAC3bEzDQxIsGDLB2L5J0htKX+B3GPJdzHLek2I3Y1e8FQm16Jz7A== X-Received: by 2002:a0c:b9a2:: with SMTP id v34mr10383802qvf.17.1614975330192; Fri, 05 Mar 2021 12:15:30 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:30 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 06/52] time: Add timegm/timelocal basic tests Date: Fri, 5 Mar 2021 17:14:32 -0300 Message-Id: <20210305201518.798584-7-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Checked i686-linux-gnu and x86_64-linux-gnu. --- 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 d52454bddc..786dc45b51 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-itimer \ - tst-gmtime + 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