1*84d9c625SLionel Sambuc /* $NetBSD: t_basic.c,v 1.12 2013/10/19 17:45:00 christos Exp $ */
211be35a1SLionel Sambuc
311be35a1SLionel Sambuc #include <sys/types.h>
411be35a1SLionel Sambuc #include <sys/mount.h>
511be35a1SLionel Sambuc #include <sys/socket.h>
611be35a1SLionel Sambuc
711be35a1SLionel Sambuc #include <assert.h>
811be35a1SLionel Sambuc #include <atf-c.h>
911be35a1SLionel Sambuc #include <err.h>
1011be35a1SLionel Sambuc #include <errno.h>
1111be35a1SLionel Sambuc #include <fcntl.h>
1211be35a1SLionel Sambuc #include <pthread.h>
1311be35a1SLionel Sambuc #include <puffs.h>
1411be35a1SLionel Sambuc #include <puffsdump.h>
1511be35a1SLionel Sambuc #include <stdio.h>
1611be35a1SLionel Sambuc #include <unistd.h>
1711be35a1SLionel Sambuc #include <string.h>
1811be35a1SLionel Sambuc #include <stdlib.h>
1911be35a1SLionel Sambuc
2011be35a1SLionel Sambuc #include <rump/rump.h>
2111be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
2211be35a1SLionel Sambuc
2311be35a1SLionel Sambuc #include "../../h_macros.h"
2411be35a1SLionel Sambuc #include "../common/h_fsmacros.h"
2511be35a1SLionel Sambuc
2611be35a1SLionel Sambuc /*
2711be35a1SLionel Sambuc * Do a synchronous operation. When this returns, all FAF operations
2811be35a1SLionel Sambuc * have at least been delivered to the file system.
2911be35a1SLionel Sambuc *
3011be35a1SLionel Sambuc * XXX: is this really good enough considering puffs(9)-issued
3111be35a1SLionel Sambuc * callback operations?
3211be35a1SLionel Sambuc */
3311be35a1SLionel Sambuc static void
syncbar(const char * fs)3411be35a1SLionel Sambuc syncbar(const char *fs)
3511be35a1SLionel Sambuc {
3611be35a1SLionel Sambuc struct statvfs svb;
3711be35a1SLionel Sambuc
3811be35a1SLionel Sambuc if (rump_sys_statvfs1(fs, &svb, ST_WAIT) == -1)
3911be35a1SLionel Sambuc atf_tc_fail_errno("statvfs");
4011be35a1SLionel Sambuc }
4111be35a1SLionel Sambuc
4211be35a1SLionel Sambuc #ifdef PUFFSDUMP
4311be35a1SLionel Sambuc static void __unused
dumpopcount(struct puffstestargs * args)4411be35a1SLionel Sambuc dumpopcount(struct puffstestargs *args)
4511be35a1SLionel Sambuc {
4611be35a1SLionel Sambuc size_t i;
4711be35a1SLionel Sambuc
4811be35a1SLionel Sambuc printf("VFS OPS:\n");
4911be35a1SLionel Sambuc for (i = 0; i < MIN(puffsdump_vfsop_count, PUFFS_VFS_MAX); i++) {
5011be35a1SLionel Sambuc printf("\t%s: %d\n",
5111be35a1SLionel Sambuc puffsdump_vfsop_revmap[i], args->pta_vfs_toserv_ops[i]);
5211be35a1SLionel Sambuc }
5311be35a1SLionel Sambuc
5411be35a1SLionel Sambuc printf("VN OPS:\n");
5511be35a1SLionel Sambuc for (i = 0; i < MIN(puffsdump_vnop_count, PUFFS_VN_MAX); i++) {
5611be35a1SLionel Sambuc printf("\t%s: %d\n",
5711be35a1SLionel Sambuc puffsdump_vnop_revmap[i], args->pta_vn_toserv_ops[i]);
5811be35a1SLionel Sambuc }
5911be35a1SLionel Sambuc }
6011be35a1SLionel Sambuc #endif
6111be35a1SLionel Sambuc
6211be35a1SLionel Sambuc ATF_TC(mount);
ATF_TC_HEAD(mount,tc)6311be35a1SLionel Sambuc ATF_TC_HEAD(mount, tc)
6411be35a1SLionel Sambuc {
6511be35a1SLionel Sambuc
6611be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "puffs+dtfs un/mount test");
6711be35a1SLionel Sambuc }
6811be35a1SLionel Sambuc
ATF_TC_BODY(mount,tc)6911be35a1SLionel Sambuc ATF_TC_BODY(mount, tc)
7011be35a1SLionel Sambuc {
7111be35a1SLionel Sambuc void *args;
7211be35a1SLionel Sambuc
7311be35a1SLionel Sambuc FSTEST_CONSTRUCTOR(tc, puffs, args);
7411be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
7511be35a1SLionel Sambuc }
7611be35a1SLionel Sambuc
7711be35a1SLionel Sambuc ATF_TC(root_reg);
ATF_TC_HEAD(root_reg,tc)7811be35a1SLionel Sambuc ATF_TC_HEAD(root_reg, tc)
7911be35a1SLionel Sambuc {
8011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "root is a regular file");
8111be35a1SLionel Sambuc }
8211be35a1SLionel Sambuc
8311be35a1SLionel Sambuc #define MAKEOPTS(...) \
8411be35a1SLionel Sambuc char *theopts[] = {NULL, "-s", __VA_ARGS__, "dtfs", "n/a", NULL}
8511be35a1SLionel Sambuc
ATF_TC_BODY(root_reg,tc)8611be35a1SLionel Sambuc ATF_TC_BODY(root_reg, tc)
8711be35a1SLionel Sambuc {
8811be35a1SLionel Sambuc MAKEOPTS("-r", "reg");
8911be35a1SLionel Sambuc void *args;
9011be35a1SLionel Sambuc int fd, rv;
9111be35a1SLionel Sambuc
9211be35a1SLionel Sambuc FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
9311be35a1SLionel Sambuc
9411be35a1SLionel Sambuc fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR);
9511be35a1SLionel Sambuc if (fd == -1)
9611be35a1SLionel Sambuc atf_tc_fail_errno("open root");
9711be35a1SLionel Sambuc if (rump_sys_write(fd, &fd, sizeof(fd)) != sizeof(fd))
9811be35a1SLionel Sambuc atf_tc_fail_errno("write to root");
9911be35a1SLionel Sambuc rv = rump_sys_mkdir(FSTEST_MNTNAME "/test", 0777);
10011be35a1SLionel Sambuc ATF_REQUIRE(errno == ENOTDIR);
10111be35a1SLionel Sambuc ATF_REQUIRE(rv == -1);
10211be35a1SLionel Sambuc rump_sys_close(fd);
10311be35a1SLionel Sambuc
10411be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
10511be35a1SLionel Sambuc }
10611be35a1SLionel Sambuc
10711be35a1SLionel Sambuc ATF_TC(root_lnk);
ATF_TC_HEAD(root_lnk,tc)10811be35a1SLionel Sambuc ATF_TC_HEAD(root_lnk, tc)
10911be35a1SLionel Sambuc {
11011be35a1SLionel Sambuc
11111be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "root is a symbolic link");
11211be35a1SLionel Sambuc }
11311be35a1SLionel Sambuc
11411be35a1SLionel Sambuc #define LINKSTR "/path/to/nowhere"
ATF_TC_BODY(root_lnk,tc)11511be35a1SLionel Sambuc ATF_TC_BODY(root_lnk, tc)
11611be35a1SLionel Sambuc {
11711be35a1SLionel Sambuc MAKEOPTS("-r", "lnk " LINKSTR);
11811be35a1SLionel Sambuc void *args;
11911be35a1SLionel Sambuc char buf[PATH_MAX];
12011be35a1SLionel Sambuc ssize_t len;
12111be35a1SLionel Sambuc
12211be35a1SLionel Sambuc FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
12311be35a1SLionel Sambuc
12411be35a1SLionel Sambuc if ((len = rump_sys_readlink(FSTEST_MNTNAME, buf, sizeof(buf)-1)) == -1)
12511be35a1SLionel Sambuc atf_tc_fail_errno("readlink");
12611be35a1SLionel Sambuc buf[len] = '\0';
12711be35a1SLionel Sambuc
12811be35a1SLionel Sambuc ATF_REQUIRE_STREQ(buf, LINKSTR);
12911be35a1SLionel Sambuc
13011be35a1SLionel Sambuc #if 0 /* XXX: unmount uses FOLLOW */
13111be35a1SLionel Sambuc if (rump_sys_unmount("/mp", 0) == -1)
13211be35a1SLionel Sambuc atf_tc_fail_errno("unmount");
13311be35a1SLionel Sambuc #endif
13411be35a1SLionel Sambuc }
13511be35a1SLionel Sambuc
13611be35a1SLionel Sambuc ATF_TC(root_fifo);
ATF_TC_HEAD(root_fifo,tc)13711be35a1SLionel Sambuc ATF_TC_HEAD(root_fifo, tc)
13811be35a1SLionel Sambuc {
13911be35a1SLionel Sambuc
14011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "root is a symbolic link");
14111be35a1SLionel Sambuc }
14211be35a1SLionel Sambuc
14311be35a1SLionel Sambuc #define MAGICSTR "nakit ja muusiperunat maustevoilla"
14411be35a1SLionel Sambuc static void *
dofifow(void * arg)14511be35a1SLionel Sambuc dofifow(void *arg)
14611be35a1SLionel Sambuc {
14711be35a1SLionel Sambuc int fd = (int)(uintptr_t)arg;
14811be35a1SLionel Sambuc char buf[512];
14911be35a1SLionel Sambuc
15011be35a1SLionel Sambuc printf("writing\n");
15111be35a1SLionel Sambuc strcpy(buf, MAGICSTR);
15211be35a1SLionel Sambuc if (rump_sys_write(fd, buf, strlen(buf)+1) != strlen(buf)+1)
15311be35a1SLionel Sambuc atf_tc_fail_errno("write to fifo");
15411be35a1SLionel Sambuc
15511be35a1SLionel Sambuc return NULL;
15611be35a1SLionel Sambuc }
15711be35a1SLionel Sambuc
ATF_TC_BODY(root_fifo,tc)15811be35a1SLionel Sambuc ATF_TC_BODY(root_fifo, tc)
15911be35a1SLionel Sambuc {
16011be35a1SLionel Sambuc MAKEOPTS("-r", "fifo");
16111be35a1SLionel Sambuc void *args;
16211be35a1SLionel Sambuc pthread_t pt;
16311be35a1SLionel Sambuc char buf[512];
16411be35a1SLionel Sambuc int fd;
16511be35a1SLionel Sambuc
16611be35a1SLionel Sambuc FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
16711be35a1SLionel Sambuc
16811be35a1SLionel Sambuc fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR);
16911be35a1SLionel Sambuc if (fd == -1)
17011be35a1SLionel Sambuc atf_tc_fail_errno("open fifo");
17111be35a1SLionel Sambuc
17211be35a1SLionel Sambuc pthread_create(&pt, NULL, dofifow, (void *)(uintptr_t)fd);
17311be35a1SLionel Sambuc
17411be35a1SLionel Sambuc memset(buf, 0, sizeof(buf));
17511be35a1SLionel Sambuc if (rump_sys_read(fd, buf, sizeof(buf)) == -1)
17611be35a1SLionel Sambuc atf_tc_fail_errno("read fifo");
17711be35a1SLionel Sambuc
17811be35a1SLionel Sambuc ATF_REQUIRE_STREQ(buf, MAGICSTR);
17911be35a1SLionel Sambuc rump_sys_close(fd);
18011be35a1SLionel Sambuc
18111be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
18211be35a1SLionel Sambuc }
18311be35a1SLionel Sambuc
18411be35a1SLionel Sambuc ATF_TC(root_chrdev);
ATF_TC_HEAD(root_chrdev,tc)18511be35a1SLionel Sambuc ATF_TC_HEAD(root_chrdev, tc)
18611be35a1SLionel Sambuc {
18711be35a1SLionel Sambuc
18811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "root is /dev/null");
18911be35a1SLionel Sambuc }
19011be35a1SLionel Sambuc
ATF_TC_BODY(root_chrdev,tc)19111be35a1SLionel Sambuc ATF_TC_BODY(root_chrdev, tc)
19211be35a1SLionel Sambuc {
19311be35a1SLionel Sambuc MAKEOPTS("-r", "chr 2 2");
19411be35a1SLionel Sambuc void *args;
19511be35a1SLionel Sambuc ssize_t rv;
19611be35a1SLionel Sambuc char buf[512];
19711be35a1SLionel Sambuc int fd;
19811be35a1SLionel Sambuc
19911be35a1SLionel Sambuc FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
20011be35a1SLionel Sambuc
20111be35a1SLionel Sambuc fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR);
20211be35a1SLionel Sambuc if (fd == -1)
20311be35a1SLionel Sambuc atf_tc_fail_errno("open null");
20411be35a1SLionel Sambuc
20511be35a1SLionel Sambuc rv = rump_sys_write(fd, buf, sizeof(buf));
20611be35a1SLionel Sambuc ATF_REQUIRE(rv == sizeof(buf));
20711be35a1SLionel Sambuc
20811be35a1SLionel Sambuc rv = rump_sys_read(fd, buf, sizeof(buf));
20911be35a1SLionel Sambuc ATF_REQUIRE(rv == 0);
21011be35a1SLionel Sambuc
21111be35a1SLionel Sambuc rump_sys_close(fd);
21211be35a1SLionel Sambuc
21311be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
21411be35a1SLionel Sambuc }
21511be35a1SLionel Sambuc
21611be35a1SLionel Sambuc /*
21711be35a1SLionel Sambuc * Inactive/reclaim tests
21811be35a1SLionel Sambuc */
21911be35a1SLionel Sambuc
22011be35a1SLionel Sambuc ATF_TC(inactive_basic);
ATF_TC_HEAD(inactive_basic,tc)22111be35a1SLionel Sambuc ATF_TC_HEAD(inactive_basic, tc)
22211be35a1SLionel Sambuc {
22311be35a1SLionel Sambuc
22411be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "inactive gets called");
22511be35a1SLionel Sambuc }
22611be35a1SLionel Sambuc
ATF_TC_BODY(inactive_basic,tc)22711be35a1SLionel Sambuc ATF_TC_BODY(inactive_basic, tc)
22811be35a1SLionel Sambuc {
22911be35a1SLionel Sambuc struct puffstestargs *pargs;
23011be35a1SLionel Sambuc void *args;
23111be35a1SLionel Sambuc int fd;
23211be35a1SLionel Sambuc
23311be35a1SLionel Sambuc FSTEST_CONSTRUCTOR(tc, puffs, args);
23411be35a1SLionel Sambuc FSTEST_ENTER();
23511be35a1SLionel Sambuc pargs = args;
23611be35a1SLionel Sambuc
23711be35a1SLionel Sambuc fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
23811be35a1SLionel Sambuc if (fd == -1)
23911be35a1SLionel Sambuc atf_tc_fail_errno("create");
24011be35a1SLionel Sambuc
24111be35a1SLionel Sambuc /* none yet */
24211be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0);
24311be35a1SLionel Sambuc
24411be35a1SLionel Sambuc rump_sys_close(fd);
24511be35a1SLionel Sambuc
24611be35a1SLionel Sambuc /* one for file */
24711be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 1);
24811be35a1SLionel Sambuc
24911be35a1SLionel Sambuc FSTEST_EXIT();
25011be35a1SLionel Sambuc
25111be35a1SLionel Sambuc /* another for the mountpoint */
25211be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 2);
25311be35a1SLionel Sambuc
25411be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
25511be35a1SLionel Sambuc }
25611be35a1SLionel Sambuc
25711be35a1SLionel Sambuc ATF_TC(inactive_reclaim);
ATF_TC_HEAD(inactive_reclaim,tc)25811be35a1SLionel Sambuc ATF_TC_HEAD(inactive_reclaim, tc)
25911be35a1SLionel Sambuc {
26011be35a1SLionel Sambuc
26111be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "inactive/reclaim gets called");
26211be35a1SLionel Sambuc }
26311be35a1SLionel Sambuc
ATF_TC_BODY(inactive_reclaim,tc)26411be35a1SLionel Sambuc ATF_TC_BODY(inactive_reclaim, tc)
26511be35a1SLionel Sambuc {
26611be35a1SLionel Sambuc struct puffstestargs *pargs;
26711be35a1SLionel Sambuc void *args;
26811be35a1SLionel Sambuc int fd;
26911be35a1SLionel Sambuc
27011be35a1SLionel Sambuc FSTEST_CONSTRUCTOR(tc, puffs, args);
27111be35a1SLionel Sambuc FSTEST_ENTER();
27211be35a1SLionel Sambuc pargs = args;
27311be35a1SLionel Sambuc
27411be35a1SLionel Sambuc fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
27511be35a1SLionel Sambuc if (fd == -1)
27611be35a1SLionel Sambuc atf_tc_fail_errno("create");
27711be35a1SLionel Sambuc
27811be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0);
27911be35a1SLionel Sambuc
28011be35a1SLionel Sambuc if (rump_sys_unlink("file") == -1)
28111be35a1SLionel Sambuc atf_tc_fail_errno("remove");
28211be35a1SLionel Sambuc
28311be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0);
28411be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0);
28511be35a1SLionel Sambuc
28611be35a1SLionel Sambuc rump_sys_close(fd);
28711be35a1SLionel Sambuc syncbar(FSTEST_MNTNAME);
28811be35a1SLionel Sambuc
28911be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 1);
29011be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 1);
29111be35a1SLionel Sambuc
29211be35a1SLionel Sambuc FSTEST_EXIT();
29311be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
29411be35a1SLionel Sambuc }
29511be35a1SLionel Sambuc
29611be35a1SLionel Sambuc ATF_TC(reclaim_hardlink);
ATF_TC_HEAD(reclaim_hardlink,tc)29711be35a1SLionel Sambuc ATF_TC_HEAD(reclaim_hardlink, tc)
29811be35a1SLionel Sambuc {
29911be35a1SLionel Sambuc
30011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "reclaim gets called only after "
30111be35a1SLionel Sambuc "final link is gone");
30211be35a1SLionel Sambuc }
30311be35a1SLionel Sambuc
ATF_TC_BODY(reclaim_hardlink,tc)30411be35a1SLionel Sambuc ATF_TC_BODY(reclaim_hardlink, tc)
30511be35a1SLionel Sambuc {
30611be35a1SLionel Sambuc struct puffstestargs *pargs;
30711be35a1SLionel Sambuc void *args;
30811be35a1SLionel Sambuc int fd;
30911be35a1SLionel Sambuc int ianow;
31011be35a1SLionel Sambuc
31111be35a1SLionel Sambuc FSTEST_CONSTRUCTOR(tc, puffs, args);
31211be35a1SLionel Sambuc FSTEST_ENTER();
31311be35a1SLionel Sambuc pargs = args;
31411be35a1SLionel Sambuc
31511be35a1SLionel Sambuc fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
31611be35a1SLionel Sambuc if (fd == -1)
31711be35a1SLionel Sambuc atf_tc_fail_errno("create");
31811be35a1SLionel Sambuc
31911be35a1SLionel Sambuc if (rump_sys_link("file", "anotherfile") == -1)
32011be35a1SLionel Sambuc atf_tc_fail_errno("create link");
32111be35a1SLionel Sambuc rump_sys_close(fd);
32211be35a1SLionel Sambuc
32311be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0);
32411be35a1SLionel Sambuc
32511be35a1SLionel Sambuc /* unlink first hardlink */
32611be35a1SLionel Sambuc if (rump_sys_unlink("file") == -1)
32711be35a1SLionel Sambuc atf_tc_fail_errno("unlink 1");
32811be35a1SLionel Sambuc
32911be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0);
33011be35a1SLionel Sambuc ianow = pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE];
33111be35a1SLionel Sambuc
33211be35a1SLionel Sambuc /* unlink second hardlink */
33311be35a1SLionel Sambuc if (rump_sys_unlink("anotherfile") == -1)
33411be35a1SLionel Sambuc atf_tc_fail_errno("unlink 2");
33511be35a1SLionel Sambuc
33611be35a1SLionel Sambuc syncbar(FSTEST_MNTNAME);
33711be35a1SLionel Sambuc
33811be35a1SLionel Sambuc ATF_REQUIRE(ianow < pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE]);
33911be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 1);
34011be35a1SLionel Sambuc
34111be35a1SLionel Sambuc FSTEST_EXIT();
34211be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
34311be35a1SLionel Sambuc }
34411be35a1SLionel Sambuc
34511be35a1SLionel Sambuc ATF_TC(unlink_accessible);
ATF_TC_HEAD(unlink_accessible,tc)34611be35a1SLionel Sambuc ATF_TC_HEAD(unlink_accessible, tc)
34711be35a1SLionel Sambuc {
34811be35a1SLionel Sambuc
34911be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "open file is accessible after "
35011be35a1SLionel Sambuc "having been unlinked");
35111be35a1SLionel Sambuc }
35211be35a1SLionel Sambuc
ATF_TC_BODY(unlink_accessible,tc)35311be35a1SLionel Sambuc ATF_TC_BODY(unlink_accessible, tc)
35411be35a1SLionel Sambuc {
35511be35a1SLionel Sambuc MAKEOPTS("-i", "-o", "nopagecache");
35611be35a1SLionel Sambuc struct puffstestargs *pargs;
35711be35a1SLionel Sambuc void *args;
35811be35a1SLionel Sambuc char buf[512];
35911be35a1SLionel Sambuc int fd, ianow;
36011be35a1SLionel Sambuc
36111be35a1SLionel Sambuc assert(sizeof(buf) > sizeof(MAGICSTR));
36211be35a1SLionel Sambuc
36311be35a1SLionel Sambuc FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
36411be35a1SLionel Sambuc FSTEST_ENTER();
36511be35a1SLionel Sambuc pargs = args;
36611be35a1SLionel Sambuc
36711be35a1SLionel Sambuc fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
36811be35a1SLionel Sambuc if (fd == -1)
36911be35a1SLionel Sambuc atf_tc_fail_errno("create");
37011be35a1SLionel Sambuc
37111be35a1SLionel Sambuc if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR))
37211be35a1SLionel Sambuc atf_tc_fail_errno("write");
37311be35a1SLionel Sambuc if (rump_sys_unlink("file") == -1)
37411be35a1SLionel Sambuc atf_tc_fail_errno("unlink");
37511be35a1SLionel Sambuc
37611be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 0);
37711be35a1SLionel Sambuc ianow = pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE];
37811be35a1SLionel Sambuc
37911be35a1SLionel Sambuc if (rump_sys_pread(fd, buf, sizeof(buf), 0) == -1)
38011be35a1SLionel Sambuc atf_tc_fail_errno("read");
38111be35a1SLionel Sambuc rump_sys_close(fd);
38211be35a1SLionel Sambuc
38311be35a1SLionel Sambuc syncbar(FSTEST_MNTNAME);
38411be35a1SLionel Sambuc
38511be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_RECLAIM], 1);
38611be35a1SLionel Sambuc ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], ianow+1);
38711be35a1SLionel Sambuc
38811be35a1SLionel Sambuc ATF_REQUIRE_STREQ(buf, MAGICSTR);
38911be35a1SLionel Sambuc
39011be35a1SLionel Sambuc FSTEST_EXIT();
39111be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
39211be35a1SLionel Sambuc }
39311be35a1SLionel Sambuc
39411be35a1SLionel Sambuc ATF_TC(signals);
ATF_TC_HEAD(signals,tc)39511be35a1SLionel Sambuc ATF_TC_HEAD(signals, tc)
39611be35a1SLionel Sambuc {
39711be35a1SLionel Sambuc
39811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Checks that sending a signal can "
39911be35a1SLionel Sambuc "cause an interrupt to puffs wait");
40011be35a1SLionel Sambuc }
40111be35a1SLionel Sambuc
40211be35a1SLionel Sambuc extern struct proc *rumpns_initproc;
40311be35a1SLionel Sambuc extern void rumpns_psignal(struct proc *, int);
40411be35a1SLionel Sambuc extern void rumpns_sigclearall(struct proc *, void *, void *);
ATF_TC_BODY(signals,tc)40511be35a1SLionel Sambuc ATF_TC_BODY(signals, tc)
40611be35a1SLionel Sambuc {
40711be35a1SLionel Sambuc struct stat sb;
40811be35a1SLionel Sambuc void *args;
40911be35a1SLionel Sambuc
41011be35a1SLionel Sambuc rump_boot_setsigmodel(RUMP_SIGMODEL_RECORD);
41111be35a1SLionel Sambuc
41211be35a1SLionel Sambuc FSTEST_CONSTRUCTOR(tc, puffs, args);
41311be35a1SLionel Sambuc FSTEST_ENTER();
41411be35a1SLionel Sambuc RL(rump_sys_stat(".", &sb));
41511be35a1SLionel Sambuc
41611be35a1SLionel Sambuc /* send SIGUSR1, should not affect puffs ops */
41711be35a1SLionel Sambuc rump_schedule();
41811be35a1SLionel Sambuc rumpns_psignal(rumpns_initproc, SIGUSR1);
41911be35a1SLionel Sambuc rump_unschedule();
42011be35a1SLionel Sambuc RL(rump_sys_stat(".", &sb));
42111be35a1SLionel Sambuc
42211be35a1SLionel Sambuc /* send SIGTERM, should get EINTR */
42311be35a1SLionel Sambuc rump_schedule();
42411be35a1SLionel Sambuc rumpns_psignal(rumpns_initproc, SIGTERM);
42511be35a1SLionel Sambuc rump_unschedule();
42611be35a1SLionel Sambuc ATF_REQUIRE_ERRNO(EINTR, rump_sys_stat(".", &sb) == -1);
42711be35a1SLionel Sambuc
42811be35a1SLionel Sambuc /* clear sigmask so that we can unmount */
42911be35a1SLionel Sambuc rump_schedule();
43011be35a1SLionel Sambuc rumpns_sigclearall(rumpns_initproc, NULL, NULL);
43111be35a1SLionel Sambuc rump_unschedule();
43211be35a1SLionel Sambuc
43311be35a1SLionel Sambuc FSTEST_EXIT();
43411be35a1SLionel Sambuc FSTEST_DESTRUCTOR(tc, puffs, args);
43511be35a1SLionel Sambuc }
43611be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)43711be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
43811be35a1SLionel Sambuc {
43911be35a1SLionel Sambuc
44011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, mount);
44111be35a1SLionel Sambuc
44211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, root_fifo);
44311be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, root_lnk);
44411be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, root_reg);
44511be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, root_chrdev);
44611be35a1SLionel Sambuc
44711be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, inactive_basic);
44811be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, inactive_reclaim);
44911be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, reclaim_hardlink);
45011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, unlink_accessible);
45111be35a1SLionel Sambuc
45211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, signals);
45311be35a1SLionel Sambuc
45411be35a1SLionel Sambuc return atf_no_error();
45511be35a1SLionel Sambuc }
456