h_fsmacros.h revision 1.14 1 /* $NetBSD: h_fsmacros.h,v 1.14 2010/07/26 16:15:49 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 ATF_TC_FSADD(fs,type,func,desc) \
60 ATF_TC_WITH_CLEANUP(fs##_##func); \
61 ATF_TC_HEAD(fs##_##func,tc) \
62 { \
63 atf_tc_set_md_var(tc, "descr", type " test for " desc); \
64 atf_tc_set_md_var(tc, "use.fs", "true"); \
65 atf_tc_set_md_var(tc, "X-fs.type", type); \
66 } \
67 void *fs##func##tmp; \
68 ATF_TC_BODY(fs##_##func,tc) \
69 { \
70 if (!atf_check_fstype(tc, type)) \
71 atf_tc_skip("filesystem not selected"); \
72 if (fs##_fstest_newfs(tc, &fs##func##tmp, FSTEST_IMGNAME, FSTEST_IMGSIZE) != 0) \
73 atf_tc_fail("newfs failed"); \
74 if (fs##_fstest_mount(tc, fs##func##tmp, FSTEST_MNTNAME, 0) != 0) \
75 atf_tc_fail("mount failed"); \
76 func(tc,FSTEST_MNTNAME); \
77 if (fs##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) \
78 atf_tc_fail("unmount failed"); \
79 } \
80 ATF_TC_CLEANUP(fs##_##func,tc) \
81 { \
82 if (!atf_check_fstype(tc, type)) \
83 return; \
84 if (fs##_fstest_delfs(tc, fs##func##tmp) != 0) \
85 atf_tc_fail("delfs failed"); \
86 }
87
88 #define ATF_TP_FSADD(fs,func) \
89 ATF_TP_ADD_TC(tp,fs##_##func)
90
91 #define ATF_TC_FSAPPLY(func,desc) \
92 ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
93 ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
94 ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
95 ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
96 ATF_TC_FSADD(nfs,MOUNT_NFS,func,desc) \
97 ATF_TC_FSADD(puffs,MOUNT_PUFFS,func,desc) \
98 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
99 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
100
101 #define ATF_TP_FSAPPLY(func) \
102 ATF_TP_FSADD(ext2fs,func); \
103 ATF_TP_FSADD(ffs,func); \
104 ATF_TP_FSADD(lfs,func); \
105 ATF_TP_FSADD(msdosfs,func); \
106 ATF_TP_FSADD(nfs,func); \
107 ATF_TP_FSADD(puffs,func); \
108 ATF_TP_FSADD(sysvbfs,func); \
109 ATF_TP_FSADD(tmpfs,func);
110
111 #define ATF_FSAPPLY(func,desc) \
112 ATF_TC_FSAPPLY(func,desc); \
113 ATF_TP_ADD_TCS(tp) \
114 { \
115 ATF_TP_FSAPPLY(func); \
116 return atf_no_error(); \
117 }
118
119 static __inline bool
120 atf_check_fstype(const atf_tc_t *tc, const char *fs)
121 {
122 const char *fstype;
123
124 if (!atf_tc_has_config_var(tc, "fstype"))
125 return true;
126 fstype = atf_tc_get_config_var(tc, "fstype");
127 if (strcmp(fstype, fs) == 0)
128 return true;
129 return false;
130 }
131
132 #define FSTYPE_EXT2FS(tc)\
133 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
134 #define FSTYPE_FFS(tc)\
135 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
136 #define FSTYPE_LFS(tc)\
137 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
138 #define FSTYPE_MSDOS(tc)\
139 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
140 #define FSTYPE_NFS(tc)\
141 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_NFS) == 0)
142 #define FSTYPE_PUFFS(tc)\
143 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
144 #define FSTYPE_SYSVBFS(tc)\
145 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
146 #define FSTYPE_TMPFS(tc)\
147 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
148
149 #endif /* __H_FSMACROS_H_ */
150