2 This file is part of GNUnet.
3 Copyright (C) 2009, 2011, 2014 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file nat/test_nat_test.c
20 * @brief Testcase for NAT testing functions
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_nat_lib.h"
28 * Time to wait before stopping NAT test, in seconds
30 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
35 static struct GNUNET_NAT_Test *tst;
37 static struct GNUNET_SCHEDULER_Task * tsk;
41 report_result (void *cls,
42 enum GNUNET_NAT_StatusCode aret)
44 if (GNUNET_NAT_ERROR_TIMEOUT == aret)
46 "NAT test timed out\n");
47 else if (GNUNET_NAT_ERROR_SUCCESS != aret)
49 "NAT test reported error %d\n", aret);
52 GNUNET_NAT_test_stop (tst);
54 GNUNET_SCHEDULER_cancel (tsk);
60 failed_timeout (void *cls)
64 "NAT test failed to terminate on timeout\n");
66 GNUNET_NAT_test_stop (tst);
72 * Main function run with scheduler.
75 run (void *cls, char *const *args, const char *cfgfile,
76 const struct GNUNET_CONFIGURATION_Handle *cfg)
79 GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT,
82 tsk = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (TIMEOUT,
91 main (int argc, char *const argv[])
93 struct GNUNET_GETOPT_CommandLineOption options[] = {
94 GNUNET_GETOPT_OPTION_END
96 struct GNUNET_OS_Process *gns;
98 char *const argv_prog[] = {
101 "test_nat_test_data.conf",
105 GNUNET_log_setup ("test-nat-test",
109 nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server", GNUNET_NO, NULL);
110 if (GNUNET_SYSERR == nat_res)
112 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
113 "Cannot run NAT test: `%s' file not found\n",
114 "gnunet-nat-server");
118 gns = GNUNET_OS_start_process (GNUNET_YES,
119 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
123 "-c", "test_nat_test_data.conf",
125 GNUNET_assert (NULL != gns);
126 GNUNET_PROGRAM_run (3, argv_prog,
127 "test-nat-test", "nohelp",
130 GNUNET_break (0 == GNUNET_OS_process_kill (gns, GNUNET_TERM_SIG));
131 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns));
132 GNUNET_OS_process_destroy (gns);
135 "NAT test failed to report success\n");
139 /* end of test_nat_test.c */