Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/fs Move basic unionfs test from fs/union to fs/vfs and...



details:   https://anonhg.NetBSD.org/src/rev/a10ced5c6eee
branches:  trunk
changeset: 760763:a10ced5c6eee
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed Jan 12 21:13:26 2011 +0000

description:
Move basic unionfs test from fs/union to fs/vfs and make it test
all whiteout-supporting file systems with the file system in question
as the upper layer.  Also, add an unlink to the test to see if
whiteouts are really working.

ffslog_basic is the test case for PR kern/44377

diffstat:

 tests/fs/union/Makefile  |    4 +-
 tests/fs/union/t_basic.c |  116 ----------------------------------------
 tests/fs/vfs/Makefile    |    4 +-
 tests/fs/vfs/t_union.c   |  136 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 141 insertions(+), 119 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 9efc46a840c3 -r a10ced5c6eee tests/fs/union/Makefile
--- a/tests/fs/union/Makefile   Wed Jan 12 21:08:55 2011 +0000
+++ b/tests/fs/union/Makefile   Wed Jan 12 21:13:26 2011 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.2 2010/06/29 15:25:28 pooka Exp $
+#      $NetBSD: Makefile,v 1.3 2011/01/12 21:13:26 pooka Exp $
 #
 
 TESTSDIR=      ${TESTSBASE}/fs/union
 WARNS=         4
 
-TESTS_C=       t_basic t_pr
+TESTS_C=       t_pr
 
 LDADD+=        -lrumpfs_union -lrumpvfs_layerfs -lrumpfs_ffs           # fs drivers
 LDADD+=        -lrumpdev_disk -lrumpdev                                # disk device
