Sync usage with man page.
[netbsd-mini2440.git] / tests / kernel / t_posix_fadvise.c
blob6776a4518df2ffb9ea3e23242363b6f399bd67cc
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by YAMAMOTO Takashi.
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.
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.
32 /*-
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
38 * are met:
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
55 * SUCH DAMAGE.
58 #include <sys/cdefs.h>
59 __COPYRIGHT("@(#) Copyright (c) 2008\
60 The NetBSD Foundation, inc. All rights reserved.");
61 __RCSID("$NetBSD$");
63 #include <sys/fcntl.h>
65 #include <errno.h>
66 #include <string.h>
67 #include <unistd.h>
69 #include <atf-c.h>
71 #include "../h_macros.h"
73 ATF_TC(posix_fadvise);
74 ATF_TC_HEAD(posix_fadvise, tc)
76 atf_tc_set_md_var(tc, "descr", "Checks posix_fadvise(2)");
78 ATF_TC_BODY(posix_fadvise, tc)
80 int fd = STDIN_FILENO;
81 int pipe_fds[2];
82 int badfd = 10;
83 int ret;
85 (void)close(badfd);
86 RL(pipe(pipe_fds));
89 * it's hard to check if posix_fadvise is working properly.
90 * only check return values here.
93 /* posix_fadvise shouldn't affect errno. */
95 #define CE(x, exp) \
96 do { \
97 int save = errno; \
98 errno = 999; \
99 ATF_CHECK_EQ_MSG(ret = (x), exp, "got: %d", ret); \
100 ATF_CHECK_EQ_MSG(errno, 999, "got: %s", strerror(errno)); \
101 errno = save; \
102 } while (0);
104 CE(posix_fadvise(fd, 0, 0, -1), EINVAL);
105 CE(posix_fadvise(pipe_fds[0], 0, 0, POSIX_FADV_NORMAL), ESPIPE);
106 CE(posix_fadvise(badfd, 0, 0, POSIX_FADV_NORMAL), EBADF);
107 CE(posix_fadvise(fd, 0, 0, POSIX_FADV_NORMAL), 0);
108 CE(posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL), 0);
109 CE(posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM), 0);
110 CE(posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED), 0);
111 CE(posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED), 0);
112 CE(posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE), 0);
113 #undef CE
116 ATF_TP_ADD_TCS(tp)
118 ATF_TP_ADD_TC(tp, posix_fadvise);
120 return atf_no_error();