diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-09-03 15:15:06 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-09-03 15:15:06 +0000 |
commit | 8b079ff34ea8049fa5635243e908b7fab9d42eeb (patch) | |
tree | 4dd32424c948b2a39e25965e7f935acc01ffbb27 /src/gns | |
parent | 32566458738aa4d91d02616ef4f38c2614acf301 (diff) | |
download | gnunet-8b079ff34ea8049fa5635243e908b7fab9d42eeb.tar.gz gnunet-8b079ff34ea8049fa5635243e908b7fab9d42eeb.zip |
- next test
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/Makefile.am | 4 | ||||
-rw-r--r-- | src/gns/test_gns_cname_lookup.c | 179 | ||||
-rw-r--r-- | src/gns/test_gns_simple_zkey_lookup.c | 1 |
3 files changed, 52 insertions, 132 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 9c2d5b3fe..232a99fb8 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -242,12 +242,12 @@ test_gns_cname_lookup_LDADD = \ | |||
242 | $(top_builddir)/src/util/libgnunetutil.la \ | 242 | $(top_builddir)/src/util/libgnunetutil.la \ |
243 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 243 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
244 | $(top_builddir)/src/gns/libgnunetgns.la \ | 244 | $(top_builddir)/src/gns/libgnunetgns.la \ |
245 | $(top_builddir)/src/testing_old/libgnunettesting_old.la | 245 | $(top_builddir)/src/testing/libgnunettesting.la |
246 | test_gns_cname_lookup_DEPENDENCIES = \ | 246 | test_gns_cname_lookup_DEPENDENCIES = \ |
247 | $(top_builddir)/src/util/libgnunetutil.la \ | 247 | $(top_builddir)/src/util/libgnunetutil.la \ |
248 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 248 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
249 | $(top_builddir)/src/gns/libgnunetgns.la \ | 249 | $(top_builddir)/src/gns/libgnunetgns.la \ |
250 | $(top_builddir)/src/testing_old/libgnunettesting_old.la | 250 | $(top_builddir)/src/testing/libgnunettesting.la |
251 | 251 | ||
252 | 252 | ||
253 | test_gns_ns_lookup_SOURCES = \ | 253 | test_gns_ns_lookup_SOURCES = \ |
diff --git a/src/gns/test_gns_cname_lookup.c b/src/gns/test_gns_cname_lookup.c index 9cc87d5c6..95aa0660b 100644 --- a/src/gns/test_gns_cname_lookup.c +++ b/src/gns/test_gns_cname_lookup.c | |||
@@ -23,7 +23,7 @@ | |||
23 | * | 23 | * |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_testing_lib.h" | 26 | #include "gnunet_testing_lib-new.h" |
27 | #include "gnunet_core_service.h" | 27 | #include "gnunet_core_service.h" |
28 | #include "block_dns.h" | 28 | #include "block_dns.h" |
29 | #include "gnunet_signatures.h" | 29 | #include "gnunet_signatures.h" |
@@ -60,13 +60,6 @@ | |||
60 | 60 | ||
61 | /* Globals */ | 61 | /* Globals */ |
62 | 62 | ||
63 | /** | ||
64 | * Directory to store temp data in, defined in config file | ||
65 | */ | ||
66 | static char *test_directory; | ||
67 | |||
68 | static struct GNUNET_TESTING_PeerGroup *pg; | ||
69 | |||
70 | /* Task handle to use to schedule test failure */ | 63 | /* Task handle to use to schedule test failure */ |
71 | GNUNET_SCHEDULER_TaskIdentifier die_task; | 64 | GNUNET_SCHEDULER_TaskIdentifier die_task; |
72 | 65 | ||
@@ -80,19 +73,35 @@ static struct GNUNET_GNS_Handle *gns_handle; | |||
80 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 73 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
81 | 74 | ||
82 | /** | 75 | /** |
83 | * Check whether peers successfully shut down. | 76 | * Check if the get_handle is being used, if so stop the request. Either |
77 | * way, schedule the end_badly_cont function which actually shuts down the | ||
78 | * test. | ||
84 | */ | 79 | */ |
85 | void | 80 | static void |
86 | shutdown_callback (void *cls, const char *emsg) | 81 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
87 | { | 82 | { |
88 | if (emsg != NULL) | 83 | die_task = GNUNET_SCHEDULER_NO_TASK; |
84 | if (NULL != gns_handle) | ||
89 | { | 85 | { |
90 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); | 86 | GNUNET_GNS_disconnect(gns_handle); |
91 | if (ok == 0) | 87 | gns_handle = NULL; |
92 | ok = 2; | ||
93 | } | 88 | } |
94 | 89 | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); | 90 | if (NULL != namestore_handle) |
91 | { | ||
92 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
93 | namestore_handle = NULL; | ||
94 | } | ||
95 | GNUNET_break (0); | ||
96 | GNUNET_SCHEDULER_shutdown (); | ||
97 | ok = 1; | ||
98 | } | ||
99 | |||
100 | static void | ||
101 | end_badly_now () | ||
102 | { | ||
103 | GNUNET_SCHEDULER_cancel (die_task); | ||
104 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
96 | } | 105 | } |
97 | 106 | ||
98 | 107 | ||
@@ -102,6 +111,14 @@ on_lookup_result_cname (void *cls, uint32_t rd_count, | |||
102 | { | 111 | { |
103 | int i; | 112 | int i; |
104 | 113 | ||
114 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
115 | { | ||
116 | GNUNET_SCHEDULER_cancel (die_task); | ||
117 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
118 | } | ||
119 | |||
120 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
121 | namestore_handle = NULL; | ||
105 | if (rd_count == 0) | 122 | if (rd_count == 0) |
106 | { | 123 | { |
107 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -132,8 +149,9 @@ on_lookup_result_cname (void *cls, uint32_t rd_count, | |||
132 | } | 149 | } |
133 | } | 150 | } |
134 | GNUNET_GNS_disconnect(gns_handle); | 151 | GNUNET_GNS_disconnect(gns_handle); |
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); | 152 | gns_handle = NULL; |
136 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); |
154 | GNUNET_SCHEDULER_shutdown (); | ||
137 | } | 155 | } |
138 | 156 | ||
139 | static void | 157 | static void |
@@ -274,13 +292,6 @@ on_lookup_result_plus (void *cls, uint32_t rd_count, | |||
274 | &on_lookup_result_zkey, TEST_DOMAIN_ZKEY); | 292 | &on_lookup_result_zkey, TEST_DOMAIN_ZKEY); |
275 | } | 293 | } |
276 | 294 | ||
277 | |||
278 | static void | ||
279 | disco_ns (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
280 | { | ||
281 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
282 | } | ||
283 | |||
284 | /** | 295 | /** |
285 | * Function scheduled to be run on the successful start of services | 296 | * Function scheduled to be run on the successful start of services |
286 | * tries to look up the dns record for TEST_DOMAIN | 297 | * tries to look up the dns record for TEST_DOMAIN |
@@ -288,16 +299,13 @@ disco_ns (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
288 | static void | 299 | static void |
289 | commence_testing (void *cls, int32_t success, const char *emsg) | 300 | commence_testing (void *cls, int32_t success, const char *emsg) |
290 | { | 301 | { |
291 | |||
292 | GNUNET_SCHEDULER_add_now (disco_ns, NULL); | ||
293 | |||
294 | gns_handle = GNUNET_GNS_connect(cfg); | 302 | gns_handle = GNUNET_GNS_connect(cfg); |
295 | |||
296 | if (NULL == gns_handle) | 303 | if (NULL == gns_handle) |
297 | { | 304 | { |
298 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
299 | "Failed to connect to GNS!\n"); | 306 | "Failed to connect to GNS!\n"); |
300 | ok = 2; | 307 | end_badly_now (); |
308 | return; | ||
301 | } | 309 | } |
302 | 310 | ||
303 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_A, | 311 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_A, |
@@ -307,53 +315,26 @@ commence_testing (void *cls, int32_t success, const char *emsg) | |||
307 | } | 315 | } |
308 | 316 | ||
309 | 317 | ||
310 | /** | ||
311 | * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut | ||
312 | * down the peers without freeing memory associated with GET request. | ||
313 | */ | ||
314 | static void | ||
315 | end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
316 | { | ||
317 | |||
318 | if (pg != NULL) | ||
319 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
320 | GNUNET_SCHEDULER_cancel (die_task); | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * Check if the get_handle is being used, if so stop the request. Either | ||
325 | * way, schedule the end_badly_cont function which actually shuts down the | ||
326 | * test. | ||
327 | */ | ||
328 | static void | ||
329 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
330 | { | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n", | ||
332 | (char *) cls); | ||
333 | GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL); | ||
334 | ok = 1; | ||
335 | } | ||
336 | |||
337 | static void | 318 | static void |
338 | do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | 319 | do_check (void *cls, |
339 | const struct GNUNET_CONFIGURATION_Handle *_cfg, | 320 | const struct GNUNET_CONFIGURATION_Handle *ccfg, |
340 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 321 | struct GNUNET_TESTING_Peer *peer) |
341 | { | 322 | { |
342 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; | 323 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; |
343 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; | 324 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; |
344 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; | 325 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; |
345 | char* alice_keyfile; | 326 | char* alice_keyfile; |
346 | 327 | ||
347 | cfg = _cfg; | 328 | cfg = ccfg; |
329 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
348 | 330 | ||
349 | GNUNET_SCHEDULER_cancel (die_task); | ||
350 | 331 | ||
351 | /* put records into namestore */ | 332 | /* put records into namestore */ |
352 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | 333 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); |
353 | if (NULL == namestore_handle) | 334 | if (NULL == namestore_handle) |
354 | { | 335 | { |
355 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); | 336 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); |
356 | ok = -1; | 337 | end_badly_now (); |
357 | return; | 338 | return; |
358 | } | 339 | } |
359 | 340 | ||
@@ -362,7 +343,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | |||
362 | &alice_keyfile)) | 343 | &alice_keyfile)) |
363 | { | 344 | { |
364 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | 345 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); |
365 | ok = -1; | 346 | end_badly_now (); |
366 | return; | 347 | return; |
367 | } | 348 | } |
368 | 349 | ||
@@ -442,80 +423,20 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | |||
442 | 423 | ||
443 | } | 424 | } |
444 | 425 | ||
445 | static void | ||
446 | run (void *cls, char *const *args, const char *cfgfile, | ||
447 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
448 | { | ||
449 | cfg = c; | ||
450 | /* Get path from configuration file */ | ||
451 | if (GNUNET_YES != | ||
452 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | ||
453 | &test_directory)) | ||
454 | { | ||
455 | ok = 404; | ||
456 | return; | ||
457 | } | ||
458 | |||
459 | |||
460 | /* Set up a task to end testing if peer start fails */ | ||
461 | die_task = | ||
462 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, | ||
463 | "didn't start all daemons in reasonable amount of time!!!"); | ||
464 | |||
465 | /* Start alice */ | ||
466 | pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT, | ||
467 | NULL, NULL, &do_lookup, NULL, | ||
468 | NULL, NULL, NULL); | ||
469 | } | ||
470 | |||
471 | static int | ||
472 | check () | ||
473 | { | ||
474 | int ret; | ||
475 | |||
476 | /* Arguments for GNUNET_PROGRAM_run */ | ||
477 | char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */ | ||
478 | "-c", | ||
479 | "test_gns_simple_lookup.conf", /* Config file to use */ | ||
480 | #if VERBOSE | ||
481 | "-L", "DEBUG", | ||
482 | #endif | ||
483 | NULL | ||
484 | }; | ||
485 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
486 | GNUNET_GETOPT_OPTION_END | ||
487 | }; | ||
488 | /* Run the run function as a new program */ | ||
489 | ret = | ||
490 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | ||
491 | "test-gns-simple-lookup", "nohelp", options, &run, | ||
492 | &ok); | ||
493 | if (ret != GNUNET_OK) | ||
494 | { | ||
495 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
496 | "`test-gns-simple-lookup': Failed with error code %d\n", ret); | ||
497 | } | ||
498 | return ok; | ||
499 | } | ||
500 | |||
501 | int | 426 | int |
502 | main (int argc, char *argv[]) | 427 | main (int argc, char *argv[]) |
503 | { | 428 | { |
504 | int ret; | 429 | ok = 1; |
505 | 430 | ||
506 | GNUNET_log_setup ("test-gns-simple-lookup", | 431 | GNUNET_log_setup ("test-gns-simple-cname-lookup", |
507 | #if VERBOSE | 432 | #if VERBOSE |
508 | "DEBUG", | 433 | "DEBUG", |
509 | #else | 434 | #else |
510 | "WARNING", | 435 | "WARNING", |
511 | #endif | 436 | #endif |
512 | NULL); | 437 | NULL); |
513 | ret = check (); | 438 | GNUNET_TESTING_peer_run ("test-gns-simple-cname-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); |
514 | /** | 439 | return ok; |
515 | * Need to remove base directory, subdirectories taken care | ||
516 | * of by the testing framework. | ||
517 | */ | ||
518 | return ret; | ||
519 | } | 440 | } |
520 | 441 | ||
521 | /* end of test_gns_twopeer.c */ | 442 | /* end of test_gns_simple_cname_lookup.c */ |
diff --git a/src/gns/test_gns_simple_zkey_lookup.c b/src/gns/test_gns_simple_zkey_lookup.c index d796d027c..6be749c88 100644 --- a/src/gns/test_gns_simple_zkey_lookup.c +++ b/src/gns/test_gns_simple_zkey_lookup.c | |||
@@ -163,7 +163,6 @@ commence_testing (void *cls, int32_t success, const char *emsg) | |||
163 | char* pos; | 163 | char* pos; |
164 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str; | 164 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str; |
165 | 165 | ||
166 | |||
167 | gns_handle = GNUNET_GNS_connect(cfg); | 166 | gns_handle = GNUNET_GNS_connect(cfg); |
168 | 167 | ||
169 | if (NULL == gns_handle) | 168 | if (NULL == gns_handle) |