2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * Testcase for the NAT testing code.
24 * @file nat/test_nat_test.c
25 * @brief Testcase for NAT testing functions
26 * @author Christian Grothoff
29 #include "gnunet_util_lib.h"
30 #include "gnunet_nat_lib.h"
33 * Time to wait before stopping NAT test, in seconds
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
40 static struct GNUNET_NAT_Test *tst;
43 report_result (void *cls,
44 enum GNUNET_NAT_FailureCode aret)
46 if (GNUNET_NAT_ERROR_TIMEOUT == aret)
48 "NAT test timed out\n");
49 else if (GNUNET_NAT_ERROR_SUCCESS != aret)
51 "NAT test reported error %d\n", aret);
58 * Main function run with scheduler.
61 run (void *cls, char *const *args, const char *cfgfile,
62 const struct GNUNET_CONFIGURATION_Handle *cfg)
65 GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT,
72 main (int argc, char *const argv[])
74 struct GNUNET_GETOPT_CommandLineOption options[] = {
75 GNUNET_GETOPT_OPTION_END
77 struct GNUNET_OS_Process *gns;
79 char *const argv_prog[] = {
82 "test_nat_test_data.conf",
86 GNUNET_log_setup ("test-nat-test",
90 nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server", GNUNET_NO, NULL);
91 if (GNUNET_SYSERR == nat_res)
93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
94 "Cannot run NAT test: `%s' file not found\n",
99 gns = GNUNET_OS_start_process (GNUNET_YES,
100 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
104 "-c", "test_nat_test_data.conf",
106 GNUNET_assert (NULL != gns);
107 GNUNET_PROGRAM_run (3, argv_prog, "test-nat-test", "nohelp", options, &run,
109 GNUNET_break (0 == GNUNET_OS_process_kill (gns, GNUNET_TERM_SIG));
110 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns));
111 GNUNET_OS_process_destroy (gns);
114 "NAT test failed to report success\n");
118 /* end of test_nat_test.c */