h_fsmacros.h revision 1.8 1 /* $NetBSD: h_fsmacros.h,v 1.8 2010/07/13 11:12:19 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 #include "ext2fs.c"
41 #include "ffs.c"
42 #include "lfs.c"
43 #include "msdosfs.c"
44 #include "sysvbfs.c"
45 #include "tmpfs.c"
46
47 #define IMGNAME "image.fs"
48 #define IMGSIZE (10000 * 512)
49 #define MNTNAME "/mnt"
50
51 #define ATF_TC_FSADD(fs,type,func,desc) \
52 ATF_TC(fs##_##func); \
53 ATF_TC_HEAD(fs##_##func,tc) \
54 { \
55 atf_tc_set_md_var(tc, "descr", type " test for " desc); \
56 atf_tc_set_md_var(tc, "use.fs", "true"); \
57 atf_tc_set_md_var(tc, "X-fs.type", type); \
58 } \
59 ATF_TC_BODY(fs##_##func,tc) \
60 { \
61 void *tmp; \
62 atf_check_fstype(tc, type); \
63 if (fs##_fstest_newfs(&tmp, IMGNAME, IMGSIZE) != 0) \
64 atf_tc_fail("newfs failed"); \
65 if (fs##_fstest_mount(tmp, MNTNAME, 0) != 0) \
66 atf_tc_fail("mount failed"); \
67 func(tc,MNTNAME); \
68 if (fs##_fstest_unmount(MNTNAME, 0) != 0) \
69 atf_tc_fail("unmount failed"); \
70 if (fs##_fstest_delfs(tmp) != 0) \
71 atf_tc_fail("delfs failed"); \
72 }
73
74 #define ATF_TP_FSADD(fs,func) \
75 ATF_TP_ADD_TC(tp,fs##_##func)
76
77 #define ATF_TC_FSAPPLY(func,desc) \
78 ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
79 ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
80 ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
81 ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
82 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
83 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
84
85 #define ATF_TP_FSAPPLY(func) \
86 ATF_TP_FSADD(ext2fs,func); \
87 ATF_TP_FSADD(ffs,func); \
88 ATF_TP_FSADD(lfs,func); \
89 ATF_TP_FSADD(msdosfs,func); \
90 ATF_TP_FSADD(sysvbfs,func); \
91 ATF_TP_FSADD(tmpfs,func);
92
93 #define ATF_FSAPPLY(func,desc) \
94 ATF_TC_FSAPPLY(func,desc); \
95 ATF_TP_ADD_TCS(tp) \
96 { \
97 ATF_TP_FSAPPLY(func); \
98 return atf_no_error(); \
99 }
100
101 static void
102 atf_check_fstype(const atf_tc_t *tc, const char *fs)
103 {
104 const char *fstype;
105
106 if (!atf_tc_has_config_var(tc, "fstype"))
107 return;
108 fstype = atf_tc_get_config_var(tc, "fstype");
109 if (strcmp(fstype, fs) == 0)
110 return;
111 atf_tc_skip("filesystem not selected");
112 }
113
114 #define FSTYPE_EXT2FS(tc)\
115 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
116 #define FSTYPE_FFS(tc)\
117 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
118 #define FSTYPE_LFS(tc)\
119 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
120 #define FSTYPE_MSDOS(tc)\
121 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
122 #define FSTYPE_PUFFS(tc)\
123 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
124 #define FSTYPE_SYSVBFS(tc)\
125 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
126 #define FSTYPE_TMPFS(tc)\
127 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
128
129 #endif /* __H_FSMACROS_H_ */
130