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

Gdamore/ipc test #1918

Merged
merged 3 commits into from
Nov 6, 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
104 changes: 103 additions & 1 deletion src/sp/transport/ipc/ipc_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Cody Piersall <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -8,6 +8,7 @@
// found online at https://opensource.org/licenses/MIT.
//

#include <nng/nng.h>
#include <nuts.h>

#ifdef NNG_PLATFORM_POSIX
Expand Down Expand Up @@ -176,6 +177,92 @@ test_ipc_recv_max(void)
NUTS_CLOSE(s1);
}

void
test_ipc_connect_blocking(void)
{
nng_socket s0;
nng_stream_listener *l;
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_stream_listener_alloc(&l, addr));
NUTS_PASS(nng_stream_listener_listen(l));

NUTS_PASS(nng_dial(s0, addr, NULL, NNG_FLAG_NONBLOCK));
nng_msleep(100);
NUTS_CLOSE(s0);
nng_stream_listener_close(l);
nng_stream_listener_free(l);
}

void
test_ipc_connect_blocking_accept(void)
{
nng_socket s0;
nng_stream_listener *l;
char *addr;
nng_aio *aio;

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_stream_listener_alloc(&l, addr));
NUTS_PASS(nng_stream_listener_listen(l));

NUTS_PASS(nng_dial(s0, addr, NULL, NNG_FLAG_NONBLOCK));
nng_msleep(100);
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
nng_stream_listener_accept(l, aio);
nng_aio_wait(aio);
NUTS_PASS(nng_aio_result(aio));
nng_stream_close(nng_aio_get_output(aio, 0));
nng_stream_free(nng_aio_get_output(aio, 0));
nng_aio_free(aio);
NUTS_CLOSE(s0);
nng_stream_listener_close(l);
nng_stream_listener_free(l);
}

void
test_ipc_listener_clean_stale(void)
{
#ifdef NNG_PLATFORM_POSIX
nng_socket s0;
nng_stream_listener *l;
char *addr;
char *path;
char renamed[256];

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_stream_listener_alloc(&l, addr));
NUTS_PASS(nng_stream_listener_listen(l));
path = addr + strlen("ipc://");
snprintf(renamed, sizeof(renamed), "%s.renamed", path);
NUTS_ASSERT(rename(path, renamed) == 0);
nng_stream_listener_close(l);
nng_stream_listener_free(l);
nng_msleep(100);
// put it back
NUTS_ASSERT(rename(renamed, path) == 0);

NUTS_PASS(nng_listen(s0, addr, NULL, 0));
nng_msleep(50);
NUTS_CLOSE(s0);
#else
NUTS_SKIP("Not POSIX.");
#endif
}

void
test_abstract_sockets(void)
{
Expand Down Expand Up @@ -203,6 +290,8 @@ test_abstract_sockets(void)
NUTS_RECV(s2, "ping");
NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
#else
NUTS_SKIP("No abstract sockets.");
#endif
}

Expand Down Expand Up @@ -250,6 +339,8 @@ test_abstract_auto_bind(void)

NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
#else
NUTS_SKIP("No abstract sockets.");
#endif
}

Expand All @@ -273,6 +364,8 @@ test_abstract_too_long(void)
NUTS_FAIL(nng_dial(s1, addr, NULL, NNG_FLAG_NONBLOCK), NNG_EADDRINVAL);

NUTS_CLOSE(s1);
#else
NUTS_SKIP("No abstract sockets.");
#endif
}

Expand Down Expand Up @@ -325,6 +418,8 @@ test_abstract_null(void)

NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
#else
NUTS_SKIP("No abstract sockets.");
#endif
}

Expand Down Expand Up @@ -374,6 +469,8 @@ test_unix_alias(void)

NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
#else
NUTS_SKIP("Not POSIX.");
#endif
}

Expand Down Expand Up @@ -427,6 +524,8 @@ test_ipc_pipe_peer(void)
nng_msg_free(msg);
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
#else
NUTS_SKIP("Not POSIX.");
#endif // NNG_PLATFORM_POSIX
}

Expand All @@ -437,6 +536,9 @@ TEST_LIST = {
{ "ipc listener perms", test_ipc_listener_perms },
{ "ipc listener props", test_ipc_listener_properties },
{ "ipc recv max", test_ipc_recv_max },
{ "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 abstract sockets", test_abstract_sockets },
{ "ipc abstract auto bind", test_abstract_auto_bind },
{ "ipc abstract name too long", test_abstract_too_long },
Expand Down
3 changes: 3 additions & 0 deletions src/tools/perf/pubdrop.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,7 @@ do_pubdrop(int argc, char **argv)
printf("Drop rate %.2f%%\n", expect ? 100.0 * missing / expect : 0);

nng_mtx_unlock(pa.mtx);
nng_cv_free(pa.cv);
nng_mtx_free(pa.mtx);
free(thrs);
}
Loading