aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c122
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c99
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c163
5 files changed, 368 insertions, 19 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 15469a310..c01e9bdbd 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -50,6 +50,7 @@ libgnunettesting_la_SOURCES = \
50 testing_api_cmd_netjail_stop.c \ 50 testing_api_cmd_netjail_stop.c \
51 testing.c testing.h \ 51 testing.c testing.h \
52 testing_api_cmd_system_create.c \ 52 testing_api_cmd_system_create.c \
53 testing_api_cmd_system_destroy.c \
53 testing_api_cmd_batch.c \ 54 testing_api_cmd_batch.c \
54 testing_api_cmd_hello_world.c \ 55 testing_api_cmd_hello_world.c \
55 testing_api_cmd_hello_world_birth.c \ 56 testing_api_cmd_hello_world_birth.c \
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
new file mode 100644
index 000000000..e94d8dad0
--- /dev/null
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -0,0 +1,122 @@
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_system_destroy.c
23 * @brief cmd to destroy a testing system handle.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_lib.h"
30
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct TestSystemState
37{
38 // Label of the cmd which started the test system.
39 const char *create_label;
40};
41
42
43/**
44 * The run method of this cmd will remove the test environment for a node.
45 *
46 */
47static void
48system_destroy_run (void *cls,
49 const struct GNUNET_TESTING_Command *cmd,
50 struct GNUNET_TESTING_Interpreter *is)
51{
52 struct TestSystemState *tss = cls;
53 const struct GNUNET_TESTING_Command *system_cmd;
54 struct GNUNET_TESTING_System *tl_system;
55
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "system destroy\n");
58
59 system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label);
60 GNUNET_TESTING_get_trait_test_system (system_cmd,
61 &tl_system);
62 GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES);
63
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
65 "system destroyed\n");
66}
67
68
69/**
70 * The cleanup function of this cmd frees resources the cmd allocated.
71 *
72 */
73static void
74system_destroy_cleanup (void *cls,
75 const struct GNUNET_TESTING_Command *cmd)
76{
77 struct TestSystemState *tss = cls;
78
79 GNUNET_free (tss);
80}
81
82
83/**
84 * Trait function of this cmd does nothing.
85 *
86 */
87static int
88system_destroy_traits (void *cls,
89 const void **ret,
90 const char *trait,
91 unsigned int index)
92{
93 return GNUNET_OK;
94}
95
96
97/**
98 * Create command.
99 *
100 * @param label name for command.
101 * @param create_label Label of the cmd which started the test system.
102 * @return command.
103 */
104struct GNUNET_TESTING_Command
105GNUNET_TESTING_cmd_system_destroy (const char *label,
106 const char *create_label)
107{
108 struct TestSystemState *tss;
109
110 tss = GNUNET_new (struct TestSystemState);
111 tss->create_label = create_label;
112
113 struct GNUNET_TESTING_Command cmd = {
114 .cls = tss,
115 .label = label,
116 .run = &system_destroy_run,
117 .cleanup = &system_destroy_cleanup,
118 .traits = &system_destroy_traits
119 };
120
121 return cmd;
122}
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 0696188c5..afa37bac5 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -169,8 +169,10 @@ libgnunettransporttesting_la_LDFLAGS = \
169libgnunettransporttesting2_la_SOURCES = \ 169libgnunettransporttesting2_la_SOURCES = \
170 transport_api_cmd_connecting_peers.c \ 170 transport_api_cmd_connecting_peers.c \
171 transport_api_cmd_start_peer.c \ 171 transport_api_cmd_start_peer.c \
172 transport_api_cmd_stop_peer.c \
172 transport_api_cmd_send_simple.c \ 173 transport_api_cmd_send_simple.c \
173 transport-testing2.c transport-testing2.h \ 174 transport-testing2.c transport-testing2.h \
175 transport-testing-ng.h \
174 transport-testing-cmds.h \ 176 transport-testing-cmds.h \
175 transport-testing-filenames2.c \ 177 transport-testing-filenames2.c \
176 transport-testing-loggers2.c \ 178 transport-testing-loggers2.c \
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index c4f7fcfe3..ac5c01075 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,10 +37,30 @@
37 37
38#define BASE_DIR "testdir" 38#define BASE_DIR "testdir"
39 39
40struct GNUNET_MQ_MessageHandler *handlers; 40/**
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
41 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 */
42unsigned int are_all_peers_started; 56unsigned int are_all_peers_started;
43 57
58
59/**
60 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
61 * received.
62 *
63 */
44static int 64static int
45check_test (void *cls, 65check_test (void *cls,
46 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 66 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -48,6 +68,12 @@ check_test (void *cls,
48 return GNUNET_OK; 68 return GNUNET_OK;
49} 69}
50 70
71
72/**
73 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
74 * being received.
75 *
76 */
51static void 77static void
52handle_test (void *cls, 78handle_test (void *cls,
53 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 79 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -56,6 +82,12 @@ handle_test (void *cls,
56 "message received\n"); 82 "message received\n");
57} 83}
58 84
85
86/**
87 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
88 * being received.
89 *
90 */
59static int 91static int
60check_test2 (void *cls, 92check_test2 (void *cls,
61 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 93 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -63,6 +95,12 @@ check_test2 (void *cls,
63 return GNUNET_OK; 95 return GNUNET_OK;
64} 96}
65 97
98
99/**
100 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
101 * being received.
102 *
103 */
66static void 104static void
67handle_test2 (void *cls, 105handle_test2 (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 106 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -71,6 +109,11 @@ handle_test2 (void *cls,
71 "message received\n"); 109 "message received\n");
72} 110}
73 111
112
113/**
114 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
115 *
116 */
74static void 117static void
75all_peers_started () 118all_peers_started ()
76{ 119{
@@ -80,6 +123,17 @@ all_peers_started ()
80 are_all_peers_started); 123 are_all_peers_started);
81} 124}
82 125
126
127/**
128 * Function to start a local test case.
129 *
130 * @param write_message Callback to send a message to the master loop.
131 * @param router_ip Global address of the network namespace.
132 * @param node_ip Local address of a node i a network namespace.
133 * @param m The number of the node in a network namespace.
134 * @param n The number of the network namespace.
135 * @param local_m The number of nodes in a network namespace.
136 */
83static void 137static void
84start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 138start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
85 char *node_ip, 139 char *node_ip,
@@ -87,12 +141,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
87 char *n, 141 char *n,
88 char *local_m) 142 char *local_m)
89{ 143{
90 char *testdir;
91 char *cfgname;
92 144
93 GNUNET_asprintf (&cfgname, 145 GNUNET_asprintf (&cfgname,
94 "%s%s.conf", 146 "test_transport_api2_tcp_node%s.conf",
95 "test_transport_api2_tcp_node",
96 n); 147 n);
97 148
98 LOG (GNUNET_ERROR_TYPE_ERROR, 149 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -103,12 +154,18 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
103 "node ip: %s\n", 154 "node ip: %s\n",
104 node_ip); 155 node_ip);
105 156
106 testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n) 157 GNUNET_asprintf (&testdir,
158 "%s%s%s",
159 BASE_DIR,
160 m,
161 n);
162
163 /*testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
107 + 1); 164 + 1);
108 165
109 strcpy (testdir, BASE_DIR); 166 strcpy (testdir, BASE_DIR);
110 strcat (testdir, m); 167 strcat (testdir, m);
111 strcat (testdir, n); 168 strcat (testdir, n);*/
112 169
113 struct GNUNET_MQ_MessageHandler handlers[] = { 170 struct GNUNET_MQ_MessageHandler handlers[] = {
114 GNUNET_MQ_hd_var_size (test, 171 GNUNET_MQ_hd_var_size (test,
@@ -123,30 +180,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
123 }; 180 };
124 181
125 struct GNUNET_TESTING_Command commands[] = { 182 struct GNUNET_TESTING_Command commands[] = {
126 GNUNET_TESTING_cmd_system_create ("system-create-1", 183 GNUNET_TESTING_cmd_system_create ("system-create",
127 testdir), 184 testdir),
128 GNUNET_TRANSPORT_cmd_start_peer ("start-peer-1", 185 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
129 "system-create-1", 186 "system-create",
130 m, 187 m,
131 n, 188 n,
132 local_m, 189 local_m,
133 handlers, 190 handlers,
134 cfgname), 191 cfgname),
135 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1", 192 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
136 write_message), 193 write_message),
137 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", 194 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
138 &are_all_peers_started), 195 &are_all_peers_started),
139 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers-1", 196 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
140 "start-peer-1", 197 "start-peer"),
141 "this is useless"), 198 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
142 GNUNET_TRANSPORT_cmd_send_simple ("send-simple-1",
143 m, 199 m,
144 n, 200 n,
145 (atoi (n) - 1) * atoi (local_m) + atoi ( 201 (atoi (n) - 1) * atoi (local_m) + atoi (
146 m), 202 m),
147 "start-peer-1", 203 "start-peer"),
148 "this is useless"), 204 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
149 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1", 205 "start-peer"),
206 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
207 "system-create"),
208 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
150 write_message) 209 write_message)
151 }; 210 };
152 211
@@ -187,6 +246,8 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
187 struct GNUNET_TESTING_PluginFunctions *api = cls; 246 struct GNUNET_TESTING_PluginFunctions *api = cls;
188 247
189 GNUNET_free (api); 248 GNUNET_free (api);
249 GNUNET_free (testdir);
250 GNUNET_free (cfgname);
190 return NULL; 251 return NULL;
191} 252}
192 253
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
new file mode 100644
index 000000000..2277520ec
--- /dev/null
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -0,0 +1,163 @@
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_stop_peer.c
23 * @brief cmd to stop a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h"
32#include "transport-testing-ng.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39
40/**
41 * Struct to hold information for callbacks.
42 *
43 */
44struct StopPeerState
45{
46 // Label of the cmd to start the peer.
47 const char *start_label;
48};
49
50
51/**
52 * The run method of this cmd will stop all services of a peer which were used to test the transport service.
53 *
54 */
55static void
56stop_peer_run (void *cls,
57 const struct GNUNET_TESTING_Command *cmd,
58 struct GNUNET_TESTING_Interpreter *is)
59{
60 struct StopPeerState *stop_ps = cls;
61 struct StartPeerState *sps;
62 const struct GNUNET_TESTING_Command *start_cmd;
63
64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (stop_ps->start_label);
65 GNUNET_TRANSPORT_get_trait_state (start_cmd,
66 &sps);
67
68 if (NULL != sps->pic)
69 {
70 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
71 sps->pic = NULL;
72 }
73 if (NULL != sps->th)
74 {
75 GNUNET_TRANSPORT_core_disconnect (sps->th);
76 sps->th = NULL;
77 }
78 if (NULL != sps->ah)
79 {
80 GNUNET_TRANSPORT_application_done (sps->ah);
81 sps->ah = NULL;
82 }
83 if (NULL != sps->ph)
84 {
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Disconnecting from PEERSTORE service\n");
87 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
88 sps->ph = NULL;
89 }
90 if (NULL != sps->peer)
91 {
92 if (GNUNET_OK !=
93 GNUNET_TESTING_peer_stop (sps->peer))
94 {
95 LOG (GNUNET_ERROR_TYPE_DEBUG,
96 "Testing lib failed to stop peer %u (`%s')\n",
97 sps->no,
98 GNUNET_i2s (&sps->id));
99 }
100 GNUNET_TESTING_peer_destroy (sps->peer);
101 sps->peer = NULL;
102 }
103 if (NULL != sps->rh_task)
104 GNUNET_SCHEDULER_cancel (sps->rh_task);
105 sps->rh_task = NULL;
106
107}
108
109
110/**
111 * The cleanup function of this cmd frees resources the cmd allocated.
112 *
113 */
114static void
115stop_peer_cleanup (void *cls,
116 const struct GNUNET_TESTING_Command *cmd)
117{
118 struct StopPeerState *sps = cls;
119
120 GNUNET_free (sps);
121}
122
123
124/**
125 * Trait function of this cmd does nothing.
126 *
127 */
128static int
129stop_peer_traits (void *cls,
130 const void **ret,
131 const char *trait,
132 unsigned int index)
133{
134 return GNUNET_OK;
135}
136
137
138/**
139 * Create command.
140 *
141 * @param label name for command.
142 * @param start_label Label of the cmd to start the peer.
143 * @return command.
144 */
145struct GNUNET_TESTING_Command
146GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
147 const char *start_label)
148{
149 struct StopPeerState *sps;
150
151 sps = GNUNET_new (struct StopPeerState);
152 sps->start_label = start_label;
153
154 struct GNUNET_TESTING_Command cmd = {
155 .cls = sps,
156 .label = label,
157 .run = &stop_peer_run,
158 .cleanup = &stop_peer_cleanup,
159 .traits = &stop_peer_traits
160 };
161
162 return cmd;
163}