aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_remove_not_existing_record.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_not_existing_record.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_not_existing_record.c')
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c151
1 files changed, 43 insertions, 108 deletions
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c
index 329602d41..5dfe8e220 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -18,69 +18,51 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file namestore/test_namestore_api.c 21 * @file namestore/test_namestore_api_remove_not_existing_record.c
22 * @brief testcase for namestore_api.c 22 * @brief testcase for namestore_api.c
23 */ 23 */
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_HashCode s_zone; 58static struct GNUNET_HashCode 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,13 +86,13 @@ 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);
@@ -123,19 +100,17 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
123 if (privkey != NULL) 100 if (privkey != NULL)
124 GNUNET_CRYPTO_rsa_key_free (privkey); 101 GNUNET_CRYPTO_rsa_key_free (privkey);
125 privkey = NULL; 102 privkey = NULL;
126
127 if (nsh != NULL) 103 if (nsh != NULL)
128 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 104 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
129 nsh = NULL; 105 nsh = NULL;
130
131 if (NULL != arm)
132 stop_arm();
133} 106}
134 107
135void 108
109static void
136remove_cont (void *cls, int32_t success, const char *emsg) 110remove_cont (void *cls, int32_t success, const char *emsg)
137{ 111{
138 char *name = cls; 112 char *name = cls;
113
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Remove record for `%s': %s `%s'\n", name, (success == GNUNET_YES) ? "SUCCESS" : "FAIL", emsg); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Remove record for `%s': %s `%s'\n", name, (success == GNUNET_YES) ? "SUCCESS" : "FAIL", emsg);
140 if (GNUNET_NO == success) 115 if (GNUNET_NO == success)
141 { 116 {
@@ -149,7 +124,8 @@ remove_cont (void *cls, int32_t success, const char *emsg)
149 GNUNET_SCHEDULER_add_now(&end, NULL); 124 GNUNET_SCHEDULER_add_now(&end, NULL);
150} 125}
151 126
152void 127
128static void
153put_cont (void *cls, int32_t success, const char *emsg) 129put_cont (void *cls, int32_t success, const char *emsg)
154{ 130{
155 char *name = cls; 131 char *name = cls;
@@ -176,53 +152,36 @@ put_cont (void *cls, int32_t success, const char *emsg)
176 } 152 }
177} 153}
178 154
155
179static struct GNUNET_NAMESTORE_RecordData * 156static struct GNUNET_NAMESTORE_RecordData *
180create_record (int count) 157create_record (int count)
181{ 158{
182 int c; 159 int c;
183 struct GNUNET_NAMESTORE_RecordData * rd; 160 struct GNUNET_NAMESTORE_RecordData * rd;
184 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
185 161
162 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
186 for (c = 0; c < RECORDS; c++) 163 for (c = 0; c < RECORDS; c++)
187 { 164 {
188 rd[c].expiration = GNUNET_TIME_absolute_get(); 165 rd[c].expiration = GNUNET_TIME_absolute_get();
189 rd[c].record_type = TEST_RECORD_TYPE; 166 rd[c].record_type = TEST_RECORD_TYPE;
190 rd[c].data_size = TEST_RECORD_DATALEN; 167 rd[c].data_size = TEST_RECORD_DATALEN;
191 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); 168 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
192 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 169 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
193 } 170 }
194
195 return rd; 171 return rd;
196} 172}
197 173
198void
199delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
200{
201 char *afsdir;
202
203 if (GNUNET_OK ==
204 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
205 "FILENAME", &afsdir))
206 {
207 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
208 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
209 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
211 GNUNET_free (afsdir);
212 }
213
214}
215 174
216static void 175static void
217run (void *cls, char *const *args, const char *cfgfile, 176run (void *cls,
218 const struct GNUNET_CONFIGURATION_Handle *cfg) 177 const struct GNUNET_CONFIGURATION_Handle *cfg)
219{ 178{
220 delete_existing_db(cfg); 179 char *hostkey_file;
221 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
222 size_t rd_ser_len; 180 size_t rd_ser_len;
223 181
182 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
183
224 /* load privat key */ 184 /* load privat key */
225 char *hostkey_file;
226 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 185 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
227 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 186 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
@@ -247,53 +206,29 @@ run (void *cls, char *const *args, const char *cfgfile,
247 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); 206 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
248 207
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_h2s_full(&s_zone)); 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_h2s_full(&s_zone));
250
251
252 start_arm (cfgfile);
253 GNUNET_assert (arm != NULL);
254
255 nsh = GNUNET_NAMESTORE_connect (cfg); 209 nsh = GNUNET_NAMESTORE_connect (cfg);
256 GNUNET_break (NULL != nsh); 210 GNUNET_break (NULL != nsh);
257
258 GNUNET_break (s_rd != NULL); 211 GNUNET_break (s_rd != NULL);
259 GNUNET_break (s_name != NULL); 212 GNUNET_break (s_name != NULL);
260
261 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, 213 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
262 GNUNET_TIME_UNIT_FOREVER_ABS, 214 GNUNET_TIME_UNIT_FOREVER_ABS,
263 RECORDS, s_rd, s_signature, put_cont, s_name); 215 RECORDS, s_rd, s_signature, put_cont, s_name);
264
265
266} 216}
267 217
268static int
269check ()
270{
271 static char *const argv[] = { "test-namestore-api",
272 "-c",
273 "test_namestore_api.conf",
274#if VERBOSE
275 "-L", "DEBUG",
276#endif
277 NULL
278 };
279 static struct GNUNET_GETOPT_CommandLineOption options[] = {
280 GNUNET_GETOPT_OPTION_END
281 };
282
283 res = 1;
284 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api",
285 "nohelp", options, &run, &res);
286 return res;
287}
288 218
289int 219int
290main (int argc, char *argv[]) 220main (int argc, char *argv[])
291{ 221{
292 int ret; 222 res = 1;
293 223 if (0 !=
294 ret = check (); 224 GNUNET_TESTING_service_run ("test-namestore-api-remove-not-existing-record",
295 GNUNET_free (s_signature); 225 "namestore",
296 return ret; 226 "test_namestore_api.conf",
227 &run,
228 NULL))
229 return 1;
230 GNUNET_free_non_null (s_signature);
231 return res;
297} 232}
298 233
299/* end of test_namestore_api.c */ 234/* end of test_namestore_api_remove_not_existing_record.c */