From owner-p4-projects@FreeBSD.ORG Sun Jun 14 13:08:29 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A97DD1065676; Sun, 14 Jun 2009 13:08:29 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 68BF31065673 for ; Sun, 14 Jun 2009 13:08:29 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 4C15D8FC12 for ; Sun, 14 Jun 2009 13:08:29 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5ED8Sdc018146 for ; Sun, 14 Jun 2009 13:08:28 GMT (envelope-from zhaoshuai@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5ED8Svw018144 for perforce@freebsd.org; Sun, 14 Jun 2009 13:08:28 GMT (envelope-from zhaoshuai@FreeBSD.org) Date: Sun, 14 Jun 2009 13:08:28 GMT Message-Id: <200906141308.n5ED8Svw018144@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zhaoshuai@FreeBSD.org using -f From: Zhao Shuai To: Perforce Change Reviews Cc: Subject: PERFORCE change 164337 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Jun 2009 13:08:30 -0000 http://perforce.freebsd.org/chv.cgi?CH=164337 Change 164337 by zhaoshuai@zhaoshuai on 2009/06/14 13:08:02 make the testing program easier to use Affected files ... .. //depot/projects/soc2009/fifo/fifo_test/functionality/reader1.c#3 edit .. //depot/projects/soc2009/fifo/fifo_test/functionality/select.c#4 edit .. //depot/projects/soc2009/fifo/fifo_test/functionality/writer1.c#3 edit Differences ... ==== //depot/projects/soc2009/fifo/fifo_test/functionality/reader1.c#3 (text+ko) ==== @@ -12,31 +12,39 @@ #include #include "test.h" +#define TEST_RDONLY 1 +#define TEST_RDWR 0 +#define TEST_NONBLOCK 0 + int main(int argc, char *argv[]) { int fd, n; char buffer[BUF_SIZE]; +#if TEST_RDONLY fd = open(FIFO_PATH, O_RDONLY); - /* +#elif TEST_RDWR fd = open(FIFO_PATH, O_RDWR); +#elif TEST_NONBLOCK fd = open(FIFO_PATH, O_RDONLY | O_NONBLOCK); - */ +#endif if (fd < 0) { perror("open error"); return (1); } +#if TEST_NONBLOCK retry: +#endif while ((n = read(fd, buffer, BUF_SIZE)) > 0) { printf("%s", buffer); memset(buffer, 0, n); } - /* +#if TEST_NONBLOCK if (n < 0 && errno == EAGAIN) { sleep(1); goto retry; } - */ +#endif return 0; } ==== //depot/projects/soc2009/fifo/fifo_test/functionality/select.c#4 (text+ko) ==== @@ -15,6 +15,9 @@ #include #include "test.h" +/* set this value to 0 when testing write */ +#define TEST_READ 1 + int main() { int fd, n, ret; @@ -23,11 +26,11 @@ FD_ZERO(&rset); FD_ZERO(&wset); +#if TEST_READ fd = open(FIFO_PATH, O_RDONLY | O_NONBLOCK); - /* +#elif fd = open(FIFO_PATH, O_WRONLY | O_NONBLOCK); - fd = open(FIFO_PATH, O_WRONLY); - */ +#endif if (fd < 0) { perror("open error"); return (1); @@ -35,25 +38,28 @@ while (1) { FD_SET(fd, &rset); FD_SET(fd, &wset); - +#if TEST_READ ret = select(fd+1, &rset, NULL, NULL, NULL); - /* +#elif ret = select(fd+1, NULL, &wset, NULL, NULL); - */ +#endif if (ret > 0) { +#if TEST_READ if (FD_ISSET(fd, &rset)) { n = read(fd, buf, BUF_SIZE); + if (n <= 0) + return (0); printf("%s", buf); memset(buf, 0, n); } - /* +#elif if (FD_ISSET(fd, &wset)) { n = read(0, buf, BUF_SIZE); if (n <= 0) return (0); write(fd, buf, n); } - */ +#endif } else if (ret < 0) { /* select error */ perror("select error"); return (2); ==== //depot/projects/soc2009/fifo/fifo_test/functionality/writer1.c#3 (text+ko) ==== @@ -13,16 +13,22 @@ #include #include "test.h" +#define TEST_WRONLY 1 +#define TEST_RDWR 0 +#define TEST_NONBLOCK 0 + int main(int argc, char *argv[]) { int fd, n; char buf[BUF_SIZE]; +#if TEST_WRONLY fd = open(FIFO_PATH, O_WRONLY); - /* +#elif TEST_RDWR fd = open(FIFO_PATH, O_RDWR); +#elif TEST_NONBLOCK fd = open(FIFO_PATH, O_WRONLY | O_NONBLOCK); - */ +#endif while ((n = read(0, buf, BUF_SIZE)) > 0) write(fd, buf, n);