From nobody Fri Jun 17 19:24:01 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9C1548435D0; Fri, 17 Jun 2022 19:24:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LPpr20yD8z3Bpy; Fri, 17 Jun 2022 19:24:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655493842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0sTGv3deMmAXcpZcl9+sFDFlFteCiiqkqmdB7Cbq2K0=; b=K86Y9SAByQhSqT+Rz/BZ+XrrTxvYNi3NEdSq5Y74SrVJqu+3PrvM+H1BvmkCfICVWg/bnK +FUa36JBSbQlbjiSMyHF5uZCvOzAZ3OSJpfU/bstLuWWHBTCx6JK8uxkXpQAIt4/TulbtZ hlbuxIvGVubAn+JJ61Mkg6JrfUI2OYAgL+0lNoaTu0IA6pNVk7ekEmtF+jzdaDRBiNj60E HpqePOmFiVRihFh0OYpANwj2X73OEnupghpA1bPFzu8lZse5MgUkWnFr1h+yG/vpq2KVvI tPDF8DoQT3cJv5W0vxtguBFdb5gIQg3LeSKHuEIwV9QQOrgD6FP2jlsjR29bVw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B50CC255E2; Fri, 17 Jun 2022 19:24:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25HJO1hH095884; Fri, 17 Jun 2022 19:24:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJO1Do095883; Fri, 17 Jun 2022 19:24:01 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:24:01 GMT Message-Id: <202206171924.25HJO1Do095883@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: cc4c1e916a37 - stable/13 - Update tools/regression/poll/sockpoll.c for POLLRDPOLL. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cc4c1e916a378a40f9a3a76b8efb0724e710edef Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655493842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0sTGv3deMmAXcpZcl9+sFDFlFteCiiqkqmdB7Cbq2K0=; b=sv3QYoG7EXcCqEceMO0u4qZfAsd5xce4c4P8oCaaiodN073FRJRoXBWxTUK57v98yMFk+5 POYCzE9ZPVOUflY8JBAoXBDUDr/aJYxozrA2K5p6CExlAHR7ToLaBIMhbrDmAmvG2aLw1/ 3Y9goifhASJdJ7Hhsg9b1B1AntQOSTBhC0R7kMC/+HIk0aoCL9j/8suq8engOej+vwMJ3r vH6SHfF8Hcq3ocVyab/JeGeEcka4Phdwn/1f4emFUZWgj01X17i2DrBP9pVxRbKzbK6Z4V 5p+ORiFwYwMcXC70sU3be/pptnUI9etNv9EUxeuL0mW6WrmKR+5VTxtnZjniDQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655493842; a=rsa-sha256; cv=none; b=uuDKVnXwhAnw8OKBO17wt/D/0gbZ3UaoW/EKnHfdrRmHwaMXL77zj/Wirdak+U/9Tt+FHD gVwYMj8lNPSJ17Y5exrjk7myh3sI2+q51Ps3u1dWQBtVanw9xsmh5/wMmfHEYiTyb5naC5 C/bi/ec4Fz7E/FGcy9nyM1SA7bqmOxbY72nqvPzdgikKbURWOZiaw5vaf5sBlHRSeCwMYL 789NQybxX+96O6eAsrLru/TogARnG0zZtKn1s4zHyhA39BW1xwqtFdtTkBwsLp7Wmq0HYu h0xnZdw5yj0CVndyUvRx+4pBgVPf/v+/pPg92dRHKIPdI1iCw0wbKJtRlsnCJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=cc4c1e916a378a40f9a3a76b8efb0724e710edef commit cc4c1e916a378a40f9a3a76b8efb0724e710edef Author: Thomas Munro AuthorDate: 2021-04-28 11:08:27 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:22:13 +0000 Update tools/regression/poll/sockpoll.c for POLLRDPOLL. Add a POLLRDHUP example to this tool, for comparison with other operating systems. Also record current output on FreeBSD and Linux. Reviewed by: kib MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D29757 (cherry picked from commit 18f21f0355481283ceef0ec10e99554f44c205c2) --- tools/regression/poll/14/sockpoll.out | 22 +++++++ tools/regression/poll/l/sockpoll.out | 22 +++++++ tools/regression/poll/sockpoll.c | 111 +++++++++++++++++++++++----------- 3 files changed, 121 insertions(+), 34 deletions(-) diff --git a/tools/regression/poll/14/sockpoll.out b/tools/regression/poll/14/sockpoll.out new file mode 100644 index 000000000000..1e60f0e283e0 --- /dev/null +++ b/tools/regression/poll/14/sockpoll.out @@ -0,0 +1,22 @@ +1..18 +ok 1 state initial 0: expected POLLOUT; got POLLOUT +ok 2 state initial 1: expected POLLOUT; got POLLOUT +ok 3 state after large write: expected 0; got 0 +ok 4 state other side after large write: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 5 state other side after close: expected POLLIN | POLLHUP; got POLLIN | POLLHUP +not ok 6 state other side after reading input: expected POLLHUP; got POLLIN | POLLHUP +ok 7 state after shutdown(SHUT_WR): expected POLLOUT; got POLLOUT +ok 8 state other side after shutdown(SHUT_WR): expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 9 state other side after reading EOF: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 10 state after data from other side: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 11 state after writing: expected POLLIN; got POLLIN +ok 12 state after second shutdown: expected POLLIN | POLLHUP; got POLLIN | POLLHUP +not ok 13 state after second shutdown: expected POLLHUP; got POLLIN | POLLHUP +not ok 14 state after close: expected POLLHUP; got POLLIN | POLLHUP +ok 15 state after shutdown(SHUT_RD): expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 16 state other side after shutdown(SHUT_RD): expected POLLOUT; got POLLOUT +not ok 17 state after shutdown(SHUT_WR): expected POLLHUP; got POLLIN | POLLHUP +ok 18 state other side after shutdown(SHUT_WR): expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 19 state other side after shutdown(SHUT_RD): expected POLLOUT; got POLLOUT +ok 20 state other side after write: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 21 state other side after shutdown(SHUT_WR): expected POLLIN | POLLOUT | POLLRDHUP; got POLLIN | POLLOUT | POLLRDHUP diff --git a/tools/regression/poll/l/sockpoll.out b/tools/regression/poll/l/sockpoll.out new file mode 100644 index 000000000000..cf5627d7953d --- /dev/null +++ b/tools/regression/poll/l/sockpoll.out @@ -0,0 +1,22 @@ +1..18 +ok 1 state initial 0: expected POLLOUT; got POLLOUT +ok 2 state initial 1: expected POLLOUT; got POLLOUT +ok 3 state after large write: expected 0; got 0 +ok 4 state other side after large write: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +not ok 5 state other side after close: expected POLLIN | POLLHUP; got POLLIN | POLLOUT | POLLHUP +not ok 6 state other side after reading input: expected POLLHUP; got POLLIN | POLLOUT | POLLHUP +ok 7 state after shutdown(SHUT_WR): expected POLLOUT; got POLLOUT +ok 8 state other side after shutdown(SHUT_WR): expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 9 state other side after reading EOF: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 10 state after data from other side: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 11 state after writing: expected POLLIN; got POLLIN +not ok 12 state after second shutdown: expected POLLIN | POLLHUP; got POLLIN | POLLOUT | POLLHUP +not ok 13 state after second shutdown: expected POLLHUP; got POLLIN | POLLHUP +not ok 14 state after close: expected POLLHUP; got POLLIN | POLLOUT | POLLHUP | 8 +ok 15 state after shutdown(SHUT_RD): expected POLLIN | POLLOUT; got POLLIN | POLLOUT +ok 16 state other side after shutdown(SHUT_RD): expected POLLOUT; got POLLOUT +not ok 17 state after shutdown(SHUT_WR): expected POLLHUP; got POLLIN | POLLOUT | POLLHUP +not ok 18 state other side after shutdown(SHUT_WR): expected POLLIN | POLLOUT; got POLLIN | POLLOUT | POLLHUP +ok 19 state other side after shutdown(SHUT_RD): expected POLLOUT; got POLLOUT +ok 20 state other side after write: expected POLLIN | POLLOUT; got POLLIN | POLLOUT +not ok 21 state other side after shutdown(SHUT_WR): expected POLLIN | POLLOUT | POLLRDHUP; got POLLIN | POLLOUT | POLLHUP | POLLRDHUP diff --git a/tools/regression/poll/sockpoll.c b/tools/regression/poll/sockpoll.c index 4bffd29dc6f3..31ebcaf9bcb2 100644 --- a/tools/regression/poll/sockpoll.c +++ b/tools/regression/poll/sockpoll.c @@ -1,61 +1,82 @@ /* $FreeBSD$ */ -#include +#define _GNU_SOURCE /* expose POLLRDHUP when testing on Linux */ + #include #include #include #include +#include #include #include #include +#include #include -static const char * -decode_events(int events) +static void +append(char *out, size_t out_size, const char *s) +{ + size_t size = strlen(out); + + snprintf(out + size, out_size - size, "%s", s); +} + +static void +decode_events(int events, char *out, size_t out_size) { - char *ncresult; - const char *result; - - switch (events) { - case POLLIN: - result = "POLLIN"; - break; - case POLLOUT: - result = "POLLOUT"; - break; - case POLLIN | POLLOUT: - result = "POLLIN | POLLOUT"; - break; - case POLLHUP: - result = "POLLHUP"; - break; - case POLLIN | POLLHUP: - result = "POLLIN | POLLHUP"; - break; - case POLLOUT | POLLHUP: - result = "POLLOUT | POLLHUP"; - break; - case POLLIN | POLLOUT | POLLHUP: - result = "POLLIN | POLLOUT | POLLHUP"; - break; - default: - asprintf(&ncresult, "%#x", events); - result = ncresult; - break; + int unknown; + + out[0] = 0; + + if (events == 0) { + append(out, out_size, "0"); + return; + } + +#define DECODE_FLAG(x) \ + if (events & (x)) { \ + if (out[0] != 0) \ + append(out, out_size, " | "); \ + append(out, out_size, #x); \ + } + + /* Show the expected flags by name. */ + DECODE_FLAG(POLLIN); + DECODE_FLAG(POLLOUT); + DECODE_FLAG(POLLHUP); +#ifndef POLLRDHUP +#define KNOWN_FLAGS (POLLIN | POLLOUT | POLLHUP) +#else + DECODE_FLAG(POLLRDHUP); +#define KNOWN_FLAGS (POLLIN | POLLOUT | POLLHUP | POLLRDHUP); +#endif + + /* Show any unexpected bits as hex. */ + unknown = events & ~KNOWN_FLAGS; + if (unknown != 0) { + char buf[80]; + + snprintf(buf, sizeof(buf), "%s%x", out[0] != 0 ? " | " : "", + unknown); + append(out, out_size, buf); } - return (result); } static void report(int num, const char *state, int expected, int got) { + char expected_str[80]; + char got_str[80]; + + decode_events(expected, expected_str, sizeof(expected_str)); + decode_events(got, got_str, sizeof(got_str)); if (expected == got) printf("ok %-2d ", num); else printf("not ok %-2d", num); printf(" state %s: expected %s; got %s\n", - state, decode_events(expected), decode_events(got)); + state, expected_str, got_str); fflush(stdout); } @@ -198,5 +219,27 @@ main(void) close(fd[0]); close(fd[1]); +#ifdef POLLRDHUP + setup(); + pfd1.events |= POLLRDHUP; + if (shutdown(fd[0], SHUT_RD) == -1) + err(1, "shutdown"); + if (poll(&pfd1, 1, 0) == -1) + err(1, "poll"); + report(num++, "other side after shutdown(SHUT_RD)", POLLOUT, pfd1.revents); + if (write(fd[0], "x", 1) != 1) + err(1, "write"); + if (poll(&pfd1, 1, 0) == -1) + err(1, "poll"); + report(num++, "other side after write", POLLIN | POLLOUT, pfd1.revents); + if (shutdown(fd[0], SHUT_WR) == -1) + err(1, "shutdown"); + if (poll(&pfd1, 1, 0) == -1) + err(1, "poll"); + report(num++, "other side after shutdown(SHUT_WR)", POLLIN | POLLOUT | POLLRDHUP, pfd1.revents); + close(fd[0]); + close(fd[1]); +#endif + return (0); }