From patchwork Fri Mar 5 20:14:28 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: 42282 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 DBA7A382D42B; Fri, 5 Mar 2021 20:15:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBA7A382D42B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975328; bh=TvOgmnBZ4SjkK6leemq9t6D8nUhX8K6fAjlCt52zXrI=; 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=eMQVkOfCyuhu+EiUYIf/E9U6xOd65qVs/ZOb8tHqEybFb9/r2Syb3bdRxkg/55b4R wvgHrbRcJ0I1XjKgVm1+sSY/Fx+f9k1iG2Wf8lTTlTXE08qj/WZYl/Ml+yjv9anXRJ NrSfDJgz57EwEey5Xg8SxNQDcYMvW3Wr+SdP1D38= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 5BEDC382D42B for ; Fri, 5 Mar 2021 20:15:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5BEDC382D42B Received: by mail-qt1-x834.google.com with SMTP id 2so2795749qtw.1 for ; Fri, 05 Mar 2021 12:15:26 -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=TvOgmnBZ4SjkK6leemq9t6D8nUhX8K6fAjlCt52zXrI=; b=REyQToFNNPcY2hToLlxfe/jiPpCN4+mRSjmS0Czpq8PMm7h2aYIuZaM/zasQhgkJz4 bqOWPkg6qV5xgiPajfaPAQTf1WOrQDQwJxFLySTzk/77z/QjRL7W4zrE6aGlTRvoeDic 2x8V44SfPF/Y36eG68Jx9AcwRy61rcIr1DqXPQMOPWVChTxaAwhfg+OJxRAWvTrhXSia qfTbbq638vwmD66TqjTcRe554/qvuowbaI2bq8jVyuULdcyxBXCw3i76+zCXJ72ZxGuW EuNzkSjl5vdsWv2eGl60X302lfk4y1Zxhz/MHm4bzTqYzvBca/nNY4o24mWlDCakCG3N diHg== X-Gm-Message-State: AOAM533PkWyFyYqZqvp5wjIKZGtiYn2mGN4CQHUlkwrPMuywGGPOWYLE KDdw7LpiRGXpg9W0q/hN5Rh6Yf+k7MiY+A== X-Google-Smtp-Source: ABdhPJzp7Jx0VBu2kT4ol8IAcKtEHJHcrA8PFAjKaeQJzNQx9JXDaSxJ4Ei3Sx6ZTaNWSgLpuX9rbg== X-Received: by 2002:ac8:5d42:: with SMTP id g2mr10730402qtx.46.1614975325769; Fri, 05 Mar 2021 12:15:25 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:25 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 02/52] linux: Add futimes test Date: Fri, 5 Mar 2021 17:14:28 -0300 Message-Id: <20210305201518.798584-3-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" It uses stat to compare against the values set by futimes. Checked on i686-linux-gnu. --- sysdeps/unix/sysv/linux/Makefile | 4 +- sysdeps/unix/sysv/linux/tst-futimes.c | 85 +++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 sysdeps/unix/sysv/linux/tst-futimes.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 51e28b97ac..94b933310b 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -107,7 +107,9 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \ tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux \ - tst-timerfd tst-ppoll tst-futimens tst-utime tst-utimes + tst-timerfd tst-ppoll tst-futimens tst-utime tst-utimes \ + tst-futimes + tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables diff --git a/sysdeps/unix/sysv/linux/tst-futimes.c b/sysdeps/unix/sysv/linux/tst-futimes.c new file mode 100644 index 0000000000..026b0af023 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-futimes.c @@ -0,0 +1,85 @@ +/* Basix test for utimes. + 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 +#include +#include +#include +#include + +#ifndef struct_stat +# define struct_stat struct stat64 +#endif + +static int temp_fd = -1; +static char *testfile; + +/* struct timeval array with Y2038 threshold minus 2 and 1 seconds. */ +const static struct timeval t1[2] = { { 0x7FFFFFFE, 0 }, { 0x7FFFFFFF, 0 } }; + +/* struct timeval array with Y2038 threshold plus 1 and 2 seconds. */ +const static struct timeval t2[2] = { { 0x80000001ULL, 0 }, + { 0x80000002ULL, 0 } }; + +/* struct timeval array around Y2038 threshold. */ +const static struct timeval t3[2] = { { 0x7FFFFFFE, 0 }, + { 0x80000002ULL, 0 } }; + +#define PREPARE do_prepare +static void +do_prepare (int argc, char *argv[]) +{ + temp_fd = create_temp_file ("utimes", &testfile); + TEST_VERIFY_EXIT (temp_fd > 0); +} + +static int +test_utime_helper (const struct timeval *tv) +{ + /* Check if we run on port with 32 bit time_t size */ + time_t t; + if (__builtin_add_overflow (tv->tv_sec, 0, &t)) + return 0; + + TEST_VERIFY_EXIT (futimes (temp_fd, tv) == 0); + + struct_stat st; + xfstat (temp_fd, &st); + + /* Check if seconds for atime match */ + TEST_COMPARE (st.st_atime, tv[0].tv_sec); + + /* Check if seconds for mtime match */ + TEST_COMPARE (st.st_mtime, tv[1].tv_sec); + + return 0; +} + +static int +do_test (void) +{ + test_utime_helper (&t1[0]); + test_utime_helper (&t2[0]); + test_utime_helper (&t3[0]); + + return 0; +} + +#include