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
82227136
Commit
82227136
authored
Aug 20, 2017
by
Simon Giesecke
Committed by
sigiesec
Aug 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_monitor sometimes fails due to a wrong event received, but not known which
Solution: add diagnostic output
parent
5e85fa6a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
45 deletions
+22
-45
test_monitor.cpp
tests/test_monitor.cpp
+6
-45
testutil_security.hpp
tests/testutil_security.hpp
+16
-0
No files found.
tests/test_monitor.cpp
View file @
82227136
...
...
@@ -28,41 +28,7 @@
*/
#include "testutil.hpp"
// Read one event off the monitor socket; return value and address
// by reference, if not null, and event number by value. Returns -1
// in case of error.
static
int
get_monitor_event
(
void
*
monitor
,
int
*
value
,
char
**
address
)
{
// First frame in message contains event number and value
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
if
(
zmq_msg_recv
(
&
msg
,
monitor
,
0
)
==
-
1
)
return
-
1
;
// Interruped, presumably
assert
(
zmq_msg_more
(
&
msg
));
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
uint16_t
event
=
*
(
uint16_t
*
)
(
data
);
if
(
value
)
*
value
=
*
(
uint32_t
*
)
(
data
+
2
);
// Second frame in message contains event address
zmq_msg_init
(
&
msg
);
if
(
zmq_msg_recv
(
&
msg
,
monitor
,
0
)
==
-
1
)
return
-
1
;
// Interruped, presumably
assert
(
!
zmq_msg_more
(
&
msg
));
if
(
address
)
{
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
size_t
size
=
zmq_msg_size
(
&
msg
);
*
address
=
(
char
*
)
malloc
(
size
+
1
);
memcpy
(
*
address
,
data
,
size
);
*
address
[
size
]
=
0
;
}
return
event
;
}
#include "testutil_security.hpp"
int
main
(
void
)
{
...
...
@@ -121,20 +87,15 @@ int main (void)
event
=
get_monitor_event
(
client_mon
,
NULL
,
NULL
);
assert
(
event
==
ZMQ_EVENT_CONNECTED
);
#ifdef ZMQ_BUILD_DRAFT_API
event
=
get_monitor_event
(
client_mon
,
NULL
,
NULL
);
assert
(
event
==
ZMQ_EVENT_HANDSHAKE_SUCCEEDED
);
expect_monitor_event
(
client_mon
,
ZMQ_EVENT_HANDSHAKE_SUCCEEDED
);
#endif
event
=
get_monitor_event
(
client_mon
,
NULL
,
NULL
);
assert
(
event
==
ZMQ_EVENT_MONITOR_STOPPED
);
expect_monitor_event
(
client_mon
,
ZMQ_EVENT_MONITOR_STOPPED
);
// This is the flow of server events
event
=
get_monitor_event
(
server_mon
,
NULL
,
NULL
);
assert
(
event
==
ZMQ_EVENT_LISTENING
);
event
=
get_monitor_event
(
server_mon
,
NULL
,
NULL
);
assert
(
event
==
ZMQ_EVENT_ACCEPTED
);
expect_monitor_event
(
server_mon
,
ZMQ_EVENT_LISTENING
);
expect_monitor_event
(
server_mon
,
ZMQ_EVENT_ACCEPTED
);
#ifdef ZMQ_BUILD_DRAFT_API
event
=
get_monitor_event
(
server_mon
,
NULL
,
NULL
);
assert
(
event
==
ZMQ_EVENT_HANDSHAKE_SUCCEEDED
);
expect_monitor_event
(
server_mon
,
ZMQ_EVENT_HANDSHAKE_SUCCEEDED
);
#endif
event
=
get_monitor_event
(
server_mon
,
NULL
,
NULL
);
// Sometimes the server sees the client closing before it gets closed.
...
...
tests/testutil_security.hpp
View file @
82227136
...
...
@@ -499,6 +499,22 @@ int get_monitor_event_with_timeout (void *monitor,
return
res
;
}
int
get_monitor_event
(
void
*
monitor
,
int
*
value
,
char
**
address
)
{
return
get_monitor_event_with_timeout
(
monitor
,
value
,
address
,
-
1
);
}
void
expect_monitor_event
(
void
*
monitor
,
int
expected_event
)
{
int
event
=
get_monitor_event
(
monitor
,
NULL
,
NULL
);
if
(
event
!=
expected_event
)
{
fprintf
(
stderr
,
"Expected monitor event %x but received %x
\n
"
,
expected_event
,
event
);
assert
(
event
==
expected_event
);
}
}
#ifdef ZMQ_BUILD_DRAFT_API
void
print_unexpected_event
(
int
event
,
...
...
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