h_fsmacros.h revision 1.20 1 /* $NetBSD: h_fsmacros.h,v 1.20 2010/08/26 08:19:18 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nicolas Joly.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef __H_FSMACROS_H_
33 #define __H_FSMACROS_H_
34
35 #include <sys/mount.h>
36
37 #include <atf-c.h>
38 #include <puffsdump.h>
39 #include <string.h>
40
41 #include <rump/rump.h>
42
43 #include "../../h_macros.h"
44
45 #define FSPROTOS(_fs_) \
46 int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, \
47 off_t, void *); \
48 int _fs_##_fstest_delfs(const atf_tc_t *, void *); \
49 int _fs_##_fstest_mount(const atf_tc_t *, void *, const char *, int); \
50 int _fs_##_fstest_unmount(const atf_tc_t *, const char *, int);
51
52 FSPROTOS(ext2fs);
53 FSPROTOS(ffs);
54 FSPROTOS(lfs);
55 FSPROTOS(msdosfs);
56 FSPROTOS(nfs);
57 FSPROTOS(puffs);
58 FSPROTOS(sysvbfs);
59 FSPROTOS(tmpfs);
60
61 #ifndef FSTEST_IMGNAME
62 #define FSTEST_IMGNAME "image.fs"
63 #endif
64 #ifndef FSTEST_IMGSIZE
65 #define FSTEST_IMGSIZE (10000 * 512)
66 #endif
67 #ifndef FSTEST_MNTNAME
68 #define FSTEST_MNTNAME "/mnt"
69 #endif
70
71 #define FSTEST_CONSTRUCTOR(_tc_, _fs_, _args_) \
72 do { \
73 if (_fs_##_fstest_newfs(_tc_, &_args_, \
74 FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0) \
75 atf_tc_fail_errno("newfs failed"); \
76 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \
77 atf_tc_fail_errno("mount failed"); \
78 } while (/*CONSTCOND*/0);
79
80 #define FSTEST_CONSTRUCTOR_FSPRIV(_tc_, _fs_, _args_, _privargs_) \
81 do { \
82 if (_fs_##_fstest_newfs(_tc_, &_args_, \
83 FSTEST_IMGNAME, FSTEST_IMGSIZE, _privargs_) != 0) \
84 atf_tc_fail_errno("newfs failed"); \
85 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \
86 atf_tc_fail_errno("mount failed"); \
87 } while (/*CONSTCOND*/0);
88
89 #define FSTEST_DESTRUCTOR(_tc_, _fs_, _args_) \
90 do { \
91 if (_fs_##_fstest_unmount(_tc_, FSTEST_MNTNAME, 0) != 0) { \
92 rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \
93 atf_tc_fail_errno("unmount failed"); \
94 } \
95 if (_fs_##_fstest_delfs(_tc_, _args_) != 0) \
96 atf_tc_fail_errno("delfs failed"); \
97 } while (/*CONSTCOND*/0);
98
99 #define ATF_TC_FSADD(fs,type,func,desc) \
100 ATF_TC_WITH_CLEANUP(fs##_##func); \
101 ATF_TC_HEAD(fs##_##func,tc) \
102 { \
103 atf_tc_set_md_var(tc, "descr", type " test for " desc); \
104 atf_tc_set_md_var(tc, "use.fs", "true"); \
105 atf_tc_set_md_var(tc, "X-fs.type", type); \
106 } \
107 void *fs##func##tmp; \
108 ATF_TC_BODY(fs##_##func,tc) \
109 { \
110 if (!atf_check_fstype(tc, type)) \
111 atf_tc_skip("filesystem not selected"); \
112 FSTEST_CONSTRUCTOR(tc,fs,fs##func##tmp); \
113 func(tc,FSTEST_MNTNAME); \
114 if (fs##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) { \
115 rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \
116 atf_tc_fail_errno("unmount failed"); \
117 } \
118 } \
119 ATF_TC_CLEANUP(fs##_##func,tc) \
120 { \
121 if (!atf_check_fstype(tc, type)) \
122 return; \
123 if (fs##_fstest_delfs(tc, fs##func##tmp) != 0) \
124 atf_tc_fail_errno("delfs failed"); \
125 }
126
127 #define ATF_TP_FSADD(fs,func) \
128 ATF_TP_ADD_TC(tp,fs##_##func)
129
130 #define ATF_TC_FSAPPLY(func,desc) \
131 ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
132 ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
133 ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
134 ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
135 ATF_TC_FSADD(nfs,MOUNT_NFS,func,desc) \
136 ATF_TC_FSADD(puffs,MOUNT_PUFFS,func,desc) \
137 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
138 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
139
140 #define ATF_TP_FSAPPLY(func) \
141 ATF_TP_FSADD(ext2fs,func); \
142 ATF_TP_FSADD(ffs,func); \
143 ATF_TP_FSADD(lfs,func); \
144 ATF_TP_FSADD(msdosfs,func); \
145 ATF_TP_FSADD(nfs,func); \
146 ATF_TP_FSADD(puffs,func); \
147 ATF_TP_FSADD(sysvbfs,func); \
148 ATF_TP_FSADD(tmpfs,func);
149
150 #define ATF_FSAPPLY(func,desc) \
151 ATF_TC_FSAPPLY(func,desc); \
152 ATF_TP_ADD_TCS(tp) \
153 { \
154 ATF_TP_FSAPPLY(func); \
155 return atf_no_error(); \
156 }
157
158 static __inline bool
159 atf_check_fstype(const atf_tc_t *tc, const char *fs)
160 {
161 const char *fstype;
162
163 if (!atf_tc_has_config_var(tc, "fstype"))
164 return true;
165 fstype = atf_tc_get_config_var(tc, "fstype");
166 if (strcmp(fstype, fs) == 0)
167 return true;
168 return false;
169 }
170
171 #define FSTYPE_EXT2FS(tc)\
172 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
173 #define FSTYPE_FFS(tc)\
174 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
175 #define FSTYPE_LFS(tc)\
176 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
177 #define FSTYPE_MSDOS(tc)\
178 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
179 #define FSTYPE_NFS(tc)\
180 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_NFS) == 0)
181 #define FSTYPE_PUFFS(tc)\
182 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
183 #define FSTYPE_SYSVBFS(tc)\
184 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
185 #define FSTYPE_TMPFS(tc)\
186 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
187
188 #define FSTEST_ENTER() \
189 if (rump_sys_chdir(FSTEST_MNTNAME) == -1) \
190 atf_tc_fail_errno("failed to cd into test mount")
191 #define FSTEST_EXIT() \
192 if (rump_sys_chdir("/") == -1) \
193 atf_tc_fail_errno("failed to cd out of test mount")
194
195 /*
196 * file system args structures
197 */
198
199 struct nfstestargs {
200 pid_t ta_childpid;
201 char ta_ethername[MAXPATHLEN];
202 };
203
204 struct puffstestargs {
205 uint8_t *pta_pargs;
206 size_t pta_pargslen;
207
208 int pta_pflags;
209 pid_t pta_childpid;
210
211 int pta_rumpfd;
212 int pta_servfd;
213
214 char pta_dev[MAXPATHLEN];
215 char pta_dir[MAXPATHLEN];
216
217 int pta_mntflags;
218
219 int pta_vfs_toserv_ops[PUFFS_VFS_MAX];
220 int pta_vn_toserv_ops[PUFFS_VN_MAX];
221 };
222
223 #endif /* __H_FSMACROS_H_ */
224