summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-01-25 23:16:45 -0800
committerGarrett D'Amore <garrett@damore.org>2024-01-25 23:16:45 -0800
commita894c226c7392ebd0c18fe4774ec8a6e4bd61b42 (patch)
tree5f5cf5c8090f4d363bcac0470b8382e3659929ba /tests
parentec4b5722fba105e3b944e3dc0f6b63c941748b3f (diff)
downloadnng-a894c226c7392ebd0c18fe4774ec8a6e4bd61b42.tar.gz
nng-a894c226c7392ebd0c18fe4774ec8a6e4bd61b42.tar.bz2
nng-a894c226c7392ebd0c18fe4774ec8a6e4bd61b42.zip
tests: assert in compat tests even in release mode
Diffstat (limited to 'tests')
-rw-r--r--tests/compat_testutil.c19
-rw-r--r--tests/compat_testutil.h25
2 files changed, 29 insertions, 15 deletions
diff --git a/tests/compat_testutil.c b/tests/compat_testutil.c
index 1656c852..aff8f02d 100644
--- a/tests/compat_testutil.c
+++ b/tests/compat_testutil.c
@@ -2,7 +2,7 @@
Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved.
Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
Copyright 2018 Capitar IT Group BV <info@capitar.com>
- Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
+ Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -27,13 +27,13 @@
// it for validating the compatibility features of nanomsg. As much as
// possible we want to run tests from the nanomsg test suite unmodified.
-#include <assert.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <nng/compat/nanomsg/nn.h>
#include "compat_testutil.h"
+#include <nng/compat/nanomsg/nn.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);
@@ -143,7 +143,7 @@ test_recv_impl(char *file, int line, int sock, char *data)
{
size_t data_len;
int rc;
- char * buf;
+ char *buf;
data_len = strlen(data);
/* We allocate plus one byte so that we are sure that message received
@@ -227,3 +227,14 @@ nn_sleep(int ms)
{
nng_msleep(ms);
}
+
+void
+nn_assert_impl(bool b, const char *expression, const char *file, int line)
+{
+ if (b) {
+ return;
+ }
+ fprintf(
+ stderr, "%s:%d: Assertion failed: %s\n", file, line, expression);
+ abort();
+}
diff --git a/tests/compat_testutil.h b/tests/compat_testutil.h
index cac8d5a2..da9baaa9 100644
--- a/tests/compat_testutil.h
+++ b/tests/compat_testutil.h
@@ -3,7 +3,7 @@
Copyright 2017 Garrett D'Amore <garrett@damore.org>
Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
Copyright 2018 Capitar IT Group BV <info@capitar.com>
- Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+ Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -31,17 +31,16 @@
#ifndef COMPAT_TESTUTIL_H_INCLUDED
#define COMPAT_TESTUTIL_H_INCLUDED
-#include <assert.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define nn_err_strerror nn_strerror
#define nn_err_abort abort
-#define nn_assert assert
-#define errno_assert assert
-#define wsa_assert assert
-#define alloc_assert(x) assert((x) != NULL)
+#define errno_assert nn_assert
+#define wsa_assert nn_assert
+#define alloc_assert(x) nn_assert((x) != NULL)
#if defined __GNUC__ || defined __llvm__ || defined __clang__
#define NN_UNUSED __attribute__((unused))
@@ -49,6 +48,8 @@
#define NN_UNUSED
#endif
+#define nn_assert(x) nn_assert_impl(x, #x, __FILE__, __LINE__)
+
extern int test_socket_impl(char *file, int line, int family, int protocol);
extern int test_connect_impl(char *file, int line, int sock, char *address);
extern int test_bind_impl(char *file, int line, int sock, char *address);
@@ -57,11 +58,13 @@ extern void test_send_impl(char *file, int line, int sock, char *data);
extern void test_recv_impl(char *file, int line, int sock, char *data);
extern void test_drop_impl(char *file, int line, int sock, int err);
extern int test_setsockopt_impl(char *file, int line, int sock, int level,
- int option, const void *optval, size_t optlen);
-extern int get_test_port(int argc, const char *argv[]);
-extern void test_addr_from(char *out, const char *proto, const char *ip,
- int port);
+ int option, const void *optval, size_t optlen);
+extern int get_test_port(int argc, const char *argv[]);
+extern void test_addr_from(
+ char *out, const char *proto, const char *ip, int port);
extern void nn_sleep(int);
+extern void nn_assert_impl(
+ bool b, const char *expression, const char *file, int line);
#define test_socket(f, p) test_socket_impl(__FILE__, __LINE__, (f), (p))
#define test_connect(s, a) test_connect_impl(__FILE__, __LINE__, (s), (a))
@@ -77,7 +80,7 @@ struct nn_thread {
void *thr;
};
-extern int nn_thread_init(struct nn_thread *, void (*)(void *), void *);
+extern int nn_thread_init(struct nn_thread *, void (*)(void *), void *);
extern void nn_thread_term(struct nn_thread *);
#endif // COMPAT_TESTUTIL_H_INCLUDED