Add basic union test.
This commit is contained in:
parent
6b070d58f9
commit
9e4e4976ad
@ -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
|
||||
|
@ -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 <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/fs
|
||||
|
||||
SUBDIR= ffs puffs tmpfs
|
||||
SUBDIR+= ffs puffs tmpfs union
|
||||
|
||||
FILES= h_funcs.subr
|
||||
FILESDIR= ${TESTSDIR}
|
||||
|
6
tests/fs/union/Atffile
Normal file
6
tests/fs/union/Atffile
Normal file
@ -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_*
|
13
tests/fs/union/Makefile
Normal file
13
tests/fs/union/Makefile
Normal file
@ -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 <bsd.test.mk>
|
137
tests/fs/union/t_basic.c
Normal file
137
tests/fs/union/t_basic.c
Normal file
@ -0,0 +1,137 @@
|
||||
/* $NetBSD: t_basic.c,v 1.1 2010/03/29 18:19:19 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>
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user