aboutsummaryrefslogtreecommitdiff
path: root/src/social
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-10-29 11:25:20 +0100
committerChristian Grothoff <christian@grothoff.org>2017-10-29 11:25:20 +0100
commitcfd5e9d749ae8d9d07ef77943a9b560b491468fc (patch)
tree7fea0288c4dff6833f44e4e7a11cf513f4915db4 /src/social
parente1e838cdb804ed54aedccf5fce030ecc066028cd (diff)
downloadgnunet-cfd5e9d749ae8d9d07ef77943a9b560b491468fc.tar.gz
gnunet-cfd5e9d749ae8d9d07ef77943a9b560b491468fc.zip
do handle CTRL-C properly in test_social
Diffstat (limited to 'src/social')
-rw-r--r--src/social/test_social.c91
1 files changed, 59 insertions, 32 deletions
diff --git a/src/social/test_social.c b/src/social/test_social.c
index 8d49e7413..de2299320 100644
--- a/src/social/test_social.c
+++ b/src/social/test_social.c
@@ -180,10 +180,28 @@ host_announce2 ();
180 180
181 181
182/** 182/**
183 * Clean up all resources used. 183 * Terminate the test case (failure).
184 *
185 * @param cls NULL
184 */ 186 */
185static void 187static void
186cleanup () 188end_badly (void *cls)
189{
190 end_badly_task = NULL;
191 GNUNET_SCHEDULER_shutdown ();
192 res = 2;
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Test FAILED.\n");
195}
196
197
198/**
199 * Terminate the test case (failure).
200 *
201 * @param cls NULL
202 */
203static void
204end_shutdown (void *cls)
187{ 205{
188 if (NULL != id) 206 if (NULL != id)
189 { 207 {
@@ -202,7 +220,11 @@ cleanup ()
202 GNUNET_PSYC_slicer_destroy (host_slicer); 220 GNUNET_PSYC_slicer_destroy (host_slicer);
203 host_slicer = NULL; 221 host_slicer = NULL;
204 } 222 }
205 223 if (NULL != end_badly_task)
224 {
225 GNUNET_SCHEDULER_cancel (end_badly_task);
226 end_badly_task = NULL;
227 }
206 if (NULL != gst) 228 if (NULL != gst)
207 { 229 {
208 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL); 230 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
@@ -216,21 +238,6 @@ cleanup ()
216 hst_plc = NULL; 238 hst_plc = NULL;
217 } 239 }
218 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL); 240 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
219 GNUNET_SCHEDULER_shutdown ();
220}
221
222
223/**
224 * Terminate the test case (failure).
225 *
226 * @param cls NULL
227 */
228static void
229end_badly (void *cls)
230{
231 res = 1;
232 cleanup ();
233 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
234} 241}
235 242
236 243
@@ -242,8 +249,8 @@ end_badly (void *cls)
242static void 249static void
243end_normally (void *cls) 250end_normally (void *cls)
244{ 251{
252 GNUNET_SCHEDULER_shutdown ();
245 res = 0; 253 res = 0;
246 cleanup ();
247 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Test PASSED.\n"); 254 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Test PASSED.\n");
248} 255}
249 256
@@ -372,6 +379,7 @@ host_reconnected (void *cls, int result,
372 is_host_reconnected = GNUNET_YES; 379 is_host_reconnected = GNUNET_YES;
373 if (GNUNET_YES == is_guest_reconnected) 380 if (GNUNET_YES == is_guest_reconnected)
374 { 381 {
382 GNUNET_assert (NULL != gst);
375 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 383 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
376 } 384 }
377} 385}
@@ -390,6 +398,7 @@ guest_reconnected (void *cls, int result,
390 is_guest_reconnected = GNUNET_YES; 398 is_guest_reconnected = GNUNET_YES;
391 if (GNUNET_YES == is_host_reconnected) 399 if (GNUNET_YES == is_host_reconnected)
392 { 400 {
401 GNUNET_assert (NULL != gst);
393 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 402 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
394 } 403 }
395} 404}
@@ -411,11 +420,15 @@ app_recv_host (void *cls,
411 enum GNUNET_SOCIAL_AppPlaceState place_state) 420 enum GNUNET_SOCIAL_AppPlaceState place_state)
412{ 421{
413 struct GNUNET_HashCode host_pub_hash; 422 struct GNUNET_HashCode host_pub_hash;
414 GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash); 423
424 GNUNET_CRYPTO_hash (host_pub_key,
425 sizeof (*host_pub_key),
426 &host_pub_hash);
415 427
416 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 428 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
417 "Test #%u: Got app host place notification: %s\n", 429 "Test #%u: Got app host place notification: %s\n",
418 test, GNUNET_h2s (&host_pub_hash)); 430 test,
431 GNUNET_h2s (&host_pub_hash));
419 432
420 if (test == TEST_RECONNECT) 433 if (test == TEST_RECONNECT)
421 { 434 {
@@ -424,8 +437,11 @@ app_recv_host (void *cls,
424 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 437 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
425 "Test #%u: Reconnecting to host place: %s\n", 438 "Test #%u: Reconnecting to host place: %s\n",
426 test, GNUNET_h2s (&host_pub_hash)); 439 test, GNUNET_h2s (&host_pub_hash));
427 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer, host_reconnected, 440 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer,
428 host_answer_door, host_farewell2, NULL); 441 &host_reconnected,
442 &host_answer_door,
443 &host_farewell2,
444 NULL);
429 } 445 }
430 } 446 }
431} 447}
@@ -439,7 +455,10 @@ app_recv_guest (void *cls,
439 enum GNUNET_SOCIAL_AppPlaceState place_state) 455 enum GNUNET_SOCIAL_AppPlaceState place_state)
440{ 456{
441 struct GNUNET_HashCode guest_pub_hash; 457 struct GNUNET_HashCode guest_pub_hash;
442 GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash); 458
459 GNUNET_CRYPTO_hash (guest_pub_key,
460 sizeof (*guest_pub_key),
461 &guest_pub_hash);
443 462
444 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 463 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
445 "Test #%u: Got app guest place notification: %s\n", 464 "Test #%u: Got app guest place notification: %s\n",
@@ -447,13 +466,19 @@ app_recv_guest (void *cls,
447 466
448 if (test == TEST_RECONNECT) 467 if (test == TEST_RECONNECT)
449 { 468 {
450 if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key))) 469 if (0 == memcmp (&place_pub_key,
470 guest_pub_key,
471 sizeof (*guest_pub_key)))
451 { 472 {
452 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 473 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
453 "Test #%u: Reconnecting to guest place: %s\n", 474 "Test #%u: Reconnecting to guest place: %s\n",
454 test, GNUNET_h2s (&guest_pub_hash)); 475 test, GNUNET_h2s (&guest_pub_hash));
455 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE, 476 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn,
456 guest_slicer, guest_reconnected, NULL); 477 GNUNET_PSYC_SLAVE_JOIN_NONE,
478 guest_slicer,
479 &guest_reconnected,
480 NULL);
481 GNUNET_assert (NULL != gst);
457 } 482 }
458 } 483 }
459} 484}
@@ -527,10 +552,10 @@ schedule_reconnect (void *cls)
527 552
528 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL); 553 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
529 app = GNUNET_SOCIAL_app_connect (cfg, app_id, 554 app = GNUNET_SOCIAL_app_connect (cfg, app_id,
530 app_recv_ego, 555 &app_recv_ego,
531 app_recv_host, 556 &app_recv_host,
532 app_recv_guest, 557 &app_recv_guest,
533 app_connected, 558 &app_connected,
534 NULL); 559 NULL);
535} 560}
536 561
@@ -1387,9 +1412,11 @@ run (void *cls,
1387#endif 1412#endif
1388{ 1413{
1389 cfg = c; 1414 cfg = c;
1415 res = 1;
1390 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1416 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1391 &end_badly, NULL); 1417 &end_badly, NULL);
1392 1418 GNUNET_SCHEDULER_add_shutdown (&end_shutdown,
1419 NULL);
1393 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer); 1420 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
1394 1421
1395 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL); 1422 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);