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
75cd23d6
Commit
75cd23d6
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
06e713e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
26 deletions
+32
-26
Makefile.am
Makefile.am
+2
-1
test_fork.cpp
tests/test_fork.cpp
+30
-25
No files found.
Makefile.am
View file @
75cd23d6
...
...
@@ -865,7 +865,8 @@ if !VALGRIND_ENABLED
test_apps
+=
tests/test_fork
tests_test_fork_SOURCES
=
tests/test_fork.cpp
tests_test_fork_LDADD
=
src/libzmq.la
tests_test_fork_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_fork_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
endif
endif
...
...
tests/test_fork.cpp
View file @
75cd23d6
...
...
@@ -28,41 +28,42 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
const
char
*
address
=
"tcp://127.0.0.1:*"
;
char
connect_address
[
MAX_SOCKET_STRING
];
#define NUM_MESSAGES 5
int
main
(
void
)
void
test_fork
(
)
{
#if !defined(ZMQ_HAVE_WINDOWS)
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Create and bind pull socket to receive messages
void
*
pull
=
zmq_socket
(
ctx
,
ZMQ_PULL
);
assert
(
pull
);
int
rc
=
zmq_bind
(
pull
,
address
);
assert
(
rc
==
0
);
size_t
len
=
MAX_SOCKET_STRING
;
rc
=
zmq_getsockopt
(
pull
,
ZMQ_LAST_ENDPOINT
,
connect_address
,
&
len
);
assert
(
rc
==
0
);
void
*
pull
=
test_context_socket
(
ZMQ_PULL
);
bind_loopback_ipv4
(
pull
,
connect_address
,
sizeof
connect_address
);
int
pid
=
fork
();
if
(
pid
==
0
)
{
// Child process
// Immediately close parent sockets and context
zmq_close
(
pull
);
zmq_ctx_term
(
ctx
);
zmq_ctx_term
(
get_test_context
()
);
// Create new context, socket, connect and send some messages
void
*
child_ctx
=
zmq_ctx_new
();
assert
(
child_ctx
);
void
*
push
=
zmq_socket
(
child_ctx
,
ZMQ_PUSH
);
assert
(
push
);
rc
=
zmq_connect
(
push
,
connect_address
);
int
rc
=
zmq_connect
(
push
,
connect_address
);
assert
(
rc
==
0
);
int
count
;
for
(
count
=
0
;
count
<
NUM_MESSAGES
;
count
++
)
...
...
@@ -75,24 +76,28 @@ int main (void)
// Parent process
int
count
;
for
(
count
=
0
;
count
<
NUM_MESSAGES
;
count
++
)
{
char
buffer
[
5
];
int
num_bytes
=
zmq_recv
(
pull
,
buffer
,
5
,
0
);
assert
(
num_bytes
==
5
);
recv_string_expect_success
(
pull
,
"Hello"
,
0
);
}
int
child_status
;
while
(
true
)
{
rc
=
waitpid
(
pid
,
&
child_status
,
0
);
int
rc
=
waitpid
(
pid
,
&
child_status
,
0
);
if
(
rc
==
-
1
&&
errno
==
EINTR
)
continue
;
assert
(
rc
>
0
);
TEST_ASSERT_GREATER_THAN
(
0
,
rc
);
// Verify the status code of the child was zero
assert
(
WEXITSTATUS
(
child_status
)
==
0
);
TEST_ASSERT_EQUAL
(
0
,
WEXITSTATUS
(
child_status
)
);
break
;
}
zmq_close
(
pull
);
zmq_ctx_term
(
ctx
);
exit
(
0
);
test_context_socket_close
(
pull
);
}
#endif
return
0
;
}
int
main
(
void
)
{
setup_test_environment
();
UNITY_BEGIN
();
RUN_TEST
(
test_fork
);
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