• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014 Fujitsu Ltd.
3  * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 /*
19  * Description:
20  * Verify that,
21  *     Basic test for fcntl(2) using F_SETPIPE_SZ, F_GETPIPE_SZ argument.
22  */
23 
24 
25 #include <stdio.h>
26 #include <errno.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <signal.h>
30 #include <sys/types.h>
31 #include <pwd.h>
32 
33 #include "test.h"
34 #include "safe_macros.h"
35 #include "lapi/fcntl.h"
36 
37 char *TCID = "fcntl30";
38 int TST_TOTAL = 1;
39 
40 static void setup(void);
41 static void cleanup(void);
42 
main(int ac,char ** av)43 int main(int ac, char **av)
44 {
45 	int lc;
46 	int pipe_fds[2], test_fd;
47 	int orig_pipe_size, new_pipe_size;
48 
49 
50 	tst_parse_opts(ac, av, NULL, NULL);
51 
52 	setup();
53 
54 	for (lc = 0; TEST_LOOPING(lc); lc++) {
55 		tst_count = 0;
56 
57 		SAFE_PIPE(cleanup, pipe_fds);
58 		test_fd = pipe_fds[1];
59 
60 		TEST(fcntl(test_fd, F_GETPIPE_SZ));
61 		if (TEST_RETURN < 0) {
62 			tst_brkm(TFAIL | TTERRNO, cleanup,
63 				 "fcntl get pipe size failed");
64 		}
65 
66 		orig_pipe_size = TEST_RETURN;
67 		new_pipe_size = orig_pipe_size * 2;
68 		TEST(fcntl(test_fd, F_SETPIPE_SZ, new_pipe_size));
69 		if (TEST_RETURN < 0) {
70 			tst_brkm(TFAIL | TTERRNO, cleanup,
71 				 "fcntl test F_SETPIPE_SZ failed");
72 		}
73 
74 		TEST(fcntl(test_fd, F_GETPIPE_SZ));
75 		if (TEST_RETURN < 0) {
76 			tst_brkm(TFAIL | TTERRNO, cleanup,
77 				 "fcntl test F_GETPIPE_SZ failed");
78 		}
79 		tst_resm(TINFO, "orig_pipe_size: %d new_pipe_size: %d",
80 			 orig_pipe_size, new_pipe_size);
81 		if (TEST_RETURN >= new_pipe_size) {
82 			tst_resm(TPASS, "fcntl test F_GETPIPE_SZ and F_SETPIPE_SZ passed");
83 		} else {
84 			tst_resm(TFAIL, "fcntl test F_GETPIPE_SZ and F_SETPIPE_SZ failed");
85 		}
86 		SAFE_CLOSE(cleanup, pipe_fds[0]);
87 		SAFE_CLOSE(cleanup, pipe_fds[1]);
88 	}
89 
90 	cleanup();
91 	tst_exit();
92 }
93 
setup(void)94 static void setup(void)
95 {
96 	if ((tst_kvercmp(2, 6, 35)) < 0) {
97 		tst_brkm(TCONF, NULL, "kernel >= 2.6.35 required");
98 	}
99 
100 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
101 
102 	TEST_PAUSE;
103 }
104 
cleanup(void)105 static void cleanup(void)
106 {
107 }
108