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_lookup.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_lookup.c')
-rw-r--r-- | src/namestore/test_namestore_api_lookup.c | 150 |
1 files changed, 43 insertions, 107 deletions
diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c index 818e7108d..1cf9ec864 100644 --- a/src/namestore/test_namestore_api_lookup.c +++ b/src/namestore/test_namestore_api_lookup.c | |||
@@ -24,59 +24,41 @@ | |||
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 | #define VERBOSE GNUNET_NO |
31 | 32 | ||
32 | #define RECORDS 5 | 33 | #define RECORDS 5 |
34 | |||
33 | #define TEST_RECORD_TYPE 1234 | 35 | #define TEST_RECORD_TYPE 1234 |
36 | |||
34 | #define TEST_RECORD_DATALEN 123 | 37 | #define TEST_RECORD_DATALEN 123 |
38 | |||
35 | #define TEST_RECORD_DATA 'a' | 39 | #define TEST_RECORD_DATA 'a' |
36 | 40 | ||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 41 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
38 | 42 | ||
43 | |||
39 | static struct GNUNET_NAMESTORE_Handle * nsh; | 44 | static struct GNUNET_NAMESTORE_Handle * nsh; |
40 | 45 | ||
41 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 46 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
42 | static struct GNUNET_OS_Process *arm; | ||
43 | 47 | ||
44 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 48 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
49 | |||
45 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 50 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
46 | struct GNUNET_CRYPTO_RsaSignature *s_signature; | 51 | |
52 | static struct GNUNET_CRYPTO_RsaSignature *s_signature; | ||
53 | |||
47 | static struct GNUNET_CRYPTO_ShortHashCode s_zone; | 54 | static struct GNUNET_CRYPTO_ShortHashCode s_zone; |
48 | struct GNUNET_NAMESTORE_RecordData *s_rd; | ||
49 | static char *s_name; | ||
50 | 55 | ||
56 | static struct GNUNET_NAMESTORE_RecordData *s_rd; | ||
51 | 57 | ||
58 | static char *s_name; | ||
52 | 59 | ||
53 | static int res; | 60 | static int res; |
54 | 61 | ||
55 | static void | ||
56 | start_arm (const char *cfgname) | ||
57 | { | ||
58 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
59 | "gnunet-service-arm", "-c", cfgname, | ||
60 | #if VERBOSE_PEERS | ||
61 | "-L", "DEBUG", | ||
62 | #else | ||
63 | "-L", "ERROR", | ||
64 | #endif | ||
65 | NULL); | ||
66 | } | ||
67 | |||
68 | static void | ||
69 | stop_arm () | ||
70 | { | ||
71 | if (NULL != arm) | ||
72 | { | ||
73 | if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) | ||
74 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
75 | GNUNET_OS_process_wait (arm); | ||
76 | GNUNET_OS_process_destroy (arm); | ||
77 | arm = NULL; | ||
78 | } | ||
79 | } | ||
80 | 62 | ||
81 | /** | 63 | /** |
82 | * Re-establish the connection to the service. | 64 | * Re-establish the connection to the service. |
@@ -90,14 +72,9 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
90 | if (nsh != NULL) | 72 | if (nsh != NULL) |
91 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 73 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
92 | nsh = NULL; | 74 | nsh = NULL; |
93 | |||
94 | if (privkey != NULL) | 75 | if (privkey != NULL) |
95 | GNUNET_CRYPTO_rsa_key_free (privkey); | 76 | GNUNET_CRYPTO_rsa_key_free (privkey); |
96 | privkey = NULL; | 77 | privkey = NULL; |
97 | |||
98 | if (NULL != arm) | ||
99 | stop_arm(); | ||
100 | |||
101 | res = 1; | 78 | res = 1; |
102 | } | 79 | } |
103 | 80 | ||
@@ -105,36 +82,33 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
105 | static void | 82 | static void |
106 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 83 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
107 | { | 84 | { |
85 | int c; | ||
86 | |||
108 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 87 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) |
109 | { | 88 | { |
110 | GNUNET_SCHEDULER_cancel (endbadly_task); | 89 | GNUNET_SCHEDULER_cancel (endbadly_task); |
111 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 90 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
112 | } | 91 | } |
113 | |||
114 | int c; | ||
115 | for (c = 0; c < RECORDS; c++) | 92 | for (c = 0; c < RECORDS; c++) |
116 | GNUNET_free_non_null((void *) s_rd[c].data); | 93 | GNUNET_free_non_null((void *) s_rd[c].data); |
117 | GNUNET_free (s_rd); | 94 | GNUNET_free (s_rd); |
118 | |||
119 | if (privkey != NULL) | 95 | if (privkey != NULL) |
120 | GNUNET_CRYPTO_rsa_key_free (privkey); | 96 | GNUNET_CRYPTO_rsa_key_free (privkey); |
121 | privkey = NULL; | 97 | privkey = NULL; |
122 | |||
123 | if (nsh != NULL) | 98 | if (nsh != NULL) |
124 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 99 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
125 | nsh = NULL; | 100 | nsh = NULL; |
126 | |||
127 | if (NULL != arm) | ||
128 | stop_arm(); | ||
129 | } | 101 | } |
130 | 102 | ||
131 | void name_lookup_proc (void *cls, | 103 | |
132 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 104 | static void |
133 | struct GNUNET_TIME_Absolute expire, | 105 | name_lookup_proc (void *cls, |
134 | const char *n, | 106 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
135 | unsigned int rd_count, | 107 | struct GNUNET_TIME_Absolute expire, |
136 | const struct GNUNET_NAMESTORE_RecordData *rd, | 108 | const char *n, |
137 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 109 | unsigned int rd_count, |
110 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
111 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
138 | { | 112 | { |
139 | static int found = GNUNET_NO; | 113 | static int found = GNUNET_NO; |
140 | int c; | 114 | int c; |
@@ -146,22 +120,18 @@ void name_lookup_proc (void *cls, | |||
146 | { | 120 | { |
147 | GNUNET_break (0); | 121 | GNUNET_break (0); |
148 | } | 122 | } |
149 | |||
150 | if (0 != memcmp (signature, s_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature))) | 123 | if (0 != memcmp (signature, s_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature))) |
151 | { | 124 | { |
152 | GNUNET_break (0); | 125 | GNUNET_break (0); |
153 | } | 126 | } |
154 | |||
155 | if (0 != strcmp(n, s_name)) | 127 | if (0 != strcmp(n, s_name)) |
156 | { | 128 | { |
157 | GNUNET_break (0); | 129 | GNUNET_break (0); |
158 | } | 130 | } |
159 | |||
160 | if (RECORDS != rd_count) | 131 | if (RECORDS != rd_count) |
161 | { | 132 | { |
162 | GNUNET_break (0); | 133 | GNUNET_break (0); |
163 | } | 134 | } |
164 | |||
165 | for (c = 0; c < RECORDS; c++) | 135 | for (c = 0; c < RECORDS; c++) |
166 | { | 136 | { |
167 | if (GNUNET_NO == GNUNET_NAMESTORE_records_cmp (&rd[c], &s_rd[c])) | 137 | if (GNUNET_NO == GNUNET_NAMESTORE_records_cmp (&rd[c], &s_rd[c])) |
@@ -184,7 +154,8 @@ void name_lookup_proc (void *cls, | |||
184 | GNUNET_SCHEDULER_add_now(&end, NULL); | 154 | GNUNET_SCHEDULER_add_now(&end, NULL); |
185 | } | 155 | } |
186 | 156 | ||
187 | void | 157 | |
158 | static void | ||
188 | put_cont (void *cls, int32_t success, const char *emsg) | 159 | put_cont (void *cls, int32_t success, const char *emsg) |
189 | { | 160 | { |
190 | char * name = cls; | 161 | char * name = cls; |
@@ -203,6 +174,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
203 | } | 174 | } |
204 | } | 175 | } |
205 | 176 | ||
177 | |||
206 | static struct GNUNET_NAMESTORE_RecordData * | 178 | static struct GNUNET_NAMESTORE_RecordData * |
207 | create_record (int count) | 179 | create_record (int count) |
208 | { | 180 | { |
@@ -212,43 +184,25 @@ create_record (int count) | |||
212 | 184 | ||
213 | for (c = 0; c < RECORDS; c++) | 185 | for (c = 0; c < RECORDS; c++) |
214 | { | 186 | { |
215 | rd[c].expiration = GNUNET_TIME_absolute_get(); | 187 | rd[c].expiration = GNUNET_TIME_absolute_get(); |
216 | rd[c].record_type = TEST_RECORD_TYPE; | 188 | rd[c].record_type = TEST_RECORD_TYPE; |
217 | rd[c].data_size = TEST_RECORD_DATALEN; | 189 | rd[c].data_size = TEST_RECORD_DATALEN; |
218 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 190 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); |
219 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 191 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); |
220 | } | 192 | } |
221 | 193 | ||
222 | return rd; | 194 | return rd; |
223 | } | 195 | } |
224 | 196 | ||
225 | void | ||
226 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
227 | { | ||
228 | char *afsdir; | ||
229 | |||
230 | if (GNUNET_OK == | ||
231 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
232 | "FILENAME", &afsdir)) | ||
233 | { | ||
234 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
235 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
236 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
238 | GNUNET_free (afsdir); | ||
239 | } | ||
240 | |||
241 | } | ||
242 | 197 | ||
243 | static void | 198 | static void |
244 | run (void *cls, char *const *args, const char *cfgfile, | 199 | run (void *cls, |
245 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 200 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
246 | { | 201 | { |
247 | delete_existing_db(cfg); | ||
248 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | ||
249 | |||
250 | size_t rd_ser_len; | 202 | size_t rd_ser_len; |
251 | 203 | ||
204 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | ||
205 | |||
252 | /* load privat key from file not included in zonekey dir */ | 206 | /* load privat key from file not included in zonekey dir */ |
253 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("test_hostkey"); | 207 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("test_hostkey"); |
254 | GNUNET_assert (privkey != NULL); | 208 | GNUNET_assert (privkey != NULL); |
@@ -268,9 +222,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
268 | 222 | ||
269 | /* create random zone hash */ | 223 | /* create random zone hash */ |
270 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | 224 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); |
271 | start_arm (cfgfile); | ||
272 | GNUNET_assert (arm != NULL); | ||
273 | |||
274 | nsh = GNUNET_NAMESTORE_connect (cfg); | 225 | nsh = GNUNET_NAMESTORE_connect (cfg); |
275 | GNUNET_break (NULL != nsh); | 226 | GNUNET_break (NULL != nsh); |
276 | 227 | ||
@@ -283,35 +234,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
283 | } | 234 | } |
284 | 235 | ||
285 | 236 | ||
286 | static int | 237 | int |
287 | check () | 238 | main (int argc, char *argv[]) |
288 | { | 239 | { |
289 | static char *const argv[] = { "test-namestore-api", | ||
290 | "-c", | ||
291 | "test_namestore_api.conf", | ||
292 | #if VERBOSE | ||
293 | "-L", "DEBUG", | ||
294 | #endif | ||
295 | NULL | ||
296 | }; | ||
297 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
298 | GNUNET_GETOPT_OPTION_END | ||
299 | }; | ||
300 | |||
301 | res = 1; | 240 | res = 1; |
302 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api", | 241 | if (0 != |
303 | "nohelp", options, &run, &res); | 242 | GNUNET_TESTING_service_run ("test-namestore-api-lookup", |
243 | "namestore", | ||
244 | "test_namestore_api.conf", | ||
245 | &run, | ||
246 | NULL)) | ||
247 | return 1; | ||
248 | GNUNET_free_non_null (s_signature); | ||
304 | return res; | 249 | return res; |
305 | } | 250 | } |
306 | 251 | ||
307 | int | ||
308 | main (int argc, char *argv[]) | ||
309 | { | ||
310 | int ret; | ||
311 | |||
312 | ret = check (); | ||
313 | GNUNET_free (s_signature); | ||
314 | return ret; | ||
315 | } | ||
316 | 252 | ||
317 | /* end of test_namestore_api.c */ | 253 | /* end of test_namestore_api.c */ |