Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipc tests #1941

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/platform/posix/posix_ipcdial.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,19 @@ ipc_dialer_dial(void *arg, nni_aio *aio)
nni_aio_finish_error(aio, rv);
}

static int
ipc_dialer_get_remaddr(void *arg, void *buf, size_t *szp, nni_type t)
{
ipc_dialer *d = arg;

return (nni_copyout_sockaddr(&d->sa, buf, szp, t));
}

static const nni_option ipc_dialer_options[] = {
{
.o_name = NNG_OPT_REMADDR,
.o_get = ipc_dialer_get_remaddr,
},
{
.o_name = NULL,
},
Expand Down
12 changes: 12 additions & 0 deletions src/platform/windows/win_ipcdial.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,19 @@ ipc_dialer_free(void *arg)
NNI_FREE_STRUCT(d);
}

static int
ipc_dialer_get_remaddr(void *arg, void *buf, size_t *szp, nni_type t)
{
ipc_dialer *d = arg;

return (nni_copyout_sockaddr(&d->sa, buf, szp, t));
}

static const nni_option ipc_dialer_options[] = {
{
.o_name = NNG_OPT_REMADDR,
.o_get = ipc_dialer_get_remaddr,
},
{
.o_name = NULL,
},
Expand Down
129 changes: 129 additions & 0 deletions src/sp/transport/ipc/ipc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ test_ipc_dialer_properties(void)
NUTS_FAIL(nng_dialer_get_addr(d, NNG_OPT_LOCADDR, &sa), NNG_ENOTSUP);

NUTS_FAIL(nng_dialer_set_addr(d, NNG_OPT_LOCADDR, &sa), NNG_ENOTSUP);
NUTS_PASS(nng_dialer_get_addr(d, NNG_OPT_REMADDR, &sa));
NUTS_TRUE(sa.s_family == NNG_AF_IPC);

z = 8192;
NUTS_PASS(nng_dialer_set_size(d, NNG_OPT_RECVMAXSZ, z));
Expand Down Expand Up @@ -143,6 +145,95 @@ test_ipc_listener_properties(void)
NUTS_CLOSE(s);
}

void
test_ipc_ping_pong(void)
{
nng_socket s0;
nng_socket s1;
char *addr;

NUTS_ENABLE_LOG(NNG_LOG_INFO);
NUTS_ADDR(addr, "ipc");
NUTS_OPEN(s0);
NUTS_OPEN(s1);
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_SENDTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_SENDTIMEO, 100));

NUTS_MARRY_EX(s0, s1, addr, NULL, NULL);

NUTS_SEND(s0, "ping");
NUTS_RECV(s1, "ping");
NUTS_SEND(s1, "pong");
NUTS_RECV(s0, "pong");
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
}

void
test_ipc_ping_pong_many(void)
{
nng_socket s0;
nng_socket s1;
char *addr;

NUTS_ADDR(addr, "ipc");
NUTS_OPEN(s0);
NUTS_OPEN(s1);
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_SENDTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_SENDTIMEO, 100));

NUTS_MARRY_EX(s0, s1, addr, NULL, NULL);

for (int i = 0; i < 100; i++) {
NUTS_SEND(s0, "ping");
NUTS_RECV(s1, "ping");
NUTS_SEND(s1, "pong");
NUTS_RECV(s0, "pong");
}
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
}

void
test_ipc_huge_msg(void)
{
nng_socket s0;
nng_socket s1;
char *addr;
nng_msg *m;

NUTS_ADDR(addr, "ipc");
NUTS_PASS(nng_msg_alloc(&m, 1 << 20));
memset(nng_msg_body(m), 'a', 1 << 20);
NUTS_OPEN(s0);
NUTS_OPEN(s1);
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_SENDTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_SENDTIMEO, 100));

NUTS_MARRY_EX(s0, s1, addr, NULL, NULL);

