From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14594 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH libc-test] add utime (utimensat, futimens) functional tests Date: Thu, 22 Aug 2019 21:04:36 -0400 Message-ID: <20190823010436.GN9017@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="pE2VAHO2njSJCslu" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="151349"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14610-gllmg-musl=m.gmane.org@lists.openwall.com Fri Aug 23 03:04:53 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i0y0b-000dBW-3Y for gllmg-musl@m.gmane.org; Fri, 23 Aug 2019 03:04:53 +0200 Original-Received: (qmail 5871 invoked by uid 550); 23 Aug 2019 01:04:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5839 invoked from network); 23 Aug 2019 01:04:50 -0000 Content-Disposition: inline Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14594 Archived-At: --pE2VAHO2njSJCslu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here's a WIP (may extend later but seems good as-is too) utime test for libc-test. I've been using it to test the upcoming time64 functionality for 32-bit archs. Rich --pE2VAHO2njSJCslu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-add-utime-utimensat-futimens-functional-tests.patch" >From abffbd450401c6638177c0bc7b789130e41c1e84 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 22 Aug 2019 20:58:00 -0400 Subject: [PATCH] add utime (utimensat, futimens) functional tests these tests check for the ability to set file timestamps using UTIME_NOW, UTIME_OMIT, and explicit timespecs. they indirectly check that fstat works as well, and include a check of the first Y2038 timestamp that overflows 32-bit time_t, reporting errors for a Y2038 EOL implementaton (if time_t is 32-bit) or a kernel, filesystem, or library implementation that fails to set and read back timestamps past the 32-bit limit despite having a time_t type that can represent such a timestamp. --- src/functional/utime.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/functional/utime.c diff --git a/src/functional/utime.c b/src/functional/utime.c new file mode 100644 index 0000000..7fa7a1f --- /dev/null +++ b/src/functional/utime.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0)) +#define TESTVAL(v,op,x) TEST(v op x, "%jd\n", (intmax_t)(v)) + +int main(void) +{ + struct stat st; + FILE *f; + int fd; + time_t t; + + TEST(utimensat(AT_FDCWD, "/dev/null/invalid", ((struct timespec[2]){{.tv_nsec=UTIME_OMIT},{.tv_nsec=UTIME_OMIT}}), 0)==0 || errno==ENOTDIR, + "%s\n", strerror(errno)); + TEST(futimens(-1, ((struct timespec[2]){{.tv_nsec=UTIME_OMIT},{.tv_nsec=UTIME_OMIT}}))==0 || errno==EBADF, + "%s\n", strerror(errno)); + + if (!TEST(f = tmpfile())) return t_status; + fd = fileno(f); + + TEST(futimens(fd, (struct timespec[2]){0}) == 0, "\n"); + TEST(fstat(fd, &st) == 0, "\n"); + TESTVAL(st.st_atim.tv_sec,==,0); + TESTVAL(st.st_atim.tv_nsec,==,0); + TESTVAL(st.st_mtim.tv_sec,==,0); + TESTVAL(st.st_mtim.tv_nsec,==,0); + + TEST(futimens(fd, ((struct timespec[2]){{.tv_sec=1,.tv_nsec=UTIME_OMIT},{.tv_sec=1,.tv_nsec=UTIME_OMIT}})) == 0, "\n"); + TEST(fstat(fd, &st) == 0, "\n"); + TESTVAL(st.st_atim.tv_sec,==,0); + TESTVAL(st.st_atim.tv_nsec,==,0); + TESTVAL(st.st_mtim.tv_sec,==,0); + TESTVAL(st.st_mtim.tv_nsec,==,0); + + t = time(0); + + TEST(futimens(fd, ((struct timespec[2]){{.tv_nsec=UTIME_NOW},{.tv_nsec=UTIME_OMIT}})) == 0, "\n"); + TEST(fstat(fd, &st) == 0, "\n"); + TESTVAL(st.st_atim.tv_sec,>=,t); + TESTVAL(st.st_mtim.tv_sec,==,0); + TESTVAL(st.st_mtim.tv_nsec,==,0); + + TEST(futimens(fd, (struct timespec[2]){0}) == 0, "\n"); + TEST(futimens(fd, ((struct timespec[2]){{.tv_nsec=UTIME_OMIT},{.tv_nsec=UTIME_NOW}})) == 0, "\n"); + TEST(fstat(fd, &st) == 0, "\n"); + TESTVAL(st.st_atim.tv_sec,==,0); + TESTVAL(st.st_mtim.tv_sec,>=,t); + + TEST(futimens(fd, ((struct timespec[2]){{.tv_nsec=UTIME_NOW},{.tv_nsec=UTIME_OMIT}})) == 0, "\n"); + TEST(fstat(fd, &st) == 0, "\n"); + TESTVAL(st.st_atim.tv_sec,>=,t); + TESTVAL(st.st_mtim.tv_sec,>=,t); + + if (TEST((time_t)(1LL<<32) == (1LL<<32), "implementation has Y2038 EOL\n")) { + if (TEST(futimens(fd, ((struct timespec[2]){{.tv_sec=1LL<<32},{.tv_sec=1LL<<32}})) == 0, "%s\n", strerror(errno))) { + TEST(fstat(fd, &st) == 0, "\n"); + TESTVAL(st.st_atim.tv_sec, ==, 1LL<<32); + TESTVAL(st.st_mtim.tv_sec, ==, 1LL<<32); + } + } + + fclose(f); + + return t_status; +} -- 2.21.0 --pE2VAHO2njSJCslu--