1 /* $NetBSD: t_basic.c,v 1.12 2013/10/19 17:45:00 christos Exp $ */
5 #include <sys/socket.h>
14 #include <puffsdump.h>
20 #include <rump/rump.h>
21 #include <rump/rump_syscalls.h>
23 #include "../../h_macros.h"
24 #include "../common/h_fsmacros.h"
27 * Do a synchronous operation. When this returns, all FAF operations
28 * have at least been delivered to the file system.
30 * XXX: is this really good enough considering puffs(9)-issued
31 * callback operations?
34 syncbar(const char *fs
)
38 if (rump_sys_statvfs1(fs
, &svb
, ST_WAIT
) == -1)
39 atf_tc_fail_errno("statvfs");
44 dumpopcount(struct puffstestargs
*args
)
49 for (i
= 0; i
< MIN(puffsdump_vfsop_count
, PUFFS_VFS_MAX
); i
++) {
51 puffsdump_vfsop_revmap
[i
], args
->pta_vfs_toserv_ops
[i
]);
55 for (i
= 0; i
< MIN(puffsdump_vnop_count
, PUFFS_VN_MAX
); i
++) {
57 puffsdump_vnop_revmap
[i
], args
->pta_vn_toserv_ops
[i
]);
63 ATF_TC_HEAD(mount
, tc
)
66 atf_tc_set_md_var(tc
, "descr", "puffs+dtfs un/mount test");
69 ATF_TC_BODY(mount
, tc
)
73 FSTEST_CONSTRUCTOR(tc
, puffs
, args
);
74 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
78 ATF_TC_HEAD(root_reg
, tc
)
80 atf_tc_set_md_var(tc
, "descr", "root is a regular file");
83 #define MAKEOPTS(...) \
84 char *theopts[] = {NULL, "-s", __VA_ARGS__, "dtfs", "n/a", NULL}
86 ATF_TC_BODY(root_reg
, tc
)
88 MAKEOPTS("-r", "reg");
92 FSTEST_CONSTRUCTOR_FSPRIV(tc
, puffs
, args
, theopts
);
94 fd
= rump_sys_open(FSTEST_MNTNAME
, O_RDWR
);
96 atf_tc_fail_errno("open root");
97 if (rump_sys_write(fd
, &fd
, sizeof(fd
)) != sizeof(fd
))
98 atf_tc_fail_errno("write to root");
99 rv
= rump_sys_mkdir(FSTEST_MNTNAME
"/test", 0777);
100 ATF_REQUIRE(errno
== ENOTDIR
);
101 ATF_REQUIRE(rv
== -1);
104 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
108 ATF_TC_HEAD(root_lnk
, tc
)
111 atf_tc_set_md_var(tc
, "descr", "root is a symbolic link");
114 #define LINKSTR "/path/to/nowhere"
115 ATF_TC_BODY(root_lnk
, tc
)
117 MAKEOPTS("-r", "lnk " LINKSTR
);
122 FSTEST_CONSTRUCTOR_FSPRIV(tc
, puffs
, args
, theopts
);
124 if ((len
= rump_sys_readlink(FSTEST_MNTNAME
, buf
, sizeof(buf
)-1)) == -1)
125 atf_tc_fail_errno("readlink");
128 ATF_REQUIRE_STREQ(buf
, LINKSTR
);
130 #if 0 /* XXX: unmount uses FOLLOW */
131 if (rump_sys_unmount("/mp", 0) == -1)
132 atf_tc_fail_errno("unmount");
137 ATF_TC_HEAD(root_fifo
, tc
)
140 atf_tc_set_md_var(tc
, "descr", "root is a symbolic link");
143 #define MAGICSTR "nakit ja muusiperunat maustevoilla"
147 int fd
= (int)(uintptr_t)arg
;
151 strcpy(buf
, MAGICSTR
);
152 if (rump_sys_write(fd
, buf
, strlen(buf
)+1) != strlen(buf
)+1)
153 atf_tc_fail_errno("write to fifo");
158 ATF_TC_BODY(root_fifo
, tc
)
160 MAKEOPTS("-r", "fifo");
166 FSTEST_CONSTRUCTOR_FSPRIV(tc
, puffs
, args
, theopts
);
168 fd
= rump_sys_open(FSTEST_MNTNAME
, O_RDWR
);
170 atf_tc_fail_errno("open fifo");
172 pthread_create(&pt
, NULL
, dofifow
, (void *)(uintptr_t)fd
);
174 memset(buf
, 0, sizeof(buf
));
175 if (rump_sys_read(fd
, buf
, sizeof(buf
)) == -1)
176 atf_tc_fail_errno("read fifo");
178 ATF_REQUIRE_STREQ(buf
, MAGICSTR
);
181 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
185 ATF_TC_HEAD(root_chrdev
, tc
)
188 atf_tc_set_md_var(tc
, "descr", "root is /dev/null");
191 ATF_TC_BODY(root_chrdev
, tc
)
193 MAKEOPTS("-r", "chr 2 2");
199 FSTEST_CONSTRUCTOR_FSPRIV(tc
, puffs
, args
, theopts
);
201 fd
= rump_sys_open(FSTEST_MNTNAME
, O_RDWR
);
203 atf_tc_fail_errno("open null");
205 rv
= rump_sys_write(fd
, buf
, sizeof(buf
));
206 ATF_REQUIRE(rv
== sizeof(buf
));
208 rv
= rump_sys_read(fd
, buf
, sizeof(buf
));
209 ATF_REQUIRE(rv
== 0);
213 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
217 * Inactive/reclaim tests
220 ATF_TC(inactive_basic
);
221 ATF_TC_HEAD(inactive_basic
, tc
)
224 atf_tc_set_md_var(tc
, "descr", "inactive gets called");
227 ATF_TC_BODY(inactive_basic
, tc
)
229 struct puffstestargs
*pargs
;
233 FSTEST_CONSTRUCTOR(tc
, puffs
, args
);
237 fd
= rump_sys_open("file", O_CREAT
| O_RDWR
, 0777);
239 atf_tc_fail_errno("create");
242 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], 0);
247 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], 1);
251 /* another for the mountpoint */
252 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], 2);
254 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
257 ATF_TC(inactive_reclaim
);
258 ATF_TC_HEAD(inactive_reclaim
, tc
)
261 atf_tc_set_md_var(tc
, "descr", "inactive/reclaim gets called");
264 ATF_TC_BODY(inactive_reclaim
, tc
)
266 struct puffstestargs
*pargs
;
270 FSTEST_CONSTRUCTOR(tc
, puffs
, args
);
274 fd
= rump_sys_open("file", O_CREAT
| O_RDWR
, 0777);
276 atf_tc_fail_errno("create");
278 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], 0);
280 if (rump_sys_unlink("file") == -1)
281 atf_tc_fail_errno("remove");
283 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], 0);
284 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 0);
287 syncbar(FSTEST_MNTNAME
);
289 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], 1);
290 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 1);
293 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
296 ATF_TC(reclaim_hardlink
);
297 ATF_TC_HEAD(reclaim_hardlink
, tc
)
300 atf_tc_set_md_var(tc
, "descr", "reclaim gets called only after "
301 "final link is gone");
304 ATF_TC_BODY(reclaim_hardlink
, tc
)
306 struct puffstestargs
*pargs
;
311 FSTEST_CONSTRUCTOR(tc
, puffs
, args
);
315 fd
= rump_sys_open("file", O_CREAT
| O_RDWR
, 0777);
317 atf_tc_fail_errno("create");
319 if (rump_sys_link("file", "anotherfile") == -1)
320 atf_tc_fail_errno("create link");
323 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 0);
325 /* unlink first hardlink */
326 if (rump_sys_unlink("file") == -1)
327 atf_tc_fail_errno("unlink 1");
329 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 0);
330 ianow
= pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
];
332 /* unlink second hardlink */
333 if (rump_sys_unlink("anotherfile") == -1)
334 atf_tc_fail_errno("unlink 2");
336 syncbar(FSTEST_MNTNAME
);
338 ATF_REQUIRE(ianow
< pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
]);
339 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 1);
342 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
345 ATF_TC(unlink_accessible
);
346 ATF_TC_HEAD(unlink_accessible
, tc
)
349 atf_tc_set_md_var(tc
, "descr", "open file is accessible after "
350 "having been unlinked");
353 ATF_TC_BODY(unlink_accessible
, tc
)
355 MAKEOPTS("-i", "-o", "nopagecache");
356 struct puffstestargs
*pargs
;
361 assert(sizeof(buf
) > sizeof(MAGICSTR
));
363 FSTEST_CONSTRUCTOR_FSPRIV(tc
, puffs
, args
, theopts
);
367 fd
= rump_sys_open("file", O_CREAT
| O_RDWR
, 0777);
369 atf_tc_fail_errno("create");
371 if (rump_sys_write(fd
, MAGICSTR
, sizeof(MAGICSTR
)) != sizeof(MAGICSTR
))
372 atf_tc_fail_errno("write");
373 if (rump_sys_unlink("file") == -1)
374 atf_tc_fail_errno("unlink");
376 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 0);
377 ianow
= pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
];
379 if (rump_sys_pread(fd
, buf
, sizeof(buf
), 0) == -1)
380 atf_tc_fail_errno("read");
383 syncbar(FSTEST_MNTNAME
);
385 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_RECLAIM
], 1);
386 ATF_REQUIRE_EQ(pargs
->pta_vn_toserv_ops
[PUFFS_VN_INACTIVE
], ianow
+1);
388 ATF_REQUIRE_STREQ(buf
, MAGICSTR
);
391 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
395 ATF_TC_HEAD(signals
, tc
)
398 atf_tc_set_md_var(tc
, "descr", "Checks that sending a signal can "
399 "cause an interrupt to puffs wait");
402 extern struct proc
*rumpns_initproc
;
403 extern void rumpns_psignal(struct proc
*, int);
404 extern void rumpns_sigclearall(struct proc
*, void *, void *);
405 ATF_TC_BODY(signals
, tc
)
410 rump_boot_setsigmodel(RUMP_SIGMODEL_RECORD
);
412 FSTEST_CONSTRUCTOR(tc
, puffs
, args
);
414 RL(rump_sys_stat(".", &sb
));
416 /* send SIGUSR1, should not affect puffs ops */
418 rumpns_psignal(rumpns_initproc
, SIGUSR1
);
420 RL(rump_sys_stat(".", &sb
));
422 /* send SIGTERM, should get EINTR */
424 rumpns_psignal(rumpns_initproc
, SIGTERM
);
426 ATF_REQUIRE_ERRNO(EINTR
, rump_sys_stat(".", &sb
) == -1);
428 /* clear sigmask so that we can unmount */
430 rumpns_sigclearall(rumpns_initproc
, NULL
, NULL
);
434 FSTEST_DESTRUCTOR(tc
, puffs
, args
);
440 ATF_TP_ADD_TC(tp
, mount
);
442 ATF_TP_ADD_TC(tp
, root_fifo
);
443 ATF_TP_ADD_TC(tp
, root_lnk
);
444 ATF_TP_ADD_TC(tp
, root_reg
);
445 ATF_TP_ADD_TC(tp
, root_chrdev
);
447 ATF_TP_ADD_TC(tp
, inactive_basic
);
448 ATF_TP_ADD_TC(tp
, inactive_reclaim
);
449 ATF_TP_ADD_TC(tp
, reclaim_hardlink
);
450 ATF_TP_ADD_TC(tp
, unlink_accessible
);
452 ATF_TP_ADD_TC(tp
, signals
);
454 return atf_no_error();