aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-19 13:33:19 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-19 13:33:19 +0000
commit15f55fea6e6d2d1656e345eab131887efbd937b4 (patch)
tree4f73dcb99b65afaaec412b4a2969771497a6f876 /src/namestore/test_namestore_api_zone_iteration_specific_zone.c
parent0f084973d63c46217d25e6660fba56755f26e6bb (diff)
downloadgnunet-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_specific_zone.c')
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c158
1 files changed, 47 insertions, 111 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index b21c860c8..b76acb4dd 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -23,68 +23,56 @@
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, 10) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
32 32
33
33static struct GNUNET_NAMESTORE_Handle * nsh; 34static struct GNUNET_NAMESTORE_Handle * nsh;
34 35
35static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; 36static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
37
36static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; 38static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task;
37static struct GNUNET_OS_Process *arm;
38 39
39static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; 40static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
41
40static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; 42static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
43
41static struct GNUNET_CRYPTO_ShortHashCode zone; 44static struct GNUNET_CRYPTO_ShortHashCode zone;
42 45
43static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; 46static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2;
47
44static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; 48static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2;
49
45static struct GNUNET_CRYPTO_ShortHashCode zone2; 50static struct GNUNET_CRYPTO_ShortHashCode zone2;
46 51
47static struct GNUNET_NAMESTORE_ZoneIterator *zi; 52static struct GNUNET_NAMESTORE_ZoneIterator *zi;
53
48static int res; 54static int res;
55
49static int returned_records; 56static int returned_records;
50 57
51struct GNUNET_CRYPTO_RsaSignature *sig_1; 58static struct GNUNET_CRYPTO_RsaSignature *sig_1;
52char * s_name_1;
53struct GNUNET_NAMESTORE_RecordData *s_rd_1;
54 59
55struct GNUNET_CRYPTO_RsaSignature *sig_2; 60static char * s_name_1;
56char * s_name_2;
57struct GNUNET_NAMESTORE_RecordData *s_rd_2;
58 61
59struct GNUNET_CRYPTO_RsaSignature *sig_3; 62static struct GNUNET_NAMESTORE_RecordData *s_rd_1;
60char * s_name_3;
61struct GNUNET_NAMESTORE_RecordData *s_rd_3;
62 63
63static void 64static struct GNUNET_CRYPTO_RsaSignature *sig_2;
64start_arm (const char *cfgname) 65
65{ 66static char * s_name_2;
66 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", 67
67 "gnunet-service-arm", "-c", cfgname, 68static struct GNUNET_NAMESTORE_RecordData *s_rd_2;
68#if VERBOSE_PEERS 69
69 "-L", "DEBUG", 70static struct GNUNET_CRYPTO_RsaSignature *sig_3;
70#else 71
71 "-L", "ERROR", 72static char * s_name_3;
72#endif 73
73 NULL); 74static struct GNUNET_NAMESTORE_RecordData *s_rd_3;
74}
75 75
76static void
77stop_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.
@@ -104,14 +92,12 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
104 if (nsh != NULL) 92 if (nsh != NULL)
105 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 93 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
106 nsh = NULL; 94 nsh = NULL;
107
108 GNUNET_free_non_null(sig_1); 95 GNUNET_free_non_null(sig_1);
109 GNUNET_free_non_null(sig_2); 96 GNUNET_free_non_null(sig_2);
110 GNUNET_free_non_null(sig_3); 97 GNUNET_free_non_null(sig_3);
111 GNUNET_free_non_null(s_name_1); 98 GNUNET_free_non_null(s_name_1);
112 GNUNET_free_non_null(s_name_2); 99 GNUNET_free_non_null(s_name_2);
113 GNUNET_free_non_null(s_name_3); 100 GNUNET_free_non_null(s_name_3);
114
115 if (s_rd_1 != NULL) 101 if (s_rd_1 != NULL)
116 { 102 {
117 GNUNET_free ((void *)s_rd_1->data); 103 GNUNET_free ((void *)s_rd_1->data);
@@ -135,10 +121,6 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
135 if (privkey2 != NULL) 121 if (privkey2 != NULL)
136 GNUNET_CRYPTO_rsa_key_free (privkey2); 122 GNUNET_CRYPTO_rsa_key_free (privkey2);
137 privkey2 = NULL; 123 privkey2 = NULL;
138
139 if (NULL != arm)
140 stop_arm();
141
142 res = 1; 124 res = 1;
143} 125}
144 126
@@ -151,17 +133,14 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
151 GNUNET_SCHEDULER_cancel (stopiteration_task); 133 GNUNET_SCHEDULER_cancel (stopiteration_task);
152 stopiteration_task = GNUNET_SCHEDULER_NO_TASK; 134 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
153 } 135 }
154
155 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) 136 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
156 { 137 {
157 GNUNET_SCHEDULER_cancel (endbadly_task); 138 GNUNET_SCHEDULER_cancel (endbadly_task);
158 endbadly_task = GNUNET_SCHEDULER_NO_TASK; 139 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
159 } 140 }
160
161 if (privkey != NULL) 141 if (privkey != NULL)
162 GNUNET_CRYPTO_rsa_key_free (privkey); 142 GNUNET_CRYPTO_rsa_key_free (privkey);
163 privkey = NULL; 143 privkey = NULL;
164
165 if (privkey2 != NULL) 144 if (privkey2 != NULL)
166 GNUNET_CRYPTO_rsa_key_free (privkey2); 145 GNUNET_CRYPTO_rsa_key_free (privkey2);
167 privkey2 = NULL; 146 privkey2 = NULL;
@@ -187,23 +166,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
187 GNUNET_free ((void *)s_rd_3->data); 166 GNUNET_free ((void *)s_rd_3->data);
188 GNUNET_free (s_rd_3); 167 GNUNET_free (s_rd_3);
189 } 168 }
190
191 if (nsh != NULL) 169 if (nsh != NULL)
192 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 170 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
193 nsh = NULL; 171 nsh = NULL;
194
195
196 if (NULL != arm)
197 stop_arm();
198} 172}
199 173
200void zone_proc (void *cls, 174
201 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 175static void
202 struct GNUNET_TIME_Absolute expire, 176zone_proc (void *cls,
203 const char *name, 177 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
204 unsigned int rd_count, 178 struct GNUNET_TIME_Absolute expire,
205 const struct GNUNET_NAMESTORE_RecordData *rd, 179 const char *name,
206 const struct GNUNET_CRYPTO_RsaSignature *signature) 180 unsigned int rd_count,
181 const struct GNUNET_NAMESTORE_RecordData *rd,
182 const struct GNUNET_CRYPTO_RsaSignature *signature)
207{ 183{
208 int failed = GNUNET_NO; 184 int failed = GNUNET_NO;
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_short_h2s (&zone)); 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_short_h2s (&zone));
@@ -285,25 +261,8 @@ void zone_proc (void *cls,
285 } 261 }
286} 262}
287 263
288void
289delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
290{
291 char *afsdir;
292
293 if (GNUNET_OK ==
294 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
295 "FILENAME", &afsdir))
296 {
297 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
298 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
299 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
301 GNUNET_free (afsdir);
302 }
303
304}
305 264
306void 265static void
307put_cont (void *cls, int32_t success, const char *emsg) 266put_cont (void *cls, int32_t success, const char *emsg)
308{ 267{
309 static int c = 0; 268 static int c = 0;
@@ -343,6 +302,7 @@ put_cont (void *cls, int32_t success, const char *emsg)
343 } 302 }
344} 303}
345 304
305
346static struct GNUNET_NAMESTORE_RecordData * 306static struct GNUNET_NAMESTORE_RecordData *
347create_record (int count) 307create_record (int count)
348{ 308{
@@ -361,14 +321,14 @@ create_record (int count)
361 return rd; 321 return rd;
362} 322}
363 323
324
364static void 325static void
365run (void *cls, char *const *args, const char *cfgfile, 326run (void *cls,
366 const struct GNUNET_CONFIGURATION_Handle *cfg) 327 const struct GNUNET_CONFIGURATION_Handle *cfg)
367{ 328{
368 delete_existing_db(cfg);
369 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
370
371 char *hostkey_file; 329 char *hostkey_file;
330
331 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
372 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 332 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
373 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 333 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
@@ -386,26 +346,18 @@ run (void *cls, char *const *args, const char *cfgfile,
386 GNUNET_assert (privkey2 != NULL); 346 GNUNET_assert (privkey2 != NULL);
387 GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); 347 GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2);
388 GNUNET_CRYPTO_short_hash (&pubkey2, sizeof (pubkey), &zone2); 348 GNUNET_CRYPTO_short_hash (&pubkey2, sizeof (pubkey), &zone2);
389
390
391 start_arm (cfgfile);
392 GNUNET_assert (arm != NULL);
393
394 nsh = GNUNET_NAMESTORE_connect (cfg); 349 nsh = GNUNET_NAMESTORE_connect (cfg);
395 GNUNET_break (NULL != nsh); 350 GNUNET_break (NULL != nsh);
396 351
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
398
399 GNUNET_asprintf(&s_name_1, "dummy1"); 353 GNUNET_asprintf(&s_name_1, "dummy1");
400 s_rd_1 = create_record(1); 354 s_rd_1 = create_record(1);
401 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_1[0].expiration ,s_name_1, s_rd_1, 1); 355 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_1[0].expiration ,s_name_1, s_rd_1, 1);
402 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL); 356 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
403 357
404
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
406 GNUNET_asprintf(&s_name_2, "dummy2"); 359 GNUNET_asprintf(&s_name_2, "dummy2");
407 s_rd_2 = create_record(1); 360 s_rd_2 = create_record(1);
408
409 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_2[0].expiration, s_name_2, s_rd_2, 1); 361 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_2[0].expiration, s_name_2, s_rd_2, 1);
410 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); 362 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
411 363
@@ -417,35 +369,19 @@ run (void *cls, char *const *args, const char *cfgfile,
417 GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); 369 GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL);
418} 370}
419 371
420static int
421check ()
422{
423 static char *const argv[] = { "test_namestore_api_zone_iteration",
424 "-c",
425 "test_namestore_api.conf",
426#if VERBOSE
427 "-L", "DEBUG",
428#endif
429 NULL
430 };
431 static struct GNUNET_GETOPT_CommandLineOption options[] = {
432 GNUNET_GETOPT_OPTION_END
433 };
434
435 res = 1;
436 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration",
437 "nohelp", options, &run, &res);
438 return res;
439}
440 372
441int 373int
442main (int argc, char *argv[]) 374main (int argc, char *argv[])
443{ 375{
444 int ret; 376 res = 1;
445 377 if (0 !=
446 ret = check (); 378 GNUNET_TESTING_service_run ("test-namestore-api-zone-iteration-specific-zone",
447 379 "namestore",
448 return ret; 380 "test_namestore_api.conf",
381 &run,
382 NULL))
383 return 1;
384 return res;
449} 385}
450 386
451/* end of test_namestore_api_zone_iteration_specific_zone.c */ 387/* end of test_namestore_api_zone_iteration_specific_zone.c */