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