From patchwork Tue Mar 23 13:44:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 42747 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 718C43850407; Tue, 23 Mar 2021 13:45:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 718C43850407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616507110; bh=NxWuTzn8c4K4l6JQ25N9zvySgYS/5U28JtueM2AkQyo=; 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=je9Eg4YYS8q4P84u/FA2MCjbcO3FuPYDlD7H3c2ewmtaKdNko9Luns89DkrLe+JyG oXues/hXz3BCPjCUUExRoi8VVxlD47LkWWqAKrnptikIRr0u+9dUD9Es/0QHeuheZH N9TWIP3/6GZ3ChRecKx7G4krLkZq0r6QrRdUaqYo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 7C2BE3860C2E for ; Tue, 23 Mar 2021 13:45:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7C2BE3860C2E Received: by mail-qk1-x731.google.com with SMTP id q3so14313688qkq.12 for ; Tue, 23 Mar 2021 06:45:07 -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=NxWuTzn8c4K4l6JQ25N9zvySgYS/5U28JtueM2AkQyo=; b=tIUNYu8EgobD9MKpU9qHrJS3s3AcJtJzRQ61iliHRwEIbAdbn9oFLhgXFdUbtnrafq ajupkNvulv6VIopCXH1JhEg3BB85hk1aO0U9VNfVWN3l/MINEjZngegHx4ZYXrANC85a aK1WAvBkkJNQ9YwcVv8P+6EDtiszsQtooacvRK9U6/CnKmc2X6D7CmALdRfHpqfhR9a8 Y+e2nx6O6l1bLZ7avr1zp3FpT0NodDGohOn6ztYkWhqJEB4vdH9kDFoFW3apIbQFiktl VuIxjG8sPWzpyJn/VPCC0a6U4UcjTO+TONHyzOk/gGa0GntPX3L4+BtWxS4CJYKkI73/ tOAg== X-Gm-Message-State: AOAM532RvWztfngFlKiCisKc3WNCsQNA5m42wsa2H69AdijYo2Ec0q71 JgAnxuKye3nb2n56vDozNESGesZD57dgmw== X-Google-Smtp-Source: ABdhPJy4qETovLoRZsB71jxbeBmAyzdCa8qDcaxKk4e2c5r/vOyWLxwyiFPxTg+lk4pP83+hJcLfcA== X-Received: by 2002:a37:4396:: with SMTP id q144mr5135159qka.441.1616507106752; Tue, 23 Mar 2021 06:45:06 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id z24sm12783384qkz.65.2021.03.23.06.45.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 06:45:06 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 04/15] io: Add basic tests for utimensat Date: Tue, 23 Mar 2021 10:44:47 -0300 Message-Id: <20210323134458.2563022-5-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.5 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 on x86_64-linux-gnu and i686-linux-gnu Reviewed-by: Siddhesh Poyarekar --- io/Makefile | 1 + io/tst-utimensat.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 io/tst-utimensat.c diff --git a/io/Makefile b/io/Makefile index bec0e5871e..0903804dfd 100644 --- a/io/Makefile +++ b/io/Makefile @@ -74,6 +74,7 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \ tst-futimes \ tst-lutimes \ tst-futimens \ + 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..0c7c8470bc --- /dev/null +++ b/io/tst-utimensat.c @@ -0,0 +1,70 @@ +/* Test for utimensat. + 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 + +static int +test_utimesat_helper (const char *testfile, int fd, const char *testlink, + const struct timespec *ts) +{ + { + TEST_VERIFY_EXIT (utimensat (fd, testfile, ts, 0) == 0); + + struct stat64 st; + xfstat (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 stat64 stfile_orig; + xlstat (testfile, &stfile_orig); + + TEST_VERIFY_EXIT (utimensat (0 /* ignored */, testlink, ts, + AT_SYMLINK_NOFOLLOW) + == 0); + struct stat64 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 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_utimesat_helper (fname, fd, lname, (struct timespec[]) { { v1, 0 }, \ + { v2, 0 } }) + +#include "tst-utimensat-skeleton.c"