diff options
author | t3sserakt <t3ss@posteo.de> | 2021-08-24 11:56:13 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-08-24 11:56:13 +0200 |
commit | 5ddaa3f8eb5e01882540f21ddf237f3a41311e8a (patch) | |
tree | 765617baebf4366c9584d71863c3077f5d107d49 /src/testing | |
parent | 9d5a8c05f3a33c49fd97e5b8ef99d58b96704c6d (diff) |
- fixed mem leaks, added code doc, formatting, removed trace logs
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/gnunet-cmds-helper.c | 190 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_block_until_all_peers_started.c | 41 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_local_test_finished.c | 42 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_start.c | 42 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_start_testsystem.c | 228 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_stop.c | 40 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_stop_testsystem.c | 25 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_send_peer_ready.c | 25 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_system_create.c | 25 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_system_destroy.c | 6 | ||||
-rw-r--r-- | src/testing/testing_api_loop.c | 44 |
11 files changed, 413 insertions, 295 deletions
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c index 5705f46c2..21ea33888 100644 --- a/src/testing/gnunet-cmds-helper.c +++ b/src/testing/gnunet-cmds-helper.c @@ -47,7 +47,7 @@ /** * Generic logging shortcut - */ +testing_api_cmd_block_until_all_peers_started.c */ #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) /** @@ -74,27 +74,71 @@ struct Plugin */ struct GNUNET_TESTING_PluginFunctions *api; + /** + * IP address of the specific node the helper is running for. + * + */ char *node_ip; + /** + * Name of the test case plugin. + * + */ char *plugin_name; + /** + * The number of namespaces + * + */ char *global_n; + /** + * The number of local nodes per namespace. + * + */ char *local_m; + /** + * The number of the namespace this node is in. + * + */ char *n; + /** + * The number of the node in the namespace. + * + */ char *m; }; +/** + * Struct with information about a specific node and the whole network namespace setup. + * + */ struct NodeIdentifier { + /** + * The number of the namespace this node is in. + * + */ char *n; + /** + * The number of the node in the namespace. + * + */ char *m; + /** + * The number of namespaces + * + */ char *global_n; + /** + * The number of local nodes per namespace. + * + */ char *local_m; }; @@ -162,11 +206,6 @@ static struct GNUNET_SCHEDULER_Task *read_task_id; static struct GNUNET_SCHEDULER_Task *write_task_id; /** - * Task to kill the child - */ -static struct GNUNET_SCHEDULER_Task *child_death_task_id; - -/** * Are we done reading messages from stdin? */ static int done_reading; @@ -187,8 +226,6 @@ shutdown_task (void *cls) { LOG_DEBUG ("Shutting down.\n"); - LOG (GNUNET_ERROR_TYPE_ERROR, - "Shutting down tokenizer!\n"); if (NULL != read_task_id) { @@ -204,11 +241,6 @@ shutdown_task (void *cls) GNUNET_free (wc->data); GNUNET_free (wc); } - if (NULL != child_death_task_id) - { - GNUNET_SCHEDULER_cancel (child_death_task_id); - child_death_task_id = NULL; - } if (NULL != stdin_fd) (void) GNUNET_DISK_file_close (stdin_fd); if (NULL != stdout_fd) @@ -235,9 +267,6 @@ write_task (void *cls) struct WriteContext *wc = cls; ssize_t bytes_wrote; - LOG (GNUNET_ERROR_TYPE_ERROR, - "Writing data!\n"); - GNUNET_assert (NULL != wc); write_task_id = NULL; bytes_wrote = GNUNET_DISK_file_write (stdout_fd, @@ -256,12 +285,8 @@ write_task (void *cls) { GNUNET_free (wc->data); GNUNET_free (wc); - LOG (GNUNET_ERROR_TYPE_ERROR, - "Written successfully!\n"); return; } - LOG (GNUNET_ERROR_TYPE_ERROR, - "Written data!\n"); write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd, &write_task, @@ -270,39 +295,14 @@ write_task (void *cls) /** - * Task triggered whenever we receive a SIGCHLD (child - * process died). + * Callback to write a message to the master loop. * - * @param cls closure, NULL if we need to self-restart */ -/*static void -child_death_task (void *cls) -{ - const struct GNUNET_DISK_FileHandle *pr; - char c[16]; - - pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); - child_death_task_id = NULL; - // consume the signal - GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c))); - LOG_DEBUG ("Got SIGCHLD\n"); - - LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n"); - child_death_task_id = - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - pr, - &child_death_task, - NULL); -}*/ - - static void write_message (struct GNUNET_MessageHeader *message, size_t msg_length) { struct WriteContext *wc; - LOG (GNUNET_ERROR_TYPE_ERROR, - "enter write_message!\n"); wc = GNUNET_new (struct WriteContext); wc->length = msg_length; wc->data = message; @@ -311,38 +311,10 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length) stdout_fd, &write_task, wc); - LOG (GNUNET_ERROR_TYPE_ERROR, - "leave write_message!\n"); } /** - * Function to run the test cases. - * - * @param cls plugin to use. - * - */ -/*static void -run_plugin (void *cls) -{ - struct Plugin *plugin = cls; - char *router_ip; - char *node_ip; - - router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1); - strcpy (router_ip, ROUTER_BASE_IP); - strcat (router_ip, plugin->m); - - node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1); - strcat (node_ip, NODE_BASE_IP); - strcat (node_ip, plugin->n); - - plugin->api->start_testcase (&write_message, router_ip, node_ip); - -}*/ - - -/** * Functions with this signature are called whenever a * complete message is received by the tokenizer. * @@ -368,9 +340,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) char *router_ip; char *node_ip; - LOG (GNUNET_ERROR_TYPE_ERROR, - "tokenizer \n"); - msize = ntohs (message->size); if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) { @@ -390,23 +359,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd"); - LOG (GNUNET_ERROR_TYPE_ERROR, - "plugin_name: %s \n", - plugin_name); - - // cmd_binary_process = GNUNET_OS_start_process ( - /*GNUNET_OS_INHERIT_STD_ERR verbose? , - NULL, - NULL, - NULL, - binary, - plugin_name, - ni->global_n, - ni->local_m, - ni->n, - ni->m, - NULL);*/ - plugin = GNUNET_new (struct Plugin); plugin->api = GNUNET_PLUGIN_load (plugin_name, NULL); @@ -429,51 +381,15 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, plugin->n, plugin->local_m); - LOG (GNUNET_ERROR_TYPE_ERROR, - "We got here!\n"); - - /*if (NULL == cmd_binary_process) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Starting plugin failed!\n"); - return GNUNET_SYSERR; - }*/ - - LOG (GNUNET_ERROR_TYPE_ERROR, - "We got here 2!\n"); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "global_n: %s local_n: %s n: %s m: %s.\n", - ni->global_n, - ni->local_m, - ni->n, - ni->m); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "We got here 3!\n"); - GNUNET_free (binary); - // done_reading = GNUNET_YES; - msg_length = sizeof(struct GNUNET_CMDS_HelperReply); reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); reply->header.size = htons ((uint16_t) msg_length); - LOG (GNUNET_ERROR_TYPE_ERROR, - "We got here 4!\n"); - write_message ((struct GNUNET_MessageHeader *) reply, msg_length); - LOG (GNUNET_ERROR_TYPE_ERROR, - "We got here 5!\n"); - - /*child_death_task_id = GNUNET_SCHEDULER_add_read_file ( - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), - &child_death_task, - NULL);*/ return GNUNET_OK; } else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( @@ -514,8 +430,6 @@ read_task (void *cls) if ((GNUNET_SYSERR == sread) || (0 == sread)) { LOG_DEBUG ("STDIN closed\n"); - LOG (GNUNET_ERROR_TYPE_ERROR, - "tokenizer shutting down during reading!\n"); GNUNET_SCHEDULER_shutdown (); return; } @@ -529,8 +443,6 @@ 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 != @@ -624,13 +536,6 @@ main (int argc, char **argv) ni->n = argv[3]; ni->m = argv[4]; - LOG (GNUNET_ERROR_TYPE_ERROR, - "global_n: %s local_n: %s n: %s m: %s.\n", - ni->global_n, - ni->local_m, - ni->n, - ni->m); - status = GNUNET_OK; if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) @@ -647,8 +552,7 @@ main (int argc, char **argv) options, &run, ni); - LOG (GNUNET_ERROR_TYPE_ERROR, - "run finished\n"); + GNUNET_SIGNAL_handler_uninstall (shc_chld); shc_chld = NULL; GNUNET_DISK_pipe_close (sigpipe); diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c index 8659fbb46..e9d3f0ed3 100644 --- a/src/testing/testing_api_cmd_block_until_all_peers_started.c +++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c @@ -32,12 +32,24 @@ */ #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) +/** + * Struct with information for callbacks. + * + */ struct BlockState { + /** + * Flag to indicate if all peers have started. + * + */ unsigned int *all_peers_started; }; +/** + * Trait function of this cmd does nothing. + * + */ static int block_until_all_peers_started_traits (void *cls, const void **ret, @@ -48,6 +60,10 @@ block_until_all_peers_started_traits (void *cls, } +/** + * The cleanup function of this cmd frees resources the cmd allocated. + * + */ static void block_until_all_peers_started_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) @@ -58,16 +74,24 @@ block_until_all_peers_started_cleanup (void *cls, } +/** + * This function does nothing but to start the cmd. + * + */ static void block_until_all_peers_started_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "block_until_all_peers_started_run!\n"); } +/** + * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called. + * + */ static int block_until_all_peers_started_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -76,20 +100,10 @@ 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; } @@ -99,6 +113,7 @@ block_until_all_peers_started_finish (void *cls, * Create command. * * @param label name for command. + * @param all_peers_started Flag which will be set from outside. * @return command. */ struct GNUNET_TESTING_Command @@ -108,10 +123,6 @@ 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/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c index 5b74d4e04..383de4c10 100644 --- a/src/testing/testing_api_cmd_local_test_finished.c +++ b/src/testing/testing_api_cmd_local_test_finished.c @@ -33,14 +33,31 @@ */ #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) + +/** + * Struct to hold information for callbacks. + * + */ struct LocalFinishedState { + /** + * Callback to write messages to the master loop. + * + */ TESTING_CMD_HELPER_write_cb write_message; + /** + * The message send back to the master loop. + * + */ struct GNUNET_CMDS_LOCAL_FINISHED *reply; }; +/** + * Trait function of this cmd does nothing. + * + */ static int local_test_finished_traits (void *cls, const void **ret, @@ -51,6 +68,10 @@ local_test_finished_traits (void *cls, } +/** + * The cleanup function of this cmd frees resources the cmd allocated. + * + */ static void local_test_finished_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) @@ -62,6 +83,10 @@ local_test_finished_cleanup (void *cls, } +/** + * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED message to the master loop. + * + */ static void local_test_finished_run (void *cls, const struct GNUNET_TESTING_Command *cmd, @@ -72,28 +97,25 @@ local_test_finished_run (void *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"); } +/** + * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method. + * + */ 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. - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping local loop\n"); return GNUNET_YES; } @@ -103,6 +125,7 @@ local_test_finished_finish (void *cls, * Create command. * * @param label name for command. + * @param write_message Callback to write messages to the master loop. * @return command. */ struct GNUNET_TESTING_Command @@ -112,9 +135,6 @@ GNUNET_TESTING_cmd_local_test_finished (const char *label, { struct LocalFinishedState *lfs; - LOG (GNUNET_ERROR_TYPE_ERROR, - "We got here 11!\n"); - lfs = GNUNET_new (struct LocalFinishedState); lfs->write_message = write_message; diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index c82392a08..536b356a6 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c @@ -29,12 +29,19 @@ #define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh" +/** + * Struct to hold information for callbacks. + * + */ struct NetJailState { + // Child Wait handle struct GNUNET_ChildWaitHandle *cwh; + // Number of local nodes in each namespace. char *local_m; + // The number of namespaces. char *global_n; /** @@ -42,16 +49,15 @@ struct NetJailState */ struct GNUNET_OS_Process *start_proc; + // Flag indication if the script finished. unsigned int finished; }; /** -* -* -* @param cls closure -* @param cmd current CMD being cleaned up. -*/ + * The cleanup function of this cmd frees resources the cmd allocated. + * + */ static void netjail_start_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) @@ -81,14 +87,9 @@ netjail_start_cleanup (void *cls, /** -* -* -* @param cls closure. -* @param[out] ret result -* @param trait name of the trait. -* @param index index number of the object to offer. -* @return #GNUNET_OK on success. -*/ + * Trait function of this cmd does nothing. + * + */ static int netjail_start_traits (void *cls, const void **ret, @@ -98,6 +99,11 @@ netjail_start_traits (void *cls, return GNUNET_OK; } + +/** + * Callback which will be called if the setup script finished. + * + */ static void child_completed_callback (void *cls, enum GNUNET_OS_ProcessStatusType type, @@ -122,7 +128,7 @@ child_completed_callback (void *cls, /** -* Run the "hello world" CMD. +* The run method starts the script which setup the network namespaces. * * @param cls closure. * @param cmd CMD being run. @@ -171,6 +177,11 @@ netjail_start_run (void *cls, GNUNET_break (NULL != ns->cwh); } + +/** + * This function checks the flag NetJailState#finished, if this cmd finished. + * + */ static int netjail_start_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -189,7 +200,8 @@ netjail_start_finish (void *cls, * Create command. * * @param label name for command. - * @param binaryname to start. + * @param local_m Number of local nodes in each namespace. + * @param global_n The number of namespaces. * @return command. */ struct GNUNET_TESTING_Command diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 5c2f71168..01bac9b05 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -29,13 +29,21 @@ #define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" -struct HelperMessage; - +/** + * Struct to store messages send/received by the helper into a DLL + * + */ struct HelperMessage { + /** + * Kept in a DLL. + */ struct HelperMessage *next; + /** + * Kept in a DLL. + */ struct HelperMessage *prev; /** @@ -47,27 +55,51 @@ struct HelperMessage }; - +/** + * Struct to store information handed over to callbacks. + * + */ struct NetJailState { - + /** + * Pointer to the return value of the test. + * + */ unsigned int *rv; + /** + * Head of the DLL which stores messages received by the helper. + * + */ struct HelperMessage *hp_messages_head; + /** + * Tail of the DLL which stores messages received by the helper. + * + */ struct HelperMessage *hp_messages_tail; /** - * The process handle + * Array with handles of helper processes. */ struct GNUNET_HELPER_Handle **helper; + /** + * Size of the array NetJailState#helper. + * + */ unsigned int n_helper; - char *binary_name; - + /** + * Number of nodes in a network namespace. //TODO make this a unsigned int + * + */ char *local_m; + /** + * Number of network namespaces. //TODO make this a unsigned int + * + */ char *global_n; /** @@ -75,33 +107,91 @@ struct NetJailState */ struct GNUNET_HELPER_SendHandle **shandle; + /** + * Size of the array NetJailState#shandle. + * + */ unsigned int n_shandle; /** - * The message corresponding to send handle + * The messages send to the helper. */ struct GNUNET_MessageHeader **msg; + /** + * Size of the array NetJailState#msg. + * + */ unsigned int n_msg; + /** + * Number of test environments started. + * + */ unsigned int number_of_testsystems_started; + /** + * Number of peers started. + * + */ unsigned int number_of_peers_started; + /** + * Number of local tests finished. + * + */ unsigned int number_of_local_test_finished; + /** + * Name of the test case plugin the helper will load. + * + */ char *plugin_name; + + /** + * HEAD of the DLL containing TestingSystemCount. + * + */ + struct TestingSystemCount *tbcs_head; + + /** + * TAIL of the DLL containing TestingSystemCount. + * + */ + struct TestingSystemCount *tbcs_tail; }; +/** + * Struct containing the number of the test environment and the NetJailState which + * will be handed to callbacks specific to a test environment. + */ struct TestingSystemCount { + /** + * Kept in a DLL. + */ + struct TestingSystemCount *next; + + /** + * Kept in a DLL. + */ + struct TestingSystemCount *prev; + + /** + * The number of the test environment. + * + */ unsigned int count; + /** + * Struct to store information handed over to callbacks. + * + */ struct NetJailState *ns; }; /** -* +* Code to clean up ressource this cmd used. * * @param cls closure * @param cmd current CMD being cleaned up. @@ -111,20 +201,31 @@ netjail_exec_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) { struct NetJailState *ns = cls; + struct HelperMessage *message_pos; + struct TestingSystemCount *tbc_pos; - GNUNET_free (ns->binary_name); + while (NULL != (message_pos = ns->hp_messages_head)) + { + GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head, + ns->hp_messages_tail, + message_pos); + GNUNET_free (message_pos); + } + while (NULL != (tbc_pos = ns->tbcs_head)) + { + GNUNET_CONTAINER_DLL_remove (ns->tbcs_head, + ns->tbcs_tail, + tbc_pos); + GNUNET_free (tbc_pos); + } + GNUNET_free (ns); } /** -* -* -* @param cls closure. -* @param[out] ret result -* @param trait name of the trait. -* @param index index number of the object to offer. -* @return #GNUNET_OK on success. -*/ + * This function prepares an array with traits. + * + */ static int netjail_exec_traits (void *cls, const void **ret, @@ -209,9 +310,6 @@ clear_msg (void *cls, int result) struct TestingSystemCount *tbc = cls; struct NetJailState *ns = tbc->ns; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "clear_msg tbc->count: %d\n", - tbc->count); GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); ns->shandle[tbc->count - 1] = NULL; GNUNET_free (ns->msg[tbc->count - 1]); @@ -240,20 +338,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "helper_mst tbc->count: %d\n", - tbc->count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message from helper.\n"); ns->number_of_testsystems_started++; } else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs ( 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)) @@ -272,7 +362,10 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) return GNUNET_OK; } - +/** + * Callback called if there was an exception during execution of the helper. + * + */ static void exp_cb (void *cls) { @@ -281,7 +374,14 @@ exp_cb (void *cls) *ns->rv = 1; } - +/** + * Function to initialize a init message for the helper. + * + * @param m_char The actual node in a namespace. //TODO Change this to unsigned int + * @param n_char The actual namespace. //TODO Change this to unsigned int + * @param plugin_name Name of the test case plugin the helper will load. + * + */ static struct GNUNET_CMDS_HelperInit * create_helper_init_msg_ (char *m_char, char *n_char, @@ -294,9 +394,6 @@ create_helper_init_msg_ (char *m_char, GNUNET_assert (NULL != plugin_name); plugin_name_len = strlen (plugin_name); msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "msg_size: %d \n", - msg_size); msg = GNUNET_malloc (msg_size); msg->header.size = htons (msg_size); msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT); @@ -308,13 +405,17 @@ create_helper_init_msg_ (char *m_char, } +/** + * Function which start a single helper process. + * + */ static void start_helper (struct NetJailState *ns, struct GNUNET_CONFIGURATION_Handle *config, char *m_char, char *n_char) { - // struct GNUNET_CONFIGURATION_Handle *cfg; + struct GNUNET_HELPER_Handle *helper; struct GNUNET_CMDS_HelperInit *msg; struct TestingSystemCount *tbc; char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, @@ -332,15 +433,13 @@ start_helper (struct NetJailState *ns, struct GNUNET_YES, NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "m: %d n: %d\n", - m, - n); - tbc = GNUNET_new (struct TestingSystemCount); tbc->ns = ns; tbc->count = (n - 1) * atoi (ns->local_m) + m; + GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, + tbc); + if (GNUNET_NO == helper_check) { @@ -365,17 +464,7 @@ start_helper (struct NetJailState *ns, struct &exp_cb, tbc)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "First using helper %d %d\n", - tbc->count - 1, - ns->n_helper); - struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1]; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "First using helper %d %d %p\n", - tbc->count - 1, - ns->n_helper, - helper); + helper = ns->helper[tbc->count - 1]; msg = create_helper_init_msg_ (m_char, n_char, @@ -389,10 +478,6 @@ start_helper (struct NetJailState *ns, struct &clear_msg, tbc)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Message %d send!\n", - tbc->count); - if (NULL == ns->shandle[tbc->count - 1]) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -404,7 +489,7 @@ start_helper (struct NetJailState *ns, struct /** -* Run the "hello world" CMD. +* This function starts a helper process for each node. * * @param cls closure. * @param cmd CMD being run. @@ -434,6 +519,15 @@ netjail_exec_run (void *cls, } +/** + * This function checks on three different information. + * + * 1. Did all helpers start. This is only logged. + * 2. Did all peer start. + * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers. + * 3. Did all peers finished the test case. In this case interpreter_next will be called. + * + */ static int netjail_start_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -455,16 +549,11 @@ netjail_start_finish (void *cls, if (ns->number_of_testsystems_started == total_number) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All helpers started!\n"); ns->number_of_testsystems_started = 0; } if (ns->number_of_peers_started == total_number) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All peers started!\n"); - for (int i = 1; i <= atoi (ns->global_n); i++) { for (int j = 1; j <= atoi (ns->local_m); j++) { @@ -472,11 +561,7 @@ netjail_start_finish (void *cls, tbc->ns = ns; // 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 = (i - 1) * atoi (ns->local_m) + j + total_number; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Second using helper %d %d %d\n", - tbc->count - 1 - total_number, - i, - j); + 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); @@ -494,10 +579,6 @@ netjail_start_finish (void *cls, 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; @@ -509,8 +590,11 @@ netjail_start_finish (void *cls, /** * Create command. * - * @param label name for command. - * @param binaryname to exec. + * @param label Name for the command. + * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int + * @param global_n Number of network namespaces. //TODO make this a unsigned int + * @param plugin_name Name of the test case plugin the helper will load. + * @param rv Pointer to the return value of the test. * @return command. */ struct GNUNET_TESTING_Command diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index 710b4fbf4..99084d9af 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c @@ -30,12 +30,19 @@ #define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" +// Child Wait handle struct GNUNET_ChildWaitHandle *cwh; +/** + * Struct to hold information for callbacks. + * + */ struct NetJailState { + // Number of local nodes in each namespace. char *local_m; + // The number of namespaces. char *global_n; /** @@ -43,16 +50,15 @@ struct NetJailState */ struct GNUNET_OS_Process *stop_proc; + // Flag indication if the script finished. unsigned int finished; }; /** -* -* -* @param cls closure -* @param cmd current CMD being cleaned up. -*/ + * The cleanup function of this cmd frees resources the cmd allocated. + * + */ static void netjail_stop_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) @@ -78,14 +84,9 @@ netjail_stop_cleanup (void *cls, /** -* -* -* @param cls closure. -* @param[out] ret result -* @param trait name of the trait. -* @param index index number of the object to offer. -* @return #GNUNET_OK on success. -*/ + * Trait function of this cmd does nothing. + * + */ static int netjail_stop_traits (void *cls, const void **ret, @@ -96,6 +97,10 @@ netjail_stop_traits (void *cls, } +/** + * Callback which will be called if the setup script finished. + * + */ static void child_completed_callback (void *cls, enum GNUNET_OS_ProcessStatusType type, @@ -118,7 +123,7 @@ child_completed_callback (void *cls, /** -* Run the "hello world" CMD. +* The run method starts the script which deletes the network namespaces. * * @param cls closure. * @param cmd CMD being run. @@ -169,6 +174,10 @@ netjail_stop_run (void *cls, } +/** + * This function checks the flag NetJailState#finished, if this cmd finished. + * + */ static int netjail_stop_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -188,7 +197,8 @@ netjail_stop_finish (void *cls, * Create command. * * @param label name for command. - * @param binaryname to stop. + * @param local_m Number of local nodes in each namespace. + * @param global_n The number of namespaces. * @return command. */ struct GNUNET_TESTING_Command diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index bed9f3ebf..d6e733e05 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c @@ -28,6 +28,10 @@ #include "testing_cmds.h" +/** + * Struct to store information handed over to callbacks. + * + */ struct StopHelperState { @@ -45,7 +49,7 @@ struct StopHelperState /** -* +* Code to clean up ressource this cmd used. * * @param cls closure * @param cmd current CMD being cleaned up. @@ -59,14 +63,9 @@ stop_testing_system_cleanup (void *cls, /** -* -* -* @param cls closure. -* @param[out] ret result -* @param trait name of the trait. -* @param index index number of the object to offer. -* @return #GNUNET_OK on success. -*/ + * Trait function of this cmd does nothing. + * + */ static int stop_testing_system_traits (void *cls, const void **ret, @@ -78,7 +77,7 @@ stop_testing_system_traits (void *cls, /** -* Run the "hello world" CMD. +* This function stops the helper process for each node. * * @param cls closure. * @param cmd CMD being run. @@ -110,9 +109,11 @@ stop_testing_system_run (void *cls, /** * Create command. - * + * @param helper_start_label label of the cmd to start the test system. * @param label name for command. - * @param binaryname to exec. + * @param . + * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int + * @param global_n Number of network namespaces. //TODO make this a unsigned int * @return command. */ struct GNUNET_TESTING_Command diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c index afe28de77..016837214 100644 --- a/src/testing/testing_api_cmd_send_peer_ready.c +++ b/src/testing/testing_api_cmd_send_peer_ready.c @@ -29,14 +29,30 @@ #include "testing_cmds.h" +/** + * Struct to hold information for callbacks. + * + */ struct SendPeerReadyState { + /** + * Callback to write messages to the master loop. + * + */ TESTING_CMD_HELPER_write_cb write_message; + /** + * The message send back to the master loop. + * + */ struct GNUNET_CMDS_PEER_STARTED *reply; }; +/** + * Trait function of this cmd does nothing. + * + */ static int send_peer_ready_traits (void *cls, const void **ret, @@ -47,6 +63,10 @@ send_peer_ready_traits (void *cls, } +/** + * The cleanup function of this cmd frees resources the cmd allocated. + * + */ static void send_peer_ready_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) @@ -58,6 +78,10 @@ send_peer_ready_cleanup (void *cls, } +/** + * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop. + * + */ static void send_peer_ready_run (void *cls, const struct GNUNET_TESTING_Command *cmd, @@ -80,6 +104,7 @@ send_peer_ready_run (void *cls, * Create command. * * @param label name for command. + * @param write_message Callback to write messages to the master loop. * @return command. */ struct GNUNET_TESTING_Command diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c index 2007b4ef3..f3a0b1a4c 100644 --- a/src/testing/testing_api_cmd_system_create.c +++ b/src/testing/testing_api_cmd_system_create.c @@ -28,6 +28,10 @@ #include "gnunet_testing_ng_lib.h" #include "gnunet_testing_lib.h" +/** + * Struct to hold information for callbacks. + * + */ struct TestSystemState { struct GNUNET_TESTING_System *test_system; @@ -36,6 +40,10 @@ struct TestSystemState }; +/** + * The run method of this cmd will setup a test environment for a node. + * + */ static void system_create_run (void *cls, const struct GNUNET_TESTING_Command *cmd, @@ -54,6 +62,11 @@ system_create_run (void *cls, "system created\n"); } + +/** + * This function prepares an array with traits. + * + */ static int system_create_traits (void *cls, const void **ret, @@ -79,6 +92,12 @@ system_create_traits (void *cls, } +/** + * Function to get the trait with struct GNUNET_TESTING_System + * + * @param[out] test_system The struct GNUNET_TESTING_System. + * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. + */ int GNUNET_TESTING_get_trait_test_system (const struct GNUNET_TESTING_Command *cmd, @@ -91,13 +110,16 @@ GNUNET_TESTING_get_trait_test_system (const struct } +/** + * The cleanup function of this cmd frees resources the cmd allocated. + * + */ static void system_create_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd) { struct TestSystemState *tss = cls; - GNUNET_free (tss->test_system); GNUNET_free (tss); } @@ -106,6 +128,7 @@ system_create_cleanup (void *cls, * Create command. * * @param label name for command. + * @param label name for the test environment directory. * @return command. */ struct GNUNET_TESTING_Command diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c index e94d8dad0..5ed0c2fd2 100644 --- a/src/testing/testing_api_cmd_system_destroy.c +++ b/src/testing/testing_api_cmd_system_destroy.c @@ -53,16 +53,10 @@ system_destroy_run (void *cls, const struct GNUNET_TESTING_Command *system_cmd; struct GNUNET_TESTING_System *tl_system; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "system destroy\n"); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "system destroyed\n"); } diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index f4fa4e17e..0c24c0e26 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -35,6 +35,7 @@ struct GNUNET_TESTING_Interpreter *is; + /** * Closure used to sync an asynchronous with an synchronous command. */ @@ -57,6 +58,7 @@ struct SyncTaskClosure struct GNUNET_TESTING_Interpreter *is; }; + /** * Closure used to run the finish task. */ @@ -74,6 +76,7 @@ struct FinishTaskClosure struct GNUNET_TESTING_Interpreter *is; }; + /** * Lookup command by label. * @@ -185,6 +188,10 @@ interpreter_next (void *cls) } +/** + * This function checks if the finish function of a command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called. + * + */ static void run_finish_task_next (void *cls) { @@ -212,6 +219,12 @@ run_finish_task_next (void *cls) } +/** + * This function checks if the finish function of an asynchronous command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called. + * + * //TODO run_finish_task_next and this function can be merged. + * + */ static void run_finish_task_sync (void *cls) { @@ -248,13 +261,17 @@ run_finish_task_sync (void *cls) } else { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sync task finished with an error.\n"); GNUNET_TESTING_interpreter_fail (); } } +/** + * run method of the command created by the interpreter to wait for another command to finish. + * + */ static void start_finish_on_ref (void *cls, const struct GNUNET_TESTING_Command *cmd, @@ -277,6 +294,17 @@ start_finish_on_ref (void *cls, } +/** + * Create (synchronous) command that waits for another command to finish. + * If @a cmd_ref did not finish after @a timeout, this command will fail + * the test case. + * + * @param finish_label label for this command + * @param cmd_ref reference to a previous command which we should + * wait for (call `finish()` on) + * @param timeout how long to wait at most for @a cmd_ref to finish + * @return a finish-command. + */ const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_finish (const char *finish_label, const char *cmd_ref, @@ -340,7 +368,7 @@ GNUNET_TESTING_interpreter_fail () while (GNUNET_TESTING_cmd_is_batch (cmd)) { cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Batch is at command `%s'\n", cmd->label); } @@ -354,7 +382,7 @@ GNUNET_TESTING_interpreter_fail () if (NULL == cmd->label) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed at command `%s'\n", cmd->label); @@ -415,7 +443,7 @@ interpreter_run (void *cls) if (NULL == cmd->label) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running command END %p\n", is); is->result = GNUNET_OK; @@ -424,7 +452,7 @@ interpreter_run (void *cls) } else if (NULL != cmd) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running command `%s' %p\n", cmd->label, is); @@ -478,8 +506,14 @@ do_shutdown (void *cls) for (unsigned int j = 0; NULL != (cmd = &is->commands[j])->label; j++) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up cmd %s\n", + cmd->label); cmd->cleanup (cmd->cls, cmd); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaned up cmd %s\n", + cmd->label); } if (NULL != is->finish_task) |