summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-20 18:56:26 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-03-17 15:04:03 +0000
commita2496af71aeed3cd7324fb59d9f32c2d52759d56 (patch)
tree0a9c4b584b8593a49651590dd3b7976a9781782f /auto_tests
parentea7ecd6d3229da0624aaa309f8a5da8a91d77c3e (diff)
Add logging to the onion_test.
Makes debugging easier.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/onion_test.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 128e122b..bd29dcf8 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -160,9 +160,15 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui
160 160
161START_TEST(test_basic) 161START_TEST(test_basic)
162{ 162{
163 uint32_t index[] = { 1, 2, 3 };
164 Logger *log1 = logger_new();
165 logger_callback_log(log1, (logger_cb *)print_debug_log, nullptr, &index[0]);
166 Logger *log2 = logger_new();
167 logger_callback_log(log2, (logger_cb *)print_debug_log, nullptr, &index[1]);
168
163 IP ip = get_loopback(); 169 IP ip = get_loopback();
164 Onion *onion1 = new_onion(new_DHT(nullptr, new_networking(nullptr, ip, 34567), true)); 170 Onion *onion1 = new_onion(new_DHT(log1, new_networking(log1, ip, 34567), true));
165 Onion *onion2 = new_onion(new_DHT(nullptr, new_networking(nullptr, ip, 34568), true)); 171 Onion *onion2 = new_onion(new_DHT(log2, new_networking(log2, ip, 34568), true));
166 ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing."); 172 ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
167 networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2); 173 networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2);
168 174
@@ -247,7 +253,10 @@ START_TEST(test_basic)
247 } 253 }
248 254
249 c_sleep(1000); 255 c_sleep(1000);
250 Onion *onion3 = new_onion(new_DHT(nullptr, new_networking(nullptr, ip, 34569), true)); 256 Logger *log3 = logger_new();
257 logger_callback_log(log3, (logger_cb *)print_debug_log, nullptr, &index[2]);
258
259 Onion *onion3 = new_onion(new_DHT(log3, new_networking(log3, ip, 34569), true));
251 ck_assert_msg((onion3 != nullptr), "Onion failed initializing."); 260 ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
252 261
253 random_nonce(nonce); 262 random_nonce(nonce);
@@ -264,17 +273,18 @@ START_TEST(test_basic)
264 c_sleep(50); 273 c_sleep(50);
265 } 274 }
266 275
267 kill_onion_announce(onion1_a);
268 kill_onion_announce(onion2_a); 276 kill_onion_announce(onion2_a);
277 kill_onion_announce(onion1_a);
269 278
270 { 279 {
271 Onion *onion = onion1; 280 Onion *onion = onion3;
272 281
273 Networking_Core *net = dht_get_net(onion->dht); 282 Networking_Core *net = dht_get_net(onion->dht);
274 DHT *dht = onion->dht; 283 DHT *dht = onion->dht;
275 kill_onion(onion); 284 kill_onion(onion);
276 kill_DHT(dht); 285 kill_DHT(dht);
277 kill_networking(net); 286 kill_networking(net);
287 logger_kill(log3);
278 } 288 }
279 289
280 { 290 {
@@ -285,27 +295,30 @@ START_TEST(test_basic)
285 kill_onion(onion); 295 kill_onion(onion);
286 kill_DHT(dht); 296 kill_DHT(dht);
287 kill_networking(net); 297 kill_networking(net);
298 logger_kill(log2);
288 } 299 }
289 300
290 { 301 {
291 Onion *onion = onion3; 302 Onion *onion = onion1;
292 303
293 Networking_Core *net = dht_get_net(onion->dht); 304 Networking_Core *net = dht_get_net(onion->dht);
294 DHT *dht = onion->dht; 305 DHT *dht = onion->dht;
295 kill_onion(onion); 306 kill_onion(onion);
296 kill_DHT(dht); 307 kill_DHT(dht);
297 kill_networking(net); 308 kill_networking(net);
309 logger_kill(log1);
298 } 310 }
299} 311}
300END_TEST 312END_TEST
301 313
302typedef struct { 314typedef struct {
315 Logger *log;
303 Onion *onion; 316 Onion *onion;
304 Onion_Announce *onion_a; 317 Onion_Announce *onion_a;
305 Onion_Client *onion_c; 318 Onion_Client *onion_c;
306} Onions; 319} Onions;
307 320
308static Onions *new_onions(uint16_t port) 321static Onions *new_onions(uint16_t port, uint32_t *index)
309{ 322{
310 IP ip = get_loopback(); 323 IP ip = get_loopback();
311 ip.ip.v6.uint8[15] = 1; 324 ip.ip.v6.uint8[15] = 1;
@@ -315,17 +328,28 @@ static Onions *new_onions(uint16_t port)
315 return nullptr; 328 return nullptr;
316 } 329 }
317 330
318 Networking_Core *net = new_networking(nullptr, ip, port); 331 on->log = logger_new();
332
333 if (!on->log) {
334 free(on);
335 return nullptr;
336 }
337
338 logger_callback_log(on->log, (logger_cb *)print_debug_log, nullptr, index);
339
340 Networking_Core *net = new_networking(on->log, ip, port);
319 341
320 if (!net) { 342 if (!net) {
343 logger_kill(on->log);
321 free(on); 344 free(on);
322 return nullptr; 345 return nullptr;
323 } 346 }
324 347
325 DHT *dht = new_DHT(nullptr, net, true); 348 DHT *dht = new_DHT(on->log, net, true);
326 349
327 if (!dht) { 350 if (!dht) {
328 kill_networking(net); 351 kill_networking(net);
352 logger_kill(on->log);
329 free(on); 353 free(on);
330 return nullptr; 354 return nullptr;
331 } 355 }
@@ -335,6 +359,7 @@ static Onions *new_onions(uint16_t port)
335 if (!on->onion) { 359 if (!on->onion) {
336 kill_DHT(dht); 360 kill_DHT(dht);
337 kill_networking(net); 361 kill_networking(net);
362 logger_kill(on->log);
338 free(on); 363 free(on);
339 return nullptr; 364 return nullptr;
340 } 365 }
@@ -345,18 +370,20 @@ static Onions *new_onions(uint16_t port)
345 kill_onion(on->onion); 370 kill_onion(on->onion);
346 kill_DHT(dht); 371 kill_DHT(dht);
347 kill_networking(net); 372 kill_networking(net);
373 logger_kill(on->log);
348 free(on); 374 free(on);
349 return nullptr; 375 return nullptr;
350 } 376 }
351 377
352 TCP_Proxy_Info inf = {{{0}}}; 378 TCP_Proxy_Info inf = {{{0}}};
353 on->onion_c = new_onion_client(new_net_crypto(nullptr, dht, &inf)); 379 on->onion_c = new_onion_client(new_net_crypto(on->log, dht, &inf));
354 380
355 if (!on->onion_c) { 381 if (!on->onion_c) {
356 kill_onion_announce(on->onion_a); 382 kill_onion_announce(on->onion_a);
357 kill_onion(on->onion); 383 kill_onion(on->onion);
358 kill_DHT(dht); 384 kill_DHT(dht);
359 kill_networking(net); 385 kill_networking(net);
386 logger_kill(on->log);
360 free(on); 387 free(on);
361 return nullptr; 388 return nullptr;
362 } 389 }
@@ -382,6 +409,7 @@ static void kill_onions(Onions *on)
382 kill_net_crypto(c); 409 kill_net_crypto(c);
383 kill_DHT(dht); 410 kill_DHT(dht);
384 kill_networking(net); 411 kill_networking(net);
412 logger_kill(on->log);
385 free(on); 413 free(on);
386} 414}
387 415
@@ -445,10 +473,12 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
445START_TEST(test_announce) 473START_TEST(test_announce)
446{ 474{
447 uint32_t i, j; 475 uint32_t i, j;
476 uint32_t index[NUM_ONIONS];
448 Onions *onions[NUM_ONIONS]; 477 Onions *onions[NUM_ONIONS];
449 478
450 for (i = 0; i < NUM_ONIONS; ++i) { 479 for (i = 0; i < NUM_ONIONS; ++i) {
451 onions[i] = new_onions(i + 34655); 480 index[i] = i + 1;
481 onions[i] = new_onions(i + 34655, &index[i]);
452 ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i); 482 ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i);
453 } 483 }
454 484