3 * Copyright (c) Red Hat Inc., 2007
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Check the value that posix_fadvise returns for wrong ADVISE value.
31 * 11/2007 Initial version by Masatake YAMATO <yamato@redhat.com>
37 #define _XOPEN_SOURCE 600
46 #include "linux_syscall_numbers.h"
47 #ifndef _FILE_OFFSET_BITS
48 #define _FILE_OFFSET_BITS 32
51 #ifndef __NR_fadvise64
52 #define __NR_fadvise64 0
58 TCID_DEFINE(posix_fadvise03
); /* Test program identifier. */
59 extern int Tst_count
; /* Test Case counter for tst_* routines */
61 char fname
[] = "/bin/cat"; /* test executable to open */
62 int fd
= -1; /* initialized in open */
64 int expected_error
= EINVAL
;
66 int defined_advise
[] = {
68 POSIX_FADV_SEQUENTIAL
,
75 #define defined_advise_total (sizeof(defined_advise) / sizeof(defined_advise[0]))
78 /* Too many test cases. */
79 int TST_TOTAL
= (INT_MAX
- defined_advise_total
);
80 int advise_limit
= INT_MAX
;
82 int TST_TOTAL
= (32 - defined_advise_total
);
83 int advise_limit
= 32;
87 Return 1 if advise is in defined_advise.
89 static int is_defined_advise(int advise
)
92 for (i
= 0; i
< defined_advise_total
; i
++) {
93 if (defined_advise
[i
] == advise
)
100 int main(int ac
, char **av
)
102 int lc
; /* loop counter */
103 char *msg
; /* message returned from parse_opts */
106 /* Check this system has fadvise64 system which is used
108 if ((_FILE_OFFSET_BITS
!= 64) && (__NR_fadvise64
== 0)) {
110 "This test can only run on kernels that implements ");
111 tst_resm(TWARN
, "fadvise64 which is used from posix_fadvise");
116 * parse standard options
118 if ((msg
= parse_opts(ac
, av
, (option_t
*) NULL
, NULL
)) != (char *)NULL
)
119 tst_brkm(TBROK
, cleanup
, "OPTION PARSING ERROR - %s", msg
);
122 * perform global setup for test
127 * check looping state if -i option given on the command line
129 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
131 /* reset Tst_count in case we are looping. */
134 /* loop through the test cases */
135 for (advise
= 0; advise
< advise_limit
; advise
++) {
137 /* Don't use defiend advise as an argument. */
138 if (is_defined_advise(advise
)) {
142 TEST(posix_fadvise(fd
, 0, 0, advise
));
144 if (TEST_RETURN
== 0) {
145 tst_resm(TFAIL
, "call succeeded unexpectedly");
150 "On error, an error number is returned." */
151 if (TEST_RETURN
== expected_error
) {
153 "expected failure - "
154 "returned value = %ld, advise = %d : %s",
156 advise
, strerror(TEST_RETURN
));
159 "unexpected return value - %ld : %s, advise %d - "
162 strerror(TEST_RETURN
),
163 advise
, expected_error
);
166 } /* End for TEST_LOOPING */
177 * setup() - performs all ONE TIME setup for this test.
181 /* capture signals */
182 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
184 /* Pause if that option was specified */
187 fd
= open(fname
, O_RDONLY
);
189 tst_brkm(TBROK
, cleanup
,
190 "Unable to open a file(\"%s\") for test: %s\n",
191 fname
, strerror(errno
));
196 * cleanup() - performs all ONE TIME cleanup for this test at
197 * completion or premature exit.
202 * print timing stats if that option was specified.
203 * print errno log if that option was specified.
211 /* exit with return code appropriate for results */
213 } /* End cleanup() */