1 /* 2 * Copyright (c) International Business Machines Corp., 2001 3 * 4 * This program is free software; you can rdistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. 16 */ 17 18 /* 19 * Basic test for pipe(). 20 */ 21 22 #include <errno.h> 23 #include <string.h> 24 #include "tst_test.h" 25 26 static int fds[2]; 27 28 static void verify_pipe(void) 29 { 30 int rd_size, wr_size; 31 char wrbuf[] = "abcdefghijklmnopqrstuvwxyz"; 32 char rdbuf[128]; 33 34 memset(rdbuf, 0, sizeof(rdbuf)); 35 36 TEST(pipe(fds)); 37 38 if (TST_RET == -1) { 39 tst_res(TFAIL | TTERRNO, "pipe()"); 40 return; 41 } 42 43 wr_size = SAFE_WRITE(1, fds[1], wrbuf, sizeof(wrbuf)); 44 rd_size = SAFE_READ(0, fds[0], rdbuf, sizeof(rdbuf)); 45 46 if (rd_size != wr_size) { 47 tst_res(TFAIL, "read() returned %d, expected %d", 48 rd_size, wr_size); 49 return; 50 } 51 52 if ((strncmp(rdbuf, wrbuf, wr_size)) != 0) { 53 tst_res(TFAIL, "Wrong data were read back"); 54 return; 55 } 56 57 SAFE_CLOSE(fds[0]); 58 SAFE_CLOSE(fds[1]); 59 60 tst_res(TPASS, "pipe() functionality is correct"); 61 } 62 63 static struct tst_test test = { 64 .test_all = verify_pipe, 65 }; 66