h_fsmacros.h revision 1.22 1 /* $NetBSD: h_fsmacros.h,v 1.22 2010/11/11 17:39:29 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(rumpfs);
59 FSPROTOS(sysvbfs);
60 FSPROTOS(tmpfs);
61
62 #ifndef FSTEST_IMGNAME
63 #define FSTEST_IMGNAME "image.fs"
64 #endif
65 #ifndef FSTEST_IMGSIZE
66 #define FSTEST_IMGSIZE (10000 * 512)
67 #endif
68 #ifndef FSTEST_MNTNAME
69 #define FSTEST_MNTNAME "/mnt"
70 #endif
71
72 #define FSTEST_CONSTRUCTOR(_tc_, _fs_, _args_) \
73 do { \
74 if (_fs_##_fstest_newfs(_tc_, &_args_, \
75 FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0) \
76 atf_tc_fail_errno("newfs failed"); \
77 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \
78 atf_tc_fail_errno("mount failed"); \
79 } while (/*CONSTCOND*/0);
80
81 #define FSTEST_CONSTRUCTOR_FSPRIV(_tc_, _fs_, _args_, _privargs_) \
82 do { \
83 if (_fs_##_fstest_newfs(_tc_, &_args_, \
84 FSTEST_IMGNAME, FSTEST_IMGSIZE, _privargs_) != 0) \
85 atf_tc_fail_errno("newfs failed"); \
86 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \
87 atf_tc_fail_errno("mount failed"); \
88 } while (/*CONSTCOND*/0);
89
90 #define FSTEST_DESTRUCTOR(_tc_, _fs_, _args_) \
91 do { \
92 if (_fs_##_fstest_unmount(_tc_, FSTEST_MNTNAME, 0) != 0) { \
93 rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \
94 atf_tc_fail_errno("unmount failed"); \
95 } \
96 if (_fs_##_fstest_delfs(_tc_, _args_) != 0) \
97 atf_tc_fail_errno("delfs failed"); \
98 } while (/*CONSTCOND*/0);
99
100 #define ATF_TC_FSADD(fs,type,func,desc) \
101 ATF_TC_WITH_CLEANUP(fs##_##func); \
102 ATF_TC_HEAD(fs##_##func,tc) \
103 { \
104 atf_tc_set_md_var(tc, "descr", type " test for " desc); \
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(rumpfs,MOUNT_RUMPFS,func,desc) \
138 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
139 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
140
141 #define ATF_TP_FSAPPLY(func) \
142 ATF_TP_FSADD(ext2fs,func); \
143 ATF_TP_FSADD(ffs,func); \
144 ATF_TP_FSADD(lfs,func); \
145 ATF_TP_FSADD(msdosfs,func); \
146 ATF_TP_FSADD(nfs,func); \
147 ATF_TP_FSADD(puffs,func); \
148 ATF_TP_FSADD(rumpfs,func); \
149 ATF_TP_FSADD(sysvbfs,func); \
150 ATF_TP_FSADD(tmpfs,func);
151
152 #define ATF_FSAPPLY(func,desc) \
153 ATF_TC_FSAPPLY(func,desc); \
154 ATF_TP_ADD_TCS(tp) \
155 { \
156 ATF_TP_FSAPPLY(func); \
157 return atf_no_error(); \
158 }
159
160 static __inline bool
161 atf_check_fstype(const atf_tc_t *tc, const char *fs)
162 {
163 const char *fstype;
164
165 if (!atf_tc_has_config_var(tc, "fstype"))
166 return true;
167 fstype = atf_tc_get_config_var(tc, "fstype");
168 if (strcmp(fstype, fs) == 0)
169 return true;
170 return false;
171 }
172
173 #define FSTYPE_EXT2FS(tc)\
174 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
175 #define FSTYPE_FFS(tc)\
176 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
177 #define FSTYPE_LFS(tc)\
178 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
179 #define FSTYPE_MSDOS(tc)\
180 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
181 #define FSTYPE_NFS(tc)\
182 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_NFS) == 0)
183 #define FSTYPE_PUFFS(tc)\
184 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
185 #define FSTYPE_RUMPFS(tc)\
186 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_RUMPFS) == 0)
187 #define FSTYPE_SYSVBFS(tc)\
188 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
189 #define FSTYPE_TMPFS(tc)\
190 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
191
192 #define FSTEST_ENTER() \
193 if (rump_sys_chdir(FSTEST_MNTNAME) == -1) \
194 atf_tc_fail_errno("failed to cd into test mount")
195 #define FSTEST_EXIT() \
196 if (rump_sys_chdir("/") == -1) \
197 atf_tc_fail_errno("failed to cd out of test mount")
198
199 /*
200 * file system args structures
201 */
202
203 struct nfstestargs {
204 pid_t ta_childpid;
205 char ta_ethername[MAXPATHLEN];
206 };
207
208 struct puffstestargs {
209 uint8_t *pta_pargs;
210 size_t pta_pargslen;
211
212 int pta_pflags;
213 pid_t pta_childpid;
214
215 int pta_rumpfd;
216 int pta_servfd;
217
218 char pta_dev[MAXPATHLEN];
219 char pta_dir[MAXPATHLEN];
220
221 int pta_mntflags;
222
223 int pta_vfs_toserv_ops[PUFFS_VFS_MAX];
224 int pta_vn_toserv_ops[PUFFS_VN_MAX];
225 };
226
227 #endif /* __H_FSMACROS_H_ */
228