diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-19 13:33:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-19 13:33:19 +0000 |
commit | 15f55fea6e6d2d1656e345eab131887efbd937b4 (patch) | |
tree | 4f73dcb99b65afaaec412b4a2969771497a6f876 /src/namestore/test_namestore_api_zone_iteration.c | |
parent | 0f084973d63c46217d25e6660fba56755f26e6bb (diff) | |
download | gnunet-15f55fea6e6d2d1656e345eab131887efbd937b4.tar.gz gnunet-15f55fea6e6d2d1656e345eab131887efbd937b4.zip |
-fixing IO-error bug in namestore tests on buildbots, simplifying testcases by using new testing API, eliminating dead code
Diffstat (limited to 'src/namestore/test_namestore_api_zone_iteration.c')
-rw-r--r-- | src/namestore/test_namestore_api_zone_iteration.c | 151 |
1 files changed, 48 insertions, 103 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index f18aad93f..9a2c2d0ab 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -24,67 +24,55 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
26 | #include "gnunet_namestore_service.h" | 26 | #include "gnunet_namestore_service.h" |
27 | #include "gnunet_testing_lib-new.h" | ||
27 | #include "namestore.h" | 28 | #include "namestore.h" |
28 | 29 | ||
29 | #define VERBOSE GNUNET_NO | ||
30 | 30 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
32 | 32 | ||
33 | |||
33 | static struct GNUNET_NAMESTORE_Handle * nsh; | 34 | static struct GNUNET_NAMESTORE_Handle * nsh; |
34 | 35 | ||
35 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 36 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
37 | |||
36 | static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; | 38 | static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; |
37 | static struct GNUNET_OS_Process *arm; | ||
38 | 39 | ||
39 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 40 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
41 | |||
40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 42 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
43 | |||
41 | static struct GNUNET_HashCode zone; | 44 | static struct GNUNET_HashCode zone; |
42 | 45 | ||
43 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; | 46 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; |
47 | |||
44 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; | 48 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; |
49 | |||
45 | static struct GNUNET_HashCode zone2; | 50 | static struct GNUNET_HashCode zone2; |
46 | 51 | ||
47 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 52 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
53 | |||
48 | static int res; | 54 | static int res; |
55 | |||
49 | static int returned_records; | 56 | static int returned_records; |
50 | 57 | ||
51 | struct GNUNET_CRYPTO_RsaSignature *sig_1; | 58 | static struct GNUNET_CRYPTO_RsaSignature *sig_1; |
52 | char * s_name_1; | ||
53 | struct GNUNET_NAMESTORE_RecordData *s_rd_1; | ||
54 | 59 | ||
55 | struct GNUNET_CRYPTO_RsaSignature *sig_2; | 60 | static char * s_name_1; |
56 | char * s_name_2; | ||
57 | struct GNUNET_NAMESTORE_RecordData *s_rd_2; | ||
58 | 61 | ||
59 | struct GNUNET_CRYPTO_RsaSignature *sig_3; | 62 | static struct GNUNET_NAMESTORE_RecordData *s_rd_1; |
60 | char * s_name_3; | ||
61 | struct GNUNET_NAMESTORE_RecordData *s_rd_3; | ||
62 | 63 | ||
63 | static void | 64 | static struct GNUNET_CRYPTO_RsaSignature *sig_2; |
64 | start_arm (const char *cfgname) | 65 | |
65 | { | 66 | static char * s_name_2; |
66 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | 67 | |
67 | "gnunet-service-arm", "-c", cfgname, | 68 | static struct GNUNET_NAMESTORE_RecordData *s_rd_2; |
68 | #if VERBOSE_PEERS | 69 | |
69 | "-L", "DEBUG", | 70 | static struct GNUNET_CRYPTO_RsaSignature *sig_3; |
70 | #else | 71 | |
71 | "-L", "ERROR", | 72 | static char * s_name_3; |
72 | #endif | 73 | |
73 | NULL); | 74 | static struct GNUNET_NAMESTORE_RecordData *s_rd_3; |
74 | } | ||
75 | 75 | ||
76 | static void | ||
77 | stop_arm () | ||
78 | { | ||
79 | if (NULL != arm) | ||
80 | { | ||
81 | if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) | ||
82 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
83 | GNUNET_OS_process_wait (arm); | ||
84 | GNUNET_OS_process_destroy (arm); | ||
85 | arm = NULL; | ||
86 | } | ||
87 | } | ||
88 | 76 | ||
89 | /** | 77 | /** |
90 | * Re-establish the connection to the service. | 78 | * Re-establish the connection to the service. |
@@ -135,10 +123,6 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | if (privkey2 != NULL) | 123 | if (privkey2 != NULL) |
136 | GNUNET_CRYPTO_rsa_key_free (privkey2); | 124 | GNUNET_CRYPTO_rsa_key_free (privkey2); |
137 | privkey2 = NULL; | 125 | privkey2 = NULL; |
138 | |||
139 | if (NULL != arm) | ||
140 | stop_arm(); | ||
141 | |||
142 | res = 1; | 126 | res = 1; |
143 | } | 127 | } |
144 | 128 | ||
@@ -187,23 +171,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
187 | GNUNET_free ((void *)s_rd_3->data); | 171 | GNUNET_free ((void *)s_rd_3->data); |
188 | GNUNET_free (s_rd_3); | 172 | GNUNET_free (s_rd_3); |
189 | } | 173 | } |
190 | |||
191 | if (nsh != NULL) | 174 | if (nsh != NULL) |
192 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 175 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
193 | nsh = NULL; | 176 | nsh = NULL; |
194 | |||
195 | |||
196 | if (NULL != arm) | ||
197 | stop_arm(); | ||
198 | } | 177 | } |
199 | 178 | ||
200 | void zone_proc (void *cls, | 179 | |
201 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 180 | static void |
202 | struct GNUNET_TIME_Absolute expire, | 181 | zone_proc (void *cls, |
203 | const char *name, | 182 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
204 | unsigned int rd_count, | 183 | struct GNUNET_TIME_Absolute expire, |
205 | const struct GNUNET_NAMESTORE_RecordData *rd, | 184 | const char *name, |
206 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 185 | unsigned int rd_count, |
186 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
187 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
207 | { | 188 | { |
208 | int failed = GNUNET_NO; | 189 | int failed = GNUNET_NO; |
209 | if ((zone_key == NULL) && (name == NULL)) | 190 | if ((zone_key == NULL) && (name == NULL)) |
@@ -322,25 +303,8 @@ void zone_proc (void *cls, | |||
322 | } | 303 | } |
323 | } | 304 | } |
324 | 305 | ||
325 | void | ||
326 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
327 | { | ||
328 | char *afsdir; | ||
329 | |||
330 | if (GNUNET_OK == | ||
331 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
332 | "FILENAME", &afsdir)) | ||
333 | { | ||
334 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
335 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
336 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
338 | GNUNET_free (afsdir); | ||
339 | } | ||
340 | |||
341 | } | ||
342 | 306 | ||
343 | void | 307 | static void |
344 | put_cont (void *cls, int32_t success, const char *emsg) | 308 | put_cont (void *cls, int32_t success, const char *emsg) |
345 | { | 309 | { |
346 | static int c = 0; | 310 | static int c = 0; |
@@ -379,6 +343,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
379 | } | 343 | } |
380 | } | 344 | } |
381 | 345 | ||
346 | |||
382 | static struct GNUNET_NAMESTORE_RecordData * | 347 | static struct GNUNET_NAMESTORE_RecordData * |
383 | create_record (int count) | 348 | create_record (int count) |
384 | { | 349 | { |
@@ -397,14 +362,14 @@ create_record (int count) | |||
397 | return rd; | 362 | return rd; |
398 | } | 363 | } |
399 | 364 | ||
365 | |||
400 | static void | 366 | static void |
401 | run (void *cls, char *const *args, const char *cfgfile, | 367 | run (void *cls, |
402 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 368 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
403 | { | 369 | { |
404 | delete_existing_db(cfg); | ||
405 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); | ||
406 | |||
407 | char *hostkey_file; | 370 | char *hostkey_file; |
371 | |||
372 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); | ||
408 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 373 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, |
409 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 374 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | 375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); |
@@ -424,11 +389,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
424 | GNUNET_assert (privkey2 != NULL); | 389 | GNUNET_assert (privkey2 != NULL); |
425 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); | 390 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); |
426 | GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); | 391 | GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); |
427 | |||
428 | |||
429 | start_arm (cfgfile); | ||
430 | GNUNET_assert (arm != NULL); | ||
431 | |||
432 | nsh = GNUNET_NAMESTORE_connect (cfg); | 392 | nsh = GNUNET_NAMESTORE_connect (cfg); |
433 | GNUNET_break (NULL != nsh); | 393 | GNUNET_break (NULL != nsh); |
434 | 394 | ||
@@ -455,35 +415,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
455 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); | 415 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); |
456 | } | 416 | } |
457 | 417 | ||
458 | static int | ||
459 | check () | ||
460 | { | ||
461 | static char *const argv[] = { "test_namestore_api_zone_iteration", | ||
462 | "-c", | ||
463 | "test_namestore_api.conf", | ||
464 | #if VERBOSE | ||
465 | "-L", "DEBUG", | ||
466 | #endif | ||
467 | NULL | ||
468 | }; | ||
469 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
470 | GNUNET_GETOPT_OPTION_END | ||
471 | }; | ||
472 | |||
473 | res = 1; | ||
474 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration", | ||
475 | "nohelp", options, &run, &res); | ||
476 | return res; | ||
477 | } | ||
478 | 418 | ||
479 | int | 419 | int |
480 | main (int argc, char *argv[]) | 420 | main (int argc, char *argv[]) |
481 | { | 421 | { |
482 | int ret; | 422 | res = 1; |
483 | 423 | if (0 != | |
484 | ret = check (); | 424 | GNUNET_TESTING_service_run ("test-namestore-api-zone-iteration", |
485 | 425 | "namestore", | |
486 | return ret; | 426 | "test_namestore_api.conf", |
427 | &run, | ||
428 | NULL)) | ||
429 | return 1; | ||
430 | return res; | ||
487 | } | 431 | } |
488 | 432 | ||
433 | |||
489 | /* end of test_namestore_api_zone_iteration.c */ | 434 | /* end of test_namestore_api_zone_iteration.c */ |