Module Name: src Committed By: martin Date: Sun Oct 13 10:51:41 UTC 2024
Modified Files: src/tests/lib/libc/c063 [netbsd-9]: t_utimensat.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #1901): tests/lib/libc/c063/t_utimensat.c: revision 1.8 tests/lib/libc/c063/t_utimensat.c: revision 1.9 t_utimensat: Tidy this up to make failures more obvious. PR kern/58571: utimensat tests are failing on armv7, aarch64, and riscv64 t_utimensat: Don't check atime on file systems mounted noatime. PR kern/58571: utimensat tests are failing on armv7, aarch64, and riscv64 To generate a diff of this commit: cvs rdiff -u -r1.6.14.1 -r1.6.14.2 src/tests/lib/libc/c063/t_utimensat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/c063/t_utimensat.c diff -u src/tests/lib/libc/c063/t_utimensat.c:1.6.14.1 src/tests/lib/libc/c063/t_utimensat.c:1.6.14.2 --- src/tests/lib/libc/c063/t_utimensat.c:1.6.14.1 Sun Oct 13 10:47:34 2024 +++ src/tests/lib/libc/c063/t_utimensat.c Sun Oct 13 10:51:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_utimensat.c,v 1.6.14.1 2024/10/13 10:47:34 martin Exp $ */ +/* $NetBSD: t_utimensat.c,v 1.6.14.2 2024/10/13 10:51:41 martin Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -29,11 +29,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_utimensat.c,v 1.6.14.1 2024/10/13 10:47:34 martin Exp $"); +__RCSID("$NetBSD: t_utimensat.c,v 1.6.14.2 2024/10/13 10:51:41 martin Exp $"); #include <sys/param.h> + #include <sys/stat.h> +#include <sys/statvfs.h> #include <sys/time.h> + #include <atf-c.h> #include <errno.h> #include <fcntl.h> @@ -43,6 +46,8 @@ __RCSID("$NetBSD: t_utimensat.c,v 1.6.14 #include <string.h> #include <unistd.h> +#include "h_macros.h" + #define DIR "dir" #define FILE "dir/utimensat" #define BASEFILE "utimensat" @@ -50,11 +55,32 @@ __RCSID("$NetBSD: t_utimensat.c,v 1.6.14 #define BASELINK "symlink" #define FILEERR "dir/symlink" -const struct timespec tptr[] = { +static const struct timespec tptr[] = { { 0x12345678, 987654321 }, { 0x15263748, 123456789 }, }; +static void +checkstattime(const struct stat *st, const struct statvfs *fs) +{ + + if ((fs->f_flag & ST_NOATIME) == 0) { + ATF_CHECK_EQ_MSG(st->st_atimespec.tv_sec, tptr[0].tv_sec, + "st->st_atimespec.tv_sec=%lld tptr[0].tv_sec=%lld", + (long long)st->st_atimespec.tv_sec, + (long long)tptr[0].tv_sec); + ATF_CHECK_EQ_MSG(st->st_atimespec.tv_nsec, tptr[0].tv_nsec, + "st->st_atimespec.tv_nsec=%ld tptr[0].tv_nsec=%ld", + (long)st->st_atimespec.tv_nsec, (long)tptr[0].tv_nsec); + } + ATF_CHECK_EQ_MSG(st->st_mtimespec.tv_sec, tptr[1].tv_sec, + "st->st_mtimespec.tv_sec=%lld tptr[1].tv_sec=%lld", + (long long)st->st_mtimespec.tv_sec, (long long)tptr[1].tv_sec); + ATF_CHECK_EQ_MSG(st->st_mtimespec.tv_nsec, tptr[1].tv_nsec, + "st->st_mtimespec.tv_nsec=%ld tptr[1].tv_nsec=%ld", + (long)st->st_mtimespec.tv_nsec, (long)tptr[1].tv_nsec); +} + ATF_TC(utimensat_fd); ATF_TC_HEAD(utimensat_fd, tc) { @@ -65,78 +91,78 @@ ATF_TC_BODY(utimensat_fd, tc) int dfd; int fd; struct stat st; + struct statvfs fs; - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); - ATF_REQUIRE(close(fd) == 0); - - ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); - ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == 0); - ATF_REQUIRE(close(dfd) == 0); - - ATF_REQUIRE(stat(FILE, &st) == 0); - ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec); - ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec); - ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec); - ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec); + RL(mkdir(DIR, 0755)); + RL(fd = open(FILE, O_CREAT|O_RDWR, 0644)); + RL(close(fd)); + + RL(dfd = open(DIR, O_RDONLY, 0)); + RL(utimensat(dfd, BASEFILE, tptr, 0)); + RL(close(dfd)); + + RL(stat(FILE, &st)); + RL(statvfs(FILE, &fs)); + checkstattime(&st, &fs); } ATF_TC(utimensat_fdcwd); ATF_TC_HEAD(utimensat_fdcwd, tc) { - atf_tc_set_md_var(tc, "descr", - "See that utimensat works with fd as AT_FDCWD"); + atf_tc_set_md_var(tc, "descr", + "See that utimensat works with fd as AT_FDCWD"); } ATF_TC_BODY(utimensat_fdcwd, tc) { int fd; struct stat st; + struct statvfs fs; - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); - ATF_REQUIRE(close(fd) == 0); - - ATF_REQUIRE(chdir(DIR) == 0); - ATF_REQUIRE(utimensat(AT_FDCWD, BASEFILE, tptr, 0) == 0); - - ATF_REQUIRE(stat(BASEFILE, &st) == 0); - ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec); - ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec); - ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec); - ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec); + RL(mkdir(DIR, 0755)); + RL(fd = open(FILE, O_CREAT|O_RDWR, 0644)); + RL(close(fd)); + + RL(chdir(DIR)); + RL(utimensat(AT_FDCWD, BASEFILE, tptr, 0)); + + RL(stat(BASEFILE, &st)); + RL(statvfs(BASEFILE, &fs)); + checkstattime(&st, &fs); } ATF_TC(utimensat_fdcwderr); ATF_TC_HEAD(utimensat_fdcwderr, tc) { - atf_tc_set_md_var(tc, "descr", - "See that utimensat fails with fd as AT_FDCWD and bad path"); + atf_tc_set_md_var(tc, "descr", + "See that utimensat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(utimensat_fdcwderr, tc) { - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE(utimensat(AT_FDCWD, FILEERR, tptr, 0) == -1); + RL(mkdir(DIR, 0755)); + ATF_CHECK_ERRNO(ENOENT, utimensat(AT_FDCWD, FILEERR, tptr, 0) == -1); } ATF_TC(utimensat_fderr1); ATF_TC_HEAD(utimensat_fderr1, tc) { - atf_tc_set_md_var(tc, "descr", "See that utimensat fail with bad path"); + atf_tc_set_md_var(tc, "descr", + "See that utimensat fail with bad path"); } ATF_TC_BODY(utimensat_fderr1, tc) { int dfd; - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); - ATF_REQUIRE(utimensat(dfd, FILEERR, tptr, 0) == -1); - ATF_REQUIRE(close(dfd) == 0); + RL(mkdir(DIR, 0755)); + RL(dfd = open(DIR, O_RDONLY, 0)); + ATF_CHECK_ERRNO(ENOENT, utimensat(dfd, FILEERR, tptr, 0) == -1); + RL(close(dfd)); } ATF_TC(utimensat_fderr2); ATF_TC_HEAD(utimensat_fderr2, tc) { - atf_tc_set_md_var(tc, "descr", "See that utimensat fails with bad fdat"); + atf_tc_set_md_var(tc, "descr", + "See that utimensat fails with bad fdat"); } ATF_TC_BODY(utimensat_fderr2, tc) { @@ -144,29 +170,30 @@ ATF_TC_BODY(utimensat_fderr2, tc) int fd; char cwd[MAXPATHLEN]; - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); - ATF_REQUIRE(close(fd) == 0); - - ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); - ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == -1); - ATF_REQUIRE(close(dfd) == 0); + RL(mkdir(DIR, 0755)); + RL(fd = open(FILE, O_CREAT|O_RDWR, 0644)); + RL(close(fd)); + + RL(dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)); + ATF_CHECK_ERRNO(ENOENT, utimensat(dfd, BASEFILE, tptr, 0) == -1); + RL(close(dfd)); } ATF_TC(utimensat_fderr3); ATF_TC_HEAD(utimensat_fderr3, tc) { - atf_tc_set_md_var(tc, "descr", "See that utimensat fails with fd as -1"); + atf_tc_set_md_var(tc, "descr", + "See that utimensat fails with fd as -1"); } ATF_TC_BODY(utimensat_fderr3, tc) { int fd; - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); - ATF_REQUIRE(close(fd) == 0); + RL(mkdir(DIR, 0755)); + RL(fd = open(FILE, O_CREAT|O_RDWR, 0644)); + RL(close(fd)); - ATF_REQUIRE(utimensat(-1, FILE, tptr, 0) == -1); + ATF_CHECK_ERRNO(EBADF, utimensat(-1, FILE, tptr, 0) == -1); } ATF_TC(utimensat_fdlink); @@ -178,24 +205,22 @@ ATF_TC_BODY(utimensat_fdlink, tc) { int dfd; struct stat st; + struct statvfs fs; - ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */ + RL(mkdir(DIR, 0755)); + RL(symlink(FILE, LINK)); /* NB: FILE does not exists */ - ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); + RL(dfd = open(DIR, O_RDONLY, 0)); - ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, 0) == -1); - ATF_REQUIRE(errno == ENOENT); + ATF_CHECK_ERRNO(ENOENT, utimensat(dfd, BASELINK, tptr, 0) == -1); - ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, AT_SYMLINK_NOFOLLOW) == 0); + RL(utimensat(dfd, BASELINK, tptr, AT_SYMLINK_NOFOLLOW)); - ATF_REQUIRE(close(dfd) == 0); + RL(close(dfd)); - ATF_REQUIRE(lstat(LINK, &st) == 0); - ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec); - ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec); - ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec); - ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec); + RL(lstat(LINK, &st)); + RL(statvfs(DIR, &fs)); /* XXX should do lstatvfs(LINK, &fs) */ + checkstattime(&st, &fs); } ATF_TP_ADD_TCS(tp)