From 6a9bd051c439ef66cf00795b3829ca3ceece0497 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 3 Jan 2021 10:58:38 -0800 Subject: fixes #1401 valgrind reports leaks in all tests This arranges for nng_fini to be called via atexit in the test version of the library. It also cleans up some of the actual tests to reduce extraneous (and in some cases incorrect) calls to nng_fini. --- tests/CMakeLists.txt | 2 +- tests/bus.c | 4 +- tests/compat_testutil.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/device.c | 4 +- tests/httpclient.c | 4 +- tests/httpserver.c | 9 +- tests/inproc.c | 3 +- tests/ipc.c | 3 +- tests/ipcsupp.c | 3 +- tests/ipcwinsec.c | 5 +- tests/multistress.c | 4 +- tests/nonblock.c | 4 +- tests/nuts_compat.c | 229 ------------------------------------------------ tests/pipe.c | 3 +- tests/reqctx.c | 8 +- tests/reqstress.c | 4 +- tests/scalability.c | 15 +--- tests/stats.c | 3 +- tests/tcp.c | 4 +- tests/tcp6.c | 4 +- tests/tcpsupp.c | 3 +- tests/tls.c | 3 +- tests/udp.c | 3 +- tests/ws.c | 4 +- tests/wss.c | 4 +- tests/zt.c | 3 +- 26 files changed, 258 insertions(+), 306 deletions(-) create mode 100644 tests/compat_testutil.c delete mode 100644 tests/nuts_compat.c (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ff9adfa..5fcd4323 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -64,7 +64,7 @@ if (NNG_TESTS) # are present. It's not worth trying to figure out which of these # should work and which shouldn't. macro(add_nng_compat_test NAME TIMEOUT) - add_executable(${NAME} ${NAME}.c nuts_compat.c) + add_executable(${NAME} ${NAME}.c compat_testutil.c) target_link_libraries(${NAME} nng_testing) target_include_directories(${NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/compat diff --git a/tests/bus.c b/tests/bus.c index 96e7ede3..ccd48167 100644 --- a/tests/bus.c +++ b/tests/bus.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Garrett D'Amore +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -24,8 +24,6 @@ TestMain("BUS pattern", { const char *addr = "inproc://test"; - Reset({ nng_fini(); }); - Convey("We can create a BUS socket", { nng_socket bus; diff --git a/tests/compat_testutil.c b/tests/compat_testutil.c new file mode 100644 index 00000000..7db03bf0 --- /dev/null +++ b/tests/compat_testutil.c @@ -0,0 +1,229 @@ +/* + Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + Copyright 2018 Staysail Systems, Inc. + Copyright 2018 Capitar IT Group BV + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +// Note: This file started life in nanomsg. We have copied it, and adjusted +// it for validating the compatibility features of nanomsg. As much as +// possible we want to run tests from the nanomsg test suite unmodified. + +#include +#include +#include +#include + +#include +#include "compat_testutil.h" + +int test_socket_impl(char *file, int line, int family, int protocol); +int test_connect_impl(char *file, int line, int sock, char *address); +int test_bind_impl(char *file, int line, int sock, char *address); +void test_close_impl(char *file, int line, int sock); +void test_send_impl(char *file, int line, int sock, char *data); +void test_recv_impl(char *file, int line, int sock, char *data); +void test_drop_impl(char *file, int line, int sock, int err); +int test_setsockopt_impl(char *file, int line, int sock, int level, int option, + const void *optval, size_t optlen); + +int +test_socket_impl(char *file, int line, int family, int protocol) +{ + int sock; + + sock = nn_socket(family, protocol); + if (sock == -1) { + fprintf(stderr, "Failed create socket: %s [%d] (%s:%d)\n", + nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } + + return (sock); +} + +int +test_connect_impl(char *file, int line, int sock, char *address) +{ + int rc; + + rc = nn_connect(sock, address); + if (rc < 0) { + fprintf(stderr, "Failed connect to \"%s\": %s [%d] (%s:%d)\n", + address, nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } + return (rc); +} + +int +test_bind_impl(char *file, int line, int sock, char *address) +{ + int rc; + + rc = nn_bind(sock, address); + if (rc < 0) { + fprintf(stderr, "Failed bind to \"%s\": %s [%d] (%s:%d)\n", + address, nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } + return (rc); +} + +int +test_setsockopt_impl(char *file, int line, int sock, int level, int option, + const void *optval, size_t optlen) +{ + int rc; + + rc = nn_setsockopt(sock, level, option, optval, optlen); + if (rc < 0) { + fprintf(stderr, "Failed set option \"%d\": %s [%d] (%s:%d)\n", + option, nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } + return rc; +} + +void +test_close_impl(char *file, int line, int sock) +{ + int rc; + + rc = nn_close(sock); + if ((rc != 0) && (errno != EBADF && errno != ETERM)) { + fprintf(stderr, "Failed to close socket: %s [%d] (%s:%d)\n", + nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } +} + +void +test_send_impl(char *file, int line, int sock, char *data) +{ + size_t data_len; + int rc; + + data_len = strlen(data); + + rc = nn_send(sock, data, data_len, 0); + if (rc < 0) { + fprintf(stderr, "Failed to send: %s [%d] (%s:%d)\n", + nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } + if (rc != (int) data_len) { + fprintf(stderr, + "Data to send is truncated: %d != %d (%s:%d)\n", rc, + (int) data_len, file, line); + nn_err_abort(); + } +} + +void +test_recv_impl(char *file, int line, int sock, char *data) +{ + size_t data_len; + int rc; + char * buf; + + data_len = strlen(data); + /* We allocate plus one byte so that we are sure that message received + has correct length and not truncated */ + buf = malloc(data_len + 1); + alloc_assert(buf); + + rc = nn_recv(sock, buf, data_len + 1, 0); + if (rc < 0) { + fprintf(stderr, "Failed to recv: %s [%d] (%s:%d)\n", + nn_err_strerror(errno), (int) errno, file, line); + nn_err_abort(); + } + if (rc != (int) data_len) { + fprintf(stderr, + "Received data has wrong length: %d != %d (%s:%d)\n", rc, + (int) data_len, file, line); + nn_err_abort(); + } + if (memcmp(data, buf, data_len) != 0) { + /* We don't print the data as it may have binary garbage */ + fprintf( + stderr, "Received data is wrong (%s:%d)\n", file, line); + nn_err_abort(); + } + + free(buf); +} + +void +test_drop_impl(char *file, int line, int sock, int err) +{ + int rc; + char buf[1024]; + + rc = nn_recv(sock, buf, sizeof(buf), 0); + if (rc < 0 && err != errno) { + fprintf(stderr, + "Got wrong err to recv: %s [%d != %d] (%s:%d)\n", + nn_err_strerror(errno), (int) errno, err, file, line); + nn_err_abort(); + } else if (rc >= 0) { + fprintf(stderr, "Did not drop message: [%d bytes] (%s:%d)\n", + rc, file, line); + nn_err_abort(); + } +} + +int +get_test_port(int argc, const char *argv[]) +{ + return (atoi(argc < 2 ? "5555" : argv[1])); +} + +void +test_addr_from(char *out, const char *proto, const char *ip, int port) +{ + sprintf(out, "%s://%s:%d", proto, ip, port); +} + +extern int nng_thread_create(void **, void (*)(void *), void *); + +int +nn_thread_init(struct nn_thread *thr, void (*func)(void *), void *arg) +{ + return (nng_thread_create(&thr->thr, func, arg)); +} + +extern void nng_thread_destroy(void *); + +void +nn_thread_term(struct nn_thread *thr) +{ + nng_thread_destroy(thr->thr); +} + +extern void nng_msleep(int32_t); + +void +nn_sleep(int ms) +{ + nng_msleep(ms); +} diff --git a/tests/device.c b/tests/device.c index 0ff784cc..7d10cbf1 100644 --- a/tests/device.c +++ b/tests/device.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -106,6 +106,4 @@ Main({ }); }); }); - - nng_fini(); }) diff --git a/tests/httpclient.c b/tests/httpclient.c index 29239ddb..e153a987 100644 --- a/tests/httpclient.c +++ b/tests/httpclient.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -35,8 +35,6 @@ const uint8_t chunked_sum[20] = { 0x9b, 0x06, 0xfb, 0xee, 0x51, 0xc6, 0x42, 0x68 }; TestMain("HTTP Client", { - atexit(nng_fini); - Convey("Given a TCP connection to example.com", { nng_aio * aio; nng_http_client *cli; diff --git a/tests/httpserver.c b/tests/httpserver.c index a509638e..445aad0e 100644 --- a/tests/httpserver.c +++ b/tests/httpserver.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2020 Dirac Research // @@ -30,12 +30,6 @@ const char *doc2 = "This is a text file."; const char *doc3 = "This is doc number 3."; const char *doc4 = "Whoops, Errored!"; -void -cleanup(void) -{ - nng_fini(); -} - static int httpdo(nng_url *url, nng_http_req *req, nng_http_res *res, void **datap, size_t *sizep) @@ -190,7 +184,6 @@ TestMain("HTTP Server", { nng_http_handler *h; nni_init(); - atexit(cleanup); Convey("We can start an HTTP server", { nng_aio *aio; diff --git a/tests/inproc.c b/tests/inproc.c index 3a3a2b60..11a6f118 100644 --- a/tests/inproc.c +++ b/tests/inproc.c @@ -1,5 +1,5 @@ // -// Copyright 2017 Garrett D'Amore +// Copyright 2021 Staysail Systems, Inc. // Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -17,5 +17,4 @@ TestMain("Inproc Transport", { trantest_test_all("inproc://TEST_%u"); - nng_fini(); }) diff --git a/tests/ipc.c b/tests/ipc.c index 590b10df..d910e0af 100644 --- a/tests/ipc.c +++ b/tests/ipc.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -85,5 +85,4 @@ check_props(nng_msg *msg) TestMain("IPC Transport", { trantest_test_extended("ipc:///tmp/nng_ipc_test_%u", check_props); - nng_fini(); }) diff --git a/tests/ipcsupp.c b/tests/ipcsupp.c index d5128098..bd751885 100644 --- a/tests/ipcsupp.c +++ b/tests/ipcsupp.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -19,7 +19,6 @@ static int num = 0; TestMain("Supplemental IPC", { - atexit(nng_fini); Convey("We can create a dialer and listener", { nng_stream_dialer * d; nng_stream_listener *l; diff --git a/tests/ipcwinsec.c b/tests/ipcwinsec.c index d6b28c1b..533dfe37 100644 --- a/tests/ipcwinsec.c +++ b/tests/ipcwinsec.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -23,7 +23,6 @@ #ifndef _WIN32 TestMain("IPC Security Descriptor", { - atexit(nng_fini); Convey("Given a socket and an IPC listener", { nng_socket s; nng_listener l; @@ -80,8 +79,6 @@ sdescAuthUsers(PSID sid, PACL *aclp) } TestMain("IPC Security Descriptor", { - atexit(nng_fini); - Convey("Given a socket and an IPC listener", { nng_socket s; nng_listener l; diff --git a/tests/multistress.c b/tests/multistress.c index 9264e6bc..fee40503 100644 --- a/tests/multistress.c +++ b/tests/multistress.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -770,8 +770,6 @@ Main({ char *str; int tmo; - atexit(nng_fini); - // Each run should truly be random. srand((int) time(NULL)); diff --git a/tests/nonblock.c b/tests/nonblock.c index c8cce901..3ad22889 100644 --- a/tests/nonblock.c +++ b/tests/nonblock.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -94,8 +94,6 @@ nng_socket reqs[NCLIENTS]; nng_socket rep; TestMain("Nonblocking Works", { - atexit(nng_fini); - Convey("Running for 15 sec", { nng_thread *server; nng_thread *clients[NCLIENTS]; diff --git a/tests/nuts_compat.c b/tests/nuts_compat.c deleted file mode 100644 index 7db03bf0..00000000 --- a/tests/nuts_compat.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. - Copyright 2016 Franklin "Snaipe" Mathieu - Copyright 2018 Staysail Systems, Inc. - Copyright 2018 Capitar IT Group BV - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom - the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Note: This file started life in nanomsg. We have copied it, and adjusted -// it for validating the compatibility features of nanomsg. As much as -// possible we want to run tests from the nanomsg test suite unmodified. - -#include -#include -#include -#include - -#include -#include "compat_testutil.h" - -int test_socket_impl(char *file, int line, int family, int protocol); -int test_connect_impl(char *file, int line, int sock, char *address); -int test_bind_impl(char *file, int line, int sock, char *address); -void test_close_impl(char *file, int line, int sock); -void test_send_impl(char *file, int line, int sock, char *data); -void test_recv_impl(char *file, int line, int sock, char *data); -void test_drop_impl(char *file, int line, int sock, int err); -int test_setsockopt_impl(char *file, int line, int sock, int level, int option, - const void *optval, size_t optlen); - -int -test_socket_impl(char *file, int line, int family, int protocol) -{ - int sock; - - sock = nn_socket(family, protocol); - if (sock == -1) { - fprintf(stderr, "Failed create socket: %s [%d] (%s:%d)\n", - nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } - - return (sock); -} - -int -test_connect_impl(char *file, int line, int sock, char *address) -{ - int rc; - - rc = nn_connect(sock, address); - if (rc < 0) { - fprintf(stderr, "Failed connect to \"%s\": %s [%d] (%s:%d)\n", - address, nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } - return (rc); -} - -int -test_bind_impl(char *file, int line, int sock, char *address) -{ - int rc; - - rc = nn_bind(sock, address); - if (rc < 0) { - fprintf(stderr, "Failed bind to \"%s\": %s [%d] (%s:%d)\n", - address, nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } - return (rc); -} - -int -test_setsockopt_impl(char *file, int line, int sock, int level, int option, - const void *optval, size_t optlen) -{ - int rc; - - rc = nn_setsockopt(sock, level, option, optval, optlen); - if (rc < 0) { - fprintf(stderr, "Failed set option \"%d\": %s [%d] (%s:%d)\n", - option, nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } - return rc; -} - -void -test_close_impl(char *file, int line, int sock) -{ - int rc; - - rc = nn_close(sock); - if ((rc != 0) && (errno != EBADF && errno != ETERM)) { - fprintf(stderr, "Failed to close socket: %s [%d] (%s:%d)\n", - nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } -} - -void -test_send_impl(char *file, int line, int sock, char *data) -{ - size_t data_len; - int rc; - - data_len = strlen(data); - - rc = nn_send(sock, data, data_len, 0); - if (rc < 0) { - fprintf(stderr, "Failed to send: %s [%d] (%s:%d)\n", - nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } - if (rc != (int) data_len) { - fprintf(stderr, - "Data to send is truncated: %d != %d (%s:%d)\n", rc, - (int) data_len, file, line); - nn_err_abort(); - } -} - -void -test_recv_impl(char *file, int line, int sock, char *data) -{ - size_t data_len; - int rc; - char * buf; - - data_len = strlen(data); - /* We allocate plus one byte so that we are sure that message received - has correct length and not truncated */ - buf = malloc(data_len + 1); - alloc_assert(buf); - - rc = nn_recv(sock, buf, data_len + 1, 0); - if (rc < 0) { - fprintf(stderr, "Failed to recv: %s [%d] (%s:%d)\n", - nn_err_strerror(errno), (int) errno, file, line); - nn_err_abort(); - } - if (rc != (int) data_len) { - fprintf(stderr, - "Received data has wrong length: %d != %d (%s:%d)\n", rc, - (int) data_len, file, line); - nn_err_abort(); - } - if (memcmp(data, buf, data_len) != 0) { - /* We don't print the data as it may have binary garbage */ - fprintf( - stderr, "Received data is wrong (%s:%d)\n", file, line); - nn_err_abort(); - } - - free(buf); -} - -void -test_drop_impl(char *file, int line, int sock, int err) -{ - int rc; - char buf[1024]; - - rc = nn_recv(sock, buf, sizeof(buf), 0); - if (rc < 0 && err != errno) { - fprintf(stderr, - "Got wrong err to recv: %s [%d != %d] (%s:%d)\n", - nn_err_strerror(errno), (int) errno, err, file, line); - nn_err_abort(); - } else if (rc >= 0) { - fprintf(stderr, "Did not drop message: [%d bytes] (%s:%d)\n", - rc, file, line); - nn_err_abort(); - } -} - -int -get_test_port(int argc, const char *argv[]) -{ - return (atoi(argc < 2 ? "5555" : argv[1])); -} - -void -test_addr_from(char *out, const char *proto, const char *ip, int port) -{ - sprintf(out, "%s://%s:%d", proto, ip, port); -} - -extern int nng_thread_create(void **, void (*)(void *), void *); - -int -nn_thread_init(struct nn_thread *thr, void (*func)(void *), void *arg) -{ - return (nng_thread_create(&thr->thr, func, arg)); -} - -extern void nng_thread_destroy(void *); - -void -nn_thread_term(struct nn_thread *thr) -{ - nng_thread_destroy(thr->thr); -} - -extern void nng_msleep(int32_t); - -void -nn_sleep(int ms) -{ - nng_msleep(ms); -} diff --git a/tests/pipe.c b/tests/pipe.c index 71e9be67..617337b0 100644 --- a/tests/pipe.c +++ b/tests/pipe.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -114,7 +114,6 @@ char addr[64]; static int cnt; TestMain("Pipe notify works", { - atexit(nng_fini); Convey("We can create a pipeline", { struct testcase push; diff --git a/tests/reqctx.c b/tests/reqctx.c index e937b995..c727b91c 100644 --- a/tests/reqctx.c +++ b/tests/reqctx.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -28,10 +28,10 @@ static struct { } rep_state; void -rep_cb(void *notused) +rep_cb(void *unused) { int rv; - (void) notused; + (void) unused; nng_mtx_lock(rep_state.mtx); if (rep_state.state == START) { @@ -96,8 +96,6 @@ TestMain("REQ concurrent contexts", { memset(recv_order, 0, NCTX * sizeof(int)); - atexit(nng_fini); - Convey("We can use REQ contexts concurrently", { nng_socket req; diff --git a/tests/reqstress.c b/tests/reqstress.c index 481e4e92..18eac37a 100644 --- a/tests/reqstress.c +++ b/tests/reqstress.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -270,8 +270,6 @@ Main({ int tmo; char *str; - atexit(nng_fini); - if (((str = ConveyGetEnv("STRESSTIME")) == NULL) || ((tmo = atoi(str)) < 1)) { tmo = 30; diff --git a/tests/scalability.c b/tests/scalability.c index 1cbbd961..0cff2243 100644 --- a/tests/scalability.c +++ b/tests/scalability.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -43,14 +43,6 @@ serve(void *arg) nng_close(rep); } -void -stop(void) -{ - nng_closeall(); - nng_thread_destroy(server); - nng_fini(); -} - int openclients(nng_socket *clients, int num) { @@ -97,8 +89,6 @@ Main({ nng_socket *clients; int * results; - atexit(stop); - clients = calloc(nclients, sizeof(nng_socket)); results = calloc(nclients, sizeof(int)); @@ -122,6 +112,9 @@ Main({ }); }); + nng_close(rep); + nng_thread_destroy(server); + free(clients); free(results); }) diff --git a/tests/stats.c b/tests/stats.c index 68a5ab62..fb731275 100644 --- a/tests/stats.c +++ b/tests/stats.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -22,7 +22,6 @@ #define SECONDS(x) ((x) *1000) TestMain("Stats Test", { - atexit(nng_fini); Convey("We are able to open a PAIR socket", { nng_socket s1; diff --git a/tests/tcp.c b/tests/tcp.c index eecc148a..afc92f19 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -62,6 +62,4 @@ check_props_v4(nng_msg *msg) TestMain("TCP Transport", { trantest_test_extended("tcp://127.0.0.1:%u", check_props_v4); - - nng_fini(); }) diff --git a/tests/tcp6.c b/tests/tcp6.c index 9b3b0d4b..ecc55a46 100644 --- a/tests/tcp6.c +++ b/tests/tcp6.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -92,6 +92,4 @@ TestMain("TCP (IPv6) Transport", { So(nng_dial(s1, "tcp://::1:5055", NULL, 0) == NNG_EADDRINVAL); So(nng_dial(s1, "tcp://[::1]", NULL, 0) == NNG_EADDRINVAL); }); - - nng_fini(); }) diff --git a/tests/tcpsupp.c b/tests/tcpsupp.c index 39558f58..9117c15b 100644 --- a/tests/tcpsupp.c +++ b/tests/tcpsupp.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -16,7 +16,6 @@ #include "stubs.h" TestMain("Supplemental TCP", { - atexit(nng_fini); Convey("We can create a dialer and listener", { nng_stream_dialer * d = NULL; nng_stream_listener *l = NULL; diff --git a/tests/tls.c b/tests/tls.c index 59525089..c6d5da6e 100644 --- a/tests/tls.c +++ b/tests/tls.c @@ -1,6 +1,6 @@ // // Copyright 2018 Capitar IT Group BV -// Copyright 2020 Staysail Systems, Inc. +// 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 @@ -266,7 +266,6 @@ TestMain("TLS Transport", { tt.listener_init = init_listener_tls; tt.tmpl = "tls+tcp://127.0.0.1:%u"; tt.proptest = check_props_v4; - atexit(nng_fini); trantest_test(&tt); diff --git a/tests/udp.c b/tests/udp.c index af7b2807..c2772048 100644 --- a/tests/udp.c +++ b/tests/udp.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -20,7 +20,6 @@ TestMain("UDP support", { nni_init(); - atexit(nng_fini); trantest_port = trantest_port ? trantest_port : 5555; diff --git a/tests/ws.c b/tests/ws.c index 70d2e8da..548521bd 100644 --- a/tests/ws.c +++ b/tests/ws.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -83,6 +83,4 @@ check_props_v4(nng_msg *msg) TestMain("WebSocket Transport", { trantest_test_extended("ws://127.0.0.1:%u/test", check_props_v4); - - nng_fini(); }) diff --git a/tests/wss.c b/tests/wss.c index ca33a542..0f570b81 100644 --- a/tests/wss.c +++ b/tests/wss.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -245,6 +245,4 @@ TestMain("WebSocket Secure (TLS) Transport", { tt.proptest = check_props; trantest_test(&tt); - - nng_fini(); }) diff --git a/tests/zt.c b/tests/zt.c index 186586c2..091fa841 100644 --- a/tests/zt.c +++ b/tests/zt.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -130,7 +130,6 @@ TestMain("ZeroTier Transport", { unsigned port; port = 5555; - atexit(nng_fini); Convey("We can register the zero tier transport", { So(nng_zt_register() == 0); }); -- cgit v1.2.3-70-g09d2