• 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 <fcntl.h>
29 #include <string.h>
30 #include <signal.h>
31 #include <sys/types.h>
32 #include <pwd.h>
33 
34 #include "test.h"
35 #include "safe_macros.h"
36 #include "lapi/fcntl.h"
37 
38 char *TCID = "fcntl30";
39 int TST_TOTAL = 1;
40 
41 static void setup(void);
42 static void cleanup(void);
43 
main(int ac,char ** av)44 int main(int ac, char **av)
45 {
46 	int lc;
47 	int pipe_fds[2], test_fd;
48 	int orig_pipe_size, new_pipe_size;
49 
50 
51 	tst_parse_opts(ac, av, NULL, NULL);
52 
53 	setup();
54 
55 	for (lc = 0; TEST_LOOPING(lc); lc++) {
56 		tst_count = 0;
57 
58 		SAFE_PIPE(cleanup, pipe_fds);
59 		test_fd = pipe_fds[1];
60 
61 		TEST(fcntl(test_fd, F_GETPIPE_SZ));
62 		if (TEST_RETURN < 0) {
63 			tst_brkm(TFAIL | TTERRNO, cleanup,
64 				 "fcntl get pipe size failed");
65 		}
66 
67 		orig_pipe_size = TEST_RETURN;
68 		new_pipe_size = orig_pipe_size * 2;
69 		TEST(fcntl(test_fd, F_SETPIPE_SZ, new_pipe_size));
70 		if (TEST_RETURN < 0) {
71 			tst_brkm(TFAIL | TTERRNO, cleanup,
72 				 "fcntl test F_SETPIPE_SZ failed");
73 		}
74 
75 		TEST(fcntl(test_fd, F_GETPIPE_SZ));
76 		if (TEST_RETURN < 0) {
77 			tst_brkm(TFAIL | TTERRNO, cleanup,
78 				 "fcntl test F_GETPIPE_SZ failed");
79 		}
80 		tst_resm(TINFO, "orig_pipe_size: %d new_pipe_size: %d",
81 			 orig_pipe_size, new_pipe_size);
82 		if (TEST_RETURN >= new_pipe_size) {
83 			tst_resm(TPASS, "fcntl test F_GETPIPE_SZ"
84 				 "and F_SETPIPE_SZ success");
85 		} else {
86 			tst_resm(TFAIL, "fcntl test F_GETPIPE_SZ"
87 				 "and F_SETPIPE_SZ fail");
88 		}
89 		SAFE_CLOSE(cleanup, pipe_fds[0]);
90 		SAFE_CLOSE(cleanup, pipe_fds[1]);
91 	}
92 
93 	cleanup();
94 	tst_exit();
95 }
96 
setup(void)97 static void setup(void)
98 {
99 	if ((tst_kvercmp(2, 6, 35)) < 0) {
100 		tst_brkm(TCONF, NULL, "This test can only run on kernels"
101 			 "that are 2.6.35 and higher");
102 	}
103 
104 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
105 
106 	TEST_PAUSE;
107 }
108 
cleanup(void)109 static void cleanup(void)
110 {
111 }
112