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
21b8d5cf
Commit
21b8d5cf
authored
Feb 04, 2020
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: duplicated code in tests related to monitoring
Solution: extract new receive_monitor_address function
parent
495fb00b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
109 deletions
+35
-109
test_security_gssapi.cpp
tests/test_security_gssapi.cpp
+1
-37
test_stream_timeout.cpp
tests/test_stream_timeout.cpp
+1
-35
testutil_monitoring.cpp
tests/testutil_monitoring.cpp
+29
-37
testutil_monitoring.hpp
tests/testutil_monitoring.hpp
+4
-0
No files found.
tests/test_security_gssapi.cpp
View file @
21b8d5cf
...
...
@@ -28,6 +28,7 @@
*/
#include "testutil.hpp"
#include "testutil_monitoring.hpp"
#include "testutil_unity.hpp"
#if defined(ZMQ_HAVE_WINDOWS)
#include <winsock2.h>
...
...
@@ -178,43 +179,6 @@ void tearDown ()
zmq_threadclose
(
zap_thread
);
}
// 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
TEST_ASSERT_TRUE
(
zmq_msg_more
(
&
msg
));
uint8_t
*
data
=
static_cast
<
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
uint16_t
event
=
*
reinterpret_cast
<
uint16_t
*>
(
data
);
if
(
value_
)
*
value_
=
*
reinterpret_cast
<
uint32_t
*>
(
data
+
2
);
zmq_msg_close
(
&
msg
);
// Second frame in message contains event address
zmq_msg_init
(
&
msg
);
if
(
zmq_msg_recv
(
&
msg
,
monitor_
,
0
)
==
-
1
)
return
-
1
;
// Interruped, presumably
TEST_ASSERT_FALSE
(
zmq_msg_more
(
&
msg
));
if
(
address_
)
{
const
uint8_t
*
const
data
=
static_cast
<
const
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
const
size_t
size
=
zmq_msg_size
(
&
msg
);
*
address_
=
static_cast
<
char
*>
(
malloc
(
size
+
1
));
memcpy
(
*
address_
,
data
,
size
);
*
address_
[
size
]
=
0
;
}
zmq_msg_close
(
&
msg
);
return
event
;
}
void
test_valid_creds
()
{
void
*
client
=
test_context_socket
(
ZMQ_DEALER
);
...
...
tests/test_stream_timeout.cpp
View file @
21b8d5cf
...
...
@@ -28,6 +28,7 @@
*/
#include "testutil.hpp"
#include "testutil_monitoring.hpp"
#include "testutil_unity.hpp"
#include <stdlib.h>
...
...
@@ -35,41 +36,6 @@
SETUP_TEARDOWN_TESTCONTEXT
// 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
TEST_ASSERT_TRUE
(
zmq_msg_more
(
&
msg
));
uint8_t
*
data
=
static_cast
<
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
uint16_t
event
=
*
reinterpret_cast
<
uint16_t
*>
(
data
);
if
(
value_
)
*
value_
=
*
reinterpret_cast
<
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
TEST_ASSERT_TRUE
(
!
zmq_msg_more
(
&
msg
));
if
(
address_
)
{
const
uint8_t
*
const
data
=
static_cast
<
const
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
const
size_t
size
=
zmq_msg_size
(
&
msg
);
*
address_
=
static_cast
<
char
*>
(
malloc
(
size
+
1
));
memcpy
(
*
address_
,
data
,
size
);
*
address_
[
size
]
=
0
;
}
return
event
;
}
static
void
test_stream_handshake_timeout_accept
()
{
char
my_endpoint
[
MAX_SOCKET_STRING
];
...
...
tests/testutil_monitoring.cpp
View file @
21b8d5cf
...
...
@@ -32,10 +32,32 @@
#include <stdlib.h>
#include <string.h>
static
int
receive_monitor_address
(
void
*
monitor_
,
char
**
address_
,
bool
expect_more_
)
{
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
if
(
zmq_msg_recv
(
&
msg
,
monitor_
,
0
)
==
-
1
)
return
-
1
;
// Interrupted, presumably
TEST_ASSERT_EQUAL
(
expect_more_
,
zmq_msg_more
(
&
msg
));
if
(
address_
)
{
const
uint8_t
*
const
data
=
static_cast
<
const
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
const
size_t
size
=
zmq_msg_size
(
&
msg
);
*
address_
=
static_cast
<
char
*>
(
malloc
(
size
+
1
));
memcpy
(
*
address_
,
data
,
size
);
(
*
address_
)[
size
]
=
0
;
}
zmq_msg_close
(
&
msg
);
return
0
;
}
// 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_internal
(
void
*
monitor_
,
int
*
value_
,
char
**
address_
,
...
...
@@ -56,18 +78,9 @@ static int get_monitor_event_internal (void *monitor_,
memcpy
(
value_
,
data
+
2
,
sizeof
(
uint32_t
));
// Second frame in message contains event address
zmq_msg_init
(
&
msg
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
monitor_
,
recv_flag_
));
TEST_ASSERT_FALSE
(
zmq_msg_more
(
&
msg
));
TEST_ASSERT_SUCCESS_ERRNO
(
receive_monitor_address
(
monitor_
,
address_
,
false
));
if
(
address_
)
{
const
uint8_t
*
const
data
=
static_cast
<
const
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
const
size_t
size
=
zmq_msg_size
(
&
msg
);
*
address_
=
static_cast
<
char
*>
(
malloc
(
size
+
1
));
memcpy
(
*
address_
,
data
,
size
);
(
*
address_
)[
size
]
=
0
;
}
return
event
;
}
...
...
@@ -242,34 +255,13 @@ static int64_t get_monitor_event_internal_v2 (void *monitor_,
}
// Second-to-last frame in message contains local address
zmq_msg_init
(
&
msg
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
monitor_
,
recv_flag_
));
TEST_ASSERT_TRUE
(
zmq_msg_more
(
&
msg
));
if
(
local_address_
)
{
const
uint8_t
*
const
data
=
static_cast
<
const
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
const
size_t
size
=
zmq_msg_size
(
&
msg
);
*
local_address_
=
static_cast
<
char
*>
(
malloc
(
size
+
1
));
memcpy
(
*
local_address_
,
data
,
size
);
(
*
local_address_
)[
size
]
=
0
;
}
zmq_msg_close
(
&
msg
);
TEST_ASSERT_SUCCESS_ERRNO
(
receive_monitor_address
(
monitor_
,
local_address_
,
true
));
// Last frame in message contains remote address
zmq_msg_init
(
&
msg
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
monitor_
,
recv_flag_
));
TEST_ASSERT_TRUE
(
!
zmq_msg_more
(
&
msg
));
TEST_ASSERT_SUCCESS_ERRNO
(
receive_monitor_address
(
monitor_
,
remote_address_
,
false
));
if
(
remote_address_
)
{
const
uint8_t
*
data
=
static_cast
<
const
uint8_t
*>
(
zmq_msg_data
(
&
msg
));
const
size_t
size
=
zmq_msg_size
(
&
msg
);
*
remote_address_
=
static_cast
<
char
*>
(
malloc
(
size
+
1
));
memcpy
(
*
remote_address_
,
data
,
size
);
(
*
remote_address_
)[
size
]
=
0
;
}
zmq_msg_close
(
&
msg
);
return
event
;
}
...
...
tests/testutil_monitoring.hpp
View file @
21b8d5cf
...
...
@@ -42,6 +42,9 @@ int get_monitor_event_with_timeout (void *monitor_,
char
**
address_
,
int
timeout_
);
// 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.
int
get_monitor_event
(
void
*
monitor_
,
int
*
value_
,
char
**
address_
);
void
expect_monitor_event
(
void
*
monitor_
,
int
expected_event_
);
...
...
@@ -72,4 +75,5 @@ void expect_monitor_event_v2 (void *monitor_,
int64_t
expected_event_
,
const
char
*
expected_local_address_
=
NULL
,
const
char
*
expected_remote_address_
=
NULL
);
#endif
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