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_stop.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_stop.c')
-rw-r--r-- | src/namestore/test_namestore_api_zone_iteration_stop.c | 156 |
1 files changed, 48 insertions, 108 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index 90031edc7..71ae43362 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c | |||
@@ -23,68 +23,55 @@ | |||
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
26 | #include "gnunet_testing_lib-new.h" | ||
26 | #include "gnunet_namestore_service.h" | 27 | #include "gnunet_namestore_service.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, 15) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
32 | 32 | ||
33 | static struct GNUNET_NAMESTORE_Handle * nsh; | 33 | static struct GNUNET_NAMESTORE_Handle * nsh; |
34 | 34 | ||
35 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 35 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
36 | |||
36 | static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; | 37 | static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; |
37 | static struct GNUNET_OS_Process *arm; | ||
38 | 38 | ||
39 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 39 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
40 | |||
40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 41 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
42 | |||
41 | static struct GNUNET_HashCode zone; | 43 | static struct GNUNET_HashCode zone; |
42 | 44 | ||
43 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; | 45 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; |
46 | |||
44 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; | 47 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; |
48 | |||
45 | static struct GNUNET_HashCode zone2; | 49 | static struct GNUNET_HashCode zone2; |
46 | 50 | ||
47 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 51 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
52 | |||
48 | static int res; | 53 | static int res; |
54 | |||
49 | static int returned_records; | 55 | static int returned_records; |
50 | 56 | ||
51 | struct GNUNET_CRYPTO_RsaSignature *sig_1; | 57 | static struct GNUNET_CRYPTO_RsaSignature *sig_1; |
52 | char * s_name_1; | ||
53 | struct GNUNET_NAMESTORE_RecordData *s_rd_1; | ||
54 | 58 | ||
55 | struct GNUNET_CRYPTO_RsaSignature *sig_2; | 59 | static char * s_name_1; |
56 | char * s_name_2; | ||
57 | struct GNUNET_NAMESTORE_RecordData *s_rd_2; | ||
58 | 60 | ||
59 | struct GNUNET_CRYPTO_RsaSignature *sig_3; | 61 | static struct GNUNET_NAMESTORE_RecordData *s_rd_1; |
60 | char * s_name_3; | ||
61 | struct GNUNET_NAMESTORE_RecordData *s_rd_3; | ||
62 | 62 | ||
63 | static void | 63 | static struct GNUNET_CRYPTO_RsaSignature *sig_2; |
64 | start_arm (const char *cfgname) | 64 | |
65 | { | 65 | static char * s_name_2; |
66 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | 66 | |
67 | "gnunet-service-arm", "-c", cfgname, | 67 | static struct GNUNET_NAMESTORE_RecordData *s_rd_2; |
68 | #if VERBOSE_PEERS | 68 | |
69 | "-L", "DEBUG", | 69 | static struct GNUNET_CRYPTO_RsaSignature *sig_3; |
70 | #else | 70 | |
71 | "-L", "ERROR", | 71 | static char * s_name_3; |
72 | #endif | 72 | |
73 | NULL); | 73 | static struct GNUNET_NAMESTORE_RecordData *s_rd_3; |
74 | } | ||
75 | 74 | ||
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 | 75 | ||
89 | /** | 76 | /** |
90 | * Re-establish the connection to the service. | 77 | * Re-establish the connection to the service. |
@@ -100,18 +87,15 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
100 | GNUNET_SCHEDULER_cancel (stopiteration_task); | 87 | GNUNET_SCHEDULER_cancel (stopiteration_task); |
101 | stopiteration_task = GNUNET_SCHEDULER_NO_TASK; | 88 | stopiteration_task = GNUNET_SCHEDULER_NO_TASK; |
102 | } | 89 | } |
103 | |||
104 | if (nsh != NULL) | 90 | if (nsh != NULL) |
105 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 91 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
106 | nsh = NULL; | 92 | nsh = NULL; |
107 | |||
108 | GNUNET_free_non_null(sig_1); | 93 | GNUNET_free_non_null(sig_1); |
109 | GNUNET_free_non_null(sig_2); | 94 | GNUNET_free_non_null(sig_2); |
110 | GNUNET_free_non_null(sig_3); | 95 | GNUNET_free_non_null(sig_3); |
111 | GNUNET_free_non_null(s_name_1); | 96 | GNUNET_free_non_null(s_name_1); |
112 | GNUNET_free_non_null(s_name_2); | 97 | GNUNET_free_non_null(s_name_2); |
113 | GNUNET_free_non_null(s_name_3); | 98 | GNUNET_free_non_null(s_name_3); |
114 | |||
115 | if (s_rd_1 != NULL) | 99 | if (s_rd_1 != NULL) |
116 | { | 100 | { |
117 | GNUNET_free ((void *)s_rd_1->data); | 101 | GNUNET_free ((void *)s_rd_1->data); |
@@ -127,7 +111,6 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
127 | GNUNET_free ((void *)s_rd_3->data); | 111 | GNUNET_free ((void *)s_rd_3->data); |
128 | GNUNET_free (s_rd_3); | 112 | GNUNET_free (s_rd_3); |
129 | } | 113 | } |
130 | |||
131 | if (privkey != NULL) | 114 | if (privkey != NULL) |
132 | GNUNET_CRYPTO_rsa_key_free (privkey); | 115 | GNUNET_CRYPTO_rsa_key_free (privkey); |
133 | privkey = NULL; | 116 | privkey = NULL; |
@@ -135,10 +118,6 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | if (privkey2 != NULL) | 118 | if (privkey2 != NULL) |
136 | GNUNET_CRYPTO_rsa_key_free (privkey2); | 119 | GNUNET_CRYPTO_rsa_key_free (privkey2); |
137 | privkey2 = NULL; | 120 | privkey2 = NULL; |
138 | |||
139 | if (NULL != arm) | ||
140 | stop_arm(); | ||
141 | |||
142 | res = 1; | 121 | res = 1; |
143 | } | 122 | } |
144 | 123 | ||
@@ -157,11 +136,9 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
157 | GNUNET_SCHEDULER_cancel (endbadly_task); | 136 | GNUNET_SCHEDULER_cancel (endbadly_task); |
158 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 137 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
159 | } | 138 | } |
160 | |||
161 | if (privkey != NULL) | 139 | if (privkey != NULL) |
162 | GNUNET_CRYPTO_rsa_key_free (privkey); | 140 | GNUNET_CRYPTO_rsa_key_free (privkey); |
163 | privkey = NULL; | 141 | privkey = NULL; |
164 | |||
165 | if (privkey2 != NULL) | 142 | if (privkey2 != NULL) |
166 | GNUNET_CRYPTO_rsa_key_free (privkey2); | 143 | GNUNET_CRYPTO_rsa_key_free (privkey2); |
167 | privkey2 = NULL; | 144 | privkey2 = NULL; |
@@ -187,13 +164,9 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
187 | GNUNET_free ((void *)s_rd_3->data); | 164 | GNUNET_free ((void *)s_rd_3->data); |
188 | GNUNET_free (s_rd_3); | 165 | GNUNET_free (s_rd_3); |
189 | } | 166 | } |
190 | |||
191 | if (nsh != NULL) | 167 | if (nsh != NULL) |
192 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 168 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
193 | nsh = NULL; | 169 | nsh = NULL; |
194 | |||
195 | if (NULL != arm) | ||
196 | stop_arm(); | ||
197 | if (returned_records == 1) | 170 | if (returned_records == 1) |
198 | res = 0; | 171 | res = 0; |
199 | else | 172 | else |
@@ -201,13 +174,15 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
201 | 174 | ||
202 | } | 175 | } |
203 | 176 | ||
204 | void zone_proc (void *cls, | 177 | |
205 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 178 | static void |
206 | struct GNUNET_TIME_Absolute expire, | 179 | zone_proc (void *cls, |
207 | const char *name, | 180 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
208 | unsigned int rd_count, | 181 | struct GNUNET_TIME_Absolute expire, |
209 | const struct GNUNET_NAMESTORE_RecordData *rd, | 182 | const char *name, |
210 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 183 | unsigned int rd_count, |
184 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
185 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
211 | { | 186 | { |
212 | int failed = GNUNET_NO; | 187 | int failed = GNUNET_NO; |
213 | 188 | ||
@@ -336,25 +311,8 @@ void zone_proc (void *cls, | |||
336 | } | 311 | } |
337 | } | 312 | } |
338 | 313 | ||
339 | void | ||
340 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
341 | { | ||
342 | char *afsdir; | ||
343 | |||
344 | if (GNUNET_OK == | ||
345 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
346 | "FILENAME", &afsdir)) | ||
347 | { | ||
348 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
349 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
350 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
352 | GNUNET_free (afsdir); | ||
353 | } | ||
354 | |||
355 | } | ||
356 | 314 | ||
357 | void | 315 | static void |
358 | put_cont (void *cls, int32_t success, const char *emsg) | 316 | put_cont (void *cls, int32_t success, const char *emsg) |
359 | { | 317 | { |
360 | static int c = 0; | 318 | static int c = 0; |
@@ -393,6 +351,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
393 | } | 351 | } |
394 | } | 352 | } |
395 | 353 | ||
354 | |||
396 | static struct GNUNET_NAMESTORE_RecordData * | 355 | static struct GNUNET_NAMESTORE_RecordData * |
397 | create_record (int count) | 356 | create_record (int count) |
398 | { | 357 | { |
@@ -411,14 +370,14 @@ create_record (int count) | |||
411 | return rd; | 370 | return rd; |
412 | } | 371 | } |
413 | 372 | ||
373 | |||
414 | static void | 374 | static void |
415 | run (void *cls, char *const *args, const char *cfgfile, | 375 | run (void *cls, |
416 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 376 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
417 | { | 377 | { |
418 | delete_existing_db(cfg); | ||
419 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); | ||
420 | |||
421 | char *hostkey_file; | 378 | char *hostkey_file; |
379 | |||
380 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); | ||
422 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 381 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, |
423 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 382 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | 383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); |
@@ -437,10 +396,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
437 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); | 396 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); |
438 | GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); | 397 | GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); |
439 | 398 | ||
440 | |||
441 | start_arm (cfgfile); | ||
442 | GNUNET_assert (arm != NULL); | ||
443 | |||
444 | nsh = GNUNET_NAMESTORE_connect (cfg); | 399 | nsh = GNUNET_NAMESTORE_connect (cfg); |
445 | GNUNET_break (NULL != nsh); | 400 | GNUNET_break (NULL != nsh); |
446 | 401 | ||
@@ -467,35 +422,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
467 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); | 422 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); |
468 | } | 423 | } |
469 | 424 | ||
470 | static int | ||
471 | check () | ||
472 | { | ||
473 | static char *const argv[] = { "test_namestore_api_zone_iteration", | ||
474 | "-c", | ||
475 | "test_namestore_api.conf", | ||
476 | #if VERBOSE | ||
477 | "-L", "DEBUG", | ||
478 | #endif | ||
479 | NULL | ||
480 | }; | ||
481 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
482 | GNUNET_GETOPT_OPTION_END | ||
483 | }; | ||
484 | |||
485 | res = 1; | ||
486 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration", | ||
487 | "nohelp", options, &run, &res); | ||
488 | return res; | ||
489 | } | ||
490 | 425 | ||
491 | int | 426 | int |
492 | main (int argc, char *argv[]) | 427 | main (int argc, char *argv[]) |
493 | { | 428 | { |
494 | int ret; | 429 | res = 1; |
495 | 430 | if (0 != | |
496 | ret = check (); | 431 | GNUNET_TESTING_service_run ("test-namestore-api-zone-iteration-stop", |
497 | 432 | "namestore", | |
498 | return ret; | 433 | "test_namestore_api.conf", |
434 | &run, | ||
435 | NULL)) | ||
436 | return 1; | ||
437 | return res; | ||
499 | } | 438 | } |
500 | 439 | ||
501 | /* end of test_namestore_api_zone_iteration.c */ | 440 | |
441 | /* end of test_namestore_api_zone_iteration_stop.c */ | ||