aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_remove.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_remove.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_remove.c')
-rw-r--r--src/namestore/test_namestore_api_remove.c150
1 files changed, 42 insertions, 108 deletions
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c
index 57bb4a822..1d57e70f9 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -24,63 +24,45 @@
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#include "gnunet_signatures.h" 29#include "gnunet_signatures.h"
29 30
30#define VERBOSE GNUNET_NO
31
32#define RECORDS 5 31#define RECORDS 5
32
33#define TEST_RECORD_TYPE 1234 33#define TEST_RECORD_TYPE 1234
34
34#define TEST_RECORD_DATALEN 123 35#define TEST_RECORD_DATALEN 123
36
35#define TEST_RECORD_DATA 'a' 37#define TEST_RECORD_DATA 'a'
36 38
37#define TEST_REMOVE_RECORD_TYPE 4321 39#define TEST_REMOVE_RECORD_TYPE 4321
40
38#define TEST_REMOVE_RECORD_DATALEN 255 41#define TEST_REMOVE_RECORD_DATALEN 255
42
39#define TEST_REMOVE_RECORD_DATA 'b' 43#define TEST_REMOVE_RECORD_DATA 'b'
40 44
41#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
42 46
47
43static struct GNUNET_NAMESTORE_Handle * nsh; 48static struct GNUNET_NAMESTORE_Handle * nsh;
44 49
45static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; 50static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
46static struct GNUNET_OS_Process *arm;
47 51
48static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; 52static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
53
49static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; 54static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
50struct GNUNET_CRYPTO_RsaSignature *s_signature; 55
56static struct GNUNET_CRYPTO_RsaSignature *s_signature;
57
51static struct GNUNET_CRYPTO_ShortHashCode s_zone; 58static struct GNUNET_CRYPTO_ShortHashCode s_zone;
52struct GNUNET_NAMESTORE_RecordData *s_rd;
53static char *s_name;
54 59
60static struct GNUNET_NAMESTORE_RecordData *s_rd;
55 61
62static char *s_name;
56 63
57static int res; 64static int res;
58 65
59static void
60start_arm (const char *cfgname)
61{
62 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
63 "gnunet-service-arm", "-c", cfgname,
64#if VERBOSE_PEERS
65 "-L", "DEBUG",
66#else
67 "-L", "ERROR",
68#endif
69 NULL);
70}
71
72static void
73stop_arm ()
74{
75 if (NULL != arm)
76 {
77 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
78 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
79 GNUNET_OS_process_wait (arm);
80 GNUNET_OS_process_destroy (arm);
81 arm = NULL;
82 }
83}
84 66
85/** 67/**
86 * Re-establish the connection to the service. 68 * Re-establish the connection to the service.
@@ -94,14 +76,9 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 if (nsh != NULL) 76 if (nsh != NULL)
95 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 77 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
96 nsh = NULL; 78 nsh = NULL;
97
98 if (privkey != NULL) 79 if (privkey != NULL)
99 GNUNET_CRYPTO_rsa_key_free (privkey); 80 GNUNET_CRYPTO_rsa_key_free (privkey);
100 privkey = NULL; 81 privkey = NULL;
101
102 if (NULL != arm)
103 stop_arm();
104
105 res = 1; 82 res = 1;
106} 83}
107 84
@@ -109,36 +86,33 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109static void 86static void
110end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 87end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
111{ 88{
89 int c;
90
112 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) 91 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
113 { 92 {
114 GNUNET_SCHEDULER_cancel (endbadly_task); 93 GNUNET_SCHEDULER_cancel (endbadly_task);
115 endbadly_task = GNUNET_SCHEDULER_NO_TASK; 94 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
116 } 95 }
117
118 int c;
119 for (c = 0; c < RECORDS; c++) 96 for (c = 0; c < RECORDS; c++)
120 GNUNET_free_non_null((void *) s_rd[c].data); 97 GNUNET_free_non_null((void *) s_rd[c].data);
121 GNUNET_free (s_rd); 98 GNUNET_free (s_rd);
122
123 if (privkey != NULL) 99 if (privkey != NULL)
124 GNUNET_CRYPTO_rsa_key_free (privkey); 100 GNUNET_CRYPTO_rsa_key_free (privkey);
125 privkey = NULL; 101 privkey = NULL;
126
127 if (nsh != NULL) 102 if (nsh != NULL)
128 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 103 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
129 nsh = NULL; 104 nsh = NULL;
130
131 if (NULL != arm)
132 stop_arm();
133} 105}
134 106
135void name_lookup_proc (void *cls, 107
136 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 108static void
137 struct GNUNET_TIME_Absolute expire, 109name_lookup_proc (void *cls,
138 const char *n, 110 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
139 unsigned int rd_count, 111 struct GNUNET_TIME_Absolute expire,
140 const struct GNUNET_NAMESTORE_RecordData *rd, 112 const char *n,
141 const struct GNUNET_CRYPTO_RsaSignature *signature) 113 unsigned int rd_count,
114 const struct GNUNET_NAMESTORE_RecordData *rd,
115 const struct GNUNET_CRYPTO_RsaSignature *signature)
142{ 116{
143 static int found = GNUNET_NO; 117 static int found = GNUNET_NO;
144 int failed = GNUNET_NO; 118 int failed = GNUNET_NO;
@@ -197,7 +171,8 @@ void name_lookup_proc (void *cls,
197 GNUNET_SCHEDULER_add_now(&end, NULL); 171 GNUNET_SCHEDULER_add_now(&end, NULL);
198} 172}
199 173
200void 174
175static void
201remove_cont (void *cls, int32_t success, const char *emsg) 176remove_cont (void *cls, int32_t success, const char *emsg)
202{ 177{
203 char *name = cls; 178 char *name = cls;
@@ -216,7 +191,8 @@ remove_cont (void *cls, int32_t success, const char *emsg)
216 191
217} 192}
218 193
219void 194
195static void
220put_cont (void *cls, int32_t success, const char *emsg) 196put_cont (void *cls, int32_t success, const char *emsg)
221{ 197{
222 char *name = cls; 198 char *name = cls;
@@ -236,6 +212,7 @@ put_cont (void *cls, int32_t success, const char *emsg)
236 } 212 }
237} 213}
238 214
215
239static struct GNUNET_NAMESTORE_RecordData * 216static struct GNUNET_NAMESTORE_RecordData *
240create_record (int count) 217create_record (int count)
241{ 218{
@@ -261,34 +238,16 @@ create_record (int count)
261 return rd; 238 return rd;
262} 239}
263 240
264void
265delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
266{
267 char *afsdir;
268
269 if (GNUNET_OK ==
270 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
271 "FILENAME", &afsdir))
272 {
273 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
274 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
275 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
277 GNUNET_free (afsdir);
278 }
279
280}
281 241
282static void 242static void
283run (void *cls, char *const *args, const char *cfgfile, 243run (void *cls,
284 const struct GNUNET_CONFIGURATION_Handle *cfg) 244 const struct GNUNET_CONFIGURATION_Handle *cfg)
285{ 245{
286 delete_existing_db(cfg);
287 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
288 size_t rd_ser_len; 246 size_t rd_ser_len;
247 char *hostkey_file;
289 248
249 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
290 /* load privat key */ 250 /* load privat key */
291 char *hostkey_file;
292 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 251 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
293 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 252 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
@@ -313,54 +272,29 @@ run (void *cls, char *const *args, const char *cfgfile,
313 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); 272 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
314 273
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_short_h2s (&s_zone)); 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_short_h2s (&s_zone));
316
317
318 start_arm (cfgfile);
319 GNUNET_assert (arm != NULL);
320
321 nsh = GNUNET_NAMESTORE_connect (cfg); 275 nsh = GNUNET_NAMESTORE_connect (cfg);
322 GNUNET_break (NULL != nsh); 276 GNUNET_break (NULL != nsh);
323
324 GNUNET_break (s_rd != NULL); 277 GNUNET_break (s_rd != NULL);
325 GNUNET_break (s_name != NULL); 278 GNUNET_break (s_name != NULL);
326
327 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, 279 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
328 GNUNET_TIME_UNIT_FOREVER_ABS, 280 GNUNET_TIME_UNIT_FOREVER_ABS,
329 RECORDS, s_rd, s_signature, put_cont, s_name); 281 RECORDS, s_rd, s_signature, put_cont, s_name);
330
331
332
333} 282}
334 283
335static int
336check ()
337{
338 static char *const argv[] = { "test-namestore-api",
339 "-c",
340 "test_namestore_api.conf",
341#if VERBOSE
342 "-L", "DEBUG",
343#endif
344 NULL
345 };
346 static struct GNUNET_GETOPT_CommandLineOption options[] = {
347 GNUNET_GETOPT_OPTION_END
348 };
349
350 res = 1;
351 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api",
352 "nohelp", options, &run, &res);
353 return res;
354}
355 284
356int 285int
357main (int argc, char *argv[]) 286main (int argc, char *argv[])
358{ 287{
359 int ret; 288 res = 1;
360 289 if (0 !=
361 ret = check (); 290 GNUNET_TESTING_service_run ("test-namestore-api-remove",
362 GNUNET_free (s_signature); 291 "namestore",
363 return ret; 292 "test_namestore_api.conf",
293 &run,
294 NULL))
295 return 1;
296 GNUNET_free_non_null (s_signature);
297 return res;
364} 298}
365 299
366/* end of test_namestore_api.c */ 300/* end of test_namestore_api.c */