NUTS_PASS(nng_sendmsg(s0, m, 0));
NUTS_PASS(nng_recvmsg(s1, &m, 0));

NUTS_TRUE(nng_msg_len(m) == 1 << 20);
char *body = nng_msg_body(m);
for (int i = 0; i < 1 << 20; i++) {
if (body[i] != 'a') {
NUTS_TRUE(body[i] == 'a');
break;
}
}
nng_msg_free(m);
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
}

void
test_ipc_recv_max(void)
{
Expand Down Expand Up @@ -177,6 +268,23 @@ test_ipc_recv_max(void)
NUTS_CLOSE(s1);
}

void
test_ipc_connect_refused(void)
{
nng_socket s0;
nng_dialer d;
char *addr;

NUTS_ENABLE_LOG(NNG_LOG_INFO);
NUTS_ADDR(addr, "ipc");
NUTS_OPEN(s0);
NUTS_PASS(nng_socket_set_ms(s0, NNG_OPT_RECVTIMEO, 100));
NUTS_PASS(nng_socket_set_size(s0, NNG_OPT_RECVMAXSZ, 200));
NUTS_PASS(nng_dialer_create(&d, s0, addr));
NUTS_FAIL(nng_dialer_start(d, 0), NNG_ECONNREFUSED);
NUTS_CLOSE(s0);
}

void
test_ipc_connect_blocking(void)
{
Expand Down Expand Up @@ -250,6 +358,22 @@ test_ipc_listen_accept_cancel(void)
nng_stream_listener_free(l);
}

void
test_ipc_listen_duplicate(void)
{
nng_socket s0;
char *addr;

NUTS_ENABLE_LOG(NNG_LOG_INFO);
NUTS_ADDR(addr, "ipc");
NUTS_OPEN(s0);

// start a listening stream listener but do not call accept
NUTS_PASS(nng_listen(s0, addr, NULL, 0));
NUTS_FAIL(nng_listen(s0, addr, NULL, 0), NNG_EADDRINUSE);
NUTS_CLOSE(s0);
}

void
test_ipc_listener_clean_stale(void)
{
Expand Down Expand Up @@ -556,10 +680,15 @@ TEST_LIST = {
{ "ipc dialer props", test_ipc_dialer_properties },
{ "ipc listener perms", test_ipc_listener_perms },
{ "ipc listener props", test_ipc_listener_properties },
{ "ipc ping pong", test_ipc_ping_pong },
{ "ipc ping pong many", test_ipc_ping_pong_many },
{ "ipc huge msg", test_ipc_huge_msg },
{ "ipc recv max", test_ipc_recv_max },
{ "ipc connect refused", test_ipc_connect_refused },
{ "ipc connect blocking", test_ipc_connect_blocking },
{ "ipc connect blocking accept", test_ipc_connect_blocking_accept },
{ "ipc listen cleanup stale", test_ipc_listener_clean_stale },
{ "ipc listen duplicate", test_ipc_listen_duplicate },
{ "ipc listen accept cancel", test_ipc_listen_accept_cancel },
{ "ipc abstract sockets", test_abstract_sockets },
{ "ipc abstract auto bind", test_abstract_auto_bind },
Expand Down
2 changes: 0 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ add_nng_test(files 5)
add_nng_test1(httpclient 60 NNG_SUPP_HTTP)
add_nng_test1(httpserver 30 NNG_SUPP_HTTP)
add_nng_test(inproc 5)
add_nng_test(ipc 5)
add_nng_test(ipcsupp 10)
add_nng_test(multistress 60)
add_nng_test(nonblock 60)
add_nng_test(options 5)
add_nng_test(pipe 5)
add_nng_test(pollfd 5)
add_nng_test(scalability 20 ON)
add_nng_test(synch 5)
add_nng_test(tcpsupp 10)
Expand Down
79 changes: 0 additions & 79 deletions tests/ipc.c

This file was deleted.

Loading
Loading