1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Red Hat Inc., 2007
4 */
5
6 /*
7 * NAME
8 * posix_fadvise01.c
9 *
10 * DESCRIPTION
11 * Check the value that posix_fadvise returns for wrong ADVISE value.
12 *
13 * USAGE
14 * posix_fadvise01
15 *
16 * HISTORY
17 * 11/2007 Initial version by Masatake YAMATO <[email protected]>
18 *
19 * RESTRICTIONS
20 * None
21 */
22
23 #include <fcntl.h>
24
25 #include <unistd.h>
26 #include <signal.h>
27 #include <errno.h>
28 #include <string.h>
29
30 #include "tst_test.h"
31 #include "lapi/syscalls.h"
32
33 char fname[] = "/bin/cat"; /* test executable to open */
34 int fd = -1; /* initialized in open */
35
36 int expected_return = 0;
37
38 int defined_advise[] = {
39 POSIX_FADV_NORMAL,
40 POSIX_FADV_SEQUENTIAL,
41 POSIX_FADV_RANDOM,
42 POSIX_FADV_NOREUSE,
43 POSIX_FADV_WILLNEED,
44 POSIX_FADV_DONTNEED,
45 };
46
verify_fadvise(unsigned int n)47 static void verify_fadvise(unsigned int n)
48 {
49 TEST(posix_fadvise(fd, 0, 0, defined_advise[n]));
50
51 /* Man page says:
52 "On error, an error number is returned." */
53 if (TST_RET == expected_return) {
54 tst_res(TPASS, "call succeeded expectedly");
55 } else {
56 tst_res(TFAIL,
57 "unexpected return value - %ld : %s, advise %d - "
58 "expected %d",
59 TST_RET,
60 tst_strerrno(TST_RET),
61 defined_advise[n], expected_return);
62 }
63 }
64
setup(void)65 static void setup(void)
66 {
67 fd = SAFE_OPEN(fname, O_RDONLY);
68 }
69
cleanup(void)70 static void cleanup(void)
71 {
72 if (fd > 0)
73 SAFE_CLOSE(fd);
74 }
75
76 static struct tst_test test = {
77 .setup = setup,
78 .cleanup = cleanup,
79 .test = verify_fadvise,
80 .tcnt = ARRAY_SIZE(defined_advise),
81 };
82