Date: Sun, 14 Jun 2009 13:08:28 GMT From: Zhao Shuai <zhaoshuai@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 164337 for review Message-ID: <200906141308.n5ED8Svw018144@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <errno.h> #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 <sys/select.h> #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 <fcntl.h> #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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906141308.n5ED8Svw018144>