2 This file is part of GNUnet.
3 Copyright (C) 2009, 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/>.
19 * @file transport/test_core_api_start_only.c
20 * @brief testcase for core_api.c that only starts two peers,
21 * connects to the core service and shuts down again
22 * @author Christian Grothoff
25 #include "gnunet_arm_service.h"
26 #include "gnunet_core_service.h"
27 #include "gnunet_util_lib.h"
35 struct GNUNET_CONFIGURATION_Handle *cfg;
36 struct GNUNET_CORE_Handle *ch;
37 struct GNUNET_PeerIdentity id;
38 struct GNUNET_OS_Process *arm_proc;
41 static struct PeerContext p1;
43 static struct PeerContext p2;
45 static struct GNUNET_SCHEDULER_Task *timeout_task_id;
51 connect_notify (void *cls,
52 const struct GNUNET_PeerIdentity *peer,
53 struct GNUNET_MQ_Handle *mq)
60 disconnect_notify (void *cls,
61 const struct GNUNET_PeerIdentity *peer,
67 static struct GNUNET_MQ_MessageHandler handlers[] = {
68 GNUNET_MQ_handler_end ()
73 shutdown_task (void *cls)
75 GNUNET_CORE_disconnect (p1.ch);
77 GNUNET_CORE_disconnect (p2.ch);
84 init_notify (void *cls,
85 const struct GNUNET_PeerIdentity *my_identity)
87 struct PeerContext *p = cls;
92 p2.ch = GNUNET_CORE_connect (p2.cfg,
101 GNUNET_assert (p == &p2);
102 GNUNET_SCHEDULER_cancel (timeout_task_id);
103 timeout_task_id = NULL;
104 GNUNET_SCHEDULER_add_now (&shutdown_task,
111 setup_peer (struct PeerContext *p,
116 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
117 p->cfg = GNUNET_CONFIGURATION_create ();
119 GNUNET_OS_start_process (GNUNET_YES,
120 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
123 "gnunet-service-arm",
126 GNUNET_assert (GNUNET_OK ==
127 GNUNET_CONFIGURATION_load (p->cfg,
129 GNUNET_free (binary);
134 timeout_task (void *cls)
141 GNUNET_CORE_disconnect (p1.ch);
146 GNUNET_CORE_disconnect (p2.ch);
157 const struct GNUNET_CONFIGURATION_Handle *cfg)
159 GNUNET_assert (ok == 1);
161 setup_peer (&p1, "test_core_api_peer1.conf");
162 setup_peer (&p2, "test_core_api_peer2.conf");
164 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
165 (GNUNET_TIME_UNIT_MINUTES,
169 p1.ch = GNUNET_CORE_connect (p1.cfg,
179 stop_arm (struct PeerContext *p)
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
183 if (0 != GNUNET_OS_process_kill (p->arm_proc,
185 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
188 GNUNET_OS_process_wait (p->arm_proc))
189 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
192 "ARM process %u stopped\n",
193 (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc));
194 GNUNET_OS_process_destroy (p->arm_proc);
196 GNUNET_CONFIGURATION_destroy (p->cfg);
203 char *const argv[] = {
204 "test-core-api-start-only",
206 "test_core_api_data.conf",
209 struct GNUNET_GETOPT_CommandLineOption options[] = {
210 GNUNET_GETOPT_OPTION_END
212 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
216 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
218 "test-core-api-start-only",
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
237 GNUNET_log_setup ("test-core-api-start-only",
241 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
242 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
246 /* end of test_core_api_start_only.c */