1 /* $NetBSD: t_vfsops.c,v 1.11 2011/04/04 19:16:58 hannken Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/statvfs.h>
38 #include <rump/rump_syscalls.h>
39 #include <rump/rump.h>
41 #include "../common/h_fsmacros.h"
42 #include "../../h_macros.h"
45 tmount(const atf_tc_t
*tc
, const char *path
)
52 tstatvfs(const atf_tc_t
*tc
, const char *path
)
54 const char *fstype
= atf_tc_get_md_var(tc
, "X-fs.mntname");
57 if (rump_sys_statvfs1(path
, &svb
, ST_WAIT
) == -1)
58 atf_tc_fail_errno("statvfs");
60 ATF_REQUIRE(svb
.f_namemax
> 0 && svb
.f_namemax
<= MAXNAMLEN
);
61 if (!(FSTYPE_PUFFS(tc
) || FSTYPE_P2K_FFS(tc
)))
62 ATF_REQUIRE_STREQ(svb
.f_fstypename
, fstype
);
63 ATF_REQUIRE_STREQ(svb
.f_mntonname
, path
);
67 tsync(const atf_tc_t
*tc
, const char *path
)
73 #define MAGICSTR "just a string, I like A"
75 tfilehandle(const atf_tc_t
*tc
, const char *path
)
77 char fpath
[MAXPATHLEN
];
78 char buf
[sizeof(MAGICSTR
)];
83 sprintf(fpath
, "%s/file", path
);
84 fd
= rump_sys_open(fpath
, O_RDWR
| O_CREAT
, 0777);
86 atf_tc_fail_errno("open");
88 if (rump_sys_write(fd
, MAGICSTR
, sizeof(MAGICSTR
)) != sizeof(MAGICSTR
))
89 atf_tc_fail("write to file");
93 * Get file handle size.
94 * This also weeds out unsupported file systems.
97 if (rump_sys_getfh(fpath
, NULL
, &fhsize
) == -1) {
98 if (errno
== EOPNOTSUPP
) {
99 atf_tc_skip("file handles not supported");
100 } else if (errno
!= E2BIG
) {
101 atf_tc_fail_errno("getfh size");
105 fhp
= malloc(fhsize
);
106 if (rump_sys_getfh(fpath
, fhp
, &fhsize
) == -1)
107 atf_tc_fail_errno("getfh");
109 /* open file based on file handle */
110 fd
= rump_sys_fhopen(fhp
, fhsize
, O_RDONLY
);
112 atf_tc_fail_errno("fhopen");
115 /* check that we got the same file */
116 if (rump_sys_read(fd
, buf
, sizeof(buf
)) != sizeof(MAGICSTR
))
117 atf_tc_fail("read fhopened file");
119 ATF_REQUIRE_STREQ(buf
, MAGICSTR
);
124 #define FNAME "a_file"
126 tfhremove(const atf_tc_t
*tc
, const char *path
)
132 RL(rump_sys_chdir(path
));
133 RL(fd
= rump_sys_open(FNAME
, O_RDWR
| O_CREAT
, 0777));
134 RL(rump_sys_close(fd
));
137 if (rump_sys_getfh(FNAME
, NULL
, &fhsize
) == -1) {
138 if (errno
== EOPNOTSUPP
) {
139 atf_tc_skip("file handles not supported");
140 } else if (errno
!= E2BIG
) {
141 atf_tc_fail_errno("getfh size");
145 fhp
= malloc(fhsize
);
146 RL(rump_sys_getfh(FNAME
, fhp
, &fhsize
));
147 RL(rump_sys_unlink(FNAME
));
150 atf_tc_expect_fail("fhopen() for removed file succeeds "
152 ATF_REQUIRE_ERRNO(ESTALE
, rump_sys_fhopen(fhp
, fhsize
, O_RDONLY
) == -1);
153 atf_tc_expect_pass();
155 RL(rump_sys_chdir("/"));
160 * This test only checks the file system doesn't crash. We *might*
161 * try a valid file handle.
164 tfhinval(const atf_tc_t
*tc
, const char *path
)
171 srandom(seed
= time(NULL
));
172 printf("RNG seed %lu\n", seed
);
174 RL(rump_sys_chdir(path
));
176 if (rump_sys_getfh(".", NULL
, &fhsize
) == -1) {
177 if (errno
== EOPNOTSUPP
) {
178 atf_tc_skip("file handles not supported");
179 } else if (errno
!= E2BIG
) {
180 atf_tc_fail_errno("getfh size");
184 fhp
= malloc(fhsize
);
185 tests_makegarbage(fhp
, fhsize
);
186 fd
= rump_sys_fhopen(fhp
, fhsize
, O_RDWR
);
190 RL(rump_sys_chdir("/"));
193 ATF_TC_FSAPPLY(tmount
, "mount/unmount");
194 ATF_TC_FSAPPLY(tstatvfs
, "statvfs");
195 ATF_TC_FSAPPLY(tsync
, "sync");
196 ATF_TC_FSAPPLY(tfilehandle
, "file handles");
197 ATF_TC_FSAPPLY(tfhremove
, "fhtovp for removed file");
198 ATF_TC_FSAPPLY(tfhinval
, "fhopen invalid filehandle");
203 ATF_TP_FSAPPLY(tmount
);
204 ATF_TP_FSAPPLY(tstatvfs
);
205 ATF_TP_FSAPPLY(tsync
);
206 ATF_TP_FSAPPLY(tfilehandle
);
207 ATF_TP_FSAPPLY(tfhremove
);
208 ATF_TP_FSAPPLY(tfhinval
);
210 return atf_no_error();