From owner-svn-src-all@FreeBSD.ORG Sat Aug 28 17:38:40 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8436E1065675; Sat, 28 Aug 2010 17:38:40 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 72BE68FC0A; Sat, 28 Aug 2010 17:38:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7SHce7f038499; Sat, 28 Aug 2010 17:38:40 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7SHce37038497; Sat, 28 Aug 2010 17:38:40 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201008281738.o7SHce37038497@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 28 Aug 2010 17:38:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211940 - head/tools/regression/poll X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Aug 2010 17:38:40 -0000 Author: kib Date: Sat Aug 28 17:38:40 2010 New Revision: 211940 URL: http://svn.freebsd.org/changeset/base/211940 Log: Test the poll(2) return value. MFC after: 2 weeks Modified: head/tools/regression/poll/pipepoll.c Modified: head/tools/regression/poll/pipepoll.c ============================================================================== --- head/tools/regression/poll/pipepoll.c Sat Aug 28 17:12:52 2010 (r211939) +++ head/tools/regression/poll/pipepoll.c Sat Aug 28 17:38:40 2010 (r211940) @@ -44,16 +44,34 @@ decode_events(int events) } static void -report(int num, const char *state, int expected, int got) +report_state(const char *state) { - if (expected == got) - printf("ok %-2d ", num); - else - printf("not ok %-2d", num); - printf(" %s state %s: expected %s; got %s\n", + + printf(" %s state %s: ", filetype == FT_PIPE ? "Pipe" : filetype == FT_SOCKETPAIR ? "Sock" : "FIFO", - state, decode_events(expected), decode_events(got)); + state); +} + +static void +report(int num, const char *state, int expected, int got, int res, + int res_expected) +{ + + if (res != res_expected) { + printf("not ok %-2d", num); + report_state(state); + printf("poll result %d expected %d. ", + res, res_expected); + } else { + if (expected == got) + printf("ok %-2d ", num); + else + printf("not ok %-2d", num); + report_state(state); + } + printf("expected %s; got %s\n", decode_events(expected), + decode_events(got)); fflush(stdout); } @@ -62,8 +80,9 @@ static pid_t ppid; static volatile sig_atomic_t state; static void -catch(int sig) +catch(int sig __unused) { + state++; } @@ -71,7 +90,7 @@ static void child(int fd, int num) { struct pollfd pfd; - int fd2; + int fd2, res; char buf[256]; if (filetype == FT_FIFO) { @@ -83,9 +102,9 @@ child(int fd, int num) pfd.events = POLLIN; if (filetype == FT_FIFO) { - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "0", 0, pfd.revents); + report(num++, "0", 0, pfd.revents, res, 0); } kill(ppid, SIGUSR1); @@ -101,30 +120,30 @@ child(int fd, int num) state = 4; goto state4; } - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "1", 0, pfd.revents); + report(num++, "1", 0, pfd.revents, res, 0); kill(ppid, SIGUSR1); usleep(1); while (state != 2) ; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "2", POLLIN, pfd.revents); + report(num++, "2", POLLIN, pfd.revents, res, 1); if (read(fd, buf, sizeof buf) != 1) err(1, "read"); - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "2a", 0, pfd.revents); + report(num++, "2a", 0, pfd.revents, res, 0); kill(ppid, SIGUSR1); usleep(1); while (state != 3) ; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "3", POLLHUP, pfd.revents); + report(num++, "3", POLLHUP, pfd.revents, res, 1); kill(ppid, SIGUSR1); /* @@ -137,17 +156,17 @@ child(int fd, int num) while (state != 4) ; state4: - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "4", 0, pfd.revents); + report(num++, "4", 0, pfd.revents, res, 0); kill(ppid, SIGUSR1); usleep(1); while (state != 5) ; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "5", POLLIN, pfd.revents); + report(num++, "5", POLLIN, pfd.revents, res, 1); kill(ppid, SIGUSR1); usleep(1); @@ -163,14 +182,14 @@ state4: * is an example of a broken program that quits on POLLHUP only -- * see its event-loop.c. */ - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6", POLLIN | POLLHUP, pfd.revents); + report(num++, "6", POLLIN | POLLHUP, pfd.revents, res, 1); if (read(fd, buf, sizeof buf) != 1) err(1, "read"); - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6a", POLLHUP, pfd.revents); + report(num++, "6a", POLLHUP, pfd.revents, res, 1); if (filetype == FT_FIFO) { /* * Check that POLLHUP is sticky for a new reader and for @@ -180,17 +199,17 @@ state4: if (fd2 < 0) err(1, "open for read"); pfd.fd = fd2; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6b", POLLHUP, pfd.revents); + report(num++, "6b", POLLHUP, pfd.revents, res, 1); pfd.fd = fd; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6c", POLLHUP, pfd.revents); + report(num++, "6c", POLLHUP, pfd.revents, res, 1); close(fd2); - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6d", POLLHUP, pfd.revents); + report(num++, "6d", POLLHUP, pfd.revents, res, 1); } close(fd); kill(ppid, SIGUSR1);