diff -r 9efc46a840c3 -r a10ced5c6eee tests/fs/union/t_basic.c
--- a/tests/fs/union/t_basic.c  Wed Jan 12 21:08:55 2011 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-/*     $NetBSD: t_basic.c,v 1.6 2011/01/12 17:16:24 pooka Exp $        */
-
-#include <sys/types.h>
-#include <sys/mount.h>
-
-#include <atf-c.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <rump/rump.h>
-#include <rump/rump_syscalls.h>
-
-#include <miscfs/union/union.h>
-#include <ufs/ufs/ufsmount.h>
-
-#include "../../h_macros.h"
-
-ATF_TC(basic);
-ATF_TC_HEAD(basic, tc)
-{
-       atf_tc_set_md_var(tc, "descr", "basic union functionality: two views");
-}
-
-#define MSTR "magic bus"
-
-static void
-xput_tfile(const char *path)
-{
-       int fd;
-
-       fd = rump_sys_open(path, O_CREAT | O_RDWR, 0777);
-       if (fd == -1)
-               atf_tc_fail_errno("create %s", path);
-       if (rump_sys_write(fd, MSTR, sizeof(MSTR)) != sizeof(MSTR))
-               atf_tc_fail_errno("write to testfile");
-       rump_sys_close(fd);
-}
-
-static int
-xread_tfile(const char *path)
-{
-       char buf[128];
-       int fd;
-
-       fd = rump_sys_open(path, O_RDONLY);
-       if (fd == -1)
-               return errno;
-       if (rump_sys_read(fd, buf, sizeof(buf)) == -1)
-               atf_tc_fail_errno("read tfile");
-       rump_sys_close(fd);
-       if (strcmp(buf, MSTR) == 0)
-               return 0;
-       return EPROGMISMATCH;
-}
-
-#define IMG1 "atf1.img"
-#define DEV1 "/dev/fs1"
-#define newfs_base "newfs -F -s 10000 "
-
-ATF_TC_BODY(basic, tc)
-{
-       struct ufs_args args;
-       struct union_args unionargs;
-       int error;
-
-       if (system(newfs_base IMG1) == -1)
-               atf_tc_fail_errno("create img1");
-
-       rump_init();
-       rump_pub_etfs_register(DEV1, IMG1, RUMP_ETFS_BLK);
-
-       if (rump_sys_mkdir("/mp1", 0777) == -1)
-               atf_tc_fail_errno("mp1");
-       if (rump_sys_mkdir("/mp2", 0777) == -1)
-               atf_tc_fail_errno("mp1");
-
-       memset(&args, 0, sizeof(args));
-       args.fspec = __UNCONST(DEV1);
-       if (rump_sys_mount(MOUNT_FFS, "/mp1", 0, &args, sizeof(args)) == -1)
-               atf_tc_fail_errno("could not mount ffs1");
-
-       xput_tfile("/mp1/tensti");
-       memset(&unionargs, 0, sizeof(unionargs));
-
-       unionargs.target = __UNCONST("/mp1");
-       unionargs.mntflags = UNMNT_BELOW;
-
-       if (rump_sys_mount(MOUNT_UNION, "/mp2", 0,
-           &unionargs, sizeof(unionargs)) == -1)
-               atf_tc_fail_errno("union mount");
-
-       /* first, test we can read the old file from the new namespace */
-       error = xread_tfile("/mp2/tensti");
-       if (error != 0)
-               atf_tc_fail("union compare failed: %d (%s)",
-                   error, strerror(error));
-
-       /* then, test upper layer writes don't affect the lower layer */
-       xput_tfile("/mp2/kiekko");
-       if ((error = xread_tfile("/mp1/kiekko")) != ENOENT)
-               atf_tc_fail("invisibility failed: %d (%s)",
-                   error, strerror(error));
-
-       /* unmount etc. yaddayadda if non-lazy */
-}
-
-ATF_TP_ADD_TCS(tp)
-{
-       ATF_TP_ADD_TC(tp, basic);
-       return 0; /*XXX?*/
-}
diff -r 9efc46a840c3 -r a10ced5c6eee tests/fs/vfs/Makefile
--- a/tests/fs/vfs/Makefile     Wed Jan 12 21:08:55 2011 +0000
+++ b/tests/fs/vfs/Makefile     Wed Jan 12 21:13:26 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.14 2011/01/06 15:19:10 njoly Exp $
+#      $NetBSD: Makefile,v 1.15 2011/01/12 21:13:27 pooka Exp $
 #
 
 .include <bsd.own.mk>
@@ -11,6 +11,7 @@
 TESTS_C+=      t_renamerace
 TESTS_C+=      t_ro
 TESTS_C+=      t_rmdirrace
+TESTS_C+=      t_union
 TESTS_C+=      t_unpriv
 TESTS_C+=      t_vfsops
 TESTS_C+=      t_vnops
@@ -23,6 +24,7 @@
 LDADD+=-lrumpdev_putter -lrumpdev                              #   \ putter
 LDADD+=-lrumpfs_sysvbfs                                                # sysvbfs
 LDADD+=-lrumpfs_tmpfs                                          # tmpfs
+LDADD+=-lrumpfs_union                                          # union
 LDADD+=-lrumpdev_disk -lrumpdev                                        # disk device
 
 
