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
991b2336
Commit
991b2336
authored
Mar 15, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_thread_safe not using unity
Solution: migrate to unity, and split test cases
parent
5d32828b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
32 deletions
+62
-32
Makefile.am
Makefile.am
+2
-1
test_thread_safe.cpp
tests/test_thread_safe.cpp
+60
-31
No files found.
Makefile.am
View file @
991b2336
...
...
@@ -865,7 +865,8 @@ tests_test_client_server_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_client_server_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_thread_safe_SOURCES
=
tests/test_thread_safe.cpp
tests_test_thread_safe_LDADD
=
src/libzmq.la
tests_test_thread_safe_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_thread_safe_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_timers_SOURCES
=
tests/test_timers.cpp
tests_test_timers_LDADD
=
src/libzmq.la
...
...
tests/test_thread_safe.cpp
View file @
991b2336
...
...
@@ -28,41 +28,42 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
#include <unity.h>
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
// Client threads loop on send/recv until told to exit
void
client_thread
(
void
*
client
)
{
char
data
=
0
;
for
(
int
count
=
0
;
count
<
15000
;
count
++
)
{
int
rc
=
zmq_send
(
client
,
&
data
,
1
,
0
);
assert
(
rc
==
1
);
send_string_expect_success
(
client
,
"0"
,
0
);
}
data
=
1
;
int
rc
=
zmq_send
(
client
,
&
data
,
1
,
0
);
assert
(
rc
==
1
);
send_string_expect_success
(
client
,
"1"
,
0
);
}
int
main
(
void
)
void
test_thread_safe
(
)
{
setup_test_environment
();
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_SERVER
);
int
rc
=
zmq_bind
(
server
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
server
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
void
*
server
=
test_context_socket
(
ZMQ_SERVER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
server
,
"tcp://127.0.0.1:*"
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
server
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
));
void
*
client
=
zmq_socket
(
ctx
,
ZMQ_CLIENT
);
int
thread_safe
;
size_t
size
=
sizeof
(
int
);
zmq_getsockopt
(
client
,
ZMQ_THREAD_SAFE
,
&
thread_safe
,
&
size
);
assert
(
thread_safe
==
1
);
rc
=
zmq_connect
(
client
,
my_endpoint
);
assert
(
rc
==
0
);
void
*
client
=
test_context_socket
(
ZMQ_CLIENT
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
client
,
my_endpoint
));
void
*
t1
=
zmq_threadstart
(
client_thread
,
client
);
void
*
t2
=
zmq_threadstart
(
client_thread
,
client
);
...
...
@@ -70,21 +71,49 @@ int main (void)
char
data
;
int
threads_completed
=
0
;
while
(
threads_completed
<
2
)
{
zmq_recv
(
server
,
&
data
,
1
,
0
);
if
(
data
==
1
)
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_recv
(
server
,
&
data
,
1
,
0
)
);
if
(
data
==
'1'
)
threads_completed
++
;
// Thread ended
}
zmq_threadclose
(
t1
);
zmq_threadclose
(
t2
);
rc
=
zmq_close
(
server
);
assert
(
rc
==
0
);
test_context_socket_close
(
server
);
test_context_socket_close
(
client
);
}
rc
=
zmq_close
(
client
);
assert
(
rc
==
0
);
void
test_getsockopt_thread_safe
(
void
*
const
socket
)
{
int
thread_safe
;
size_t
size
=
sizeof
(
int
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_THREAD_SAFE
,
&
thread_safe
,
&
size
));
TEST_ASSERT_EQUAL_INT
(
1
,
thread_safe
);
}
void
test_client_getsockopt_thread_safe
()
{
void
*
client
=
test_context_socket
(
ZMQ_CLIENT
);
test_getsockopt_thread_safe
(
client
);
test_context_socket_close
(
client
);
}
void
test_server_getsockopt_thread_safe
()
{
void
*
server
=
test_context_socket
(
ZMQ_SERVER
);
test_getsockopt_thread_safe
(
server
);
test_context_socket_close
(
server
);
}
int
main
(
void
)
{
setup_test_environment
();
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
// TODO this file could be merged with test_client_server
UNITY_BEGIN
();
RUN_TEST
(
test_client_getsockopt_thread_safe
);
RUN_TEST
(
test_server_getsockopt_thread_safe
);
RUN_TEST
(
test_thread_safe
);
return
0
;
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