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
90a4d268
Commit
90a4d268
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
6ed03e93
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
125 deletions
+108
-125
Makefile.am
Makefile.am
+4
-2
test_proxy_single_socket.cpp
tests/test_proxy_single_socket.cpp
+50
-61
test_proxy_terminate.cpp
tests/test_proxy_terminate.cpp
+54
-62
No files found.
Makefile.am
View file @
90a4d268
...
...
@@ -672,10 +672,12 @@ tests_test_proxy_hwm_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_proxy_hwm_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_proxy_single_socket_SOURCES
=
tests/test_proxy_single_socket.cpp
tests_test_proxy_single_socket_LDADD
=
src/libzmq.la
tests_test_proxy_single_socket_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_proxy_single_socket_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
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
${
UNITY_LIBS
}
tests_test_proxy_terminate_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_getsockopt_memset_SOURCES
=
tests/test_getsockopt_memset.cpp
tests_test_getsockopt_memset_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_proxy_single_socket.cpp
View file @
90a4d268
...
...
@@ -28,92 +28,81 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
// This is our server task.
// It runs a proxy with a single REP socket as both frontend and backend.
void
server_task
(
void
*
ctx_
)
void
server_task
(
void
*
/*unused_*/
)
{
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
rep
=
zmq_socket
(
ctx_
,
ZMQ_REP
);
assert
(
rep
);
int
rc
=
zmq_bind
(
rep
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
rep
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
void
*
rep
=
zmq_socket
(
get_test_context
(),
ZMQ_REP
);
TEST_ASSERT_NOT_NULL
(
rep
);
bind_loopback_ipv4
(
rep
,
my_endpoint
,
sizeof
my_endpoint
);
// Control socket receives terminate command from main over inproc
void
*
control
=
zmq_socket
(
ctx_
,
ZMQ_REQ
);
assert
(
control
);
rc
=
zmq_connect
(
control
,
"inproc://control"
);
assert
(
rc
==
0
);
rc
=
s_send
(
control
,
my_endpoint
);
assert
(
rc
>
0
);
void
*
control
=
zmq_socket
(
get_test_context
(),
ZMQ_REQ
);
TEST_ASSERT_NOT_NULL
(
control
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
control
,
"inproc://control"
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
TEST_ASSERT_SUCCESS_ERRNO
(
s_send
(
control
,
my_endpoint
)));
// Use rep as both frontend and backend
rc
=
zmq_proxy_steerable
(
rep
,
rep
,
NULL
,
control
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_proxy_steerable
(
rep
,
rep
,
NULL
,
control
));
rc
=
zmq_close
(
rep
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
control
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
rep
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
control
));
}
// The main thread simply starts several clients and a server, and then
// waits for the server to finish.
int
main
(
void
)
void
test_proxy_single_socket
()
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
server_thread
=
zmq_threadstart
(
&
server_task
,
ctx
);
void
*
server_thread
=
zmq_threadstart
(
&
server_task
,
NULL
);
// Control socket receives terminate command from main over inproc
void
*
control
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
control
);
int
rc
=
zmq_bind
(
control
,
"inproc://control"
);
assert
(
rc
==
0
);
void
*
control
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_NOT_NULL
(
control
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
control
,
"inproc://control"
));
char
*
my_endpoint
=
s_recv
(
control
);
assert
(
my_endpoint
);
TEST_ASSERT_NOT_NULL
(
my_endpoint
);
// client socket pings proxy over tcp
void
*
req
=
zmq_socket
(
ctx
,
ZMQ_REQ
);
assert
(
req
);
rc
=
zmq_connect
(
req
,
my_endpoint
);
assert
(
rc
==
0
);
char
buf
[
255
];
rc
=
zmq_send
(
req
,
"msg1"
,
4
,
0
);
assert
(
rc
==
4
);
rc
=
zmq_recv
(
req
,
buf
,
255
,
0
);
assert
(
rc
==
4
);
assert
(
memcmp
(
buf
,
"msg1"
,
4
)
==
0
);
rc
=
zmq_send
(
req
,
"msg22"
,
5
,
0
);
assert
(
rc
==
5
);
rc
=
zmq_recv
(
req
,
buf
,
255
,
0
);
assert
(
rc
==
5
);
assert
(
memcmp
(
buf
,
"msg22"
,
5
)
==
0
);
rc
=
zmq_send
(
control
,
"TERMINATE"
,
9
,
0
);
assert
(
rc
==
9
);
rc
=
zmq_close
(
control
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
req
);
assert
(
rc
==
0
);
void
*
req
=
test_context_socket
(
ZMQ_REQ
);
TEST_ASSERT_NOT_NULL
(
req
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
req
,
my_endpoint
));
send_string_expect_success
(
req
,
"msg1"
,
0
);
recv_string_expect_success
(
req
,
"msg1"
,
0
);
send_string_expect_success
(
req
,
"msg22"
,
0
);
recv_string_expect_success
(
req
,
"msg22"
,
0
);
send_string_expect_success
(
control
,
"TERMINATE"
,
0
);
test_context_socket_close
(
control
);
test_context_socket_close
(
req
);
free
(
my_endpoint
);
zmq_threadclose
(
server_thread
);
}
int
main
(
void
)
{
setup_test_environment
();
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
UNITY_BEGIN
(
);
RUN_TEST
(
test_proxy_single_socket
);
return
UNITY_END
()
;
}
tests/test_proxy_terminate.cpp
View file @
90a4d268
...
...
@@ -28,104 +28,96 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
// This is a test for issue #1382. The server thread creates a SUB-PUSH
// steerable proxy. The main process then sends messages to the SUB
// but there is no pull on the other side, previously the proxy blocks
// in writing to the backend, preventing the proxy from terminating
void
server_task
(
void
*
ctx_
)
void
server_task
(
void
*
/*unused_*/
)
{
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
// Frontend socket talks to main process
void
*
frontend
=
zmq_socket
(
ctx_
,
ZMQ_SUB
);
assert
(
frontend
);
int
rc
=
zmq_setsockopt
(
frontend
,
ZMQ_SUBSCRIBE
,
""
,
0
);
assert
(
rc
==
0
);
rc
=
zmq_bind
(
frontend
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
frontend
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
void
*
frontend
=
zmq_socket
(
get_test_context
(),
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
frontend
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
frontend
,
ZMQ_SUBSCRIBE
,
""
,
0
));
bind_loopback_ipv4
(
frontend
,
my_endpoint
,
sizeof
my_endpoint
);
// Nice socket which is never read
void
*
backend
=
zmq_socket
(
ctx_
,
ZMQ_PUSH
);
assert
(
backend
);
rc
=
zmq_bind
(
backend
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
void
*
backend
=
zmq_socket
(
get_test_context
(),
ZMQ_PUSH
);
TEST_ASSERT_NOT_NULL
(
backend
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
backend
,
"tcp://127.0.0.1:*"
));
// Control socket receives terminate command from main over inproc
void
*
control
=
zmq_socket
(
ctx_
,
ZMQ_REQ
);
assert
(
control
);
rc
=
zmq_connect
(
control
,
"inproc://control"
);
assert
(
rc
==
0
);
rc
=
s_send
(
control
,
my_endpoint
);
assert
(
rc
>
0
);
void
*
control
=
zmq_socket
(
get_test_context
(),
ZMQ_REQ
);
TEST_ASSERT_NOT_NULL
(
control
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
control
,
"inproc://control"
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
TEST_ASSERT_SUCCESS_ERRNO
(
s_send
(
control
,
my_endpoint
)));
// Connect backend to frontend via a proxy
rc
=
zmq_proxy_steerable
(
frontend
,
backend
,
NULL
,
control
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
frontend
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
backend
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
control
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_proxy_steerable
(
frontend
,
backend
,
NULL
,
control
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
frontend
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
backend
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
control
));
}
// The main thread simply starts a basic steerable proxy server, publishes some messages, and then
// waits for the server to terminate.
int
main
(
void
)
void
test_proxy_terminate
()
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
thread
=
zmq_threadstart
(
&
server_task
,
ctx
);
void
*
thread
=
zmq_threadstart
(
&
server_task
,
NULL
);
// Control socket receives terminate command from main over inproc
void
*
control
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
control
);
int
rc
=
zmq_bind
(
control
,
"inproc://control"
);
assert
(
rc
==
0
);
void
*
control
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_NOT_NULL
(
control
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
control
,
"inproc://control"
));
char
*
my_endpoint
=
s_recv
(
control
);
assert
(
my_endpoint
);
TEST_ASSERT_NOT_NULL
(
my_endpoint
);
msleep
(
500
);
// Run for 500 ms
// Start a secondary publisher which writes data to the SUB-PUSH server socket
void
*
publisher
=
zmq_socket
(
ctx
,
ZMQ_PUB
);
assert
(
publisher
);
rc
=
zmq_connect
(
publisher
,
my_endpoint
);
assert
(
rc
==
0
);
void
*
publisher
=
test_context_socket
(
ZMQ_PUB
);
TEST_ASSERT_NOT_NULL
(
publisher
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
publisher
,
my_endpoint
));
msleep
(
SETTLE_TIME
);
rc
=
zmq_send
(
publisher
,
"This is a test"
,
14
,
0
);
assert
(
rc
==
14
);
send_string_expect_success
(
publisher
,
"This is a test"
,
0
);
msleep
(
50
);
rc
=
zmq_send
(
publisher
,
"This is a test"
,
14
,
0
);
assert
(
rc
==
14
);
send_string_expect_success
(
publisher
,
"This is a test"
,
0
);
msleep
(
50
);
rc
=
zmq_send
(
publisher
,
"This is a test"
,
14
,
0
);
assert
(
rc
==
14
);
rc
=
zmq_send
(
control
,
"TERMINATE"
,
9
,
0
);
assert
(
rc
==
9
);
rc
=
zmq_close
(
publisher
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
control
);
assert
(
rc
==
0
);
send_string_expect_success
(
publisher
,
"This is a test"
,
0
);
send_string_expect_success
(
control
,
"TERMINATE"
,
0
);
test_context_socket_close
(
publisher
);
test_context_socket_close
(
control
);
free
(
my_endpoint
);
zmq_threadclose
(
thread
);
}
int
main
(
void
)
{
setup_test_environment
();
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
UNITY_BEGIN
(
);
RUN_TEST
(
test_proxy_terminate
);
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