etc/services - sync with NetBSD-8
[minix.git] / tests / fs / puffs / t_basic.c
blobce5e4ea15f8323757fbbf6fa9cd5fc9592c08007
1 /* $NetBSD: t_basic.c,v 1.12 2013/10/19 17:45:00 christos Exp $ */
3 #include <sys/types.h>
4 #include <sys/mount.h>
5 #include <sys/socket.h>
7 #include <assert.h>
8 #include <atf-c.h>
9 #include <err.h>
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <pthread.h>
13 #include <puffs.h>
14 #include <puffsdump.h>
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <stdlib.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?
33 static void
34 syncbar(const char *fs)
36 struct statvfs svb;
38 if (rump_sys_statvfs1(fs, &svb, ST_WAIT) == -1)
39 atf_tc_fail_errno("statvfs");
42 #ifdef PUFFSDUMP
43 static void __unused
44 dumpopcount(struct puffstestargs *args)
46 size_t i;
48 printf("VFS OPS:\n");
49 for (i = 0; i < MIN(puffsdump_vfsop_count, PUFFS_VFS_MAX); i++) {
50 printf("\t%s: %d\n",
51 puffsdump_vfsop_revmap[i], args->pta_vfs_toserv_ops[i]);
54 printf("VN OPS:\n");
55 for (i = 0; i < MIN(puffsdump_vnop_count, PUFFS_VN_MAX); i++) {
56 printf("\t%s: %d\n",
57 puffsdump_vnop_revmap[i], args->pta_vn_toserv_ops[i]);
60 #endif
62 ATF_TC(mount);
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)
71 void *args;
73 FSTEST_CONSTRUCTOR(tc, puffs, args);
74 FSTEST_DESTRUCTOR(tc, puffs, args);
77 ATF_TC(root_reg);
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");
89 void *args;
90 int fd, rv;
92 FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
94 fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR);
95 if (fd == -1)
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);
102 rump_sys_close(fd);
104 FSTEST_DESTRUCTOR(tc, puffs, args);
107 ATF_TC(root_lnk);
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);
118 void *args;
119 char buf[PATH_MAX];
120 ssize_t len;
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");
126 buf[len] = '\0';
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");
133 #endif
136 ATF_TC(root_fifo);
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"
144 static void *
145 dofifow(void *arg)
147 int fd = (int)(uintptr_t)arg;
148 char buf[512];
150 printf("writing\n");
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");
155 return NULL;
158 ATF_TC_BODY(root_fifo, tc)
160 MAKEOPTS("-r", "fifo");
161 void *args;
162 pthread_t pt;
163 char buf[512];
164 int fd;
166 FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
168 fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR);
169 if (fd == -1)
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);
179 rump_sys_close(fd);
181 FSTEST_DESTRUCTOR(tc, puffs, args);
184 ATF_TC(root_chrdev);
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");
194 void *args;
195 ssize_t rv;
196 char buf[512];
197 int fd;
199 FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
201 fd = rump_sys_open(FSTEST_MNTNAME, O_RDWR);
202 if (fd == -1)
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);
211 rump_sys_close(fd);
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;
230 void *args;
231 int fd;
233 FSTEST_CONSTRUCTOR(tc, puffs, args);
234 FSTEST_ENTER();
235 pargs = args;
237 fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
238 if (fd == -1)
239 atf_tc_fail_errno("create");
241 /* none yet */
242 ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 0);
244 rump_sys_close(fd);
246 /* one for file */
247 ATF_REQUIRE_EQ(pargs->pta_vn_toserv_ops[PUFFS_VN_INACTIVE], 1);
249 FSTEST_EXIT();
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;
267 void *args;
268 int fd;
270 FSTEST_CONSTRUCTOR(tc, puffs, args);
271 FSTEST_ENTER();
272 pargs = args;
274 fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
275 if (fd == -1)
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);
286 rump_sys_close(fd);
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);
292 FSTEST_EXIT();
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;
307 void *args;
308 int fd;
309 int ianow;
311 FSTEST_CONSTRUCTOR(tc, puffs, args);
312 FSTEST_ENTER();
313 pargs = args;
315 fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
316 if (fd == -1)
317 atf_tc_fail_errno("create");
319 if (rump_sys_link("file", "anotherfile") == -1)
320 atf_tc_fail_errno("create link");
321 rump_sys_close(fd);
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);
341 FSTEST_EXIT();
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;
357 void *args;
358 char buf[512];
359 int fd, ianow;
361 assert(sizeof(buf) > sizeof(MAGICSTR));
363 FSTEST_CONSTRUCTOR_FSPRIV(tc, puffs, args, theopts);
364 FSTEST_ENTER();
365 pargs = args;
367 fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777);
368 if (fd == -1)
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");
381 rump_sys_close(fd);
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);
390 FSTEST_EXIT();
391 FSTEST_DESTRUCTOR(tc, puffs, args);
394 ATF_TC(signals);
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)
407 struct stat sb;
408 void *args;
410 rump_boot_setsigmodel(RUMP_SIGMODEL_RECORD);
412 FSTEST_CONSTRUCTOR(tc, puffs, args);
413 FSTEST_ENTER();
414 RL(rump_sys_stat(".", &sb));
416 /* send SIGUSR1, should not affect puffs ops */
417 rump_schedule();
418 rumpns_psignal(rumpns_initproc, SIGUSR1);
419 rump_unschedule();
420 RL(rump_sys_stat(".", &sb));
422 /* send SIGTERM, should get EINTR */
423 rump_schedule();
424 rumpns_psignal(rumpns_initproc, SIGTERM);
425 rump_unschedule();
426 ATF_REQUIRE_ERRNO(EINTR, rump_sys_stat(".", &sb) == -1);
428 /* clear sigmask so that we can unmount */
429 rump_schedule();
430 rumpns_sigclearall(rumpns_initproc, NULL, NULL);
431 rump_unschedule();
433 FSTEST_EXIT();
434 FSTEST_DESTRUCTOR(tc, puffs, args);
437 ATF_TP_ADD_TCS(tp)
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();