aboutsummaryrefslogtreecommitdiff
path: root/src/nat
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-01 09:57:57 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-01 09:57:57 +0000
commit80a4a7ad18d013dd02ab53ec71d5d9edbb690b61 (patch)
tree5b37cdd1a25bfeeac1d5d17e6ff3a272a904babf /src/nat
parent21309bc4672041b0ae505dfed2e5665d16d89599 (diff)
downloadgnunet-80a4a7ad18d013dd02ab53ec71d5d9edbb690b61.tar.gz
gnunet-80a4a7ad18d013dd02ab53ec71d5d9edbb690b61.zip
-fix nat test timeout/termination issue
Diffstat (limited to 'src/nat')
-rw-r--r--src/nat/nat_test.c6
-rw-r--r--src/nat/test_nat_test.c34
2 files changed, 33 insertions, 7 deletions
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index 179b6b171..b96ee60ed 100644
--- a/src/nat/nat_test.c
+++ b/src/nat/nat_test.c
@@ -440,8 +440,10 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
440 nh->status = GNUNET_NAT_ERROR_SUCCESS; 440 nh->status = GNUNET_NAT_ERROR_SUCCESS;
441 if (0 == bnd_port) 441 if (0 == bnd_port)
442 { 442 {
443 nh->nat = 443 nh->nat
444 GNUNET_NAT_register (cfg, is_tcp, 0, 0, NULL, NULL, &addr_cb, 444 = GNUNET_NAT_register (cfg, is_tcp, 0, 0,
445 NULL, NULL,
446 &addr_cb,
445 &reversal_cb, nh); 447 &reversal_cb, nh);
446 } 448 }
447 else 449 else
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c
index e86f2ed11..d32015b56 100644
--- a/src/nat/test_nat_test.c
+++ b/src/nat/test_nat_test.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2011, 2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -17,10 +17,7 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 * Testcase for the NAT testing code.
23 *
24 * @file nat/test_nat_test.c 21 * @file nat/test_nat_test.c
25 * @brief Testcase for NAT testing functions 22 * @brief Testcase for NAT testing functions
26 * @author Christian Grothoff 23 * @author Christian Grothoff
@@ -39,6 +36,9 @@ static int ret = 1;
39 36
40static struct GNUNET_NAT_Test *tst; 37static struct GNUNET_NAT_Test *tst;
41 38
39static GNUNET_SCHEDULER_TaskIdentifier tsk;
40
41
42static void 42static void
43report_result (void *cls, 43report_result (void *cls,
44 enum GNUNET_NAT_StatusCode aret) 44 enum GNUNET_NAT_StatusCode aret)
@@ -51,6 +51,23 @@ report_result (void *cls,
51 "NAT test reported error %d\n", aret); 51 "NAT test reported error %d\n", aret);
52 else 52 else
53 ret = 0; 53 ret = 0;
54 GNUNET_NAT_test_stop (tst);
55 tst = NULL;
56 GNUNET_SCHEDULER_cancel (tsk);
57 tsk = GNUNET_SCHEDULER_NO_TASK;
58}
59
60
61static void
62failed_timeout (void *cls,
63 const struct GNUNET_SCHEDULER_TaskContext *tc)
64{
65 tsk = GNUNET_SCHEDULER_NO_TASK;
66 fprintf (stderr,
67 "NAT test failed to terminate on timeout\n");
68 ret = 2;
69 GNUNET_NAT_test_stop (tst);
70 tst = NULL;
54} 71}
55 72
56 73
@@ -65,6 +82,11 @@ run (void *cls, char *const *args, const char *cfgfile,
65 GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT, 82 GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT,
66 &report_result, 83 &report_result,
67 NULL); 84 NULL);
85 tsk = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (TIMEOUT,
86 2),
87 &failed_timeout,
88 NULL);
89
68} 90}
69 91
70 92
@@ -104,7 +126,9 @@ main (int argc, char *const argv[])
104 "-c", "test_nat_test_data.conf", 126 "-c", "test_nat_test_data.conf",
105 "12345", NULL); 127 "12345", NULL);
106 GNUNET_assert (NULL != gns); 128 GNUNET_assert (NULL != gns);
107 GNUNET_PROGRAM_run (3, argv_prog, "test-nat-test", "nohelp", options, &run, 129 GNUNET_PROGRAM_run (3, argv_prog,
130 "test-nat-test", "nohelp",
131 options, &run,
108 NULL); 132 NULL);
109 GNUNET_break (0 == GNUNET_OS_process_kill (gns, GNUNET_TERM_SIG)); 133 GNUNET_break (0 == GNUNET_OS_process_kill (gns, GNUNET_TERM_SIG));
110 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns)); 134 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns));