From owner-svn-src-all@freebsd.org Mon Apr 15 03:32:02 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0060C1587C82; Mon, 15 Apr 2019 03:32:02 +0000 (UTC) (envelope-from oshogbo@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 952C18DB98; Mon, 15 Apr 2019 03:32:01 +0000 (UTC) (envelope-from oshogbo@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 6A6232241; Mon, 15 Apr 2019 03:32:01 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3F3W1pf031231; Mon, 15 Apr 2019 03:32:01 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3F3W1Kb031230; Mon, 15 Apr 2019 03:32:01 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201904150332.x3F3W1Kb031230@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Mon, 15 Apr 2019 03:32:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346219 - head/lib/libnv/tests X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/lib/libnv/tests X-SVN-Commit-Revision: 346219 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 952C18DB98 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.956,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Mon, 15 Apr 2019 03:32:02 -0000 Author: oshogbo Date: Mon Apr 15 03:32:01 2019 New Revision: 346219 URL: https://svnweb.freebsd.org/changeset/base/346219 Log: libnv: extend the tests Add cases for sending file descriptors. Submitted by: Mindaugas Rasiukevicius MFC after: 2 weeks 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 Mon Apr 15 03:31:02 2019 (r346218) +++ head/lib/libnv/tests/nvlist_send_recv_test.c Mon Apr 15 03:32:01 2019 (r346219) @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -58,6 +59,7 @@ child(int sock) { nvlist_t *nvl; nvlist_t *empty; + int pfd[2]; nvl = nvlist_create(0); empty = nvlist_create(0); @@ -73,7 +75,16 @@ child(int sock) nvlist_add_string(nvl, "nvlist/string/", ""); nvlist_add_string(nvl, "nvlist/string/x", "x"); nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"); + nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO); + if (pipe(pfd) == -1) + err(EXIT_FAILURE, "pipe"); + if (write(pfd[1], "test", 4) != 4) + err(EXIT_FAILURE, "write"); + close(pfd[1]); + nvlist_add_descriptor(nvl, "nvlist/descriptor/pipe_rd", pfd[0]); + close(pfd[0]); + nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1); nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")); nvlist_move_nvlist(nvl, "nvlist/nvlist/empty", empty); @@ -91,8 +102,9 @@ parent(int sock) const nvlist_t *cnvl, *empty; const char *name, *cname; void *cookie, *ccookie; - int type, ctype; + int type, ctype, fd; size_t size; + char buf[4]; nvl = nvlist_recv(sock, 0); CHECK(nvlist_error(nvl) == 0); @@ -175,6 +187,15 @@ parent(int sock) name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); + CHECK(type == NV_TYPE_DESCRIPTOR); + CHECK(strcmp(name, "nvlist/descriptor/pipe_rd") == 0); + fd = nvlist_get_descriptor(nvl, name); + CHECK(fd_is_valid(fd)); + CHECK(read(fd, buf, sizeof(buf)) == 4); + CHECK(strncmp(buf, "test", sizeof(buf)) == 0); + + name = nvlist_next(nvl, &type, &cookie); + CHECK(name != NULL); CHECK(type == NV_TYPE_BINARY); CHECK(strcmp(name, "nvlist/binary/x") == 0); CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "x", 1) == 0); @@ -278,6 +299,12 @@ parent(int sock) cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); + CHECK(ctype == NV_TYPE_DESCRIPTOR); + CHECK(strcmp(cname, "nvlist/descriptor/pipe_rd") == 0); + CHECK(fd_is_valid(nvlist_get_descriptor(cnvl, cname))); + + cname = nvlist_next(cnvl, &ctype, &ccookie); + CHECK(cname != NULL); CHECK(ctype == NV_TYPE_BINARY); CHECK(strcmp(cname, "nvlist/binary/x") == 0); CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "x", 1) == 0); @@ -359,7 +386,7 @@ int main(void) { - printf("1..136\n"); + printf("1..146\n"); fflush(stdout); send_nvlist();