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