summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/fs/vfs/t_vnops.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/fs/vfs/t_vnops.c')
-rw-r--r--contrib/netbsd-tests/fs/vfs/t_vnops.c191
1 files changed, 135 insertions, 56 deletions
diff --git a/contrib/netbsd-tests/fs/vfs/t_vnops.c b/contrib/netbsd-tests/fs/vfs/t_vnops.c
index 66b5505..978fadb 100644
--- a/contrib/netbsd-tests/fs/vfs/t_vnops.c
+++ b/contrib/netbsd-tests/fs/vfs/t_vnops.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_vnops.c,v 1.43 2014/09/09 06:51:00 gson Exp $ */
+/* $NetBSD: t_vnops.c,v 1.58 2016/08/29 02:31:46 kre Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -28,9 +28,11 @@
#include <sys/stat.h>
#include <sys/statvfs.h>
+#include <sys/time.h>
#include <assert.h>
#include <atf-c.h>
+#include <ctype.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdlib.h>
@@ -54,10 +56,10 @@
atf_tc_skip("symlinks not supported by file system")
static char *
-md(char *buf, const char *base, const char *tail)
+md(char *buf, size_t buflen, const char *base, const char *tail)
{
- sprintf(buf, "%s/%s", base, tail);
+ snprintf(buf, buflen, "%s/%s", base, tail);
return buf;
}
@@ -68,11 +70,11 @@ lookup_simple(const atf_tc_t *tc, const char *mountpath)
struct stat sb1, sb2;
strcpy(final, mountpath);
- sprintf(pb, "%s/../%s", mountpath, basename(final));
+ snprintf(pb, sizeof(pb), "%s/../%s", mountpath, basename(final));
if (rump_sys_stat(pb, &sb1) == -1)
atf_tc_fail_errno("stat 1");
- sprintf(pb, "%s/./../%s", mountpath, basename(final));
+ snprintf(pb, sizeof(pb), "%s/./../%s", mountpath, basename(final));
if (rump_sys_stat(pb, &sb2) == -1)
atf_tc_fail_errno("stat 2");
@@ -84,22 +86,38 @@ lookup_complex(const atf_tc_t *tc, const char *mountpath)
{
char pb[MAXPATHLEN];
struct stat sb1, sb2;
+ struct timespec atplus1, onesec;
USES_DIRS;
- if (FSTYPE_UDF(tc))
- atf_tc_expect_fail("PR kern/49033");
-
- sprintf(pb, "%s/dir", mountpath);
+ snprintf(pb, sizeof(pb), "%s/dir", mountpath);
if (rump_sys_mkdir(pb, 0777) == -1)
atf_tc_fail_errno("mkdir");
if (rump_sys_stat(pb, &sb1) == -1)
atf_tc_fail_errno("stat 1");
- sprintf(pb, "%s/./dir/../././dir/.", mountpath);
+ snprintf(pb, sizeof(pb), "%s/./dir/../././dir/.", mountpath);
if (rump_sys_stat(pb, &sb2) == -1)
atf_tc_fail_errno("stat 2");
+ /*
+ * The lookup is permitted to modify the access time of
+ * any directories searched - such a directory is the
+ * subject of this test. Any difference should cause
+ * the 2nd lookup atime tp be >= the first, if it is ==, all is
+ * OK (atime is not required to be modified by the search, or
+ * both references may happen within the came clock tick), if the
+ * 2nd lookup atime is > the first, but not "too much" greater,
+ * just set it back, so the memcmp just below succeeds
+ * (assuming all else is OK).
+ */
+ onesec.tv_sec = 1;
+ onesec.tv_nsec = 0;
+ timespecadd(&sb1.st_atimespec, &onesec, &atplus1);
+ if (timespeccmp(&sb2.st_atimespec, &sb1.st_atimespec, >) &&
+ timespeccmp(&sb2.st_atimespec, &atplus1, <))
+ sb2.st_atimespec = sb1.st_atimespec;
+
if (memcmp(&sb1, &sb2, sizeof(sb1)) != 0) {
printf("what\tsb1\t\tsb2\n");
@@ -118,10 +136,10 @@ lookup_complex(const atf_tc_t *tc, const char *mountpath)
FIELD(st_uid);
FIELD(st_gid);
FIELD(st_rdev);
- TIME(st_atim);
- TIME(st_mtim);
- TIME(st_ctim);
- TIME(st_birthtim);
+ TIME(st_atimespec);
+ TIME(st_mtimespec);
+ TIME(st_ctimespec);
+ TIME(st_birthtimespec);
FIELD(st_size);
FIELD(st_blocks);
FIELD(st_flags);
@@ -132,9 +150,6 @@ lookup_complex(const atf_tc_t *tc, const char *mountpath)
atf_tc_fail("stat results differ, see ouput for more details");
}
- if (FSTYPE_UDF(tc))
- atf_tc_fail("random failure of PR kern/49033 "
- "did not happen this time");
}
static void
@@ -146,7 +161,7 @@ dir_simple(const atf_tc_t *tc, const char *mountpath)
USES_DIRS;
/* check we can create directories */
- sprintf(pb, "%s/dir", mountpath);
+ snprintf(pb, sizeof(pb), "%s/dir", mountpath);
if (rump_sys_mkdir(pb, 0777) == -1)
atf_tc_fail_errno("mkdir");
if (rump_sys_stat(pb, &sb) == -1)
@@ -168,19 +183,17 @@ dir_notempty(const atf_tc_t *tc, const char *mountpath)
USES_DIRS;
/* check we can create directories */
- sprintf(pb, "%s/dir", mountpath);
+ snprintf(pb, sizeof(pb), "%s/dir", mountpath);
if (rump_sys_mkdir(pb, 0777) == -1)
atf_tc_fail_errno("mkdir");
- sprintf(pb2, "%s/dir/file", mountpath);
+ snprintf(pb2, sizeof(pb2), "%s/dir/file", mountpath);
fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
if (fd == -1)
atf_tc_fail_errno("create file");
rump_sys_close(fd);
rv = rump_sys_rmdir(pb);
- if (FSTYPE_ZFS(tc))
- atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (rv != -1 || errno != ENOTEMPTY)
atf_tc_fail("non-empty directory removed succesfully");
@@ -206,9 +219,9 @@ dir_rmdirdotdot(const atf_tc_t *tc, const char *mp)
RL(rump_sys_mkdir("subtest", 0777));
RL(rump_sys_chdir("subtest"));
- md(pb, mp, "test/subtest");
+ md(pb, sizeof(pb), mp, "test/subtest");
RL(rump_sys_rmdir(pb));
- md(pb, mp, "test");
+ md(pb, sizeof(pb), mp, "test");
RL(rump_sys_rmdir(pb));
if (FSTYPE_NFS(tc))
@@ -226,7 +239,7 @@ checkfile(const char *path, struct stat *refp)
struct stat sb;
static int n = 1;
- md(buf, path, "file");
+ md(buf, sizeof(buf), path, "file");
if (rump_sys_stat(buf, &sb) == -1)
atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
if (memcmp(&sb, refp, sizeof(sb)) != 0)
@@ -245,18 +258,18 @@ rename_dir(const atf_tc_t *tc, const char *mp)
USES_DIRS;
- md(pb1, mp, "dir1");
+ md(pb1, sizeof(pb1), mp, "dir1");
if (rump_sys_mkdir(pb1, 0777) == -1)
atf_tc_fail_errno("mkdir 1");
- md(pb2, mp, "dir2");
+ md(pb2, sizeof(pb2), mp, "dir2");
if (rump_sys_mkdir(pb2, 0777) == -1)
atf_tc_fail_errno("mkdir 2");
- md(pb2, mp, "dir2/subdir");
+ md(pb2, sizeof(pb2), mp, "dir2/subdir");
if (rump_sys_mkdir(pb2, 0777) == -1)
atf_tc_fail_errno("mkdir 3");
- md(pb3, mp, "dir1/file");
+ md(pb3, sizeof(pb3), mp, "dir1/file");
if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
atf_tc_fail_errno("create file");
if (rump_sys_stat(pb3, &ref) == -1)
@@ -267,30 +280,28 @@ rename_dir(const atf_tc_t *tc, const char *mp)
*/
/* rename within directory */
- md(pb3, mp, "dir3");
+ md(pb3, sizeof(pb3), mp, "dir3");
if (rump_sys_rename(pb1, pb3) == -1)
atf_tc_fail_errno("rename 1");
checkfile(pb3, &ref);
/* rename directory onto itself (two ways, should fail) */
- md(pb1, mp, "dir3/.");
+ md(pb1, sizeof(pb1), mp, "dir3/.");
if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
atf_tc_fail_errno("rename 2");
- if (FSTYPE_ZFS(tc))
- atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
atf_tc_fail_errno("rename 3");
checkfile(pb3, &ref);
/* rename father of directory into directory */
- md(pb1, mp, "dir2/dir");
- md(pb2, mp, "dir2");
+ md(pb1, sizeof(pb1), mp, "dir2/dir");
+ md(pb2, sizeof(pb2), mp, "dir2");
if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
atf_tc_fail_errno("rename 4");
/* same for grandfather */
- md(pb1, mp, "dir2/subdir/dir2");
+ md(pb1, sizeof(pb1), mp, "dir2/subdir/dir2");
if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
atf_tc_fail("rename 5");
@@ -301,29 +312,29 @@ rename_dir(const atf_tc_t *tc, const char *mp)
atf_tc_fail("rename 6");
/* cross-directory rename */
- md(pb1, mp, "dir3");
- md(pb2, mp, "dir2/somedir");
+ md(pb1, sizeof(pb1), mp, "dir3");
+ md(pb2, sizeof(pb2), mp, "dir2/somedir");
if (rump_sys_rename(pb1, pb2) == -1)
atf_tc_fail_errno("rename 7");
checkfile(pb2, &ref);
/* move to parent directory */
- md(pb1, mp, "dir2/somedir/../../dir3");
+ md(pb1, sizeof(pb1), mp, "dir2/somedir/../../dir3");
if (rump_sys_rename(pb2, pb1) == -1)
atf_tc_fail_errno("rename 8");
- md(pb1, mp, "dir2/../dir3");
+ md(pb1, sizeof(pb1), mp, "dir2/../dir3");
checkfile(pb1, &ref);
/* atomic cross-directory rename */
- md(pb3, mp, "dir2/subdir");
+ md(pb3, sizeof(pb3), mp, "dir2/subdir");
if (rump_sys_rename(pb1, pb3) == -1)
atf_tc_fail_errno("rename 9");
checkfile(pb3, &ref);
/* rename directory over an empty directory */
- md(pb1, mp, "parent");
- md(pb2, mp, "parent/dir1");
- md(pb3, mp, "parent/dir2");
+ md(pb1, sizeof(pb1), mp, "parent");
+ md(pb2, sizeof(pb2), mp, "parent/dir1");
+ md(pb3, sizeof(pb3), mp, "parent/dir2");
RL(rump_sys_mkdir(pb1, 0777));
RL(rump_sys_mkdir(pb2, 0777));
RL(rump_sys_mkdir(pb3, 0777));
@@ -442,6 +453,78 @@ rename_reg_nodir(const atf_tc_t *tc, const char *mp)
rump_sys_chdir("/");
}
+/* PR kern/50607 */
+static void
+create_many(const atf_tc_t *tc, const char *mp)
+{
+ char buf[64];
+ int nfiles = 2324; /* #Nancy */
+ int i;
+
+ /* takes forever with many files */
+ if (FSTYPE_MSDOS(tc))
+ nfiles /= 4;
+
+ RL(rump_sys_chdir(mp));
+
+ if (FSTYPE_SYSVBFS(tc)) {
+ /* fs doesn't support many files or subdirectories */
+ nfiles = 5;
+ } else {
+ /* msdosfs doesn't like many entries in the root directory */
+ RL(rump_sys_mkdir("subdir", 0777));
+ RL(rump_sys_chdir("subdir"));
+ }
+
+ /* create them */
+#define TESTFN "testfile"
+ for (i = 0; i < nfiles; i++) {
+ int fd;
+
+ snprintf(buf, sizeof(buf), TESTFN "%d", i);
+ RL(fd = rump_sys_open(buf, O_RDWR|O_CREAT|O_EXCL, 0666));
+ RL(rump_sys_close(fd));
+ }
+
+ /* wipe them out */
+ for (i = 0; i < nfiles; i++) {
+ snprintf(buf, sizeof(buf), TESTFN "%d", i);
+ RLF(rump_sys_unlink(buf), "%s", buf);
+ }
+#undef TESTFN
+
+ rump_sys_chdir("/");
+}
+
+/*
+ * Test creating files with one-character names using all possible
+ * character values. Failures to create the file are ignored as the
+ * characters allowed in file names vary by file system, but at least
+ * we can check that the fs does not crash, and if the file is
+ * successfully created, unlinking it should also succeed.
+ */
+static void
+create_nonalphanum(const atf_tc_t *tc, const char *mp)
+{
+ char buf[64];
+ int i;
+
+ RL(rump_sys_chdir(mp));
+
+ for (i = 0; i < 256; i++) {
+ int fd;
+ snprintf(buf, sizeof(buf), "%c", i);
+ fd = rump_sys_open(buf, O_RDWR|O_CREAT|O_EXCL, 0666);
+ if (fd == -1)
+ continue;
+ RLF(rump_sys_close(fd), "%d", fd);
+ RLF(rump_sys_unlink(buf), "%s", buf);
+ }
+ printf("\n");
+
+ rump_sys_chdir("/");
+}
+
static void
create_nametoolong(const atf_tc_t *tc, const char *mp)
{
@@ -563,7 +646,7 @@ symlink_len(const atf_tc_t *tc, const char *mp, size_t len)
USES_SYMLINKS;
- RL(rump_sys_chdir(mp));
+ RLF(rump_sys_chdir(mp), "%s", mp);
buf = malloc(len + 1);
ATF_REQUIRE(buf);
@@ -645,8 +728,6 @@ attrs(const atf_tc_t *tc, const char *mp)
RL(rump_sys_stat(TESTFILE, &sb2));
#define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a)
- if (FSTYPE_ZFS(tc))
- atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
CHECK(st_uid);
CHECK(st_gid);
@@ -684,9 +765,6 @@ fcntl_lock(const atf_tc_t *tc, const char *mp)
RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
RL(rump_sys_ftruncate(fd, 8192));
- /* PR kern/43321 */
- if (FSTYPE_ZFS(tc))
- atf_tc_expect_fail("PR kern/47656: Test known to be broken");
RL(rump_sys_fcntl(fd, F_SETLK, &l));
/* Next, we fork and try to lock the same area */
@@ -820,9 +898,6 @@ fcntl_getlock_pids(const atf_tc_t *tc, const char *mp)
RL(rump_sys_ftruncate(fd[i], sz));
- if (FSTYPE_ZFS(tc))
- atf_tc_expect_fail("PR kern/47656: Test known to be "
- "broken");
if (i < __arraycount(lock)) {
RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i]));
expect[i].l_pid = pid[i];
@@ -932,9 +1007,6 @@ lstat_symlink(const atf_tc_t *tc, const char *mp)
USES_SYMLINKS;
- if (FSTYPE_V7FS(tc))
- atf_tc_expect_fail("PR kern/48864");
-
FSTEST_ENTER();
src = "source";
@@ -973,6 +1045,11 @@ ATF_TC_FSAPPLY(access_simple, "access(2)");
ATF_TC_FSAPPLY(read_directory, "read(2) on directories");
ATF_TC_FSAPPLY(lstat_symlink, "lstat(2) values for symbolic links");
+#undef FSTEST_IMGSIZE
+#define FSTEST_IMGSIZE (1024*1024*64)
+ATF_TC_FSAPPLY(create_many, "create many directory entries");
+ATF_TC_FSAPPLY(create_nonalphanum, "non-alphanumeric filenames");
+
ATF_TP_ADD_TCS(tp)
{
@@ -984,6 +1061,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_FSAPPLY(rename_dir);
ATF_TP_FSAPPLY(rename_dotdot);
ATF_TP_FSAPPLY(rename_reg_nodir);
+ ATF_TP_FSAPPLY(create_many);
+ ATF_TP_FSAPPLY(create_nonalphanum);
ATF_TP_FSAPPLY(create_nametoolong);
ATF_TP_FSAPPLY(create_exist);
ATF_TP_FSAPPLY(rename_nametoolong);
OpenPOWER on IntegriCloud