aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/testing_api_cmd_start_peer.c296
-rw-r--r--src/testing/testing_api_cmd_system_create.c14
3 files changed, 15 insertions, 296 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 95fc5c805..868e3fcec 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -16,6 +16,7 @@ lib_LTLIBRARIES = \
16 16
17libgnunettesting_la_SOURCES = \ 17libgnunettesting_la_SOURCES = \
18 testing.c \ 18 testing.c \
19 testing_api_cmd_system_create.c \
19 testing_api_cmd_batch.c \ 20 testing_api_cmd_batch.c \
20 testing_api_cmd_hello_world.c \ 21 testing_api_cmd_hello_world.c \
21 testing_api_cmd_hello_world_birth.c \ 22 testing_api_cmd_hello_world_birth.c \
diff --git a/src/testing/testing_api_cmd_start_peer.c b/src/testing/testing_api_cmd_start_peer.c
deleted file mode 100644
index 0f8c618b8..000000000
--- a/src/testing/testing_api_cmd_start_peer.c
+++ /dev/null
@@ -1,296 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30
31struct StartPeerState
32{
33 /**
34 * Receive callback
35 */
36 struct GNUNET_MQ_MessageHandler *handlers;
37
38 const char *cfgname;
39
40 /**
41 * Peer's configuration
42 */
43 struct GNUNET_CONFIGURATION_Handle *cfg;
44
45 struct GNUNET_TESTING_Peer *peer;
46
47 /**
48 * Peer identity
49 */
50 struct GNUNET_PeerIdentity id;
51
52 /**
53 * Peer's transport service handle
54 */
55 struct GNUNET_TRANSPORT_CoreHandle *th;
56
57 /**
58 * Application handle
59 */
60 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
61
62 /**
63 * Peer's PEERSTORE Handle
64 */
65 struct GNUNET_PEERSTORE_Handle *ph;
66
67 /**
68 * Hello get task
69 */
70 struct GNUNET_SCHEDULER_Task *rh_task;
71
72 /**
73 * Peer's transport get hello handle to retrieve peer's HELLO message
74 */
75 struct GNUNET_PEERSTORE_IterateContext *pic;
76
77 /**
78 * Hello
79 */
80 char *hello;
81
82 /**
83 * Hello size
84 */
85 size_t hello_size;
86
87 char *m;
88
89 char *n;
90
91 unsigned int finished;
92};
93
94
95static void
96retrieve_hello (void *cls);
97
98static void
99hello_iter_cb (void *cb_cls,
100 const struct GNUNET_PEERSTORE_Record *record,
101 const char *emsg)
102{
103 struct StartPeerState *sps = cb_cls;
104 if (NULL == record)
105 {
106 sps->pic = NULL;
107 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, p);
108 return;
109 }
110 // Check record type et al?
111 sps->hello_size = record->value_size;
112 sps->hello = GNUNET_malloc (sps->hello_size);
113 memcpy (sps->hello, record->value, sps->hello_size);
114 p->hello[p->hello_size - 1] = '\0';
115
116 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
117 sps->pic = NULL;
118 sps->finished = GNUNET_YES;
119}
120
121
122static void
123retrieve_hello (void *cls)
124{
125 struct StartPeerState *sps = cls;
126 sps->rh_task = NULL;
127 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
128 "transport",
129 &sps->id,
130 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
131 hello_iter_cb,
132 sps);
133
134}
135
136static int
137start_peer_finish (void *cls,
138 GNUNET_SCHEDULER_TaskCallback cont,
139 void *cont_cls)
140{
141 struct StartPeerState *sps = cls;
142
143 return sps->finished;
144}
145
146
147static void
148start_peer_run (void *cls,
149 const struct GNUNET_TESTING_Command *cmd,
150 struct GNUNET_TESTING_Interpreter *is)
151{
152 struct StartPeerState *sps = cls;
153 char *emsg = NULL;
154 struct GNUNET_PeerIdentity dummy;
155
156 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
157 {
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "File not found: `%s'\n",
160 cfgname);
161 return NULL;
162 }
163
164 if (NULL != handlers)
165 {
166 for (i = 0; NULL != handlers[i].cb; i++)
167 ;
168 sps->handlers = GNUNET_new_array (i + 1,
169 struct GNUNET_MQ_MessageHandler);
170 GNUNET_memcpy (sps->handlers,
171 handlers,
172 i * sizeof(struct GNUNET_MQ_MessageHandler));
173 }
174 sps->cfg = GNUNET_CONFIGURATION_create ();
175 GNUNET_assert (GNUNET_OK ==
176 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
177 if (GNUNET_SYSERR ==
178 GNUNET_TESTING_configuration_create (tl_system,
179 sps->cfg))
180 {
181 LOG (GNUNET_ERROR_TYPE_ERROR,
182 "Testing library failed to create unique configuration based on `%s'\n",
183 sps->cfgname);
184 GNUNET_CONFIGURATION_destroy (sps->cfg);
185 GNUNET_TESTING_interpreter_fail ();
186 }
187
188 sps->peer = GNUNET_TESTING_peer_configure (tth->tl_system,
189 p->cfg,
190 p->no,
191 NULL,
192 &emsg);
193 if (NULL == sps->peer)
194 {
195 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "Testing library failed to create unique configuration based on `%s': `%s'\n",
197 cfgname,
198 emsg);
199 GNUNET_free (emsg);
200 GNUNET_TESTING_interpreter_fail ();
201 }
202
203 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
204 {
205 LOG (GNUNET_ERROR_TYPE_ERROR,
206 "Testing library failed to create unique configuration based on `%s'\n",
207 cfgname);
208 GNUNET_free (emsg);
209 GNUNET_TESTING_interpreter_fail ();
210 }
211
212 memset (&dummy,
213 '\0',
214 sizeof(dummy));
215 GNUNET_TESTING_peer_get_identity (sps->peer,
216 &sps->id);
217 if (0 == memcmp (&dummy,
218 &sps->id,
219 sizeof(struct GNUNET_PeerIdentity)))
220 {
221 LOG (GNUNET_ERROR_TYPE_ERROR,
222 "Testing library failed to obtain peer identity for peer %s_%s\n",
223 p->no);
224 GNUNET_free (emsg);
225 GNUNET_TESTING_interpreter_fail ();
226 }
227 LOG (GNUNET_ERROR_TYPE_DEBUG,
228 "Peer %u configured with identity `%s'\n",
229 p->no,
230 GNUNET_i2s_full (&p->id));
231 sps->th = GNUNET_TRANSPORT_core_connect (p->cfg,
232 NULL,
233 handlers,
234 p,
235 &notify_connect,
236 &notify_disconnect);
237 if (NULL == sps->th)
238 {
239 LOG (GNUNET_ERROR_TYPE_ERROR,
240 "Failed to connect to transport service for peer `%s': `%s'\n",
241 cfgname,
242 emsg);
243 GNUNET_free (emsg);
244 GNUNET_TESTING_interpreter_fail ();
245 }
246 sps->ph = GNUNET_PEERSTORE_connect (p->cfg);
247 if (NULL == sps->th)
248 {
249 LOG (GNUNET_ERROR_TYPE_ERROR,
250 "Failed to connect to peerstore service for peer `%s': `%s'\n",
251 cfgname,
252 emsg);
253 GNUNET_free (emsg);
254 GNUNET_TESTING_interpreter_fail ();
255 }
256 sps->ah = GNUNET_TRANSPORT_application_init (p->cfg);
257 if (NULL == sps->ah)
258 {
259 LOG (GNUNET_ERROR_TYPE_ERROR,
260 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
261 cfgname,
262 emsg);
263 GNUNET_free (emsg);
264 GNUNET_TESTING_interpreter_fail ();
265 }
266 p->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, p);
267}
268
269
270/**
271 * Create command.
272 *
273 * @param label name for command.
274 * @return command.
275 */
276struct GNUNET_TESTING_Command
277GNUNET_TESTING_cmd_start_peer (const char *label,
278 char *m,
279 char *n)
280{
281 struct StartPeerState *sps;
282
283 sps = GNUNET_new (struct StartPeerState);
284 sps->m = m;
285 sps->n = n;
286
287 struct GNUNET_TESTING_Command cmd = {
288 .cls = sps,
289 .label = label,
290 .run = &start_peer_run,
291 .cleanup = &start_peer_cleanup,
292 .traits = &start_peer_traits
293 };
294
295 return cmd;
296}
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index ad0aa4f90..a324940bb 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -26,10 +26,13 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_lib.h"
29 30
30struct TestSystemState 31struct TestSystemState
31{ 32{
32 struct GNUNET_TESTING_System *test_system; 33 struct GNUNET_TESTING_System *test_system;
34
35 const char *testdir;
33}; 36};
34 37
35 38
@@ -83,6 +86,17 @@ GNUNET_TESTING_get_trait_test_system (const struct
83} 86}
84 87
85 88
89static void
90system_create_cleanup (void *cls,
91 const struct GNUNET_TESTING_Command *cmd)
92{
93 struct TestSystemState *tss = cls;
94
95 GNUNET_free (tss->test_system);
96 GNUNET_free (tss);
97}
98
99
86/** 100/**
87 * Create command. 101 * Create command.
88 * 102 *