test_metadata.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "testutil.hpp"
4 #include "testutil_unity.hpp"
5 
6 #include <stdlib.h>
7 #include <unity.h>
8 
9 void setUp ()
10 {
11 }
12 
13 void tearDown ()
14 {
15 }
16 
17 static void zap_handler (void *handler_)
18 {
19  uint8_t metadata[] = {5, 'H', 'e', 'l', 'l', 'o', 0, 0,
20  0, 5, 'W', 'o', 'r', 'l', 'd'};
21 
22  // Process ZAP requests forever
23  while (true) {
24  char *version = s_recv (handler_);
25  if (!version)
26  break; // Terminating
27 
28  char *sequence = s_recv (handler_);
29  char *domain = s_recv (handler_);
30  char *address = s_recv (handler_);
31  char *routing_id = s_recv (handler_);
32  char *mechanism = s_recv (handler_);
33 
35  TEST_ASSERT_EQUAL_STRING ("NULL", mechanism);
36 
38  send_string_expect_success (handler_, sequence, ZMQ_SNDMORE);
39  if (streq (domain, "DOMAIN")) {
40  send_string_expect_success (handler_, "200", ZMQ_SNDMORE);
41  send_string_expect_success (handler_, "OK", ZMQ_SNDMORE);
42  send_string_expect_success (handler_, "anonymous", ZMQ_SNDMORE);
43  zmq_send (handler_, metadata, sizeof (metadata), 0);
44  } else {
45  send_string_expect_success (handler_, "400", ZMQ_SNDMORE);
46  send_string_expect_success (handler_, "BAD DOMAIN", ZMQ_SNDMORE);
48  send_string_expect_success (handler_, "", 0);
49  }
50  free (version);
51  free (sequence);
52  free (domain);
53  free (address);
54  free (routing_id);
55  free (mechanism);
56  }
57  close_zero_linger (handler_);
58 }
59 
61 {
64 
65  // Spawn ZAP handler
66  // We create and bind ZAP socket in main thread to avoid case
67  // where child thread does not start up fast enough.
70  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (handler, "inproc://zeromq.zap.01"));
72 
76  zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "DOMAIN", 6));
79 
80  send_string_expect_success (client, "This is a message", 0);
81  zmq_msg_t msg;
82  zmq_msg_init (&msg);
84  TEST_ASSERT_EQUAL_STRING ("World", zmq_msg_gets (&msg, "Hello"));
85  TEST_ASSERT_EQUAL_STRING ("DEALER", zmq_msg_gets (&msg, "Socket-Type"));
86  TEST_ASSERT_EQUAL_STRING ("anonymous", zmq_msg_gets (&msg, "User-Id"));
87  TEST_ASSERT_EQUAL_STRING ("127.0.0.1", zmq_msg_gets (&msg, "Peer-Address"));
88 
89  TEST_ASSERT_NULL (zmq_msg_gets (&msg, "No Such"));
91  zmq_msg_close (&msg);
92 
95 
96  // Shutdown
98 
99  // Wait until ZAP handler terminates
101 }
102 
104 {
107 
108  // Spawn ZAP handler
109  // We create and bind ZAP socket in main thread to avoid case
110  // where child thread does not start up fast enough.
113  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (handler, "inproc://zeromq.zap.01"));
115 
119  zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "DOMAIN", 6));
122 
123  send_string_expect_success (client, "This is a message", 0);
124 
126 
127  // Check for messages in the ROUTER socket which will trigger a prefetch
128  unsigned long int dummy;
129  size_t dummy_size = sizeof (dummy);
130  zmq_getsockopt (server, ZMQ_EVENTS, &dummy, &dummy_size);
131 
132  zmq_msg_t msg;
133 
134  // Ensure all frames in the message contain metadata
135  for (int i = 0; i < 3; i++) {
136  zmq_msg_init (&msg);
138  TEST_ASSERT_EQUAL_STRING ("World", zmq_msg_gets (&msg, "Hello"));
139  zmq_msg_close (&msg);
140  }
141 
144 
145  // Shutdown
147 
148  // Wait until ZAP handler terminates
150 }
151 
152 
153 int main ()
154 {
156  UNITY_BEGIN ();
159  return UNITY_END ();
160 }
TEST_ASSERT_EQUAL_STRING
#define TEST_ASSERT_EQUAL_STRING(expected, actual)
Definition: unity.h:235
test_router_prefetch_metadata
void test_router_prefetch_metadata()
Definition: test_metadata.cpp:103
domain
const char domain[]
Definition: test_security_plain.cpp:74
UNITY_END
return UNITY_END()
setUp
void setUp()
Definition: test_metadata.cpp:9
ZMQ_EVENTS
#define ZMQ_EVENTS
Definition: zmq.h:286
zmq_threadstart
ZMQ_EXPORT void * zmq_threadstart(zmq_thread_fn *func_, void *arg_)
Definition: zmq_utils.cpp:54
zmq_errno
ZMQ_EXPORT int zmq_errno(void)
Definition: zmq.cpp:101
EINVAL
#define EINVAL
Definition: errno.hpp:25
msleep
void msleep(int milliseconds_)
Definition: testutil.cpp:227
benchmarks.util.result_uploader.metadata
def metadata
Definition: result_uploader.py:97
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
tearDown
void tearDown()
Definition: test_metadata.cpp:13
setup_test_context
void setup_test_context()
Definition: testutil_unity.cpp:179
bind_loopback_ipv4
void bind_loopback_ipv4(void *socket_, char *my_endpoint_, size_t len_)
Definition: testutil_unity.cpp:246
main
int main()
Definition: test_metadata.cpp:153
teardown_test_context
void teardown_test_context()
Definition: testutil_unity.cpp:189
get_test_context
void * get_test_context()
Definition: testutil_unity.cpp:184
client
void client(int num)
Definition: test_multithread.cpp:134
address
const char * address
Definition: builds/zos/test_fork.cpp:6
dummy
ReturnVal dummy
Definition: register_benchmark_test.cc:68
test_context_socket_close_zero_linger
void * test_context_socket_close_zero_linger(void *socket_)
Definition: testutil_unity.cpp:215
close_zero_linger
void close_zero_linger(void *socket_)
Definition: testutil.cpp:193
test_metadata
void test_metadata()
Definition: test_metadata.cpp:60
s_recv
char * s_recv(void *socket_)
Definition: testutil.cpp:123
ZMQ_REQ
#define ZMQ_REQ
Definition: zmq.h:261
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
testutil_unity.hpp
zmq_msg_gets
const ZMQ_EXPORT char * zmq_msg_gets(const zmq_msg_t *msg_, const char *property_)
Definition: zmq.cpp:711
ZMQ_DEALER
#define ZMQ_DEALER
Definition: zmq.h:263
zmq_setsockopt
ZMQ_EXPORT int zmq_setsockopt(void *s_, int option_, const void *optval_, size_t optvallen_)
Definition: zmq.cpp:250
zmq_threadclose
ZMQ_EXPORT void zmq_threadclose(void *thread_)
Definition: zmq_utils.cpp:62
testutil.hpp
ZMQ_ROUTER
#define ZMQ_ROUTER
Definition: zmq.h:264
zmq_msg_t
Definition: zmq.h:218
ZMQ_REP
#define ZMQ_REP
Definition: zmq.h:262
my_endpoint
char my_endpoint[MAX_SOCKET_STRING]
Definition: test_security_curve.cpp:31
MAX_SOCKET_STRING
#define MAX_SOCKET_STRING
Definition: libzmq/tests/testutil.hpp:35
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
zmq_msg_recv
ZMQ_EXPORT int zmq_msg_recv(zmq_msg_t *msg_, void *s_, int flags_)
Definition: zmq.cpp:617
zmq_socket
ZMQ_EXPORT void * zmq_socket(void *, int type_)
Definition: zmq.cpp:230
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
SETTLE_TIME
#define SETTLE_TIME
Definition: libzmq/tests/testutil.hpp:31
server
void * server
Definition: test_security_curve.cpp:29
TEST_ASSERT_EQUAL_INT
#define TEST_ASSERT_EQUAL_INT(expected, actual)
Definition: unity.h:128
streq
bool streq(const char *lhs_, const char *rhs_)
Definition: testutil.cpp:508
zmq_msg_init
ZMQ_EXPORT int zmq_msg_init(zmq_msg_t *msg_)
Definition: zmq.cpp:587
ZMQ_ZAP_DOMAIN
#define ZMQ_ZAP_DOMAIN
Definition: zmq.h:320
i
int i
Definition: gmock-matchers_test.cc:764
unity.h
send_string_expect_success
void send_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:94
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
ZMQ_SNDMORE
#define ZMQ_SNDMORE
Definition: zmq.h:359
zap_handler
static void zap_handler(void *handler_)
Definition: test_metadata.cpp:17
handler
void * handler
Definition: test_security_curve.cpp:27
zap_thread
void * zap_thread
Definition: test_security_curve.cpp:28
zmq_send
ZMQ_EXPORT int zmq_send(void *s_, const void *buf_, size_t len_, int flags_)
Definition: zmq.cpp:377
version
static struct @0 version
TEST_ASSERT_NOT_NULL
#define TEST_ASSERT_NOT_NULL(pointer)
Definition: unity.h:125
zmq_msg_close
ZMQ_EXPORT int zmq_msg_close(zmq_msg_t *msg_)
Definition: zmq.cpp:625
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47
zmq_getsockopt
ZMQ_EXPORT int zmq_getsockopt(void *s_, int option_, void *optval_, size_t *optvallen_)
Definition: zmq.cpp:261
TEST_ASSERT_NULL
#define TEST_ASSERT_NULL(pointer)
Definition: unity.h:124


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59