From patchwork Fri Mar 5 20:14:35 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: 42291 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 3FDD63951C10; Fri, 5 Mar 2021 20:15:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FDD63951C10 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975337; bh=3r8pocvVBiNgszvvzScxVORSJ4+ZRc5ruQGnCveYtww=; 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=y7uhLxKkqOfnG4pstttl7O83HPN5PcN3FHiyInkjIGnSNvVKdAT8AP/RFdDfsgGeX 2ywU7V5e/akDnUk5nkgWCP7fO4Hn/V50++fq7kIiJABM9o1CKj6xC0f4L0OsPH/z60 QCA0WQlylB8FtKEJmqAuj4552qK4loFUpIpzX0wQ= 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 19A313896835 for ; Fri, 5 Mar 2021 20:15:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 19A313896835 Received: by mail-qv1-xf2f.google.com with SMTP id 15so1603386qvp.13 for ; Fri, 05 Mar 2021 12:15:34 -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=3r8pocvVBiNgszvvzScxVORSJ4+ZRc5ruQGnCveYtww=; b=LLmstTgsnXTmMegUBhWFBbttoBpC1TIbu90+AqY7SFXNnBVut7cXaNxgyDZc6qoS7g lJBAO3aZl/kfobzPgxIUKXlccI8nZRc6xh3ZSp/R68LpV9RbbZ7g8Aj2odqOaWDSinxa Ob6imEMbhGMAXzUXn4e94o5o5jMI2V1dzB1hOUwpLh6gBTgCY1O5CVdcw2cxcSehbHOc 9jpGsSqCYHQKOtZOh1HnwKzRDsMxvEhawf0ZTVc0p9K9uyfRwXKNyyM1y05mXTTSwaGt nFp5/676Gwz/dYvtYWey2EQ6EoktQI+83AmE0ZLsxUNzPaqLXaaELyFZD5a5MNu1pnsL h7bA== X-Gm-Message-State: AOAM533KVXtPKv/am+9r6o67InorwcQY2Ky5bMcEMGqE+yjtML2KGjtn MzoK9k16Li+ZQ18M+rMX7yE90rGt5jr60g== X-Google-Smtp-Source: ABdhPJzHJZwz8268vEjzyRHLg6mP5GKDUB1XC/TEYhQC/cDRk7YCvVKJbjR+3tjfZAjFWM6HVJE3Ww== X-Received: by 2002:a0c:83a4:: with SMTP id k33mr10545253qva.1.1614975333494; Fri, 05 Mar 2021 12:15:33 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:33 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 09/52] io: Add basic tests for utimensat Date: Fri, 5 Mar 2021 17:14:35 -0300 Message-Id: <20210305201518.798584-10-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 --- io/Makefile | 2 +- io/tst-utimensat.c | 115 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 io/tst-utimensat.c diff --git a/io/Makefile b/io/Makefile index b7bebe923f..59d36e8782 100644 --- a/io/Makefile +++ b/io/Makefile @@ -68,7 +68,7 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \ tst-fts tst-fts-lfs tst-open-tmpfile \ tst-copy_file_range tst-getcwd-abspath tst-lockf \ tst-ftw-lnk tst-file_change_detection tst-lchmod \ - tst-ftw-bz26353 + tst-ftw-bz26353 tst-utimensat # Likewise for statx, but we do not need static linking here. tests-internal += tst-statx diff --git a/io/tst-utimensat.c b/io/tst-utimensat.c new file mode 100644 index 0000000000..b62e409e07 --- /dev/null +++ b/io/tst-utimensat.c @@ -0,0 +1,115 @@ +/* utimensat basic tests. + 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 +#include + +#ifndef struct_stat +# define struct_stat struct stat64 +#endif + +static int temp_fd = -1; +static char *testfile; +static char *testlink; + +/* struct timeval array with Y2038 threshold minus 2 and 1 seconds. */ +const static struct timespec t1[2] = { { 0x7FFFFFFE, 0 }, + { 0x7FFFFFFF, 0 } }; + +/* struct timeval array with Y2038 threshold plus 1 and 2 seconds. */ +const static struct timespec t2[2] = { { 0x80000001ULL, 0 }, + { 0x80000002ULL, 0 } }; + +/* struct timeval array around Y2038 threshold. */ +const static struct timespec t3[2] = { { 0x7FFFFFFE, 0 }, + { 0x80000002ULL, 0 } }; + +static void +do_prepare (int argc, char *argv[]) +{ + temp_fd = create_temp_file ("tst-utimensat", &testfile); + TEST_VERIFY_EXIT (temp_fd > 0); + + testlink = xasprintf ("%s-symlink", testfile); + xsymlink (testfile, testlink); + add_temp_file (testlink); +} +#define PREPARE do_prepare + +static void +test_utimensat_helper (const struct timespec ts[2]) +{ + /* Check if we run on port with 32 bit time_t size */ + { + time_t t; + if (__builtin_add_overflow (ts->tv_sec, 0, &t)) + return; + } + + { + TEST_VERIFY_EXIT (utimensat (temp_fd, testfile, ts, 0) == 0); + + struct_stat st; + xfstat (temp_fd, &st); + + /* Check if seconds for atime match */ + TEST_COMPARE (st.st_atime, ts[0].tv_sec); + + /* Check if seconds for mtime match */ + TEST_COMPARE (st.st_mtime, ts[1].tv_sec); + } + + { + struct_stat stfile_orig; + xlstat (testfile, &stfile_orig); + + TEST_VERIFY_EXIT (utimensat (0 /* ignored */, testlink, ts, + AT_SYMLINK_NOFOLLOW) + == 0); + struct_stat stlink; + xlstat (testlink, &stlink); + + TEST_COMPARE (stlink.st_atime, ts[0].tv_sec); + TEST_COMPARE (stlink.st_mtime, ts[1].tv_sec); + + /* Check if the timestamp from original file is not changed. */ + struct_stat stfile; + xlstat (testfile, &stfile); + + TEST_COMPARE (stfile_orig.st_atime, stfile.st_atime); + TEST_COMPARE (stfile_orig.st_mtime, stfile.st_mtime); + } +} + +static int +do_test (void) +{ + test_utimensat_helper (t1); + test_utimensat_helper (t2); + test_utimensat_helper (t3); + + return 0; +} + +#include