aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3serakt <t3ss@posteo.de>2024-04-10 20:00:57 +0200
committert3serakt <t3ss@posteo.de>2024-04-10 20:15:00 +0200
commit447673694f1bc2992734125424181d46e48f6087 (patch)
tree47065dc5d53f72373972726331f0bf923c58ce7a
parentd70237cfe915c12360e3a618ecb30c9bdb0aa0f3 (diff)
downloadgnunet-dev/t3ss/probnat.tar.gz
gnunet-dev/t3ss/probnat.zip
Added test case to start Android SDK emulator.dev/t3ss/probnat
-rw-r--r--scripts/Makefile.am4
-rw-r--r--scripts/testing-ng/emu_run.sh19
-rw-r--r--src/service/core/Makefile.am20
-rw-r--r--src/service/core/test_core_plugin_cmd_run_emu.c346
-rw-r--r--src/service/core/test_core_run_emu_topo.conf8
5 files changed, 395 insertions, 2 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index f714cdc84..3f154da55 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -9,7 +9,8 @@ dist_pkgdata_DATA = \
9 netjail/netjail_start.sh \ 9 netjail/netjail_start.sh \
10 netjail/netjail_stop.sh \ 10 netjail/netjail_stop.sh \
11 netjail/topo.sh \ 11 netjail/topo.sh \
12 testing-ng/block.sh 12 testing-ng/block.sh \
13 testing-ng/emu_run.sh
13 14
14EXTRA_DIST = \ 15EXTRA_DIST = \
15 get_version.sh \ 16 get_version.sh \
@@ -30,5 +31,6 @@ install-data-hook:
30 chmod o+x '$(DESTDIR)$(pkgdatadir)/netjail_exec.sh' 31 chmod o+x '$(DESTDIR)$(pkgdatadir)/netjail_exec.sh'
31 chmod o+x '$(DESTDIR)$(pkgdatadir)/topo.sh' 32 chmod o+x '$(DESTDIR)$(pkgdatadir)/topo.sh'
32 chmod o+x '$(DESTDIR)$(pkgdatadir)/block.sh' 33 chmod o+x '$(DESTDIR)$(pkgdatadir)/block.sh'
34 chmod o+x '$(DESTDIR)$(pkgdatadir)/emu_run.sh'
33 35
34## EOF 36## EOF
diff --git a/scripts/testing-ng/emu_run.sh b/scripts/testing-ng/emu_run.sh
new file mode 100644
index 000000000..1ef63e9d3
--- /dev/null
+++ b/scripts/testing-ng/emu_run.sh
@@ -0,0 +1,19 @@
1if [ "$1" != "" ];then
2 # echo arg: $1 > /tmp/emu_run_$1.log
3 $(/home/t3sserakt/Android/Sdk/platform-tools/adb start-server)
4 echo 1 > /tmp/emu_run_$1.log
5 $(/home/t3sserakt/Android/Sdk/emulator/emulator -no-window -avd $1) & #>> /tmp/emu_run_$1.log
6 echo 2 >> /tmp/emu_run_$1.log
7 $(/home/t3sserakt/Android/Sdk/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;') #>> /tmp/emu_run_$1.log
8 echo 3 >> /tmp/emu_run_$1.log
9 $(/home/t3sserakt/Android/Sdk/platform-tools/adb forward tcp:5000 tcp:5000) #>> /tmp/emu_run_$1.log
10 $(/home/t3sserakt/Android/Sdk/platform-tools/adb forward --list >> /tmp/emu_run_$1.log)
11 echo 4 >> /tmp/emu_run_$1.log
12 $(/home/t3sserakt/Android/Sdk/platform-tools/adb shell am start -n com.example.androidserver/.MainActivity) #>> /tmp/emu_run_$1.log
13 echo 5 >> /tmp/emu_run_$1.log
14 sleep 300
15 echo 6 >> /tmp/emu_run_$1.log
16 $(/home/t3sserakt/Android/Sdk/platform-tools/adb emu kill) #>> /tmp/emu_run_$1.log
17 echo 7 >> /tmp/emu_run_$1.log
18 $(/home/t3sserakt/Android/Sdk/platform-tools/adb kill-server)
19fi
diff --git a/src/service/core/Makefile.am b/src/service/core/Makefile.am
index 220da838f..1925645f8 100644
--- a/src/service/core/Makefile.am
+++ b/src/service/core/Makefile.am
@@ -16,7 +16,8 @@ if USE_COVERAGE
16endif 16endif
17 17
18plugin_LTLIBRARIES = \ 18plugin_LTLIBRARIES = \
19 libgnunet_test_core_plugin_cmd_just_run.la 19 libgnunet_test_core_plugin_cmd_just_run.la \
20 libgnunet_test_core_plugin_cmd_run_emu.la
20 21
21TESTING_LIBS = \ 22TESTING_LIBS = \
22 libgnunetcoretesting.la 23 libgnunetcoretesting.la
@@ -35,6 +36,23 @@ libgnunetcore_la_LDFLAGS = \
35 $(GN_LIB_LDFLAGS) \ 36 $(GN_LIB_LDFLAGS) \
36 -version-info 0:1:0 37 -version-info 0:1:0
37 38
39libgnunet_test_core_plugin_cmd_run_emu_la_SOURCES = \
40 test_core_plugin_cmd_run_emu.c
41libgnunet_test_core_plugin_cmd_run_emu_la_LIBADD = \
42 libgnunetcoretesting.la \
43 $(top_builddir)/src/service/transport/libgnunettransportapplication.la \
44 $(top_builddir)/src/service/transport/libgnunettransportcore.la \
45 $(top_builddir)/src/lib/hello/libgnunethello.la \
46 $(top_builddir)/src/service/peerstore/libgnunetpeerstore.la \
47 $(top_builddir)/src/service/transport/libgnunettransporttesting2.la \
48 $(top_builddir)/src/service/testing/libgnunettesting.la \
49 $(top_builddir)/src/service/statistics/libgnunetstatistics.la \
50 $(top_builddir)/src/service/arm/libgnunetarm.la \
51 $(top_builddir)/src/lib/util/libgnunetutil.la \
52 $(LTLIBINTL)
53libgnunet_test_core_plugin_cmd_run_emu_la_LDFLAGS = \
54 $(GN_PLUGIN_LDFLAGS)
55
38libgnunet_test_core_plugin_cmd_just_run_la_SOURCES = \ 56libgnunet_test_core_plugin_cmd_just_run_la_SOURCES = \
39 test_core_plugin_cmd_just_run.c 57 test_core_plugin_cmd_just_run.c
40libgnunet_test_core_plugin_cmd_just_run_la_LIBADD = \ 58libgnunet_test_core_plugin_cmd_just_run_la_LIBADD = \
diff --git a/src/service/core/test_core_plugin_cmd_run_emu.c b/src/service/core/test_core_plugin_cmd_run_emu.c
new file mode 100644
index 000000000..6d06c14f1
--- /dev/null
+++ b/src/service/core/test_core_plugin_cmd_run_emu.c
@@ -0,0 +1,346 @@
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_barrier.h"
28#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_transport_application_service.h"
31#include "gnunet_transport_core_service.h"
32#include "gnunet_testing_barrier.h"
33#include "gnunet_core_service.h"
34#include "gnunet_transport_testing_ng_lib.h"
35#include "gnunet_core_testing_lib.h"
36
37/**
38 * Generic logging shortcut
39 */
40#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
41
42#define BASE_DIR "testdir"
43
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
45
46#define MAX_RECEIVED 1000
47
48#define MESSAGE_SIZE 65000
49
50static struct GNUNET_TESTING_Command block_script;
51
52static struct GNUNET_TESTING_Command emu_run_script;
53
54static struct GNUNET_TESTING_Interpreter *is;
55
56struct TestState
57{
58 /**
59 * Callback to write messages to the master loop.
60 *
61 */
62 GNUNET_TESTING_cmd_helper_write_cb write_message;
63
64 /**
65 * Callback to notify the helper test case has finished.
66 */
67 GNUNET_TESTING_cmd_helper_finish_cb finished_cb;
68
69 /**
70 * The name for a specific test environment directory.
71 *
72 */
73 char *testdir;
74
75 /**
76 * The name for the configuration file of the specific node.
77 *
78 */
79 char *cfgname;
80
81 /**
82 * The complete topology information.
83 */
84 struct GNUNET_TESTING_NetjailTopology *topology;
85};
86
87struct Sender
88{
89 /**
90 * Number of received messages from sender.
91 */
92 unsigned long long num_received;
93
94 /**
95 * Sample mean time the message traveled.
96 */
97 struct GNUNET_TIME_Relative mean_time;
98
99 /**
100 * Time the first message was send.
101 */
102 struct GNUNET_TIME_Absolute time_first;
103};
104
105
106struct GNUNET_TESTING_BarrierList*
107get_waiting_for_barriers ()
108{
109 struct GNUNET_TESTING_BarrierList*barriers;
110 struct GNUNET_TESTING_BarrierListEntry *ble;
111
112 barriers = GNUNET_new (struct GNUNET_TESTING_BarrierList);
113 ble = GNUNET_new (struct GNUNET_TESTING_BarrierListEntry);
114 ble->barrier_name = "ready-to-connect";
115 ble->expected_reaches = 1;
116 GNUNET_CONTAINER_DLL_insert (barriers->head,
117 barriers->tail,
118 ble);
119
120 ble = GNUNET_new (struct GNUNET_TESTING_BarrierListEntry);
121 ble->barrier_name = "test-case-finished";
122 ble->expected_reaches = 1;
123 GNUNET_CONTAINER_DLL_insert (barriers->head,
124 barriers->tail,
125 ble);
126 return barriers;
127}
128
129
130/**
131 * Function called with the final result of the test.
132 *
133 * @param cls the `struct MainParams`
134 * @param rv #GNUNET_OK if the test passed
135 */
136static void
137handle_result (void *cls,
138 enum GNUNET_GenericReturnValue rv)
139{
140 struct TestState *ts = cls;
141
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 "Local test exits with status %d\n",
144 rv);
145
146 ts->finished_cb (rv);
147 GNUNET_free (ts->testdir);
148 GNUNET_free (ts->cfgname);
149 GNUNET_TESTING_free_topology (ts->topology);
150 GNUNET_free (ts);
151}
152
153
154static void
155child_completed_callback (void *cls,
156 enum GNUNET_OS_ProcessStatusType type,
157 long unsigned int exit_code)
158{
159
160}
161
162
163/**
164 * Function to start a local test case.
165 *
166 * @param write_message Callback to send a message to the master loop.
167 * @param router_ip Global address of the network namespace.
168 * @param node_ip The IP address of the node.
169 * @param m The number of the node in a network namespace.
170 * @param n The number of the network namespace.
171 * @param local_m The number of nodes in a network namespace.
172 * @param topology_data A file name for the file containing the topology configuration, or a string containing
173 * the topology configuration.
174 * @param read_file If read_file is GNUNET_YES this string is the filename for the topology configuration,
175 * if read_file is GNUNET_NO the string contains the topology configuration.
176 * @param finish_cb Callback function which writes a message from the helper process running on a netjail
177 * node to the master process * signaling that the test case running on the netjail node finished.
178 * @return Returns the struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node.
179 */
180static struct GNUNET_TESTING_Interpreter *
181start_testcase (GNUNET_TESTING_cmd_helper_write_cb write_message,
182 const char *router_ip,
183 const char *node_ip,
184 const char *m,
185 const char *n,
186 const char *local_m,
187 const char *topology_data,
188 unsigned int *read_file,
189 GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
190{
191
192 unsigned int n_int;
193 unsigned int m_int;
194 unsigned int local_m_int;
195 unsigned int num;
196 struct TestState *ts = GNUNET_new (struct TestState);
197 struct GNUNET_TESTING_NetjailTopology *topology;
198 unsigned int sscanf_ret = 0;
199 char **argv = NULL;
200 int argc = 0;
201 char **argv_emu = NULL;
202 int argc_emu = 0;
203
204 ts->finished_cb = finished_cb;
205 LOG (GNUNET_ERROR_TYPE_ERROR,
206 "n %s m %s\n",
207 n,
208 m);
209
210 if (GNUNET_YES == *read_file)
211 {
212 LOG (GNUNET_ERROR_TYPE_DEBUG,
213 "read from file\n");
214 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
215 }
216 else
217 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
218
219 ts->topology = topology;
220
221 errno = 0;
222 sscanf_ret = sscanf (m, "%u", &m_int);
223 if (errno != 0)
224 {
225 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
226 }
227 GNUNET_assert (0 < sscanf_ret);
228 errno = 0;
229 sscanf_ret = sscanf (n, "%u", &n_int);
230 if (errno != 0)
231 {
232 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
233 }
234 GNUNET_assert (0 < sscanf_ret);
235 errno = 0;
236 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
237 if (errno != 0)
238 {
239 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
240 }
241 GNUNET_assert (0 < sscanf_ret);
242
243 if (0 == n_int)
244 num = m_int;
245 else
246 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
247
248 block_script = GNUNET_TESTING_cmd_block_until_external_trigger (
249 "block-script");
250
251 GNUNET_asprintf (&ts->cfgname,
252 "test_core_just_run.conf");
253
254 if (1 == n_int)
255 {
256 LOG (GNUNET_ERROR_TYPE_DEBUG,
257 "Is n_int 1: %u\n",
258 n_int);
259 GNUNET_array_append (argv_emu, argc_emu, "Pixel_6a_API_31");
260 }
261 else if (0 != n_int)
262 {
263 LOG (GNUNET_ERROR_TYPE_DEBUG,
264 "Is n_int not 0: %u\n",
265 n_int);
266 GNUNET_array_append (argv_emu, argc_emu, "Pixel_6a_API_31_II");
267 }
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_TESTING_Command commands[] = {
284 GNUNET_TESTING_cmd_exec_bash_script ("emu_run",
285 "emu_run.sh",
286 argv_emu,
287 argc_emu,
288 &child_completed_callback),
289 GNUNET_TESTING_cmd_exec_bash_script ("script",
290 "block.sh",
291 argv,
292 argc,
293 &child_completed_callback),
294 block_script,
295 GNUNET_TESTING_cmd_end ()
296 };
297
298 ts->write_message = write_message;
299
300 is = GNUNET_TESTING_run (commands,
301 TIMEOUT,
302 &handle_result,
303 ts);
304 return is;
305}
306
307
308/**
309 * Entry point for the plugin.
310 *
311 * @param cls NULL
312 * @return the exported block API
313 */
314void *
315libgnunet_test_core_plugin_cmd_run_emu_init (void *cls)
316{
317 struct GNUNET_TESTING_PluginFunctions *api;
318
319 GNUNET_log_setup ("simple-send",
320 "DEBUG",
321 NULL);
322
323 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
324 api->start_testcase = &start_testcase;
325 api->get_waiting_for_barriers = get_waiting_for_barriers;
326 return api;
327}
328
329
330/**
331 * Exit point from the plugin.
332 *
333 * @param cls the return value from #libgnunet_test_transport_plugin_run_emu_init
334 * @return NULL
335 */
336void *
337libgnunet_test_core_plugin_cmd_run_emu_done (void *cls)
338{
339 struct GNUNET_TESTING_PluginFunctions *api = cls;
340
341 GNUNET_free (api);
342 return NULL;
343}
344
345
346/* end of plugin_cmd_simple_send.c */
diff --git a/src/service/core/test_core_run_emu_topo.conf b/src/service/core/test_core_run_emu_topo.conf
new file mode 100644
index 000000000..78d6d4407
--- /dev/null
+++ b/src/service/core/test_core_run_emu_topo.conf
@@ -0,0 +1,8 @@
1M:1
2N:2
3X:1
4T:libgnunet_test_core_plugin_cmd_run_emu
5K:1|{connect:{P:1:1:tcp}}
6R:1|{tcp_port:1}|{udp_port:1}
7P:1:1|{connect:{K:1:tcp}}
8P:2:1|{connect:{K:1:tcp}} \ No newline at end of file