aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_monitor_peers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 22:34:49 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 22:34:49 +0000
commitc0b81510ffe194dc662c3a6267d5e66a69873c4b (patch)
tree5ad5cc473d6993523be80bcf1430230e224d9216 /src/transport/test_transport_api_monitor_peers.c
parenta7345f7436c421fd15e18e87ec399ea93b6dde03 (diff)
downloadgnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.tar.gz
gnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.zip
-start to refactor testcases for sanity
Diffstat (limited to 'src/transport/test_transport_api_monitor_peers.c')
-rw-r--r--src/transport/test_transport_api_monitor_peers.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c
index 90c96829d..4731e41e2 100644
--- a/src/transport/test_transport_api_monitor_peers.c
+++ b/src/transport/test_transport_api_monitor_peers.c
@@ -57,15 +57,15 @@ static struct GNUNET_SCHEDULER_Task * die_task;
57 57
58static struct GNUNET_SCHEDULER_Task * send_task; 58static struct GNUNET_SCHEDULER_Task * send_task;
59 59
60static struct PeerContext *p1; 60static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
61 61
62static struct PeerContext *p2; 62static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
63 63
64static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; 64static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc;
65 65
66static struct GNUNET_TRANSPORT_TransmitHandle *th; 66static struct GNUNET_TRANSPORT_TransmitHandle *th;
67 67
68static struct GNUNET_TRANSPORT_TESTING_handle *tth; 68static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
69 69
70static char *cfg_file_p1; 70static char *cfg_file_p1;
71 71
@@ -107,10 +107,10 @@ end ()
107 th = NULL; 107 th = NULL;
108 108
109 if (NULL != p1) 109 if (NULL != p1)
110 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 110 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
111 p1 = NULL; 111 p1 = NULL;
112 if (NULL != p2) 112 if (NULL != p2)
113 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 113 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
114 p2 = NULL; 114 p2 = NULL;
115 115
116 if (NULL != pmc_p1) 116 if (NULL != pmc_p1)
@@ -143,7 +143,7 @@ end_badly (void *cls)
143 if (cc != NULL) 143 if (cc != NULL)
144 { 144 {
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); 145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
146 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); 146 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
147 cc = NULL; 147 cc = NULL;
148 } 148 }
149 149
@@ -181,11 +181,11 @@ end_badly (void *cls)
181 } 181 }
182 182
183 if (p1 != NULL) 183 if (p1 != NULL)
184 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 184 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
185 else 185 else
186 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); 186 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n"));
187 if (p2 != NULL) 187 if (p2 != NULL)
188 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 188 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
189 else 189 else
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n"));
191 191
@@ -197,8 +197,8 @@ static void
197notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 197notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
198 const struct GNUNET_MessageHeader *message) 198 const struct GNUNET_MessageHeader *message)
199{ 199{
200 struct PeerContext *p = cls; 200 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
201 struct PeerContext *t = NULL; 201 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
202 202
203 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 203 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
204 t = p1; 204 t = p1;
@@ -219,7 +219,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
219static size_t 219static size_t
220notify_ready (void *cls, size_t size, void *buf) 220notify_ready (void *cls, size_t size, void *buf)
221{ 221{
222 struct PeerContext *p = cls; 222 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
223 struct GNUNET_MessageHeader *hdr; 223 struct GNUNET_MessageHeader *hdr;
224 224
225 th = NULL; 225 th = NULL;
@@ -294,8 +294,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
294 static int c; 294 static int c;
295 295
296 c++; 296 c++;
297 struct PeerContext *p = cls; 297 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
298 struct PeerContext *t = NULL; 298 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
299 299
300 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 300 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
301 { 301 {
@@ -323,7 +323,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
323static void 323static void
324notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 324notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
325{ 325{
326 struct PeerContext *p = cls; 326 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
327 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 327 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
328 328
329 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 329 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -339,9 +339,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
339 339
340 340
341static void 341static void
342testing_connect_cb (struct PeerContext *p1, 342testing_connect_cb (void *cls)
343 struct PeerContext *p2,
344 void *cls)
345{ 343{
346 cc = NULL; 344 cc = NULL;
347 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 345 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
@@ -357,7 +355,7 @@ testing_connect_cb (struct PeerContext *p1,
357 355
358 356
359static void 357static void
360start_cb (struct PeerContext *p, void *cls) 358start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
361{ 359{
362 static int started; 360 static int started;
363 361
@@ -378,7 +376,9 @@ start_cb (struct PeerContext *p, void *cls)
378 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); 376 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
379 GNUNET_free (sender_c); 377 GNUNET_free (sender_c);
380 378
381 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 379 cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
380 p2,
381 &testing_connect_cb,
382 NULL); 382 NULL);
383 383
384} 384}
@@ -446,9 +446,13 @@ run (void *cls, char *const *args, const char *cfgfile,
446 s_connected = GNUNET_NO; 446 s_connected = GNUNET_NO;
447 s_sending = GNUNET_NO; 447 s_sending = GNUNET_NO;
448 448
449 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 449 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
450 &notify_receive, &notify_connect, 450 cfg_file_p1,
451 &notify_disconnect, &start_cb, 451 1,
452 &notify_receive,
453 &notify_connect,
454 &notify_disconnect,
455 &start_cb,
452 NULL); 456 NULL);
453 pmc_p1 = GNUNET_TRANSPORT_monitor_peers (p1->cfg, 457 pmc_p1 = GNUNET_TRANSPORT_monitor_peers (p1->cfg,
454 NULL, 458 NULL,
@@ -457,9 +461,13 @@ run (void *cls, char *const *args, const char *cfgfile,
457 NULL); 461 NULL);
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n"); 462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n");
459 463
460 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 464 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
461 &notify_receive, &notify_connect, 465 cfg_file_p2,
462 &notify_disconnect, &start_cb, 466 2,
467 &notify_receive,
468 &notify_connect,
469 &notify_disconnect,
470 &start_cb,
463 NULL); 471 NULL);
464 pmc_p2 = GNUNET_TRANSPORT_monitor_peers (p2->cfg, 472 pmc_p2 = GNUNET_TRANSPORT_monitor_peers (p2->cfg,
465 NULL, 473 NULL,
@@ -507,18 +515,18 @@ main (int argc, char *argv[])
507 515
508 ok = 1; 516 ok = 1;
509 517
510 GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); 518 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
511 GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); 519 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__);
512 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, 520 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0],
513 &test_plugin); 521 test_source);
514 522
515 GNUNET_log_setup (test_name, 523 GNUNET_log_setup (test_name,
516 "WARNING", 524 "WARNING",
517 NULL); 525 NULL);
518 tth = GNUNET_TRANSPORT_TESTING_init (); 526 tth = GNUNET_TRANSPORT_TESTING_init ();
519 527
520 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); 528 cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1);
521 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); 529 cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2);
522 530
523 ret = check (); 531 ret = check ();
524 532