aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_simple_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c369
1 files changed, 0 insertions, 369 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
deleted file mode 100644
index 154c0abca..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ /dev/null
@@ -1,369 +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 testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_transport_application_service.h"
31#include "transport-testing2.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define BASE_DIR "testdir"
40
41#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
42
43struct TestState
44{
45 /**
46 * Callback to write messages to the master loop.
47 *
48 */
49 TESTING_CMD_HELPER_write_cb write_message;
50
51 /**
52 * The name for a specific test environment directory.
53 *
54 */
55 char *testdir;
56
57 /**
58 * The name for the configuration file of the specific node.
59 *
60 */
61 char *cfgname;
62
63 /**
64 * The complete topology information.
65 */
66 struct GNUNET_TESTING_NetjailTopology *topology;
67};
68
69static struct GNUNET_TESTING_Command block_send;
70
71static struct GNUNET_TESTING_Command block_receive;
72
73static struct GNUNET_TESTING_Command connect_peers;
74
75static struct GNUNET_TESTING_Command local_prepared;
76
77
78/**
79 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
80 * received.
81 *
82 */
83static int
84check_test (void *cls,
85 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
86{
87 return GNUNET_OK;
88}
89
90
91/**
92 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
93 * being received.
94 *
95 */
96static void
97handle_test (void *cls,
98 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
99{
100 const struct GNUNET_TESTING_AsyncContext *ac;
101
102 GNUNET_TESTING_get_trait_async_context (&block_receive,
103 &ac);
104 GNUNET_assert (NULL != ac);
105 if (NULL == ac->cont)
106 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
107 else
108 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
109}
110
111
112/**
113 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
114 *
115 */
116static void
117all_peers_started ()
118{
119 const struct GNUNET_TESTING_AsyncContext *ac;
120
121 GNUNET_TESTING_get_trait_async_context (&block_send,
122 &ac);
123 GNUNET_assert (NULL != ac);
124 if (NULL == ac->cont)
125 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
126 else
127 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
128}
129
130
131/**
132 * Function called with the final result of the test.
133 *
134 * @param cls the `struct MainParams`
135 * @param rv #GNUNET_OK if the test passed
136 */
137static void
138handle_result (void *cls,
139 enum GNUNET_GenericReturnValue rv)
140{
141 struct TestState *ts = cls;
142 struct GNUNET_MessageHeader *reply;
143
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Local test exits with status %d\n",
146 rv);
147 reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
148
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
150 "message prepared\n");
151 ts->write_message (reply,
152 ntohs (reply->size));
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "message send\n");
155 GNUNET_free (ts->testdir);
156 GNUNET_free (ts->cfgname);
157 GNUNET_TESTING_free_topology (ts->topology);
158 GNUNET_free (ts);
159}
160
161
162/**
163 * Callback from start peer cmd for signaling a peer got connected.
164 *
165 */
166static void *
167notify_connect (struct GNUNET_TESTING_Interpreter *is,
168 const struct GNUNET_PeerIdentity *peer)
169{
170 const struct ConnectPeersState *cps;
171 const struct GNUNET_TESTING_Command *cmd;
172
173 cmd = GNUNET_TESTING_interpreter_lookup_command (is,
174 "connect-peers");
175 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd,
176 &cps);
177 void *ret = NULL;
178
179 cps->notify_connect (is,
180 peer);
181 return ret;
182}
183
184
185/**
186 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
187 */
188static void
189all_local_tests_prepared ()
190{
191 const struct LocalPreparedState *lfs;
192
193 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
194 &lfs);
195 GNUNET_assert (NULL != &lfs->ac);
196 if (NULL == lfs->ac.cont)
197 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
198 else
199 GNUNET_TESTING_async_finish ((struct
200 GNUNET_TESTING_AsyncContext *) &lfs->ac);
201}
202
203
204/**
205 * Function to start a local test case.
206 *
207 * @param write_message Callback to send a message to the master loop.
208 * @param router_ip Global address of the network namespace.
209 * @param node_ip Local address of a node i a network namespace.
210 * @param m The number of the node in a network namespace.
211 * @param n The number of the network namespace.
212 * @param local_m The number of nodes in a network namespace.
213 */
214static void
215start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
216 char *node_ip,
217 char *m,
218 char *n,
219 char *local_m,
220 char *topology_data,
221 unsigned int *read_file)
222{
223
224 unsigned int n_int;
225 unsigned int m_int;
226 unsigned int local_m_int;
227 unsigned int num;
228 struct TestState *ts = GNUNET_new (struct TestState);
229 struct GNUNET_TESTING_NetjailTopology *topology;
230
231 if (GNUNET_YES == *read_file)
232 {
233 LOG (GNUNET_ERROR_TYPE_DEBUG,
234 "read from file\n");
235 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
236 }
237 else
238 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
239
240 ts->topology = topology;
241
242 sscanf (m, "%u", &m_int);
243 sscanf (n, "%u", &n_int);
244 sscanf (local_m, "%u", &local_m_int);
245
246 if (0 == n_int)
247 num = m_int;
248 else
249 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
250
251 block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
252 "block");
253 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
254 "block-receive");
255 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
256 "start-peer",
257 "system-create",
258 num,
259 topology,
260 0);
261 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
262 "local-test-prepared",
263 write_message);
264
265
266 GNUNET_asprintf (&ts->cfgname,
267 "test_transport_api2_tcp_node1.conf");
268
269 LOG (GNUNET_ERROR_TYPE_DEBUG,
270 "plugin cfgname: %s\n",
271 ts->cfgname);
272
273 LOG (GNUNET_ERROR_TYPE_DEBUG,
274 "node ip: %s\n",
275 node_ip);
276
277 GNUNET_asprintf (&ts->testdir,
278 "%s%s%s",
279 BASE_DIR,
280 m,
281 n);
282
283 struct GNUNET_MQ_MessageHandler handlers[] = {
284 GNUNET_MQ_hd_var_size (test,
285 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
286 struct GNUNET_TRANSPORT_TESTING_TestMessage,
287 ts),
288 GNUNET_MQ_handler_end ()
289 };
290
291 struct GNUNET_TESTING_Command commands[] = {
292 GNUNET_TESTING_cmd_system_create ("system-create",
293 ts->testdir),
294 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
295 "system-create",
296 num,
297 node_ip,
298 handlers,
299 ts->cfgname,
300 notify_connect,
301 GNUNET_NO),
302 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
303 write_message),
304 block_send,
305 connect_peers,
306 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
307 "start-peer",
308 "system-create",
309 num,
310 topology),
311 block_receive,
312 local_prepared,
313 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
314 "start-peer"),
315 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
316 "system-create"),
317 GNUNET_TESTING_cmd_end ()
318 };
319
320 ts->write_message = write_message;
321
322 GNUNET_TESTING_run (commands,
323 GNUNET_TIME_UNIT_FOREVER_REL,
324 &handle_result,
325 ts);
326
327}
328
329
330/**
331 * Entry point for the plugin.
332 *
333 * @param cls NULL
334 * @return the exported block API
335 */
336void *
337libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
338{
339 struct GNUNET_TESTING_PluginFunctions *api;
340
341 GNUNET_log_setup ("simple-send",
342 "DEBUG",
343 NULL);
344
345 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
346 api->start_testcase = &start_testcase;
347 api->all_peers_started = &all_peers_started;
348 api->all_local_tests_prepared = all_local_tests_prepared;
349 return api;
350}
351
352
353/**
354 * Exit point from the plugin.
355 *
356 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
357 * @return NULL
358 */
359void *
360libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
361{
362 struct GNUNET_TESTING_PluginFunctions *api = cls;
363
364 GNUNET_free (api);
365 return NULL;
366}
367
368
369/* end of plugin_cmd_simple_send.c */