aboutsummaryrefslogtreecommitdiff
path: root/src/seti
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-19 00:24:48 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-19 00:24:48 +0200
commit076acb9981bc141c7905e0dcf3f9fcda3497a8aa (patch)
tree0857ee937cca3607de20a218284abc9380d024d8 /src/seti
parent62853641f7ddb1e1b52b105c48039b3c65f36a32 (diff)
downloadgnunet-076acb9981bc141c7905e0dcf3f9fcda3497a8aa.tar.gz
gnunet-076acb9981bc141c7905e0dcf3f9fcda3497a8aa.zip
-fix test FTBFS
Diffstat (limited to 'src/seti')
-rw-r--r--src/seti/test_seti_api.c224
1 files changed, 86 insertions, 138 deletions
diff --git a/src/seti/test_seti_api.c b/src/seti/test_seti_api.c
index 42dedb846..22a3a06e5 100644
--- a/src/seti/test_seti_api.c
+++ b/src/seti/test_seti_api.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file set/test_set_intersection_result_full.c 22 * @file set/test_seti_api.c
23 * @brief testcase for full result mode of the intersection set operation 23 * @brief testcase for full result mode of the intersection set operation
24 * @author Christian Fuchs 24 * @author Christian Fuchs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
@@ -27,7 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30#include "gnunet_set_service.h" 30#include "gnunet_seti_service.h"
31 31
32 32
33static int ret; 33static int ret;
@@ -36,28 +36,26 @@ static struct GNUNET_PeerIdentity local_id;
36 36
37static struct GNUNET_HashCode app_id; 37static struct GNUNET_HashCode app_id;
38 38
39static struct GNUNET_SET_Handle *set1; 39static struct GNUNET_SETI_Handle *set1;
40 40
41static struct GNUNET_SET_Handle *set2; 41static struct GNUNET_SETI_Handle *set2;
42 42
43static struct GNUNET_SET_ListenHandle *listen_handle; 43static struct GNUNET_SETI_ListenHandle *listen_handle;
44 44
45static const struct GNUNET_CONFIGURATION_Handle *config; 45static const struct GNUNET_CONFIGURATION_Handle *config;
46 46
47static int iter_count;
48
49static struct GNUNET_SCHEDULER_Task *tt; 47static struct GNUNET_SCHEDULER_Task *tt;
50 48
51static struct GNUNET_SET_OperationHandle *oh1; 49static struct GNUNET_SETI_OperationHandle *oh1;
52 50
53static struct GNUNET_SET_OperationHandle *oh2; 51static struct GNUNET_SETI_OperationHandle *oh2;
54 52
55 53
56static void 54static void
57result_cb_set1 (void *cls, 55result_cb_set1 (void *cls,
58 const struct GNUNET_SET_Element *element, 56 const struct GNUNET_SETI_Element *element,
59 uint64_t current_size, 57 uint64_t current_size,
60 enum GNUNET_SET_Status status) 58 enum GNUNET_SETI_Status status)
61{ 59{
62 static int count; 60 static int count;
63 61
@@ -66,19 +64,17 @@ result_cb_set1 (void *cls,
66 status); 64 status);
67 switch (status) 65 switch (status)
68 { 66 {
69 case GNUNET_SET_STATUS_OK: 67 case GNUNET_SETI_STATUS_ADD_LOCAL:
70 count++; 68 count++;
71 break; 69 break;
72 70 case GNUNET_SETI_STATUS_FAILURE:
73 case GNUNET_SET_STATUS_FAILURE:
74 oh1 = NULL; 71 oh1 = NULL;
75 ret = 1; 72 ret = 1;
76 break; 73 break;
77 74 case GNUNET_SETI_STATUS_DONE:
78 case GNUNET_SET_STATUS_DONE:
79 oh1 = NULL; 75 oh1 = NULL;
80 GNUNET_assert (1 == count); 76 GNUNET_assert (1 == count);
81 GNUNET_SET_destroy (set1); 77 GNUNET_SETI_destroy (set1);
82 set1 = NULL; 78 set1 = NULL;
83 if (NULL == set2) 79 if (NULL == set2)
84 GNUNET_SCHEDULER_shutdown (); 80 GNUNET_SCHEDULER_shutdown ();
@@ -92,9 +88,9 @@ result_cb_set1 (void *cls,
92 88
93static void 89static void
94result_cb_set2 (void *cls, 90result_cb_set2 (void *cls,
95 const struct GNUNET_SET_Element *element, 91 const struct GNUNET_SETI_Element *element,
96 uint64_t current_size, 92 uint64_t current_size,
97 enum GNUNET_SET_Status status) 93 enum GNUNET_SETI_Status status)
98{ 94{
99 static int count; 95 static int count;
100 96
@@ -103,24 +99,21 @@ result_cb_set2 (void *cls,
103 status); 99 status);
104 switch (status) 100 switch (status)
105 { 101 {
106 case GNUNET_SET_STATUS_OK: 102 case GNUNET_SETI_STATUS_ADD_LOCAL:
107 count++; 103 count++;
108 break; 104 break;
109 105 case GNUNET_SETI_STATUS_FAILURE:
110 case GNUNET_SET_STATUS_FAILURE:
111 oh2 = NULL; 106 oh2 = NULL;
112 ret = 1; 107 ret = 1;
113 break; 108 break;
114 109 case GNUNET_SETI_STATUS_DONE:
115 case GNUNET_SET_STATUS_DONE:
116 oh2 = NULL; 110 oh2 = NULL;
117 GNUNET_assert (1 == count); 111 GNUNET_assert (1 == count);
118 GNUNET_SET_destroy (set2); 112 GNUNET_SETI_destroy (set2);
119 set2 = NULL; 113 set2 = NULL;
120 if (NULL == set1) 114 if (NULL == set1)
121 GNUNET_SCHEDULER_shutdown (); 115 GNUNET_SCHEDULER_shutdown ();
122 break; 116 break;
123
124 default: 117 default:
125 GNUNET_assert (0); 118 GNUNET_assert (0);
126 } 119 }
@@ -131,19 +124,23 @@ static void
131listen_cb (void *cls, 124listen_cb (void *cls,
132 const struct GNUNET_PeerIdentity *other_peer, 125 const struct GNUNET_PeerIdentity *other_peer,
133 const struct GNUNET_MessageHeader *context_msg, 126 const struct GNUNET_MessageHeader *context_msg,
134 struct GNUNET_SET_Request *request) 127 struct GNUNET_SETI_Request *request)
135{ 128{
129 struct GNUNET_SETI_Option opts[] = {
130 { .type = GNUNET_SETI_OPTION_RETURN_INTERSECTION },
131 { .type = GNUNET_SETI_OPTION_END }
132 };
133
136 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 134 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
137 "starting intersection by accepting and committing\n"); 135 "starting intersection by accepting and committing\n");
138 GNUNET_assert (NULL != context_msg); 136 GNUNET_assert (NULL != context_msg);
139 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); 137 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
140 oh2 = GNUNET_SET_accept (request, 138 oh2 = GNUNET_SETI_accept (request,
141 GNUNET_SET_RESULT_FULL, 139 opts,
142 (struct GNUNET_SET_Option[]) { 0 }, 140 &result_cb_set2,
143 &result_cb_set2, 141 NULL);
144 NULL); 142 GNUNET_SETI_commit (oh2,
145 GNUNET_SET_commit (oh2, 143 set2);
146 set2);
147} 144}
148 145
149 146
@@ -156,25 +153,27 @@ static void
156start (void *cls) 153start (void *cls)
157{ 154{
158 struct GNUNET_MessageHeader context_msg; 155 struct GNUNET_MessageHeader context_msg;
156 struct GNUNET_SETI_Option opts[] = {
157 { .type = GNUNET_SETI_OPTION_RETURN_INTERSECTION },
158 { .type = GNUNET_SETI_OPTION_END }
159 };
159 160
160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 161 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
161 "starting listener\n"); 162 "starting listener\n");
162 context_msg.size = htons (sizeof context_msg); 163 context_msg.size = htons (sizeof (context_msg));
163 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); 164 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
164 listen_handle = GNUNET_SET_listen (config, 165 listen_handle = GNUNET_SETI_listen (config,
165 GNUNET_SET_OPERATION_INTERSECTION, 166 &app_id,
166 &app_id, 167 &listen_cb,
167 &listen_cb, 168 NULL);
168 NULL); 169 oh1 = GNUNET_SETI_prepare (&local_id,
169 oh1 = GNUNET_SET_prepare (&local_id, 170 &app_id,
170 &app_id, 171 &context_msg,
171 &context_msg, 172 opts,
172 GNUNET_SET_RESULT_FULL, 173 &result_cb_set1,
173 (struct GNUNET_SET_Option[]) { 0 }, 174 NULL);
174 &result_cb_set1, 175 GNUNET_SETI_commit (oh1,
175 NULL); 176 set1);
176 GNUNET_SET_commit (oh1,
177 set1);
178} 177}
179 178
180 179
@@ -186,29 +185,29 @@ start (void *cls)
186static void 185static void
187init_set2 (void *cls) 186init_set2 (void *cls)
188{ 187{
189 struct GNUNET_SET_Element element; 188 struct GNUNET_SETI_Element element;
190 189
191 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 190 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
192 "initializing set 2\n"); 191 "initializing set 2\n");
193 element.element_type = 0; 192 element.element_type = 0;
194 element.data = "hello"; 193 element.data = "hello";
195 element.size = strlen (element.data); 194 element.size = strlen (element.data);
196 GNUNET_SET_add_element (set2, 195 GNUNET_SETI_add_element (set2,
197 &element, 196 &element,
198 NULL, 197 NULL,
199 NULL); 198 NULL);
200 element.data = "quux"; 199 element.data = "quux";
201 element.size = strlen (element.data); 200 element.size = strlen (element.data);
202 GNUNET_SET_add_element (set2, 201 GNUNET_SETI_add_element (set2,
203 &element, 202 &element,
204 NULL, 203 NULL,
205 NULL); 204 NULL);
206 element.data = "baz"; 205 element.data = "baz";
207 element.size = strlen (element.data); 206 element.size = strlen (element.data);
208 GNUNET_SET_add_element (set2, 207 GNUNET_SETI_add_element (set2,
209 &element, 208 &element,
210 &start, 209 &start,
211 NULL); 210 NULL);
212} 211}
213 212
214 213
@@ -218,71 +217,23 @@ init_set2 (void *cls)
218static void 217static void
219init_set1 (void) 218init_set1 (void)
220{ 219{
221 struct GNUNET_SET_Element element; 220 struct GNUNET_SETI_Element element;
222 221
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 222 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
224 "initializing set 1\n"); 223 "initializing set 1\n");
225 element.element_type = 0; 224 element.element_type = 0;
226 element.data = "hello"; 225 element.data = "hello";
227 element.size = strlen (element.data); 226 element.size = strlen (element.data);
228 GNUNET_SET_add_element (set1, 227 GNUNET_SETI_add_element (set1,
229 &element, 228 &element,
230 NULL, 229 NULL,
231 NULL); 230 NULL);
232 element.data = "bar";
233 element.size = strlen (element.data);
234 GNUNET_SET_add_element (set1,
235 &element,
236 &init_set2,
237 NULL);
238}
239
240
241static int
242iter_cb (void *cls,
243 const struct GNUNET_SET_Element *element)
244{
245 if (NULL == element)
246 {
247 GNUNET_assert (iter_count == 3);
248 GNUNET_SET_destroy (cls);
249 return GNUNET_YES;
250 }
251 iter_count++;
252 return GNUNET_YES;
253}
254
255
256static void
257test_iter ()
258{
259 struct GNUNET_SET_Element element;
260 struct GNUNET_SET_Handle *iter_set;
261
262 iter_set = GNUNET_SET_create (config,
263 GNUNET_SET_OPERATION_INTERSECTION);
264 element.element_type = 0;
265 element.data = "hello";
266 element.size = strlen (element.data);
267 GNUNET_SET_add_element (iter_set,
268 &element,
269 NULL,
270 NULL);
271 element.data = "bar"; 231 element.data = "bar";
272 element.size = strlen (element.data); 232 element.size = strlen (element.data);
273 GNUNET_SET_add_element (iter_set, 233 GNUNET_SETI_add_element (set1,
274 &element, 234 &element,
275 NULL, 235 &init_set2,
276 NULL); 236 NULL);
277 element.data = "quux";
278 element.size = strlen (element.data);
279 GNUNET_SET_add_element (iter_set,
280 &element,
281 NULL,
282 NULL);
283 GNUNET_SET_iterate (iter_set,
284 &iter_cb,
285 iter_set);
286} 237}
287 238
288 239
@@ -301,27 +252,27 @@ do_shutdown (void *cls)
301 } 252 }
302 if (NULL != oh1) 253 if (NULL != oh1)
303 { 254 {
304 GNUNET_SET_operation_cancel (oh1); 255 GNUNET_SETI_operation_cancel (oh1);
305 oh1 = NULL; 256 oh1 = NULL;
306 } 257 }
307 if (NULL != oh2) 258 if (NULL != oh2)
308 { 259 {
309 GNUNET_SET_operation_cancel (oh2); 260 GNUNET_SETI_operation_cancel (oh2);
310 oh2 = NULL; 261 oh2 = NULL;
311 } 262 }
312 if (NULL != set1) 263 if (NULL != set1)
313 { 264 {
314 GNUNET_SET_destroy (set1); 265 GNUNET_SETI_destroy (set1);
315 set1 = NULL; 266 set1 = NULL;
316 } 267 }
317 if (NULL != set2) 268 if (NULL != set2)
318 { 269 {
319 GNUNET_SET_destroy (set2); 270 GNUNET_SETI_destroy (set2);
320 set2 = NULL; 271 set2 = NULL;
321 } 272 }
322 if (NULL != listen_handle) 273 if (NULL != listen_handle)
323 { 274 {
324 GNUNET_SET_listen_cancel (listen_handle); 275 GNUNET_SETI_listen_cancel (listen_handle);
325 listen_handle = NULL; 276 listen_handle = NULL;
326 } 277 }
327} 278}
@@ -359,20 +310,16 @@ run (void *cls,
359 config = cfg; 310 config = cfg;
360 GNUNET_TESTING_peer_get_identity (peer, 311 GNUNET_TESTING_peer_get_identity (peer,
361 &local_id); 312 &local_id);
362 if (0) 313 tt = GNUNET_SCHEDULER_add_delayed (
363 test_iter (); 314 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
364 315 5),
365 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( 316 &timeout_fail,
366 GNUNET_TIME_UNIT_SECONDS, 5), 317 NULL);
367 &timeout_fail,
368 NULL);
369 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 318 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
370 NULL); 319 NULL);
371 320
372 set1 = GNUNET_SET_create (cfg, 321 set1 = GNUNET_SETI_create (cfg);
373 GNUNET_SET_OPERATION_INTERSECTION); 322 set2 = GNUNET_SETI_create (cfg);
374 set2 = GNUNET_SET_create (cfg,
375 GNUNET_SET_OPERATION_INTERSECTION);
376 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 323 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
377 &app_id); 324 &app_id);
378 325
@@ -385,9 +332,10 @@ int
385main (int argc, 332main (int argc,
386 char **argv) 333 char **argv)
387{ 334{
388 if (0 != GNUNET_TESTING_peer_run ("test_set_intersection_result_full", 335 if (0 != GNUNET_TESTING_peer_run ("test_seti_api",
389 "test_set.conf", 336 "test_seti.conf",
390 &run, NULL)) 337 &run,
338 NULL))
391 return 1; 339 return 1;
392 return ret; 340 return ret;
393} 341}