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 <yamato (at) redhat.com> 18 * 19 * RESTRICTIONS 20 * None 21 */ 22 23 #define _XOPEN_SOURCE 600 24 #include <fcntl.h> 25 26 #include <unistd.h> 27 #include <signal.h> 28 #include <errno.h> 29 #include <string.h> 30 31 #include "tst_test.h" 32 #include "lapi/syscalls.h" 33 34 char fname[] = "/bin/cat"; /* test executable to open */ 35 int fd = -1; /* initialized in open */ 36 37 int expected_return = 0; 38 39 int defined_advise[] = { 40 POSIX_FADV_NORMAL, 41 POSIX_FADV_SEQUENTIAL, 42 POSIX_FADV_RANDOM, 43 POSIX_FADV_NOREUSE, 44 POSIX_FADV_WILLNEED, 45 POSIX_FADV_DONTNEED, 46 }; 47 48 static void verify_fadvise(unsigned int n) 49 { 50 TEST(posix_fadvise(fd, 0, 0, defined_advise[n])); 51 52 /* Man page says: 53 "On error, an error number is returned." */ 54 if (TST_RET == expected_return) { 55 tst_res(TPASS, "call succeeded expectedly"); 56 } else { 57 tst_res(TFAIL, 58 "unexpected return value - %ld : %s, advise %d - " 59 "expected %d", 60 TST_RET, 61 tst_strerrno(TST_RET), 62 defined_advise[n], expected_return); 63 } 64 } 65 66 static void setup(void) 67 { 68 fd = SAFE_OPEN(fname, O_RDONLY); 69 } 70 71 static void cleanup(void) 72 { 73 if (fd > 0) 74 SAFE_CLOSE(fd); 75 } 76 77 static struct tst_test test = { 78 .setup = setup, 79 .cleanup = cleanup, 80 .test = verify_fadvise, 81 .tcnt = ARRAY_SIZE(defined_advise), 82 }; 83