Skip to content

Commit

Permalink
More test cases (coverage)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Dec 29, 2023
1 parent 6dd8b70 commit 84699b3
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion src/sp/transport/socket/sockfd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ test_sfd_exchange(void)
close(fds[1]);
}

void
test_sfd_exchange_late(void)
{
nng_socket s1, s2;
nng_listener l1, l2;
int fds[2];

NUTS_PASS(nng_socket_pair(fds));
NUTS_OPEN(s1);
NUTS_OPEN(s2);
NUTS_PASS(nng_listener_create(&l1, s1, "socket://"));
NUTS_PASS(nng_listener_set_int(l1, NNG_OPT_SOCKET_FD, fds[0]));
NUTS_PASS(nng_listener_start(l1, 0));
NUTS_PASS(nng_listener_create(&l2, s2, "socket://"));
NUTS_PASS(nng_listener_set_int(l2, NNG_OPT_SOCKET_FD, fds[1]));
NUTS_PASS(nng_listener_start(l2, 0));
NUTS_SLEEP(10);
NUTS_SEND(s1, "hello");
NUTS_RECV(s2, "hello");
NUTS_SEND(s2, "there");
NUTS_RECV(s1, "there");

NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
close(fds[1]);
}

void
test_sfd_recv_max(void)
{
Expand Down Expand Up @@ -331,28 +358,79 @@ test_sockfd_pipe_peer(void)
NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id));
NUTS_ASSERT(id == (uint64_t) getzoneid());
#else
NUTS_FAIL(nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id), NNG_ENOTSUP);
NUTS_FAIL(
nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id), NNG_ENOTSUP);
#endif

nng_msg_free(msg);
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
}

void
test_sfd_listen_full(void)
{
#ifndef NNG_SFD_LISTEN_QUEUE
#define NNG_SFD_LISTEN_QUEUE 16
#endif

int fds[NNG_SFD_LISTEN_QUEUE * 2];
nng_socket s;
int i;
nng_listener l;
for (i = 0; i < NNG_SFD_LISTEN_QUEUE * 2; i += 2) {
int pair[2];
NUTS_PASS(nng_socket_pair(pair));
fds[i] = pair[0];
fds[i+1] = pair[1];
}
NUTS_OPEN(s);
NUTS_PASS(nng_listener_create(&l, s, "socket://"));
for (i = 0; i < NNG_SFD_LISTEN_QUEUE * 2; i++) {
if (i < NNG_SFD_LISTEN_QUEUE) {
NUTS_PASS(nng_listener_set_int(
l, NNG_OPT_SOCKET_FD, fds[i]));
} else {
NUTS_FAIL(
nng_listener_set_int(l, NNG_OPT_SOCKET_FD, fds[i]),
NNG_ENOSPC);
}
}
for (i = 0; i < NNG_SFD_LISTEN_QUEUE * 2; i++) {
close(fds[i]);
}
NUTS_CLOSE(s);
}

void
test_sfd_fd_option_type(void)
{
nng_socket s;
nng_listener l;

NUTS_OPEN(s);
NUTS_PASS(nng_listener_create(&l, s, "socket://"));
NUTS_FAIL(nng_listener_set_bool(l, NNG_OPT_SOCKET_FD, false), NNG_EBADTYPE);
NUTS_CLOSE(s);
}

NUTS_TESTS = {
{ "socket connect fail", test_sfd_connect_fail },
{ "socket malformed address", test_sfd_malformed_address },
#ifdef NNG_HAVE_SOCKETPAIR
{ "socket listen", test_sfd_listen },
{ "socket accept", test_sfd_accept },
{ "socket exchange", test_sfd_exchange },
{ "socket exchange late", test_sfd_exchange_late },
{ "socket recv max", test_sfd_recv_max },
{ "socket exchange large", test_sfd_large },
{ "socket close pending", test_sockfd_close_pending },
{ "socket close peer", test_sockfd_close_peer },
{ "socket listener address", test_sockfd_listener_sockaddr },
{ "socket pipe address", test_sockfd_pipe_sockaddr },
{ "socket pipe peer id", test_sockfd_pipe_peer },
{ "socket listen full", test_sfd_listen_full },
{ "socket bad fd type", test_sfd_fd_option_type },
#endif

{ NULL, NULL },
Expand Down

0 comments on commit 84699b3

Please sign in to comment.