From 9c6ac231b8b7d0c597a4010135edb14b8513e3f6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 3 Jan 2021 10:35:06 -0800 Subject: fixes #1398 integrate new acutest.h (#1400) --- src/compat/nanomsg/compat_tcp_test.c | 98 ++++++++++++++++++------------------ src/compat/nanomsg/compat_testutil.h | 74 --------------------------- src/compat/nanomsg/nuts_compat.h | 73 +++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 123 deletions(-) delete mode 100644 src/compat/nanomsg/compat_testutil.h create mode 100644 src/compat/nanomsg/nuts_compat.h (limited to 'src/compat') diff --git a/src/compat/nanomsg/compat_tcp_test.c b/src/compat/nanomsg/compat_tcp_test.c index ae4193b7..d090463f 100644 --- a/src/compat/nanomsg/compat_tcp_test.c +++ b/src/compat/nanomsg/compat_tcp_test.c @@ -30,7 +30,7 @@ #include #include -#include "compat_testutil.h" +#include "nuts_compat.h" #include @@ -54,9 +54,9 @@ test_connect_and_close(void) char *addr; NUTS_ADDR(addr, "tcp"); - TEST_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR)) >= 0); - TEST_NN_PASS(nn_connect(sc, addr)); - TEST_NN_PASS(nn_close(sc)); + NUTS_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR)) >= 0); + NUTS_NN_PASS(nn_connect(sc, addr)); + NUTS_NN_PASS(nn_close(sc)); } void @@ -70,10 +70,10 @@ test_bind_and_connect(void) NUTS_TRUE((sc = nn_socket(AF_SP, NN_PAIR)) >= 0); NUTS_TRUE(sb != sc); - TEST_NN_MARRY_EX(sb, sc, addr, p1, p2); + NUTS_NN_MARRY_EX(sb, sc, addr, p1, p2); - TEST_NN_PASS(nn_close(sb)); - TEST_NN_PASS(nn_close(sc)); + NUTS_NN_PASS(nn_close(sb)); + NUTS_NN_PASS(nn_close(sc)); } void @@ -82,15 +82,15 @@ test_bad_addresses(void) int s; NUTS_TRUE((s = nn_socket(AF_SP, NN_PAIR)) >= 0); - TEST_NN_FAIL(nn_connect(s, "tcp://*:"), EINVAL); - TEST_NN_FAIL(nn_connect(s, "tcp://*:1000000"), EINVAL); - TEST_NN_FAIL(nn_connect(s, "tcp://*:some_port"), EINVAL); - TEST_NN_FAIL(nn_connect(s, "tcp://127.0.0.1"), EINVAL); - TEST_NN_FAIL(nn_connect(s, "tcp://:5555"), EINVAL); - TEST_NN_FAIL(nn_connect(s, "tcp://abc.123.---.#:5555"), EINVAL); + NUTS_NN_FAIL(nn_connect(s, "tcp://*:"), EINVAL); + NUTS_NN_FAIL(nn_connect(s, "tcp://*:1000000"), EINVAL); + NUTS_NN_FAIL(nn_connect(s, "tcp://*:some_port"), EINVAL); + NUTS_NN_FAIL(nn_connect(s, "tcp://127.0.0.1"), EINVAL); + NUTS_NN_FAIL(nn_connect(s, "tcp://:5555"), EINVAL); + NUTS_NN_FAIL(nn_connect(s, "tcp://abc.123.---.#:5555"), EINVAL); - TEST_NN_FAIL(nn_bind(s, "tcp://127.0.0.1:1000000"), EINVAL); - TEST_NN_PASS(nn_close(s)); + NUTS_NN_FAIL(nn_bind(s, "tcp://127.0.0.1:1000000"), EINVAL); + NUTS_NN_PASS(nn_close(s)); } void @@ -102,21 +102,21 @@ test_no_delay(void) NUTS_TRUE((s = nn_socket(AF_SP, NN_PAIR)) >= 0); sz = sizeof(opt); - TEST_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz)); + NUTS_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz)); NUTS_TRUE(sz == sizeof(opt)); NUTS_TRUE(opt == 0); opt = 2; - TEST_NN_FAIL( + NUTS_NN_FAIL( nn_setsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, sz), EINVAL); opt = 1; - TEST_NN_PASS(nn_setsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, sz)); + NUTS_NN_PASS(nn_setsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, sz)); opt = 3; - TEST_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz)); + NUTS_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz)); NUTS_TRUE(sz == sizeof(opt)); NUTS_TRUE(opt == 1); - TEST_NN_PASS(nn_close(s)); + NUTS_NN_PASS(nn_close(s)); } void @@ -126,10 +126,10 @@ test_ping_pong(void) char *addr; NUTS_ADDR(addr, "tcp"); - TEST_NN_PASS((sb = nn_socket(AF_SP, NN_PAIR))); - TEST_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR))); + NUTS_NN_PASS((sb = nn_socket(AF_SP, NN_PAIR))); + NUTS_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR))); NUTS_TRUE(sb != sc); - TEST_NN_MARRY_EX(sc, sb, addr, p1, p2); + NUTS_NN_MARRY_EX(sc, sb, addr, p1, p2); NUTS_TRUE(p1 >= 0); NUTS_TRUE(p2 >= 0); @@ -138,19 +138,19 @@ test_ping_pong(void) char buf[4]; int n; - TEST_NN_PASS(nn_send(sc, "ABC", 3, 0)); - TEST_NN_PASS(n = nn_recv(sb, buf, 4, 0)); + NUTS_NN_PASS(nn_send(sc, "ABC", 3, 0)); + NUTS_NN_PASS(n = nn_recv(sb, buf, 4, 0)); NUTS_TRUE(n == 3); NUTS_TRUE(memcmp(buf, "ABC", 3) == 0); - TEST_NN_PASS(nn_send(sb, "DEF", 3, 0)); - TEST_NN_PASS(n = nn_recv(sc, buf, 4, 0)); + NUTS_NN_PASS(nn_send(sb, "DEF", 3, 0)); + NUTS_NN_PASS(n = nn_recv(sc, buf, 4, 0)); NUTS_TRUE(n == 3); NUTS_TRUE(memcmp(buf, "DEF", 3) == 0); } - TEST_NN_PASS(nn_close(sb)); - TEST_NN_PASS(nn_close(sc)); + NUTS_NN_PASS(nn_close(sb)); + NUTS_NN_PASS(nn_close(sc)); } void @@ -166,14 +166,14 @@ test_pair_reject(void) NUTS_TRUE((sd = nn_socket(AF_SP, NN_PAIR)) >= 0); NUTS_TRUE(sb != sc); - TEST_NN_MARRY_EX(sc, sb, addr, p1, p2); + NUTS_NN_MARRY_EX(sc, sb, addr, p1, p2); NUTS_TRUE(nn_connect(sd, addr) >= 0); NUTS_SLEEP(200); - TEST_NN_PASS(nn_close(sb)); - TEST_NN_PASS(nn_close(sc)); - TEST_NN_PASS(nn_close(sd)); + NUTS_NN_PASS(nn_close(sb)); + NUTS_NN_PASS(nn_close(sc)); + NUTS_NN_PASS(nn_close(sd)); } void @@ -186,11 +186,11 @@ test_addr_in_use(void) NUTS_TRUE((sb = nn_socket(AF_SP, NN_PAIR)) >= 0); NUTS_TRUE((sc = nn_socket(AF_SP, NN_PAIR)) >= 0); NUTS_TRUE(sb != sc); - TEST_NN_PASS(nn_bind(sb, addr)); - TEST_NN_FAIL(nn_bind(sc, addr), EADDRINUSE); + NUTS_NN_PASS(nn_bind(sb, addr)); + NUTS_NN_FAIL(nn_bind(sc, addr), EADDRINUSE); - TEST_NN_PASS(nn_close(sb)); - TEST_NN_PASS(nn_close(sc)); + NUTS_NN_PASS(nn_close(sb)); + NUTS_NN_PASS(nn_close(sc)); } void @@ -210,40 +210,40 @@ test_max_recv_size(void) NUTS_TRUE(sb != sc); opt = 100; sz = sizeof(opt); - TEST_NN_PASS(nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sz)); + NUTS_NN_PASS(nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sz)); /* Test that NN_RCVMAXSIZE can be -1, but not lower */ sz = sizeof(opt); opt = -1; - TEST_NN_PASS( + NUTS_NN_PASS( nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sz)); opt = -2; - TEST_NN_FAIL( + NUTS_NN_FAIL( nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sz), EINVAL); opt = 4; - TEST_NN_PASS( + NUTS_NN_PASS( nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sz)); opt = -5; - TEST_NN_PASS( + NUTS_NN_PASS( nn_getsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, &sz)); NUTS_TRUE(opt == 4); NUTS_TRUE(sz == sizeof(opt)); - TEST_NN_MARRY_EX(sc, sb, addr, p1, p2); + NUTS_NN_MARRY_EX(sc, sb, addr, p1, p2); - TEST_NN_PASS(nn_send(sc, "ABC", 4, 0)); - TEST_NN_PASS(nn_send(sc, "012345", 6, 0)); + NUTS_NN_PASS(nn_send(sc, "ABC", 4, 0)); + NUTS_NN_PASS(nn_send(sc, "012345", 6, 0)); - TEST_NN_PASS(n = nn_recv(sb, buf, sizeof(buf), 0)); + NUTS_NN_PASS(n = nn_recv(sb, buf, sizeof(buf), 0)); NUTS_TRUE(n == 4); NUTS_TRUE(strcmp(buf, "ABC") == 0); - TEST_NN_FAIL(nn_recv(sb, buf, sizeof(buf), 0), ETIMEDOUT); + NUTS_NN_FAIL(nn_recv(sb, buf, sizeof(buf), 0), ETIMEDOUT); - TEST_NN_PASS(nn_close(sb)); - TEST_NN_PASS(nn_close(sc)); + NUTS_NN_PASS(nn_close(sb)); + NUTS_NN_PASS(nn_close(sc)); } TEST_LIST = { diff --git a/src/compat/nanomsg/compat_testutil.h b/src/compat/nanomsg/compat_testutil.h deleted file mode 100644 index e0612adb..00000000 --- a/src/compat/nanomsg/compat_testutil.h +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright 2020 Staysail Systems, Inc. -// -// This software is supplied under the terms of the MIT License, a -// copy of which should be located in the distribution where this -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef COMPAT_TESTUTIL_H -#define COMPAT_TESTUTIL_H - -#include -#include - -// The following headers are provided for test code convenience. -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// TEST_NNG_PASS tests for NNG success. It reports the failure if it -// did not. -#define TEST_NN_PASS(cond) \ - do { \ - int result_ = (cond); \ - TEST_CHECK_(result_ >= 0, "%s succeeds", #cond); \ - TEST_MSG("%s: expected success, got %s (%d)", #cond, \ - nn_strerror(errno), errno); \ - } while (0) - -#define TEST_NN_FAIL(cond, expect) \ - do { \ - int result_ = (cond); \ - int err_ = errno; \ - TEST_CHECK_(result_ < 0, "%s did not succeed", #cond); \ - TEST_CHECK_( \ - err_ = expect, "%s fails with %s", #cond, #expect); \ - TEST_MSG("%s: expected %s, got %s (%d)", #cond, #expect, \ - expect, nng_strerror(err_), result_); \ - } while (0) - -// These macros use some details of the socket and pipe which are not public. -// We do that to facilitate testing. Don't rely on this equivalence in your -// own application code. - -#define TEST_NN_MARRY(s1, s2) \ - do { \ - nng_socket s1_, s2_; \ - s1_.id = s1; \ - s2_.id = s2; \ - \ - NUTS_MARRY(s1_, s2_); \ - } while (0) - -#define TEST_NN_MARRY_EX(s1, s2, url, p1, p2) \ - do { \ - nng_socket s1_, s2_; \ - nng_pipe p1_, p2_; \ - s1_.id = s1; \ - s2_.id = s2; \ - NUTS_MARRY_EX(s1_, s2_, url, &p1_, &p2_); \ - p1 = p1_.id; \ - p2 = p2_.id; \ - NUTS_TRUE(p1 >= 0); \ - NUTS_TRUE(p2 >= 0); \ - } while (0) - -#ifdef __cplusplus -}; -#endif - -#endif // COMPAT_TESTUTIL_H diff --git a/src/compat/nanomsg/nuts_compat.h b/src/compat/nanomsg/nuts_compat.h new file mode 100644 index 00000000..d7bd56e7 --- /dev/null +++ b/src/compat/nanomsg/nuts_compat.h @@ -0,0 +1,73 @@ +// +// Copyright 2021 Staysail Systems, Inc. +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#ifndef NUTS_COMPAT_H +#define NUTS_COMPAT_H + +#include +#include + +// The following headers are provided for test code convenience. +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// NUTS_NN_PASS tests for NN success. It reports the failure if it did not. +#define NUTS_NN_PASS(cond) \ + do { \ + int result_ = (cond); \ + TEST_CHECK_(result_ >= 0, "%s succeeds", #cond); \ + TEST_MSG("%s: expected success, got %s (%d)", #cond, \ + nn_strerror(errno), errno); \ + } while (0) + +#define NUTS_NN_FAIL(cond, expect) \ + do { \ + int result_ = (cond); \ + int err_ = errno; \ + TEST_CHECK_(result_ < 0, "%s did not succeed", #cond); \ + TEST_CHECK_( \ + err_ == (expect), "%s fails with %s", #cond, #expect); \ + TEST_MSG("%s: expected %s, got %d / %d (%s)", #cond, #expect, \ + result_, (expect), nng_strerror(err_)); \ + } while (0) + +// These macros use some details of the socket and pipe which are not public. +// We do that to facilitate testing. Don't rely on this equivalence in your +// own application code. + +#define NUTS_NN_MARRY(s1, s2) \ + do { \ + nng_socket s1_, s2_; \ + s1_.id = s1; \ + s2_.id = s2; \ + \ + NUTS_MARRY(s1_, s2_); \ + } while (0) + +#define NUTS_NN_MARRY_EX(s1, s2, url, p1, p2) \ + do { \ + nng_socket s1_, s2_; \ + nng_pipe p1_, p2_; \ + s1_.id = s1; \ + s2_.id = s2; \ + NUTS_MARRY_EX(s1_, s2_, url, &p1_, &p2_); \ + (p1) = p1_.id; \ + (p2) = p2_.id; \ + NUTS_TRUE((p1) >= 0); \ + NUTS_TRUE((p2) >= 0); \ + } while (0) + +#ifdef __cplusplus +}; +#endif + +#endif // NUTS_COMPAT -- cgit v1.2.3-70-g09d2