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" : "unsuccessfully");
58 GNUNET_SCHEDULER_shutdown();
63 resolver_stop_cb(void *cls,
64 enum GNUNET_ARM_RequestStatus status,
65 enum GNUNET_ARM_Result result)
68 /* (5), a stop request should be sent to ARM successfully.
69 * ARM should report that resolver is stopped.
71 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
72 GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED);
73 GNUNET_break(phase == 5);
74 LOG("Sent 'STOP' request for resolver to ARM %s\n",
75 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
77 GNUNET_assert(NULL == op);
78 op = GNUNET_ARM_request_service_stop(arm,
87 const struct sockaddr *addr,
92 /* (4), resolver should finish resolving localhost */
93 GNUNET_break(phase == 4);
95 LOG("Finished resolving localhost\n");
98 GNUNET_assert(NULL == op);
99 op = GNUNET_ARM_request_service_stop(arm,
105 /* (3), resolver should resolve localhost */
106 GNUNET_break(phase == 3);
107 LOG("Resolved localhost\n");
109 GNUNET_break(addr != NULL);
115 resolver_start_cb(void *cls,
116 enum GNUNET_ARM_RequestStatus status,
117 enum GNUNET_ARM_Result result)
120 /* (2), the start request for resolver should be sent successfully
121 * ARM should report that resolver service is starting.
123 GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK);
124 GNUNET_break(phase == 2);
125 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
126 LOG("Sent 'START' request for resolver to ARM %s\n",
127 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
129 GNUNET_RESOLVER_ip_get("localhost",
140 if (GNUNET_SYSERR == connected)
142 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
143 _("Fatal error initializing ARM API.\n"));
144 GNUNET_SCHEDULER_shutdown();
148 if (GNUNET_YES == connected)
150 /* (1), arm connection should be established */
151 LOG("Connected to ARM\n");
152 GNUNET_break(phase == 1);
154 GNUNET_assert(NULL == op);
155 op = GNUNET_ARM_request_service_start(arm,
157 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
163 /* (7), ARM should stop (we disconnect from it) */
164 LOG("Disconnected from ARM\n");
165 GNUNET_break(phase == 7);
175 arm_start_cb(void *cls,
176 enum GNUNET_ARM_RequestStatus status,
177 enum GNUNET_ARM_Result result)
180 /* (0) The request should be "sent" successfully
181 * ("sent", because it isn't going anywhere, ARM API starts ARM service
183 * ARM API should report that ARM service is starting.
185 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
186 GNUNET_break(phase == 0);
187 LOG("Sent 'START' request for arm to ARM %s\n",
188 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
189 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
195 do_shutdown(void *cls)
199 GNUNET_ARM_operation_cancel(op);
204 GNUNET_ARM_disconnect(arm);
214 const struct GNUNET_CONFIGURATION_Handle *c)
217 arm = GNUNET_ARM_connect(cfg,
222 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
224 op = GNUNET_ARM_request_service_start(arm,
226 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
233 main(int argc, char *argvx[])
235 char *const argv[] = {
237 "-c", "test_arm_api_data.conf",
240 struct GNUNET_GETOPT_CommandLineOption options[] = {
241 GNUNET_GETOPT_OPTION_END
244 GNUNET_log_setup("test-arm-api",
247 GNUNET_assert(GNUNET_OK ==
248 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
249 argv, "test-arm-api", "nohelp", options,
254 /* end of test_arm_api.c */