svn commit: r346219 - head/lib/libnv/tests
Mariusz Zaborski
oshogbo at FreeBSD.org
Tue Sep 3 14:07:41 UTC 2019
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 <rmind at noxt.eu>
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 <sys/wait.h>
#include <sys/nv.h>
+#include <stdlib.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -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();
More information about the svn-src-all
mailing list