diff options
Diffstat (limited to 'src/arm/test_arm_api.c')
-rw-r--r-- | src/arm/test_arm_api.c | 241 |
1 files changed, 121 insertions, 120 deletions
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index f851595b0..84d6f1bfd 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.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 arm/test_arm_api.c | 21 | * @file arm/test_arm_api.c |
22 | * @brief testcase for arm_api.c | 22 | * @brief testcase for arm_api.c |
@@ -26,9 +26,9 @@ | |||
26 | #include "gnunet_arm_service.h" | 26 | #include "gnunet_arm_service.h" |
27 | #include "gnunet_resolver_service.h" | 27 | #include "gnunet_resolver_service.h" |
28 | 28 | ||
29 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 29 | #define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
30 | 30 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
32 | 32 | ||
33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
34 | 34 | ||
@@ -42,139 +42,139 @@ static int phase = 0; | |||
42 | 42 | ||
43 | 43 | ||
44 | static void | 44 | static void |
45 | arm_stop_cb (void *cls, | 45 | arm_stop_cb(void *cls, |
46 | enum GNUNET_ARM_RequestStatus status, | 46 | enum GNUNET_ARM_RequestStatus status, |
47 | enum GNUNET_ARM_Result result) | 47 | enum GNUNET_ARM_Result result) |
48 | { | 48 | { |
49 | op = NULL; | 49 | op = NULL; |
50 | /* (6), a stop request should be sent to ARM successfully */ | 50 | /* (6), a stop request should be sent to ARM successfully */ |
51 | /* ARM should report that it is stopping */ | 51 | /* ARM should report that it is stopping */ |
52 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 52 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
53 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 53 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); |
54 | GNUNET_break (phase == 6); | 54 | GNUNET_break(phase == 6); |
55 | phase++; | 55 | phase++; |
56 | LOG ("Sent 'STOP' request for arm to ARM %s\n", | 56 | LOG("Sent 'STOP' request for arm to ARM %s\n", |
57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
58 | GNUNET_SCHEDULER_shutdown (); | 58 | GNUNET_SCHEDULER_shutdown(); |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | static void | 62 | static void |
63 | resolver_stop_cb (void *cls, | 63 | resolver_stop_cb(void *cls, |
64 | enum GNUNET_ARM_RequestStatus status, | 64 | enum GNUNET_ARM_RequestStatus status, |
65 | enum GNUNET_ARM_Result result) | 65 | enum GNUNET_ARM_Result result) |
66 | { | 66 | { |
67 | op = NULL; | 67 | op = NULL; |
68 | /* (5), a stop request should be sent to ARM successfully. | 68 | /* (5), a stop request should be sent to ARM successfully. |
69 | * ARM should report that resolver is stopped. | 69 | * ARM should report that resolver is stopped. |
70 | */ | 70 | */ |
71 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 71 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
72 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 72 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); |
73 | GNUNET_break (phase == 5); | 73 | GNUNET_break(phase == 5); |
74 | LOG ("Sent 'STOP' request for resolver to ARM %s\n", | 74 | LOG("Sent 'STOP' request for resolver to ARM %s\n", |
75 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 75 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
76 | phase++; | 76 | phase++; |
77 | GNUNET_assert (NULL == op); | 77 | GNUNET_assert(NULL == op); |
78 | op = GNUNET_ARM_request_service_stop (arm, | 78 | op = GNUNET_ARM_request_service_stop(arm, |
79 | "arm", | 79 | "arm", |
80 | &arm_stop_cb, | 80 | &arm_stop_cb, |
81 | NULL); | 81 | NULL); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void | 85 | static void |
86 | dns_notify (void *cls, | 86 | dns_notify(void *cls, |
87 | const struct sockaddr *addr, | 87 | const struct sockaddr *addr, |
88 | socklen_t addrlen) | 88 | socklen_t addrlen) |
89 | { | 89 | { |
90 | if (addr == NULL) | 90 | if (addr == NULL) |
91 | { | 91 | { |
92 | /* (4), resolver should finish resolving localhost */ | 92 | /* (4), resolver should finish resolving localhost */ |
93 | GNUNET_break (phase == 4); | 93 | GNUNET_break(phase == 4); |
94 | phase++; | 94 | phase++; |
95 | LOG ("Finished resolving localhost\n"); | 95 | LOG("Finished resolving localhost\n"); |
96 | if (ok != 0) | 96 | if (ok != 0) |
97 | ok = 2; | 97 | ok = 2; |
98 | GNUNET_assert (NULL == op); | 98 | GNUNET_assert(NULL == op); |
99 | op = GNUNET_ARM_request_service_stop (arm, | 99 | op = GNUNET_ARM_request_service_stop(arm, |
100 | "resolver", | 100 | "resolver", |
101 | &resolver_stop_cb, | 101 | &resolver_stop_cb, |
102 | NULL); | 102 | NULL); |
103 | return; | 103 | return; |
104 | } | 104 | } |
105 | /* (3), resolver should resolve localhost */ | 105 | /* (3), resolver should resolve localhost */ |
106 | GNUNET_break (phase == 3); | 106 | GNUNET_break(phase == 3); |
107 | LOG ("Resolved localhost\n"); | 107 | LOG("Resolved localhost\n"); |
108 | phase++; | 108 | phase++; |
109 | GNUNET_break (addr != NULL); | 109 | GNUNET_break(addr != NULL); |
110 | ok = 0; | 110 | ok = 0; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static void | 114 | static void |
115 | resolver_start_cb (void *cls, | 115 | resolver_start_cb(void *cls, |
116 | enum GNUNET_ARM_RequestStatus status, | 116 | enum GNUNET_ARM_RequestStatus status, |
117 | enum GNUNET_ARM_Result result) | 117 | enum GNUNET_ARM_Result result) |
118 | { | 118 | { |
119 | op = NULL; | 119 | op = NULL; |
120 | /* (2), the start request for resolver should be sent successfully | 120 | /* (2), the start request for resolver should be sent successfully |
121 | * ARM should report that resolver service is starting. | 121 | * ARM should report that resolver service is starting. |
122 | */ | 122 | */ |
123 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); | 123 | GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK); |
124 | GNUNET_break (phase == 2); | 124 | GNUNET_break(phase == 2); |
125 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 125 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); |
126 | LOG ("Sent 'START' request for resolver to ARM %s\n", | 126 | LOG("Sent 'START' request for resolver to ARM %s\n", |
127 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 127 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
128 | phase++; | 128 | phase++; |
129 | GNUNET_RESOLVER_ip_get ("localhost", | 129 | GNUNET_RESOLVER_ip_get("localhost", |
130 | AF_INET, | 130 | AF_INET, |
131 | TIMEOUT, | 131 | TIMEOUT, |
132 | &dns_notify, NULL); | 132 | &dns_notify, NULL); |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | static void | 136 | static void |
137 | arm_conn (void *cls, | 137 | arm_conn(void *cls, |
138 | int connected) | 138 | int connected) |
139 | { | 139 | { |
140 | if (GNUNET_SYSERR == connected) | 140 | if (GNUNET_SYSERR == connected) |
141 | { | 141 | { |
142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
143 | _("Fatal error initializing ARM API.\n")); | 143 | _("Fatal error initializing ARM API.\n")); |
144 | GNUNET_SCHEDULER_shutdown (); | 144 | GNUNET_SCHEDULER_shutdown(); |
145 | GNUNET_assert (0); | 145 | GNUNET_assert(0); |
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | if (GNUNET_YES == connected) | 148 | if (GNUNET_YES == connected) |
149 | { | 149 | { |
150 | /* (1), arm connection should be established */ | 150 | /* (1), arm connection should be established */ |
151 | LOG ("Connected to ARM\n"); | 151 | LOG("Connected to ARM\n"); |
152 | GNUNET_break (phase == 1); | 152 | GNUNET_break(phase == 1); |
153 | phase++; | 153 | phase++; |
154 | GNUNET_assert (NULL == op); | 154 | GNUNET_assert(NULL == op); |
155 | op = GNUNET_ARM_request_service_start (arm, | 155 | op = GNUNET_ARM_request_service_start(arm, |
156 | "resolver", | 156 | "resolver", |
157 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 157 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
158 | &resolver_start_cb, | 158 | &resolver_start_cb, |
159 | NULL); | 159 | NULL); |
160 | } | 160 | } |
161 | else | 161 | else |
162 | { | 162 | { |
163 | /* (7), ARM should stop (we disconnect from it) */ | 163 | /* (7), ARM should stop (we disconnect from it) */ |
164 | LOG ("Disconnected from ARM\n"); | 164 | LOG("Disconnected from ARM\n"); |
165 | GNUNET_break (phase == 7); | 165 | GNUNET_break(phase == 7); |
166 | if (phase != 7) | 166 | if (phase != 7) |
167 | ok = 3; | 167 | ok = 3; |
168 | else if (ok == 1) | 168 | else if (ok == 1) |
169 | ok = 0; | 169 | ok = 0; |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | static void | 174 | static void |
175 | arm_start_cb (void *cls, | 175 | arm_start_cb(void *cls, |
176 | enum GNUNET_ARM_RequestStatus status, | 176 | enum GNUNET_ARM_RequestStatus status, |
177 | enum GNUNET_ARM_Result result) | 177 | enum GNUNET_ARM_Result result) |
178 | { | 178 | { |
179 | op = NULL; | 179 | op = NULL; |
180 | /* (0) The request should be "sent" successfully | 180 | /* (0) The request should be "sent" successfully |
@@ -182,55 +182,55 @@ arm_start_cb (void *cls, | |||
182 | * by itself). | 182 | * by itself). |
183 | * ARM API should report that ARM service is starting. | 183 | * ARM API should report that ARM service is starting. |
184 | */ | 184 | */ |
185 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 185 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
186 | GNUNET_break (phase == 0); | 186 | GNUNET_break(phase == 0); |
187 | LOG ("Sent 'START' request for arm to ARM %s\n", | 187 | LOG("Sent 'START' request for arm to ARM %s\n", |
188 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 188 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
189 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 189 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); |
190 | phase++; | 190 | phase++; |
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | static void | 194 | static void |
195 | do_shutdown (void *cls) | 195 | do_shutdown(void *cls) |
196 | { | 196 | { |
197 | if (NULL != op) | 197 | if (NULL != op) |
198 | { | 198 | { |
199 | GNUNET_ARM_operation_cancel (op); | 199 | GNUNET_ARM_operation_cancel(op); |
200 | op = NULL; | 200 | op = NULL; |
201 | } | 201 | } |
202 | if (NULL != arm) | 202 | if (NULL != arm) |
203 | { | 203 | { |
204 | GNUNET_ARM_disconnect (arm); | 204 | GNUNET_ARM_disconnect(arm); |
205 | arm = NULL; | 205 | arm = NULL; |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | static void | 210 | static void |
211 | task (void *cls, | 211 | task(void *cls, |
212 | char *const *args, | 212 | char *const *args, |
213 | const char *cfgfile, | 213 | const char *cfgfile, |
214 | const struct GNUNET_CONFIGURATION_Handle *c) | 214 | const struct GNUNET_CONFIGURATION_Handle *c) |
215 | { | 215 | { |
216 | cfg = c; | 216 | cfg = c; |
217 | arm = GNUNET_ARM_connect (cfg, | 217 | arm = GNUNET_ARM_connect(cfg, |
218 | &arm_conn, | 218 | &arm_conn, |
219 | NULL); | 219 | NULL); |
220 | if (NULL == arm) | 220 | if (NULL == arm) |
221 | return; | 221 | return; |
222 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 222 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
223 | NULL); | 223 | NULL); |
224 | op = GNUNET_ARM_request_service_start (arm, | 224 | op = GNUNET_ARM_request_service_start(arm, |
225 | "arm", | 225 | "arm", |
226 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 226 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
227 | &arm_start_cb, | 227 | &arm_start_cb, |
228 | NULL); | 228 | NULL); |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | int | 232 | int |
233 | main (int argc, char *argvx[]) | 233 | main(int argc, char *argvx[]) |
234 | { | 234 | { |
235 | char *const argv[] = { | 235 | char *const argv[] = { |
236 | "test-arm-api", | 236 | "test-arm-api", |
@@ -240,13 +240,14 @@ main (int argc, char *argvx[]) | |||
240 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 240 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
241 | GNUNET_GETOPT_OPTION_END | 241 | GNUNET_GETOPT_OPTION_END |
242 | }; | 242 | }; |
243 | GNUNET_log_setup ("test-arm-api", | 243 | |
244 | "WARNING", | 244 | GNUNET_log_setup("test-arm-api", |
245 | NULL); | 245 | "WARNING", |
246 | GNUNET_assert (GNUNET_OK == | 246 | NULL); |
247 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 247 | GNUNET_assert(GNUNET_OK == |
248 | argv, "test-arm-api", "nohelp", options, | 248 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
249 | &task, NULL)); | 249 | argv, "test-arm-api", "nohelp", options, |
250 | &task, NULL)); | ||
250 | return ok; | 251 | return ok; |
251 | } | 252 | } |
252 | 253 | ||