aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-12-08 17:30:22 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-12-08 17:30:22 +0900
commit5c4b060714954a6e4571fe981b333856d2ef4a1b (patch)
tree7d26623cedb260caaac4c094c3ad436383ab12e1 /src
parent715ca9df95320ccb5edc8982b264cb41774b7ccc (diff)
downloadgnunet-5c4b060714954a6e4571fe981b333856d2ef4a1b.tar.gz
gnunet-5c4b060714954a6e4571fe981b333856d2ef4a1b.zip
TESTING: The testing API should properly take strings as const
Strings passed to the API should either be const and copied, or handled by the caller and free'd. Looking at the transport tests currently neither is happening. The strings are probably safer but definitely leaked. Changed the API to use "const" strings. Users of the testing API must define functions that copy (and free!) strings accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testing_plugin.h19
-rw-r--r--src/testing/gnunet-cmds-helper.c3
-rw-r--r--src/transport/test_transport_plugin_cmd_nat_upnp.c13
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c13
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_broadcast.c13
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_dv.c13
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c13
-rw-r--r--src/transport/transport-testing-cmds.h8
-rw-r--r--src/transport/transport_api_cmd_start_peer.c16
9 files changed, 54 insertions, 57 deletions
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 28b505976..6c1b9c1a9 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -28,6 +28,8 @@
28#ifndef GNUNET_TESTING_PLUGIN_H 28#ifndef GNUNET_TESTING_PLUGIN_H
29#define GNUNET_TESTING_PLUGIN_H 29#define GNUNET_TESTING_PLUGIN_H
30 30
31#include "gnunet_common.h"
32
31#ifdef __cplusplus 33#ifdef __cplusplus
32extern "C" 34extern "C"
33{ 35{
@@ -37,20 +39,21 @@ extern "C"
37#endif 39#endif
38 40
39typedef void 41typedef void
40(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t 42(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message,
41 msg_length); 43 size_t msg_length);
42 44
43typedef void 45typedef void
44(*TESTING_CMD_HELPER_finish_cb) (); 46(*TESTING_CMD_HELPER_finish_cb) ();
45 47
46typedef void 48typedef void
47(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb 49(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb
48 write_message, char *router_ip, 50 write_message,
49 char *node_ip, 51 const char *router_ip,
50 char *n, 52 const char *node_ip,
51 char *m, 53 const char *n,
52 char *local_m, 54 const char *m,
53 char *topology_data, 55 const char *local_m,
56 const char *topology_data,
54 unsigned int *read_file, 57 unsigned int *read_file,
55 TESTING_CMD_HELPER_finish_cb finish_cb); 58 TESTING_CMD_HELPER_finish_cb finish_cb);
56 59
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 624aa58eb..591ddd499 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -385,6 +385,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
385 LOG (GNUNET_ERROR_TYPE_ERROR, 385 LOG (GNUNET_ERROR_TYPE_ERROR,
386 "subnet node n: %s\n", 386 "subnet node n: %s\n",
387 plugin->n); 387 plugin->n);
388 // FIXME: Free?
388 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1); 389 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1);
389 strcat (node_ip, NODE_BASE_IP); 390 strcat (node_ip, NODE_BASE_IP);
390 } 391 }
@@ -622,7 +623,7 @@ main (int argc, char **argv)
622 } 623 }
623 shc_chld = 624 shc_chld =
624 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); 625 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
625 626
626 ret = GNUNET_PROGRAM_run (argc, 627 ret = GNUNET_PROGRAM_run (argc,
627 argv, 628 argv,
628 "gnunet-cmds-helper", 629 "gnunet-cmds-helper",
diff --git a/src/transport/test_transport_plugin_cmd_nat_upnp.c b/src/transport/test_transport_plugin_cmd_nat_upnp.c
index 86280c66b..73380e03c 100644
--- a/src/transport/test_transport_plugin_cmd_nat_upnp.c
+++ b/src/transport/test_transport_plugin_cmd_nat_upnp.c
@@ -210,12 +210,13 @@ all_local_tests_prepared ()
210 * @param local_m The number of nodes in a network namespace. 210 * @param local_m The number of nodes in a network namespace.
211 */ 211 */
212static void 212static void
213start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 213start_testcase (TESTING_CMD_HELPER_write_cb write_message,
214 char *node_ip, 214 const char *router_ip,
215 char *m, 215 const char *node_ip,
216 char *n, 216 const char *m,
217 char *local_m, 217 const char *n,
218 char *topology_data, 218 const char *local_m,
219 const char *topology_data,
219 unsigned int *read_file, 220 unsigned int *read_file,
220 TESTING_CMD_HELPER_finish_cb finished_cb) 221 TESTING_CMD_HELPER_finish_cb finished_cb)
221{ 222{
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index c9acb0431..de923cbdd 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -202,12 +202,13 @@ all_local_tests_prepared ()
202 * @param local_m The number of nodes in a network namespace. 202 * @param local_m The number of nodes in a network namespace.
203 */ 203 */
204static void 204static void
205start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 205start_testcase (TESTING_CMD_HELPER_write_cb write_message,
206 char *node_ip, 206 const char *router_ip,
207 char *m, 207 const char *node_ip,
208 char *n, 208 const char *m,
209 char *local_m, 209 const char *n,
210 char *topology_data, 210 const char *local_m,
211 const char *topology_data,
211 unsigned int *read_file, 212 unsigned int *read_file,
212 TESTING_CMD_HELPER_finish_cb finished_cb) 213 TESTING_CMD_HELPER_finish_cb finished_cb)
213{ 214{
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
index f7a4b117f..ff6f0def9 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
@@ -235,12 +235,13 @@ all_local_tests_prepared ()
235 * @param local_m The number of nodes in a network namespace. 235 * @param local_m The number of nodes in a network namespace.
236 */ 236 */
237static void 237static void
238start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 238start_testcase (TESTING_CMD_HELPER_write_cb write_message,
239 char *node_ip, 239 const char *router_ip,
240 char *m, 240 const char *node_ip,
241 char *n, 241 const char *m,
242 char *local_m, 242 const char *n,
243 char *topology_data, 243 const char *local_m,
244 const char *topology_data,
244 unsigned int *read_file, 245 unsigned int *read_file,
245 TESTING_CMD_HELPER_finish_cb finished_cb) 246 TESTING_CMD_HELPER_finish_cb finished_cb)
246{ 247{
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_dv.c b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
index 674c0d576..adbb3cc0b 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_dv.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
@@ -258,12 +258,13 @@ all_local_tests_prepared ()
258 * @param local_m The number of nodes in a network namespace. 258 * @param local_m The number of nodes in a network namespace.
259 */ 259 */
260static void 260static void
261start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 261start_testcase (TESTING_CMD_HELPER_write_cb write_message,
262 char *node_ip, 262 const char *router_ip,
263 char *m, 263 const char *node_ip,
264 char *n, 264 const char *m,
265 char *local_m, 265 const char *n,
266 char *topology_data, 266 const char *local_m,
267 const char *topology_data,
267 unsigned int *read_file, 268 unsigned int *read_file,
268 TESTING_CMD_HELPER_finish_cb finished_cb) 269 TESTING_CMD_HELPER_finish_cb finished_cb)
269{ 270{
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 38b81da85..81445b25e 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -195,12 +195,13 @@ all_local_tests_prepared ()
195 * @param local_m The number of nodes in a network namespace. 195 * @param local_m The number of nodes in a network namespace.
196 */ 196 */
197static void 197static void
198start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 198start_testcase (TESTING_CMD_HELPER_write_cb write_message,
199 char *node_ip, 199 const char *router_ip,
200 char *m, 200 const char *node_ip,
201 char *n, 201 const char *m,
202 char *local_m, 202 const char *n,
203 char *topology_data, 203 const char *local_m,
204 const char *topology_data,
204 unsigned int *read_file, 205 unsigned int *read_file,
205 TESTING_CMD_HELPER_finish_cb finished_cb) 206 TESTING_CMD_HELPER_finish_cb finished_cb)
206{ 207{
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index c577feb34..680162563 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -26,7 +26,7 @@
26 */ 26 */
27#ifndef TRANSPORT_TESTING_CMDS_H 27#ifndef TRANSPORT_TESTING_CMDS_H
28#define TRANSPORT_TESTING_CMDS_H 28#define TRANSPORT_TESTING_CMDS_H
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_ng_lib.h"
30 30
31 31
32typedef void * 32typedef void *
@@ -109,7 +109,7 @@ struct StartPeerState
109 /** 109 /**
110 * The ip of a node. 110 * The ip of a node.
111 */ 111 */
112 char *node_ip; 112 const char *node_ip;
113 113
114 /** 114 /**
115 * Receive callback 115 * Receive callback
@@ -193,6 +193,8 @@ struct StartPeerState
193 193
194/** 194/**
195 * Create command. 195 * Create command.
196 * FIXME: Parameter list does not match documentation.
197 * FIXME: m and n parameters need a rename.
196 * 198 *
197 * @param label name for command. 199 * @param label name for command.
198 * @param system_label Label of the cmd to setup a test environment. 200 * @param system_label Label of the cmd to setup a test environment.
@@ -209,7 +211,7 @@ struct GNUNET_TESTING_Command
209GNUNET_TRANSPORT_cmd_start_peer (const char *label, 211GNUNET_TRANSPORT_cmd_start_peer (const char *label,
210 const char *system_label, 212 const char *system_label,
211 uint32_t no, 213 uint32_t no,
212 char *node_ip, 214 const char *node_ip,
213 struct GNUNET_MQ_MessageHandler *handlers, 215 struct GNUNET_MQ_MessageHandler *handlers,
214 const char *cfgname, 216 const char *cfgname,
215 GNUNET_TRANSPORT_notify_connect_cb 217 GNUNET_TRANSPORT_notify_connect_cb
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 4add06609..5dfb820e0 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -431,25 +431,11 @@ start_peer_traits (void *cls,
431} 431}
432 432
433 433
434/**
435 * Create command.
436 *
437 * @param label name for command.
438 * @param system_label Label of the cmd to setup a test environment.
439 * @param m The number of the local node of the actual network namespace.
440 * @param n The number of the actual namespace.
441 * @param local_m Number of local nodes in each namespace.
442 * @param handlers Handler for messages received by this peer.
443 * @param cfgname Configuration file name for this peer.
444 * @param notify_connect Method which will be called, when a peer connects.
445 * @param broadcast Flag indicating, if broadcast should be switched on.
446 * @return command.
447 */
448struct GNUNET_TESTING_Command 434struct GNUNET_TESTING_Command
449GNUNET_TRANSPORT_cmd_start_peer (const char *label, 435GNUNET_TRANSPORT_cmd_start_peer (const char *label,
450 const char *system_label, 436 const char *system_label,
451 uint32_t no, 437 uint32_t no,
452 char *node_ip, 438 const char *node_ip,
453 struct GNUNET_MQ_MessageHandler *handlers, 439 struct GNUNET_MQ_MessageHandler *handlers,
454 const char *cfgname, 440 const char *cfgname,
455 GNUNET_TRANSPORT_notify_connect_cb 441 GNUNET_TRANSPORT_notify_connect_cb