Permalink
Browse files

Part of tests are refactored

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
  • Loading branch information...
1 parent 50e8b8d commit 2a3598e494a222858a4b52c97417366417dd00d2 @tailhook tailhook committed with sustrik Sep 6, 2013
Showing with 114 additions and 258 deletions.
  1. +1 −0 .gitignore
  2. +11 −26 tests/block.c
  3. +15 −33 tests/bus.c
  4. +42 −91 tests/device.c
  5. +3 −5 tests/domain.c
  6. +22 −55 tests/inproc.c
  7. +20 −48 tests/tcp.c
View
@@ -44,6 +44,7 @@ perf/local_lat
perf/local_thr
perf/remote_lat
perf/remote_thr
+doc/*.1
doc/*.7
doc/*.3
doc/*.html
View
@@ -23,9 +23,8 @@
#include "../src/nn.h"
#include "../src/pair.h"
-#include "../src/utils/err.c"
+#include "testutil.h"
#include "../src/utils/thread.c"
-#include "../src/utils/sleep.c"
/* This test checks whether blocking on send/recv works as expected. */
@@ -41,17 +40,13 @@ void worker (void *arg)
/* Wait 0.1 sec for the main thread to block. */
nn_sleep (100);
- rc = nn_send (sc, "ABC", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_send (sc, "ABC");
/* Wait 0.1 sec for the main thread to process the previous message
and block once again. */
nn_sleep (100);
- rc = nn_send (sc, "ABC", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_send (sc, "ABC");
}
int main ()
@@ -60,30 +55,20 @@ int main ()
char buf [3];
struct nn_thread thread;
- sb = nn_socket (AF_SP, NN_PAIR);
- errno_assert (sb != -1);
- rc = nn_bind (sb, SOCKET_ADDRESS);
- errno_assert (rc >= 0);
- sc = nn_socket (AF_SP, NN_PAIR);
- errno_assert (sc != -1);
- rc = nn_connect (sc, SOCKET_ADDRESS);
- errno_assert (rc >= 0);
+ sb = test_socket (AF_SP, NN_PAIR);
+ test_bind (sb, SOCKET_ADDRESS);
+ sc = test_socket (AF_SP, NN_PAIR);
+ test_connect (sc, SOCKET_ADDRESS);
nn_thread_init (&thread, worker, NULL);
- rc = nn_recv (sb, buf, sizeof (buf), 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
- rc = nn_recv (sb, buf, sizeof (buf), 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_recv (sb, "ABC");
+ test_recv (sb, "ABC");
nn_thread_term (&thread);
- rc = nn_close (sc);
- errno_assert (rc == 0);
- rc = nn_close (sb);
- errno_assert (rc == 0);
+ test_close (sc);
+ test_close (sb);
return 0;
}
View
@@ -22,8 +22,7 @@
#include "../src/nn.h"
#include "../src/bus.h"
-#include "../src/utils/err.c"
-#include "../src/utils/sleep.c"
+#include "testutil.h"
#define SOCKET_ADDRESS_A "inproc://a"
#define SOCKET_ADDRESS_B "inproc://b"
@@ -37,33 +36,19 @@ int main ()
char buf [3];
/* Create a simple bus topology consisting of 3 nodes. */
- bus1 = nn_socket (AF_SP, NN_BUS);
- errno_assert (bus1 != -1);
- rc = nn_bind (bus1, SOCKET_ADDRESS_A);
- errno_assert (rc >= 0);
- bus2 = nn_socket (AF_SP, NN_BUS);
- errno_assert (bus2 != -1);
- rc = nn_bind (bus2, SOCKET_ADDRESS_B);
- errno_assert (rc >= 0);
- rc = nn_connect (bus2, SOCKET_ADDRESS_A);
- errno_assert (rc >= 0);
- bus3 = nn_socket (AF_SP, NN_BUS);
- errno_assert (bus3 != -1);
- rc = nn_connect (bus3, SOCKET_ADDRESS_A);
- errno_assert (rc >= 0);
- rc = nn_connect (bus3, SOCKET_ADDRESS_B);
- errno_assert (rc >= 0);
+ bus1 = test_socket (AF_SP, NN_BUS);
+ test_bind (bus1, SOCKET_ADDRESS_A);
+ bus2 = test_socket (AF_SP, NN_BUS);
+ test_bind (bus2, SOCKET_ADDRESS_B);
+ test_connect (bus2, SOCKET_ADDRESS_A);
+ bus3 = test_socket (AF_SP, NN_BUS);
+ test_connect (bus3, SOCKET_ADDRESS_A);
+ test_connect (bus3, SOCKET_ADDRESS_B);
/* Send a message from each node. */
- rc = nn_send (bus1, "A", 1, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 1);
- rc = nn_send (bus2, "AB", 2, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 2);
- rc = nn_send (bus3, "ABC", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_send (bus1, "A");
+ test_send (bus2, "AB");
+ test_send (bus3, "ABC");
/* Check that two messages arrived at each node. */
rc = nn_recv (bus1, buf, 3, 0);
@@ -88,12 +73,9 @@ int main ()
/* Wait till both connections are established. */
nn_sleep (10);
- rc = nn_close (bus3);
- errno_assert (rc == 0);
- rc = nn_close (bus2);
- errno_assert (rc == 0);
- rc = nn_close (bus1);
- errno_assert (rc == 0);
+ test_close (bus3);
+ test_close (bus2);
+ test_close (bus1);
return 0;
}
View
@@ -27,8 +27,7 @@
#include "../src/pipeline.h"
#include "../src/inproc.h"
-#include "../src/utils/err.c"
-#include "../src/utils/sleep.c"
+#include "testutil.h"
#include "../src/utils/thread.c"
#define SOCKET_ADDRESS_A "inproc://a"
@@ -44,24 +43,18 @@ void device1 (void *arg)
int devb;
/* Intialise the device sockets. */
- deva = nn_socket (AF_SP_RAW, NN_PAIR);
- errno_assert (deva >= 0);
- rc = nn_bind (deva, SOCKET_ADDRESS_A);
- errno_assert (rc >= 0);
- devb = nn_socket (AF_SP_RAW, NN_PAIR);
- errno_assert (devb >= 0);
- rc = nn_bind (devb, SOCKET_ADDRESS_B);
- errno_assert (rc >= 0);
+ deva = test_socket (AF_SP_RAW, NN_PAIR);
+ test_bind (deva, SOCKET_ADDRESS_A);
+ devb = test_socket (AF_SP_RAW, NN_PAIR);
+ test_bind (devb, SOCKET_ADDRESS_B);
/* Run the device. */
rc = nn_device (deva, devb);
nn_assert (rc < 0 && nn_errno () == ETERM);
/* Clean up. */
- rc = nn_close (devb);
- errno_assert (rc == 0);
- rc = nn_close (deva);
- errno_assert (rc == 0);
+ test_close (devb);
+ test_close (deva);
}
void device2 (void *arg)
@@ -71,24 +64,18 @@ void device2 (void *arg)
int devd;
/* Intialise the device sockets. */
- devc = nn_socket (AF_SP_RAW, NN_PULL);
- errno_assert (devc >= 0);
- rc = nn_bind (devc, SOCKET_ADDRESS_C);
- errno_assert (rc >= 0);
- devd = nn_socket (AF_SP_RAW, NN_PUSH);
- errno_assert (devd >= 0);
- rc = nn_bind (devd, SOCKET_ADDRESS_D);
- errno_assert (rc >= 0);
+ devc = test_socket (AF_SP_RAW, NN_PULL);
+ test_bind (devc, SOCKET_ADDRESS_C);
+ devd = test_socket (AF_SP_RAW, NN_PUSH);
+ test_bind (devd, SOCKET_ADDRESS_D);
/* Run the device. */
rc = nn_device (devc, devd);
nn_assert (rc < 0 && nn_errno () == ETERM);
/* Clean up. */
- rc = nn_close (devd);
- errno_assert (rc == 0);
- rc = nn_close (devc);
- errno_assert (rc == 0);
+ test_close (devd);
+ test_close (devc);
}
void device3 (void *arg)
@@ -97,18 +84,15 @@ void device3 (void *arg)
int deve;
/* Intialise the device socket. */
- deve = nn_socket (AF_SP_RAW, NN_BUS);
- errno_assert (deve >= 0);
- rc = nn_bind (deve, SOCKET_ADDRESS_E);
- errno_assert (rc >= 0);
+ deve = test_socket (AF_SP_RAW, NN_BUS);
+ test_bind (deve, SOCKET_ADDRESS_E);
/* Run the device. */
rc = nn_device (deve, -1);
nn_assert (rc < 0 && nn_errno () == ETERM);
/* Clean up. */
- rc = nn_close (deve);
- errno_assert (rc == 0);
+ test_close (deve);
}
int main ()
@@ -132,89 +116,58 @@ int main ()
nn_thread_init (&thread1, device1, NULL);
/* Create two sockets to connect to the device. */
- enda = nn_socket (AF_SP, NN_PAIR);
- errno_assert (enda >= 0);
- rc = nn_connect (enda, SOCKET_ADDRESS_A);
- errno_assert (rc >= 0);
- endb = nn_socket (AF_SP, NN_PAIR);
- errno_assert (endb >= 0);
- rc = nn_connect (endb, SOCKET_ADDRESS_B);
- errno_assert (rc >= 0);
+ enda = test_socket (AF_SP, NN_PAIR);
+ test_connect (enda, SOCKET_ADDRESS_A);
+ endb = test_socket (AF_SP, NN_PAIR);
+ test_connect (endb, SOCKET_ADDRESS_B);
/* Pass a pair of messages between endpoints. */
- rc = nn_send (enda, "ABC", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
- rc = nn_recv (endb, buf, sizeof (buf), 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
- rc = nn_send (endb, "ABC", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
- rc = nn_recv (enda, buf, sizeof (buf), 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_send (enda, "ABC");
+ test_recv (endb, "ABC");
+ test_send (endb, "ABC");
+ test_recv (enda, "ABC");
/* Clean up. */
- rc = nn_close (endb);
- errno_assert (rc == 0);
- rc = nn_close (enda);
- errno_assert (rc == 0);
+ test_close (endb);
+ test_close (enda);
/* Test the uni-directional device. */
/* Start the device. */
nn_thread_init (&thread2, device2, NULL);
/* Create two sockets to connect to the device. */
- endc = nn_socket (AF_SP, NN_PUSH);
- errno_assert (endc >= 0);
- rc = nn_connect (endc, SOCKET_ADDRESS_C);
- errno_assert (rc >= 0);
- endd = nn_socket (AF_SP, NN_PULL);
- errno_assert (endd >= 0);
- rc = nn_connect (endd, SOCKET_ADDRESS_D);
- errno_assert (rc >= 0);
+ endc = test_socket (AF_SP, NN_PUSH);
+ test_connect (endc, SOCKET_ADDRESS_C);
+ endd = test_socket (AF_SP, NN_PULL);
+ test_connect (endd, SOCKET_ADDRESS_D);
/* Pass a message between endpoints. */
- rc = nn_send (endc, "XYZ", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
- rc = nn_recv (endd, buf, sizeof (buf), 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_send (endc, "XYZ");
+ test_recv (endd, "XYZ");
/* Clean up. */
- rc = nn_close (endd);
- errno_assert (rc == 0);
- rc = nn_close (endc);
- errno_assert (rc == 0);
+ test_close (endd);
+ test_close (endc);
/* Test the loopback device. */
/* Start the device. */
nn_thread_init (&thread3, device3, NULL);
/* Create two sockets to connect to the device. */
- ende1 = nn_socket (AF_SP, NN_BUS);
- errno_assert (ende1 >= 0);
- rc = nn_connect (ende1, SOCKET_ADDRESS_E);
- errno_assert (rc >= 0);
- ende2 = nn_socket (AF_SP, NN_BUS);
- errno_assert (ende2 >= 0);
- rc = nn_connect (ende2, SOCKET_ADDRESS_E);
+ ende1 = test_socket (AF_SP, NN_BUS);
+ test_connect (ende1, SOCKET_ADDRESS_E);
+ ende2 = test_socket (AF_SP, NN_BUS);
+ test_connect (ende2, SOCKET_ADDRESS_E);
errno_assert (rc >= 0);
/* BUS is unreliable so wait a bit for connections to be established. */
nn_sleep (100);
/* Pass a message to the bus. */
- rc = nn_send (ende1, "KLM", 3, 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
- rc = nn_recv (ende2, buf, sizeof (buf), 0);
- errno_assert (rc >= 0);
- nn_assert (rc == 3);
+ test_send (ende1, "KLM");
+ test_recv (ende2, "KLM");
/* Make sure that the message doesn't arrive at the socket it was
originally sent to. */
@@ -226,10 +179,8 @@ int main ()
errno_assert (rc < 0 && nn_errno () == EAGAIN);
/* Clean up. */
- rc = nn_close (ende2);
- errno_assert (rc == 0);
- rc = nn_close (ende1);
- errno_assert (rc == 0);
+ test_close (ende2);
+ test_close (ende1);
/* Shut down the devices. */
nn_term ();
View
@@ -22,7 +22,7 @@
#include "../src/nn.h"
#include "../src/pair.h"
-#include "../src/utils/err.c"
+#include "testutil.h"
/* Test the NN_DOMAIN and NN_PROTOCOL socket options. */
@@ -33,8 +33,7 @@ int main ()
int op;
size_t opsz;
- s = nn_socket (AF_SP, NN_PAIR);
- errno_assert (s >= 0);
+ s = test_socket (AF_SP, NN_PAIR);
opsz = sizeof (op);
rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_DOMAIN, &op, &opsz);
@@ -48,8 +47,7 @@ int main ()
nn_assert (opsz == sizeof (op));
nn_assert (op == NN_PAIR);
- rc = nn_close (s);
- errno_assert (rc == 0);
+ test_close (s);
return 0;
}
Oops, something went wrong.

0 comments on commit 2a3598e

Please sign in to comment.