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