diff options
Diffstat (limited to 'src/nat/test_nat_test.c')
-rw-r--r-- | src/nat/test_nat_test.c | 133 |
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 | |||
43 | static int ret = 1; | ||
44 | |||
45 | static struct GNUNET_NAT_Test *tst; | ||
46 | |||
47 | static GNUNET_SCHEDULER_TaskIdentifier end; | ||
48 | |||
49 | static void | ||
50 | end_test (void *cls, | ||
51 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
52 | { | ||
53 | GNUNET_NAT_test_stop (tst); | ||
54 | } | ||
55 | |||
56 | static void | ||
57 | report_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 | */ | ||
69 | static void | ||
70 | run (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 | |||
85 | int | ||
86 | main (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 */ | ||