diff options
Diffstat (limited to 'src/nat/test_nat_test.c')
-rw-r--r-- | src/nat/test_nat_test.c | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c index c9479a688..e217c1d29 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file nat/test_nat_test.c | 21 | * @file nat/test_nat_test.c |
22 | * @brief Testcase for NAT testing functions | 22 | * @brief Testcase for NAT testing functions |
@@ -29,7 +29,7 @@ | |||
29 | /** | 29 | /** |
30 | * Time to wait before stopping NAT test, in seconds | 30 | * Time to wait before stopping NAT test, in seconds |
31 | */ | 31 | */ |
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 32 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
33 | 33 | ||
34 | 34 | ||
35 | static int ret = 1; | 35 | static int ret = 1; |
@@ -40,32 +40,32 @@ static struct GNUNET_SCHEDULER_Task * tsk; | |||
40 | 40 | ||
41 | 41 | ||
42 | static void | 42 | static void |
43 | report_result (void *cls, | 43 | report_result(void *cls, |
44 | enum GNUNET_NAT_StatusCode aret) | 44 | enum GNUNET_NAT_StatusCode aret) |
45 | { | 45 | { |
46 | if (GNUNET_NAT_ERROR_TIMEOUT == aret) | 46 | if (GNUNET_NAT_ERROR_TIMEOUT == aret) |
47 | fprintf (stderr, | 47 | fprintf(stderr, |
48 | "NAT test timed out\n"); | 48 | "NAT test timed out\n"); |
49 | else if (GNUNET_NAT_ERROR_SUCCESS != aret) | 49 | else if (GNUNET_NAT_ERROR_SUCCESS != aret) |
50 | fprintf (stderr, | 50 | fprintf(stderr, |
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); | 54 | GNUNET_NAT_test_stop(tst); |
55 | tst = NULL; | 55 | tst = NULL; |
56 | GNUNET_SCHEDULER_cancel (tsk); | 56 | GNUNET_SCHEDULER_cancel(tsk); |
57 | tsk = NULL; | 57 | tsk = NULL; |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static void | 61 | static void |
62 | failed_timeout (void *cls) | 62 | failed_timeout(void *cls) |
63 | { | 63 | { |
64 | tsk = NULL; | 64 | tsk = NULL; |
65 | fprintf (stderr, | 65 | fprintf(stderr, |
66 | "NAT test failed to terminate on timeout\n"); | 66 | "NAT test failed to terminate on timeout\n"); |
67 | ret = 2; | 67 | ret = 2; |
68 | GNUNET_NAT_test_stop (tst); | 68 | GNUNET_NAT_test_stop(tst); |
69 | tst = NULL; | 69 | tst = NULL; |
70 | } | 70 | } |
71 | 71 | ||
@@ -74,23 +74,22 @@ failed_timeout (void *cls) | |||
74 | * Main function run with scheduler. | 74 | * Main function run with scheduler. |
75 | */ | 75 | */ |
76 | static void | 76 | static void |
77 | run (void *cls, char *const *args, const char *cfgfile, | 77 | run(void *cls, char *const *args, const char *cfgfile, |
78 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 78 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
79 | { | 79 | { |
80 | tst = | 80 | tst = |
81 | GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT, | 81 | GNUNET_NAT_test_start(cfg, GNUNET_YES, 1285, 1285, TIMEOUT, |
82 | &report_result, | 82 | &report_result, |
83 | NULL); | 83 | NULL); |
84 | tsk = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (TIMEOUT, | 84 | tsk = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(TIMEOUT, |
85 | 2), | 85 | 2), |
86 | &failed_timeout, | 86 | &failed_timeout, |
87 | NULL); | 87 | NULL); |
88 | |||
89 | } | 88 | } |
90 | 89 | ||
91 | 90 | ||
92 | int | 91 | int |
93 | main (int argc, char *const argv[]) | 92 | main(int argc, char *const argv[]) |
94 | { | 93 | { |
95 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 94 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
96 | GNUNET_GETOPT_OPTION_END | 95 | GNUNET_GETOPT_OPTION_END |
@@ -104,37 +103,37 @@ main (int argc, char *const argv[]) | |||
104 | NULL | 103 | NULL |
105 | }; | 104 | }; |
106 | 105 | ||
107 | GNUNET_log_setup ("test-nat-test", | 106 | GNUNET_log_setup("test-nat-test", |
108 | "WARNING", | 107 | "WARNING", |
109 | NULL); | 108 | NULL); |
110 | 109 | ||
111 | nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server", GNUNET_NO, NULL); | 110 | nat_res = GNUNET_OS_check_helper_binary("gnunet-nat-server", GNUNET_NO, NULL); |
112 | if (GNUNET_SYSERR == nat_res) | 111 | if (GNUNET_SYSERR == nat_res) |
113 | { | 112 | { |
114 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 113 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
115 | "Cannot run NAT test: `%s' file not found\n", | 114 | "Cannot run NAT test: `%s' file not found\n", |
116 | "gnunet-nat-server"); | 115 | "gnunet-nat-server"); |
117 | return 0; | 116 | return 0; |
118 | } | 117 | } |
119 | 118 | ||
120 | gns = GNUNET_OS_start_process (GNUNET_YES, | 119 | gns = GNUNET_OS_start_process(GNUNET_YES, |
121 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 120 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
122 | NULL, NULL, NULL, | 121 | NULL, NULL, NULL, |
123 | "gnunet-nat-server", | 122 | "gnunet-nat-server", |
124 | "gnunet-nat-server", | 123 | "gnunet-nat-server", |
125 | "-c", "test_nat_test_data.conf", | 124 | "-c", "test_nat_test_data.conf", |
126 | "12345", NULL); | 125 | "12345", NULL); |
127 | GNUNET_assert (NULL != gns); | 126 | GNUNET_assert(NULL != gns); |
128 | GNUNET_PROGRAM_run (3, argv_prog, | 127 | GNUNET_PROGRAM_run(3, argv_prog, |
129 | "test-nat-test", "nohelp", | 128 | "test-nat-test", "nohelp", |
130 | options, &run, | 129 | options, &run, |
131 | NULL); | 130 | NULL); |
132 | GNUNET_break (0 == GNUNET_OS_process_kill (gns, GNUNET_TERM_SIG)); | 131 | GNUNET_break(0 == GNUNET_OS_process_kill(gns, GNUNET_TERM_SIG)); |
133 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns)); | 132 | GNUNET_break(GNUNET_OK == GNUNET_OS_process_wait(gns)); |
134 | GNUNET_OS_process_destroy (gns); | 133 | GNUNET_OS_process_destroy(gns); |
135 | if (0 != ret) | 134 | if (0 != ret) |
136 | fprintf (stderr, | 135 | fprintf(stderr, |
137 | "NAT test failed to report success\n"); | 136 | "NAT test failed to report success\n"); |
138 | return ret; | 137 | return ret; |
139 | } | 138 | } |
140 | 139 | ||