diff -r 9efc46a840c3 -r a10ced5c6eee tests/fs/vfs/t_union.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fs/vfs/t_union.c    Wed Jan 12 21:13:26 2011 +0000
@@ -0,0 +1,136 @@
+/*     $NetBSD: t_union.c,v 1.1 2011/01/12 21:13:27 pooka Exp $        */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <atf-c.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <miscfs/union/union.h>
+
+#include "../../h_macros.h"
+#include "../common/h_fsmacros.h"
+
+#define MSTR "magic bus"
+
+#define HAS_WHITEOUT (FSTYPE_FFS(tc) || FSTYPE_FFSLOG(tc) ||   \
+    FSTYPE_LFS(tc) || FSTYPE_RUMPFS(tc))
+
+static void
+xput_tfile(const char *mp, const char *path)
+{
+       char pathb[MAXPATHLEN];
+       int fd;
+
+       strcpy(pathb, mp);
+       strcat(pathb, "/");
+       strcat(pathb, path);
+
+       RL(fd = rump_sys_open(pathb, O_CREAT | O_RDWR, 0777));
+       if (rump_sys_write(fd, MSTR, sizeof(MSTR)) != sizeof(MSTR))
+               atf_tc_fail_errno("write to testfile");
+       RL(rump_sys_close(fd));
+}
+
+static int
+xread_tfile(const char *mp, const char *path)
+{
+       char pathb[MAXPATHLEN];
+       char buf[128];
+       int fd;
+
+       strcpy(pathb, mp);
+       strcat(pathb, "/");
+       strcat(pathb, path);
+
+       fd = rump_sys_open(pathb, O_RDONLY);
+       if (fd == -1)
+               return errno;
+       if (rump_sys_read(fd, buf, sizeof(buf)) == -1)
+               atf_tc_fail_errno("read tfile");
+       RL(rump_sys_close(fd));
+       if (strcmp(buf, MSTR) == 0)
+               return 0;
+       return EPROGMISMATCH;
+}
+
+#define TFILE "tensti"
+static void
+basic(const atf_tc_t *tc, const char *mp)
+{
+       char lowerpath[MAXPATHLEN];
+       char dbuf[8192];
+       struct union_args unionargs;
+       struct stat sb;
+       struct dirent *dp;
+       int error, fd, dsize;
+
+       if (!HAS_WHITEOUT) {
+               atf_tc_skip("file system does not support VOP_WHITEOUT");
+       }
+
+       snprintf(lowerpath, sizeof(lowerpath), "%s.lower", mp);
+
+       RL(rump_sys_mkdir(lowerpath, 0777));
+
+       /* create a file in the lower layer */
+       xput_tfile(lowerpath, TFILE);
+
+       /* mount the union with our testfs as the upper layer */
+       memset(&unionargs, 0, sizeof(unionargs));
+       unionargs.target = lowerpath;
+       unionargs.mntflags = UNMNT_BELOW;
+
+       if (rump_sys_mount(MOUNT_UNION, mp, 0,
+           &unionargs, sizeof(unionargs)) == -1)
+               atf_tc_fail_errno("union mount");
+
+       /* first, test we can read the old file from the new namespace */
+       error = xread_tfile(mp, TFILE);
+       if (error != 0)
+               atf_tc_fail("union compare failed: %d (%s)",
+                   error, strerror(error));
+
+       /* then, test upper layer writes don't affect the lower layer */
+       xput_tfile(mp, "kiekko");
+       if ((error = xread_tfile(lowerpath, "kiekko")) != ENOENT)
+               atf_tc_fail("invisibility failed: %d (%s)",
+                   error, strerror(error));
+       
+       /* check that we can whiteout stuff in the upper layer */
+       FSTEST_ENTER();
+       RL(rump_sys_unlink(TFILE));
+       ATF_REQUIRE_ERRNO(ENOENT, rump_sys_stat(TFILE, &sb) == -1);
+       FSTEST_EXIT();
+
+       /* check that the removed node is not in the directory listing */
+       RL(fd = rump_sys_open(mp, O_RDONLY));
+       RL(dsize = rump_sys_getdents(fd, dbuf, sizeof(dbuf)));
+       for (dp = (struct dirent *)dbuf;
+           (char *)dp < dbuf + dsize;
+           dp = _DIRENT_NEXT(dp)) {
+               if (strcmp(dp->d_name, TFILE) == 0 && dp->d_type != DT_WHT)
+                       atf_tc_fail("removed file non-white-outed");
+       }
+       RL(rump_sys_close(fd));
+
+       RL(rump_sys_unmount(mp, 0));
+}
+
+ATF_TC_FSAPPLY(basic, "check basic union functionality");
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_FSAPPLY(basic);
+       return atf_no_error();



Home | Main Index | Thread Index | Old Index