h_fsmacros.h revision 1.9 1 1.9 njoly /* $NetBSD: h_fsmacros.h,v 1.9 2010/07/13 15:50:31 njoly Exp $ */
2 1.1 njoly
3 1.1 njoly /*-
4 1.1 njoly * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 1.1 njoly * All rights reserved.
6 1.1 njoly *
7 1.1 njoly * This code is derived from software contributed to The NetBSD Foundation
8 1.2 njoly * by Nicolas Joly.
9 1.1 njoly *
10 1.1 njoly * Redistribution and use in source and binary forms, with or without
11 1.1 njoly * modification, are permitted provided that the following conditions
12 1.1 njoly * are met:
13 1.1 njoly * 1. Redistributions of source code must retain the above copyright
14 1.1 njoly * notice, this list of conditions and the following disclaimer.
15 1.1 njoly * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 njoly * notice, this list of conditions and the following disclaimer in the
17 1.1 njoly * documentation and/or other materials provided with the distribution.
18 1.1 njoly *
19 1.1 njoly * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 njoly * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 njoly * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 njoly * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 njoly * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 njoly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 njoly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 njoly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 njoly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 njoly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 njoly * POSSIBILITY OF SUCH DAMAGE.
30 1.1 njoly */
31 1.1 njoly
32 1.1 njoly #ifndef __H_FSMACROS_H_
33 1.1 njoly #define __H_FSMACROS_H_
34 1.1 njoly
35 1.5 njoly #include <sys/mount.h>
36 1.5 njoly
37 1.1 njoly #include <atf-c.h>
38 1.1 njoly #include <string.h>
39 1.1 njoly
40 1.1 njoly #include "ext2fs.c"
41 1.1 njoly #include "ffs.c"
42 1.3 pooka #include "lfs.c"
43 1.1 njoly #include "msdosfs.c"
44 1.1 njoly #include "sysvbfs.c"
45 1.1 njoly #include "tmpfs.c"
46 1.1 njoly
47 1.1 njoly #define IMGNAME "image.fs"
48 1.1 njoly #define IMGSIZE (10000 * 512)
49 1.1 njoly #define MNTNAME "/mnt"
50 1.1 njoly
51 1.1 njoly #define ATF_TC_FSADD(fs,type,func,desc) \
52 1.1 njoly ATF_TC(fs##_##func); \
53 1.1 njoly ATF_TC_HEAD(fs##_##func,tc) \
54 1.1 njoly { \
55 1.1 njoly atf_tc_set_md_var(tc, "descr", type " test for " desc); \
56 1.1 njoly atf_tc_set_md_var(tc, "use.fs", "true"); \
57 1.6 njoly atf_tc_set_md_var(tc, "X-fs.type", type); \
58 1.1 njoly } \
59 1.1 njoly ATF_TC_BODY(fs##_##func,tc) \
60 1.1 njoly { \
61 1.1 njoly void *tmp; \
62 1.1 njoly atf_check_fstype(tc, type); \
63 1.9 njoly if (fs##_fstest_newfs(tc, &tmp, IMGNAME, IMGSIZE) != 0) \
64 1.1 njoly atf_tc_fail("newfs failed"); \
65 1.9 njoly if (fs##_fstest_mount(tc, tmp, MNTNAME, 0) != 0) \
66 1.1 njoly atf_tc_fail("mount failed"); \
67 1.6 njoly func(tc,MNTNAME); \
68 1.9 njoly if (fs##_fstest_unmount(tc, MNTNAME, 0) != 0) \
69 1.1 njoly atf_tc_fail("unmount failed"); \
70 1.9 njoly if (fs##_fstest_delfs(tc, tmp) != 0) \
71 1.1 njoly atf_tc_fail("delfs failed"); \
72 1.1 njoly }
73 1.1 njoly
74 1.1 njoly #define ATF_TP_FSADD(fs,func) \
75 1.1 njoly ATF_TP_ADD_TC(tp,fs##_##func)
76 1.1 njoly
77 1.1 njoly #define ATF_TC_FSAPPLY(func,desc) \
78 1.5 njoly ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
79 1.5 njoly ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
80 1.5 njoly ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
81 1.5 njoly ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
82 1.5 njoly ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
83 1.5 njoly ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
84 1.1 njoly
85 1.1 njoly #define ATF_TP_FSAPPLY(func) \
86 1.1 njoly ATF_TP_FSADD(ext2fs,func); \
87 1.1 njoly ATF_TP_FSADD(ffs,func); \
88 1.3 pooka ATF_TP_FSADD(lfs,func); \
89 1.1 njoly ATF_TP_FSADD(msdosfs,func); \
90 1.1 njoly ATF_TP_FSADD(sysvbfs,func); \
91 1.1 njoly ATF_TP_FSADD(tmpfs,func);
92 1.1 njoly
93 1.1 njoly #define ATF_FSAPPLY(func,desc) \
94 1.1 njoly ATF_TC_FSAPPLY(func,desc); \
95 1.1 njoly ATF_TP_ADD_TCS(tp) \
96 1.1 njoly { \
97 1.1 njoly ATF_TP_FSAPPLY(func); \
98 1.1 njoly return atf_no_error(); \
99 1.1 njoly }
100 1.1 njoly
101 1.1 njoly static void
102 1.1 njoly atf_check_fstype(const atf_tc_t *tc, const char *fs)
103 1.1 njoly {
104 1.1 njoly const char *fstype;
105 1.1 njoly
106 1.1 njoly if (!atf_tc_has_config_var(tc, "fstype"))
107 1.1 njoly return;
108 1.1 njoly fstype = atf_tc_get_config_var(tc, "fstype");
109 1.1 njoly if (strcmp(fstype, fs) == 0)
110 1.1 njoly return;
111 1.1 njoly atf_tc_skip("filesystem not selected");
112 1.1 njoly }
113 1.1 njoly
114 1.8 pooka #define FSTYPE_EXT2FS(tc)\
115 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
116 1.8 pooka #define FSTYPE_FFS(tc)\
117 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
118 1.8 pooka #define FSTYPE_LFS(tc)\
119 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
120 1.8 pooka #define FSTYPE_MSDOS(tc)\
121 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
122 1.8 pooka #define FSTYPE_PUFFS(tc)\
123 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
124 1.8 pooka #define FSTYPE_SYSVBFS(tc)\
125 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
126 1.8 pooka #define FSTYPE_TMPFS(tc)\
127 1.8 pooka (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
128 1.5 njoly
129 1.1 njoly #endif /* __H_FSMACROS_H_ */
130