From patchwork Mon Mar 8 16:58:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 42365 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 4407E3850415; Mon, 8 Mar 2021 16:58:16 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from aloka.lostca.se (aloka.lostca.se [178.63.46.202]) by sourceware.org (Postfix) with ESMTPS id CC5483854801 for ; Mon, 8 Mar 2021 16:58:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CC5483854801 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lostca.se Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arjun.is@lostca.se Received: from aloka.lostca.se (aloka [127.0.0.1]) by aloka.lostca.se (Postfix) with ESMTP id C77F517E20; Mon, 8 Mar 2021 16:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=lostca.se; h=date:from:to :cc:subject:message-id:mime-version:content-type; s=howrah; bh=Q +ASQ/2ZMY9BMzni2+2Tp20thsw=; b=foPo47+X8Gf9aOrYK/GHQbVaSPAGwGtvP fIhVS3TBLAtfiLsuOub2shmUP9qqdit8WyUCimWgkE2Fw6vpRx+IMDVnrID1k34d JO9eDdZKRb9Gu29c/WJ80BKRW40DNglnAMvf5KuoKn9XENFfoKt2DUUE0/9Ho3GB VcuPQ7Q/8w= Received: from localhost (unknown [IPv6:2a01:4f8:120:624c::25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: spectre) by aloka.lostca.se (Postfix) with ESMTPSA id 8B3DC17E1F; Mon, 8 Mar 2021 16:58:10 +0000 (UTC) Date: Mon, 8 Mar 2021 16:58:09 +0000 From: Arjun Shankar To: libc-alpha@sourceware.org Subject: [PATCH] Prefer /dev/shm over /tmp in utime family tests Message-ID: <20210308165808.GA53302@aloka.lostca.se> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: , Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Arjun Shankar tst-utime.c, tst-utimes.c, and tst-futimens.c create a temporary file in /tmp to test Y2038 support in the corresponding functions. This causes the tests to fail when /tmp is mounted as a filesystem that has a Y2038 bug; e.g. XFS. This commit changes the tests to prefer using /dev/shm over /tmp. /dev/shm is always mounted as tmpfs. Since the change means a longer do_prepare function and duplicate code, the do_prepare function is moved to a separate, new source file. --- sysdeps/unix/sysv/linux/tst-futimens.c | 13 ++----- sysdeps/unix/sysv/linux/tst-utime-prep.c | 44 ++++++++++++++++++++++++ sysdeps/unix/sysv/linux/tst-utime.c | 14 ++------ sysdeps/unix/sysv/linux/tst-utimes.c | 14 ++------ 4 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/tst-utime-prep.c diff --git a/sysdeps/unix/sysv/linux/tst-futimens.c b/sysdeps/unix/sysv/linux/tst-futimens.c index 8f48cfee63..739635f9f3 100644 --- a/sysdeps/unix/sysv/linux/tst-futimens.c +++ b/sysdeps/unix/sysv/linux/tst-futimens.c @@ -22,9 +22,6 @@ #include #include #include -#include - -static int temp_fd = -1; /* struct timespec array with Y2038 threshold minus 2 and 1 seconds. */ const struct timespec t1[2] = { { 0x7FFFFFFE, 0 }, { 0x7FFFFFFF, 0 } }; @@ -35,13 +32,9 @@ const struct timespec t2[2] = { { 0x80000001ULL, 0 }, { 0x80000002ULL, 0 } }; /* struct timespec array around Y2038 threshold. */ const struct timespec t3[2] = { { 0x7FFFFFFE, 0 }, { 0x80000002ULL, 0 } }; -#define PREPARE do_prepare -static void -do_prepare (int argc, char *argv[]) -{ - temp_fd = create_temp_file ("futimensat", NULL); - TEST_VERIFY_EXIT (temp_fd > 0); -} +/* The do_prepare function creates a temporary file to work with, + defining `int temp_fd' and `char *testfile'. */ +#include "tst-utime-prep.c" static int test_futimens_helper (const struct timespec *ts) diff --git a/sysdeps/unix/sysv/linux/tst-utime-prep.c b/sysdeps/unix/sysv/linux/tst-utime-prep.c new file mode 100644 index 0000000000..3729d8d92e --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-utime-prep.c @@ -0,0 +1,44 @@ +/* do_prepare function for tests of the utime family of functions. + 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 temp_fd = -1; +char *testfile; + +#define PREPARE do_prepare +static void +do_prepare (int argc, char *argv[]) +{ + /* Prefer using /dev/shm when it exists. It uses tmpfs, which is + Y2038-safe. /tmp could use, e.g. XFS, which presently has a Y2038 bug + triggering a test failure. */ + DIR *d = opendir ("/dev/shm"); + if (d != NULL) + { + temp_fd = create_temp_file_in_dir ("utime", "/dev/shm", &testfile); + closedir (d); + } + else + temp_fd = create_temp_file ("utime", &testfile); + + TEST_VERIFY_EXIT (temp_fd > 0); +} diff --git a/sysdeps/unix/sysv/linux/tst-utime.c b/sysdeps/unix/sysv/linux/tst-utime.c index 6735421657..130a0c6a6e 100644 --- a/sysdeps/unix/sysv/linux/tst-utime.c +++ b/sysdeps/unix/sysv/linux/tst-utime.c @@ -24,10 +24,6 @@ #include #include #include -#include - -static int temp_fd = -1; -char *testfile; /* struct utimbuf with Y2038 threshold minus 2 and 1 seconds. */ const static struct utimbuf t1 = { 0x7FFFFFFE, 0x7FFFFFFF }; @@ -38,13 +34,9 @@ const static struct utimbuf t2 = { 0x80000001ULL, 0x80000002ULL }; /* struct utimbuf around Y2038 threshold. */ const static struct utimbuf t3 = { 0x7FFFFFFE, 0x80000002ULL }; -#define PREPARE do_prepare -static void -do_prepare (int argc, char *argv[]) -{ - temp_fd = create_temp_file ("utime", &testfile); - TEST_VERIFY_EXIT (temp_fd > 0); -} +/* The do_prepare function creates a temporary file to work with, + defining `int temp_fd' and `char *testfile'. */ +#include "tst-utime-prep.c" static int test_utime_helper (const struct utimbuf *ut) diff --git a/sysdeps/unix/sysv/linux/tst-utimes.c b/sysdeps/unix/sysv/linux/tst-utimes.c index 8c7b006a22..fb59ef263e 100644 --- a/sysdeps/unix/sysv/linux/tst-utimes.c +++ b/sysdeps/unix/sysv/linux/tst-utimes.c @@ -23,10 +23,6 @@ #include #include #include -#include - -static int temp_fd = -1; -char *testfile; /* struct timeval array with Y2038 threshold minus 2 and 1 seconds. */ const static struct timeval t1[2] = { { 0x7FFFFFFE, 0 }, { 0x7FFFFFFF, 0 } }; @@ -39,13 +35,9 @@ struct timeval t2[2] = { { 0x80000001ULL, 0 }, { 0x80000002ULL, 0 } }; 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); -} +/* The do_prepare function creates a temporary file to work with, + defining `int temp_fd' and `char *testfile'. */ +#include "tst-utime-prep.c" static int test_utime_helper (const struct timeval *tv)