diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-08-14 11:55:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-08-14 11:55:02 +0000 |
commit | d87f02395bb84c9f57b085170c8c14e4c33985ba (patch) | |
tree | 8bd6d6bef405021d7ab8f3a36027c5629738d740 /src/set/test_set_intersection_result_full.c | |
parent | b0268a0ef60e6e68d29c4eb8baf2742da2326bf8 (diff) | |
download | gnunet-d87f02395bb84c9f57b085170c8c14e4c33985ba.tar.gz gnunet-d87f02395bb84c9f57b085170c8c14e4c33985ba.zip |
-fix testcases, ensure shutdown works properly
Diffstat (limited to 'src/set/test_set_intersection_result_full.c')
-rw-r--r-- | src/set/test_set_intersection_result_full.c | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c index 9a5d0aa43..9c2f64bc1 100644 --- a/src/set/test_set_intersection_result_full.c +++ b/src/set/test_set_intersection_result_full.c | |||
@@ -46,6 +46,12 @@ static const struct GNUNET_CONFIGURATION_Handle *config; | |||
46 | 46 | ||
47 | static int iter_count; | 47 | static int iter_count; |
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task *tt; | ||
50 | |||
51 | static struct GNUNET_SET_OperationHandle *oh1; | ||
52 | |||
53 | static struct GNUNET_SET_OperationHandle *oh2; | ||
54 | |||
49 | 55 | ||
50 | static void | 56 | static void |
51 | result_cb_set1 (void *cls, | 57 | result_cb_set1 (void *cls, |
@@ -60,11 +66,14 @@ result_cb_set1 (void *cls, | |||
60 | count++; | 66 | count++; |
61 | break; | 67 | break; |
62 | case GNUNET_SET_STATUS_FAILURE: | 68 | case GNUNET_SET_STATUS_FAILURE: |
69 | oh1 = NULL; | ||
63 | ret = 1; | 70 | ret = 1; |
64 | break; | 71 | break; |
65 | case GNUNET_SET_STATUS_DONE: | 72 | case GNUNET_SET_STATUS_DONE: |
73 | oh1 = NULL; | ||
66 | GNUNET_assert (1 == count); | 74 | GNUNET_assert (1 == count); |
67 | GNUNET_SET_destroy (set1); | 75 | GNUNET_SET_destroy (set1); |
76 | set1 = NULL; | ||
68 | break; | 77 | break; |
69 | default: | 78 | default: |
70 | GNUNET_assert (0); | 79 | GNUNET_assert (0); |
@@ -85,11 +94,14 @@ result_cb_set2 (void *cls, | |||
85 | count++; | 94 | count++; |
86 | break; | 95 | break; |
87 | case GNUNET_SET_STATUS_FAILURE: | 96 | case GNUNET_SET_STATUS_FAILURE: |
97 | oh2 = NULL; | ||
88 | ret = 1; | 98 | ret = 1; |
89 | break; | 99 | break; |
90 | case GNUNET_SET_STATUS_DONE: | 100 | case GNUNET_SET_STATUS_DONE: |
101 | oh2 = NULL; | ||
91 | GNUNET_assert (1 == count); | 102 | GNUNET_assert (1 == count); |
92 | GNUNET_SET_destroy (set2); | 103 | GNUNET_SET_destroy (set2); |
104 | set2 = NULL; | ||
93 | break; | 105 | break; |
94 | default: | 106 | default: |
95 | GNUNET_assert (0); | 107 | GNUNET_assert (0); |
@@ -103,15 +115,16 @@ listen_cb (void *cls, | |||
103 | const struct GNUNET_MessageHeader *context_msg, | 115 | const struct GNUNET_MessageHeader *context_msg, |
104 | struct GNUNET_SET_Request *request) | 116 | struct GNUNET_SET_Request *request) |
105 | { | 117 | { |
106 | struct GNUNET_SET_OperationHandle *oh; | ||
107 | |||
108 | GNUNET_assert (NULL != context_msg); | 118 | GNUNET_assert (NULL != context_msg); |
109 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); | 119 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); |
110 | GNUNET_SET_listen_cancel (listen_handle); | 120 | GNUNET_SET_listen_cancel (listen_handle); |
111 | oh = GNUNET_SET_accept (request, | 121 | listen_handle = NULL; |
122 | oh2 = GNUNET_SET_accept (request, | ||
112 | GNUNET_SET_RESULT_FULL, | 123 | GNUNET_SET_RESULT_FULL, |
113 | &result_cb_set2, NULL); | 124 | &result_cb_set2, |
114 | GNUNET_SET_commit (oh, set2); | 125 | NULL); |
126 | GNUNET_SET_commit (oh2, | ||
127 | set2); | ||
115 | } | 128 | } |
116 | 129 | ||
117 | 130 | ||
@@ -123,7 +136,6 @@ listen_cb (void *cls, | |||
123 | static void | 136 | static void |
124 | start (void *cls) | 137 | start (void *cls) |
125 | { | 138 | { |
126 | struct GNUNET_SET_OperationHandle *oh; | ||
127 | struct GNUNET_MessageHeader context_msg; | 139 | struct GNUNET_MessageHeader context_msg; |
128 | 140 | ||
129 | context_msg.size = htons (sizeof context_msg); | 141 | context_msg.size = htons (sizeof context_msg); |
@@ -132,12 +144,14 @@ start (void *cls) | |||
132 | GNUNET_SET_OPERATION_INTERSECTION, | 144 | GNUNET_SET_OPERATION_INTERSECTION, |
133 | &app_id, | 145 | &app_id, |
134 | &listen_cb, NULL); | 146 | &listen_cb, NULL); |
135 | oh = GNUNET_SET_prepare (&local_id, | 147 | oh1 = GNUNET_SET_prepare (&local_id, |
136 | &app_id, | 148 | &app_id, |
137 | &context_msg, | 149 | &context_msg, |
138 | GNUNET_SET_RESULT_FULL, | 150 | GNUNET_SET_RESULT_FULL, |
139 | &result_cb_set1, NULL); | 151 | &result_cb_set1, |
140 | GNUNET_SET_commit (oh, set1); | 152 | NULL); |
153 | GNUNET_SET_commit (oh1, | ||
154 | set1); | ||
141 | } | 155 | } |
142 | 156 | ||
143 | 157 | ||
@@ -216,7 +230,66 @@ test_iter () | |||
216 | element.data = "quux"; | 230 | element.data = "quux"; |
217 | element.size = strlen(element.data); | 231 | element.size = strlen(element.data); |
218 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 232 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); |
219 | GNUNET_SET_iterate (iter_set, &iter_cb, iter_set); | 233 | GNUNET_SET_iterate (iter_set, |
234 | &iter_cb, | ||
235 | iter_set); | ||
236 | } | ||
237 | |||
238 | |||
239 | /** | ||
240 | * Function run on shutdown. | ||
241 | * | ||
242 | * @param cls closure | ||
243 | */ | ||
244 | static void | ||
245 | do_shutdown (void *cls) | ||
246 | { | ||
247 | if (NULL != tt) | ||
248 | { | ||
249 | GNUNET_SCHEDULER_cancel (tt); | ||
250 | tt = NULL; | ||
251 | } | ||
252 | if (NULL != oh1) | ||
253 | { | ||
254 | GNUNET_SET_operation_cancel (oh1); | ||
255 | oh1 = NULL; | ||
256 | } | ||
257 | if (NULL != oh2) | ||
258 | { | ||
259 | GNUNET_SET_operation_cancel (oh2); | ||
260 | oh2 = NULL; | ||
261 | } | ||
262 | if (NULL != set1) | ||
263 | { | ||
264 | GNUNET_SET_destroy (set1); | ||
265 | set1 = NULL; | ||
266 | } | ||
267 | if (NULL != set2) | ||
268 | { | ||
269 | GNUNET_SET_destroy (set2); | ||
270 | set2 = NULL; | ||
271 | } | ||
272 | if (NULL != listen_handle) | ||
273 | { | ||
274 | GNUNET_SET_listen_cancel (listen_handle); | ||
275 | listen_handle = NULL; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | |||
280 | /** | ||
281 | * Function run on timeout. | ||
282 | * | ||
283 | * @param cls closure | ||
284 | */ | ||
285 | static void | ||
286 | timeout_fail (void *cls) | ||
287 | { | ||
288 | tt = NULL; | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
290 | "Testcase failed with timeout\n"); | ||
291 | GNUNET_SCHEDULER_shutdown (); | ||
292 | ret = 1; | ||
220 | } | 293 | } |
221 | 294 | ||
222 | 295 | ||
@@ -237,9 +310,16 @@ run (void *cls, | |||
237 | GNUNET_TESTING_peer_get_identity (peer, &local_id); | 310 | GNUNET_TESTING_peer_get_identity (peer, &local_id); |
238 | if (0) test_iter (); | 311 | if (0) test_iter (); |
239 | 312 | ||
313 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | ||
314 | &timeout_fail, | ||
315 | NULL); | ||
316 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
317 | NULL); | ||
318 | |||
240 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 319 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); |
241 | set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 320 | set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); |
242 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); | 321 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, |
322 | &app_id); | ||
243 | 323 | ||
244 | /* test the real set reconciliation */ | 324 | /* test the real set reconciliation */ |
245 | init_set1 (); | 325 | init_set1 (); |
@@ -255,4 +335,3 @@ main (int argc, char **argv) | |||
255 | return 1; | 335 | return 1; |
256 | return ret; | 336 | return ret; |
257 | } | 337 | } |
258 | |||