From owner-svn-src-head@freebsd.org Tue Jul 16 16:33:45 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1370FB45F0; Tue, 16 Jul 2019 16:33:45 +0000 (UTC) (envelope-from markj@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E8DA88EDDC; Tue, 16 Jul 2019 16:33:44 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B2B778B03; Tue, 16 Jul 2019 16:33:44 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6GGXiJX039799; Tue, 16 Jul 2019 16:33:44 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6GGXiXI039798; Tue, 16 Jul 2019 16:33:44 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201907161633.x6GGXiXI039798@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 16 Jul 2019 16:33:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r350055 - head/lib/libnv/tests X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/lib/libnv/tests X-SVN-Commit-Revision: 350055 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E8DA88EDDC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_SHORT(-0.98)[-0.980,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jul 2019 16:33:45 -0000 Author: markj Date: Tue Jul 16 16:33:44 2019 New Revision: 350055 URL: https://svnweb.freebsd.org/changeset/base/350055 Log: Add a regression test which transfers varying number of rights. This exercises the PKG_MAX_SIZE limit mentioned in r350054. MFC after: 1 week Sponsored by: The FreeBSD Foundation Modified: head/lib/libnv/tests/nvlist_send_recv_test.c Modified: head/lib/libnv/tests/nvlist_send_recv_test.c ============================================================================== --- head/lib/libnv/tests/nvlist_send_recv_test.c Tue Jul 16 16:28:50 2019 (r350054) +++ head/lib/libnv/tests/nvlist_send_recv_test.c Tue Jul 16 16:33:44 2019 (r350055) @@ -30,8 +30,9 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include +#include #include #include @@ -39,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -375,11 +377,106 @@ ATF_TC_BODY(nvlist_send_recv__send_closed_fd, tc) ATF_REQUIRE_ERRNO(EBADF, nvlist_send(socks[1], nvl) != 0); } +static int +nopenfds(void) +{ + size_t len; + int error, mib[4], n; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_NFDS; + mib[3] = 0; + + len = sizeof(n); + error = sysctl(mib, nitems(mib), &n, &len, NULL, 0); + if (error != 0) + return (-1); + return (n); +} + +#define NFDS 512 + +static void +send_many_fds_child(int sock) +{ + char name[16]; + nvlist_t *nvl; + int anfds, bnfds, fd, i, j; + + fd = open(_PATH_DEVNULL, O_RDONLY); + ATF_REQUIRE(fd >= 0); + + for (i = 1; i < NFDS; i++) { + nvl = nvlist_create(0); + bnfds = nopenfds(); + if (bnfds == -1) + err(EXIT_FAILURE, "sysctl"); + + for (j = 0; j < i; j++) { + snprintf(name, sizeof(name), "fd%d", j); + nvlist_add_descriptor(nvl, name, fd); + } + nvlist_send(sock, nvl); + nvlist_destroy(nvl); + + anfds = nopenfds(); + if (anfds == -1) + err(EXIT_FAILURE, "sysctl"); + if (anfds != bnfds) + errx(EXIT_FAILURE, "fd count mismatch"); + } +} + +ATF_TC_WITHOUT_HEAD(nvlist_send_recv__send_many_fds); +ATF_TC_BODY(nvlist_send_recv__send_many_fds, tc) +{ + char name[16]; + nvlist_t *nvl; + int anfds, bnfds, fd, i, j, socks[2], status; + pid_t pid; + + ATF_REQUIRE(socketpair(PF_UNIX, SOCK_STREAM, 0, socks) == 0); + + pid = fork(); + ATF_REQUIRE(pid >= 0); + if (pid == 0) { + /* Child. */ + (void)close(socks[0]); + send_many_fds_child(socks[1]); + _exit(0); + } + + (void)close(socks[1]); + + for (i = 1; i < NFDS; i++) { + bnfds = nopenfds(); + ATF_REQUIRE(bnfds != -1); + + nvl = nvlist_recv(socks[0], 0); + ATF_REQUIRE(nvl != NULL); + for (j = 0; j < i; j++) { + snprintf(name, sizeof(name), "fd%d", j); + fd = nvlist_take_descriptor(nvl, name); + ATF_REQUIRE(close(fd) == 0); + } + nvlist_destroy(nvl); + + anfds = nopenfds(); + ATF_REQUIRE(anfds != -1); + ATF_REQUIRE(anfds == bnfds); + } + + ATF_REQUIRE(waitpid(pid, &status, 0) == pid); + ATF_REQUIRE(status == 0); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, nvlist_send_recv__send_nvlist); ATF_TP_ADD_TC(tp, nvlist_send_recv__send_closed_fd); + ATF_TP_ADD_TC(tp, nvlist_send_recv__send_many_fds); return (atf_no_error()); }