From 9d7ff3c3fbee189367da05a1517777c76a80b23b Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Mon, 19 Jul 2021 19:53:56 +0200 Subject: - finished first prototype for running several local testcase. --- src/include/gnunet_protocols.h | 2 + src/include/gnunet_testbed_ng_service.h | 6 + src/testbed/Makefile.am | 1 + src/testbed/gnunet-cmds-helper.c | 23 ++-- src/testbed/plugin_testcmd.c | 17 ++- ...testbed_api_cmd_block_until_all_peers_started.c | 26 +++++ src/testbed/testbed_api_cmd_local_test_finished.c | 129 +++++++++++++++++++++ .../testbed_api_cmd_netjail_start_testbed.c | 49 +++++--- src/testbed/testbed_api_cmd_send_peer_ready.c | 5 +- src/testbed/testbed_helper.h | 8 ++ src/testing/testing_api_cmd_send_peer_ready.c | 104 +++++++++++++++++ src/testing/testing_api_loop.c | 4 +- 12 files changed, 347 insertions(+), 27 deletions(-) create mode 100644 src/testbed/testbed_api_cmd_local_test_finished.c create mode 100644 src/testing/testing_api_cmd_send_peer_ready.c (limited to 'src') diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 1d33d986d..715e94c6a 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -3567,6 +3567,8 @@ extern "C" { #define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED 1703 +#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1704 + /*********************************************************************************/ /** diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h index 2ea5e616c..caaee26b6 100644 --- a/src/include/gnunet_testbed_ng_service.h +++ b/src/include/gnunet_testbed_ng_service.h @@ -274,4 +274,10 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_send_peer_ready (const char *label, TESTBED_CMD_HELPER_write_cb write_message); + +struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_local_test_finished (const char *label, + TESTBED_CMD_HELPER_write_cb + write_message); + #endif diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index dc24eaf26..8fa3350a2 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -125,6 +125,7 @@ lib_LTLIBRARIES = \ libgnunettestbed.la libgnunettestbed_la_SOURCES = \ + testbed_api_cmd_local_test_finished.c \ testbed_api_cmd_send_peer_ready.c \ testbed_api_cmd_block_until_all_peers_started.c \ testbed_api_cmd_netjail_start.c \ diff --git a/src/testbed/gnunet-cmds-helper.c b/src/testbed/gnunet-cmds-helper.c index 693892a9c..6498d1279 100644 --- a/src/testbed/gnunet-cmds-helper.c +++ b/src/testbed/gnunet-cmds-helper.c @@ -383,7 +383,7 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length) * @param cls plugin to use. * */ -static void +/*static void run_plugin (void *cls) { struct Plugin *plugin = cls; @@ -400,7 +400,7 @@ run_plugin (void *cls) plugin->api->start_testcase (&write_message, router_ip, node_ip); -} +}*/ /** @@ -433,12 +433,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) "tokenizer \n"); msize = ntohs (message->size); - if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( - message->type)) - { - plugin->api->all_peers_started (); - } - else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) + if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) { msg = (const struct GNUNET_CMDS_HelperInit *) message; plugin_name_size = ntohs (msg->plugin_name_size); @@ -519,7 +514,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) GNUNET_free (binary); - done_reading = GNUNET_YES; + // done_reading = GNUNET_YES; msg_length = sizeof(struct GNUNET_CMDS_HelperReply); reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); @@ -541,6 +536,14 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) NULL);*/ return GNUNET_OK; } + else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( + message->type)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 8!\n"); + plugin->api->all_peers_started (); + return GNUNET_OK; + } else { LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); @@ -588,6 +591,8 @@ read_task (void *cls) return; } LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Read %u bytes\n", (unsigned int) sread); /* FIXME: could introduce a GNUNET_MST_read2 to read directly from 'stdin_fd' and save a memcpy() here */ if (GNUNET_OK != diff --git a/src/testbed/plugin_testcmd.c b/src/testbed/plugin_testcmd.c index 6f28e102d..70b6ad3ae 100644 --- a/src/testbed/plugin_testcmd.c +++ b/src/testbed/plugin_testcmd.c @@ -28,12 +28,20 @@ #include "gnunet_util_lib.h" #include "gnunet_testbed_ng_service.h" +/** + * Generic logging shortcut + */ +#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) + unsigned int are_all_peers_started; static void all_peers_started () { are_all_peers_started = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_ERROR, + "setting are_all_peers_started: %d\n", + are_all_peers_started); } static void @@ -42,6 +50,9 @@ start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip, { struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 6!\n"); + are_all_peers_started = GNUNET_NO; struct GNUNET_TESTING_Command commands[] = { @@ -52,12 +63,15 @@ start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip, write_message), GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", &are_all_peers_started), - GNUNET_TESTING_cmd_end () + GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1", + write_message) }; GNUNET_TESTING_run (NULL, commands, GNUNET_TIME_UNIT_FOREVER_REL); + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 7!\n"); } @@ -75,6 +89,7 @@ libgnunet_plugin_testcmd_init (void *cls) api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); api->start_testcase = &start_testcase; + api->all_peers_started = &all_peers_started; return api; } diff --git a/src/testbed/testbed_api_cmd_block_until_all_peers_started.c b/src/testbed/testbed_api_cmd_block_until_all_peers_started.c index fc872311d..8659fbb46 100644 --- a/src/testbed/testbed_api_cmd_block_until_all_peers_started.c +++ b/src/testbed/testbed_api_cmd_block_until_all_peers_started.c @@ -27,6 +27,11 @@ #include "gnunet_util_lib.h" #include "gnunet_testing_ng_lib.h" +/** + * Generic logging shortcut + */ +#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) + struct BlockState { unsigned int *all_peers_started; @@ -58,6 +63,8 @@ block_until_all_peers_started_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { + LOG (GNUNET_ERROR_TYPE_ERROR, + "block_until_all_peers_started_run!\n"); } @@ -69,6 +76,21 @@ block_until_all_peers_started_finish (void *cls, struct BlockState *bs = cls; unsigned int *ret = bs->all_peers_started; + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 10\n"); + + if (GNUNET_YES == *ret) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "We do not need to block anymore!\n"); + cont (cont_cls); + } + else + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "You shall not pass!\n"); + } + return *ret; } @@ -86,6 +108,10 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, { struct BlockState *bs; + LOG (GNUNET_ERROR_TYPE_ERROR, + "we have all_peers_started: %u\n", + *all_peers_started); + bs = GNUNET_new (struct BlockState); bs->all_peers_started = all_peers_started; diff --git a/src/testbed/testbed_api_cmd_local_test_finished.c b/src/testbed/testbed_api_cmd_local_test_finished.c new file mode 100644 index 000000000..8829f1b9a --- /dev/null +++ b/src/testbed/testbed_api_cmd_local_test_finished.c @@ -0,0 +1,129 @@ +/* + This file is part of GNUnet + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @file testing_api_cmd_block_until_all_peers_started.c + * @brief cmd to block the interpreter loop until all peers started. + * @author t3sserakt + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testing_ng_lib.h" +#include "testbed_helper.h" + +/** + * Generic logging shortcut + */ +#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) + +struct LocalFinishedState +{ + TESTBED_CMD_HELPER_write_cb write_message; + + struct GNUNET_CMDS_LOCAL_FINISHED *reply; +}; + + +static int +local_test_finished_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_OK; +} + + +static void +local_test_finished_cleanup (void *cls, + const struct GNUNET_TESTING_Command *cmd) +{ + struct LocalFinishedState *lfs = cls; + + GNUNET_free (lfs->reply); + GNUNET_free (lfs); +} + + +static void +local_test_finished_run (void *cls, + const struct GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTING_Interpreter *is) +{ + struct LocalFinishedState *lfs = cls; + + struct GNUNET_CMDS_LOCAL_FINISHED *reply; + size_t msg_length; + + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 12!\n"); + + msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED); + reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED); + reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED); + reply->header.size = htons ((uint16_t) msg_length); + lfs->reply = reply; + lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); + + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 13!\n"); +} + + +static int +local_test_finished_finish (void *cls, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) +{ + // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method. + return GNUNET_YES; +} + + +/** + * Create command. + * + * @param label name for command. + * @return command. + */ +struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_local_test_finished (const char *label, + TESTBED_CMD_HELPER_write_cb + write_message) +{ + struct LocalFinishedState *lfs; + + LOG (GNUNET_ERROR_TYPE_ERROR, + "We got here 11!\n"); + + lfs = GNUNET_new (struct LocalFinishedState); + lfs->write_message = write_message; + + struct GNUNET_TESTING_Command cmd = { + .cls = lfs, + .label = label, + .run = &local_test_finished_run, + .finish = &local_test_finished_finish, + .cleanup = &local_test_finished_cleanup, + .traits = &local_test_finished_traits + }; + + return cmd; +} diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c index 585825cbc..bc4674b74 100644 --- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c +++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c @@ -89,6 +89,8 @@ struct NetJailState unsigned int number_of_peers_started; + unsigned int number_of_local_test_finished; + /** * The host where the controller is running */ @@ -256,6 +258,14 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) message->type)) { ns->number_of_peers_started++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "number_of_peers_started: %d\n", + ns->number_of_peers_started); + } + else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( + message->type)) + { + ns->number_of_local_test_finished++; } else { @@ -375,7 +385,8 @@ start_testbed (struct NetJailState *ns, struct tbc)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Message send!\n"); + "Message %d send!\n", + tbc->count); if (NULL == ns->shandle[tbc->count - 1]) { @@ -426,17 +437,22 @@ netjail_start_finish (void *cls, unsigned int ret = GNUNET_NO; struct NetJailState *ns = cls; unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n); - struct GNUNET_CMDS_PEER_STARTED *reply; + struct GNUNET_CMDS_ALL_PEERS_STARTED *reply; size_t msg_length; struct GNUNET_HELPER_Handle *helper; struct TestbedCount *tbc; + if (ns->number_of_local_test_finished == total_number) + { + ret = GNUNET_YES; + cont (cont_cls); + } + if (ns->number_of_testbeds_started == total_number) { - /* ret = GNUNET_YES; - cont (cont_cls);*/ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All helpers started!\n"); + ns->number_of_testbeds_started = 0; } if (ns->number_of_peers_started == total_number) @@ -449,9 +465,9 @@ netjail_start_finish (void *cls, { tbc = GNUNET_new (struct TestbedCount); tbc->ns = ns; - tbc->count = (j - 1) * atoi (ns->local_m) + i + atoi (ns->global_n) - * atoi (ns->local_m); - helper = ns->helper[tbc->count - 1]; + // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. + tbc->count = (j - 1) * atoi (ns->local_m) + i + total_number; + helper = ns->helper[tbc->count - 1 - total_number]; msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); reply->header.type = htons ( @@ -460,14 +476,21 @@ netjail_start_finish (void *cls, GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); - GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( - helper, - &reply->header, - GNUNET_NO, - &clear_msg, - tbc)); + struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( + helper, + &reply->header, + GNUNET_NO, + &clear_msg, + tbc); + + GNUNET_array_append (ns->shandle, ns->n_shandle, sh); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers started message %d send!\n", + tbc->count); } } + ns->number_of_peers_started = 0; } return ret; } diff --git a/src/testbed/testbed_api_cmd_send_peer_ready.c b/src/testbed/testbed_api_cmd_send_peer_ready.c index 8a82b23a8..f175a3e18 100644 --- a/src/testbed/testbed_api_cmd_send_peer_ready.c +++ b/src/testbed/testbed_api_cmd_send_peer_ready.c @@ -26,6 +26,7 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_testing_ng_lib.h" +#include "testbed_helper.h" struct SendPeerReadyState @@ -62,7 +63,7 @@ send_peer_ready_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { - /*struct SendPeerReadyState *sprs = cls; + struct SendPeerReadyState *sprs = cls; struct GNUNET_CMDS_PEER_STARTED *reply; size_t msg_length; @@ -71,7 +72,7 @@ send_peer_ready_run (void *cls, reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED); reply->header.size = htons ((uint16_t) msg_length); sprs->reply = reply; - sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);*/ + sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); } diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h index 84059fef2..af90ce85d 100644 --- a/src/testbed/testbed_helper.h +++ b/src/testbed/testbed_helper.h @@ -130,6 +130,14 @@ struct GNUNET_CMDS_ALL_PEERS_STARTED struct GNUNET_MessageHeader header; }; +struct GNUNET_CMDS_LOCAL_FINISHED +{ + /** + * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED + */ + struct GNUNET_MessageHeader header; +}; + GNUNET_NETWORK_STRUCT_END #endif /* end of testbed_helper.h */ diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c new file mode 100644 index 000000000..27761c4d5 --- /dev/null +++ b/src/testing/testing_api_cmd_send_peer_ready.c @@ -0,0 +1,104 @@ +/* + This file is part of GNUnet + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @file testing_api_cmd_send_peer_ready.c + * @brief cmd to send a helper message if peer is ready. + * @author t3sserakt + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testing_ng_lib.h" +#include "testbed_api.h" +#include "testbed_helper.h" + + +struct SendPeerReadyState +{ + TESTBED_CMD_HELPER_write_cb write_message; + + struct GNUNET_CMDS_PEER_STARTED *reply; +}; + + +static int +send_peer_ready_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_OK; +} + + +static void +send_peer_ready_cleanup (void *cls, + const struct GNUNET_TESTING_Command *cmd) +{ + struct SendPeerReadyState *sprs = cls; + + GNUNET_free (sprs->reply); + GNUNET_free (sprs); +} + + +static void +send_peer_ready_run (void *cls, + const struct GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTING_Interpreter *is) +{ + struct SendPeerReadyState *sprs = cls; + struct GNUNET_CMDS_PEER_STARTED *reply; + size_t msg_length; + + msg_length = sizeof(struct GNUNET_CMDS_HelperInit);// GNUNET_CMDS_PEER_STARTED); + reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED); + reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED); + reply->header.size = htons ((uint16_t) msg_length); + sprs->reply = reply; + sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); +} + + +/** + * Create command. + * + * @param label name for command. + * @return command. + */ +struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_send_peer_ready (const char *label, + TESTBED_CMD_HELPER_write_cb write_message) +{ + struct SendPeerReadyState *sprs; + + sprs = GNUNET_new (struct SendPeerReadyState); + sprs->write_message = write_message; + + struct GNUNET_TESTING_Command cmd = { + .cls = sprs, + .label = label, + .run = &send_peer_ready_run, + .cleanup = &send_peer_ready_cleanup, + .traits = &send_peer_ready_traits + }; + + return cmd; +} diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index 7b7dc010a..f4fa4e17e 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -415,7 +415,7 @@ interpreter_run (void *cls) if (NULL == cmd->label) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running command END %p\n", is); is->result = GNUNET_OK; @@ -424,7 +424,7 @@ interpreter_run (void *cls) } else if (NULL != cmd) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running command `%s' %p\n", cmd->label, is); -- cgit v1.2.3