From 802d84df533c131f91fbc599dae915390fad3e2b Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:05:52 +0900 Subject: Redundant test_ prefix removed from tests Signed-off-by: Martin Sustrik --- tests/Makefile.am | 60 +++++++++--------- tests/hwm.cpp | 81 ++++++++++++++++++++++++ tests/invalid_rep.cpp | 88 ++++++++++++++++++++++++++ tests/linger.cpp | 59 ++++++++++++++++++ tests/msg_flags.cpp | 82 ++++++++++++++++++++++++ tests/pair_inproc.cpp | 52 ++++++++++++++++ tests/pair_ipc.cpp | 52 ++++++++++++++++ tests/pair_tcp.cpp | 53 ++++++++++++++++ tests/reconnect.cpp | 87 ++++++++++++++++++++++++++ tests/reqrep_device.cpp | 138 +++++++++++++++++++++++++++++++++++++++++ tests/reqrep_inproc.cpp | 52 ++++++++++++++++ tests/reqrep_ipc.cpp | 52 ++++++++++++++++ tests/reqrep_tcp.cpp | 53 ++++++++++++++++ tests/shutdown_stress.cpp | 90 +++++++++++++++++++++++++++ tests/sub_forward.cpp | 94 ++++++++++++++++++++++++++++ tests/test_hwm.cpp | 81 ------------------------ tests/test_invalid_rep.cpp | 88 -------------------------- tests/test_linger.cpp | 59 ------------------ tests/test_msg_flags.cpp | 80 ------------------------ tests/test_pair_inproc.cpp | 52 ---------------- tests/test_pair_ipc.cpp | 52 ---------------- tests/test_pair_tcp.cpp | 53 ---------------- tests/test_reconnect.cpp | 87 -------------------------- tests/test_reqrep_device.cpp | 138 ----------------------------------------- tests/test_reqrep_inproc.cpp | 52 ---------------- tests/test_reqrep_ipc.cpp | 52 ---------------- tests/test_reqrep_tcp.cpp | 53 ---------------- tests/test_shutdown_stress.cpp | 90 --------------------------- tests/test_sub_forward.cpp | 94 ---------------------------- tests/test_timeo.cpp | 114 ---------------------------------- tests/timeo.cpp | 114 ++++++++++++++++++++++++++++++++++ 31 files changed, 1177 insertions(+), 1175 deletions(-) create mode 100644 tests/hwm.cpp create mode 100644 tests/invalid_rep.cpp create mode 100644 tests/linger.cpp create mode 100644 tests/msg_flags.cpp create mode 100644 tests/pair_inproc.cpp create mode 100644 tests/pair_ipc.cpp create mode 100644 tests/pair_tcp.cpp create mode 100644 tests/reconnect.cpp create mode 100644 tests/reqrep_device.cpp create mode 100644 tests/reqrep_inproc.cpp create mode 100644 tests/reqrep_ipc.cpp create mode 100644 tests/reqrep_tcp.cpp create mode 100644 tests/shutdown_stress.cpp create mode 100644 tests/sub_forward.cpp delete mode 100644 tests/test_hwm.cpp delete mode 100644 tests/test_invalid_rep.cpp delete mode 100644 tests/test_linger.cpp delete mode 100644 tests/test_msg_flags.cpp delete mode 100644 tests/test_pair_inproc.cpp delete mode 100644 tests/test_pair_ipc.cpp delete mode 100644 tests/test_pair_tcp.cpp delete mode 100644 tests/test_reconnect.cpp delete mode 100644 tests/test_reqrep_device.cpp delete mode 100644 tests/test_reqrep_inproc.cpp delete mode 100644 tests/test_reqrep_ipc.cpp delete mode 100644 tests/test_reqrep_tcp.cpp delete mode 100644 tests/test_shutdown_stress.cpp delete mode 100644 tests/test_sub_forward.cpp delete mode 100644 tests/test_timeo.cpp create mode 100644 tests/timeo.cpp (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 6a28e65..f448d8f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,42 +3,42 @@ INCLUDES = -I$(top_builddir)/include \ LDADD = $(top_builddir)/src/libxs.la -noinst_PROGRAMS = test_pair_inproc \ - test_pair_tcp \ - test_reqrep_inproc \ - test_reqrep_tcp \ - test_hwm \ - test_reqrep_device \ - test_sub_forward \ - test_invalid_rep \ - test_msg_flags \ - test_reconnect \ - test_linger +noinst_PROGRAMS = pair_inproc \ + pair_tcp \ + reqrep_inproc \ + reqrep_tcp \ + hwm \ + reqrep_device \ + sub_forward \ + invalid_rep \ + msg_flags \ + reconnect \ + linger if !ON_MINGW -noinst_PROGRAMS += test_shutdown_stress \ - test_pair_ipc \ - test_reqrep_ipc \ - test_timeo +noinst_PROGRAMS += shutdown_stress \ + pair_ipc \ + reqrep_ipc \ + timeo endif -test_pair_inproc_SOURCES = test_pair_inproc.cpp testutil.hpp -test_pair_tcp_SOURCES = test_pair_tcp.cpp testutil.hpp -test_reqrep_inproc_SOURCES = test_reqrep_inproc.cpp testutil.hpp -test_reqrep_tcp_SOURCES = test_reqrep_tcp.cpp testutil.hpp -test_hwm_SOURCES = test_hwm.cpp -test_reqrep_device_SOURCES = test_reqrep_device.cpp -test_sub_forward_SOURCES = test_sub_forward.cpp -test_invalid_rep_SOURCES = test_invalid_rep.cpp -test_msg_flags_SOURCES = test_msg_flags.cpp -test_reconnect_SOURCES = test_reconnect.cpp -test_linger_SOURCES = test_linger.cpp +pair_inproc_SOURCES = pair_inproc.cpp testutil.hpp +pair_tcp_SOURCES = pair_tcp.cpp testutil.hpp +reqrep_inproc_SOURCES = reqrep_inproc.cpp testutil.hpp +reqrep_tcp_SOURCES = reqrep_tcp.cpp testutil.hpp +hwm_SOURCES = hwm.cpp +reqrep_device_SOURCES = reqrep_device.cpp +sub_forward_SOURCES = sub_forward.cpp +invalid_rep_SOURCES = invalid_rep.cpp +msg_flags_SOURCES = msg_flags.cpp +reconnect_SOURCES = reconnect.cpp +linger_SOURCES = linger.cpp if !ON_MINGW -test_shutdown_stress_SOURCES = test_shutdown_stress.cpp -test_pair_ipc_SOURCES = test_pair_ipc.cpp testutil.hpp -test_reqrep_ipc_SOURCES = test_reqrep_ipc.cpp testutil.hpp -test_timeo_SOURCES = test_timeo.cpp +shutdown_stress_SOURCES = shutdown_stress.cpp +pair_ipc_SOURCES = pair_ipc.cpp testutil.hpp +reqrep_ipc_SOURCES = reqrep_ipc.cpp testutil.hpp +timeo_SOURCES = timeo.cpp endif TESTS = $(noinst_PROGRAMS) diff --git a/tests/hwm.cpp b/tests/hwm.cpp new file mode 100644 index 0000000..a5163f9 --- /dev/null +++ b/tests/hwm.cpp @@ -0,0 +1,81 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "hwm test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + // Create pair of socket, each with high watermark of 2. Thus the total + // buffer space should be 4 messages. + void *sb = xs_socket (ctx, XS_PULL); + assert (sb); + int hwm = 2; + int rc = xs_setsockopt (sb, XS_RCVHWM, &hwm, sizeof (hwm)); + assert (rc == 0); + rc = xs_bind (sb, "inproc://a"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_PUSH); + assert (sc); + rc = xs_setsockopt (sc, XS_SNDHWM, &hwm, sizeof (hwm)); + assert (rc == 0); + rc = xs_connect (sc, "inproc://a"); + assert (rc == 0); + + // Try to send 10 messages. Only 4 should succeed. + for (int i = 0; i < 10; i++) + { + int rc = xs_send (sc, NULL, 0, XS_DONTWAIT); + if (i < 4) + assert (rc == 0); + else + assert (rc < 0 && errno == EAGAIN); + } + + // There should be now 4 messages pending, consume them. + for (int i = 0; i != 4; i++) { + rc = xs_recv (sb, NULL, 0, 0); + assert (rc == 0); + } + + // Now it should be possible to send one more. + rc = xs_send (sc, NULL, 0, 0); + assert (rc == 0); + + // Consume the remaining message. + rc = xs_recv (sb, NULL, 0, 0); + assert (rc == 0); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0; +} diff --git a/tests/invalid_rep.cpp b/tests/invalid_rep.cpp new file mode 100644 index 0000000..8a33eb1 --- /dev/null +++ b/tests/invalid_rep.cpp @@ -0,0 +1,88 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2011 VMware, Inc. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "invalid_rep test running...\n"); + + // Create REQ/XREP wiring. + void *ctx = xs_init (1); + assert (ctx); + void *xrep_socket = xs_socket (ctx, XS_XREP); + assert (xrep_socket); + void *req_socket = xs_socket (ctx, XS_REQ); + assert (req_socket); + int linger = 0; + int rc = xs_setsockopt (xrep_socket, XS_LINGER, &linger, sizeof (int)); + assert (rc == 0); + rc = xs_setsockopt (req_socket, XS_LINGER, &linger, sizeof (int)); + assert (rc == 0); + rc = xs_bind (xrep_socket, "inproc://hi"); + assert (rc == 0); + rc = xs_connect (req_socket, "inproc://hi"); + assert (rc == 0); + + // Initial request. + rc = xs_send (req_socket, "r", 1, 0); + assert (rc == 1); + + // Receive the request. + char addr [32]; + int addr_size; + char bottom [1]; + char body [1]; + addr_size = xs_recv (xrep_socket, addr, sizeof (addr), 0); + assert (addr_size >= 0); + rc = xs_recv (xrep_socket, bottom, sizeof (bottom), 0); + assert (rc == 0); + rc = xs_recv (xrep_socket, body, sizeof (body), 0); + assert (rc == 1); + + // Send invalid reply. + rc = xs_send (xrep_socket, addr, addr_size, 0); + assert (rc == addr_size); + + // Send valid reply. + rc = xs_send (xrep_socket, addr, addr_size, XS_SNDMORE); + assert (rc == addr_size); + rc = xs_send (xrep_socket, bottom, 0, XS_SNDMORE); + assert (rc == 0); + rc = xs_send (xrep_socket, "b", 1, 0); + assert (rc == 1); + + // Check whether we've got the valid reply. + rc = xs_recv (req_socket, body, sizeof (body), 0); + assert (rc == 1); + assert (body [0] == 'b'); + + // Tear down the wiring. + rc = xs_close (xrep_socket); + assert (rc == 0); + rc = xs_close (req_socket); + assert (rc == 0); + rc = xs_term (ctx); + assert (rc == 0); + + return 0; +} + diff --git a/tests/linger.cpp b/tests/linger.cpp new file mode 100644 index 0000000..a9feec3 --- /dev/null +++ b/tests/linger.cpp @@ -0,0 +1,59 @@ +/* + Copyright (c) 2012 250bpm s.r.o. + Copyright (c) 2012 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "linger test running...\n"); + + // Create REQ/XREP wiring. + void *ctx = xs_init (1); + assert (ctx); + void *s = xs_socket (ctx, XS_PUSH); + assert (s); + + // Set linger to 0.1 second. + int linger = 100; + int rc = xs_setsockopt (s, XS_LINGER, &linger, sizeof (int)); + + // Connect to non-existent endpoing. + assert (rc == 0); + rc = xs_connect (s, "ipc:///tmp/this-file-does-not-exist"); + assert (rc == 0); + + // Send a message. + rc = xs_send (s, "r", 1, 0); + assert (rc == 1); + + // Close the socket. + rc = xs_close (s); + assert (rc == 0); + + // Terminate the context. This should take 0.1 second. + void *watch = xs_stopwatch_start (); + rc = xs_term (ctx); + assert (rc == 0); + int ms = (int) xs_stopwatch_stop (watch) / 1000; + assert (ms > 50 && ms < 150); + + return 0; +} + diff --git a/tests/msg_flags.cpp b/tests/msg_flags.cpp new file mode 100644 index 0000000..326b2b4 --- /dev/null +++ b/tests/msg_flags.cpp @@ -0,0 +1,82 @@ +/* + Copyright (c) 2011-2012 250bpm s.r.o. + Copyright (c) 2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "msg_flags test running...\n"); + + // Create the infrastructure + void *ctx = xs_init (1); + assert (ctx); + void *sb = xs_socket (ctx, XS_XREP); + assert (sb); + int rc = xs_bind (sb, "inproc://a"); + assert (rc == 0); + void *sc = xs_socket (ctx, XS_XREQ); + assert (sc); + rc = xs_connect (sc, "inproc://a"); + assert (rc == 0); + + // Send 2-part message. + rc = xs_send (sc, "A", 1, XS_SNDMORE); + assert (rc == 1); + rc = xs_send (sc, "B", 1, 0); + assert (rc == 1); + + // Identity comes first. + xs_msg_t msg; + rc = xs_msg_init (&msg); + assert (rc == 0); + rc = xs_recvmsg (sb, &msg, 0); + assert (rc >= 0); + int more; + size_t more_size = sizeof (more); + rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size); + assert (rc == 0); + assert (more == 1); + + // Then the first part of the message body. + rc = xs_recvmsg (sb, &msg, 0); + assert (rc == 1); + more_size = sizeof (more); + rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size); + assert (rc == 0); + assert (more == 1); + + // And finally, the second part of the message body. + rc = xs_recvmsg (sb, &msg, 0); + assert (rc == 1); + more_size = sizeof (more); + rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size); + assert (rc == 0); + assert (more == 0); + + // Deallocate the infrastructure. + rc = xs_close (sc); + assert (rc == 0); + rc = xs_close (sb); + assert (rc == 0); + rc = xs_term (ctx); + assert (rc == 0); + return 0 ; +} + diff --git a/tests/pair_inproc.cpp b/tests/pair_inproc.cpp new file mode 100644 index 0000000..8d4202a --- /dev/null +++ b/tests/pair_inproc.cpp @@ -0,0 +1,52 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "pair_inproc test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + void *sb = xs_socket (ctx, XS_PAIR); + assert (sb); + int rc = xs_bind (sb, "inproc://a"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_PAIR); + assert (sc); + rc = xs_connect (sc, "inproc://a"); + assert (rc == 0); + + bounce (sb, sc); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/pair_ipc.cpp b/tests/pair_ipc.cpp new file mode 100644 index 0000000..c9dd5ae --- /dev/null +++ b/tests/pair_ipc.cpp @@ -0,0 +1,52 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "pair_ipc test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + void *sb = xs_socket (ctx, XS_PAIR); + assert (sb); + int rc = xs_bind (sb, "ipc:///tmp/tester"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_PAIR); + assert (sc); + rc = xs_connect (sc, "ipc:///tmp/tester"); + assert (rc == 0); + + bounce (sb, sc); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/pair_tcp.cpp b/tests/pair_tcp.cpp new file mode 100644 index 0000000..9e71159 --- /dev/null +++ b/tests/pair_tcp.cpp @@ -0,0 +1,53 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2011 iMatix Corporation + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "pair_tcp test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + void *sb = xs_socket (ctx, XS_PAIR); + assert (sb); + int rc = xs_bind (sb, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_PAIR); + assert (sc); + rc = xs_connect (sc, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + bounce (sb, sc); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/reconnect.cpp b/tests/reconnect.cpp new file mode 100644 index 0000000..6442b38 --- /dev/null +++ b/tests/reconnect.cpp @@ -0,0 +1,87 @@ +/* + Copyright (c) 2012 250bpm s.r.o. + Copyright (c) 2012 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "reconnect test running...\n"); + + // Create the basic infrastructure. + void *ctx = xs_init (1); + assert (ctx); + void *push = xs_socket (ctx, XS_PUSH); + assert (push); + void *pull = xs_socket (ctx, XS_PULL); + 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 == 0); + rc = xs_send (push, "ABC", 3, 0); + assert (rc == 3); + + // Wait a while for few attempts to reconnect to happen. + xs_sleep (1); + + // Bind the peer and get the message. + rc = xs_bind (pull, "tcp://127.0.0.1:5560"); + assert (rc == 0); + unsigned char buf [3]; + rc = xs_recv (pull, buf, sizeof (buf), 0); + assert (rc == 3); + + // Clean up. + rc = xs_close (push); + assert (rc == 0); + rc = xs_close (pull); + assert (rc == 0); + + // Now, let's test the same scenario with IPC. + push = xs_socket (ctx, XS_PUSH); + assert (push); + pull = xs_socket (ctx, XS_PULL); + assert (push); + + // Connect before bind was done at the peer and send one message. + rc = xs_connect (push, "ipc:///tmp/tester"); + assert (rc == 0); + rc = xs_send (push, "ABC", 3, 0); + assert (rc == 3); + + // Wait a while for few attempts to reconnect to happen. + xs_sleep (1); + + // Bind the peer and get the message. + rc = xs_bind (pull, "ipc:///tmp/tester"); + assert (rc == 0); + rc = xs_recv (pull, buf, sizeof (buf), 0); + assert (rc == 3); + + // Clean up. + rc = xs_close (push); + assert (rc == 0); + rc = xs_close (pull); + assert (rc == 0); + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/reqrep_device.cpp b/tests/reqrep_device.cpp new file mode 100644 index 0000000..8b0d807 --- /dev/null +++ b/tests/reqrep_device.cpp @@ -0,0 +1,138 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2011 VMware, Inc. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "reqrep_device test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + // Create a req/rep device. + void *xreq = xs_socket (ctx, XS_XREQ); + assert (xreq); + int rc = xs_bind (xreq, "tcp://127.0.0.1:5560"); + assert (rc == 0); + void *xrep = xs_socket (ctx, XS_XREP); + assert (xrep); + rc = xs_bind (xrep, "tcp://127.0.0.1:5561"); + assert (rc == 0); + + // Create a worker. + void *rep = xs_socket (ctx, XS_REP); + assert (rep); + rc = xs_connect (rep, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + // Create a client. + void *req = xs_socket (ctx, XS_REQ); + assert (req); + rc = xs_connect (req, "tcp://127.0.0.1:5561"); + assert (rc == 0); + + // Send a request. + rc = xs_send (req, "ABC", 3, XS_SNDMORE); + assert (rc == 3); + rc = xs_send (req, "DEF", 3, 0); + 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); + rc = xs_recvmsg (xrep, &msg, 0); + assert (rc >= 0); + int rcvmore; + size_t sz = sizeof (rcvmore); + rc = xs_getsockopt (xrep, XS_RCVMORE, &rcvmore, &sz); + assert (rc == 0); + rc = xs_sendmsg (xreq, &msg, rcvmore ? XS_SNDMORE : 0); + assert (rc >= 0); + } + + // Receive the request. + char buff [3]; + rc = xs_recv (rep, buff, 3, 0); + 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); + assert (rcvmore); + rc = xs_recv (rep, buff, 3, 0); + assert (rc == 3); + assert (memcmp (buff, "DEF", 3) == 0); + rc = xs_getsockopt (rep, XS_RCVMORE, &rcvmore, &sz); + assert (rc == 0); + assert (!rcvmore); + + // Send the reply. + rc = xs_send (rep, "GHI", 3, XS_SNDMORE); + assert (rc == 3); + rc = xs_send (rep, "JKL", 3, 0); + 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); + rc = xs_recvmsg (xreq, &msg, 0); + assert (rc >= 0); + int rcvmore; + rc = xs_getsockopt (xreq, XS_RCVMORE, &rcvmore, &sz); + assert (rc == 0); + rc = xs_sendmsg (xrep, &msg, rcvmore ? XS_SNDMORE : 0); + assert (rc >= 0); + } + + // Receive the reply. + rc = xs_recv (req, buff, 3, 0); + assert (rc == 3); + assert (memcmp (buff, "GHI", 3) == 0); + rc = xs_getsockopt (req, XS_RCVMORE, &rcvmore, &sz); + assert (rc == 0); + assert (rcvmore); + rc = xs_recv (req, buff, 3, 0); + assert (rc == 3); + assert (memcmp (buff, "JKL", 3) == 0); + rc = xs_getsockopt (req, XS_RCVMORE, &rcvmore, &sz); + assert (rc == 0); + assert (!rcvmore); + + // Clean up. + rc = xs_close (req); + assert (rc == 0); + rc = xs_close (rep); + assert (rc == 0); + rc = xs_close (xrep); + assert (rc == 0); + rc = xs_close (xreq); + assert (rc == 0); + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/reqrep_inproc.cpp b/tests/reqrep_inproc.cpp new file mode 100644 index 0000000..b056a6a --- /dev/null +++ b/tests/reqrep_inproc.cpp @@ -0,0 +1,52 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "reqrep_inproc test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + void *sb = xs_socket (ctx, XS_REP); + assert (sb); + int rc = xs_bind (sb, "inproc://a"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_REQ); + assert (sc); + rc = xs_connect (sc, "inproc://a"); + assert (rc == 0); + + bounce (sb, sc); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/reqrep_ipc.cpp b/tests/reqrep_ipc.cpp new file mode 100644 index 0000000..3d1092e --- /dev/null +++ b/tests/reqrep_ipc.cpp @@ -0,0 +1,52 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "reqrep_ipc test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + void *sb = xs_socket (ctx, XS_REP); + assert (sb); + int rc = xs_bind (sb, "ipc:///tmp/tester"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_REQ); + assert (sc); + rc = xs_connect (sc, "ipc:///tmp/tester"); + assert (rc == 0); + + bounce (sb, sc); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/reqrep_tcp.cpp b/tests/reqrep_tcp.cpp new file mode 100644 index 0000000..d66f726 --- /dev/null +++ b/tests/reqrep_tcp.cpp @@ -0,0 +1,53 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2011 iMatix Corporation + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "reqrep_tcp test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + void *sb = xs_socket (ctx, XS_REP); + assert (sb); + int rc = xs_bind (sb, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + void *sc = xs_socket (ctx, XS_REQ); + assert (sc); + rc = xs_connect (sc, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + bounce (sb, sc); + + rc = xs_close (sc); + assert (rc == 0); + + rc = xs_close (sb); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/shutdown_stress.cpp b/tests/shutdown_stress.cpp new file mode 100644 index 0000000..d0156ff --- /dev/null +++ b/tests/shutdown_stress.cpp @@ -0,0 +1,90 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2011 iMatix Corporation + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +#include +#include + +#define THREAD_COUNT 100 + +extern "C" +{ + static void *worker (void *s) + { + int rc; + + rc = xs_connect (s, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + // Start closing the socket while the connecting process is underway. + rc = xs_close (s); + assert (rc == 0); + + return NULL; + } +} + +int XS_TEST_MAIN () +{ + void *ctx; + void *s1; + void *s2; + int i; + int j; + int rc; + pthread_t threads [THREAD_COUNT]; + + fprintf (stderr, "shutdown_stress test running...\n"); + + for (j = 0; j != 10; j++) { + + // Check the shutdown with many parallel I/O threads. + ctx = xs_init (7); + assert (ctx); + + s1 = xs_socket (ctx, XS_PUB); + assert (s1); + + rc = xs_bind (s1, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + for (i = 0; i != THREAD_COUNT; i++) { + s2 = xs_socket (ctx, XS_SUB); + assert (s2); + rc = pthread_create (&threads [i], NULL, worker, s2); + assert (rc == 0); + } + + for (i = 0; i != THREAD_COUNT; i++) { + rc = pthread_join (threads [i], NULL); + assert (rc == 0); + } + + rc = xs_close (s1); + assert (rc == 0); + + rc = xs_term (ctx); + assert (rc == 0); + } + + return 0; +} diff --git a/tests/sub_forward.cpp b/tests/sub_forward.cpp new file mode 100644 index 0000000..2111d5a --- /dev/null +++ b/tests/sub_forward.cpp @@ -0,0 +1,94 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2011 iMatix Corporation + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int XS_TEST_MAIN () +{ + fprintf (stderr, "sub_forward test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + // First, create an intermediate device. + void *xpub = xs_socket (ctx, XS_XPUB); + assert (xpub); + int rc = xs_bind (xpub, "tcp://127.0.0.1:5560"); + assert (rc == 0); + void *xsub = xs_socket (ctx, XS_XSUB); + assert (xsub); + rc = xs_bind (xsub, "tcp://127.0.0.1:5561"); + assert (rc == 0); + + // Create a publisher. + void *pub = xs_socket (ctx, XS_PUB); + assert (pub); + rc = xs_connect (pub, "tcp://127.0.0.1:5561"); + assert (rc == 0); + + // Create a subscriber. + void *sub = xs_socket (ctx, XS_SUB); + assert (sub); + rc = xs_connect (sub, "tcp://127.0.0.1:5560"); + assert (rc == 0); + + // Subscribe for all messages. + rc = xs_setsockopt (sub, XS_SUBSCRIBE, "", 0); + assert (rc == 0); + + // Pass the subscription upstream through the device. + char buff [32]; + rc = xs_recv (xpub, buff, sizeof (buff), 0); + assert (rc >= 0); + rc = xs_send (xsub, buff, rc, 0); + assert (rc >= 0); + + // Wait a bit till the subscription gets to the publisher. + xs_sleep (1); + + // Send an empty message. + rc = xs_send (pub, NULL, 0, 0); + assert (rc == 0); + + // Pass the message downstream through the device. + rc = xs_recv (xsub, buff, sizeof (buff), 0); + assert (rc >= 0); + rc = xs_send (xpub, buff, rc, 0); + assert (rc >= 0); + + // Receive the message in the subscriber. + rc = xs_recv (sub, buff, sizeof (buff), 0); + assert (rc == 0); + + // Clean up. + rc = xs_close (xpub); + assert (rc == 0); + rc = xs_close (xsub); + assert (rc == 0); + rc = xs_close (pub); + assert (rc == 0); + rc = xs_close (sub); + assert (rc == 0); + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} diff --git a/tests/test_hwm.cpp b/tests/test_hwm.cpp deleted file mode 100644 index 1a520c0..0000000 --- a/tests/test_hwm.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_hwm running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - // Create pair of socket, each with high watermark of 2. Thus the total - // buffer space should be 4 messages. - void *sb = xs_socket (ctx, XS_PULL); - assert (sb); - int hwm = 2; - int rc = xs_setsockopt (sb, XS_RCVHWM, &hwm, sizeof (hwm)); - assert (rc == 0); - rc = xs_bind (sb, "inproc://a"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_PUSH); - assert (sc); - rc = xs_setsockopt (sc, XS_SNDHWM, &hwm, sizeof (hwm)); - assert (rc == 0); - rc = xs_connect (sc, "inproc://a"); - assert (rc == 0); - - // Try to send 10 messages. Only 4 should succeed. - for (int i = 0; i < 10; i++) - { - int rc = xs_send (sc, NULL, 0, XS_DONTWAIT); - if (i < 4) - assert (rc == 0); - else - assert (rc < 0 && errno == EAGAIN); - } - - // There should be now 4 messages pending, consume them. - for (int i = 0; i != 4; i++) { - rc = xs_recv (sb, NULL, 0, 0); - assert (rc == 0); - } - - // Now it should be possible to send one more. - rc = xs_send (sc, NULL, 0, 0); - assert (rc == 0); - - // Consume the remaining message. - rc = xs_recv (sb, NULL, 0, 0); - assert (rc == 0); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0; -} diff --git a/tests/test_invalid_rep.cpp b/tests/test_invalid_rep.cpp deleted file mode 100644 index 70a14e5..0000000 --- a/tests/test_invalid_rep.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2011 VMware, Inc. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_invalid_rep running...\n"); - - // Create REQ/XREP wiring. - void *ctx = xs_init (1); - assert (ctx); - void *xrep_socket = xs_socket (ctx, XS_XREP); - assert (xrep_socket); - void *req_socket = xs_socket (ctx, XS_REQ); - assert (req_socket); - int linger = 0; - int rc = xs_setsockopt (xrep_socket, XS_LINGER, &linger, sizeof (int)); - assert (rc == 0); - rc = xs_setsockopt (req_socket, XS_LINGER, &linger, sizeof (int)); - assert (rc == 0); - rc = xs_bind (xrep_socket, "inproc://hi"); - assert (rc == 0); - rc = xs_connect (req_socket, "inproc://hi"); - assert (rc == 0); - - // Initial request. - rc = xs_send (req_socket, "r", 1, 0); - assert (rc == 1); - - // Receive the request. - char addr [32]; - int addr_size; - char bottom [1]; - char body [1]; - addr_size = xs_recv (xrep_socket, addr, sizeof (addr), 0); - assert (addr_size >= 0); - rc = xs_recv (xrep_socket, bottom, sizeof (bottom), 0); - assert (rc == 0); - rc = xs_recv (xrep_socket, body, sizeof (body), 0); - assert (rc == 1); - - // Send invalid reply. - rc = xs_send (xrep_socket, addr, addr_size, 0); - assert (rc == addr_size); - - // Send valid reply. - rc = xs_send (xrep_socket, addr, addr_size, XS_SNDMORE); - assert (rc == addr_size); - rc = xs_send (xrep_socket, bottom, 0, XS_SNDMORE); - assert (rc == 0); - rc = xs_send (xrep_socket, "b", 1, 0); - assert (rc == 1); - - // Check whether we've got the valid reply. - rc = xs_recv (req_socket, body, sizeof (body), 0); - assert (rc == 1); - assert (body [0] == 'b'); - - // Tear down the wiring. - rc = xs_close (xrep_socket); - assert (rc == 0); - rc = xs_close (req_socket); - assert (rc == 0); - rc = xs_term (ctx); - assert (rc == 0); - - return 0; -} - diff --git a/tests/test_linger.cpp b/tests/test_linger.cpp deleted file mode 100644 index 0a5bc49..0000000 --- a/tests/test_linger.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (c) 2012 250bpm s.r.o. - Copyright (c) 2012 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_linger running...\n"); - - // Create REQ/XREP wiring. - void *ctx = xs_init (1); - assert (ctx); - void *s = xs_socket (ctx, XS_PUSH); - assert (s); - - // Set linger to 0.1 second. - int linger = 100; - int rc = xs_setsockopt (s, XS_LINGER, &linger, sizeof (int)); - - // Connect to non-existent endpoing. - assert (rc == 0); - rc = xs_connect (s, "ipc:///tmp/this-file-does-not-exist"); - assert (rc == 0); - - // Send a message. - rc = xs_send (s, "r", 1, 0); - assert (rc == 1); - - // Close the socket. - rc = xs_close (s); - assert (rc == 0); - - // Terminate the context. This should take 0.1 second. - void *watch = xs_stopwatch_start (); - rc = xs_term (ctx); - assert (rc == 0); - int ms = (int) xs_stopwatch_stop (watch) / 1000; - assert (ms > 50 && ms < 150); - - return 0; -} - diff --git a/tests/test_msg_flags.cpp b/tests/test_msg_flags.cpp deleted file mode 100644 index 6c2b819..0000000 --- a/tests/test_msg_flags.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2011-2012 250bpm s.r.o. - Copyright (c) 2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - // Create the infrastructure - void *ctx = xs_init (1); - assert (ctx); - void *sb = xs_socket (ctx, XS_XREP); - assert (sb); - int rc = xs_bind (sb, "inproc://a"); - assert (rc == 0); - void *sc = xs_socket (ctx, XS_XREQ); - assert (sc); - rc = xs_connect (sc, "inproc://a"); - assert (rc == 0); - - // Send 2-part message. - rc = xs_send (sc, "A", 1, XS_SNDMORE); - assert (rc == 1); - rc = xs_send (sc, "B", 1, 0); - assert (rc == 1); - - // Identity comes first. - xs_msg_t msg; - rc = xs_msg_init (&msg); - assert (rc == 0); - rc = xs_recvmsg (sb, &msg, 0); - assert (rc >= 0); - int more; - size_t more_size = sizeof (more); - rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size); - assert (rc == 0); - assert (more == 1); - - // Then the first part of the message body. - rc = xs_recvmsg (sb, &msg, 0); - assert (rc == 1); - more_size = sizeof (more); - rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size); - assert (rc == 0); - assert (more == 1); - - // And finally, the second part of the message body. - rc = xs_recvmsg (sb, &msg, 0); - assert (rc == 1); - more_size = sizeof (more); - rc = xs_getmsgopt (&msg, XS_MORE, &more, &more_size); - assert (rc == 0); - assert (more == 0); - - // Deallocate the infrastructure. - rc = xs_close (sc); - assert (rc == 0); - rc = xs_close (sb); - assert (rc == 0); - rc = xs_term (ctx); - assert (rc == 0); - return 0 ; -} - diff --git a/tests/test_pair_inproc.cpp b/tests/test_pair_inproc.cpp deleted file mode 100644 index 653daca..0000000 --- a/tests/test_pair_inproc.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_pair_inproc running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - void *sb = xs_socket (ctx, XS_PAIR); - assert (sb); - int rc = xs_bind (sb, "inproc://a"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_PAIR); - assert (sc); - rc = xs_connect (sc, "inproc://a"); - assert (rc == 0); - - bounce (sb, sc); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_pair_ipc.cpp b/tests/test_pair_ipc.cpp deleted file mode 100644 index 8e7f17e..0000000 --- a/tests/test_pair_ipc.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_pair_ipc running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - void *sb = xs_socket (ctx, XS_PAIR); - assert (sb); - int rc = xs_bind (sb, "ipc:///tmp/tester"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_PAIR); - assert (sc); - rc = xs_connect (sc, "ipc:///tmp/tester"); - assert (rc == 0); - - bounce (sb, sc); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_pair_tcp.cpp b/tests/test_pair_tcp.cpp deleted file mode 100644 index bf4fcd8..0000000 --- a/tests/test_pair_tcp.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2011 iMatix Corporation - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_pair_tcp running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - void *sb = xs_socket (ctx, XS_PAIR); - assert (sb); - int rc = xs_bind (sb, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_PAIR); - assert (sc); - rc = xs_connect (sc, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - bounce (sb, sc); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_reconnect.cpp b/tests/test_reconnect.cpp deleted file mode 100644 index 7ae505e..0000000 --- a/tests/test_reconnect.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2012 250bpm s.r.o. - Copyright (c) 2012 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_reconnect running...\n"); - - // Create the basic infrastructure. - void *ctx = xs_init (1); - assert (ctx); - void *push = xs_socket (ctx, XS_PUSH); - assert (push); - void *pull = xs_socket (ctx, XS_PULL); - 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 == 0); - rc = xs_send (push, "ABC", 3, 0); - assert (rc == 3); - - // Wait a while for few attempts to reconnect to happen. - xs_sleep (1); - - // Bind the peer and get the message. - rc = xs_bind (pull, "tcp://127.0.0.1:5560"); - assert (rc == 0); - unsigned char buf [3]; - rc = xs_recv (pull, buf, sizeof (buf), 0); - assert (rc == 3); - - // Clean up. - rc = xs_close (push); - assert (rc == 0); - rc = xs_close (pull); - assert (rc == 0); - - // Now, let's test the same scenario with IPC. - push = xs_socket (ctx, XS_PUSH); - assert (push); - pull = xs_socket (ctx, XS_PULL); - assert (push); - - // Connect before bind was done at the peer and send one message. - rc = xs_connect (push, "ipc:///tmp/tester"); - assert (rc == 0); - rc = xs_send (push, "ABC", 3, 0); - assert (rc == 3); - - // Wait a while for few attempts to reconnect to happen. - xs_sleep (1); - - // Bind the peer and get the message. - rc = xs_bind (pull, "ipc:///tmp/tester"); - assert (rc == 0); - rc = xs_recv (pull, buf, sizeof (buf), 0); - assert (rc == 3); - - // Clean up. - rc = xs_close (push); - assert (rc == 0); - rc = xs_close (pull); - assert (rc == 0); - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_reqrep_device.cpp b/tests/test_reqrep_device.cpp deleted file mode 100644 index 68ee347..0000000 --- a/tests/test_reqrep_device.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2011 VMware, Inc. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_reqrep_device running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - // Create a req/rep device. - void *xreq = xs_socket (ctx, XS_XREQ); - assert (xreq); - int rc = xs_bind (xreq, "tcp://127.0.0.1:5560"); - assert (rc == 0); - void *xrep = xs_socket (ctx, XS_XREP); - assert (xrep); - rc = xs_bind (xrep, "tcp://127.0.0.1:5561"); - assert (rc == 0); - - // Create a worker. - void *rep = xs_socket (ctx, XS_REP); - assert (rep); - rc = xs_connect (rep, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - // Create a client. - void *req = xs_socket (ctx, XS_REQ); - assert (req); - rc = xs_connect (req, "tcp://127.0.0.1:5561"); - assert (rc == 0); - - // Send a request. - rc = xs_send (req, "ABC", 3, XS_SNDMORE); - assert (rc == 3); - rc = xs_send (req, "DEF", 3, 0); - 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); - rc = xs_recvmsg (xrep, &msg, 0); - assert (rc >= 0); - int rcvmore; - size_t sz = sizeof (rcvmore); - rc = xs_getsockopt (xrep, XS_RCVMORE, &rcvmore, &sz); - assert (rc == 0); - rc = xs_sendmsg (xreq, &msg, rcvmore ? XS_SNDMORE : 0); - assert (rc >= 0); - } - - // Receive the request. - char buff [3]; - rc = xs_recv (rep, buff, 3, 0); - 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); - assert (rcvmore); - rc = xs_recv (rep, buff, 3, 0); - assert (rc == 3); - assert (memcmp (buff, "DEF", 3) == 0); - rc = xs_getsockopt (rep, XS_RCVMORE, &rcvmore, &sz); - assert (rc == 0); - assert (!rcvmore); - - // Send the reply. - rc = xs_send (rep, "GHI", 3, XS_SNDMORE); - assert (rc == 3); - rc = xs_send (rep, "JKL", 3, 0); - 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); - rc = xs_recvmsg (xreq, &msg, 0); - assert (rc >= 0); - int rcvmore; - rc = xs_getsockopt (xreq, XS_RCVMORE, &rcvmore, &sz); - assert (rc == 0); - rc = xs_sendmsg (xrep, &msg, rcvmore ? XS_SNDMORE : 0); - assert (rc >= 0); - } - - // Receive the reply. - rc = xs_recv (req, buff, 3, 0); - assert (rc == 3); - assert (memcmp (buff, "GHI", 3) == 0); - rc = xs_getsockopt (req, XS_RCVMORE, &rcvmore, &sz); - assert (rc == 0); - assert (rcvmore); - rc = xs_recv (req, buff, 3, 0); - assert (rc == 3); - assert (memcmp (buff, "JKL", 3) == 0); - rc = xs_getsockopt (req, XS_RCVMORE, &rcvmore, &sz); - assert (rc == 0); - assert (!rcvmore); - - // Clean up. - rc = xs_close (req); - assert (rc == 0); - rc = xs_close (rep); - assert (rc == 0); - rc = xs_close (xrep); - assert (rc == 0); - rc = xs_close (xreq); - assert (rc == 0); - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_reqrep_inproc.cpp b/tests/test_reqrep_inproc.cpp deleted file mode 100644 index 89080eb..0000000 --- a/tests/test_reqrep_inproc.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_reqrep_inproc running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - void *sb = xs_socket (ctx, XS_REP); - assert (sb); - int rc = xs_bind (sb, "inproc://a"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_REQ); - assert (sc); - rc = xs_connect (sc, "inproc://a"); - assert (rc == 0); - - bounce (sb, sc); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_reqrep_ipc.cpp b/tests/test_reqrep_ipc.cpp deleted file mode 100644 index 557b8af..0000000 --- a/tests/test_reqrep_ipc.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_reqrep_ipc running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - void *sb = xs_socket (ctx, XS_REP); - assert (sb); - int rc = xs_bind (sb, "ipc:///tmp/tester"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_REQ); - assert (sc); - rc = xs_connect (sc, "ipc:///tmp/tester"); - assert (rc == 0); - - bounce (sb, sc); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_reqrep_tcp.cpp b/tests/test_reqrep_tcp.cpp deleted file mode 100644 index e86f947..0000000 --- a/tests/test_reqrep_tcp.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2011 iMatix Corporation - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_reqrep_tcp running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - void *sb = xs_socket (ctx, XS_REP); - assert (sb); - int rc = xs_bind (sb, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - void *sc = xs_socket (ctx, XS_REQ); - assert (sc); - rc = xs_connect (sc, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - bounce (sb, sc); - - rc = xs_close (sc); - assert (rc == 0); - - rc = xs_close (sb); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_shutdown_stress.cpp b/tests/test_shutdown_stress.cpp deleted file mode 100644 index 7c36106..0000000 --- a/tests/test_shutdown_stress.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2011 iMatix Corporation - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -#include -#include - -#define THREAD_COUNT 100 - -extern "C" -{ - static void *worker (void *s) - { - int rc; - - rc = xs_connect (s, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - // Start closing the socket while the connecting process is underway. - rc = xs_close (s); - assert (rc == 0); - - return NULL; - } -} - -int XS_TEST_MAIN () -{ - void *ctx; - void *s1; - void *s2; - int i; - int j; - int rc; - pthread_t threads [THREAD_COUNT]; - - fprintf (stderr, "test_shutdown_stress running...\n"); - - for (j = 0; j != 10; j++) { - - // Check the shutdown with many parallel I/O threads. - ctx = xs_init (7); - assert (ctx); - - s1 = xs_socket (ctx, XS_PUB); - assert (s1); - - rc = xs_bind (s1, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - for (i = 0; i != THREAD_COUNT; i++) { - s2 = xs_socket (ctx, XS_SUB); - assert (s2); - rc = pthread_create (&threads [i], NULL, worker, s2); - assert (rc == 0); - } - - for (i = 0; i != THREAD_COUNT; i++) { - rc = pthread_join (threads [i], NULL); - assert (rc == 0); - } - - rc = xs_close (s1); - assert (rc == 0); - - rc = xs_term (ctx); - assert (rc == 0); - } - - return 0; -} diff --git a/tests/test_sub_forward.cpp b/tests/test_sub_forward.cpp deleted file mode 100644 index dafd338..0000000 --- a/tests/test_sub_forward.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2011 iMatix Corporation - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_sub_forward running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - // First, create an intermediate device. - void *xpub = xs_socket (ctx, XS_XPUB); - assert (xpub); - int rc = xs_bind (xpub, "tcp://127.0.0.1:5560"); - assert (rc == 0); - void *xsub = xs_socket (ctx, XS_XSUB); - assert (xsub); - rc = xs_bind (xsub, "tcp://127.0.0.1:5561"); - assert (rc == 0); - - // Create a publisher. - void *pub = xs_socket (ctx, XS_PUB); - assert (pub); - rc = xs_connect (pub, "tcp://127.0.0.1:5561"); - assert (rc == 0); - - // Create a subscriber. - void *sub = xs_socket (ctx, XS_SUB); - assert (sub); - rc = xs_connect (sub, "tcp://127.0.0.1:5560"); - assert (rc == 0); - - // Subscribe for all messages. - rc = xs_setsockopt (sub, XS_SUBSCRIBE, "", 0); - assert (rc == 0); - - // Pass the subscription upstream through the device. - char buff [32]; - rc = xs_recv (xpub, buff, sizeof (buff), 0); - assert (rc >= 0); - rc = xs_send (xsub, buff, rc, 0); - assert (rc >= 0); - - // Wait a bit till the subscription gets to the publisher. - xs_sleep (1); - - // Send an empty message. - rc = xs_send (pub, NULL, 0, 0); - assert (rc == 0); - - // Pass the message downstream through the device. - rc = xs_recv (xsub, buff, sizeof (buff), 0); - assert (rc >= 0); - rc = xs_send (xpub, buff, rc, 0); - assert (rc >= 0); - - // Receive the message in the subscriber. - rc = xs_recv (sub, buff, sizeof (buff), 0); - assert (rc == 0); - - // Clean up. - rc = xs_close (xpub); - assert (rc == 0); - rc = xs_close (xsub); - assert (rc == 0); - rc = xs_close (pub); - assert (rc == 0); - rc = xs_close (sub); - assert (rc == 0); - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} diff --git a/tests/test_timeo.cpp b/tests/test_timeo.cpp deleted file mode 100644 index 29ed634..0000000 --- a/tests/test_timeo.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "testutil.hpp" - -#include - -extern "C" -{ - void *worker(void *ctx) - { - // Worker thread connects after delay of 1 second. Then it waits - // for 1 more second, so that async connect has time to succeed. - xs_sleep (1); - void *sc = xs_socket (ctx, XS_PUSH); - assert (sc); - int rc = xs_connect (sc, "inproc://timeout_test"); - assert (rc == 0); - xs_sleep (1); - rc = xs_close (sc); - assert (rc == 0); - return NULL; - } -} - -int XS_TEST_MAIN () -{ - fprintf (stderr, "test_timeo running...\n"); - - void *ctx = xs_init (1); - assert (ctx); - - // Create a disconnected socket. - void *sb = xs_socket (ctx, XS_PULL); - assert (sb); - int rc = xs_bind (sb, "inproc://timeout_test"); - assert (rc == 0); - - // Check whether non-blocking recv returns immediately. - char buf [] = "12345678ABCDEFGH12345678abcdefgh"; - rc = xs_recv (sb, buf, 32, XS_DONTWAIT); - assert (rc == -1); - assert (xs_errno() == EAGAIN); - - // Check whether recv timeout is honoured. - int timeout = 500; - size_t timeout_size = sizeof timeout; - rc = xs_setsockopt(sb, XS_RCVTIMEO, &timeout, timeout_size); - assert (rc == 0); - void *watch = xs_stopwatch_start (); - rc = xs_recv (sb, buf, 32, 0); - assert (rc == -1); - assert (xs_errno () == EAGAIN); - unsigned long elapsed = xs_stopwatch_stop (watch); - assert (elapsed > 440000 && elapsed < 550000); - - // Check whether connection during the wait doesn't distort the timeout. - timeout = 2000; - rc = xs_setsockopt(sb, XS_RCVTIMEO, &timeout, timeout_size); - assert (rc == 0); - pthread_t thread; - rc = pthread_create (&thread, NULL, worker, ctx); - assert (rc == 0); - watch = xs_stopwatch_start (); - rc = xs_recv (sb, buf, 32, 0); - assert (rc == -1); - assert (xs_errno () == EAGAIN); - elapsed = xs_stopwatch_stop (watch); - assert (elapsed > 1900000 && elapsed < 2100000); - rc = pthread_join (thread, NULL); - assert (rc == 0); - - // Check that timeouts don't break normal message transfer. - void *sc = xs_socket (ctx, XS_PUSH); - assert (sc); - rc = xs_setsockopt(sb, XS_RCVTIMEO, &timeout, timeout_size); - assert (rc == 0); - rc = xs_setsockopt(sb, XS_SNDTIMEO, &timeout, timeout_size); - assert (rc == 0); - rc = xs_connect (sc, "inproc://timeout_test"); - assert (rc == 0); - rc = xs_send (sc, buf, 32, 0); - assert (rc == 32); - rc = xs_recv (sb, buf, 32, 0); - assert (rc == 32); - - // Clean-up. - rc = xs_close (sc); - assert (rc == 0); - rc = xs_close (sb); - assert (rc == 0); - rc = xs_term (ctx); - assert (rc == 0); - - return 0 ; -} - diff --git a/tests/timeo.cpp b/tests/timeo.cpp new file mode 100644 index 0000000..f718056 --- /dev/null +++ b/tests/timeo.cpp @@ -0,0 +1,114 @@ +/* + Copyright (c) 2010-2012 250bpm s.r.o. + Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +#include + +extern "C" +{ + void *worker(void *ctx) + { + // Worker thread connects after delay of 1 second. Then it waits + // for 1 more second, so that async connect has time to succeed. + xs_sleep (1); + void *sc = xs_socket (ctx, XS_PUSH); + assert (sc); + int rc = xs_connect (sc, "inproc://timeout_test"); + assert (rc == 0); + xs_sleep (1); + rc = xs_close (sc); + assert (rc == 0); + return NULL; + } +} + +int XS_TEST_MAIN () +{ + fprintf (stderr, "timeo test running...\n"); + + void *ctx = xs_init (1); + assert (ctx); + + // Create a disconnected socket. + void *sb = xs_socket (ctx, XS_PULL); + assert (sb); + int rc = xs_bind (sb, "inproc://timeout_test"); + assert (rc == 0); + + // Check whether non-blocking recv returns immediately. + char buf [] = "12345678ABCDEFGH12345678abcdefgh"; + rc = xs_recv (sb, buf, 32, XS_DONTWAIT); + assert (rc == -1); + assert (xs_errno() == EAGAIN); + + // Check whether recv timeout is honoured. + int timeout = 500; + size_t timeout_size = sizeof timeout; + rc = xs_setsockopt(sb, XS_RCVTIMEO, &timeout, timeout_size); + assert (rc == 0); + void *watch = xs_stopwatch_start (); + rc = xs_recv (sb, buf, 32, 0); + assert (rc == -1); + assert (xs_errno () == EAGAIN); + unsigned long elapsed = xs_stopwatch_stop (watch); + assert (elapsed > 440000 && elapsed < 550000); + + // Check whether connection during the wait doesn't distort the timeout. + timeout = 2000; + rc = xs_setsockopt(sb, XS_RCVTIMEO, &timeout, timeout_size); + assert (rc == 0); + pthread_t thread; + rc = pthread_create (&thread, NULL, worker, ctx); + assert (rc == 0); + watch = xs_stopwatch_start (); + rc = xs_recv (sb, buf, 32, 0); + assert (rc == -1); + assert (xs_errno () == EAGAIN); + elapsed = xs_stopwatch_stop (watch); + assert (elapsed > 1900000 && elapsed < 2100000); + rc = pthread_join (thread, NULL); + assert (rc == 0); + + // Check that timeouts don't break normal message transfer. + void *sc = xs_socket (ctx, XS_PUSH); + assert (sc); + rc = xs_setsockopt(sb, XS_RCVTIMEO, &timeout, timeout_size); + assert (rc == 0); + rc = xs_setsockopt(sb, XS_SNDTIMEO, &timeout, timeout_size); + assert (rc == 0); + rc = xs_connect (sc, "inproc://timeout_test"); + assert (rc == 0); + rc = xs_send (sc, buf, 32, 0); + assert (rc == 32); + rc = xs_recv (sb, buf, 32, 0); + assert (rc == 32); + + // Clean-up. + rc = xs_close (sc); + assert (rc == 0); + rc = xs_close (sb); + assert (rc == 0); + rc = xs_term (ctx); + assert (rc == 0); + + return 0 ; +} + -- cgit v1.2.3