forked from nanomsg/nng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: assert in compat tests even in release mode
- Loading branch information
Showing
2 changed files
with
29 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. | ||
Copyright 2016 Franklin "Snaipe" Mathieu <[email protected]> | ||
Copyright 2018 Capitar IT Group BV <[email protected]> | ||
Copyright 2022 Staysail Systems, Inc. <[email protected]> | ||
Copyright 2024 Staysail Systems, Inc. <[email protected]> | ||
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
Copyright 2017 Garrett D'Amore <[email protected]> | ||
Copyright 2016 Franklin "Snaipe" Mathieu <[email protected]> | ||
Copyright 2018 Capitar IT Group BV <[email protected]> | ||
Copyright 2021 Staysail Systems, Inc. <[email protected]> | ||
Copyright 2024 Staysail Systems, Inc. <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
|
@@ -31,24 +31,25 @@ | |
#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)) | ||
#else | ||
#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 |