1 /* $NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * Copyright (c)2005 YAMAMOTO Takashi,
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 #include <sys/cdefs.h>
59 __COPYRIGHT("@(#) Copyright (c) 2008\
60 The NetBSD Foundation, inc. All rights reserved.");
61 __RCSID("$NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $");
63 #include <sys/fcntl.h>
71 #include "../../../h_macros.h"
73 #include <rump/rump.h>
74 #include <rump/rump_syscalls.h>
76 ATF_TC(posix_fadvise
);
77 ATF_TC_HEAD(posix_fadvise
, tc
)
79 atf_tc_set_md_var(tc
, "descr", "Checks posix_fadvise(2)");
82 ATF_TC(posix_fadvise_reg
);
83 ATF_TC_HEAD(posix_fadvise_reg
, tc
)
85 atf_tc_set_md_var(tc
, "descr", "Checks posix_fadvise(2) "
89 ATF_TC_BODY(posix_fadvise
, tc
)
96 RL(fd
= open("/dev/null", O_RDWR
));
102 * it's hard to check if posix_fadvise is working properly.
103 * only check return values here.
106 /* posix_fadvise shouldn't affect errno. */
112 ATF_CHECK_EQ_MSG(ret = (x), exp, "got: %d", ret); \
113 ATF_CHECK_EQ_MSG(errno, 999, "got: %s", strerror(errno)); \
117 CE(posix_fadvise(fd
, 0, 0, -1), EINVAL
);
118 CE(posix_fadvise(pipe_fds
[0], 0, 0, POSIX_FADV_NORMAL
), ESPIPE
);
119 CE(posix_fadvise(badfd
, 0, 0, POSIX_FADV_NORMAL
), EBADF
);
120 CE(posix_fadvise(fd
, 0, 0, POSIX_FADV_NORMAL
), 0);
121 CE(posix_fadvise(fd
, 0, 0, POSIX_FADV_SEQUENTIAL
), 0);
122 CE(posix_fadvise(fd
, 0, 0, POSIX_FADV_RANDOM
), 0);
123 CE(posix_fadvise(fd
, 0, 0, POSIX_FADV_WILLNEED
), 0);
124 CE(posix_fadvise(fd
, 0, 0, POSIX_FADV_DONTNEED
), 0);
125 CE(posix_fadvise(fd
, 0, 0, POSIX_FADV_NOREUSE
), 0);
128 ATF_TC_BODY(posix_fadvise_reg
, tc
)
133 RL(rfd
= rump_sys_open("/a_file", O_CREAT
, 0666));
135 CE(rump_sys_posix_fadvise(rfd
, 0, 0, POSIX_FADV_NORMAL
), 0);
136 CE(rump_sys_posix_fadvise(rfd
, 0, 0, POSIX_FADV_SEQUENTIAL
), 0);
137 CE(rump_sys_posix_fadvise(rfd
, 0, 0, POSIX_FADV_RANDOM
), 0);
138 CE(rump_sys_posix_fadvise(rfd
, 0, 0, POSIX_FADV_WILLNEED
), 0);
139 CE(rump_sys_posix_fadvise(rfd
, 0, 0, POSIX_FADV_NOREUSE
), 0);
141 CE(rump_sys_posix_fadvise(rfd
,
142 INT64_MAX
-getpagesize(), getpagesize(), POSIX_FADV_NORMAL
), 0);
143 CE(rump_sys_posix_fadvise(rfd
,
144 INT64_MAX
-getpagesize(), getpagesize(), POSIX_FADV_SEQUENTIAL
), 0);
145 CE(rump_sys_posix_fadvise(rfd
,
146 INT64_MAX
-getpagesize(), getpagesize(), POSIX_FADV_RANDOM
), 0);
147 CE(rump_sys_posix_fadvise(rfd
,
148 INT64_MAX
-getpagesize(), getpagesize(), POSIX_FADV_WILLNEED
), 0);
149 CE(rump_sys_posix_fadvise(rfd
,
150 INT64_MAX
-getpagesize(), getpagesize(), POSIX_FADV_NOREUSE
), 0);
152 //atf_tc_expect_signal(-1, "http://mail-index.netbsd.org/source-changes-d/2010/11/11/msg002508.html");
153 CE(rump_sys_posix_fadvise(rfd
,
154 INT64_MAX
-getpagesize(), getpagesize(), POSIX_FADV_DONTNEED
), 0);
155 CE(rump_sys_posix_fadvise(rfd
, 0, 0, POSIX_FADV_DONTNEED
), 0);
161 ATF_TP_ADD_TC(tp
, posix_fadvise
);
162 ATF_TP_ADD_TC(tp
, posix_fadvise_reg
);
164 return atf_no_error();