Xiaoguang Wang | fe17303 | 2014-02-12 18:01:38 +0800 | [diff] [blame] | 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" |
Xiaoguang Wang | fe17303 | 2014-02-12 18:01:38 +0800 | [diff] [blame] | 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 | |
| 44 | int main(int ac, char **av) |
| 45 | { |
| 46 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 47 | const char *msg; |
Xiaoguang Wang | fe17303 | 2014-02-12 18:01:38 +0800 | [diff] [blame] | 48 | int pipe_fds[2], test_fd; |
| 49 | int orig_pipe_size, new_pipe_size; |
| 50 | |
| 51 | |
| 52 | msg = parse_opts(ac, av, NULL, NULL); |
| 53 | if (msg != NULL) |
| 54 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 55 | |
| 56 | setup(); |
| 57 | |
| 58 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 59 | tst_count = 0; |
| 60 | |
| 61 | SAFE_PIPE(cleanup, pipe_fds); |
| 62 | test_fd = pipe_fds[1]; |
| 63 | |
| 64 | TEST(fcntl(test_fd, F_GETPIPE_SZ)); |
| 65 | if (TEST_RETURN < 0) { |
| 66 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 67 | "fcntl get pipe size failed"); |
| 68 | } |
| 69 | |
| 70 | orig_pipe_size = TEST_RETURN; |
| 71 | new_pipe_size = orig_pipe_size * 2; |
| 72 | TEST(fcntl(test_fd, F_SETPIPE_SZ, new_pipe_size)); |
| 73 | if (TEST_RETURN < 0) { |
| 74 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 75 | "fcntl test F_SETPIPE_SZ failed"); |
| 76 | } |
| 77 | |
| 78 | TEST(fcntl(test_fd, F_GETPIPE_SZ)); |
| 79 | if (TEST_RETURN < 0) { |
| 80 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 81 | "fcntl test F_GETPIPE_SZ failed"); |
| 82 | } |
| 83 | tst_resm(TINFO, "orig_pipe_size: %d new_pipe_size: %d", |
| 84 | orig_pipe_size, new_pipe_size); |
| 85 | if (TEST_RETURN >= new_pipe_size) { |
| 86 | tst_resm(TPASS, "fcntl test F_GETPIPE_SZ" |
| 87 | "and F_SETPIPE_SZ success"); |
| 88 | } else { |
| 89 | tst_resm(TFAIL, "fcntl test F_GETPIPE_SZ" |
| 90 | "and F_SETPIPE_SZ fail"); |
| 91 | } |
| 92 | SAFE_CLOSE(cleanup, pipe_fds[0]); |
| 93 | SAFE_CLOSE(cleanup, pipe_fds[1]); |
| 94 | } |
| 95 | |
| 96 | cleanup(); |
| 97 | tst_exit(); |
| 98 | } |
| 99 | |
| 100 | static void setup(void) |
| 101 | { |
| 102 | if ((tst_kvercmp(2, 6, 35)) < 0) { |
| 103 | tst_brkm(TCONF, NULL, "This test can only run on kernels" |
| 104 | "that are 2.6.35 and higher"); |
| 105 | } |
| 106 | |
| 107 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 108 | |
| 109 | TEST_PAUSE; |
| 110 | } |
| 111 | |
| 112 | static void cleanup(void) |
| 113 | { |
Xiaoguang Wang | fe17303 | 2014-02-12 18:01:38 +0800 | [diff] [blame] | 114 | } |