2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
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 START_ARM GNUNET_YES
33 #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1500)
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
37 static const struct GNUNET_CONFIGURATION_Handle *cfg;
39 static struct GNUNET_ARM_Handle *arm;
46 arm_stop_cb (void *cls,
47 enum GNUNET_ARM_RequestStatus status,
48 const char *servicename,
49 enum GNUNET_ARM_Result result)
51 /* (6), a stop request should be sent to ARM successfully */
52 /* ARM should report that it is stopping */
53 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
54 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
55 GNUNET_break (phase == 6);
57 LOG ("Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
62 resolver_stop_cb (void *cls,
63 enum GNUNET_ARM_RequestStatus status,
64 const char *servicename, enum GNUNET_ARM_Result result)
66 /* (5), a stop request should be sent to ARM successfully.
67 * ARM should report that resolver is stopped.
69 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
70 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
71 GNUNET_break (phase == 5);
72 LOG ("Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
75 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL);
77 arm_stop_cb (NULL, GNUNET_ARM_STATUS_SENT_OK, "arm", GNUNET_ARM_SERVICE_STOPPING);
78 arm_conn (NULL, GNUNET_NO);
84 dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
88 /* (4), resolver should finish resolving localhost */
89 GNUNET_break (phase == 4);
91 LOG ("Finished resolving localhost\n");
94 GNUNET_ARM_request_service_stop (arm, "resolver", TIMEOUT, resolver_stop_cb, NULL);
97 /* (3), resolver should resolve localhost */
98 GNUNET_break (phase == 3);
99 LOG ("Resolved localhost\n");
101 GNUNET_break (addr != NULL);
107 resolver_start_cb (void *cls,
108 enum GNUNET_ARM_RequestStatus status,
109 const char *servicename,
110 enum GNUNET_ARM_Result result)
112 /* (2), the start request for resolver should be sent successfully
113 * ARM should report that resolver service is starting.
115 GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK);
116 GNUNET_break (phase == 2);
117 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
118 LOG ("Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
120 GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
125 trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
127 GNUNET_ARM_disconnect_and_free ((struct GNUNET_ARM_Handle *) cls);
135 if (GNUNET_SYSERR == connected)
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
138 _("Fatal error initializing ARM API.\n"));
139 GNUNET_SCHEDULER_shutdown ();
143 if (GNUNET_YES == connected)
145 /* (1), arm connection should be established */
146 LOG ("Connected to ARM\n");
147 GNUNET_break (phase == 1);
149 GNUNET_ARM_request_service_start (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, resolver_start_cb, NULL);
153 /* (7), ARM should stop (we disconnect from it) */
154 LOG ("Disconnected from ARM\n");
155 GNUNET_break (phase == 7);
160 GNUNET_SCHEDULER_add_now (trigger_disconnect, arm);
166 arm_start_cb (void *cls,
167 enum GNUNET_ARM_RequestStatus status,
168 const char *servicename,
169 enum GNUNET_ARM_Result result)
171 /* (0) The request should be "sent" successfully
172 * ("sent", because it isn't going anywhere, ARM API starts ARM service
174 * ARM API should report that ARM service is starting.
176 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
177 GNUNET_break (phase == 0);
178 LOG ("Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
179 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
185 task (void *cls, char *const *args, const char *cfgfile,
186 const struct GNUNET_CONFIGURATION_Handle *c)
193 GNUNET_CONFIGURATION_get_value_filename (cfg, "arm", "CONFIG",
196 GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle
197 *) cfg, "arm", "CONFIG",
201 GNUNET_free (armconfig);
203 arm = GNUNET_ARM_connect (cfg, &arm_conn, NULL);
207 GNUNET_ARM_request_service_start (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL);
209 arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_STARTING);
210 arm_conn (NULL, arm, GNUNET_YES);
216 main (int argc, char *argvx[])
218 char *const argv[] = {
220 "-c", "test_arm_api_data.conf",
223 struct GNUNET_GETOPT_CommandLineOption options[] = {
224 GNUNET_GETOPT_OPTION_END
226 GNUNET_log_setup ("test-arm-api",
229 GNUNET_assert (GNUNET_OK ==
230 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
231 argv, "test-arm-api", "nohelp", options,
236 /* end of test_arm_api.c */