2 This file is part of GNUnet.
3 Copyright (C) 2009, 2011, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file arm/test_arm_api.c
22 * @brief testcase for arm_api.c
25 #include "gnunet_util_lib.h"
26 #include "gnunet_arm_service.h"
27 #include "gnunet_resolver_service.h"
29 #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
33 static const struct GNUNET_CONFIGURATION_Handle *cfg;
35 static struct GNUNET_ARM_Handle *arm;
37 static struct GNUNET_ARM_Operation *op;
45 arm_stop_cb (void *cls,
46 enum GNUNET_ARM_RequestStatus status,
47 enum GNUNET_ARM_Result result)
50 /* (6), a stop request should be sent to ARM successfully */
51 /* ARM should report that it is stopping */
52 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
53 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
54 GNUNET_break (phase == 6);
56 LOG ("Sent 'STOP' request for arm to ARM %s\n",
57 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
59 GNUNET_SCHEDULER_shutdown ();
64 resolver_stop_cb (void *cls,
65 enum GNUNET_ARM_RequestStatus status,
66 enum GNUNET_ARM_Result result)
69 /* (5), a stop request should be sent to ARM successfully.
70 * ARM should report that resolver is stopped.
72 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
73 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
74 GNUNET_break (phase == 5);
75 LOG ("Sent 'STOP' request for resolver to ARM %s\n",
76 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
79 GNUNET_assert (NULL == op);
80 op = GNUNET_ARM_request_service_stop (arm,
88 dns_notify (void *cls,
89 const struct sockaddr *addr,
94 /* (4), resolver should finish resolving localhost */
95 GNUNET_break (phase == 4);
97 LOG ("Finished resolving localhost\n");
100 GNUNET_assert (NULL == op);
101 op = GNUNET_ARM_request_service_stop (arm,
107 /* (3), resolver should resolve localhost */
108 GNUNET_break (phase == 3);
109 LOG ("Resolved localhost\n");
111 GNUNET_break (addr != NULL);
117 resolver_start_cb (void *cls,
118 enum GNUNET_ARM_RequestStatus status,
119 enum GNUNET_ARM_Result result)
122 /* (2), the start request for resolver should be sent successfully
123 * ARM should report that resolver service is starting.
125 GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK);
126 GNUNET_break (phase == 2);
127 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
128 LOG ("Sent 'START' request for resolver to ARM %s\n",
129 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
132 GNUNET_RESOLVER_ip_get ("localhost",
143 if (GNUNET_SYSERR == connected)
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
146 _ ("Fatal error initializing ARM API.\n"));
147 GNUNET_SCHEDULER_shutdown ();
151 if (GNUNET_YES == connected)
153 /* (1), arm connection should be established */
154 LOG ("Connected to ARM\n");
155 GNUNET_break (phase == 1);
157 GNUNET_assert (NULL == op);
158 op = GNUNET_ARM_request_service_start (arm,
160 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
166 /* (7), ARM should stop (we disconnect from it) */
167 LOG ("Disconnected from ARM\n");
168 GNUNET_break (phase == 7);
178 arm_start_cb (void *cls,
179 enum GNUNET_ARM_RequestStatus status,
180 enum GNUNET_ARM_Result result)
183 /* (0) The request should be "sent" successfully
184 * ("sent", because it isn't going anywhere, ARM API starts ARM service
186 * ARM API should report that ARM service is starting.
187 */GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
188 GNUNET_break (phase == 0);
189 LOG ("Sent 'START' request for arm to ARM %s\n",
190 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
192 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
198 do_shutdown (void *cls)
202 GNUNET_ARM_operation_cancel (op);
207 GNUNET_ARM_disconnect (arm);
217 const struct GNUNET_CONFIGURATION_Handle *c)
220 arm = GNUNET_ARM_connect (cfg,
225 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
227 op = GNUNET_ARM_request_service_start (arm,
229 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
236 main (int argc, char *argvx[])
238 char *const argv[] = {
240 "-c", "test_arm_api_data.conf",
243 struct GNUNET_GETOPT_CommandLineOption options[] = {
244 GNUNET_GETOPT_OPTION_END
247 GNUNET_log_setup ("test-arm-api",
250 GNUNET_assert (GNUNET_OK ==
251 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
252 argv, "test-arm-api", "nohelp", options,
258 /* end of test_arm_api.c */