aboutsummaryrefslogtreecommitdiff
path: root/src/nat/test_nat_test.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-01 21:30:28 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-01 21:30:28 +0000
commite3f24011c0e95a67d673b43348202b7751574474 (patch)
tree89fff5172468c23f762c3db9c531b3e792da56dc /src/nat/test_nat_test.c
parent490cf7e092613f7c511b46332710187336eb3a6a (diff)
downloadgnunet-e3f24011c0e95a67d673b43348202b7751574474.tar.gz
gnunet-e3f24011c0e95a67d673b43348202b7751574474.zip
testcase for nat test code
Diffstat (limited to 'src/nat/test_nat_test.c')
-rw-r--r--src/nat/test_nat_test.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c
new file mode 100644
index 000000000..3b20a9abd
--- /dev/null
+++ b/src/nat/test_nat_test.c
@@ -0,0 +1,133 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * Testcase for the NAT testing code.
23 *
24 * @file nat/test_nat_test.c
25 * @brief Testcase for NAT testing functions
26 * @author Christian Grothoff
27 */
28#include "platform.h"
29#include "gnunet_common.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_nat_lib.h"
32
33
34#define VERBOSE GNUNET_YES
35
36
37/**
38 * Time to wait before stopping NAT test, in seconds
39 */
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
41
42
43static int ret = 1;
44
45static struct GNUNET_NAT_Test *tst;
46
47static GNUNET_SCHEDULER_TaskIdentifier end;
48
49static void
50end_test (void *cls,
51 const struct GNUNET_SCHEDULER_TaskContext *tc)
52{
53 GNUNET_NAT_test_stop (tst);
54}
55
56static void
57report_success (void *cls,
58 int success)
59{
60 GNUNET_assert (GNUNET_OK == success);
61 ret = 0;
62 GNUNET_SCHEDULER_cancel (end);
63 end = GNUNET_SCHEDULER_add_now (&end_test, NULL);
64}
65
66/**
67 * Main function run with scheduler.
68 */
69static void
70run (void *cls,
71 char *const *args,
72 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
73{
74 tst = GNUNET_NAT_test_start (cfg, GNUNET_YES,
75 1285, 1285,
76 &report_success, NULL);
77 if (NULL == tst)
78 return;
79 end = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
80 &end_test,
81 NULL);
82}
83
84
85int
86main (int argc, char *const argv[])
87{
88 struct GNUNET_GETOPT_CommandLineOption options[] = {
89 GNUNET_GETOPT_OPTION_END
90 };
91 struct GNUNET_OS_Process *gns;
92 char *const argv_prog[] = {
93 "test-nat-test",
94 "-c",
95 "test_nat_test_data.conf",
96 "-L",
97#if VERBOSE
98 "DEBUG",
99#else
100 "WARNING",
101#endif
102 NULL
103 };
104
105 GNUNET_log_setup ("test-nat-test",
106#if VERBOSE
107 "DEBUG",
108#else
109 "WARNING",
110#endif
111 NULL);
112 gns = GNUNET_OS_start_process (NULL, NULL,
113 "gnunet-nat-server",
114 "gnunet-nat-server",
115#if VERBOSE
116 "-L",
117 "DEBUG",
118#endif
119 "12345",
120 NULL);
121 GNUNET_assert (NULL != gns);
122 GNUNET_PROGRAM_run (5, argv_prog,
123 "test-nat-test", "nohelp",
124 options,
125 &run, NULL);
126 GNUNET_break (0 == GNUNET_OS_process_kill (gns, SIGTERM));
127 GNUNET_break (GNUNET_OK ==
128 GNUNET_OS_process_wait (gns));
129 GNUNET_OS_process_close (gns);
130 return ret;
131}
132
133/* end of test_nat_test.c */