aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-03 16:26:19 -0800
committerGarrett D'Amore <garrett@damore.org>2024-11-03 16:50:04 -0800
commitc2e396d5f9b0151b3564073e9f439fa492e735f6 (patch)
treeee699f2b76a9d0e6995a475cadc3812393fa08f7 /src
parente7802b729a5b837df9bcac80b94196d015c2b29f (diff)
downloadnng-c2e396d5f9b0151b3564073e9f439fa492e735f6.tar.gz
nng-c2e396d5f9b0151b3564073e9f439fa492e735f6.tar.bz2
nng-c2e396d5f9b0151b3564073e9f439fa492e735f6.zip
Introduce NUTS_SKIP and use it in a few tests.
This lets us see that we are skipping tests due to lack of support, and makes it a little clearer to an observer.
Diffstat (limited to 'src')
-rw-r--r--src/platform/udp_test.c8
-rw-r--r--src/sp/transport/socket/sockfd_test.c57
-rw-r--r--src/sp/transport/tls/tls_tran_test.c6
-rw-r--r--src/testing/nuts.h1
4 files changed, 61 insertions, 11 deletions
diff --git a/src/platform/udp_test.c b/src/platform/udp_test.c
index b6b31c9b..7cafff1e 100644
--- a/src/platform/udp_test.c
+++ b/src/platform/udp_test.c
@@ -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 };
@@ -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 },
@@ -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 },
};
diff --git a/src/sp/transport/socket/sockfd_test.c b/src/sp/transport/socket/sockfd_test.c
index aba5af4e..842a377c 100644
--- a/src/sp/transport/socket/sockfd_test.c
+++ b/src/sp/transport/socket/sockfd_test.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
// Copyright 2018 Cody Piersall <cody.piersall@gmail.com>
@@ -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];
@@ -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];
@@ -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];
@@ -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;
@@ -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;
@@ -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];
@@ -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];
@@ -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];
@@ -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];
@@ -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];
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -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 },
@@ -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 },
};
diff --git a/src/sp/transport/tls/tls_tran_test.c b/src/sp/transport/tls/tls_tran_test.c
index 1965bdce..f186c3d3 100644
--- a/src/sp/transport/tls/tls_tran_test.c
+++ b/src/sp/transport/tls/tls_tran_test.c
@@ -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;
@@ -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 = {
@@ -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 },
};
diff --git a/src/testing/nuts.h b/src/testing/nuts.h
index 00a18994..ef639c31 100644
--- a/src/testing/nuts.h
+++ b/src/testing/nuts.h
@@ -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