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
dce77fda
Commit
dce77fda
authored
Aug 16, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_filter_ipc not yet using unity
Solution: migrate to unity
parent
fe82c643
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
68 deletions
+127
-68
Makefile.am
Makefile.am
+2
-1
test_filter_ipc.cpp
tests/test_filter_ipc.cpp
+123
-65
testutil_unity.hpp
tests/testutil_unity.hpp
+2
-2
No files found.
Makefile.am
View file @
dce77fda
...
...
@@ -775,7 +775,8 @@ tests_test_timeo_SOURCES = tests/test_timeo.cpp
tests_test_timeo_LDADD
=
src/libzmq.la
tests_test_filter_ipc_SOURCES
=
tests/test_filter_ipc.cpp
tests_test_filter_ipc_LDADD
=
src/libzmq.la
tests_test_filter_ipc_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_filter_ipc_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_use_fd_ipc_SOURCES
=
\
tests/test_use_fd_ipc.cpp
\
...
...
tests/test_filter_ipc.cpp
View file @
dce77fda
...
...
@@ -28,6 +28,17 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
static
void
bounce_fail
(
void
*
server_
,
void
*
client_
)
{
...
...
@@ -35,131 +46,178 @@ static void bounce_fail (void *server_, void *client_)
char
buffer
[
32
];
// Send message from client to server
int
rc
=
zmq_send
(
client_
,
content
,
32
,
ZMQ_SNDMORE
);
assert
(
rc
==
32
);
rc
=
zmq_send
(
client_
,
content
,
32
,
0
);
assert
(
rc
==
32
);
send_string_expect_success
(
client_
,
content
,
ZMQ_SNDMORE
);
send_string_expect_success
(
client_
,
content
,
0
);
// Receive message at server side (should not succeed)
int
timeout
=
250
;
rc
=
zmq_setsockopt
(
server_
,
ZMQ_RCVTIMEO
,
&
timeout
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_recv
(
server_
,
buffer
,
32
,
0
);
assert
(
rc
==
-
1
);
assert
(
zmq_errno
()
==
EAGAIN
);
int
timeout
=
SETTLE_TIME
;
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
server_
,
ZMQ_RCVTIMEO
,
&
timeout
,
sizeof
(
int
)));
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_recv
(
server_
,
buffer
,
32
,
0
));
// Send message from server to client to test other direction
rc
=
zmq_setsockopt
(
server_
,
ZMQ_SNDTIMEO
,
&
timeout
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_send
(
server_
,
content
,
32
,
ZMQ_SNDMORE
);
assert
(
rc
==
-
1
);
assert
(
zmq_errno
()
==
EAGAIN
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
server_
,
ZMQ_SNDTIMEO
,
&
timeout
,
sizeof
(
int
)));
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_send
(
server_
,
content
,
32
,
ZMQ_SNDMORE
));
}
template
<
class
T
>
static
void
run_test
(
int
opt_
,
T
optval_
,
int
expected_error_
,
int
bounce_test_
)
{
int
rc
;
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
sb
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
sb
);
void
*
sb
=
test_context_socket
(
ZMQ_DEALER
);
if
(
opt_
)
{
rc
=
zmq_setsockopt
(
sb
,
opt_
,
&
optval_
,
sizeof
(
optval_
));
const
int
rc
=
zmq_setsockopt
(
sb
,
opt_
,
&
optval_
,
sizeof
(
optval_
));
if
(
expected_error_
)
{
assert
(
rc
==
-
1
);
assert
(
zmq_errno
()
==
expected_error_
);
}
else
assert
(
rc
==
0
);
TEST_ASSERT_FAILURE_ERRNO
(
expected_error_
,
rc
);
}
else
{
TEST_ASSERT_SUCCESS_ERRNO
(
rc
);
}
}
void
*
sc
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
sc
);
void
*
sc
=
test_context_socket
(
ZMQ_DEALER
);
// If a test fails, don't hang for too long
int
timeout
=
2500
;
rc
=
zmq_setsockopt
(
sb
,
ZMQ_RCVTIMEO
,
&
timeout
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_setsockopt
(
sb
,
ZMQ_SNDTIMEO
,
&
timeout
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_setsockopt
(
sc
,
ZMQ_RCVTIMEO
,
&
timeout
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_setsockopt
(
sc
,
ZMQ_SNDTIMEO
,
&
timeout
,
sizeof
(
int
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb
,
ZMQ_RCVTIMEO
,
&
timeout
,
sizeof
(
int
))
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb
,
ZMQ_SNDTIMEO
,
&
timeout
,
sizeof
(
int
))
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sc
,
ZMQ_RCVTIMEO
,
&
timeout
,
sizeof
(
int
))
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sc
,
ZMQ_SNDTIMEO
,
&
timeout
,
sizeof
(
int
))
);
int
interval
=
-
1
;
rc
=
zmq_setsockopt
(
sc
,
ZMQ_RECONNECT_IVL
,
&
interval
,
sizeof
(
int
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sc
,
ZMQ_RECONNECT_IVL
,
&
interval
,
sizeof
(
int
))
);
if
(
bounce_test_
)
{
const
char
*
endpoint
=
"ipc://test_filter_ipc.sock"
;
int
rc
=
zmq_bind
(
sb
,
endpoint
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
sc
,
endpoint
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
endpoint
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sc
,
endpoint
));
if
(
bounce_test_
>
0
)
bounce
(
sb
,
sc
);
else
bounce_fail
(
sb
,
sc
);
}
close_zero_linger
(
sc
);
close_zero_linger
(
sb
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
// TODO only use zero linger when bounce_test_ < 0?
test_context_socket_close_zero_linger
(
sc
);
test_context_socket_close_zero_linger
(
sb
);
}
int
main
(
void
)
{
#if !defined(ZMQ_HAVE_WINDOWS)
setup_test_environment
();
// No filters
run_test
<
int
>
(
0
,
0
,
0
,
1
);
#if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
// Get the group and supplimental groups of the process owner
gid_t
group
,
supgroup
,
notgroup
;
void
init_groups
()
{
// Get the group and supplemental groups of the process owner
gid_t
groups
[
100
];
int
ngroups
=
getgroups
(
100
,
groups
);
assert
(
ngroups
!=
-
1
);
gid_t
group
=
getgid
(),
supgroup
=
group
,
notgroup
=
group
+
1
;
group
=
getgid
();
supgroup
=
group
;
notgroup
=
group
+
1
;
for
(
int
i
=
0
;
i
<
ngroups
;
i
++
)
{
if
(
supgroup
==
group
&&
group
!=
groups
[
i
])
supgroup
=
groups
[
i
];
if
(
notgroup
<=
groups
[
i
])
notgroup
=
groups
[
i
]
+
1
;
}
}
#endif
void
test_no_filters
()
{
run_test
<
int
>
(
0
,
0
,
0
,
1
);
}
// Test filter with UID of process owner
#if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
void
test_filter_with_process_owner_uid
()
{
run_test
<
uid_t
>
(
ZMQ_IPC_FILTER_UID
,
getuid
(),
0
,
1
);
// Test filter with UID of another (possibly non-existent) user
}
void
test_filter_with_possibly_nonexistent_uid
()
{
run_test
<
uid_t
>
(
ZMQ_IPC_FILTER_UID
,
getuid
()
+
1
,
0
,
-
1
);
// Test filter with GID of process owner
}
void
test_filter_with_process_owner_gid
()
{
run_test
<
gid_t
>
(
ZMQ_IPC_FILTER_GID
,
group
,
0
,
1
);
// Test filter with supplimental group of process owner
}
void
test_filter_with_supplemental_process_owner_gid
()
{
run_test
<
gid_t
>
(
ZMQ_IPC_FILTER_GID
,
supgroup
,
0
,
1
);
// Test filter with GID of another (possibly non-existent) group
}
void
test_filter_with_possibly_nonexistent_gid
()
{
run_test
<
gid_t
>
(
ZMQ_IPC_FILTER_GID
,
notgroup
,
0
,
-
1
);
}
#if defined ZMQ_HAVE_SO_PEERCRED
// Test filter with PID of current process
void
test_filter_with_current_process_pid
()
{
run_test
<
pid_t
>
(
ZMQ_IPC_FILTER_PID
,
getpid
(),
0
,
1
);
// Test filter with PID of another (possibly non-existent) process
}
void
test_filter_with_possibly_nonexistent_pid
()
{
run_test
<
pid_t
>
(
ZMQ_IPC_FILTER_PID
,
getpid
()
+
1
,
0
,
-
1
);
}
#else
void
test_filter_with_pid_fails
()
{
// Setup of PID filter should fail with operation not supported error
// TODO EINVAL is not ENOTSUP (!)
run_test
<
pid_t
>
(
ZMQ_IPC_FILTER_PID
,
getpid
(),
EINVAL
,
0
);
}
#endif
#else
void
test_filter_with_zero_uid_fails
()
{
run_test
<
uid_t
>
(
ZMQ_IPC_FILTER_UID
,
0
,
EINVAL
,
0
);
}
void
test_filter_with_zero_gid_fails
()
{
run_test
<
gid_t
>
(
ZMQ_IPC_FILTER_GID
,
0
,
EINVAL
,
0
);
}
void
test_filter_with_zero_pid_fails
()
{
run_test
<
pid_t
>
(
ZMQ_IPC_FILTER_PID
,
0
,
EINVAL
,
0
);
}
#endif // defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
int
main
(
void
)
{
#if !defined(ZMQ_HAVE_WINDOWS)
setup_test_environment
();
#if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
init_groups
();
#endif
UNITY_BEGIN
();
RUN_TEST
(
test_no_filters
);
#if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
RUN_TEST
(
test_filter_with_process_owner_uid
);
RUN_TEST
(
test_filter_with_possibly_nonexistent_uid
);
RUN_TEST
(
test_filter_with_process_owner_gid
);
RUN_TEST
(
test_filter_with_supplemental_process_owner_gid
);
RUN_TEST
(
test_filter_with_possibly_nonexistent_gid
);
#if defined ZMQ_HAVE_SO_PEERCRED
RUN_TEST
(
test_filter_with_current_process_pid
);
RUN_TEST
(
test_filter_with_possibly_nonexistent_pid
);
#else
RUN_TEST
(
test_filter_with_pid_fails
());
#endif
#else
RUN_TEST
(
test_filter_with_zero_uid_fails
);
RUN_TEST
(
test_filter_with_zero_gid_fails
);
RUN_TEST
(
test_filter_with_zero_pid_fails
);
#endif // defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
return
UNITY_END
();
#else
return
0
;
#endif
}
tests/testutil_unity.hpp
View file @
dce77fda
...
...
@@ -90,8 +90,8 @@ int test_assert_success_message_raw_errno_helper (int rc_,
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr) \
{ \
int
rc = (expr);
\
TEST_ASSERT_EQUAL_INT (-1,
rc);
\
int
_rc = (expr);
\
TEST_ASSERT_EQUAL_INT (-1,
_rc);
\
TEST_ASSERT_EQUAL_INT (error_code, errno); \
}
...
...
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