Lines 1-179
Link Here
|
1 |
From 4147957a5eec57ec7a2a416dca74c3c0299a3432 Mon Sep 17 00:00:00 2001 |
|
|
2 |
From: Luca Boccassi <bluca@debian.org> |
3 |
Date: Sun, 13 Jan 2019 13:08:10 +0000 |
4 |
Subject: [PATCH 1/2] Problem: test_security_zap fails on architectures that |
5 |
disallow unaligned pointer access |
6 |
|
7 |
Solution: use memcpy instead of doing pointer arithmetics with casting |
8 |
and dereferencing to fix the error on sparc64 |
9 |
--- |
10 |
tests/testutil_security.hpp | 2 +- |
11 |
1 file changed, 1 insertion(+), 1 deletion(-) |
12 |
|
13 |
diff --git tests/testutil_security.hpp tests/testutil_security.hpp |
14 |
index 90999118c..437bfb298 100644 |
15 |
--- tests/testutil_security.hpp |
16 |
+++ tests/testutil_security.hpp |
17 |
@@ -345,7 +345,7 @@ static int get_monitor_event_internal (void *monitor_, |
18 |
uint8_t *data = (uint8_t *) zmq_msg_data (&msg); |
19 |
uint16_t event = *(uint16_t *) (data); |
20 |
if (value_) |
21 |
- *value_ = *(uint32_t *) (data + 2); |
22 |
+ memcpy (value_, data + 2, sizeof (uint32_t)); |
23 |
|
24 |
// Second frame in message contains event address |
25 |
zmq_msg_init (&msg); |
26 |
|
27 |
From f64b697095c6d8862bdfd2a159857e915bbf20ee Mon Sep 17 00:00:00 2001 |
28 |
From: Luca Boccassi <bluca@debian.org> |
29 |
Date: Sun, 13 Jan 2019 14:50:07 +0000 |
30 |
Subject: [PATCH 2/2] Problem: tests use hard-coded fixed IPC file path |
31 |
|
32 |
Solution: use wildcards or random directories to avoid races when |
33 |
multiple users are running the same test on the same machine |
34 |
--- |
35 |
tests/test_pair_ipc.cpp | 9 +++++++-- |
36 |
tests/test_rebind_ipc.cpp | 13 ++++++++----- |
37 |
tests/test_reconnect_ivl.cpp | 10 +++++++--- |
38 |
tests/test_use_fd.cpp | 24 +++++++++++++++++++----- |
39 |
4 files changed, 41 insertions(+), 15 deletions(-) |
40 |
|
41 |
diff --git tests/test_pair_ipc.cpp tests/test_pair_ipc.cpp |
42 |
index c9a216dd2..ab4dde350 100644 |
43 |
--- tests/test_pair_ipc.cpp |
44 |
+++ tests/test_pair_ipc.cpp |
45 |
@@ -44,11 +44,16 @@ void tearDown () |
46 |
|
47 |
void test_roundtrip () |
48 |
{ |
49 |
+ char my_endpoint[256]; |
50 |
+ size_t len = sizeof (my_endpoint); |
51 |
+ |
52 |
void *sb = test_context_socket (ZMQ_PAIR); |
53 |
- TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc:///tmp/test_pair_ipc")); |
54 |
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc://*")); |
55 |
+ TEST_ASSERT_SUCCESS_ERRNO ( |
56 |
+ zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); |
57 |
|
58 |
void *sc = test_context_socket (ZMQ_PAIR); |
59 |
- TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, "ipc:///tmp/test_pair_ipc")); |
60 |
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint)); |
61 |
|
62 |
bounce (sb, sc); |
63 |
|
64 |
diff --git tests/test_rebind_ipc.cpp tests/test_rebind_ipc.cpp |
65 |
index 830d18030..784641270 100644 |
66 |
--- tests/test_rebind_ipc.cpp |
67 |
+++ tests/test_rebind_ipc.cpp |
68 |
@@ -42,24 +42,27 @@ void tearDown () |
69 |
teardown_test_context (); |
70 |
} |
71 |
|
72 |
-static const char *SOCKET_ADDR = "ipc:///tmp/test_rebind_ipc"; |
73 |
- |
74 |
void test_rebind_ipc () |
75 |
{ |
76 |
+ char my_endpoint[256]; |
77 |
+ size_t len = sizeof (my_endpoint); |
78 |
+ |
79 |
void *sb0 = test_context_socket (ZMQ_PUSH); |
80 |
void *sb1 = test_context_socket (ZMQ_PUSH); |
81 |
|
82 |
- TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb0, SOCKET_ADDR)); |
83 |
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb0, "ipc://*")); |
84 |
+ TEST_ASSERT_SUCCESS_ERRNO ( |
85 |
+ zmq_getsockopt (sb0, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); |
86 |
|
87 |
void *sc = test_context_socket (ZMQ_PULL); |
88 |
- TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, SOCKET_ADDR)); |
89 |
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint)); |
90 |
|
91 |
send_string_expect_success (sb0, "42", 0); |
92 |
recv_string_expect_success (sc, "42", 0); |
93 |
|
94 |
test_context_socket_close (sb0); |
95 |
|
96 |
- TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb1, SOCKET_ADDR)); |
97 |
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb1, my_endpoint)); |
98 |
|
99 |
send_string_expect_success (sb1, "42", 0); |
100 |
recv_string_expect_success (sc, "42", 0); |
101 |
diff --git tests/test_reconnect_ivl.cpp tests/test_reconnect_ivl.cpp |
102 |
index b67b40e5f..6dd0e4cd2 100644 |
103 |
--- tests/test_reconnect_ivl.cpp |
104 |
+++ tests/test_reconnect_ivl.cpp |
105 |
@@ -71,11 +71,15 @@ void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_, |
106 |
#if !defined(ZMQ_HAVE_WINDOWS) && !defined(ZMQ_HAVE_GNU) |
107 |
void test_reconnect_ivl_ipc (void) |
108 |
{ |
109 |
- const char *ipc_endpoint = "ipc:///tmp/test_reconnect_ivl"; |
110 |
+ char my_endpoint[256]; |
111 |
+ size_t len = sizeof (my_endpoint); |
112 |
+ |
113 |
void *sb = test_context_socket (ZMQ_PAIR); |
114 |
- TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, ipc_endpoint)); |
115 |
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc://*")); |
116 |
+ TEST_ASSERT_SUCCESS_ERRNO ( |
117 |
+ zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); |
118 |
|
119 |
- test_reconnect_ivl_against_pair_socket (ipc_endpoint, sb); |
120 |
+ test_reconnect_ivl_against_pair_socket (my_endpoint, sb); |
121 |
test_context_socket_close (sb); |
122 |
} |
123 |
#endif |
124 |
diff --git tests/test_use_fd.cpp tests/test_use_fd.cpp |
125 |
index 67414f5bf..e9852b13d 100644 |
126 |
--- tests/test_use_fd.cpp |
127 |
+++ tests/test_use_fd.cpp |
128 |
@@ -237,24 +237,38 @@ void pre_allocate_sock_ipc_int (void *zmq_socket_, const char *path_) |
129 |
sizeof (struct sockaddr_un)); |
130 |
} |
131 |
|
132 |
+char ipc_endpoint[16]; |
133 |
+ |
134 |
void pre_allocate_sock_ipc (void *sb_, char *my_endpoint_) |
135 |
{ |
136 |
- pre_allocate_sock_ipc_int (sb_, "/tmp/test_use_fd_ipc"); |
137 |
- strcpy (my_endpoint_, "ipc:///tmp/test_use_fd_ipc"); |
138 |
+ strcpy (ipc_endpoint, "tmpXXXXXX"); |
139 |
+ |
140 |
+#ifdef HAVE_MKDTEMP |
141 |
+ TEST_ASSERT_TRUE (mkdtemp (ipc_endpoint)); |
142 |
+ strcat (ipc_endpoint, "/ipc"); |
143 |
+#else |
144 |
+ int fd = mkstemp (ipc_endpoint); |
145 |
+ TEST_ASSERT_TRUE (fd != -1); |
146 |
+ close (fd); |
147 |
+#endif |
148 |
+ |
149 |
+ pre_allocate_sock_ipc_int (sb_, ipc_endpoint); |
150 |
+ strcpy (my_endpoint_, "ipc://"); |
151 |
+ strcat (my_endpoint_, ipc_endpoint); |
152 |
} |
153 |
|
154 |
void test_req_rep_ipc () |
155 |
{ |
156 |
test_req_rep (pre_allocate_sock_ipc); |
157 |
|
158 |
- TEST_ASSERT_SUCCESS_ERRNO (unlink ("/tmp/test_use_fd_ipc")); |
159 |
+ TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint)); |
160 |
} |
161 |
|
162 |
void test_pair_ipc () |
163 |
{ |
164 |
test_pair (pre_allocate_sock_ipc); |
165 |
|
166 |
- TEST_ASSERT_SUCCESS_ERRNO (unlink ("/tmp/test_use_fd_ipc")); |
167 |
+ TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint)); |
168 |
} |
169 |
|
170 |
void test_client_server_ipc () |
171 |
@@ -262,7 +276,7 @@ void test_client_server_ipc () |
172 |
#if defined(ZMQ_SERVER) && defined(ZMQ_CLIENT) |
173 |
test_client_server (pre_allocate_sock_ipc); |
174 |
|
175 |
- TEST_ASSERT_SUCCESS_ERRNO (unlink ("/tmp/test_use_fd_ipc")); |
176 |
+ TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint)); |
177 |
#endif |
178 |
} |
179 |
|