h_fsmacros.h revision 1.16 1 /* $NetBSD: h_fsmacros.h,v 1.16 2010/07/28 15:16:50 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 <string.h>
39
40 #define FSPROTOS(_fs_) \
41 int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, off_t);\
42 int _fs_##_fstest_delfs(const atf_tc_t *, void *); \
43 int _fs_##_fstest_mount(const atf_tc_t *, void *, const char *, int); \
44 int _fs_##_fstest_unmount(const atf_tc_t *, const char *, int);
45
46 FSPROTOS(ext2fs);
47 FSPROTOS(ffs);
48 FSPROTOS(lfs);
49 FSPROTOS(msdosfs);
50 FSPROTOS(nfs);
51 FSPROTOS(puffs);
52 FSPROTOS(sysvbfs);
53 FSPROTOS(tmpfs);
54
55 #define FSTEST_IMGNAME "image.fs"
56 #define FSTEST_IMGSIZE (10000 * 512)
57 #define FSTEST_MNTNAME "/mnt"
58
59 #define FSTEST_CONSTRUCTOR(_tc_, _fs_, _args_) \
60 do { \
61 if (_fs_##_fstest_newfs(_tc_, &_args_, \
62 FSTEST_IMGNAME, FSTEST_IMGSIZE) != 0) \
63 atf_tc_fail("newfs failed"); \
64 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \
65 atf_tc_fail("mount failed"); \
66 } while (/*CONSTCOND*/0);
67
68 #define FSTEST_DESTRUCTOR(_tc_, _fs_, _args_) \
69 do { \
70 if (_fs_##_fstest_unmount(_tc_, FSTEST_MNTNAME, 0) != 0) \
71 atf_tc_fail("unmount failed"); \
72 if (_fs_##_fstest_delfs(_tc_, _args_) != 0) \
73 atf_tc_fail("delfs failed"); \
74 } while (/*CONSTCOND*/0);
75
76 #define ATF_TC_FSADD(fs,type,func,desc) \
77 ATF_TC_WITH_CLEANUP(fs##_##func); \
78 ATF_TC_HEAD(fs##_##func,tc) \
79 { \
80 atf_tc_set_md_var(tc, "descr", type " test for " desc); \
81 atf_tc_set_md_var(tc, "use.fs", "true"); \
82 atf_tc_set_md_var(tc, "X-fs.type", type); \
83 } \
84 void *fs##func##tmp; \
85 ATF_TC_BODY(fs##_##func,tc) \
86 { \
87 if (!atf_check_fstype(tc, type)) \
88 atf_tc_skip("filesystem not selected"); \
89 FSTEST_CONSTRUCTOR(tc,fs,fs##func##tmp); \
90 func(tc,FSTEST_MNTNAME); \
91 if (fs##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) \
92 atf_tc_fail("unmount failed"); \
93 } \
94 ATF_TC_CLEANUP(fs##_##func,tc) \
95 { \
96 if (!atf_check_fstype(tc, type)) \
97 return; \
98 if (fs##_fstest_delfs(tc, fs##func##tmp) != 0) \
99 atf_tc_fail("delfs failed"); \
100 }
101
102 #define ATF_TP_FSADD(fs,func) \
103 ATF_TP_ADD_TC(tp,fs##_##func)
104
105 #define ATF_TC_FSAPPLY(func,desc) \
106 ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
107 ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
108 ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
109 ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
110 ATF_TC_FSADD(nfs,MOUNT_NFS,func,desc) \
111 ATF_TC_FSADD(puffs,MOUNT_PUFFS,func,desc) \
112 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
113 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
114
115 #define ATF_TP_FSAPPLY(func) \
116 ATF_TP_FSADD(ext2fs,func); \
117 ATF_TP_FSADD(ffs,func); \
118 ATF_TP_FSADD(lfs,func); \
119 ATF_TP_FSADD(msdosfs,func); \
120 ATF_TP_FSADD(nfs,func); \
121 ATF_TP_FSADD(puffs,func); \
122 ATF_TP_FSADD(sysvbfs,func); \
123 ATF_TP_FSADD(tmpfs,func);
124
125 #define ATF_FSAPPLY(func,desc) \
126 ATF_TC_FSAPPLY(func,desc); \
127 ATF_TP_ADD_TCS(tp) \
128 { \
129 ATF_TP_FSAPPLY(func); \
130 return atf_no_error(); \
131 }
132
133 static __inline bool
134 atf_check_fstype(const atf_tc_t *tc, const char *fs)
135 {
136 const char *fstype;
137
138 if (!atf_tc_has_config_var(tc, "fstype"))
139 return true;
140 fstype = atf_tc_get_config_var(tc, "fstype");
141 if (strcmp(fstype, fs) == 0)
142 return true;
143 return false;
144 }
145
146 #define FSTYPE_EXT2FS(tc)\
147 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
148 #define FSTYPE_FFS(tc)\
149 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
150 #define FSTYPE_LFS(tc)\
151 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
152 #define FSTYPE_MSDOS(tc)\
153 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
154 #define FSTYPE_NFS(tc)\
155 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_NFS) == 0)
156 #define FSTYPE_PUFFS(tc)\
157 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
158 #define FSTYPE_SYSVBFS(tc)\
159 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
160 #define FSTYPE_TMPFS(tc)\
161 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
162
163
164 /* file system args structures */
165 struct nfstestargs {
166 pid_t ta_childpid;
167 char ta_ethername[MAXPATHLEN];
168 };
169
170 #endif /* __H_FSMACROS_H_ */
171