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 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.
16 * @file transport/test_core_api_start_only.c
17 * @brief testcase for core_api.c that only starts two peers,
18 * connects to the core service and shuts down again
19 * @author Christian Grothoff
22 #include "gnunet_arm_service.h"
23 #include "gnunet_core_service.h"
24 #include "gnunet_util_lib.h"
32 struct GNUNET_CONFIGURATION_Handle *cfg;
33 struct GNUNET_CORE_Handle *ch;
34 struct GNUNET_PeerIdentity id;
35 struct GNUNET_OS_Process *arm_proc;
38 static struct PeerContext p1;
40 static struct PeerContext p2;
42 static struct GNUNET_SCHEDULER_Task *timeout_task_id;
48 connect_notify (void *cls,
49 const struct GNUNET_PeerIdentity *peer,
50 struct GNUNET_MQ_Handle *mq)
57 disconnect_notify (void *cls,
58 const struct GNUNET_PeerIdentity *peer,
64 static struct GNUNET_MQ_MessageHandler handlers[] = {
65 GNUNET_MQ_handler_end ()
70 shutdown_task (void *cls)
72 GNUNET_CORE_disconnect (p1.ch);
74 GNUNET_CORE_disconnect (p2.ch);
81 init_notify (void *cls,
82 const struct GNUNET_PeerIdentity *my_identity)
84 struct PeerContext *p = cls;
89 p2.ch = GNUNET_CORE_connect (p2.cfg,
98 GNUNET_assert (p == &p2);
99 GNUNET_SCHEDULER_cancel (timeout_task_id);
100 timeout_task_id = NULL;
101 GNUNET_SCHEDULER_add_now (&shutdown_task,
108 setup_peer (struct PeerContext *p,
113 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
114 p->cfg = GNUNET_CONFIGURATION_create ();
116 GNUNET_OS_start_process (GNUNET_YES,
117 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
120 "gnunet-service-arm",
123 GNUNET_assert (GNUNET_OK ==
124 GNUNET_CONFIGURATION_load (p->cfg,
126 GNUNET_free (binary);
131 timeout_task (void *cls)
138 GNUNET_CORE_disconnect (p1.ch);
143 GNUNET_CORE_disconnect (p2.ch);
154 const struct GNUNET_CONFIGURATION_Handle *cfg)
156 GNUNET_assert (ok == 1);
158 setup_peer (&p1, "test_core_api_peer1.conf");
159 setup_peer (&p2, "test_core_api_peer2.conf");
161 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
162 (GNUNET_TIME_UNIT_MINUTES,
166 p1.ch = GNUNET_CORE_connect (p1.cfg,
176 stop_arm (struct PeerContext *p)
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 if (0 != GNUNET_OS_process_kill (p->arm_proc,
182 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
185 GNUNET_OS_process_wait (p->arm_proc))
186 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "ARM process %u stopped\n",
190 (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc));
191 GNUNET_OS_process_destroy (p->arm_proc);
193 GNUNET_CONFIGURATION_destroy (p->cfg);
200 char *const argv[] = {
201 "test-core-api-start-only",
203 "test_core_api_data.conf",
206 struct GNUNET_GETOPT_CommandLineOption options[] = {
207 GNUNET_GETOPT_OPTION_END
209 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
210 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
213 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
215 "test-core-api-start-only",
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 GNUNET_log_setup ("test-core-api-start-only",
238 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
239 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
243 /* end of test_core_api_start_only.c */