summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/backlog.cpp45
-rw-r--r--tests/emptyctx.cpp4
-rw-r--r--tests/invalid_rep.cpp38
-rw-r--r--tests/libzmq21.cpp52
-rw-r--r--tests/linger.cpp14
-rw-r--r--tests/max_sockets.cpp12
-rw-r--r--tests/msg_flags.cpp34
-rw-r--r--tests/pair_inproc.cpp16
-rw-r--r--tests/pair_ipc.cpp16
-rw-r--r--tests/pair_tcp.cpp22
-rw-r--r--tests/polltimeo.cpp20
-rw-r--r--tests/reconnect.cpp36
-rw-r--r--tests/reqrep_device.cpp68
-rw-r--r--tests/reqrep_inproc.cpp16
-rw-r--r--tests/reqrep_ipc.cpp16
-rw-r--r--tests/reqrep_tcp.cpp16
-rw-r--r--tests/resubscribe.cpp34
-rw-r--r--tests/shutdown.cpp44
-rw-r--r--tests/shutdown_stress.cpp18
-rw-r--r--tests/sub_forward.cpp42
-rw-r--r--tests/survey.cpp118
-rw-r--r--tests/testutil.hpp47
-rw-r--r--tests/wireformat.cpp34
23 files changed, 392 insertions, 370 deletions
diff --git a/tests/backlog.cpp b/tests/backlog.cpp
index f215ec5..629503c 100644
--- a/tests/backlog.cpp
+++ b/tests/backlog.cpp
@@ -35,13 +35,13 @@ extern "C"
void *push;
push = xs_socket (ctx_, XS_PUSH);
- assert (push);
+ errno_assert (push);
rc = xs_connect (push, "ipc:///tmp/test-backlog");
- assert (rc >= 0);
+ errno_assert (rc >= 0);
rc = xs_send (push, NULL, 0, 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
#endif
static void tcp_worker (void *ctx_)
@@ -50,14 +50,14 @@ extern "C"
void *push;
push = xs_socket (ctx_, XS_PUSH);
- assert (push);
+ errno_assert (push);
rc = xs_connect (push, "tcp://127.0.0.1:5560");
- assert (rc >= 0);
+ errno_assert (rc >= 0);
rc = xs_send (push, NULL, 0, 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
}
#endif
@@ -77,29 +77,28 @@ int XS_TEST_MAIN ()
// Test the exhaustion on IPC backlog.
#if !defined XS_HAVE_WINDOWS && !defined XS_HAVE_OPENVMS
ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
pull = xs_socket (ctx, XS_PULL);
- assert (pull);
+ errno_assert (pull);
backlog = BACKLOG;
rc = xs_setsockopt (pull, XS_BACKLOG, &backlog, sizeof (backlog));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_bind (pull, "ipc:///tmp/test-backlog");
- assert (rc >= 0);
+ errno_assert (rc >= 0);
-
for (i = 0; i < PARALLEL_CONNECTS; i++)
threads [i] = thread_create (ipc_worker, ctx);
for (i = 0; i < PARALLEL_CONNECTS; i++) {
rc = xs_recv (pull, NULL, 0, 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
for (i = 0; i < PARALLEL_CONNECTS; i++)
thread_join (threads [i]);
@@ -108,28 +107,28 @@ int XS_TEST_MAIN ()
// Test the exhaustion on TCP backlog.
ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
pull = xs_socket (ctx, XS_PULL);
- assert (pull);
+ errno_assert (pull);
backlog = BACKLOG;
rc = xs_setsockopt (pull, XS_BACKLOG, &backlog, sizeof (backlog));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_bind (pull, "tcp://127.0.0.1:5560");
- assert (rc >= 0);
+ errno_assert (rc >= 0);
for (i = 0; i < PARALLEL_CONNECTS; i++)
threads [i] = thread_create (tcp_worker, ctx);
for (i = 0; i < PARALLEL_CONNECTS; i++) {
rc = xs_recv (pull, NULL, 0, 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
for (i = 0; i < PARALLEL_CONNECTS; i++)
thread_join (threads [i]);
diff --git a/tests/emptyctx.cpp b/tests/emptyctx.cpp
index 1448254..0c95446 100644
--- a/tests/emptyctx.cpp
+++ b/tests/emptyctx.cpp
@@ -27,9 +27,9 @@ int XS_TEST_MAIN ()
// This is a very simple test to check whether everything works OK when
// context is terminated even before I/O threads were launched.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
int rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/invalid_rep.cpp b/tests/invalid_rep.cpp
index 93118b6..c65b600 100644
--- a/tests/invalid_rep.cpp
+++ b/tests/invalid_rep.cpp
@@ -27,24 +27,24 @@ int XS_TEST_MAIN ()
// Create REQ/XREP wiring.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *xrep_socket = xs_socket (ctx, XS_XREP);
- assert (xrep_socket);
+ errno_assert (xrep_socket);
void *req_socket = xs_socket (ctx, XS_REQ);
- assert (req_socket);
+ errno_assert (req_socket);
int linger = 0;
int rc = xs_setsockopt (xrep_socket, XS_LINGER, &linger, sizeof (int));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_setsockopt (req_socket, XS_LINGER, &linger, sizeof (int));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_bind (xrep_socket, "inproc://hi");
- assert (rc != -1);
+ errno_assert (rc != -1);
rc = xs_connect (req_socket, "inproc://hi");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Initial request.
rc = xs_send (req_socket, "r", 1, 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
// Receive the request.
char addr [32];
@@ -52,36 +52,36 @@ int XS_TEST_MAIN ()
char bottom [1];
char body [1];
addr_size = xs_recv (xrep_socket, addr, sizeof (addr), 0);
- assert (addr_size >= 0);
+ errno_assert (addr_size >= 0);
rc = xs_recv (xrep_socket, bottom, sizeof (bottom), 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_recv (xrep_socket, body, sizeof (body), 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
// Send invalid reply.
rc = xs_send (xrep_socket, addr, addr_size, 0);
- assert (rc == addr_size);
+ errno_assert (rc == addr_size);
// Send valid reply.
rc = xs_send (xrep_socket, addr, addr_size, XS_SNDMORE);
- assert (rc == addr_size);
+ errno_assert (rc == addr_size);
rc = xs_send (xrep_socket, bottom, 0, XS_SNDMORE);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_send (xrep_socket, "b", 1, 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
// Check whether we've got the valid reply.
rc = xs_recv (req_socket, body, sizeof (body), 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
assert (body [0] == 'b');
// Tear down the wiring.
rc = xs_close (xrep_socket);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (req_socket);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0;
}
diff --git a/tests/libzmq21.cpp b/tests/libzmq21.cpp
index ecf271b..ea02f7d 100644
--- a/tests/libzmq21.cpp
+++ b/tests/libzmq21.cpp
@@ -50,14 +50,14 @@ int XS_TEST_MAIN ()
// Create the basic infrastructure.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *pub = xs_socket (ctx, XS_PUB);
- assert (pub);
+ errno_assert (pub);
int protocol = 1;
int rc = xs_setsockopt (pub, XS_PROTOCOL, &protocol, sizeof (protocol));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_bind (pub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
int oldsub = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in address;
@@ -65,7 +65,7 @@ int XS_TEST_MAIN ()
address.sin_addr.s_addr = inet_addr ("127.0.0.1");
address.sin_port = htons (5560);
rc = connect (oldsub, (struct sockaddr*) &address, sizeof (address));
- assert (rc == 0);
+ errno_assert (rc == 0);
// Wait a while to allow connection to be accepted on the publisher side.
sleep (1);
@@ -73,46 +73,46 @@ int XS_TEST_MAIN ()
// Send a message and check whether it arrives although there was no
// subscription sent.
rc = xs_send (pub, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
char buf [5];
rc = recv (oldsub, buf, sizeof (buf), 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
assert (!memcmp (buf, "\x04\0ABC", 5));
// Tear down the infrastructure.
rc = xs_close (pub);
- assert (rc == 0);
+ errno_assert (rc == 0);
#if defined XS_HAVE_WINDOWS
rc = closesocket (oldsub);
assert (rc != SOCKET_ERROR);
#else
rc = close (oldsub);
- assert (rc == 0);
+ errno_assert (rc == 0);
#endif
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
// Second, test the 0MQ/2.1-style publisher with up-to-date subscriber.
// Create the basic infrastructure.
ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sub = xs_socket (ctx, XS_SUB);
- assert (sub);
+ errno_assert (sub);
protocol = 1;
rc = xs_setsockopt (sub, XS_PROTOCOL, &protocol, sizeof (protocol));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_setsockopt (sub, XS_SUBSCRIBE, "", 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_bind (sub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
int oldpub = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr ("127.0.0.1");
address.sin_port = htons (5560);
rc = connect (oldpub, (struct sockaddr*) &address, sizeof (address));
- assert (rc == 0);
+ errno_assert (rc == 0);
// Wait a while to allow connection to be accepted on the subscriber side.
sleep (1);
@@ -125,13 +125,13 @@ int XS_TEST_MAIN ()
#elif XS_HAVE_OPENVMS
int nonblock = 1;
rc = ioctl (oldpub, FIONBIO, &nonblock);
- assert (rc != -1);
+ errno_assert (rc != -1);
#else
int flags = fcntl (oldpub, F_GETFL, 0);
if (flags == -1)
flags = 0;
rc = fcntl (oldpub, F_SETFL, flags | O_NONBLOCK);
- assert (rc != -1);
+ errno_assert (rc != -1);
#endif
// Check that subscription haven't arrived at the publisher side.
@@ -139,33 +139,33 @@ int XS_TEST_MAIN ()
#if defined XS_HAVE_WINDOWS
assert (rc == SOCKET_ERROR && WSAGetLastError () == WSAEWOULDBLOCK);
#else
- assert (rc == -1 && (errno == EAGAIN || errno == EWOULDBLOCK));
+ errno_assert (rc == -1 && (errno == EAGAIN || errno == EWOULDBLOCK));
#endif
// Pass one message through.
rc = send (oldpub, "\x04\0ABC", 5, 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
rc = xs_recv (sub, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Pass one message with usused flags set (0MQ/2.1 bug).
rc = send (oldpub, "\x04\xfe" "ABC", 5, 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
rc = xs_recv (sub, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Tear down the infrastructure.
rc = xs_close (sub);
- assert (rc == 0);
+ errno_assert (rc == 0);
#if defined XS_HAVE_WINDOWS
rc = closesocket (oldpub);
assert (rc != SOCKET_ERROR);
#else
rc = close (oldpub);
- assert (rc == 0);
+ errno_assert (rc == 0);
#endif
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
#if defined XS_HAVE_WINDOWS
WSACleanup ();
diff --git a/tests/linger.cpp b/tests/linger.cpp
index 1b1d341..592cf09 100644
--- a/tests/linger.cpp
+++ b/tests/linger.cpp
@@ -26,31 +26,31 @@ int XS_TEST_MAIN ()
// Create socket.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *s = xs_socket (ctx, XS_PUSH);
- assert (s);
+ errno_assert (s);
// Set linger to 0.1 second.
int linger = 100;
int rc = xs_setsockopt (s, XS_LINGER, &linger, sizeof (int));
+ errno_assert (rc == 0);
// Connect to non-existent endpoing.
- assert (rc == 0);
rc = xs_connect (s, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Send a message.
rc = xs_send (s, "r", 1, 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
// Close the socket.
rc = xs_close (s);
- assert (rc == 0);
+ errno_assert (rc == 0);
// Terminate the context. This should take 0.1 second.
void *watch = xs_stopwatch_start ();
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
int ms = (int) xs_stopwatch_stop (watch) / 1000;
time_assert (ms, linger);
diff --git a/tests/max_sockets.cpp b/tests/max_sockets.cpp
index 5890d0f..c09f205 100644
--- a/tests/max_sockets.cpp
+++ b/tests/max_sockets.cpp
@@ -26,25 +26,25 @@ int XS_TEST_MAIN ()
// Create context and set MAX_SOCKETS to 1.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
int max_sockets = 1;
int rc = xs_setctxopt (ctx, XS_MAX_SOCKETS, &max_sockets,
sizeof (max_sockets));
- assert (rc == 0);
+ errno_assert (rc == 0);
// First socket should be created OK.
void *s1 = xs_socket (ctx, XS_PUSH);
- assert (s1);
+ errno_assert (s1);
// Creation of second socket should fail.
void *s2 = xs_socket (ctx, XS_PUSH);
- assert (!s2 && errno == EMFILE);
+ errno_assert (!s2 && errno == EMFILE);
// Clean up.
rc = xs_close (s1);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0;
}
diff --git a/tests/msg_flags.cpp b/tests/msg_flags.cpp
index 3f3b3b1..e83e4d2 100644
--- a/tests/msg_flags.cpp
+++ b/tests/msg_flags.cpp
@@ -26,57 +26,57 @@ int XS_TEST_MAIN ()
// Create the infrastructure
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_XREP);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_XREQ);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Send 2-part message.
rc = xs_send (sc, "A", 1, XS_SNDMORE);
- assert (rc == 1);
+ errno_assert (rc == 1);
rc = xs_send (sc, "B", 1, 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
// Identity comes first.
xs_msg_t msg;
rc = xs_msg_init (&msg);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_recvmsg (sb, &msg, 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
int more;
size_t more_size = sizeof (more);
rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (more == 1);
// Then the first part of the message body.
rc = xs_recvmsg (sb, &msg, 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
more_size = sizeof (more);
rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (more == 1);
// And finally, the second part of the message body.
rc = xs_recvmsg (sb, &msg, 0);
- assert (rc == 1);
+ errno_assert (rc == 1);
more_size = sizeof (more);
rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (more == 0);
// Deallocate the infrastructure.
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/pair_inproc.cpp b/tests/pair_inproc.cpp
index 456a371..575381b 100644
--- a/tests/pair_inproc.cpp
+++ b/tests/pair_inproc.cpp
@@ -25,28 +25,28 @@ int XS_TEST_MAIN ()
fprintf (stderr, "pair_inproc test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_PAIR);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_PAIR);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
bounce (sb, sc);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/pair_ipc.cpp b/tests/pair_ipc.cpp
index ef39bfc..38ab4d9 100644
--- a/tests/pair_ipc.cpp
+++ b/tests/pair_ipc.cpp
@@ -32,28 +32,28 @@ int XS_TEST_MAIN ()
fprintf (stderr, "pair_ipc test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_PAIR);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "ipc:///tmp/tester");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_PAIR);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "ipc:///tmp/tester");
- assert (rc != -1);
+ errno_assert (rc != -1);
bounce (sb, sc);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/pair_tcp.cpp b/tests/pair_tcp.cpp
index d406523..51184a5 100644
--- a/tests/pair_tcp.cpp
+++ b/tests/pair_tcp.cpp
@@ -26,39 +26,39 @@ int XS_TEST_MAIN ()
fprintf (stderr, "pair_tcp test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_PAIR);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_PAIR);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
bounce (sb, sc);
// Now let's try to open one more connection to the bound socket.
// The connection should be silently rejected rather than causing error.
void *sc2 = xs_socket (ctx, XS_PAIR);
- assert (sc2);
+ errno_assert (sc2);
rc = xs_connect (sc2, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
sleep (1);
rc = xs_close (sc2);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/polltimeo.cpp b/tests/polltimeo.cpp
index f425593..9538d8d 100644
--- a/tests/polltimeo.cpp
+++ b/tests/polltimeo.cpp
@@ -28,12 +28,12 @@ extern "C"
// for 1 more second, so that async connect has time to succeed.
sleep (1);
void *sc = xs_socket (ctx_, XS_PUSH);
- assert (sc);
+ errno_assert (sc);
int rc = xs_connect (sc, "inproc://timeout_test");
- assert (rc != -1);
+ errno_assert (rc != -1);
sleep (1);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
}
@@ -42,13 +42,13 @@ int XS_TEST_MAIN ()
fprintf (stderr, "polltimeo test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
// Create a disconnected socket.
void *sb = xs_socket (ctx, XS_PULL);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "inproc://timeout_test");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Check whether timeout is honoured.
xs_pollitem_t pi;
@@ -56,7 +56,7 @@ int XS_TEST_MAIN ()
pi.events = XS_POLLIN;
void *watch = xs_stopwatch_start ();
rc = xs_poll (&pi, 1, 500);
- assert (rc == 0);
+ errno_assert (rc == 0);
unsigned long elapsed = xs_stopwatch_stop (watch) / 1000;
time_assert (elapsed, 500);
@@ -65,16 +65,16 @@ int XS_TEST_MAIN ()
assert (thread);
watch = xs_stopwatch_start ();
rc = xs_poll (&pi, 1, 2000);
- assert (rc == 0);
+ errno_assert (rc == 0);
elapsed = xs_stopwatch_stop (watch) / 1000;
time_assert (elapsed, 2000);
thread_join (thread);
// Clean-up.
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/reconnect.cpp b/tests/reconnect.cpp
index ebbaf32..9aa6e20 100644
--- a/tests/reconnect.cpp
+++ b/tests/reconnect.cpp
@@ -26,67 +26,67 @@ int XS_TEST_MAIN ()
// Create the basic infrastructure.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *push = xs_socket (ctx, XS_PUSH);
- assert (push);
+ errno_assert (push);
void *pull = xs_socket (ctx, XS_PULL);
- assert (push);
+ errno_assert (push);
// Connect before bind was done at the peer and send one message.
int rc = xs_connect (push, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
rc = xs_send (push, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Wait a while for few attempts to reconnect to happen.
sleep (1);
// Bind the peer and get the message.
rc = xs_bind (pull, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
unsigned char buf [3];
rc = xs_recv (pull, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Clean up.
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
#if !defined XS_HAVE_WINDOWS && !defined XS_HAVE_OPENVMS
// Now, let's test the same scenario with IPC.
push = xs_socket (ctx, XS_PUSH);
- assert (push);
+ errno_assert (push);
pull = xs_socket (ctx, XS_PULL);
- assert (push);
+ errno_assert (push);
// Connect before bind was done at the peer and send one message.
rc = xs_connect (push, "ipc:///tmp/tester");
- assert (rc != -1);
+ errno_assert (rc != -1);
rc = xs_send (push, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Wait a while for few attempts to reconnect to happen.
sleep (1);
// Bind the peer and get the message.
rc = xs_bind (pull, "ipc:///tmp/tester");
- assert (rc != -1);
+ errno_assert (rc != -1);
rc = xs_recv (pull, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Clean up.
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
#endif
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/reqrep_device.cpp b/tests/reqrep_device.cpp
index 732f4dc..0fb09d6 100644
--- a/tests/reqrep_device.cpp
+++ b/tests/reqrep_device.cpp
@@ -26,112 +26,112 @@ int XS_TEST_MAIN ()
fprintf (stderr, "reqrep_device test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
// Create a req/rep device.
void *xreq = xs_socket (ctx, XS_XREQ);
- assert (xreq);
+ errno_assert (xreq);
int rc = xs_bind (xreq, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *xrep = xs_socket (ctx, XS_XREP);
- assert (xrep);
+ errno_assert (xrep);
rc = xs_bind (xrep, "tcp://127.0.0.1:5561");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Create a worker.
void *rep = xs_socket (ctx, XS_REP);
- assert (rep);
+ errno_assert (rep);
rc = xs_connect (rep, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Create a client.
void *req = xs_socket (ctx, XS_REQ);
- assert (req);
+ errno_assert (req);
rc = xs_connect (req, "tcp://127.0.0.1:5561");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Send a request.
rc = xs_send (req, "ABC", 3, XS_SNDMORE);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_send (req, "DEF", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Pass the request through the device.
for (int i = 0; i != 4; i++) {
xs_msg_t msg;
rc = xs_msg_init (&msg);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_recvmsg (xrep, &msg, 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
int rcvmore;
size_t sz = sizeof (rcvmore);
rc = xs_getsockopt (xrep, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_sendmsg (xreq, &msg, rcvmore ? XS_SNDMORE : 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
}
// Receive the request.
char buff [3];
rc = xs_recv (rep, buff, 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
assert (memcmp (buff, "ABC", 3) == 0);
int rcvmore;
size_t sz = sizeof (rcvmore);
rc = xs_getsockopt (rep, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (rcvmore);
rc = xs_recv (rep, buff, 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
assert (memcmp (buff, "DEF", 3) == 0);
rc = xs_getsockopt (rep, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (!rcvmore);
// Send the reply.
rc = xs_send (rep, "GHI", 3, XS_SNDMORE);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_send (rep, "JKL", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Pass the reply through the device.
for (int i = 0; i != 4; i++) {
xs_msg_t msg;
rc = xs_msg_init (&msg);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_recvmsg (xreq, &msg, 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
rc = xs_getsockopt (xreq, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_sendmsg (xrep, &msg, rcvmore ? XS_SNDMORE : 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
}
// Receive the reply.
rc = xs_recv (req, buff, 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
assert (memcmp (buff, "GHI", 3) == 0);
rc = xs_getsockopt (req, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (rcvmore);
rc = xs_recv (req, buff, 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
assert (memcmp (buff, "JKL", 3) == 0);
rc = xs_getsockopt (req, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (!rcvmore);
// Clean up.
rc = xs_close (req);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (rep);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (xrep);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (xreq);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/reqrep_inproc.cpp b/tests/reqrep_inproc.cpp
index bd5cc92..64f1c95 100644
--- a/tests/reqrep_inproc.cpp
+++ b/tests/reqrep_inproc.cpp
@@ -25,28 +25,28 @@ int XS_TEST_MAIN ()
fprintf (stderr, "reqrep_inproc test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_REP);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_REQ);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
bounce (sb, sc);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/reqrep_ipc.cpp b/tests/reqrep_ipc.cpp
index 66315ef..5a98f89 100644
--- a/tests/reqrep_ipc.cpp
+++ b/tests/reqrep_ipc.cpp
@@ -32,28 +32,28 @@ int XS_TEST_MAIN ()
fprintf (stderr, "reqrep_ipc test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_REP);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "ipc:///tmp/tester");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_REQ);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "ipc:///tmp/tester");
- assert (rc != -1);
+ errno_assert (rc != -1);
bounce (sb, sc);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/reqrep_tcp.cpp b/tests/reqrep_tcp.cpp
index f68d762..6c1cd09 100644
--- a/tests/reqrep_tcp.cpp
+++ b/tests/reqrep_tcp.cpp
@@ -26,28 +26,28 @@ int XS_TEST_MAIN ()
fprintf (stderr, "reqrep_tcp test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *sb = xs_socket (ctx, XS_REP);
- assert (sb);
+ errno_assert (sb);
int rc = xs_bind (sb, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *sc = xs_socket (ctx, XS_REQ);
- assert (sc);
+ errno_assert (sc);
rc = xs_connect (sc, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
bounce (sb, sc);
rc = xs_close (sc);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sb);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/resubscribe.cpp b/tests/resubscribe.cpp
index 5d78712..d60d1d4 100644
--- a/tests/resubscribe.cpp
+++ b/tests/resubscribe.cpp
@@ -26,33 +26,33 @@ int XS_TEST_MAIN ()
// Create the basic infrastructure.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *xpub = xs_socket (ctx, XS_XPUB);
- assert (xpub);
+ errno_assert (xpub);
void *sub = xs_socket (ctx, XS_SUB);
- assert (sub);
+ errno_assert (sub);
// Send two subscriptions upstream.
int rc = xs_bind (xpub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
rc = xs_setsockopt (sub, XS_SUBSCRIBE, "a", 1);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_setsockopt (sub, XS_SUBSCRIBE, "b", 1);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_connect (sub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Check whether subscriptions are correctly received.
char buf [5];
rc = xs_recv (xpub, buf, sizeof (buf), 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
assert (buf [0] == 0);
assert (buf [1] == 1);
assert (buf [2] == 0);
assert (buf [3] == 1);
assert (buf [4] == 'a');
rc = xs_recv (xpub, buf, sizeof (buf), 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
assert (buf [0] == 0);
assert (buf [1] == 1);
assert (buf [2] == 0);
@@ -61,14 +61,14 @@ int XS_TEST_MAIN ()
// Tear down the connection.
rc = xs_close (xpub);
- assert (rc == 0);
+ errno_assert (rc == 0);
sleep (1);
// Re-establish the connection.
xpub = xs_socket (ctx, XS_XPUB);
- assert (xpub);
+ errno_assert (xpub);
rc = xs_bind (xpub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// We have to give control to the SUB socket here so that it has
// chance to resend the subscriptions.
@@ -77,14 +77,14 @@ int XS_TEST_MAIN ()
// Check whether subscriptions are correctly generated.
rc = xs_recv (xpub, buf, sizeof (buf), 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
assert (buf [0] == 0);
assert (buf [1] == 1);
assert (buf [2] == 0);
assert (buf [3] == 1);
assert (buf [4] == 'a');
rc = xs_recv (xpub, buf, sizeof (buf), 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
assert (buf [0] == 0);
assert (buf [1] == 1);
assert (buf [2] == 0);
@@ -93,11 +93,11 @@ int XS_TEST_MAIN ()
// Clean up.
rc = xs_close (sub);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (xpub);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/shutdown.cpp b/tests/shutdown.cpp
index 9f055a1..af88c90 100644
--- a/tests/shutdown.cpp
+++ b/tests/shutdown.cpp
@@ -29,25 +29,25 @@ int XS_TEST_MAIN ()
// Create infrastructure.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *push = xs_socket (ctx, XS_PUSH);
- assert (push);
+ errno_assert (push);
int push_id = xs_bind (push, "tcp://127.0.0.1:5560");
- assert (push_id != -1);
+ errno_assert (push_id != -1);
void *pull = xs_socket (ctx, XS_PULL);
- assert (pull);
+ errno_assert (pull);
rc = xs_connect (pull, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Pass one message through to ensure the connection is established.
rc = xs_send (push, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_recv (pull, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Shut down the bound endpoint.
rc = xs_shutdown (push, push_id);
- assert (rc == 0);
+ errno_assert (rc == 0);
sleep (1);
// Check that sending would block (there's no outbound connection).
@@ -56,35 +56,35 @@ int XS_TEST_MAIN ()
// Clean up.
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
// Now the other way round.
// Create infrastructure.
ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
pull = xs_socket (ctx, XS_PULL);
- assert (pull);
+ errno_assert (pull);
rc = xs_bind (pull, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
push = xs_socket (ctx, XS_PUSH);
- assert (push);
+ errno_assert (push);
push_id = xs_connect (push, "tcp://127.0.0.1:5560");
- assert (push_id != -1);
+ errno_assert (push_id != -1);
// Pass one message through to ensure the connection is established.
rc = xs_send (push, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_recv (pull, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Shut down the bound endpoint.
rc = xs_shutdown (push, push_id);
- assert (rc == 0);
+ errno_assert (rc == 0);
sleep (1);
// Check that sending would block (there's no outbound connection).
@@ -93,11 +93,11 @@ int XS_TEST_MAIN ()
// Clean up.
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0;
}
diff --git a/tests/shutdown_stress.cpp b/tests/shutdown_stress.cpp
index 2b598a9..25ec56a 100644
--- a/tests/shutdown_stress.cpp
+++ b/tests/shutdown_stress.cpp
@@ -30,11 +30,11 @@ extern "C"
int rc;
rc = xs_connect (s_, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Start closing the socket while the connecting process is underway.
rc = xs_close (s_);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
}
@@ -55,24 +55,24 @@ int XS_TEST_MAIN ()
// Check the shutdown with many parallel I/O threads.
ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
io_threads = 7;
rc = xs_setctxopt (ctx, XS_IO_THREADS, &io_threads,
sizeof (io_threads));
- assert (rc == 0);
+ errno_assert (rc == 0);
s1 = xs_socket (ctx, XS_PUB);
- assert (s1);
+ errno_assert (s1);
rc = xs_bind (s1, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
for (i = 0; i != THREAD_COUNT; i++) {
s2 = xs_socket (ctx, XS_SUB);
if (!s2 && (errno == EMFILE || errno == ENFILE))
threads [i] = NULL;
else {
- assert (s2);
+ errno_assert (s2);
threads [i] = thread_create (shutdown_stress_worker, s2);
assert (threads [i]);
}
@@ -83,10 +83,10 @@ int XS_TEST_MAIN ()
thread_join (threads [i]);
rc = xs_close (s1);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
}
return 0;
diff --git a/tests/sub_forward.cpp b/tests/sub_forward.cpp
index 0237352..5c2350e 100644
--- a/tests/sub_forward.cpp
+++ b/tests/sub_forward.cpp
@@ -26,69 +26,69 @@ int XS_TEST_MAIN ()
fprintf (stderr, "sub_forward test running...\n");
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
// First, create an intermediate device.
void *xpub = xs_socket (ctx, XS_XPUB);
- assert (xpub);
+ errno_assert (xpub);
int rc = xs_bind (xpub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *xsub = xs_socket (ctx, XS_XSUB);
- assert (xsub);
+ errno_assert (xsub);
rc = xs_bind (xsub, "tcp://127.0.0.1:5561");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Create a publisher.
void *pub = xs_socket (ctx, XS_PUB);
- assert (pub);
+ errno_assert (pub);
rc = xs_connect (pub, "tcp://127.0.0.1:5561");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Create a subscriber.
void *sub = xs_socket (ctx, XS_SUB);
- assert (sub);
+ errno_assert (sub);
rc = xs_connect (sub, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Subscribe for all messages.
rc = xs_setsockopt (sub, XS_SUBSCRIBE, "", 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
// Pass the subscription upstream through the device.
char buff [32];
rc = xs_recv (xpub, buff, sizeof (buff), 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
rc = xs_send (xsub, buff, rc, 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
// Wait a bit till the subscription gets to the publisher.
sleep (1);
// Send an empty message.
rc = xs_send (pub, NULL, 0, 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
// Pass the message downstream through the device.
rc = xs_recv (xsub, buff, sizeof (buff), 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
rc = xs_send (xpub, buff, rc, 0);
- assert (rc >= 0);
+ errno_assert (rc >= 0);
// Receive the message in the subscriber.
rc = xs_recv (sub, buff, sizeof (buff), 0);
- assert (rc == 0);
+ errno_assert (rc == 0);
// Clean up.
rc = xs_close (xpub);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (xsub);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (pub);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (sub);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/survey.cpp b/tests/survey.cpp
index 2179779..c5b0285 100644
--- a/tests/survey.cpp
+++ b/tests/survey.cpp
@@ -29,101 +29,101 @@ int XS_TEST_MAIN ()
// Create the basic infrastructure.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *xsurveyor = xs_socket (ctx, XS_XSURVEYOR);
- assert (xsurveyor);
+ errno_assert (xsurveyor);
rc = xs_bind (xsurveyor, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *xrespondent = xs_socket (ctx, XS_XRESPONDENT);
- assert (xrespondent);
+ errno_assert (xrespondent);
rc = xs_bind (xrespondent, "inproc://b");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *surveyor = xs_socket (ctx, XS_SURVEYOR);
- assert (surveyor);
+ errno_assert (surveyor);
rc = xs_connect (surveyor, "inproc://b");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *respondent1 = xs_socket (ctx, XS_RESPONDENT);
- assert (respondent1);
+ errno_assert (respondent1);
rc = xs_connect (respondent1, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
void *respondent2 = xs_socket (ctx, XS_RESPONDENT);
- assert (respondent2);
+ errno_assert (respondent2);
rc = xs_connect (respondent2, "inproc://a");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Send the survey.
rc = xs_send (surveyor, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Forward the survey through the intermediate device.
// Survey consist of identity (4 bytes), survey ID (4 bytes) and the body.
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xsurveyor, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xsurveyor, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_send (xsurveyor, buf, 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Respondent 1 responds to the survey.
rc = xs_recv (respondent1, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_send (respondent1, "DE", 2, 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
// Forward the response through the intermediate device.
rc = xs_recv (xsurveyor, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xsurveyor, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xsurveyor, buf, sizeof (buf), 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
rc = xs_send (xrespondent, buf, 2, 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
// Surveyor gets the response.
rc = xs_recv (surveyor, buf, sizeof (buf), 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
// Respondent 2 responds to the survey.
rc = xs_recv (respondent2, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_send (respondent2, "FGHI", 4, 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
// Forward the response through the intermediate device.
rc = xs_recv (xsurveyor, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xsurveyor, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xsurveyor, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
// Surveyor gets the response.
rc = xs_recv (surveyor, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
// Now let's test whether survey timeout works as expected.
int timeout = 100;
rc = xs_setsockopt (surveyor, XS_SURVEY_TIMEOUT, &timeout, sizeof (int));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_send (surveyor, "ABC", 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
void *watch = xs_stopwatch_start ();
rc = xs_recv (surveyor, buf, sizeof (buf), 0);
assert (rc == - 1 && errno == ETIMEDOUT);
@@ -133,55 +133,55 @@ int XS_TEST_MAIN ()
// Test whether responses for old surveys are discarded. First,
// initiate new survey.
rc = xs_setsockopt (surveyor, XS_SURVEY_TIMEOUT, &timeout, sizeof (int));
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_send (surveyor, "DE", 2, 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
// Read, process and reply to the old survey.
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = xs_send (xrespondent, buf, 3, 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
// Read, process and reply to the new survey.
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_send (xrespondent, buf, 4, XS_SNDMORE);
- assert (rc == 4);
+ errno_assert (rc == 4);
rc = xs_recv (xrespondent, buf, sizeof (buf), 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
rc = xs_send (xrespondent, buf, 2, 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
// Get the response and check it's the response to the new survey and
// that response to the old survey was silently discarded.
rc = xs_recv (surveyor, buf, sizeof (buf), 0);
- assert (rc == 2);
+ errno_assert (rc == 2);
rc = xs_close (respondent2);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (respondent1);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (surveyor);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (xrespondent);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (xsurveyor);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}
diff --git a/tests/testutil.hpp b/tests/testutil.hpp
index b6a55a2..307fdf8 100644
--- a/tests/testutil.hpp
+++ b/tests/testutil.hpp
@@ -42,10 +42,25 @@
#define XS_TEST_MAIN main
#endif
+#define errno_assert(x) \
+ do {\
+ if (!(x)) {\
+ const char *errstr = xs_strerror (errno);\
+ fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
+ abort ();\
+ }\
+ } while (false)
+
#if defined XS_HAVE_WINDOWS
#define sleep(s) Sleep ((s) * 1000)
#endif
+// Check whether measured time is the expected time (in milliseconds).
+// The upper tolerance is 1/2 sec so that the test doesn't fail even on
+// very slow or very loaded systems.
+#define time_assert(actual,expected) \
+ assert (actual > ((expected) - 50) && actual < ((expected) + 500));
+
#if defined XS_HAVE_WINDOWS
struct arg_t
@@ -113,7 +128,10 @@ void *thread_create (void (*fn_) (void *arg_), void *arg_)
arg->fn = fn_;
arg->arg = arg_;
int rc = pthread_create (&arg->handle, NULL, thread_routine, (void*) arg);
- assert (rc == 0);
+ if (rc != 0) {
+ errno = rc;
+ errno_assert (0);
+ }
return (void*) arg;
}
@@ -121,7 +139,10 @@ void thread_join (void *thread_)
{
arg_t *arg = (arg_t*) thread_;
int rc = pthread_join (arg->handle, NULL);
- assert (rc == 0);
+ if (rc != 0) {
+ errno = rc;
+ errno_assert (0);
+ }
free (arg);
}
@@ -133,50 +154,52 @@ inline void bounce (void *sb, void *sc)
// Send the message.
int rc = xs_send (sc, content, 32, XS_SNDMORE);
+ errno_assert (rc != -1);
assert (rc == 32);
rc = xs_send (sc, content, 32, 0);
+ errno_assert (rc != -1);
assert (rc == 32);
// Bounce the message back.
char buf1 [32];
rc = xs_recv (sb, buf1, 32, 0);
+ errno_assert (rc != -1);
assert (rc == 32);
int rcvmore;
size_t sz = sizeof (rcvmore);
rc = xs_getsockopt (sb, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (rcvmore);
rc = xs_recv (sb, buf1, 32, 0);
+ errno_assert (rc != -1);
assert (rc == 32);
rc = xs_getsockopt (sb, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (!rcvmore);
rc = xs_send (sb, buf1, 32, XS_SNDMORE);
+ errno_assert (rc != -1);
assert (rc == 32);
rc = xs_send (sb, buf1, 32, 0);
+ errno_assert (rc != -1);
assert (rc == 32);
// Receive the bounced message.
char buf2 [32];
rc = xs_recv (sc, buf2, 32, 0);
+ errno_assert (rc != -1);
assert (rc == 32);
rc = xs_getsockopt (sc, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (rcvmore);
rc = xs_recv (sc, buf2, 32, 0);
+ errno_assert (rc != -1);
assert (rc == 32);
rc = xs_getsockopt (sc, XS_RCVMORE, &rcvmore, &sz);
- assert (rc == 0);
+ errno_assert (rc == 0);
assert (!rcvmore);
// Check whether the message is still the same.
assert (memcmp (buf2, content, 32) == 0);
}
-// Check whether measured time is the expected time (in milliseconds).
-// The upper tolerance is 1/2 sec so that the test doesn't fail even on
-// very slow or very loaded systems.
-#define time_assert(actual,expected) \
- assert (actual > ((expected) - 50) && actual < ((expected) + 500));
-
#endif
diff --git a/tests/wireformat.cpp b/tests/wireformat.cpp
index f3e0f96..ad690d5 100644
--- a/tests/wireformat.cpp
+++ b/tests/wireformat.cpp
@@ -42,17 +42,17 @@ int XS_TEST_MAIN ()
// Create the basic infrastructure.
void *ctx = xs_init ();
- assert (ctx);
+ errno_assert (ctx);
void *push = xs_socket (ctx, XS_PUSH);
- assert (push);
+ errno_assert (push);
void *pull = xs_socket (ctx, XS_PULL);
- assert (push);
+ errno_assert (push);
// Bind the peer and get the message.
int rc = xs_bind (pull, "tcp://127.0.0.1:5560");
- assert (rc != -1);
+ errno_assert (rc != -1);
rc = xs_bind (push, "tcp://127.0.0.1:5561");
- assert (rc != -1);
+ errno_assert (rc != -1);
// Connect to the peer using raw sockets.
int rpush = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -60,30 +60,30 @@ int XS_TEST_MAIN ()
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr ("127.0.0.1");
address.sin_port = htons (5560);
- rc = connect(rpush, (struct sockaddr*) &address, sizeof (address));
- assert (rc == 0);
+ rc = connect (rpush, (struct sockaddr*) &address, sizeof (address));
+ errno_assert (rc == 0);
int rpull = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr ("127.0.0.1");
address.sin_port = htons (5561);
rc = connect (rpull, (struct sockaddr*) &address, sizeof (address));
- assert (rc == 0);
+ errno_assert (rc == 0);
// Let's send some data and check if it arrived
rc = send (rpush, "\x04\0abc", 5, 0);
- assert (rc == 5);
+ errno_assert (rc == 5);
unsigned char buf [3];
unsigned char buf2 [3];
rc = xs_recv (pull, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
assert (!memcmp (buf, "abc", 3));
// Let's push this data into another socket
rc = xs_send (push, buf, sizeof (buf), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
rc = recv (rpull, (char*) buf2, sizeof (buf2), 0);
- assert (rc == 3);
+ errno_assert (rc == 3);
assert (!memcmp (buf2, "\x04\0abc", 3));
#if defined XS_HAVE_WINDOWS
@@ -94,17 +94,17 @@ int XS_TEST_MAIN ()
WSACleanup ();
#else
rc = close (rpush);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = close (rpull);
- assert (rc == 0);
+ errno_assert (rc == 0);
#endif
rc = xs_close (pull);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_close (push);
- assert (rc == 0);
+ errno_assert (rc == 0);
rc = xs_term (ctx);
- assert (rc == 0);
+ errno_assert (rc == 0);
return 0 ;
}