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_api.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_api.c')
-rw-r--r-- | src/set/test_set_api.c | 133 |
1 files changed, 107 insertions, 26 deletions
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c index d04877b39..19d63d00b 100644 --- a/src/set/test_set_api.c +++ b/src/set/test_set_api.c | |||
@@ -21,6 +21,7 @@ | |||
21 | /** | 21 | /** |
22 | * @file set/test_set_api.c | 22 | * @file set/test_set_api.c |
23 | * @brief testcase for set_api.c | 23 | * @brief testcase for set_api.c |
24 | * @author Florian Dold | ||
24 | */ | 25 | */ |
25 | #include "platform.h" | 26 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
@@ -38,6 +39,10 @@ static struct GNUNET_SET_Handle *set2; | |||
38 | 39 | ||
39 | static struct GNUNET_SET_ListenHandle *listen_handle; | 40 | static struct GNUNET_SET_ListenHandle *listen_handle; |
40 | 41 | ||
42 | static struct GNUNET_SET_OperationHandle *oh1; | ||
43 | |||
44 | static struct GNUNET_SET_OperationHandle *oh2; | ||
45 | |||
41 | static const struct GNUNET_CONFIGURATION_Handle *config; | 46 | static const struct GNUNET_CONFIGURATION_Handle *config; |
42 | 47 | ||
43 | static unsigned int iter_count; | 48 | static unsigned int iter_count; |
@@ -60,18 +65,26 @@ result_cb_set1 (void *cls, | |||
60 | break; | 65 | break; |
61 | case GNUNET_SET_STATUS_FAILURE: | 66 | case GNUNET_SET_STATUS_FAILURE: |
62 | GNUNET_break (0); | 67 | GNUNET_break (0); |
68 | oh1 = NULL; | ||
63 | fprintf (stderr, | 69 | fprintf (stderr, |
64 | "set 1: received failure status!\n"); | 70 | "set 1: received failure status!\n"); |
65 | ret = 1; | 71 | ret = 1; |
66 | GNUNET_SCHEDULER_cancel (tt); | 72 | if (NULL != tt) |
67 | tt = NULL; | 73 | { |
74 | GNUNET_SCHEDULER_cancel (tt); | ||
75 | tt = NULL; | ||
76 | } | ||
68 | GNUNET_SCHEDULER_shutdown (); | 77 | GNUNET_SCHEDULER_shutdown (); |
69 | break; | 78 | break; |
70 | case GNUNET_SET_STATUS_DONE: | 79 | case GNUNET_SET_STATUS_DONE: |
71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
72 | "set 1: done\n"); | 81 | "set 1: done\n"); |
73 | GNUNET_SET_destroy (set1); | 82 | oh1 = NULL; |
74 | set1 = NULL; | 83 | if (NULL != set1) |
84 | { | ||
85 | GNUNET_SET_destroy (set1); | ||
86 | set1 = NULL; | ||
87 | } | ||
75 | if (NULL == set2) | 88 | if (NULL == set2) |
76 | { | 89 | { |
77 | GNUNET_SCHEDULER_cancel (tt); | 90 | GNUNET_SCHEDULER_cancel (tt); |
@@ -98,11 +111,13 @@ result_cb_set2 (void *cls, | |||
98 | break; | 111 | break; |
99 | case GNUNET_SET_STATUS_FAILURE: | 112 | case GNUNET_SET_STATUS_FAILURE: |
100 | GNUNET_break (0); | 113 | GNUNET_break (0); |
114 | oh2 = NULL; | ||
101 | fprintf (stderr, | 115 | fprintf (stderr, |
102 | "set 2: received failure status\n"); | 116 | "set 2: received failure status\n"); |
103 | ret = 1; | 117 | ret = 1; |
104 | break; | 118 | break; |
105 | case GNUNET_SET_STATUS_DONE: | 119 | case GNUNET_SET_STATUS_DONE: |
120 | oh2 = NULL; | ||
106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
107 | "set 2: done\n"); | 122 | "set 2: done\n"); |
108 | GNUNET_SET_destroy (set2); | 123 | GNUNET_SET_destroy (set2); |
@@ -126,19 +141,18 @@ listen_cb (void *cls, | |||
126 | const struct GNUNET_MessageHeader *context_msg, | 141 | const struct GNUNET_MessageHeader *context_msg, |
127 | struct GNUNET_SET_Request *request) | 142 | struct GNUNET_SET_Request *request) |
128 | { | 143 | { |
129 | struct GNUNET_SET_OperationHandle *oh; | ||
130 | |||
131 | GNUNET_assert (NULL != context_msg); | 144 | GNUNET_assert (NULL != context_msg); |
132 | |||
133 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); | 145 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); |
134 | |||
135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
136 | "listen cb called\n"); | 147 | "listen cb called\n"); |
137 | GNUNET_SET_listen_cancel (listen_handle); | 148 | GNUNET_SET_listen_cancel (listen_handle); |
138 | oh = GNUNET_SET_accept (request, | 149 | listen_handle = NULL; |
139 | GNUNET_SET_RESULT_ADDED, | 150 | oh2 = GNUNET_SET_accept (request, |
140 | &result_cb_set2, NULL); | 151 | GNUNET_SET_RESULT_ADDED, |
141 | GNUNET_SET_commit (oh, set2); | 152 | &result_cb_set2, |
153 | NULL); | ||
154 | GNUNET_SET_commit (oh, | ||
155 | set2); | ||
142 | } | 156 | } |
143 | 157 | ||
144 | 158 | ||
@@ -150,18 +164,25 @@ listen_cb (void *cls, | |||
150 | static void | 164 | static void |
151 | start (void *cls) | 165 | start (void *cls) |
152 | { | 166 | { |
153 | struct GNUNET_SET_OperationHandle *oh; | ||
154 | struct GNUNET_MessageHeader context_msg; | 167 | struct GNUNET_MessageHeader context_msg; |
155 | 168 | ||
169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
170 | "Starting reconciliation\n"); | ||
156 | context_msg.size = htons (sizeof context_msg); | 171 | context_msg.size = htons (sizeof context_msg); |
157 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST); | 172 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST); |
158 | 173 | listen_handle = GNUNET_SET_listen (config, | |
159 | listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, | 174 | GNUNET_SET_OPERATION_UNION, |
160 | &app_id, listen_cb, NULL); | 175 | &app_id, |
161 | oh = GNUNET_SET_prepare (&local_id, &app_id, &context_msg, | 176 | &listen_cb, |
162 | GNUNET_SET_RESULT_ADDED, | 177 | NULL); |
163 | result_cb_set1, NULL); | 178 | oh1 = GNUNET_SET_prepare (&local_id, |
164 | GNUNET_SET_commit (oh, set1); | 179 | &app_id, |
180 | &context_msg, | ||
181 | GNUNET_SET_RESULT_ADDED, | ||
182 | &result_cb_set1, | ||
183 | NULL); | ||
184 | GNUNET_SET_commit (oh1, | ||
185 | set1); | ||
165 | } | 186 | } |
166 | 187 | ||
167 | 188 | ||
@@ -187,7 +208,7 @@ init_set2 (void *cls) | |||
187 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | 208 | GNUNET_SET_add_element (set2, &element, NULL, NULL); |
188 | element.data = "baz"; | 209 | element.data = "baz"; |
189 | element.size = strlen(element.data); | 210 | element.size = strlen(element.data); |
190 | GNUNET_SET_add_element (set2, &element, start, NULL); | 211 | GNUNET_SET_add_element (set2, &element, &start, NULL); |
191 | } | 212 | } |
192 | 213 | ||
193 | 214 | ||
@@ -208,7 +229,8 @@ init_set1 (void) | |||
208 | element.size = strlen(element.data); | 229 | element.size = strlen(element.data); |
209 | GNUNET_SET_add_element (set1, &element, init_set2, NULL); | 230 | GNUNET_SET_add_element (set1, &element, init_set2, NULL); |
210 | 231 | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); | 232 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
233 | "initialized set 1\n"); | ||
212 | } | 234 | } |
213 | 235 | ||
214 | 236 | ||
@@ -255,7 +277,7 @@ test_iter () | |||
255 | 277 | ||
256 | 278 | ||
257 | /** | 279 | /** |
258 | * Signature of the main function of a task. | 280 | * Function run on timeout. |
259 | * | 281 | * |
260 | * @param cls closure | 282 | * @param cls closure |
261 | */ | 283 | */ |
@@ -263,12 +285,55 @@ static void | |||
263 | timeout_fail (void *cls) | 285 | timeout_fail (void *cls) |
264 | { | 286 | { |
265 | tt = NULL; | 287 | tt = NULL; |
288 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
289 | "Testcase failed with timeout\n"); | ||
266 | GNUNET_SCHEDULER_shutdown (); | 290 | GNUNET_SCHEDULER_shutdown (); |
267 | ret = 1; | 291 | ret = 1; |
268 | } | 292 | } |
269 | 293 | ||
270 | 294 | ||
271 | /** | 295 | /** |
296 | * Function run on shutdown. | ||
297 | * | ||
298 | * @param cls closure | ||
299 | */ | ||
300 | static void | ||
301 | do_shutdown (void *cls) | ||
302 | { | ||
303 | if (NULL != tt) | ||
304 | { | ||
305 | GNUNET_SCHEDULER_cancel (tt); | ||
306 | tt = NULL; | ||
307 | } | ||
308 | if (NULL != oh1) | ||
309 | { | ||
310 | GNUNET_SET_operation_cancel (oh1); | ||
311 | oh1 = NULL; | ||
312 | } | ||
313 | if (NULL != oh2) | ||
314 | { | ||
315 | GNUNET_SET_operation_cancel (oh2); | ||
316 | oh2 = NULL; | ||
317 | } | ||
318 | if (NULL != set1) | ||
319 | { | ||
320 | GNUNET_SET_destroy (set1); | ||
321 | set1 = NULL; | ||
322 | } | ||
323 | if (NULL != set2) | ||
324 | { | ||
325 | GNUNET_SET_destroy (set2); | ||
326 | set2 = NULL; | ||
327 | } | ||
328 | if (NULL != listen_handle) | ||
329 | { | ||
330 | GNUNET_SET_listen_cancel (listen_handle); | ||
331 | listen_handle = NULL; | ||
332 | } | ||
333 | } | ||
334 | |||
335 | |||
336 | /** | ||
272 | * Signature of the 'main' function for a (single-peer) testcase that | 337 | * Signature of the 'main' function for a (single-peer) testcase that |
273 | * is run using 'GNUNET_TESTING_peer_run'. | 338 | * is run using 'GNUNET_TESTING_peer_run'. |
274 | * | 339 | * |
@@ -284,8 +349,13 @@ run (void *cls, | |||
284 | 349 | ||
285 | struct GNUNET_SET_OperationHandle *my_oh; | 350 | struct GNUNET_SET_OperationHandle *my_oh; |
286 | 351 | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
353 | "Running preparatory tests\n"); | ||
287 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 354 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), |
288 | &timeout_fail, NULL); | 355 | &timeout_fail, |
356 | NULL); | ||
357 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
358 | NULL); | ||
289 | 359 | ||
290 | config = cfg; | 360 | config = cfg; |
291 | GNUNET_CRYPTO_get_peer_identity (cfg, &local_id); | 361 | GNUNET_CRYPTO_get_peer_identity (cfg, &local_id); |
@@ -304,12 +374,18 @@ run (void *cls, | |||
304 | &app_id); | 374 | &app_id); |
305 | 375 | ||
306 | ///* test if canceling an uncommited request works! */ | 376 | ///* test if canceling an uncommited request works! */ |
307 | my_oh = GNUNET_SET_prepare (&local_id, &app_id, NULL, | 377 | my_oh = GNUNET_SET_prepare (&local_id, |
308 | GNUNET_SET_RESULT_ADDED, NULL, NULL); | 378 | &app_id, |
379 | NULL, | ||
380 | GNUNET_SET_RESULT_ADDED, | ||
381 | NULL, | ||
382 | NULL); | ||
309 | 383 | ||
310 | GNUNET_SET_operation_cancel (my_oh); | 384 | GNUNET_SET_operation_cancel (my_oh); |
311 | 385 | ||
312 | /* test the real set reconciliation */ | 386 | /* test the real set reconciliation */ |
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
388 | "Running real set-reconciliation\n"); | ||
313 | init_set1 (); | 389 | init_set1 (); |
314 | } | 390 | } |
315 | 391 | ||
@@ -317,6 +393,11 @@ run (void *cls, | |||
317 | int | 393 | int |
318 | main (int argc, char **argv) | 394 | main (int argc, char **argv) |
319 | { | 395 | { |
396 | GNUNET_log_setup ("test_set_api", | ||
397 | "WARNING", | ||
398 | NULL); | ||
399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
400 | "Launching peer\n"); | ||
320 | if (0 != GNUNET_TESTING_peer_run ("test_set_api", | 401 | if (0 != GNUNET_TESTING_peer_run ("test_set_api", |
321 | "test_set.conf", | 402 | "test_set.conf", |
322 | &run, NULL)) | 403 | &run, NULL)) |