From owner-svn-src-all@FreeBSD.ORG Sat Sep 11 06:38:34 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 A4DF1106566B; Sat, 11 Sep 2010 06:38:34 +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 883508FC15; Sat, 11 Sep 2010 06:38:34 +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 o8B6cYoJ056608; Sat, 11 Sep 2010 06:38:34 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8B6cYxn056606; Sat, 11 Sep 2010 06:38:34 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009110638.o8B6cYxn056606@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 11 Sep 2010 06:38:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212454 - stable/8/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, 11 Sep 2010 06:38:34 -0000 Author: kib Date: Sat Sep 11 06:38:34 2010 New Revision: 212454 URL: http://svn.freebsd.org/changeset/base/212454 Log: MFC r211940: Test the poll(2) return value. Modified: stable/8/tools/regression/poll/pipepoll.c Directory Properties: stable/8/tools/regression/poll/ (props changed) Modified: stable/8/tools/regression/poll/pipepoll.c ============================================================================== --- stable/8/tools/regression/poll/pipepoll.c Sat Sep 11 04:45:51 2010 (r212453) +++ stable/8/tools/regression/poll/pipepoll.c Sat Sep 11 06:38:34 2010 (r212454) @@ -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);