aboutsummaryrefslogtreecommitdiff
path: root/lib/libnv
diff options
context:
space:
mode:
authorMariusz Zaborski <oshogbo@FreeBSD.org>2019-04-15 03:32:01 +0000
committerMariusz Zaborski <oshogbo@FreeBSD.org>2019-04-15 03:32:01 +0000
commit908d1eef0b6e35421bc9bee34603c73e97d0fc7c (patch)
treee3bc5789b13538feefd7e825b72f64ffca699289 /lib/libnv
parent3810ba1b33c9301b7d62a38fded4c8a04524465e (diff)
downloadsrc-908d1eef0b6e35421bc9bee34603c73e97d0fc7c.tar.gz
src-908d1eef0b6e35421bc9bee34603c73e97d0fc7c.zip
libnv: extend the tests
Add cases for sending file descriptors. Submitted by: Mindaugas Rasiukevicius <rmind@noxt.eu> MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=346219
Diffstat (limited to 'lib/libnv')
-rw-r--r--lib/libnv/tests/nvlist_send_recv_test.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/libnv/tests/nvlist_send_recv_test.c b/lib/libnv/tests/nvlist_send_recv_test.c
index fbc918102b50..449a6df1da0d 100644
--- a/lib/libnv/tests/nvlist_send_recv_test.c
+++ b/lib/libnv/tests/nvlist_send_recv_test.c
@@ -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();