diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-11-21 22:11:21 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-11-23 22:20:12 -0800 |
| commit | d1218d7309475193b53911667911c4f59a1a7752 (patch) | |
| tree | 6ea796998fb60d2cb8afa704faa77fe7fddd644c /src/protocol/survey0/respond_test.c | |
| parent | b826bfc171d90f8bde7bd672c0ac14201b8b2742 (diff) | |
| download | nng-d1218d7309475193b53911667911c4f59a1a7752.tar.gz nng-d1218d7309475193b53911667911c4f59a1a7752.tar.bz2 nng-d1218d7309475193b53911667911c4f59a1a7752.zip | |
New NUTS test framework (NNG Unit Test Support).
This is based on testutil/acutest, but is cleaner and fixes some
short-comings. We will be adding more support for additional
common paradigms to better facilitate transport tests.
While here we added some more test cases, and fixed a possible
symbol collision in the the stats framework (due to Linux use
of a macro definition of "si_value" in a standard OS header).
Test coverage may regress slightly as we are no longer using
some of the legacy APIs.
Diffstat (limited to 'src/protocol/survey0/respond_test.c')
| -rw-r--r-- | src/protocol/survey0/respond_test.c | 503 |
1 files changed, 244 insertions, 259 deletions
diff --git a/src/protocol/survey0/respond_test.c b/src/protocol/survey0/respond_test.c index efda181b..51844c76 100644 --- a/src/protocol/survey0/respond_test.c +++ b/src/protocol/survey0/respond_test.c @@ -7,18 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // -#include <string.h> - -#include <nng/nng.h> -#include <nng/protocol/survey0/respond.h> -#include <nng/protocol/survey0/survey.h> - -#include <acutest.h> -#include <testutil.h> - -#ifndef NNI_PROTO -#define NNI_PROTO(x, y) (((x) << 4u) | (y)) -#endif +#include <nuts.h> void test_resp_identity(void) @@ -27,18 +16,18 @@ test_resp_identity(void) int p; char * n; - TEST_CHECK(nng_respondent0_open(&s) == 0); - TEST_CHECK(nng_getopt_int(s, NNG_OPT_PROTO, &p) == 0); - TEST_CHECK(p == NNI_PROTO(6u, 3u)); - TEST_CHECK(nng_getopt_int(s, NNG_OPT_PEER, &p) == 0); - TEST_CHECK(p == NNI_PROTO(6u, 2u)); - TEST_CHECK(nng_getopt_string(s, NNG_OPT_PROTONAME, &n) == 0); - TEST_CHECK(strcmp(n, "respondent") == 0); + NUTS_PASS(nng_respondent0_open(&s)); + NUTS_PASS(nng_socket_get_int(s, NNG_OPT_PROTO, &p)); + NUTS_TRUE(p == NNG_RESPONDENT0_SELF); + NUTS_TRUE(nng_socket_get_int(s, NNG_OPT_PEER, &p) == 0); + NUTS_TRUE(p == NNG_RESPONDENT0_PEER); + NUTS_TRUE(nng_socket_get_string(s, NNG_OPT_PROTONAME, &n) == 0); + NUTS_MATCH(n, NNG_RESPONDENT0_SELF_NAME); nng_strfree(n); - TEST_CHECK(nng_getopt_string(s, NNG_OPT_PEERNAME, &n) == 0); - TEST_CHECK(strcmp(n, "surveyor") == 0); + NUTS_TRUE(nng_socket_get_string(s, NNG_OPT_PEERNAME, &n) == 0); + NUTS_MATCH(n, NNG_RESPONDENT0_PEER_NAME); nng_strfree(n); - TEST_CHECK(nng_close(s) == 0); + NUTS_CLOSE(s); } void @@ -47,11 +36,11 @@ test_resp_send_bad_state(void) nng_socket resp; nng_msg * msg = NULL; - TEST_CHECK(nng_respondent0_open(&resp) == 0); - TEST_CHECK(nng_msg_alloc(&msg, 0) == 0); - TEST_CHECK(nng_sendmsg(resp, msg, 0) == NNG_ESTATE); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_msg_alloc(&msg, 0)); + NUTS_FAIL(nng_sendmsg(resp, msg, 0), NNG_ESTATE); nng_msg_free(msg); - TEST_CHECK(nng_close(resp) == 0); + NUTS_CLOSE(resp); } void @@ -61,33 +50,33 @@ test_resp_poll_writeable(void) nng_socket surv; nng_socket resp; - TEST_NNG_PASS(nng_surveyor0_open(&surv)); - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_getopt_int(resp, NNG_OPT_SENDFD, &fd)); - TEST_CHECK(fd >= 0); + NUTS_PASS(nng_surveyor0_open(&surv)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_socket_get_int(resp, NNG_OPT_SENDFD, &fd)); + NUTS_TRUE(fd >= 0); // Not writable before connect. - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_TRUE(nuts_poll_fd(fd) == false); - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_MARRY(surv, resp); // Still not writable. - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_TRUE(nuts_poll_fd(fd) == false); // If we get a job, *then* we become writable - TEST_NNG_SEND_STR(surv, "abc"); - TEST_NNG_RECV_STR(resp, "abc"); - TEST_CHECK(testutil_pollfd(fd) == true); + NUTS_SEND(surv, "abc"); + NUTS_RECV(resp, "abc"); + NUTS_TRUE(nuts_poll_fd(fd) == true); // And is no longer writable once we send a message - TEST_NNG_SEND_STR(resp, "def"); - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_SEND(resp, "def"); + NUTS_TRUE(nuts_poll_fd(fd) == false); // Even after receiving it - TEST_NNG_RECV_STR(surv, "def"); - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_RECV(surv, "def"); + NUTS_TRUE(nuts_poll_fd(fd) == false); - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); } void @@ -98,34 +87,34 @@ test_resp_poll_readable(void) nng_socket resp; nng_msg * msg; - TEST_NNG_PASS(nng_surveyor0_open(&surv)); - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_getopt_int(resp, NNG_OPT_RECVFD, &fd)); - TEST_CHECK(fd >= 0); + NUTS_PASS(nng_surveyor0_open(&surv)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_socket_get_int(resp, NNG_OPT_RECVFD, &fd)); + NUTS_TRUE(fd >= 0); // Not readable if not connected! - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_TRUE(nuts_poll_fd(fd) == false); // Even after connect (no message yet) - TEST_NNG_PASS(testutil_marry(surv, resp)); - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_MARRY(surv, resp); + NUTS_TRUE(nuts_poll_fd(fd) == false); // But once we send messages, it is. // We have to send a request, in order to send a reply. - TEST_NNG_SEND_STR(surv, "abc"); - testutil_sleep(100); + NUTS_SEND(surv, "abc"); + NUTS_SLEEP(100); - TEST_CHECK(testutil_pollfd(fd) == true); + NUTS_TRUE(nuts_poll_fd(fd) == true); // and receiving makes it no longer ready - TEST_NNG_PASS(nng_recvmsg(resp, &msg, 0)); + NUTS_PASS(nng_recvmsg(resp, &msg, 0)); nng_msg_free(msg); - TEST_CHECK(testutil_pollfd(fd) == false); + NUTS_TRUE(nuts_poll_fd(fd) == false); // TODO verify unsolicited response - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); } void @@ -135,14 +124,12 @@ test_resp_context_no_poll(void) nng_socket resp; nng_ctx ctx; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_ctx_open(&ctx, resp)); - TEST_NNG_FAIL( - nng_ctx_getopt_int(ctx, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP); - TEST_NNG_FAIL( - nng_ctx_getopt_int(ctx, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP); - TEST_NNG_PASS(nng_ctx_close(ctx)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_ctx_open(&ctx, resp)); + NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP); + NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP); + NUTS_PASS(nng_ctx_close(ctx)); + NUTS_CLOSE(resp); } void @@ -151,28 +138,28 @@ test_resp_validate_peer(void) nng_socket s1, s2; nng_stat * stats; nng_stat * reject; - char addr[64]; + char * addr; - testutil_scratch_addr("inproc", sizeof(addr), addr); + NUTS_ADDR(addr, "inproc"); - TEST_NNG_PASS(nng_respondent0_open(&s1)); - TEST_NNG_PASS(nng_respondent0_open(&s2)); + NUTS_PASS(nng_respondent0_open(&s1)); + NUTS_PASS(nng_respondent0_open(&s2)); - TEST_NNG_PASS(nng_listen(s1, addr, NULL, 0)); - TEST_NNG_PASS(nng_dial(s2, addr, NULL, NNG_FLAG_NONBLOCK)); + NUTS_PASS(nng_listen(s1, addr, NULL, 0)); + NUTS_PASS(nng_dial(s2, addr, NULL, NNG_FLAG_NONBLOCK)); - testutil_sleep(100); - TEST_NNG_PASS(nng_stats_get(&stats)); + NUTS_SLEEP(100); + NUTS_PASS(nng_stats_get(&stats)); - TEST_CHECK(stats != NULL); - TEST_CHECK((reject = nng_stat_find_socket(stats, s1)) != NULL); - TEST_CHECK((reject = nng_stat_find(reject, "reject")) != NULL); + NUTS_TRUE(stats != NULL); + NUTS_TRUE((reject = nng_stat_find_socket(stats, s1)) != NULL); + NUTS_TRUE((reject = nng_stat_find(reject, "reject")) != NULL); - TEST_CHECK(nng_stat_type(reject) == NNG_STAT_COUNTER); - TEST_CHECK(nng_stat_value(reject) > 0); + NUTS_TRUE(nng_stat_type(reject) == NNG_STAT_COUNTER); + NUTS_TRUE(nng_stat_value(reject) > 0); - TEST_NNG_PASS(nng_close(s1)); - TEST_NNG_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); nng_stats_free(stats); } @@ -183,17 +170,17 @@ test_resp_double_recv(void) nng_aio * aio1; nng_aio * aio2; - TEST_NNG_PASS(nng_respondent0_open(&s1)); - TEST_NNG_PASS(nng_aio_alloc(&aio1, NULL, NULL)); - TEST_NNG_PASS(nng_aio_alloc(&aio2, NULL, NULL)); + NUTS_PASS(nng_respondent0_open(&s1)); + NUTS_PASS(nng_aio_alloc(&aio1, NULL, NULL)); + NUTS_PASS(nng_aio_alloc(&aio2, NULL, NULL)); nng_recv_aio(s1, aio1); nng_recv_aio(s1, aio2); nng_aio_wait(aio2); - TEST_NNG_FAIL(nng_aio_result(aio2), NNG_ESTATE); - TEST_NNG_PASS(nng_close(s1)); - TEST_NNG_FAIL(nng_aio_result(aio1), NNG_ECLOSED); + NUTS_FAIL(nng_aio_result(aio2), NNG_ESTATE); + NUTS_CLOSE(s1); + NUTS_FAIL(nng_aio_result(aio1), NNG_ECLOSED); nng_aio_free(aio1); nng_aio_free(aio2); } @@ -207,26 +194,26 @@ test_resp_close_pipe_before_send(void) nng_aio * aio1; nng_msg * m; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_surveyor0_open(&surv)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_aio_alloc(&aio1, NULL, NULL)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_surveyor0_open(&surv)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_aio_alloc(&aio1, NULL, NULL)); - TEST_NNG_PASS(testutil_marry(surv, resp)); - TEST_NNG_SEND_STR(surv, "test"); + NUTS_MARRY(surv, resp); + NUTS_SEND(surv, "test"); nng_recv_aio(resp, aio1); nng_aio_wait(aio1); - TEST_NNG_PASS(nng_aio_result(aio1)); - TEST_CHECK((m = nng_aio_get_msg(aio1)) != NULL); + NUTS_PASS(nng_aio_result(aio1)); + NUTS_TRUE((m = nng_aio_get_msg(aio1)) != NULL); p = nng_msg_get_pipe(m); - TEST_NNG_PASS(nng_pipe_close(p)); - TEST_NNG_PASS(nng_sendmsg(resp, m, 0)); + NUTS_PASS(nng_pipe_close(p)); + NUTS_PASS(nng_sendmsg(resp, m, 0)); - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); nng_aio_free(aio1); } @@ -238,25 +225,24 @@ test_resp_close_pipe_during_send(void) nng_pipe p = NNG_PIPE_INITIALIZER; nng_msg * m; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_surveyor0_open_raw(&surv)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 200)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_SENDBUF, 20)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_RECVBUF, 20)); - TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 20)); - TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_RECVBUF, 1)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_surveyor0_open_raw(&surv)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 200)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_SENDBUF, 20)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_RECVBUF, 20)); + NUTS_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 20)); + NUTS_PASS(nng_setopt_int(surv, NNG_OPT_RECVBUF, 1)); - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_MARRY(surv, resp); for (int i = 0; i < 100; i++) { int rv; - TEST_NNG_PASS(nng_msg_alloc(&m, 4)); - TEST_NNG_PASS( - nng_msg_append_u32(m, (unsigned) i | 0x80000000u)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); - TEST_NNG_PASS(nng_recvmsg(resp, &m, 0)); + NUTS_PASS(nng_msg_alloc(&m, 4)); + NUTS_PASS(nng_msg_append_u32(m, (unsigned) i | 0x80000000u)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); + NUTS_PASS(nng_recvmsg(resp, &m, 0)); p = nng_msg_get_pipe(m); rv = nng_sendmsg(resp, m, 0); if (rv == NNG_ETIMEDOUT) { @@ -264,12 +250,12 @@ test_resp_close_pipe_during_send(void) nng_msg_free(m); break; } - TEST_NNG_PASS(rv); + NUTS_PASS(rv); } - TEST_NNG_PASS(nng_pipe_close(p)); + NUTS_PASS(nng_pipe_close(p)); - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); } void @@ -279,16 +265,16 @@ test_resp_ctx_recv_aio_stopped(void) nng_ctx ctx; nng_aio * aio; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL)); - TEST_NNG_PASS(nng_ctx_open(&ctx, resp)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); + NUTS_PASS(nng_ctx_open(&ctx, resp)); nng_aio_stop(aio); nng_ctx_recv(ctx, aio); nng_aio_wait(aio); - TEST_NNG_FAIL(nng_aio_result(aio), NNG_ECANCELED); - TEST_NNG_PASS(nng_ctx_close(ctx)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED); + NUTS_PASS(nng_ctx_close(ctx)); + NUTS_CLOSE(resp); nng_aio_free(aio); } @@ -303,54 +289,53 @@ test_resp_close_pipe_context_send(void) nng_aio * aio[10]; int i; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_surveyor0_open_raw(&surv)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_SENDBUF, 1)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_RECVBUF, 1)); - TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 1)); - TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_RECVBUF, 1)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_surveyor0_open_raw(&surv)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_SENDBUF, 1)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_RECVBUF, 1)); + NUTS_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 1)); + NUTS_PASS(nng_setopt_int(surv, NNG_OPT_RECVBUF, 1)); for (i = 0; i < 10; i++) { - TEST_NNG_PASS(nng_ctx_open(&ctx[i], resp)); - TEST_NNG_PASS(nng_aio_alloc(&aio[i], NULL, NULL)); + NUTS_PASS(nng_ctx_open(&ctx[i], resp)); + NUTS_PASS(nng_aio_alloc(&aio[i], NULL, NULL)); } - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_MARRY(surv, resp); for (i = 0; i < 10; i++) { - TEST_NNG_PASS(nng_msg_alloc(&m, 4)); - TEST_NNG_PASS( - nng_msg_append_u32(m, (unsigned) i | 0x80000000u)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); + NUTS_PASS(nng_msg_alloc(&m, 4)); + NUTS_PASS(nng_msg_append_u32(m, (unsigned) i | 0x80000000u)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); nng_ctx_recv(ctx[i], aio[i]); } for (i = 0; i < 10; i++) { nng_aio_wait(aio[i]); - TEST_NNG_PASS(nng_aio_result(aio[i])); - TEST_CHECK((m = nng_aio_get_msg(aio[i])) != NULL); + NUTS_PASS(nng_aio_result(aio[i])); + NUTS_TRUE((m = nng_aio_get_msg(aio[i])) != NULL); p = nng_msg_get_pipe(m); nng_aio_set_msg(aio[i], m); nng_ctx_send(ctx[i], aio[i]); } // Note that SURVEYOR socket is not reading the results. - TEST_NNG_PASS(nng_pipe_close(p)); + NUTS_PASS(nng_pipe_close(p)); for (i = 0; i < 10; i++) { int rv; nng_aio_wait(aio[i]); rv = nng_aio_result(aio[i]); if (rv != 0) { - TEST_NNG_FAIL(rv, NNG_ECLOSED); + NUTS_FAIL(rv, NNG_ECLOSED); nng_msg_free(nng_aio_get_msg(aio[i])); } nng_aio_free(aio[i]); - TEST_NNG_PASS(nng_ctx_close(ctx[i])); + NUTS_PASS(nng_ctx_close(ctx[i])); } - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); } void @@ -363,33 +348,32 @@ test_resp_close_context_send(void) nng_aio * aio[10]; int i; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_surveyor0_open_raw(&surv)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_SENDBUF, 1)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_RECVBUF, 1)); - TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 1)); - TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_RECVBUF, 1)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_surveyor0_open_raw(&surv)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_SENDBUF, 1)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_RECVBUF, 1)); + NUTS_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 1)); + NUTS_PASS(nng_setopt_int(surv, NNG_OPT_RECVBUF, 1)); for (i = 0; i < 10; i++) { - TEST_NNG_PASS(nng_ctx_open(&ctx[i], resp)); - TEST_NNG_PASS(nng_aio_alloc(&aio[i], NULL, NULL)); + NUTS_PASS(nng_ctx_open(&ctx[i], resp)); + NUTS_PASS(nng_aio_alloc(&aio[i], NULL, NULL)); } - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_MARRY(surv, resp); for (i = 0; i < 10; i++) { - TEST_NNG_PASS(nng_msg_alloc(&m, 4)); - TEST_NNG_PASS( - nng_msg_append_u32(m, (unsigned) i | 0x80000000u)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); + NUTS_PASS(nng_msg_alloc(&m, 4)); + NUTS_PASS(nng_msg_append_u32(m, (unsigned) i | 0x80000000u)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); nng_ctx_recv(ctx[i], aio[i]); } for (i = 0; i < 10; i++) { nng_aio_wait(aio[i]); - TEST_NNG_PASS(nng_aio_result(aio[i])); - TEST_CHECK((m = nng_aio_get_msg(aio[i])) != NULL); + NUTS_PASS(nng_aio_result(aio[i])); + NUTS_TRUE((m = nng_aio_get_msg(aio[i])) != NULL); nng_aio_set_msg(aio[i], m); nng_ctx_send(ctx[i], aio[i]); } @@ -397,17 +381,17 @@ test_resp_close_context_send(void) // Note that REQ socket is not reading the results. for (i = 0; i < 10; i++) { int rv; - TEST_NNG_PASS(nng_ctx_close(ctx[i])); + NUTS_PASS(nng_ctx_close(ctx[i])); nng_aio_wait(aio[i]); rv = nng_aio_result(aio[i]); if (rv != 0) { - TEST_NNG_FAIL(rv, NNG_ECLOSED); + NUTS_FAIL(rv, NNG_ECLOSED); nng_msg_free(nng_aio_get_msg(aio[i])); } nng_aio_free(aio[i]); } - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); } static void @@ -417,16 +401,16 @@ test_resp_ctx_recv_nonblock(void) nng_ctx ctx; nng_aio * aio; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_ctx_open(&ctx, resp)); - TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_ctx_open(&ctx, resp)); + NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); nng_aio_set_timeout(aio, 0); // Instant timeout nng_ctx_recv(ctx, aio); nng_aio_wait(aio); - TEST_NNG_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT); - TEST_NNG_PASS(nng_close(resp)); + NUTS_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT); + NUTS_CLOSE(resp); nng_aio_free(aio); } @@ -439,19 +423,19 @@ test_resp_ctx_send_nonblock(void) nng_aio * aio; nng_msg * msg; - TEST_NNG_PASS(nng_surveyor0_open(&surv)); - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(nng_ctx_open(&ctx, resp)); - TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL)); - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_PASS(nng_surveyor0_open(&surv)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_ctx_open(&ctx, resp)); + NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); + NUTS_MARRY(surv, resp); - TEST_NNG_SEND_STR(surv, "SEND"); + NUTS_SEND(surv, "SEND"); nng_ctx_recv(ctx, aio); nng_aio_wait(aio); - TEST_NNG_PASS(nng_aio_result(aio)); + NUTS_PASS(nng_aio_result(aio)); // message carries over msg = nng_aio_get_msg(aio); nng_aio_set_msg(aio, msg); @@ -459,9 +443,9 @@ test_resp_ctx_send_nonblock(void) nng_ctx_send(ctx, aio); nng_aio_wait(aio); - TEST_NNG_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT); - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); nng_aio_free(aio); nng_msg_free(msg); } @@ -473,21 +457,21 @@ test_resp_recv_garbage(void) nng_socket surv; nng_msg * m; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_surveyor0_open_raw(&surv)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 200)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 200)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_surveyor0_open_raw(&surv)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 200)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 200)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_MARRY(surv, resp); - TEST_NNG_PASS(nng_msg_alloc(&m, 4)); - TEST_NNG_PASS(nng_msg_append_u32(m, 1u)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); - TEST_NNG_FAIL(nng_recvmsg(resp, &m, 0), NNG_ETIMEDOUT); + NUTS_PASS(nng_msg_alloc(&m, 4)); + NUTS_PASS(nng_msg_append_u32(m, 1u)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); + NUTS_FAIL(nng_recvmsg(resp, &m, 0), NNG_ETIMEDOUT); - TEST_NNG_PASS(nng_close(surv)); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(surv); + NUTS_CLOSE(resp); } static void @@ -499,29 +483,29 @@ test_resp_ttl_option(void) size_t sz; const char *opt = NNG_OPT_MAXTTL; - TEST_NNG_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_setopt_int(resp, opt, 1)); - TEST_NNG_FAIL(nng_setopt_int(resp, opt, 0), NNG_EINVAL); - TEST_NNG_FAIL(nng_setopt_int(resp, opt, -1), NNG_EINVAL); - TEST_NNG_FAIL(nng_setopt_int(resp, opt, 16), NNG_EINVAL); - TEST_NNG_FAIL(nng_setopt_int(resp, opt, 256), NNG_EINVAL); - TEST_NNG_PASS(nng_setopt_int(resp, opt, 3)); - TEST_NNG_PASS(nng_getopt_int(resp, opt, &v)); - TEST_CHECK(v == 3); + NUTS_PASS(nng_setopt_int(resp, opt, 1)); + NUTS_FAIL(nng_setopt_int(resp, opt, 0), NNG_EINVAL); + NUTS_FAIL(nng_setopt_int(resp, opt, -1), NNG_EINVAL); + NUTS_FAIL(nng_setopt_int(resp, opt, 16), NNG_EINVAL); + NUTS_FAIL(nng_setopt_int(resp, opt, 256), NNG_EINVAL); + NUTS_PASS(nng_setopt_int(resp, opt, 3)); + NUTS_PASS(nng_socket_get_int(resp, opt, &v)); + NUTS_TRUE(v == 3); v = 0; sz = sizeof(v); - TEST_NNG_PASS(nng_getopt(resp, opt, &v, &sz)); - TEST_CHECK(v == 3); - TEST_CHECK(sz == sizeof(v)); + NUTS_PASS(nng_socket_get(resp, opt, &v, &sz)); + NUTS_TRUE(v == 3); + NUTS_TRUE(sz == sizeof(v)); - TEST_NNG_FAIL(nng_setopt(resp, opt, "", 1), NNG_EINVAL); + NUTS_FAIL(nng_setopt(resp, opt, "", 1), NNG_EINVAL); sz = 1; - TEST_NNG_FAIL(nng_getopt(resp, opt, &v, &sz), NNG_EINVAL); - TEST_NNG_FAIL(nng_setopt_bool(resp, opt, true), NNG_EBADTYPE); - TEST_NNG_FAIL(nng_getopt_bool(resp, opt, &b), NNG_EBADTYPE); + NUTS_FAIL(nng_socket_get(resp, opt, &v, &sz), NNG_EINVAL); + NUTS_FAIL(nng_setopt_bool(resp, opt, true), NNG_EBADTYPE); + NUTS_FAIL(nng_socket_get_bool(resp, opt, &b), NNG_EBADTYPE); - TEST_NNG_PASS(nng_close(resp)); + NUTS_CLOSE(resp); } static void @@ -531,52 +515,52 @@ test_resp_ttl_drop(void) nng_socket surv; nng_msg * m; - TEST_NNG_PASS(nng_respondent0_open(&resp)); - TEST_NNG_PASS(nng_surveyor0_open_raw(&surv)); - TEST_NNG_PASS(nng_setopt_int(resp, NNG_OPT_MAXTTL, 3)); - TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 200)); - TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); + NUTS_PASS(nng_respondent0_open(&resp)); + NUTS_PASS(nng_surveyor0_open_raw(&surv)); + NUTS_PASS(nng_setopt_int(resp, NNG_OPT_MAXTTL, 3)); + NUTS_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 200)); + NUTS_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000)); - TEST_NNG_PASS(testutil_marry(surv, resp)); + NUTS_MARRY(surv, resp); // Send messages. Note that xrep implicitly adds a hop on receive. - TEST_NNG_PASS(nng_msg_alloc(&m, 0)); - TEST_NNG_PASS(nng_msg_append_u32(m, 1u)); // 2 hops - TEST_NNG_PASS(nng_msg_append_u32(m, 0x80000001u)); - TEST_NNG_PASS(nng_msg_append(m, "PASS1", 6)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); - - TEST_NNG_PASS(nng_msg_alloc(&m, 0)); - TEST_NNG_PASS(nng_msg_append_u32(m, 1u)); // 4 hops -- discard! - TEST_NNG_PASS(nng_msg_append_u32(m, 2u)); - TEST_NNG_PASS(nng_msg_append_u32(m, 3u)); - TEST_NNG_PASS(nng_msg_append_u32(m, 0x80000002u)); - TEST_NNG_PASS(nng_msg_append(m, "FAIL2", 6)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); - - TEST_NNG_PASS(nng_msg_alloc(&m, 0)); - TEST_NNG_PASS(nng_msg_append_u32(m, 1u)); // 3 hops - passes - TEST_NNG_PASS(nng_msg_append_u32(m, 2u)); - TEST_NNG_PASS(nng_msg_append_u32(m, 0x80000003u)); - TEST_NNG_PASS(nng_msg_append(m, "PASS3", 6)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); - - TEST_NNG_PASS(nng_msg_alloc(&m, 0)); - TEST_NNG_PASS(nng_msg_append_u32(m, 1u)); // 4 hops -- discard! - TEST_NNG_PASS(nng_msg_append_u32(m, 2u)); - TEST_NNG_PASS(nng_msg_append_u32(m, 3u)); - TEST_NNG_PASS(nng_msg_append_u32(m, 0x80000003u)); - TEST_NNG_PASS(nng_msg_append(m, "FAIL4", 6)); - TEST_NNG_PASS(nng_sendmsg(surv, m, 0)); - - TEST_NNG_RECV_STR(resp, "PASS1"); - TEST_NNG_RECV_STR(resp, "PASS3"); - - TEST_NNG_FAIL(nng_recvmsg(resp, &m, 0), NNG_ETIMEDOUT); - - TEST_NNG_PASS(nng_close(resp)); - TEST_NNG_PASS(nng_close(surv)); + NUTS_PASS(nng_msg_alloc(&m, 0)); + NUTS_PASS(nng_msg_append_u32(m, 1u)); // 2 hops + NUTS_PASS(nng_msg_append_u32(m, 0x80000001u)); + NUTS_PASS(nng_msg_append(m, "PASS1", 6)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); + + NUTS_PASS(nng_msg_alloc(&m, 0)); + NUTS_PASS(nng_msg_append_u32(m, 1u)); // 4 hops -- discard! + NUTS_PASS(nng_msg_append_u32(m, 2u)); + NUTS_PASS(nng_msg_append_u32(m, 3u)); + NUTS_PASS(nng_msg_append_u32(m, 0x80000002u)); + NUTS_PASS(nng_msg_append(m, "FAIL2", 6)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); + + NUTS_PASS(nng_msg_alloc(&m, 0)); + NUTS_PASS(nng_msg_append_u32(m, 1u)); // 3 hops - passes + NUTS_PASS(nng_msg_append_u32(m, 2u)); + NUTS_PASS(nng_msg_append_u32(m, 0x80000003u)); + NUTS_PASS(nng_msg_append(m, "PASS3", 6)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); + + NUTS_PASS(nng_msg_alloc(&m, 0)); + NUTS_PASS(nng_msg_append_u32(m, 1u)); // 4 hops -- discard! + NUTS_PASS(nng_msg_append_u32(m, 2u)); + NUTS_PASS(nng_msg_append_u32(m, 3u)); + NUTS_PASS(nng_msg_append_u32(m, 0x80000003u)); + NUTS_PASS(nng_msg_append(m, "FAIL4", 6)); + NUTS_PASS(nng_sendmsg(surv, m, 0)); + + NUTS_RECV(resp, "PASS1"); + NUTS_RECV(resp, "PASS3"); + + NUTS_FAIL(nng_recvmsg(resp, &m, 0), NNG_ETIMEDOUT); + + NUTS_CLOSE(resp); + NUTS_CLOSE(surv); } TEST_LIST = { @@ -590,7 +574,8 @@ TEST_LIST = { { "respond close pipe before send", test_resp_close_pipe_before_send }, { "respond close pipe during send", test_resp_close_pipe_during_send }, { "respond recv aio ctx stopped", test_resp_ctx_recv_aio_stopped }, - { "respond close pipe context send", test_resp_close_pipe_context_send }, + { "respond close pipe context send", + test_resp_close_pipe_context_send }, { "respond close context send", test_resp_close_context_send }, { "respond context send nonblock", test_resp_ctx_send_nonblock }, { "respond context recv nonblock", test_resp_ctx_recv_nonblock }, |
