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
924d47f8
Commit
924d47f8
authored
Mar 22, 2019
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: tests without test framework
Solution: migrate to Unity
parent
f4b9cc99
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
219 additions
and
205 deletions
+219
-205
Makefile.am
Makefile.am
+10
-5
test_getsockopt_memset.cpp
tests/test_getsockopt_memset.cpp
+29
-26
test_msg_ffn.cpp
tests/test_msg_ffn.cpp
+52
-66
test_msg_flags.cpp
tests/test_msg_flags.cpp
+60
-61
test_router_mandatory_tipc.cpp
tests/test_router_mandatory_tipc.cpp
+29
-27
test_system.cpp
tests/test_system.cpp
+39
-20
No files found.
Makefile.am
View file @
924d47f8
...
...
@@ -473,7 +473,8 @@ tests_test_ancillaries_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_ancillaries_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_system_SOURCES
=
tests/test_system.cpp
tests_test_system_LDADD
=
src/libzmq.la
tests_test_system_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_system_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_pair_inproc_SOURCES
=
\
tests/test_pair_inproc.cpp
\
...
...
@@ -520,10 +521,12 @@ tests_test_invalid_rep_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_invalid_rep_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_msg_flags_SOURCES
=
tests/test_msg_flags.cpp
tests_test_msg_flags_LDADD
=
src/libzmq.la
tests_test_msg_flags_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_msg_flags_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_msg_ffn_SOURCES
=
tests/test_msg_ffn.cpp
tests_test_msg_ffn_LDADD
=
src/libzmq.la
tests_test_msg_ffn_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_msg_ffn_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_connect_resolve_SOURCES
=
tests/test_connect_resolve.cpp
tests_test_connect_resolve_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
@@ -673,7 +676,8 @@ tests_test_proxy_terminate_SOURCES = tests/test_proxy_terminate.cpp
tests_test_proxy_terminate_LDADD
=
src/libzmq.la
tests_test_getsockopt_memset_SOURCES
=
tests/test_getsockopt_memset.cpp
tests_test_getsockopt_memset_LDADD
=
src/libzmq.la
tests_test_getsockopt_memset_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_getsockopt_memset_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_many_sockets_SOURCES
=
tests/test_many_sockets.cpp
tests_test_many_sockets_LDADD
=
src/libzmq.la
...
...
@@ -895,7 +899,8 @@ tests_test_reqrep_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_reqrep_tipc_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_router_mandatory_tipc_SOURCES
=
tests/test_router_mandatory_tipc.cpp
tests_test_router_mandatory_tipc_LDADD
=
src/libzmq.la
tests_test_router_mandatory_tipc_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_router_mandatory_tipc_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_shutdown_stress_tipc_SOURCES
=
tests/test_shutdown_stress_tipc.cpp
tests_test_shutdown_stress_tipc_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_getsockopt_memset.cpp
View file @
924d47f8
...
...
@@ -23,42 +23,45 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int
main
(
void
)
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
void
test_getsockopt_memset
()
{
int64_t
more
;
size_t
more_size
=
sizeof
(
more
);
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
sb
=
zmq_socket
(
ctx
,
ZMQ_PUB
);
assert
(
sb
);
int
rc
=
zmq_bind
(
sb
,
"inproc://a"
);
assert
(
rc
==
0
);
void
*
sb
=
test_context_socket
(
ZMQ_PUB
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
"inproc://a"
));
void
*
sc
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
assert
(
sc
);
rc
=
zmq_connect
(
sc
,
"inproc://a"
);
assert
(
rc
==
0
);
void
*
sc
=
test_context_socket
(
ZMQ_SUB
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sc
,
"inproc://a"
));
memset
(
&
more
,
0xFF
,
sizeof
(
int64_t
));
zmq_getsockopt
(
sc
,
ZMQ_RCVMORE
,
&
more
,
&
more_size
);
assert
(
more_size
==
sizeof
(
int
));
assert
(
more
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sc
,
ZMQ_RCVMORE
,
&
more
,
&
more_size
));
TEST_ASSERT_EQUAL_INT
(
sizeof
(
int
),
more_size
);
TEST_ASSERT_EQUAL_INT
(
0
,
more
);
// Cleanup
test_context_socket_close
(
sc
);
test_context_socket_close
(
sb
);
}
rc
=
zmq_close
(
sc
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
sb
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
int
main
(
void
)
{
setup_test_environment
();
return
0
;
UNITY_BEGIN
();
RUN_TEST
(
test_getsockopt_memset
);
return
UNITY_END
();
}
tests/test_msg_ffn.cpp
View file @
924d47f8
...
...
@@ -28,6 +28,17 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
void
ffn
(
void
*
data_
,
void
*
hint_
)
{
...
...
@@ -36,29 +47,16 @@ void ffn (void *data_, void *hint_)
memcpy
(
hint_
,
(
void
*
)
"freed"
,
5
);
}
int
main
(
void
)
void
test_msg_ffn
(
)
{
setup_test_environment
();
// Create the infrastructure
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
router
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
router
);
int
rc
=
zmq_bind
(
router
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
router
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
void
*
router
=
test_context_socket
(
ZMQ_ROUTER
);
bind_loopback_ipv4
(
router
,
my_endpoint
,
sizeof
my_endpoint
);
void
*
dealer
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
dealer
);
rc
=
zmq_connect
(
dealer
,
my_endpoint
);
assert
(
rc
==
0
);
void
*
dealer
=
test_context_socket
(
ZMQ_DEALER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
dealer
,
my_endpoint
));
// Test that creating and closing a message triggers ffn
zmq_msg_t
msg
;
...
...
@@ -67,80 +65,68 @@ int main (void)
memset
(
data
,
0
,
255
);
memcpy
(
data
,
(
void
*
)
"data"
,
4
);
memcpy
(
hint
,
(
void
*
)
"hint"
,
4
);
rc
=
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg
));
msleep
(
SETTLE_TIME
);
assert
(
memcmp
(
hint
,
"freed"
,
5
)
==
0
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"freed"
,
hint
,
5
);
memcpy
(
hint
,
(
void
*
)
"hint"
,
4
);
// Making and closing a copy triggers ffn
zmq_msg_t
msg2
;
zmq_msg_init
(
&
msg2
);
rc
=
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
);
assert
(
rc
==
0
);
rc
=
zmq_msg_copy
(
&
msg2
,
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
msg2
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_copy
(
&
msg2
,
&
msg
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg2
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg
));
msleep
(
SETTLE_TIME
);
assert
(
memcmp
(
hint
,
"freed"
,
5
)
==
0
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"freed"
,
hint
,
5
);
memcpy
(
hint
,
(
void
*
)
"hint"
,
4
);
// Test that sending a message triggers ffn
rc
=
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
)
);
zmq_msg_send
(
&
msg
,
dealer
,
0
);
char
buf
[
255
];
rc
=
zmq_recv
(
router
,
buf
,
255
,
0
);
assert
(
rc
>
-
1
);
rc
=
zmq_recv
(
router
,
buf
,
255
,
0
);
assert
(
rc
==
255
);
assert
(
memcmp
(
data
,
buf
,
4
)
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_recv
(
router
,
buf
,
255
,
0
));
TEST_ASSERT_EQUAL_INT
(
255
,
zmq_recv
(
router
,
buf
,
255
,
0
));
TEST_ASSERT_EQUAL_STRING_LEN
(
data
,
buf
,
4
);
msleep
(
SETTLE_TIME
);
assert
(
memcmp
(
hint
,
"freed"
,
5
)
==
0
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"freed"
,
hint
,
5
);
memcpy
(
hint
,
(
void
*
)
"hint"
,
4
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg
));
// Sending a copy of a message triggers ffn
rc
=
zmq_msg_init
(
&
msg2
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
);
assert
(
rc
==
0
);
rc
=
zmq_msg_copy
(
&
msg2
,
&
msg
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
msg2
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
255
,
ffn
,
(
void
*
)
hint
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_copy
(
&
msg2
,
&
msg
));
zmq_msg_send
(
&
msg
,
dealer
,
0
);
rc
=
zmq_recv
(
router
,
buf
,
255
,
0
);
assert
(
rc
>
-
1
);
rc
=
zmq_recv
(
router
,
buf
,
255
,
0
);
assert
(
rc
==
255
);
assert
(
memcmp
(
data
,
buf
,
4
)
==
0
);
rc
=
zmq_msg_close
(
&
msg2
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_recv
(
router
,
buf
,
255
,
0
));
TEST_ASSERT_EQUAL_INT
(
255
,
zmq_recv
(
router
,
buf
,
255
,
0
));
TEST_ASSERT_EQUAL_STRING_LEN
(
data
,
buf
,
4
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg2
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg
));
msleep
(
SETTLE_TIME
);
assert
(
memcmp
(
hint
,
"freed"
,
5
)
==
0
);
memcpy
(
hint
,
(
void
*
)
"hint"
,
4
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"freed"
,
hint
,
5
);
// Deallocate the infrastructure.
rc
=
zmq_close
(
router
);
assert
(
rc
==
0
);
test_context_socket_close
(
router
);
test_context_socket_close
(
dealer
);
}
rc
=
zmq_close
(
dealer
);
assert
(
rc
==
0
);
int
main
(
void
)
{
setup_test_environment
();
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
UNITY_BEGIN
(
);
RUN_TEST
(
test_msg_ffn
);
return
UNITY_END
()
;
}
tests/test_msg_flags.cpp
View file @
924d47f8
...
...
@@ -28,99 +28,98 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int
main
(
void
)
void
setUp
(
)
{
setup_test_environment
();
// Create the infrastructure
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
sb
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
sb
);
setup_test_context
();
}
int
rc
=
zmq_bind
(
sb
,
"inproc://a"
);
assert
(
rc
==
0
);
void
tearDown
()
{
teardown_test_context
();
}
void
*
sc
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
sc
);
void
test_more
()
{
// Create the infrastructure
void
*
sb
=
test_context_socket
(
ZMQ_ROUTER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
"inproc://a"
));
rc
=
zmq_connect
(
sc
,
"inproc://a"
);
assert
(
rc
==
0
);
void
*
sc
=
test_context_socket
(
ZMQ_DEALER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sc
,
"inproc://a"
)
);
// Send 2-part message.
rc
=
zmq_send
(
sc
,
"A"
,
1
,
ZMQ_SNDMORE
);
assert
(
rc
==
1
);
rc
=
zmq_send
(
sc
,
"B"
,
1
,
0
);
assert
(
rc
==
1
);
send_string_expect_success
(
sc
,
"A"
,
ZMQ_SNDMORE
);
send_string_expect_success
(
sc
,
"B"
,
0
);
// Routing id comes first.
zmq_msg_t
msg
;
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
sb
,
0
);
assert
(
rc
>=
0
);
int
more
=
zmq_msg_more
(
&
msg
);
assert
(
more
==
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
msg
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
sb
,
0
));
TEST_ASSERT_EQUAL_INT
(
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_more
(
&
msg
)));
// Then the first part of the message body.
rc
=
zmq_msg_recv
(
&
msg
,
sb
,
0
);
assert
(
rc
==
1
);
more
=
zmq_msg_more
(
&
msg
);
assert
(
more
==
1
);
TEST_ASSERT_EQUAL_INT
(
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
sb
,
0
)));
TEST_ASSERT_EQUAL_INT
(
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_more
(
&
msg
)));
// And finally, the second part of the message body.
rc
=
zmq_msg_recv
(
&
msg
,
sb
,
0
);
assert
(
rc
==
1
);
more
=
zmq_msg_more
(
&
msg
);
assert
(
more
==
0
);
TEST_ASSERT_EQUAL_INT
(
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
sb
,
0
)));
TEST_ASSERT_EQUAL_INT
(
0
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_more
(
&
msg
)));
// Deallocate the infrastructure.
test_context_socket_close
(
sc
);
test_context_socket_close
(
sb
);
}
void
test_shared_refcounted
()
{
// Test ZMQ_SHARED property (case 1, refcounted messages)
zmq_msg_t
msg_a
;
rc
=
zmq_msg_init_size
(
&
msg_a
,
1024
);
// large enough to be a type_lmsg
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_size
(
&
msg_a
,
1024
));
// large enough to be a type_lmsg
// Message is not shared
rc
=
zmq_msg_get
(
&
msg_a
,
ZMQ_SHARED
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_get
(
&
msg_a
,
ZMQ_SHARED
));
zmq_msg_t
msg_b
;
rc
=
zmq_msg_init
(
&
msg_b
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
msg_b
));
rc
=
zmq_msg_copy
(
&
msg_b
,
&
msg_a
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_copy
(
&
msg_b
,
&
msg_a
));
// Message is now shared
rc
=
zmq_msg_get
(
&
msg_b
,
ZMQ_SHARED
);
assert
(
rc
==
1
);
TEST_ASSERT_EQUAL_INT
(
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_get
(
&
msg_b
,
ZMQ_SHARED
))
);
// cleanup
rc
=
zmq_msg_close
(
&
msg_a
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
msg_b
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg_a
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg_b
));
}
void
test_shared_const
()
{
zmq_msg_t
msg_a
;
// Test ZMQ_SHARED property (case 2, constant data messages)
rc
=
zmq_msg_init_data
(
&
msg_a
,
(
void
*
)
"TEST"
,
5
,
0
,
0
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_data
(
&
msg_a
,
(
void
*
)
"TEST"
,
5
,
0
,
0
)
);
// Message reports as shared
rc
=
zmq_msg_get
(
&
msg_a
,
ZMQ_SHARED
);
assert
(
rc
==
1
);
TEST_ASSERT_EQUAL_INT
(
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_get
(
&
msg_a
,
ZMQ_SHARED
))
);
// cleanup
rc
=
zmq_msg_close
(
&
msg_a
);
assert
(
rc
==
0
);
// Deallocate the infrastructure.
rc
=
zmq_close
(
sc
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg_a
));
}
rc
=
zmq_close
(
sb
);
assert
(
rc
==
0
);
int
main
()
{
setup_test_environment
();
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
UNITY_BEGIN
();
RUN_TEST
(
test_more
);
RUN_TEST
(
test_shared_refcounted
);
RUN_TEST
(
test_shared_const
);
return
UNITY_END
();
}
tests/test_router_mandatory_tipc.cpp
View file @
924d47f8
...
...
@@ -30,47 +30,49 @@
#include <stdio.h>
#include "testutil.hpp"
int
main
(
void
)
#include "testutil_unity.hpp"
void
setUp
()
{
if
(
!
is_tipc_available
())
{
printf
(
"TIPC environment unavailable, skipping test
\n
"
);
return
77
;
}
setup_test_context
();
}
fprintf
(
stderr
,
"test_router_mandatory_tipc running...
\n
"
);
void
tearDown
()
{
teardown_test_context
();
}
void
*
ctx
=
zmq_init
(
1
);
assert
(
ctx
);
void
test_router_mandatory_tipc
()
{
if
(
!
is_tipc_available
())
{
TEST_IGNORE_MESSAGE
(
"TIPC environment unavailable, skipping test"
);
}
// Creating the first socket.
void
*
sa
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
sa
);
void
*
sa
=
test_context_socket
(
ZMQ_ROUTER
);
int
rc
=
zmq_bind
(
sa
,
"tipc://{15560,0,0}"
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sa
,
"tipc://{15560,0,0}"
));
// Sending a message to an unknown peer with the default setting
rc
=
zmq_send
(
sa
,
"UNKNOWN"
,
7
,
ZMQ_SNDMORE
);
assert
(
rc
==
7
);
rc
=
zmq_send
(
sa
,
"DATA"
,
4
,
0
);
assert
(
rc
==
4
);
send_string_expect_success
(
sa
,
"UNKNOWN"
,
ZMQ_SNDMORE
);
send_string_expect_success
(
sa
,
"DATA"
,
0
);
int
mandatory
=
1
;
// Set mandatory routing on socket
rc
=
zmq_setsockopt
(
sa
,
ZMQ_ROUTER_MANDATORY
,
&
mandatory
,
sizeof
(
mandatory
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sa
,
ZMQ_ROUTER_MANDATORY
,
&
mandatory
,
sizeof
(
mandatory
)));
// Send a message and check that it fails
rc
=
zmq_send
(
sa
,
"UNKNOWN"
,
7
,
ZMQ_SNDMORE
|
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
&&
errno
==
EHOSTUNREACH
);
rc
=
zmq_close
(
sa
);
assert
(
rc
==
0
);
TEST_ASSERT_FAILURE_ERRNO
(
EHOSTUNREACH
,
zmq_send
(
sa
,
"UNKNOWN"
,
7
,
ZMQ_SNDMORE
|
ZMQ_DONTWAIT
));
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
test_context_socket_close
(
sa
);
}
return
0
;
int
main
(
void
)
{
UNITY_BEGIN
();
RUN_TEST
(
test_router_mandatory_tipc
);
return
UNITY_END
();
}
tests/test_system.cpp
View file @
924d47f8
...
...
@@ -28,6 +28,7 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
#if defined(ZMQ_HAVE_WINDOWS)
#include <winsock2.h>
...
...
@@ -38,6 +39,16 @@
#include <unistd.h>
#endif
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
// Solaris has a default of 256 max files per process
#ifdef ZMQ_HAVE_SOLARIS
#define MAX_SOCKETS 200
...
...
@@ -62,25 +73,21 @@ void initialise_network (void)
#endif
// This test case stresses the system to shake out known configuration
// problems. We're direct system calls when necessary. Some code may
// need wrapping to be properly portable.
int
main
(
void
)
void
test_localhost
()
{
initialise_network
();
// Check that we have local networking via ZeroMQ
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
dealer
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
void
*
dealer
=
test_context_socket
(
ZMQ_DEALER
);
if
(
zmq_bind
(
dealer
,
"tcp://127.0.0.1:*"
)
==
-
1
)
{
printf
(
"E: Cannot find 127.0.0.1 -- your system does not have local
\n
"
);
printf
(
TEST_FAIL_MESSAGE
(
"E: Cannot find 127.0.0.1 -- your system does not have local
\n
"
"E: networking. Please fix this before running libzmq checks.
\n
"
);
return
-
1
;
}
test_context_socket_close
(
dealer
);
}
void
test_max_sockets
()
{
// Check that we can create 1,000 sockets
fd_t
handle
[
MAX_SOCKETS
];
int
count
;
...
...
@@ -88,19 +95,31 @@ int main (void)
handle
[
count
]
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
if
(
handle
[
count
]
==
-
1
)
{
printf
(
"W: Only able to create %d sockets on this box
\n
"
,
count
);
printf
(
"I: Tune your system to increase maximum allowed file handles
\n
"
);
const
char
msg
[]
=
"I: Tune your system to increase maximum allowed file handles
\n
"
#if !defined(ZMQ_HAVE_WINDOWS)
printf
(
"I: Run 'ulimit -n 1200' in bash
\n
"
);
"I: Run 'ulimit -n 1200' in bash
\n
"
#endif
return
-
1
;
;
TEST_FAIL_MESSAGE
(
msg
);
}
}
// Release the socket handles
for
(
count
=
0
;
count
<
MAX_SOCKETS
;
count
++
)
{
close
(
handle
[
count
]);
}
}
// This test case stresses the system to shake out known configuration
// problems. We're direct system calls when necessary. Some code may
// need wrapping to be properly portable.
int
main
(
void
)
{
initialise_network
();
zmq_close
(
dealer
);
zmq_ctx_term
(
ctx
);
UNITY_BEGIN
();
RUN_TEST
(
test_localhost
);
RUN_TEST
(
test_max_sockets
);
return
UNITY_END
();
}
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