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
Show whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
166 additions
and
103 deletions
+166
-103
CMakeLists.txt
CMakeLists.txt
+46
-0
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
+4
-6
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
+4
-4
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
...
@@ -576,6 +576,52 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why?
...
@@ -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
...
...
include/zmq_utils.h
View file @
7f74fc7c
...
@@ -56,6 +56,12 @@ ZMQ_EXPORT unsigned long zmq_stopwatch_stop (void *watch_);
...
@@ -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
...
...
src/zmq_utils.cpp
View file @
7f74fc7c
...
@@ -26,6 +26,7 @@
...
@@ -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_)
...
@@ -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
;
}
tests/test_connect_delay.cpp
View file @
7f74fc7c
...
@@ -18,17 +18,16 @@
...
@@ -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
];
...
@@ -201,8 +200,7 @@ int main (void)
...
@@ -201,8 +200,7 @@ int main (void)
// 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
);
...
...
tests/test_connect_resolve.cpp
View file @
7f74fc7c
...
@@ -20,12 +20,11 @@
...
@@ -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
);
...
...
tests/test_ctx_options.cpp
View file @
7f74fc7c
...
@@ -19,12 +19,11 @@
...
@@ -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
...
...
tests/test_disconnect_inproc.cpp
View file @
7f74fc7c
...
@@ -19,7 +19,7 @@
...
@@ -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;
...
@@ -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
;
...
...
tests/test_hwm.cpp
View file @
7f74fc7c
...
@@ -20,11 +20,11 @@
...
@@ -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
);
...
...
tests/test_invalid_rep.cpp
View file @
7f74fc7c
...
@@ -19,12 +19,11 @@
...
@@ -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
);
...
...
tests/test_iov.cpp
View file @
7f74fc7c
...
@@ -18,12 +18,11 @@
...
@@ -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 {
...
@@ -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)
...
@@ -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"
);
...
...
tests/test_last_endpoint.cpp
View file @
7f74fc7c
...
@@ -19,9 +19,7 @@
...
@@ -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)
...
@@ -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
);
...
...
tests/test_monitor.cpp
View file @
7f74fc7c
...
@@ -19,9 +19,8 @@
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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
;
}
}
tests/test_msg_flags.cpp
View file @
7f74fc7c
...
@@ -19,12 +19,11 @@
...
@@ -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
);
...
...
tests/test_pair_inproc.cpp
View file @
7f74fc7c
...
@@ -22,6 +22,7 @@
...
@@ -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
);
...
...
tests/test_pair_ipc.cpp
View file @
7f74fc7c
...
@@ -22,6 +22,7 @@
...
@@ -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
);
...
...
tests/test_pair_tcp.cpp
View file @
7f74fc7c
...
@@ -22,6 +22,7 @@
...
@@ -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
);
...
...
tests/test_probe_router.cpp
View file @
7f74fc7c
...
@@ -20,11 +20,11 @@
...
@@ -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
);
...
...
tests/test_raw_sock.cpp
View file @
7f74fc7c
...
@@ -19,9 +19,7 @@
...
@@ -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
...
@@ -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
...
...
tests/test_req_request_ids.cpp
View file @
7f74fc7c
...
@@ -18,12 +18,12 @@
...
@@ -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
);
...
...
tests/test_req_strict.cpp
View file @
7f74fc7c
...
@@ -17,13 +17,14 @@
...
@@ -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)
...
@@ -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.
...
...
tests/test_reqrep_device.cpp
View file @
7f74fc7c
...
@@ -20,12 +20,11 @@
...
@@ -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
);
...
...
tests/test_reqrep_inproc.cpp
View file @
7f74fc7c
...
@@ -22,6 +22,7 @@
...
@@ -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
);
...
...
tests/test_reqrep_ipc.cpp
View file @
7f74fc7c
...
@@ -22,6 +22,7 @@
...
@@ -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
);
...
...
tests/test_reqrep_tcp.cpp
View file @
7f74fc7c
...
@@ -22,6 +22,7 @@
...
@@ -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
);
...
...
tests/test_router_mandatory.cpp
View file @
7f74fc7c
...
@@ -20,11 +20,11 @@
...
@@ -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
);
...
...
tests/test_security.cpp
View file @
7f74fc7c
...
@@ -17,7 +17,7 @@
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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
);
...
...
tests/test_security_curve.cpp
View file @
7f74fc7c
...
@@ -18,7 +18,7 @@
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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
);
...
...
tests/test_shutdown_stress.cpp
View file @
7f74fc7c
...
@@ -18,12 +18,10 @@
...
@@ -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"
...
@@ -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)
...
@@ -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
);
...
...
tests/test_spec_dealer.cpp
View file @
7f74fc7c
...
@@ -220,6 +220,7 @@ void test_block_on_send_no_peers (void *ctx)
...
@@ -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
);
...
...
tests/test_spec_pushpull.cpp
View file @
7f74fc7c
...
@@ -258,6 +258,7 @@ void test_destroy_queue_on_disconnect (void *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
);
...
...
tests/test_spec_rep.cpp
View file @
7f74fc7c
...
@@ -123,6 +123,7 @@ void test_envelope (void *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
);
...
...
tests/test_spec_req.cpp
View file @
7f74fc7c
...
@@ -17,8 +17,8 @@
...
@@ -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)
...
@@ -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)
...
@@ -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
);
...
...
tests/test_spec_router.cpp
View file @
7f74fc7c
...
@@ -177,6 +177,7 @@ void test_destroy_queue_on_disconnect (void *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
);
...
...
tests/test_stream.cpp
View file @
7f74fc7c
...
@@ -19,9 +19,7 @@
...
@@ -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)
...
@@ -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
();
}
}
tests/test_sub_forward.cpp
View file @
7f74fc7c
...
@@ -18,13 +18,14 @@
...
@@ -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)
...
@@ -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
);
...
...
tests/test_term_endpoint.cpp
View file @
7f74fc7c
...
@@ -18,15 +18,14 @@
...
@@ -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)
...
@@ -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)
...
@@ -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
);
...
...
tests/test_timeo.cpp
View file @
7f74fc7c
...
@@ -18,15 +18,15 @@
...
@@ -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)
...
@@ -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
...
...
tests/testutil.hpp
View file @
7f74fc7c
...
@@ -22,10 +22,15 @@
...
@@ -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)
...
@@ -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
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