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.c229
1 files changed, 0 insertions, 229 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 07255a1a5..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ /dev/null
@@ -1,229 +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_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40/**
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
45
46/**
47 * The name for the configuration file of the specific node.
48 *
49 */
50char *cfgname;
51
52/**
53 * Flag indicating if all peers have been started.
54 *
55 */
56unsigned int are_all_peers_started;
57
58/**
59 * Flag indicating a received message.
60 */
61unsigned int message_received;
62
63
64/**
65 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
66 * received.
67 *
68 */
69static int
70check_test (void *cls,
71 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
72{
73 return GNUNET_OK;
74}
75
76
77/**
78 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
79 * being received.
80 *
81 */
82static void
83handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{
86 message_received = GNUNET_YES;
87}
88
89
90/**
91 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
92 *
93 */
94static void
95all_peers_started ()
96{
97 are_all_peers_started = GNUNET_YES;
98}
99
100
101/**
102 * Function to start a local test case.
103 *
104 * @param write_message Callback to send a message to the master loop.
105 * @param router_ip Global address of the network namespace.
106 * @param node_ip Local address of a node i a network namespace.
107 * @param m The number of the node in a network namespace.
108 * @param n The number of the network namespace.
109 * @param local_m The number of nodes in a network namespace.
110 */
111static void
112start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
113 char *node_ip,
114 char *m,
115 char *n,
116 char *local_m)
117{
118
119 GNUNET_asprintf (&cfgname,
120 "test_transport_api2_tcp_node%s.conf",
121 "1");
122
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "plugin cfgname: %s\n",
125 cfgname);
126
127 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "node ip: %s\n",
129 node_ip);
130
131 LOG (GNUNET_ERROR_TYPE_ERROR,
132 "m: %s n: %s\n",
133 m,
134 n);
135
136 GNUNET_asprintf (&testdir,
137 "%s%s%s",
138 BASE_DIR,
139 m,
140 n);
141
142 struct GNUNET_MQ_MessageHandler handlers[] = {
143 GNUNET_MQ_hd_var_size (test,
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
145 struct GNUNET_TRANSPORT_TESTING_TestMessage,
146 NULL),
147 GNUNET_MQ_handler_end ()
148 };
149
150 struct GNUNET_TESTING_Command commands[] = {
151 GNUNET_TESTING_cmd_system_create ("system-create",
152 testdir),
153 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
154 "system-create",
155 m,
156 n,
157 local_m,
158 node_ip,
159 handlers,
160 cfgname),
161 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
162 write_message),
163 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
164 &are_all_peers_started),
165 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
166 "start-peer",
167 "system-create",
168 (atoi (n) - 1) * atoi (local_m) + atoi (
169 m)),
170 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
171 m,
172 n,
173 (atoi (n) - 1) * atoi (local_m) + atoi (
174 m),
175 "start-peer"),
176 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
177 &message_received),
178 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
179 "start-peer"),
180 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
181 "system-create"),
182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
183 write_message)
184 };
185
186 GNUNET_TESTING_run (NULL,
187 commands,
188 GNUNET_TIME_UNIT_FOREVER_REL);
189
190}
191
192
193/**
194 * Entry point for the plugin.
195 *
196 * @param cls NULL
197 * @return the exported block API
198 */
199void *
200libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
201{
202 struct GNUNET_TESTING_PluginFunctions *api;
203
204 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
205 api->start_testcase = &start_testcase;
206 api->all_peers_started = &all_peers_started;
207 return api;
208}
209
210
211/**
212 * Exit point from the plugin.
213 *
214 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
215 * @return NULL
216 */
217void *
218libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
219{
220 struct GNUNET_TESTING_PluginFunctions *api = cls;
221
222 GNUNET_free (api);
223 GNUNET_free (testdir);
224 GNUNET_free (cfgname);
225 return NULL;
226}
227
228
229/* end of plugin_cmd_simple_send.c */