Module Name:    src
Committed By:   pooka
Date:           Tue Mar 30 01:02:47 UTC 2010

Modified Files:
        src/tests/fs: Makefile
Added Files:
        src/tests/fs/nullfs: Atffile Makefile t_basic.c

Log Message:
Basic test for nullfs, which just checks that the two views act
somewhat sensibly.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/fs/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/fs/nullfs/Atffile \
    src/tests/fs/nullfs/Makefile src/tests/fs/nullfs/t_basic.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/fs/Makefile
diff -u src/tests/fs/Makefile:1.5 src/tests/fs/Makefile:1.6
--- src/tests/fs/Makefile:1.5	Mon Mar 29 18:19:19 2010
+++ src/tests/fs/Makefile	Tue Mar 30 01:02:47 2010
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.5 2010/03/29 18:19:19 pooka Exp $
+# $NetBSD: Makefile,v 1.6 2010/03/30 01:02:47 pooka Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/fs
 
-SUBDIR+=	ffs puffs tmpfs union
+SUBDIR+=	ffs nullfs puffs tmpfs union
 
 FILES= h_funcs.subr
 FILESDIR= ${TESTSDIR}

Added files:

Index: src/tests/fs/nullfs/Atffile
diff -u /dev/null src/tests/fs/nullfs/Atffile:1.1
--- /dev/null	Tue Mar 30 01:02:47 2010
+++ src/tests/fs/nullfs/Atffile	Tue Mar 30 01:02:47 2010
@@ -0,0 +1,6 @@
+Content-Type: application/X-atf-atffile; version="1"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2010/03/30 01:02:47 pooka Exp $"
+
+prop: test-suite = "NetBSD"
+
+tp: t_*
Index: src/tests/fs/nullfs/Makefile
diff -u /dev/null src/tests/fs/nullfs/Makefile:1.1
--- /dev/null	Tue Mar 30 01:02:47 2010
+++ src/tests/fs/nullfs/Makefile	Tue Mar 30 01:02:47 2010
@@ -0,0 +1,12 @@
+#	$NetBSD: Makefile,v 1.1 2010/03/30 01:02:47 pooka Exp $
+#
+
+TESTSDIR=	${TESTSBASE}/fs/union
+WARNS=		4
+
+TESTS_C=	t_basic
+
+LDADD+=	-lrumpfs_tmpfs -lrumpfs_nullfs -lrumpvfs_layerfs	# fs drivers
+LDADD+=	-lrumpvfs -lrump -lrumpuser -lpthread			# base
+
+.include <bsd.test.mk>
Index: src/tests/fs/nullfs/t_basic.c
diff -u /dev/null src/tests/fs/nullfs/t_basic.c:1.1
--- /dev/null	Tue Mar 30 01:02:47 2010
+++ src/tests/fs/nullfs/t_basic.c	Tue Mar 30 01:02:47 2010
@@ -0,0 +1,137 @@
+/*	$NetBSD: t_basic.c,v 1.1 2010/03/30 01:02:47 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/nullfs/null.h>
+#include <fs/tmpfs/tmpfs_args.h>
+
+#define USE_ATF
+#include "../../h_macros.h"
+
+#ifdef USE_ATF
+ATF_TC(basic);
+ATF_TC_HEAD(basic, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "basic nullfs functionality");
+}
+#else
+#define atf_tc_fail(...) errx(1, __VA_ARGS__)
+#endif
+
+#define MSTR "magic bus"
+
+static void
+xput_tfile(const char *path, const char *mstr)
+{
+	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, const char *mstr)
+{
+	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;
+}
+
+#ifdef USE_ATF
+ATF_TC_BODY(basic, tc)
+#else
+int main(int argc, char *argv[])
+#endif
+{
+	struct null_args nargs;
+	struct tmpfs_args targs;
+	struct stat sb;
+	int error;
+
+	rump_init();
+	if (rump_sys_mkdir("/td1", 0777) == -1)
+		atf_tc_fail_errno("mp1");
+	if (rump_sys_mkdir("/td2", 0777) == -1)
+		atf_tc_fail_errno("mp1");
+
+	/* use tmpfs because rumpfs doesn't support regular files */
+	memset(&targs, 0, sizeof(targs));
+	targs.ta_version = TMPFS_ARGS_VERSION;
+	targs.ta_root_mode = 0777;
+	if (rump_sys_mount(MOUNT_TMPFS, "/td1", 0, &targs, sizeof(targs)) == -1)
+		atf_tc_fail_errno("could not mount tmpfs td1");
+
+	memset(&nargs, 0, sizeof(nargs));
+	nargs.nulla_target = __UNCONST("/td1");
+	if (rump_sys_mount(MOUNT_NULL, "/td2", 0, &nargs, sizeof(nargs)) == -1)
+		atf_tc_fail_errno("could not mount nullfs");
+
+	/* test unnull -> null */
+	xput_tfile("/td1/tensti", "jeppe");
+	error = xread_tfile("/td2/tensti", "jeppe");
+	if (error != 0)
+		atf_tc_fail("null compare failed: %d (%s)",
+		    error, strerror(error));
+
+	/* test null -> unnull */
+	xput_tfile("/td2/kiekko", "keppi");
+	error = xread_tfile("/td1/kiekko", "keppi");
+	if (error != 0)
+		atf_tc_fail("unnull compare failed: %d (%s)",
+		    error, strerror(error));
+
+	/* test unnull -> null overwrite */
+	xput_tfile("/td1/tensti", "se oolannin sota");
+	error = xread_tfile("/td2/tensti", "se oolannin sota");
+	if (error != 0)
+		atf_tc_fail("unnull compare failed: %d (%s)",
+		    error, strerror(error));
+
+	/* test that /td2 is unaffected in "real life" */
+	if (rump_sys_unmount("/td2", 0) == -1)
+		atf_tc_fail_errno("cannot unmount nullfs");
+	if ((error = rump_sys_stat("/td2/tensti", &sb)) != -1
+	    || errno != ENOENT) {
+		atf_tc_fail("stat tensti should return ENOENT, got %d", error);
+	}
+	if ((error = rump_sys_stat("/td2/kiekko", &sb)) != -1
+	    || errno != ENOENT) {
+		atf_tc_fail("stat kiekko should return ENOENT, got %d", error);
+	}
+
+	/* done */
+}
+
+#ifdef USE_ATF
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, basic);
+	return 0; /*XXX?*/
+}
+#endif

Reply via email to