From patchwork Tue Mar 23 13:44:46 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: 42746 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 E51C4386103F; Tue, 23 Mar 2021 13:45:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E51C4386103F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616507110; bh=ld42uF0BKX/CGdowJNRv5/+bAidDG2eTv2JsaCiKlIk=; 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=Iepmqdqtu5V7O5fiGsavJNgX4T4txBxiCVJrQKwf0Qi19JQQjK/kVhcjufTYbF381 ZWlmfI8IgGbnQulhCwC9ekV9OvFM+YbBwaML7Te7A0mSZD44VJIFhendk/IVotouyZ eQhVkCRmfxyK9gcLMYKC43LlvV3WkFOfX+ZTRc7E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 479653861027 for ; Tue, 23 Mar 2021 13:45:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 479653861027 Received: by mail-qk1-x730.google.com with SMTP id i9so14295985qka.2 for ; Tue, 23 Mar 2021 06:45:06 -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=ld42uF0BKX/CGdowJNRv5/+bAidDG2eTv2JsaCiKlIk=; b=ahBELKbF8qZ2vKaRQvYpJFwVGCgtaXrEuvzexSMBoZXlyhuhKxJ/CMfr6XRDXQBF3K QHrvu6meEcGTDyS1ssS9gPt3bQV2blpMxAN479DwxhpjU4HTnU1xzzze690eF4sN9a4t zAG2iwNqRDSqo5hbgxEhMZuoAc9Vs9EOJvjM4+nJPqlyA8J8bWCmAgw4M6tCrakvoIv9 t7M1qcR5rliPXN0M8H+3J2cJt3IRLvcjp3unAMwGZqBZ6OvcSjk3s3UY6d1TIBdCFU39 cEqZK+p/WoIU3FZeWT3mdMn7wBnhy9gtRzz/JinhZhjwOI+yDR9E09li86WgEPD4Qhgo OZgw== X-Gm-Message-State: AOAM531M4scxAJcxPTC7DI9B9gmdt/O+yz7NTHCuIjTXcrMpqDQUVl/i A//Htcepmr9JFNDKlNLs3RiNysJEku7J2Q== X-Google-Smtp-Source: ABdhPJxq4+q7/bY3cjNZf4BHr9YtFEpxxpi6AI+QYSvqiDuL3b5U2lDkY6BLwUL8xkTAABeWzAEI5w== X-Received: by 2002:a05:620a:a92:: with SMTP id v18mr5441831qkg.417.1616507105596; Tue, 23 Mar 2021 06:45:05 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id z24sm12783384qkz.65.2021.03.23.06.45.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 06:45:05 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 03/15] linux: Add lutimes test Date: Tue, 23 Mar 2021 10:44:46 -0300 Message-Id: <20210323134458.2563022-4-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.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 lutimes. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Siddhesh Poyarekar --- io/Makefile | 1 + io/tst-futimens.c | 2 +- io/tst-futimes.c | 2 +- io/tst-lutimes.c | 53 +++++++++++++++++++++++++++++++++++++ io/tst-utime.c | 2 +- io/tst-utimensat-skeleton.c | 7 ++++- io/tst-utimes.c | 2 +- 7 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 io/tst-lutimes.c diff --git a/io/Makefile b/io/Makefile index 0002e108a6..bec0e5871e 100644 --- a/io/Makefile +++ b/io/Makefile @@ -72,6 +72,7 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \ tst-utime \ tst-utimes \ tst-futimes \ + tst-lutimes \ tst-futimens \ # Likewise for statx, but we do not need static linking here. diff --git a/io/tst-futimens.c b/io/tst-futimens.c index ac7a980017..b3e3f3137f 100644 --- a/io/tst-futimens.c +++ b/io/tst-futimens.c @@ -38,7 +38,7 @@ test_futimens_helper (const char *file, int fd, const struct timespec *ts) return 0; } -#define TEST_CALL(fname, fd, v1, v2) \ +#define TEST_CALL(fname, fd, lname, v1, v2) \ test_futimens_helper (fname, fd, (struct timespec[]) { { v1, 0 }, \ { v2, 0 } }) diff --git a/io/tst-futimes.c b/io/tst-futimes.c index ea7ac7d5f8..bdef38d7cb 100644 --- a/io/tst-futimes.c +++ b/io/tst-futimes.c @@ -39,7 +39,7 @@ test_futimens_helper (const char *file, int fd, const struct timeval *tv) return 0; } -#define TEST_CALL(fname, fd, v1, v2) \ +#define TEST_CALL(fname, fd, lname, v1, v2) \ test_futimens_helper (fname, fd, (struct timeval[]) { { v1, 0 }, \ { v2, 0 } }) diff --git a/io/tst-lutimes.c b/io/tst-lutimes.c new file mode 100644 index 0000000000..b2da3c5796 --- /dev/null +++ b/io/tst-lutimes.c @@ -0,0 +1,53 @@ +/* Test for lutimes. + 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 + +static int +test_lutimes_helper (const char *testfile, int fd, const char *testlink, + const struct timeval *tv) +{ + struct stat64 stfile_orig; + xlstat (testfile, &stfile_orig); + + TEST_VERIFY_EXIT (lutimes (testlink, tv) == 0); + + struct stat64 stlink; + xlstat (testlink, &stlink); + + TEST_COMPARE (stlink.st_atime, tv[0].tv_sec); + TEST_COMPARE (stlink.st_mtime, tv[1].tv_sec); + + /* Check if the timestamp from original file is not changed. */ + struct stat64 stfile; + xlstat (testfile, &stfile); + + TEST_COMPARE (stfile_orig.st_atime, stfile.st_atime); + TEST_COMPARE (stfile_orig.st_mtime, stfile.st_mtime); + + return 0; +} + +#define TEST_CALL(fname, fd, lname, v1, v2) \ + test_lutimes_helper (fname, fd, lname, (struct timeval[]) { { v1, 0 }, \ + { v2, 0 } }) + +#include "tst-utimensat-skeleton.c" diff --git a/io/tst-utime.c b/io/tst-utime.c index c1c7e75a29..6269ef7929 100644 --- a/io/tst-utime.c +++ b/io/tst-utime.c @@ -39,7 +39,7 @@ test_utime_helper (const char *file, int fd, const struct utimbuf *ut) return 0; } -#define TEST_CALL(fname, fd, v1, v2) \ +#define TEST_CALL(fname, fd, lname, v1, v2) \ test_utime_helper (fname, fd, &(struct utimbuf) { (v1), (v2) }) #include "tst-utimensat-skeleton.c" diff --git a/io/tst-utimensat-skeleton.c b/io/tst-utimensat-skeleton.c index 3589146db5..ad9f6763c5 100644 --- a/io/tst-utimensat-skeleton.c +++ b/io/tst-utimensat-skeleton.c @@ -24,6 +24,7 @@ static int temp_fd = -1; static char *testfile; +static char *testlink; const static struct { int64_t v1; @@ -49,6 +50,10 @@ do_prepare (int argc, char *argv[]) { temp_fd = create_temp_file ("utime", &testfile); TEST_VERIFY_EXIT (temp_fd > 0); + + testlink = xasprintf ("%s-symlink", testfile); + xsymlink (testfile, testlink); + add_temp_file (testlink); } static int @@ -82,7 +87,7 @@ do_test (void) continue; } - TEST_CALL (testfile, temp_fd, tests[i].v1, tests[i].v2); + TEST_CALL (testfile, temp_fd, testlink, tests[i].v1, tests[i].v2); } return 0; diff --git a/io/tst-utimes.c b/io/tst-utimes.c index ba710508b7..991ab0c7d3 100644 --- a/io/tst-utimes.c +++ b/io/tst-utimes.c @@ -40,7 +40,7 @@ test_utimes_helper (const char *file, int fd, const struct timeval *tv) return 0; } -#define TEST_CALL(fname, fd, v1, v2) \ +#define TEST_CALL(fname, fd, lname, v1, v2) \ test_utimes_helper (fname, fd, (struct timeval[]) { { v1, 0 }, \ { v2, 0 } })