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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file transport/test_core_api_start_only.c
22 * @brief testcase for core_api.c that only starts two peers,
23 * connects to the core service and shuts down again
24 * @author Christian Grothoff
27 #include "gnunet_arm_service.h"
28 #include "gnunet_core_service.h"
29 #include "gnunet_util_lib.h"
37 struct GNUNET_CONFIGURATION_Handle *cfg;
38 struct GNUNET_CORE_Handle *ch;
39 struct GNUNET_PeerIdentity id;
40 struct GNUNET_OS_Process *arm_proc;
43 static struct PeerContext p1;
45 static struct PeerContext p2;
47 static struct GNUNET_SCHEDULER_Task *timeout_task_id;
53 connect_notify (void *cls,
54 const struct GNUNET_PeerIdentity *peer,
55 struct GNUNET_MQ_Handle *mq)
62 disconnect_notify (void *cls,
63 const struct GNUNET_PeerIdentity *peer,
69 static struct GNUNET_MQ_MessageHandler handlers[] = {
70 GNUNET_MQ_handler_end ()
75 shutdown_task (void *cls)
77 GNUNET_CORE_disconnecT (p1.ch);
79 GNUNET_CORE_disconnecT (p2.ch);
86 init_notify (void *cls,
87 const struct GNUNET_PeerIdentity *my_identity)
89 struct PeerContext *p = cls;
94 p2.ch = GNUNET_CORE_connecT (p2.cfg,
103 GNUNET_assert (p == &p2);
104 GNUNET_SCHEDULER_cancel (timeout_task_id);
105 timeout_task_id = NULL;
106 GNUNET_SCHEDULER_add_now (&shutdown_task,
113 setup_peer (struct PeerContext *p,
118 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
119 p->cfg = GNUNET_CONFIGURATION_create ();
121 GNUNET_OS_start_process (GNUNET_YES,
122 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
125 "gnunet-service-arm",
128 GNUNET_assert (GNUNET_OK ==
129 GNUNET_CONFIGURATION_load (p->cfg,
131 GNUNET_free (binary);
136 timeout_task (void *cls)
143 GNUNET_CORE_disconnecT (p1.ch);
148 GNUNET_CORE_disconnecT (p2.ch);
159 const struct GNUNET_CONFIGURATION_Handle *cfg)
161 GNUNET_assert (ok == 1);
163 setup_peer (&p1, "test_core_api_peer1.conf");
164 setup_peer (&p2, "test_core_api_peer2.conf");
166 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
167 (GNUNET_TIME_UNIT_MINUTES,
171 p1.ch = GNUNET_CORE_connecT (p1.cfg,
181 stop_arm (struct PeerContext *p)
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 if (0 != GNUNET_OS_process_kill (p->arm_proc,
187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
190 GNUNET_OS_process_wait (p->arm_proc))
191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "ARM process %u stopped\n",
195 (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc));
196 GNUNET_OS_process_destroy (p->arm_proc);
198 GNUNET_CONFIGURATION_destroy (p->cfg);
205 char *const argv[] = {
206 "test-core-api-start-only",
208 "test_core_api_data.conf",
211 struct GNUNET_GETOPT_CommandLineOption options[] = {
212 GNUNET_GETOPT_OPTION_END
214 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
215 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
218 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
220 "test-core-api-start-only",
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 GNUNET_log_setup ("test-core-api-start-only",
243 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
244 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
248 /* end of test_core_api_start_only.c */