From 9e4e4976adf3ab2d6846daf78d0fb46097ca2a15 Mon Sep 17 00:00:00 2001 From: pooka Date: Mon, 29 Mar 2010 18:19:19 +0000 Subject: [PATCH] Add basic union test. --- tests/fs/Atffile | 4 +- tests/fs/Makefile | 4 +- tests/fs/union/Atffile | 6 ++ tests/fs/union/Makefile | 13 ++++ tests/fs/union/t_basic.c | 137 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 tests/fs/union/Atffile create mode 100644 tests/fs/union/Makefile create mode 100644 tests/fs/union/t_basic.c diff --git a/tests/fs/Atffile b/tests/fs/Atffile index 91d6e4d3c6ee..c3050c645ec3 100644 --- a/tests/fs/Atffile +++ b/tests/fs/Atffile @@ -1,6 +1,6 @@ Content-Type: application/X-atf-atffile; version="1" -X-NetBSD-Id: "$NetBSD: Atffile,v 1.4 2007/12/30 09:13:32 jmmv Exp $" +X-NetBSD-Id: "$NetBSD: Atffile,v 1.5 2010/03/29 18:19:19 pooka Exp $" prop: test-suite = "NetBSD" -tp-glob: *fs +tp-glob: *fs union diff --git a/tests/fs/Makefile b/tests/fs/Makefile index d499aefabd63..8aa1b8ecdd99 100644 --- a/tests/fs/Makefile +++ b/tests/fs/Makefile @@ -1,10 +1,10 @@ -# $NetBSD: Makefile,v 1.4 2009/04/08 12:09:04 pooka Exp $ +# $NetBSD: Makefile,v 1.5 2010/03/29 18:19:19 pooka Exp $ .include TESTSDIR= ${TESTSBASE}/fs -SUBDIR= ffs puffs tmpfs +SUBDIR+= ffs puffs tmpfs union FILES= h_funcs.subr FILESDIR= ${TESTSDIR} diff --git a/tests/fs/union/Atffile b/tests/fs/union/Atffile new file mode 100644 index 000000000000..49ba491c928a --- /dev/null +++ b/tests/fs/union/Atffile @@ -0,0 +1,6 @@ +Content-Type: application/X-atf-atffile; version="1" +X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2010/03/29 18:19:19 pooka Exp $" + +prop: test-suite = "NetBSD" + +tp: t_* diff --git a/tests/fs/union/Makefile b/tests/fs/union/Makefile new file mode 100644 index 000000000000..c7347a482a32 --- /dev/null +++ b/tests/fs/union/Makefile @@ -0,0 +1,13 @@ +# $NetBSD: Makefile,v 1.1 2010/03/29 18:19:19 pooka Exp $ +# + +TESTSDIR= ${TESTSBASE}/fs/union +WARNS= 4 + +TESTS_C= t_basic + +LDADD+= -lrumpfs_union -lrumpvfs_layerfs -lrumpfs_ffs # fs drivers +LDADD+= -lrumpdev_disk -lrumpdev # disk device +LDADD+= -lrumpvfs -lrump -lrumpuser -lpthread # base + +.include diff --git a/tests/fs/union/t_basic.c b/tests/fs/union/t_basic.c new file mode 100644 index 000000000000..8d1dfa6d6027 --- /dev/null +++ b/tests/fs/union/t_basic.c @@ -0,0 +1,137 @@ +/* $NetBSD: t_basic.c,v 1.1 2010/03/29 18:19:19 pooka Exp $ */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#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 union functionality: two views"); +} +#else +#define atf_tc_fail(a, ...) errx(1, __VA_ARGS__) +#endif + +#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 IMG2 "atf2.img" +#define DEV1 "/dev/fs1" +#define DEV2 "/dev/fs2" +#define newfs_base "newfs -F -s 10000 " + +#ifdef USE_ATF +ATF_TC_BODY(basic, tc) +#else +int main(int argc, char *argv[]) +#endif +{ + struct ufs_args args; + struct union_args unionargs; + int error; + + if (system(newfs_base IMG1) == -1) + atf_tc_fail_errno("create img1"); + if (system(newfs_base IMG2) == -1) + atf_tc_fail_errno("create img2"); + + rump_init(); + rump_pub_etfs_register(DEV1, IMG1, RUMP_ETFS_BLK); + rump_pub_etfs_register(DEV2, IMG2, 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"); + + memset(&args, 0, sizeof(args)); + args.fspec = __UNCONST(DEV2); + if (rump_sys_mount(MOUNT_FFS, "/mp2", 0, &args, sizeof(args)) == -1) + atf_tc_fail_errno("could not mount tmpfs2"); + + 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 */ +} + +#ifdef USE_ATF +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, basic); + return 0; /*XXX?*/ +} +#endif