mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 10:52:56 +01:00
Port tests to windows and add to cmake build.
This commit is contained in:
parent
e16a6af0c7
commit
7f74fc7c99
@ -308,19 +308,19 @@ set(cxx-sources
|
|||||||
kqueue.cpp
|
kqueue.cpp
|
||||||
lb.cpp
|
lb.cpp
|
||||||
mailbox.cpp
|
mailbox.cpp
|
||||||
mechanism.cpp
|
mechanism.cpp
|
||||||
msg.cpp
|
msg.cpp
|
||||||
mtrie.cpp
|
mtrie.cpp
|
||||||
object.cpp
|
object.cpp
|
||||||
options.cpp
|
options.cpp
|
||||||
own.cpp
|
own.cpp
|
||||||
null_mechanism.cpp
|
null_mechanism.cpp
|
||||||
pair.cpp
|
pair.cpp
|
||||||
pgm_receiver.cpp
|
pgm_receiver.cpp
|
||||||
pgm_sender.cpp
|
pgm_sender.cpp
|
||||||
pgm_socket.cpp
|
pgm_socket.cpp
|
||||||
pipe.cpp
|
pipe.cpp
|
||||||
plain_mechanism.cpp
|
plain_mechanism.cpp
|
||||||
poll.cpp
|
poll.cpp
|
||||||
poller_base.cpp
|
poller_base.cpp
|
||||||
precompiled.cpp
|
precompiled.cpp
|
||||||
@ -576,6 +576,52 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why?
|
|||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
set(tests
|
||||||
|
test_connect_delay
|
||||||
|
test_connect_resolve
|
||||||
|
test_ctx_options
|
||||||
|
test_disconnect_inproc
|
||||||
|
test_hwm
|
||||||
|
test_invalid_rep
|
||||||
|
test_iov
|
||||||
|
test_last_endpoint
|
||||||
|
test_monitor
|
||||||
|
test_msg_flags
|
||||||
|
test_pair_inproc
|
||||||
|
test_pair_ipc
|
||||||
|
test_pair_tcp
|
||||||
|
test_probe_router
|
||||||
|
test_raw_sock
|
||||||
|
test_req_request_ids
|
||||||
|
test_req_strict
|
||||||
|
test_reqrep_device
|
||||||
|
test_reqrep_inproc
|
||||||
|
test_reqrep_ipc
|
||||||
|
test_reqrep_tcp
|
||||||
|
test_router_mandatory
|
||||||
|
test_security
|
||||||
|
test_security_curve
|
||||||
|
test_shutdown_stress
|
||||||
|
test_spec_dealer
|
||||||
|
test_spec_pushpull
|
||||||
|
test_spec_rep
|
||||||
|
test_spec_req
|
||||||
|
test_spec_router
|
||||||
|
test_stream
|
||||||
|
test_sub_forward
|
||||||
|
test_term_endpoint
|
||||||
|
test_timeo)
|
||||||
|
|
||||||
|
foreach(test ${tests})
|
||||||
|
add_executable(${test} tests/${test}.cpp)
|
||||||
|
target_link_libraries(${test} libzmq)
|
||||||
|
|
||||||
|
if(RT_LIBRARY)
|
||||||
|
target_link_libraries(${test} ${RT_LIBRARY})
|
||||||
|
endif()
|
||||||
|
add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH}/Debug COMMAND ${test})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# installer
|
# installer
|
||||||
|
@ -56,6 +56,12 @@ ZMQ_EXPORT unsigned long zmq_stopwatch_stop (void *watch_);
|
|||||||
/* Sleeps for specified number of seconds. */
|
/* Sleeps for specified number of seconds. */
|
||||||
ZMQ_EXPORT void zmq_sleep (int seconds_);
|
ZMQ_EXPORT void zmq_sleep (int seconds_);
|
||||||
|
|
||||||
|
/* Start a thread. Returns a handle to the thread. */
|
||||||
|
ZMQ_EXPORT void *zmq_threadstart(void* func, void* arg);
|
||||||
|
|
||||||
|
/* Wait for thread to complete then free up resources. */
|
||||||
|
ZMQ_EXPORT void zmq_threadclose(void* thread);
|
||||||
|
|
||||||
#undef ZMQ_EXPORT
|
#undef ZMQ_EXPORT
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "stdint.hpp"
|
#include "stdint.hpp"
|
||||||
#include "clock.hpp"
|
#include "clock.hpp"
|
||||||
#include "err.hpp"
|
#include "err.hpp"
|
||||||
|
#include "thread.hpp"
|
||||||
|
|
||||||
#if !defined ZMQ_HAVE_WINDOWS
|
#if !defined ZMQ_HAVE_WINDOWS
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -57,3 +58,17 @@ unsigned long zmq_stopwatch_stop (void *watch_)
|
|||||||
free (watch_);
|
free (watch_);
|
||||||
return (unsigned long) (end - start);
|
return (unsigned long) (end - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *zmq_threadstart(void* func, void* arg)
|
||||||
|
{
|
||||||
|
zmq::thread_t* thread = new zmq::thread_t;
|
||||||
|
thread->start(static_cast<zmq::thread_fn*>(func), arg);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zmq_threadclose(void* thread)
|
||||||
|
{
|
||||||
|
zmq::thread_t* pThread = static_cast<zmq::thread_t*>(thread);
|
||||||
|
pThread->stop();
|
||||||
|
delete pThread;
|
||||||
|
}
|
||||||
|
@ -18,17 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
|
#include "../include/zmq_utils.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
int val;
|
int val;
|
||||||
int rc;
|
int rc;
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
@ -198,11 +197,10 @@ int main (void)
|
|||||||
|
|
||||||
rc = zmq_close (backend);
|
rc = zmq_close (backend);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Give time to process disconnect
|
// Give time to process disconnect
|
||||||
// There's no way to do this except with a sleep
|
// There's no way to do this except with a sleep
|
||||||
struct timespec t = { 0, 250 * 1000000 };
|
zmq_sleep(1);
|
||||||
nanosleep (&t, NULL);
|
|
||||||
|
|
||||||
// Send a message, should fail
|
// Send a message, should fail
|
||||||
rc = zmq_send (frontend, "Hello", 5, ZMQ_DONTWAIT);
|
rc = zmq_send (frontend, "Hello", 5, ZMQ_DONTWAIT);
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
// Set up our context and sockets
|
// Set up our context and sockets
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <zmq.h>
|
#include <zmq.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include "testutil.hpp"
|
||||||
|
|
||||||
/// Initialize a zeromq message with a given null-terminated string
|
/// Initialize a zeromq message with a given null-terminated string
|
||||||
#define ZMQ_PREPARE_STRING(msg, data, size) \
|
#define ZMQ_PREPARE_STRING(msg, data, size) \
|
||||||
@ -31,6 +31,7 @@ int publicationsReceived = 0;
|
|||||||
bool isSubscribed = false;
|
bool isSubscribed = false;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
setup_test_environment();
|
||||||
void* context = zmq_ctx_new();
|
void* context = zmq_ctx_new();
|
||||||
void* pubSocket;
|
void* pubSocket;
|
||||||
void* subSocket;
|
void* subSocket;
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#undef NDEBUG
|
#include "testutil.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
// Create REQ/ROUTER wiring.
|
// Create REQ/ROUTER wiring.
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
@ -18,12 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
|
#include "../include/zmq_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#undef NDEBUG
|
#include "testutil.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
// XSI vector I/O
|
// XSI vector I/O
|
||||||
#if defined ZMQ_HAVE_UIO
|
#if defined ZMQ_HAVE_UIO
|
||||||
@ -37,6 +36,7 @@ struct iovec {
|
|||||||
|
|
||||||
void do_check(void* sb, void* sc, unsigned int msgsz)
|
void do_check(void* sb, void* sc, unsigned int msgsz)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
int sum =0;
|
int sum =0;
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
@ -85,7 +85,7 @@ int main (void)
|
|||||||
rc = zmq_bind (sb, "inproc://a");
|
rc = zmq_bind (sb, "inproc://a");
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
::sleep(1);
|
zmq_sleep(1);
|
||||||
void *sc = zmq_socket (ctx, ZMQ_PUSH);
|
void *sc = zmq_socket (ctx, ZMQ_PUSH);
|
||||||
|
|
||||||
rc = zmq_connect (sc, "inproc://a");
|
rc = zmq_connect (sc, "inproc://a");
|
||||||
@ -107,5 +107,5 @@ int main (void)
|
|||||||
rc = zmq_ctx_term (ctx);
|
rc = zmq_ctx_term (ctx);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
static void do_bind_and_verify (void *s, const char *endpoint)
|
static void do_bind_and_verify (void *s, const char *endpoint)
|
||||||
{
|
{
|
||||||
@ -35,6 +33,7 @@ static void do_bind_and_verify (void *s, const char *endpoint)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
// Create the infrastructure
|
// Create the infrastructure
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <pthread.h>
|
#include "../include/zmq_utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
|
||||||
// REQ socket events handled
|
// REQ socket events handled
|
||||||
@ -180,11 +179,12 @@ static void *rep_socket_monitor (void *ctx)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
void *req;
|
void *req;
|
||||||
void *req2;
|
void *req2;
|
||||||
void *rep;
|
void *rep;
|
||||||
pthread_t threads [3];
|
void* threads [3];
|
||||||
|
|
||||||
addr = "tcp://127.0.0.1:5560";
|
addr = "tcp://127.0.0.1:5560";
|
||||||
|
|
||||||
@ -208,8 +208,7 @@ int main (void)
|
|||||||
// REP socket monitor, all events
|
// REP socket monitor, all events
|
||||||
rc = zmq_socket_monitor (rep, "inproc://monitor.rep", ZMQ_EVENT_ALL);
|
rc = zmq_socket_monitor (rep, "inproc://monitor.rep", ZMQ_EVENT_ALL);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = pthread_create (&threads [0], NULL, rep_socket_monitor, ctx);
|
threads [0] = zmq_threadstart(rep_socket_monitor, ctx);
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// REQ socket
|
// REQ socket
|
||||||
req = zmq_socket (ctx, ZMQ_REQ);
|
req = zmq_socket (ctx, ZMQ_REQ);
|
||||||
@ -218,9 +217,8 @@ int main (void)
|
|||||||
// REQ socket monitor, all events
|
// REQ socket monitor, all events
|
||||||
rc = zmq_socket_monitor (req, "inproc://monitor.req", ZMQ_EVENT_ALL);
|
rc = zmq_socket_monitor (req, "inproc://monitor.req", ZMQ_EVENT_ALL);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = pthread_create (&threads [1], NULL, req_socket_monitor, ctx);
|
threads [1] = zmq_threadstart(req_socket_monitor, ctx);
|
||||||
assert (rc == 0);
|
zmq_sleep(1);
|
||||||
sleep (1);
|
|
||||||
|
|
||||||
// Bind REQ and REP
|
// Bind REQ and REP
|
||||||
rc = zmq_bind (rep, addr.c_str());
|
rc = zmq_bind (rep, addr.c_str());
|
||||||
@ -238,8 +236,7 @@ int main (void)
|
|||||||
// 2nd REQ socket monitor, connected event only
|
// 2nd REQ socket monitor, connected event only
|
||||||
rc = zmq_socket_monitor (req2, "inproc://monitor.req2", ZMQ_EVENT_CONNECTED);
|
rc = zmq_socket_monitor (req2, "inproc://monitor.req2", ZMQ_EVENT_CONNECTED);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = pthread_create (&threads [2], NULL, req2_socket_monitor, ctx);
|
threads [2] = zmq_threadstart(req2_socket_monitor, ctx);
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_connect (req2, addr.c_str());
|
rc = zmq_connect (req2, addr.c_str());
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
@ -249,8 +246,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Allow some time for detecting error states
|
// Allow some time for detecting error states
|
||||||
struct timespec t = { 0, 250 * 1000000 };
|
zmq_sleep(1);
|
||||||
nanosleep (&t, NULL);
|
|
||||||
|
|
||||||
// Close the REQ socket
|
// Close the REQ socket
|
||||||
rc = zmq_close (req);
|
rc = zmq_close (req);
|
||||||
@ -276,7 +272,8 @@ int main (void)
|
|||||||
assert (req2_socket_events & ZMQ_EVENT_CONNECTED);
|
assert (req2_socket_events & ZMQ_EVENT_CONNECTED);
|
||||||
assert (!(req2_socket_events & ZMQ_EVENT_CLOSED));
|
assert (!(req2_socket_events & ZMQ_EVENT_CLOSED));
|
||||||
|
|
||||||
pthread_exit (NULL);
|
for (unsigned int i = 0; i < 3; ++i)
|
||||||
|
zmq_threadclose(threads [i]);
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
// Create the infrastructure
|
// Create the infrastructure
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#undef NDEBUG
|
#include "testutil.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
// ZMTP protocol greeting structure
|
// ZMTP protocol greeting structure
|
||||||
|
|
||||||
@ -45,6 +43,7 @@ static zmtp_greeting_t greeting
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
// Set up our context and sockets
|
// Set up our context and sockets
|
||||||
|
@ -18,12 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../include/zmq_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
@ -57,9 +58,7 @@ int main (void)
|
|||||||
// We have to give the connects time to finish otherwise the requests
|
// We have to give the connects time to finish otherwise the requests
|
||||||
// will not properly round-robin. We could alternatively connect the
|
// will not properly round-robin. We could alternatively connect the
|
||||||
// REQ sockets to the REP sockets.
|
// REQ sockets to the REP sockets.
|
||||||
struct timespec t = { 0, 250 * 1000000 };
|
zmq_sleep(1);
|
||||||
nanosleep (&t, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
// Case 1: Second send() before a reply arrives in a pipe.
|
// Case 1: Second send() before a reply arrives in a pipe.
|
||||||
|
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#undef NDEBUG
|
#include "testutil.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
void *router = zmq_socket (ctx, ZMQ_ROUTER);
|
void *router = zmq_socket (ctx, ZMQ_ROUTER);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pthread.h>
|
#include "../include/zmq_utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
@ -68,6 +68,7 @@ zap_handler (void *zap)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
@ -177,9 +178,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Spawn ZAP handler
|
// Spawn ZAP handler
|
||||||
pthread_t zap_thread;
|
void* zap_thread = zmq_threadstart(&zap_handler, zap);
|
||||||
rc = pthread_create (&zap_thread, NULL, &zap_handler, zap);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_bind (server, "tcp://*:9998");
|
rc = zmq_bind (server, "tcp://*:9998");
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
@ -194,7 +193,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Wait until ZAP handler terminates.
|
// Wait until ZAP handler terminates.
|
||||||
pthread_join (zap_thread, NULL);
|
zmq_threadclose(zap_thread);
|
||||||
|
|
||||||
// Check PLAIN security -- two servers trying to talk to each other
|
// Check PLAIN security -- two servers trying to talk to each other
|
||||||
server = zmq_socket (ctx, ZMQ_DEALER);
|
server = zmq_socket (ctx, ZMQ_DEALER);
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
#include <pthread.h>
|
#include "../include/zmq_utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
@ -62,6 +62,7 @@ int main (void)
|
|||||||
printf ("libsodium not installed, skipping CURVE test\n");
|
printf ("libsodium not installed, skipping CURVE test\n");
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
size_t optsize;
|
size_t optsize;
|
||||||
int mechanism;
|
int mechanism;
|
||||||
@ -122,9 +123,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Spawn ZAP handler
|
// Spawn ZAP handler
|
||||||
pthread_t zap_thread;
|
void* zap_thread = zmq_threadstart(&zap_handler, zap);
|
||||||
rc = pthread_create (&zap_thread, NULL, &zap_handler, zap);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_bind (server, "tcp://*:9998");
|
rc = zmq_bind (server, "tcp://*:9998");
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
@ -139,7 +138,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Wait until ZAP handler terminates.
|
// Wait until ZAP handler terminates.
|
||||||
pthread_join (zap_thread, NULL);
|
zmq_threadclose(zap_thread);
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
rc = zmq_ctx_term (ctx);
|
rc = zmq_ctx_term (ctx);
|
||||||
|
@ -18,12 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <pthread.h>
|
#include "../include/zmq_utils.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#define THREAD_COUNT 100
|
#define THREAD_COUNT 100
|
||||||
|
|
||||||
@ -46,12 +44,13 @@ extern "C"
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *s1;
|
void *s1;
|
||||||
void *s2;
|
void *s2;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int rc;
|
int rc;
|
||||||
pthread_t threads [THREAD_COUNT];
|
void* threads [THREAD_COUNT];
|
||||||
|
|
||||||
for (j = 0; j != 10; j++) {
|
for (j = 0; j != 10; j++) {
|
||||||
|
|
||||||
@ -69,13 +68,11 @@ int main (void)
|
|||||||
for (i = 0; i != THREAD_COUNT; i++) {
|
for (i = 0; i != THREAD_COUNT; i++) {
|
||||||
s2 = zmq_socket (ctx, ZMQ_SUB);
|
s2 = zmq_socket (ctx, ZMQ_SUB);
|
||||||
assert (s2);
|
assert (s2);
|
||||||
rc = pthread_create (&threads [i], NULL, worker, s2);
|
threads [i] = zmq_threadstart(worker, s2);
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i != THREAD_COUNT; i++) {
|
for (i = 0; i != THREAD_COUNT; i++) {
|
||||||
rc = pthread_join (threads [i], NULL);
|
zmq_threadclose(threads [i]);
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = zmq_close (s1);
|
rc = zmq_close (s1);
|
||||||
|
@ -220,6 +220,7 @@ void test_block_on_send_no_peers (void *ctx)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -258,6 +258,7 @@ void test_destroy_queue_on_disconnect (void *ctx)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ void test_envelope (void *ctx)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../include/zmq_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
|
||||||
@ -49,8 +49,7 @@ void test_round_robin_out (void *ctx)
|
|||||||
// We have to give the connects time to finish otherwise the requests
|
// We have to give the connects time to finish otherwise the requests
|
||||||
// will not properly round-robin. We could alternatively connect the
|
// will not properly round-robin. We could alternatively connect the
|
||||||
// REQ sockets to the REP sockets.
|
// REQ sockets to the REP sockets.
|
||||||
struct timespec t = { 0, 250 * 1000000 };
|
zmq_sleep(1);
|
||||||
nanosleep (&t, NULL);
|
|
||||||
|
|
||||||
// Send our peer-replies, and expect every REP it used once in order
|
// Send our peer-replies, and expect every REP it used once in order
|
||||||
for (size_t peer = 0; peer < services; peer++) {
|
for (size_t peer = 0; peer < services; peer++) {
|
||||||
@ -217,6 +216,7 @@ void test_block_on_send_no_peers (void *ctx)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -177,6 +177,7 @@ void test_destroy_queue_on_disconnect (void *ctx)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
// ZMTP protocol greeting structure
|
// ZMTP protocol greeting structure
|
||||||
|
|
||||||
@ -222,6 +220,7 @@ test_stream_to_stream (void)
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
test_stream_to_dealer ();
|
test_stream_to_dealer ();
|
||||||
test_stream_to_stream ();
|
test_stream_to_stream ();
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
|
#include "../include/zmq_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#undef NDEBUG
|
#include "testutil.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
@ -62,8 +63,7 @@ int main (void)
|
|||||||
assert (rc >= 0);
|
assert (rc >= 0);
|
||||||
|
|
||||||
// Wait a bit till the subscription gets to the publisher
|
// Wait a bit till the subscription gets to the publisher
|
||||||
struct timespec t = { 0, 250 * 1000000 };
|
zmq_sleep(1);
|
||||||
nanosleep (&t, NULL);
|
|
||||||
|
|
||||||
// Send an empty message
|
// Send an empty message
|
||||||
rc = zmq_send (pub, NULL, 0, 0);
|
rc = zmq_send (pub, NULL, 0, 0);
|
||||||
|
@ -18,15 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
|
#include "../include/zmq_utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "testutil.hpp"
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
const char *ep = "tcp://127.0.0.1:5560";
|
const char *ep = "tcp://127.0.0.1:5560";
|
||||||
@ -54,8 +53,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Allow unbind to settle
|
// Allow unbind to settle
|
||||||
struct timespec t = { 0, 250 * 1000000 };
|
zmq_sleep(1);
|
||||||
nanosleep (&t, NULL);
|
|
||||||
|
|
||||||
// Check that sending would block (there's no outbound connection)
|
// Check that sending would block (there's no outbound connection)
|
||||||
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
|
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
|
||||||
@ -92,7 +90,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Allow disconnect to settle
|
// Allow disconnect to settle
|
||||||
nanosleep (&t, NULL);
|
zmq_sleep(1);
|
||||||
|
|
||||||
// Check that sending would block (there's no inbound connections).
|
// Check that sending would block (there's no inbound connections).
|
||||||
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
|
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
|
||||||
|
@ -18,15 +18,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <sys/time.h>
|
#include "../include/zmq_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#undef NDEBUG
|
#include "testutil.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
setup_test_environment();
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
|
||||||
@ -46,17 +46,11 @@ int main (void)
|
|||||||
rc = zmq_setsockopt (frontend, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
rc = zmq_setsockopt (frontend, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
struct timeval before, after;
|
void* stopwatch = zmq_stopwatch_start();
|
||||||
gettimeofday (&before, NULL);
|
|
||||||
rc = zmq_recv (frontend, buffer, 32, 0);
|
rc = zmq_recv (frontend, buffer, 32, 0);
|
||||||
assert (rc == -1);
|
assert (rc == -1);
|
||||||
assert (zmq_errno () == EAGAIN);
|
assert (zmq_errno () == EAGAIN);
|
||||||
gettimeofday (&after, NULL);
|
unsigned int elapsed = zmq_stopwatch_stop(stopwatch) / 1000;
|
||||||
|
|
||||||
long elapsed = (long)
|
|
||||||
((after.tv_sec * 1000 + after.tv_usec / 1000)
|
|
||||||
- (before.tv_sec * 1000 + before.tv_usec / 1000));
|
|
||||||
|
|
||||||
assert (elapsed > 200 && elapsed < 300);
|
assert (elapsed > 200 && elapsed < 300);
|
||||||
|
|
||||||
// Check that normal message flow works as expected
|
// Check that normal message flow works as expected
|
||||||
|
@ -22,10 +22,15 @@
|
|||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if defined _WIN32
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Bounce a message from client to server and back
|
// Bounce a message from client to server and back
|
||||||
// For REQ/REP or DEALER/DEALER pairs only
|
// For REQ/REP or DEALER/DEALER pairs only
|
||||||
|
|
||||||
@ -191,4 +196,11 @@ void close_zero_linger (void *socket)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setup_test_environment()
|
||||||
|
{
|
||||||
|
#if defined _WIN32
|
||||||
|
_set_abort_behavior( 0, _WRITE_ABORT_MSG);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user