Skip to content

Commit

Permalink
Introduce NUTS_SKIP and use it in a few tests.
Browse files Browse the repository at this point in the history
This lets us see that we are skipping tests due to lack of support,
and makes it a little clearer to an observer.
  • Loading branch information
gdamore committed Nov 4, 2024
1 parent e7802b7 commit c2e396d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/platform/udp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ test_udp_multicast_send_recv(void)
nng_aio_free(aio2);
}

#ifdef NNG_ENABLE_IPV6
void
test_udp_send_v6_from_v4(void)
{
#ifdef NNG_ENABLE_IPV6
int rv;
nng_udp *u1;
nng_sockaddr sa = { 0 };
Expand Down Expand Up @@ -403,8 +403,10 @@ test_udp_send_v6_from_v4(void)

nng_aio_free(aio1);
nng_udp_close(u1);
#else
NUTS_SKIP("IPv6 not enabled");
#endif
}
#endif // NNG_ENABLE_IPV6

NUTS_TESTS = {
{ "udp pair", test_udp_pair },
Expand All @@ -415,8 +417,6 @@ NUTS_TESTS = {
{ "udp duplicate bind", test_udp_duplicate_bind },
{ "udp multicast membership", test_udp_multicast_membership },
{ "udp multicast send recv", test_udp_multicast_send_recv },
#ifdef NNG_ENABLE_IPV6
{ "udp send v6 from v4", test_udp_send_v6_from_v4 },
#endif
{ NULL, NULL },
};
57 changes: 52 additions & 5 deletions src/sp/transport/socket/sockfd_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 Staysail Systems, Inc. <[email protected]>
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2018 Devolutions <[email protected]>
// Copyright 2018 Cody Piersall <[email protected]>
Expand Down Expand Up @@ -60,6 +60,7 @@ test_sfd_listen(void)
void
test_sfd_accept(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
nng_socket s1, s2;
nng_listener l;
int fds[2];
Expand All @@ -74,11 +75,15 @@ test_sfd_accept(void)
NUTS_SLEEP(10);
NUTS_CLOSE(s1);
close(fds[1]);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sfd_exchange(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
nng_socket s1, s2;
nng_listener l1, l2;
int fds[2];
Expand All @@ -101,11 +106,15 @@ test_sfd_exchange(void)
NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
close(fds[1]);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sfd_exchange_late(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
nng_socket s1, s2;
nng_listener l1, l2;
int fds[2];
Expand All @@ -128,11 +137,15 @@ test_sfd_exchange_late(void)
NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
close(fds[1]);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sfd_recv_max(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
char msg[256];
char buf[256];
nng_socket s0;
Expand Down Expand Up @@ -169,11 +182,15 @@ test_sfd_recv_max(void)
NUTS_FAIL(nng_recv(s0, buf, &sz, 0), NNG_ETIMEDOUT);
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sfd_large(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
char *buf;
nng_socket s0;
nng_socket s1;
Expand Down Expand Up @@ -230,11 +247,15 @@ test_sfd_large(void)
NUTS_CLOSE(s1);
nng_msg_free(msg);
nng_free(buf, sz);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sockfd_close_pending(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
// this test verifies that closing a socket pair that has not
// started negotiation with the other side still works.
int fds[2];
Expand All @@ -248,11 +269,15 @@ test_sockfd_close_pending(void)
nng_msleep(10);
NUTS_CLOSE(s0);
close(fds[1]);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sockfd_close_peer(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
// this test verifies that closing a socket peer
// during negotiation is ok.
int fds[2];
Expand All @@ -266,11 +291,15 @@ test_sockfd_close_peer(void)
close(fds[1]);
nng_msleep(100);
NUTS_CLOSE(s0);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sockfd_listener_sockaddr(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
// this test verifies that closing a socket peer
// during negotiation is ok.
int fds[2];
Expand All @@ -286,11 +315,15 @@ test_sockfd_listener_sockaddr(void)
NUTS_ASSERT(sa.s_family == NNG_AF_UNSPEC);
close(fds[1]);
NUTS_CLOSE(s0);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sockfd_pipe_sockaddr(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
// this test verifies that closing a socket peer
// during negotiation is ok.
int fds[2];
Expand Down Expand Up @@ -322,11 +355,15 @@ test_sockfd_pipe_sockaddr(void)
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
nng_msg_free(msg);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sockfd_pipe_peer(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
// this test verifies that closing a socket peer
// during negotiation is ok.
int fds[2];
Expand Down Expand Up @@ -375,6 +412,9 @@ test_sockfd_pipe_peer(void)
nng_msg_free(msg);
NUTS_CLOSE(s0);
NUTS_CLOSE(s1);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
Expand All @@ -384,6 +424,7 @@ test_sfd_listen_full(void)
#define NNG_SFD_LISTEN_QUEUE 16
#endif

#ifdef NNG_HAVE_SOCKETPAIR
int fds[NNG_SFD_LISTEN_QUEUE * 2];
nng_socket s;
int i;
Expand All @@ -410,11 +451,15 @@ test_sfd_listen_full(void)
close(fds[i]);
}
NUTS_CLOSE(s);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sfd_fd_option_type(void)
{
#ifdef NNG_HAVE_SOCKETPAIR
nng_socket s;
nng_listener l;

Expand All @@ -423,12 +468,15 @@ test_sfd_fd_option_type(void)
NUTS_FAIL(
nng_listener_set_bool(l, NNG_OPT_SOCKET_FD, false), NNG_EBADTYPE);
NUTS_CLOSE(s);
#else
NUTS_SKIP("no socketpair");
#endif
}

void
test_sfd_fd_dev_zero(void)
{
#ifdef NNG_PLATFORM_POSIX
#ifdef NNG_HAVE_SOCKETPAIR
nng_socket s;
nng_listener l;
int fd;
Expand All @@ -441,13 +489,14 @@ test_sfd_fd_dev_zero(void)
NUTS_PASS(nng_listener_set_int(l, NNG_OPT_SOCKET_FD, fd));
nng_msleep(100);
NUTS_CLOSE(s);
#else
NUTS_SKIP("no socketpair");
#endif
}

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 },
Expand All @@ -462,7 +511,5 @@ NUTS_TESTS = {
{ "socket listen full", test_sfd_listen_full },
{ "socket bad fd type", test_sfd_fd_option_type },
{ "socket dev zero", test_sfd_fd_dev_zero },
#endif

{ NULL, NULL },
};
6 changes: 4 additions & 2 deletions src/sp/transport/tls/tls_tran_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ test_tls_recv_max(void)
void
test_tls_psk(void)
{
#ifdef NNG_SUPP_TLS_PSK
char msg[256];
char buf[256];
nng_socket s0;
Expand Down Expand Up @@ -348,6 +349,9 @@ test_tls_psk(void)
NUTS_CLOSE(s1);
nng_tls_config_free(c0);
nng_tls_config_free(c1);
#else
NUTS_SKIP("no PSK support");
#endif
}

NUTS_TESTS = {
Expand All @@ -360,8 +364,6 @@ NUTS_TESTS = {
{ "tls no delay option", test_tls_no_delay_option },
{ "tls keep alive option", test_tls_keep_alive_option },
{ "tls recv max", test_tls_recv_max },
#ifdef NNG_SUPP_TLS_PSK
{ "tls pre-shared key", test_tls_psk },
#endif
{ NULL, NULL },
};
1 change: 1 addition & 0 deletions src/testing/nuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ extern const char *nuts_garbled_crt;
#define NUTS_ASSERT TEST_ASSERT
#define NUTS_CASE TEST_CASE
#define NUTS_MSG TEST_MSG
#define NUTS_SKIP TEST_SKIP

#define NUTS_TESTS TEST_LIST

Expand Down

0 comments on commit c2e396d

Please sign in to comment.