aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-03 12:58:29 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-03 12:58:29 +0000
commit9d99db63729a6143186b9b5b39bdb60e77b19c31 (patch)
treef4a9df7edca1b7528c0d424c40fd9bcd22605a63 /src/gns
parent78c337fc8b8e0d1b35ccd0fad4331a7bde62a9bf (diff)
downloadgnunet-9d99db63729a6143186b9b5b39bdb60e77b19c31.tar.gz
gnunet-9d99db63729a6143186b9b5b39bdb60e77b19c31.zip
- more test
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am4
-rw-r--r--src/gns/test_gns_simple_lookup.c1
-rw-r--r--src/gns/test_gns_simple_mx_lookup.c175
3 files changed, 57 insertions, 123 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 49ae289c4..535adb7ef 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -132,12 +132,12 @@ test_gns_simple_mx_lookup_LDADD = \
132 $(top_builddir)/src/util/libgnunetutil.la \ 132 $(top_builddir)/src/util/libgnunetutil.la \
133 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 133 $(top_builddir)/src/namestore/libgnunetnamestore.la \
134 $(top_builddir)/src/gns/libgnunetgns.la \ 134 $(top_builddir)/src/gns/libgnunetgns.la \
135 $(top_builddir)/src/testing_old/libgnunettesting_old.la 135 $(top_builddir)/src/testing/libgnunettesting.la
136test_gns_simple_mx_lookup_DEPENDENCIES = \ 136test_gns_simple_mx_lookup_DEPENDENCIES = \
137 $(top_builddir)/src/util/libgnunetutil.la \ 137 $(top_builddir)/src/util/libgnunetutil.la \
138 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 138 $(top_builddir)/src/namestore/libgnunetnamestore.la \
139 $(top_builddir)/src/gns/libgnunetgns.la \ 139 $(top_builddir)/src/gns/libgnunetgns.la \
140 $(top_builddir)/src/testing_old/libgnunettesting_old.la 140 $(top_builddir)/src/testing/libgnunettesting.la
141 141
142test_gns_simple_srv_lookup_SOURCES = \ 142test_gns_simple_srv_lookup_SOURCES = \
143 test_gns_simple_srv_lookup.c 143 test_gns_simple_srv_lookup.c
diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c
index 76df1d479..d3c96fd0b 100644
--- a/src/gns/test_gns_simple_lookup.c
+++ b/src/gns/test_gns_simple_lookup.c
@@ -157,6 +157,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 "Failed to connect to GNS!\n"); 158 "Failed to connect to GNS!\n");
159 end_badly_now(); 159 end_badly_now();
160 return;
160 } 161 }
161 162
162 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 163 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
diff --git a/src/gns/test_gns_simple_mx_lookup.c b/src/gns/test_gns_simple_mx_lookup.c
index 8648d3f16..43a939cb5 100644
--- a/src/gns/test_gns_simple_mx_lookup.c
+++ b/src/gns/test_gns_simple_mx_lookup.c
@@ -23,7 +23,7 @@
23 * 23 *
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_testing_lib.h" 26#include "gnunet_testing_lib-new.h"
27#include "gnunet_core_service.h" 27#include "gnunet_core_service.h"
28#include "block_dns.h" 28#include "block_dns.h"
29#include "gnunet_signatures.h" 29#include "gnunet_signatures.h"
@@ -54,12 +54,6 @@
54 54
55/* Globals */ 55/* Globals */
56 56
57/**
58 * Directory to store temp data in, defined in config file
59 */
60static char *test_directory;
61
62static struct GNUNET_TESTING_PeerGroup *pg;
63 57
64/* Task handle to use to schedule test failure */ 58/* Task handle to use to schedule test failure */
65GNUNET_SCHEDULER_TaskIdentifier die_task; 59GNUNET_SCHEDULER_TaskIdentifier die_task;
@@ -73,20 +67,36 @@ static struct GNUNET_GNS_Handle *gns_handle;
73 67
74const struct GNUNET_CONFIGURATION_Handle *cfg; 68const struct GNUNET_CONFIGURATION_Handle *cfg;
75 69
70
76/** 71/**
77 * Check whether peers successfully shut down. 72 * Check if the get_handle is being used, if so stop the request. Either
73 * way, schedule the end_badly_cont function which actually shuts down the
74 * test.
78 */ 75 */
79void 76static void
80shutdown_callback (void *cls, const char *emsg) 77end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81{ 78{
82 if (emsg != NULL) 79 if (NULL != gns_handle)
80 {
81 GNUNET_GNS_disconnect(gns_handle);
82 gns_handle = NULL;
83 }
84
85 if (NULL != namestore_handle)
83 { 86 {
84 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 87 GNUNET_NAMESTORE_disconnect (namestore_handle);
85 if (ok == 0) 88 namestore_handle = NULL;
86 ok = 2;
87 } 89 }
90 GNUNET_break (0);
91 GNUNET_SCHEDULER_shutdown ();
92 ok = 1;
93}
88 94
89 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 95static void
96end_badly_now ()
97{
98 GNUNET_SCHEDULER_cancel (die_task);
99 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
90} 100}
91 101
92static void 102static void
@@ -97,6 +107,12 @@ on_lookup_result(void *cls, uint32_t rd_count,
97 uint16_t mx_preference; 107 uint16_t mx_preference;
98 char* mx; 108 char* mx;
99 109
110 if (GNUNET_SCHEDULER_NO_TASK != die_task)
111 {
112 GNUNET_SCHEDULER_cancel (die_task);
113 die_task = GNUNET_SCHEDULER_NO_TASK;
114 }
115
100 GNUNET_NAMESTORE_disconnect (namestore_handle); 116 GNUNET_NAMESTORE_disconnect (namestore_handle);
101 if (rd_count == 0) 117 if (rd_count == 0)
102 { 118 {
@@ -129,8 +145,9 @@ on_lookup_result(void *cls, uint32_t rd_count,
129 } 145 }
130 146
131 GNUNET_GNS_disconnect(gns_handle); 147 GNUNET_GNS_disconnect(gns_handle);
132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 148 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
133 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 149 GNUNET_SCHEDULER_shutdown ();
150
134} 151}
135 152
136 153
@@ -141,52 +158,25 @@ on_lookup_result(void *cls, uint32_t rd_count,
141static void 158static void
142commence_testing (void *cls, int32_t success, const char *emsg) 159commence_testing (void *cls, int32_t success, const char *emsg)
143{ 160{
144
145 gns_handle = GNUNET_GNS_connect(cfg); 161 gns_handle = GNUNET_GNS_connect(cfg);
146
147 if (NULL == gns_handle) 162 if (NULL == gns_handle)
148 { 163 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "Failed to connect to GNS!\n"); 165 "Failed to connect to GNS!\n");
166 end_badly_now();
167 return;
151 } 168 }
152
153 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_MX, 169 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_MX,
154 GNUNET_NO, 170 GNUNET_NO,
155 NULL, 171 NULL,
156 &on_lookup_result, TEST_DOMAIN); 172 &on_lookup_result, TEST_DOMAIN);
157} 173}
158 174
159/**
160 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
161 * down the peers without freeing memory associated with GET request.
162 */
163static void
164end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165{
166
167 if (pg != NULL)
168 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
169 GNUNET_SCHEDULER_cancel (die_task);
170}
171
172/**
173 * Check if the get_handle is being used, if so stop the request. Either
174 * way, schedule the end_badly_cont function which actually shuts down the
175 * test.
176 */
177static void
178end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
179{
180 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
181 (char *) cls);
182 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
183 ok = 1;
184}
185 175
186static void 176static void
187do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 177do_check (void *cls,
188 const struct GNUNET_CONFIGURATION_Handle *_cfg, 178 const struct GNUNET_CONFIGURATION_Handle *ccfg,
189 struct GNUNET_TESTING_Daemon *d, const char *emsg) 179 struct GNUNET_TESTING_Peer *peer)
190{ 180{
191 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 181 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
192 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; 182 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
@@ -197,16 +187,15 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
197 char* alice_keyfile; 187 char* alice_keyfile;
198 struct GNUNET_TIME_Absolute et; 188 struct GNUNET_TIME_Absolute et;
199 189
200 cfg = _cfg; 190 cfg = ccfg;
201 191 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
202 GNUNET_SCHEDULER_cancel (die_task);
203 192
204 /* put records into namestore */ 193 /* put records into namestore */
205 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 194 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
206 if (NULL == namestore_handle) 195 if (NULL == namestore_handle)
207 { 196 {
208 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 197 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
209 ok = -1; 198 end_badly_now();
210 return; 199 return;
211 } 200 }
212 201
@@ -215,7 +204,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
215 &alice_keyfile)) 204 &alice_keyfile))
216 { 205 {
217 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 206 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
218 ok = -1; 207 end_badly_now();
219 return; 208 return;
220 } 209 }
221 210
@@ -264,9 +253,10 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
264 sig, 253 sig,
265 NULL, 254 NULL,
266 NULL); 255 NULL);
256 GNUNET_free (sig);
267 257
268 rd.data_size = sizeof(struct GNUNET_DNSPARSER_MxRecord)+strlen(TEST_MX_NAME)+1; 258 rd.data_size = sizeof(struct GNUNET_DNSPARSER_MxRecord)+strlen(TEST_MX_NAME)+1;
269 mx_record = GNUNET_malloc(sizeof(uint16_t)+strlen(TEST_MX_NAME)+1); 259 mx_record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_MxRecord)+strlen(TEST_MX_NAME)+1);
270 memcpy(mx_record, &mx_preference, sizeof(uint16_t)); 260 memcpy(mx_record, &mx_preference, sizeof(uint16_t));
271 strcpy(mx_record+sizeof(uint16_t), TEST_MX_NAME); 261 strcpy(mx_record+sizeof(uint16_t), TEST_MX_NAME);
272 rd.data = mx_record; 262 rd.data = mx_record;
@@ -285,73 +275,20 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
285 sig, 275 sig,
286 &commence_testing, 276 &commence_testing,
287 NULL); 277 NULL);
288 GNUNET_free(mx_record);
289 GNUNET_free(mail);
290 GNUNET_free(sig);
291 GNUNET_CRYPTO_rsa_key_free(bob_key);
292 GNUNET_CRYPTO_rsa_key_free(alice_key);
293}
294 278
295static void 279 GNUNET_free (alice_keyfile);
296run (void *cls, char *const *args, const char *cfgfile, 280 GNUNET_free (mx_record);
297 const struct GNUNET_CONFIGURATION_Handle *c) 281 GNUNET_free (mail);
298{ 282 GNUNET_free (sig);
299 cfg = c; 283 GNUNET_CRYPTO_rsa_key_free (bob_key);
300 /* Get path from configuration file */ 284 GNUNET_CRYPTO_rsa_key_free (alice_key);
301 if (GNUNET_YES !=
302 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
303 &test_directory))
304 {
305 ok = 404;
306 return;
307 }
308
309
310 /* Set up a task to end testing if peer start fails */
311 die_task =
312 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
313 "didn't start all daemons in reasonable amount of time!!!");
314
315 /* Start alice */
316 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
317 NULL, NULL, &do_lookup, NULL,
318 NULL, NULL, NULL);
319} 285}
320 286
321static int
322check ()
323{
324 int ret;
325
326 /* Arguments for GNUNET_PROGRAM_run */
327 char *const argv[] = { "test-gns-simple-mx-lookup", /* Name to give running binary */
328 "-c",
329 "test_gns_simple_lookup.conf", /* Config file to use */
330#if VERBOSE
331 "-L", "DEBUG",
332#endif
333 NULL
334 };
335 struct GNUNET_GETOPT_CommandLineOption options[] = {
336 GNUNET_GETOPT_OPTION_END
337 };
338 /* Run the run function as a new program */
339 ret =
340 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
341 "test-gns-simple-mx-lookup", "nohelp", options, &run,
342 &ok);
343 if (ret != GNUNET_OK)
344 {
345 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
346 "`test-gns-simple-mx-lookup': Failed with error code %d\n", ret);
347 }
348 return ok;
349}
350 287
351int 288int
352main (int argc, char *argv[]) 289main (int argc, char *argv[])
353{ 290{
354 int ret; 291 ok = 1;
355 292
356 GNUNET_log_setup ("test-gns-simple-mx-lookup", 293 GNUNET_log_setup ("test-gns-simple-mx-lookup",
357#if VERBOSE 294#if VERBOSE
@@ -360,12 +297,8 @@ main (int argc, char *argv[])
360 "WARNING", 297 "WARNING",
361#endif 298#endif
362 NULL); 299 NULL);
363 ret = check (); 300 GNUNET_TESTING_peer_run ("test-gns-simple-mx-lookup", "test_gns_simple_lookup.conf", &do_check, NULL);
364 /** 301 return ok;
365 * Need to remove base directory, subdirectories taken care
366 * of by the testing framework.
367 */
368 return ret;
369} 302}
370 303
371/* end of test_gns_simple_mx_lookup.c */ 304/* end of test_gns_simple_mx_lookup.c */