Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
7f74fc7c
Commit
7f74fc7c
authored
Aug 17, 2013
by
Richard Newton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port tests to windows and add to cmake build.
parent
e16a6af0
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
171 additions
and
108 deletions
+171
-108
CMakeLists.txt
CMakeLists.txt
+49
-3
zmq_utils.h
include/zmq_utils.h
+6
-0
zmq_utils.cpp
src/zmq_utils.cpp
+15
-0
test_connect_delay.cpp
tests/test_connect_delay.cpp
+5
-7
test_connect_resolve.cpp
tests/test_connect_resolve.cpp
+2
-3
test_ctx_options.cpp
tests/test_ctx_options.cpp
+2
-3
test_disconnect_inproc.cpp
tests/test_disconnect_inproc.cpp
+2
-1
test_hwm.cpp
tests/test_hwm.cpp
+2
-2
test_invalid_rep.cpp
tests/test_invalid_rep.cpp
+2
-3
test_iov.cpp
tests/test_iov.cpp
+5
-5
test_last_endpoint.cpp
tests/test_last_endpoint.cpp
+2
-3
test_monitor.cpp
tests/test_monitor.cpp
+10
-13
test_msg_flags.cpp
tests/test_msg_flags.cpp
+2
-3
test_pair_inproc.cpp
tests/test_pair_inproc.cpp
+1
-0
test_pair_ipc.cpp
tests/test_pair_ipc.cpp
+1
-0
test_pair_tcp.cpp
tests/test_pair_tcp.cpp
+1
-0
test_probe_router.cpp
tests/test_probe_router.cpp
+2
-2
test_raw_sock.cpp
tests/test_raw_sock.cpp
+2
-3
test_req_request_ids.cpp
tests/test_req_request_ids.cpp
+1
-1
test_req_strict.cpp
tests/test_req_strict.cpp
+3
-4
test_reqrep_device.cpp
tests/test_reqrep_device.cpp
+2
-3
test_reqrep_inproc.cpp
tests/test_reqrep_inproc.cpp
+1
-0
test_reqrep_ipc.cpp
tests/test_reqrep_ipc.cpp
+1
-0
test_reqrep_tcp.cpp
tests/test_reqrep_tcp.cpp
+1
-0
test_router_mandatory.cpp
tests/test_router_mandatory.cpp
+2
-2
test_security.cpp
tests/test_security.cpp
+4
-5
test_security_curve.cpp
tests/test_security_curve.cpp
+4
-5
test_shutdown_stress.cpp
tests/test_shutdown_stress.cpp
+6
-9
test_spec_dealer.cpp
tests/test_spec_dealer.cpp
+1
-0
test_spec_pushpull.cpp
tests/test_spec_pushpull.cpp
+1
-0
test_spec_rep.cpp
tests/test_spec_rep.cpp
+1
-0
test_spec_req.cpp
tests/test_spec_req.cpp
+3
-3
test_spec_router.cpp
tests/test_spec_router.cpp
+1
-0
test_stream.cpp
tests/test_stream.cpp
+2
-3
test_sub_forward.cpp
tests/test_sub_forward.cpp
+4
-4
test_term_endpoint.cpp
tests/test_term_endpoint.cpp
+5
-7
test_timeo.cpp
tests/test_timeo.cpp
+5
-11
testutil.hpp
tests/testutil.hpp
+12
-0
No files found.
CMakeLists.txt
View file @
7f74fc7c
...
...
@@ -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
...
...
include/zmq_utils.h
View file @
7f74fc7c
...
...
@@ -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
...
...
src/zmq_utils.cpp
View file @
7f74fc7c
...
...
@@ -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
;
}
tests/test_connect_delay.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_connect_resolve.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_ctx_options.cpp
View file @
7f74fc7c
...
...
@@ -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
...
...
tests/test_disconnect_inproc.cpp
View file @
7f74fc7c
...
...
@@ -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
;
...
...
tests/test_hwm.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_invalid_rep.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_iov.cpp
View file @
7f74fc7c
...
...
@@ -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
;
}
tests/test_last_endpoint.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_monitor.cpp
View file @
7f74fc7c
...
...
@@ -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
;
}
tests/test_msg_flags.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_pair_inproc.cpp
View file @
7f74fc7c
...
...
@@ -22,6 +22,7 @@
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_pair_ipc.cpp
View file @
7f74fc7c
...
...
@@ -22,6 +22,7 @@
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_pair_tcp.cpp
View file @
7f74fc7c
...
...
@@ -22,6 +22,7 @@
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_probe_router.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_raw_sock.cpp
View file @
7f74fc7c
...
...
@@ -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
...
...
tests/test_req_request_ids.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_req_strict.cpp
View file @
7f74fc7c
...
...
@@ -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.
...
...
tests/test_reqrep_device.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_reqrep_inproc.cpp
View file @
7f74fc7c
...
...
@@ -22,6 +22,7 @@
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_reqrep_ipc.cpp
View file @
7f74fc7c
...
...
@@ -22,6 +22,7 @@
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_reqrep_tcp.cpp
View file @
7f74fc7c
...
...
@@ -22,6 +22,7 @@
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_router_mandatory.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_security.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_security_curve.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_shutdown_stress.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_spec_dealer.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_spec_pushpull.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_spec_rep.cpp
View file @
7f74fc7c
...
...
@@ -123,6 +123,7 @@ void test_envelope (void *ctx)
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
...
...
tests/test_spec_req.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_spec_router.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_stream.cpp
View file @
7f74fc7c
...
...
@@ -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
();
}
tests/test_sub_forward.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_term_endpoint.cpp
View file @
7f74fc7c
...
...
@@ -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
);
...
...
tests/test_timeo.cpp
View file @
7f74fc7c
...
...
@@ -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
...
...
tests/testutil.hpp
View file @
7f74fc7c
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment