1 /* $NetBSD: t_fifos.c,v 1.5 2010/11/07 17:51:17 jmmv Exp $ */
15 #include <rump/rump.h>
16 #include <rump/rump_syscalls.h>
18 #include <ufs/ufs/ufsmount.h>
20 #include "../../h_macros.h"
22 ATF_TC_WITH_CLEANUP(fifos
);
23 ATF_TC_HEAD(fifos
, tc
)
25 atf_tc_set_md_var(tc
, "descr", "test fifo support in ffs");
26 atf_tc_set_md_var(tc
, "timeout", "5");
29 #define teststr1 "raving & drooling"
30 #define teststr2 "haha, charade"
37 fd
= rump_sys_open("sheep", O_WRONLY
);
39 atf_tc_fail_errno("w1 open");
40 if (rump_sys_write(fd
, teststr1
, sizeof(teststr1
)) != sizeof(teststr1
))
41 atf_tc_fail_errno("w1 write");
52 fd
= rump_sys_open("pigs", O_WRONLY
);
54 atf_tc_fail_errno("w2 open");
55 if (rump_sys_write(fd
, teststr2
, sizeof(teststr2
)) != sizeof(teststr2
))
56 atf_tc_fail_errno("w2 write");
68 fd
= rump_sys_open("sheep", O_RDONLY
);
70 atf_tc_fail_errno("r1 open");
71 if (rump_sys_read(fd
, buf
, sizeof(buf
)) != sizeof(teststr1
))
72 atf_tc_fail_errno("r1 read");
75 if (strcmp(teststr1
, buf
) != 0)
76 atf_tc_fail("got invalid str, %s vs. %s", buf
, teststr1
);
87 fd
= rump_sys_open("pigs", O_RDONLY
);
89 atf_tc_fail_errno("r2 open");
90 if (rump_sys_read(fd
, buf
, sizeof(buf
)) != sizeof(teststr2
))
91 atf_tc_fail_errno("r2 read");
94 if (strcmp(teststr2
, buf
) != 0)
95 atf_tc_fail("got invalid str, %s vs. %s", buf
, teststr2
);
100 #define IMGNAME "atf.img"
102 const char *newfs
= "newfs -F -s 10000 " IMGNAME
;
103 #define FAKEBLK "/dev/sp00ka"
105 ATF_TC_BODY(fifos
, tc
)
107 struct ufs_args args
;
108 pthread_t ptw1
, ptw2
, ptr1
, ptr2
;
110 if (system(newfs
) == -1)
111 atf_tc_fail_errno("newfs failed");
113 memset(&args
, 0, sizeof(args
));
114 args
.fspec
= __UNCONST(FAKEBLK
);
117 if (rump_sys_mkdir("/animals", 0777) == -1)
118 atf_tc_fail_errno("cannot create mountpoint");
119 rump_pub_etfs_register(FAKEBLK
, IMGNAME
, RUMP_ETFS_BLK
);
120 if (rump_sys_mount(MOUNT_FFS
, "/animals", 0, &args
, sizeof(args
))==-1)
121 atf_tc_fail_errno("rump_sys_mount failed");
124 if (rump_sys_chdir("/animals") == 1)
125 atf_tc_fail_errno("chdir");
126 if (rump_sys_mkfifo("pigs", S_IFIFO
| 0777) == -1)
127 atf_tc_fail_errno("mknod1");
128 if (rump_sys_mkfifo("sheep", S_IFIFO
| 0777) == -1)
129 atf_tc_fail_errno("mknod2");
131 pthread_create(&ptw1
, NULL
, w1
, NULL
);
132 pthread_create(&ptw2
, NULL
, w2
, NULL
);
133 pthread_create(&ptr1
, NULL
, r1
, NULL
);
134 pthread_create(&ptr2
, NULL
, r2
, NULL
);
136 pthread_join(ptw1
, NULL
);
137 pthread_join(ptw2
, NULL
);
138 pthread_join(ptr1
, NULL
);
139 pthread_join(ptr2
, NULL
);
141 if (rump_sys_chdir("/") == 1)
142 atf_tc_fail_errno("chdir");
144 if (rump_sys_unmount("/animals", 0) == -1)
145 atf_tc_fail_errno("unmount failed");
148 ATF_TC_CLEANUP(fifos
, tc
)
156 ATF_TP_ADD_TC(tp
, fifos
);