[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 03/03: Testing: Fixing bugs in plugin helper and topology api c
From: |
gnunet |
Subject: |
[gnunet] 03/03: Testing: Fixing bugs in plugin helper and topology api code. |
Date: |
Fri, 31 May 2024 15:56:21 +0200 |
This is an automated email from the git hooks/post-receive script.
t3sserakt pushed a commit to branch master
in repository gnunet.
commit 430411553cdffbb9c3f90f82dc28b0ddee1399b1
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Fri May 31 15:54:18 2024 +0200
Testing: Fixing bugs in plugin helper and topology api code.
---
src/lib/testing/gnunet-cmds-helper.c | 27 ++++++++--
src/lib/testing/testing_api_cmd_netjail_start.c | 1 +
src/lib/testing/testing_api_loop.c | 18 +++++--
src/lib/testing/testing_api_topology.c | 71 ++++++++++++++++++++-----
src/lib/testing/testing_api_topology.h | 14 ++---
5 files changed, 105 insertions(+), 26 deletions(-)
diff --git a/src/lib/testing/gnunet-cmds-helper.c
b/src/lib/testing/gnunet-cmds-helper.c
index edbbd8d13..93d4d96de 100644
--- a/src/lib/testing/gnunet-cmds-helper.c
+++ b/src/lib/testing/gnunet-cmds-helper.c
@@ -96,6 +96,11 @@ static struct GNUNET_TESTING_PluginFunctions *plugin;
*/
static char *plugin_name;
+/**
+ * The loaded topology.
+ */
+ struct GNUNET_TESTING_NetjailTopology *njt;
+
/**
* Our message stream tokenizer
*/
@@ -170,7 +175,11 @@ do_shutdown (void *cls)
{
GNUNET_PLUGIN_unload (plugin_name,
plugin);
- GNUNET_free (plugin_name);
+ }
+ if (NULL != njt)
+ {
+ GNUNET_TESTING_free_topology (njt);
+ njt = NULL;
}
}
@@ -232,7 +241,7 @@ static void
write_message (const struct GNUNET_MessageHeader *message)
{
struct WriteContext *wc;
- size_t msg_length = ntohl (message->size);
+ size_t msg_length = ntohs (message->size);
wc = GNUNET_new (struct WriteContext);
wc->length = msg_length;
@@ -309,7 +318,7 @@ handle_helper_init (
const struct GNUNET_ShortHashCode *bd
= (const struct GNUNET_ShortHashCode *) &msg[1];
const char *topo = (const char *) &bd[barrier_count];
- struct GNUNET_TESTING_NetjailTopology *njt;
+
GNUNET_assert ('\0' == topo[left - 1]);
njt = GNUNET_TESTING_get_topo_from_string_ (topo);
@@ -322,9 +331,12 @@ handle_helper_init (
}
plugin_name = GNUNET_TESTING_get_plugin_from_topo (njt,
my_node_id);
- GNUNET_TESTING_free_topology (njt);
plugin = GNUNET_PLUGIN_load (plugin_name,
(void *) my_node_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting plugin `%s' for node %s\n",
+ plugin_name,
+ my_node_id);
if (NULL == plugin)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -334,6 +346,13 @@ handle_helper_init (
GNUNET_SCHEDULER_shutdown ();
return;
}
+ struct GNUNET_TESTING_Command *commands = plugin->cls;
+ unsigned int i;
+
+ for (i = 0; NULL != commands[i].run; i++)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "helper %s\n",
+ commands[i].label.value);
is = plugin->start_testcase (plugin->cls,
topo,
barrier_count,
diff --git a/src/lib/testing/testing_api_cmd_netjail_start.c
b/src/lib/testing/testing_api_cmd_netjail_start.c
index 8a84b2769..eede2fea6 100644
--- a/src/lib/testing/testing_api_cmd_netjail_start.c
+++ b/src/lib/testing/testing_api_cmd_netjail_start.c
@@ -178,6 +178,7 @@ netjail_start_run (void *cls,
char *const script_argv[] = {
script_name,
(char *) topology_data,
+ pid,
"0",
NULL
};
diff --git a/src/lib/testing/testing_api_loop.c
b/src/lib/testing/testing_api_loop.c
index 7bb88ddda..098de8a05 100644
--- a/src/lib/testing/testing_api_loop.c
+++ b/src/lib/testing/testing_api_loop.c
@@ -680,9 +680,20 @@ GNUNET_TESTING_make_plugin (
const struct GNUNET_TESTING_Command *commands)
{
struct GNUNET_TESTING_PluginFunctions *api;
+ struct GNUNET_TESTING_Command *commands_copy;
+ unsigned int i;
+
+ for (i = 0; NULL != commands[i].run; i++)
+ ;
+ commands_copy = GNUNET_malloc_large ( (i + 1)
+ * sizeof (struct
+ GNUNET_TESTING_Command));
+ memcpy (commands_copy,
+ commands,
+ sizeof (struct GNUNET_TESTING_Command) * i + 1);
api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
- api->cls = (void *) commands;
+ api->cls = (void *) commands_copy;
api->start_testcase = &start_testcase;
return api;
}
@@ -744,7 +755,7 @@ unsigned int
GNUNET_TESTING_barrier_count_ (
struct GNUNET_TESTING_Interpreter *is)
{
- return GNUNET_CONTAINER_multishortmap_size (is->barriers);
+ return NULL != is->barriers ? GNUNET_CONTAINER_multishortmap_size
(is->barriers) : 0;
}
@@ -754,7 +765,8 @@ GNUNET_TESTING_barrier_iterate_ (
GNUNET_CONTAINER_ShortmapIterator cb,
void *cb_cls)
{
- GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
+ if (NULL != is->barriers)
+ GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
cb,
cb_cls);
}
diff --git a/src/lib/testing/testing_api_topology.c
b/src/lib/testing/testing_api_topology.c
index b83d7ba10..22cfd85fe 100644
--- a/src/lib/testing/testing_api_topology.c
+++ b/src/lib/testing/testing_api_topology.c
@@ -634,8 +634,50 @@ free_value_cb (void *cls,
(void) cls;
GNUNET_free (value);
+
+ return GNUNET_OK;
}
-
+
+
+static int
+free_subnets_cb (void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *value)
+{
+ (void) cls;
+ struct GNUNET_TESTING_NetjailSubnet *subnet = value;
+
+ GNUNET_CONTAINER_multishortmap_iterate (subnet->peers,
+ &free_value_cb,
+ NULL);
+
+ GNUNET_free (subnet);
+
+ return GNUNET_OK;
+}
+
+
+static int
+free_carriers_cb (void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *value)
+{
+ (void) cls;
+ struct GNUNET_TESTING_NetjailCarrier *carrier = value;
+
+ GNUNET_CONTAINER_multishortmap_iterate (carrier->peers,
+ &free_value_cb,
+ NULL);
+ GNUNET_CONTAINER_multishortmap_iterate (carrier->subnets,
+ &free_subnets_cb,
+ NULL);
+
+ GNUNET_free (carrier);
+
+ return GNUNET_OK;
+}
+
+
/**
* Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
*
@@ -647,9 +689,9 @@ GNUNET_TESTING_free_topology (struct
GNUNET_TESTING_NetjailTopology *topology)
GNUNET_CONTAINER_multishortmap_iterate (topology->backbone_peers,
&free_value_cb,
NULL);
- /*GNUNET_CONTAINER_multishortmap_iterate (topology->carriers,
+ GNUNET_CONTAINER_multishortmap_iterate (topology->carriers,
&free_carriers_cb,
- NULL);*/
+ NULL);
GNUNET_free (topology->plugin);
GNUNET_free (topology);
}
@@ -807,6 +849,7 @@ create_subnet_peers (struct GNUNET_CONFIGURATION_Handle
*cfg,
struct GNUNET_TESTING_NetjailSubnet *subnet)
{
struct GNUNET_HashCode hc;
+ subnet->peers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
for (int i = 1; i < subnet->number_peers; i++)
{
@@ -832,6 +875,7 @@ create_subnets (struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_NetjailCarrier *carrier)
{
struct GNUNET_HashCode hc;
+ carrier->subnets = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
for (int i = 1; i < carrier->number_subnets; i++)
{
@@ -872,7 +916,8 @@ create_peers (struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_NetjailCarrier *carrier)
{
struct GNUNET_HashCode hc;
-
+ carrier->peers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
+
for (int i = 1; i < carrier->number_peers; i++)
{
struct GNUNET_ShortHashCode hkey;
@@ -903,6 +948,7 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
struct GNUNET_HashCode hc;
cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_assert (NULL != topology->carriers);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_deserialize (cfg,
@@ -915,11 +961,10 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
GNUNET_CONFIGURATION_destroy (cfg);
return NULL;
}
-
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
"DEFAULTS",
"SUBNETS",
- (unsigned long long
*) &topology->default_subnets))
+
&(topology->default_subnets)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Missing default SUBNETS!\n");
@@ -937,7 +982,7 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
"DEFAULTS",
"CARRIER_PEERS",
- (unsigned long long
*) &topology->default_carrier_peers))
+
&(topology->default_carrier_peers)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Missing default CARRIER_PEERS!\n");
@@ -946,7 +991,7 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
"DEFAULTS",
"SUBNET_PEERS",
- (unsigned long long
*) &topology->default_subnet_peers))
+
&(topology->default_subnet_peers)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Missing default SUBNET_PEERS!\n");
@@ -955,7 +1000,7 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
"BACKBONE",
"CARRIERS",
- (unsigned long long
*) &topology->num_carriers))
+
&(topology->num_carriers)))
{
LOG (GNUNET_ERROR_TYPE_INFO,
"No carrier configured!\n");
@@ -963,8 +1008,8 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
}
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
"BACKBONE",
- "CARRIERS",
- (unsigned long long
*) &topology->num_backbone_peers))
+ "BACKBONE_PEERS",
+
&(topology->num_backbone_peers)))
{
LOG (GNUNET_ERROR_TYPE_INFO,
"No backbone peers configured!\n");
@@ -986,6 +1031,7 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
peer,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
}
+ GNUNET_assert (NULL != topology->carriers);
for (int i = 0;i < topology->num_carriers; i++)
{
struct GNUNET_TESTING_NetjailCarrier *carrier = GNUNET_new (struct
GNUNET_TESTING_NetjailCarrier);
@@ -995,9 +1041,10 @@ GNUNET_TESTING_get_topo_from_string_ (const char *input)
topology->total++;
carrier->number = topology->total;
GNUNET_CRYPTO_hash (&topology->total, sizeof(topology->total), &hc);
- memcpy (&hkey,
+ memcpy (&hkey,
&hc,
sizeof (hkey));
+ GNUNET_assert (NULL != topology->carriers);
GNUNET_CONTAINER_multishortmap_put (topology->carriers,
&hkey,
carrier,
diff --git a/src/lib/testing/testing_api_topology.h
b/src/lib/testing/testing_api_topology.h
index 7040ca286..45afb9114 100644
--- a/src/lib/testing/testing_api_topology.h
+++ b/src/lib/testing/testing_api_topology.h
@@ -314,31 +314,31 @@ struct GNUNET_TESTING_NetjailTopology
/**
* Default number of subnets per carrier.
*/
- unsigned int default_subnets;
+ unsigned long long default_subnets;
/**
* Default number of peers per carrier.
*/
- unsigned int default_carrier_peers;
+ unsigned long long default_carrier_peers;
/**
* Default number of peers per subnet.
*/
- unsigned int default_subnet_peers;
+ unsigned long long default_subnet_peers;
/**
* Default plugin for the test case to be run on nodes.
*/
char *plugin;
/**
- * Number of carriers.
+ * Default number of backbone peers.
*/
- unsigned int num_carriers;
+ unsigned long long num_backbone_peers;
/**
- * Default number of backbone peers.
+ * Number of carriers.
*/
- unsigned int num_backbone_peers;
+ unsigned long long num_carriers;
/**
* Hash map containing the carriers.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.