From e7b082de7fcdb394deecde4a098aa927bcd72fdb Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Tue, 13 Dec 2022 22:40:46 +0900 Subject: -more namespace cleanup and comments regarding API --- src/testing/gnunet-cmds-helper.c | 2 +- src/testing/testing.h | 27 +++++++--- src/testing/testing_api_cmd_barrier.c | 58 ++-------------------- src/testing/testing_api_cmd_barrier_reached.c | 6 +-- .../testing_api_cmd_netjail_start_testsystem.c | 15 +++--- src/testing/testing_api_loop.c | 40 +++++++++++---- 6 files changed, 65 insertions(+), 83 deletions(-) (limited to 'src/testing') diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c index 458830cb9..4d3da6260 100644 --- a/src/testing/gnunet-cmds-helper.c +++ b/src/testing/gnunet-cmds-helper.c @@ -419,7 +419,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) struct CommandBarrierAdvanced *adm = (struct CommandBarrierAdvanced *) message; barrier_name = (const char *) &adm[1]; - GNUNET_TESTING_finish_attached_cmds (is, barrier_name); + TST_interpreter_finish_attached_cmds (is, barrier_name); return GNUNET_OK; } else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( diff --git a/src/testing/testing.h b/src/testing/testing.h index 7372b143e..debcec39a 100644 --- a/src/testing/testing.h +++ b/src/testing/testing.h @@ -265,6 +265,8 @@ GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd, // wait on other peers to reach it. /** * FIXME: Documentation + * FIXME: Now this, as it returns a Command, seems to me like it should be + * part of the public API? * Create command. * * @param label name for command. @@ -287,9 +289,13 @@ GNUNET_TESTING_cmd_barrier_reached ( /** - * FIXME: Return type - * FIXME: Documentation * Can we advance the barrier? + * FIXME: As this is not in testing.h it should be in another namespace. + * Possibly BARRIER_can_advance. However, as this is also used in a netjail cmd, + * I am not sure if this needs to be public? Maybe there should be a barrier + * trait that returns a barrier where this helper function can be called on? + * Barriers are usually also not "advanced" but "crossed" or "passed" + * but it seems to me that the word here should correctly be "reached"? * * @param barrier The barrier in question. * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not. @@ -307,7 +313,7 @@ GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier); * @param global_node_number The global number of the node to inform. */ void -GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, +TST_interpreter_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name, unsigned int global_node_number); @@ -318,12 +324,13 @@ GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, * @param barrier The barrier in question. */ void -GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, +TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name); /** * Send Message to master loop that cmds being attached to a barrier. + * FIXME: Unused function * * @param is The interpreter loop. * @param barrier_name The name of the barrier to advance. @@ -341,13 +348,17 @@ GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, /** * Getting a node from a map by global node number. + * FIXME: This is a barrier helper function not related to a command but it is + * implemented in the *_cmd_barrier.c file. + * Maybe move into a separate file like testing_barrier.c; see also can + * barrier advance above * * @param nodes The map. * @param node_number The global node number. * @return The node. */ struct GNUNET_TESTING_NetjailNode * -GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, +GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier, unsigned int node_number); @@ -357,7 +368,7 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, * @param is The interpreter. */ void -GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is); +TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is); /** @@ -368,7 +379,7 @@ GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is); * @return The barrier. */ struct GNUNET_TESTING_Barrier * -GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, +TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name); @@ -379,7 +390,7 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, * @param barrier The barrier to add. */ void -GNUNET_TESTING_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, +TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier); diff --git a/src/testing/testing_api_cmd_barrier.c b/src/testing/testing_api_cmd_barrier.c index 7e4e67dea..bc4f79eb6 100644 --- a/src/testing/testing_api_cmd_barrier.c +++ b/src/testing/testing_api_cmd_barrier.c @@ -43,16 +43,7 @@ struct BarrierState const char *label; }; - -/** - * Send Message to master loop that cmds being attached to a barrier. - * - * @param is The interpreter loop. - * @param barrier_name The name of the barrier to advance. - * @param subnet_number The number of the subnet. - * @param node_number The node to inform. - * @param write_message Callback to write messages to the master loop. - */ +// FIXME Unused function void GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, char *barrier_name, @@ -78,40 +69,6 @@ GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, } -/** - * Send Message to netjail nodes that a barrier can be advanced. - * - * @param is The interpreter loop. - * @param barrier_name The name of the barrier to advance. - * @param global_node_number The global number of the node to inform. - */ -void -GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, - const char *barrier_name, - unsigned int global_node_number) -{ - struct CommandBarrierAdvanced *adm = GNUNET_new (struct - CommandBarrierAdvanced); - size_t msg_length = sizeof(struct CommandBarrierAdvanced); - size_t name_len; - - name_len = strlen (barrier_name) + 1; - adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED); - adm->header.size = htons ((uint16_t) msg_length); - memcpy (&adm[1], barrier_name, name_len); - GNUNET_TESTING_send_message_to_netjail (is, - global_node_number, - &adm->header); - GNUNET_free (adm); -} - - -/** - * Can we advance the barrier? - * - * @param barrier The barrier in question. - * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not. - */ unsigned int GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier) { @@ -186,18 +143,11 @@ barrier_run (void *cls, { struct BarrierState *brs = cls; - GNUNET_TESTING_interpreter_add_barrier (is, brs->barrier); + TST_interpreter_add_barrier (is, brs->barrier); } -/** - * Getting a node from a map by global node number. - * - * @param nodes The map. - * @param node_number The global node number. - * @return The node. - */ struct GNUNET_TESTING_NetjailNode * -GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, +GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier, unsigned int node_number) { struct GNUNET_HashCode hc; @@ -207,7 +157,7 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, memcpy (&key, &hc, sizeof (key)); - return GNUNET_CONTAINER_multishortmap_get (nodes, &key); + return GNUNET_CONTAINER_multishortmap_get (barrier->nodes, &key); } diff --git a/src/testing/testing_api_cmd_barrier_reached.c b/src/testing/testing_api_cmd_barrier_reached.c index eca422b1d..8d52310c9 100644 --- a/src/testing/testing_api_cmd_barrier_reached.c +++ b/src/testing/testing_api_cmd_barrier_reached.c @@ -93,13 +93,13 @@ barrier_reached_run (void *cls, struct GNUNET_TESTING_CommandBarrierReached *msg; size_t name_len; - barrier = GNUNET_TESTING_get_barrier (is, brs->barrier_name); + barrier = TST_interpreter_get_barrier (is, brs->barrier_name); if (NULL == barrier) { barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); barrier->shadow = GNUNET_YES; barrier->name = brs->label; - GNUNET_TESTING_interpreter_add_barrier (is, barrier); + TST_interpreter_add_barrier (is, barrier); } barrier->reached++; if (GNUNET_TESTING_can_barrier_advance (barrier)) @@ -107,7 +107,7 @@ barrier_reached_run (void *cls, //FIXME cmd uninitialized GNUNET_assert (NULL != cmd); cmd->asynchronous_finish = GNUNET_YES; - GNUNET_TESTING_finish_attached_cmds (is, barrier->name); + TST_interpreter_finish_attached_cmds (is, barrier->name); } else if (GNUNET_NO == brs->asynchronous_finish) { diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 62b628928..40a23c67c 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -207,6 +207,7 @@ struct TestingSystemCount struct GNUNET_MessageHeader *msg; }; + /** * Code to clean up resource this cmd used. * @@ -216,7 +217,7 @@ static void netjail_exec_cleanup (void *cls) { struct NetJailState *ns = cls; - GNUNET_TESTING_delete_barriers (ns->is); + TST_interpreter_delete_barriers (ns->is); GNUNET_free (ns); } @@ -354,9 +355,9 @@ barrier_attached (struct NetJailState *ns, const struct am = (struct CommandBarrierAttached *) message; barrier_name = (const char *) &am[1]; - barrier = GNUNET_TESTING_get_barrier (ns->is, barrier_name); + barrier = TST_interpreter_get_barrier (ns->is, barrier_name); GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow); - node = GNUNET_TESTING_barrier_get_node (barrier->nodes, am->node_number); + node = GNUNET_TESTING_barrier_get_node (barrier, am->node_number); if (NULL == node) { node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); @@ -385,12 +386,12 @@ barrier_reached (struct NetJailState *ns, const struct *) message; barrier_name = (const char *) &rm[1]; - barrier = GNUNET_TESTING_get_barrier (ns->is, barrier_name); + barrier = TST_interpreter_get_barrier (ns->is, barrier_name); GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow); barrier->reached++; if (GNUNET_TESTING_can_barrier_advance (barrier)) { - GNUNET_TESTING_finish_attached_cmds (ns->is, barrier->name); + TST_interpreter_finish_attached_cmds (ns->is, barrier->name); } } @@ -702,12 +703,12 @@ start_helper (struct NetJailState *ns, for (pos = barriers->head; NULL != pos; pos = pos->next) { - barrier = GNUNET_TESTING_get_barrier (ns->is, pos->barrier_name); + barrier = TST_interpreter_get_barrier (ns->is, pos->barrier_name); if (NULL == barrier || GNUNET_YES == barrier->shadow) { barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); barrier->name = pos->barrier_name; - GNUNET_TESTING_interpreter_add_barrier (ns->is, barrier); + TST_interpreter_add_barrier (ns->is, barrier); barrier->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); } diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index d7456b91f..7d76979dc 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -665,6 +665,27 @@ GNUNET_TESTING_send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is, is); } +void +TST_interpreter_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, + const char *barrier_name, + unsigned int global_node_number) +{ + struct CommandBarrierAdvanced *adm = GNUNET_new (struct + CommandBarrierAdvanced); + size_t msg_length = sizeof(struct CommandBarrierAdvanced); + size_t name_len; + + name_len = strlen (barrier_name) + 1; + adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED); + adm->header.size = htons ((uint16_t) msg_length); + memcpy (&adm[1], barrier_name, name_len); + GNUNET_TESTING_send_message_to_netjail (is, + global_node_number, + &adm->header); + GNUNET_free (adm); +} + + int free_barrier_node_cb (void *cls, @@ -678,9 +699,9 @@ free_barrier_node_cb (void *cls, if (GNUNET_NO == is->finishing) { - GNUNET_TESTING_send_barrier_advance (is, - barrier->name, - node->node_number); + TST_interpreter_send_barrier_advance (is, + barrier->name, + node->node_number); } GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node); return GNUNET_YES; @@ -695,7 +716,7 @@ free_barrier_node_cb (void *cls, * @return The barrier. */ struct GNUNET_TESTING_Barrier * -GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, +TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name) { struct GNUNET_HashCode hc; @@ -718,12 +739,12 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, * @param barrier The barrier in question. */ void -GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, - const char *barrier_name) +TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, + const char *barrier_name) { struct CommandListEntry *pos; struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; - struct GNUNET_TESTING_Barrier *barrier = GNUNET_TESTING_get_barrier (is, + struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is, barrier_name); while (NULL != (pos = barrier->cmds_head)) @@ -783,14 +804,13 @@ free_barriers_cb (void *cls, return GNUNET_YES; } - /** * Deleting all barriers create in the context of this interpreter. * * @param is The interpreter. */ void -GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is) +TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is) { GNUNET_CONTAINER_multishortmap_iterate (is->barriers, free_barriers_cb, @@ -806,7 +826,7 @@ GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is) * @param barrier The barrier to add. */ void -GNUNET_TESTING_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, +TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier) { struct GNUNET_HashCode hc; -- cgit v1.2.3