![]() |
GNUnet
0.16.x
|
main interpreter loop for testcases More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "testing.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_TESTING_Interpreter |
Global state of the interpreter, used by a command to access information about other commands. More... | |
struct | MainParams |
Closure for loop_run(). More... | |
Functions | |
const struct GNUNET_TESTING_Command * | get_command (struct GNUNET_TESTING_Interpreter *is, const char *label, unsigned int future) |
const struct GNUNET_TESTING_Command * | GNUNET_TESTING_interpreter_lookup_future_command (struct GNUNET_TESTING_Interpreter *is, const char *label) |
Lookup command by label. More... | |
const struct GNUNET_TESTING_Command * | GNUNET_TESTING_interpreter_lookup_command (struct GNUNET_TESTING_Interpreter *is, const char *label) |
Lookup command by label. More... | |
const struct GNUNET_TESTING_Command * | GNUNET_TESTING_interpreter_lookup_command_all (struct GNUNET_TESTING_Interpreter *is, const char *label) |
Lookup command by label. More... | |
static void | finish_test (void *cls) |
Finish the test run, return the final result. More... | |
static void | interpreter_run (void *cls) |
Run the main interpreter loop that performs exchange operations. More... | |
static void | interpreter_next (void *cls) |
Current command is done, run the next one. More... | |
void | GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is) |
Current command failed, clean up and fail the test case. More... | |
struct GNUNET_TESTING_Command * | GNUNET_TESTING_interpreter_get_current_command (struct GNUNET_TESTING_Interpreter *is) |
Returns the actual running command. More... | |
const char * | GNUNET_TESTING_interpreter_get_current_label (struct GNUNET_TESTING_Interpreter *is) |
Obtain label of the command being now run. More... | |
static void | do_timeout (void *cls) |
Function run when the test terminates (good or bad) with timeout. More... | |
enum GNUNET_GenericReturnValue | GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command) |
Check if the command is running. More... | |
enum GNUNET_GenericReturnValue | GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command) |
Check if a command is finished. More... | |
void | GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls) |
Run the testsuite. More... | |
static void | handle_result (void *cls, enum GNUNET_GenericReturnValue rv) |
Function called with the final result of the test. More... | |
static void | loop_run (void *cls) |
Main function to run the test cases. More... | |
int | GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout) |
Start a GNUnet scheduler event loop and run the testsuite. More... | |
void | GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac) |
The asynchronous command of ac has failed. More... | |
void | GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac) |
The asynchronous command of ac has finished. More... | |
main interpreter loop for testcases
Definition in file testing_api_loop.c.
const struct GNUNET_TESTING_Command* get_command | ( | struct GNUNET_TESTING_Interpreter * | is, |
const char * | label, | ||
unsigned int | future | ||
) |
Definition at line 91 of file testing_api_loop.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_TESTING_cmd_batch_get_current_(), GNUNET_TESTING_cmd_is_batch_(), GNUNET_TESTING_get_trait_batch_cmds(), is, and GNUNET_TESTING_Command::label.
Referenced by GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_interpreter_lookup_command_all(), and GNUNET_TESTING_interpreter_lookup_future_command().
const struct GNUNET_TESTING_Command* GNUNET_TESTING_interpreter_lookup_future_command | ( | struct GNUNET_TESTING_Interpreter * | is, |
const char * | label | ||
) |
Lookup command by label.
Only future commands are looked up.
is | interpreter to lookup command in |
label | label of the command to lookup. |
Definition at line 167 of file testing_api_loop.c.
References get_command(), GNUNET_YES, is, and GNUNET_TESTING_Command::label.
const struct GNUNET_TESTING_Command* GNUNET_TESTING_interpreter_lookup_command | ( | struct GNUNET_TESTING_Interpreter * | is, |
const char * | label | ||
) |
Lookup command by label.
Only commands from current command to commands in the past are looked up.
is | interpreter to lookup command in |
label | label of the command to lookup. |
Definition at line 184 of file testing_api_loop.c.
References get_command(), GNUNET_NO, is, and GNUNET_TESTING_Command::label.
Referenced by backchannel_check_run(), connect_peers_run(), run_finish(), send_simple_run(), start_peer_run(), stop_peer_run(), stop_testing_system_run(), and system_destroy_run().
const struct GNUNET_TESTING_Command* GNUNET_TESTING_interpreter_lookup_command_all | ( | struct GNUNET_TESTING_Interpreter * | is, |
const char * | label | ||
) |
Lookup command by label.
All commands, first into the past, then into the furture are looked up.
is | interpreter to lookup command in |
label | label of the command to lookup. |
Definition at line 201 of file testing_api_loop.c.
References get_command(), GNUNET_NO, GNUNET_YES, is, and GNUNET_TESTING_Command::label.
Referenced by notify_connect().
|
static |
Finish the test run, return the final result.
cls | the struct GNUNET_TESTING_Interpreter |
Definition at line 220 of file testing_api_loop.c.
References GNUNET_TESTING_Command::cleanup, GNUNET_TESTING_Command::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), is, and GNUNET_TESTING_Command::label.
Referenced by do_timeout(), GNUNET_TESTING_interpreter_fail(), and interpreter_run().
|
static |
Run the main interpreter loop that performs exchange operations.
Run the main interpreter loop.
cls | contains the struct InterpreterState |
cls | contains the struct GNUNET_TESTING_Interpreter |
Definition at line 370 of file testing_api_loop.c.
References GNUNET_TIME_Absolute::abs_value_us, GNUNET_TESTING_Command::ac, GNUNET_TESTING_Command::asynchronous_finish, GNUNET_TESTING_Command::cls, GNUNET_TESTING_AsyncContext::cont, GNUNET_TESTING_AsyncContext::cont_cls, finish_test(), GNUNET_TESTING_AsyncContext::finished, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_get(), interpreter_next(), GNUNET_TESTING_AsyncContext::is, is, GNUNET_TESTING_Command::label, GNUNET_TESTING_Command::last_req_time, GNUNET_TESTING_Command::num_tries, GNUNET_TESTING_Command::run, and GNUNET_TESTING_Command::start_time.
Referenced by GNUNET_TESTING_run(), and interpreter_next().
|
static |
Current command is done, run the next one.
Definition at line 276 of file testing_api_loop.c.
References GNUNET_TESTING_Command::cls, GNUNET_TESTING_Command::finish_time, GNUNET_ERROR_TYPE_MESSAGE, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TESTING_cmd_batch_next_(), GNUNET_TESTING_cmd_is_batch_(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, interpreter_run(), and is.
Referenced by interpreter_run().
void GNUNET_TESTING_interpreter_fail | ( | struct GNUNET_TESTING_Interpreter * | is | ) |
Current command failed, clean up and fail the test case.
is | interpreter state. |
Definition at line 306 of file testing_api_loop.c.
References finish_test(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, GNUNET_TESTING_cmd_batch_get_current_(), GNUNET_TESTING_cmd_is_batch_(), is, and GNUNET_TESTING_Command::label.
Referenced by GNUNET_TESTING_async_fail(), netjail_stop_run(), run_finish(), start_helper(), and start_peer_run().
struct GNUNET_TESTING_Command* GNUNET_TESTING_interpreter_get_current_command | ( | struct GNUNET_TESTING_Interpreter * | is | ) |
Returns the actual running command.
is | Global state of the interpreter, used by a command to access information about other commands. |
Definition at line 348 of file testing_api_loop.c.
References is.
Referenced by block_until_all_peers_started_run(), and do_timeout().
const char* GNUNET_TESTING_interpreter_get_current_label | ( | struct GNUNET_TESTING_Interpreter * | is | ) |
Obtain label of the command being now run.
is | interpreter state. |
Definition at line 355 of file testing_api_loop.c.
References is, and GNUNET_TESTING_Command::label.
|
static |
Function run when the test terminates (good or bad) with timeout.
cls | the interpreter state |
Definition at line 427 of file testing_api_loop.c.
References finish_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SYSERR, and is.
Referenced by GNUNET_TESTING_run().
enum GNUNET_GenericReturnValue GNUNET_TESTING_running | ( | const struct GNUNET_TESTING_Command * | command | ) |
Check if the command is running.
cmd | The command to check. |
Definition at line 427 of file testing_api_loop.c.
enum GNUNET_GenericReturnValue GNUNET_TESTING_finished | ( | struct GNUNET_TESTING_Command * | command | ) |
Check if a command is finished.
cmd | The command to check. |
Definition at line 427 of file testing_api_loop.c.
void GNUNET_TESTING_run | ( | struct GNUNET_TESTING_Command * | commands, |
struct GNUNET_TIME_Relative | timeout, | ||
GNUNET_TESTING_ResultCallback | rc, | ||
void * | rc_cls | ||
) |
Run the testsuite.
Note, CMDs are copied into the interpreter state because they are usually defined into the "run" method that returns after having scheduled the test interpreter.
commands | the list of command to execute |
timeout | how long to wait for each command to execute |
rc | function to call with the final result |
rc_cls | closure for rc |
Definition at line 471 of file testing_api_loop.c.
References commands, do_timeout(), GNUNET_new, GNUNET_new_array, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), interpreter_run(), is, GNUNET_TESTING_Interpreter::rc, GNUNET_TESTING_Interpreter::rc_cls, and timeout.
Referenced by loop_run().
|
static |
Function called with the final result of the test.
cls | the struct MainParams |
rv | GNUNET_OK if the test passed |
Definition at line 530 of file testing_api_loop.c.
References GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_shutdown(), and MainParams::rv.
Referenced by loop_run().
|
static |
Main function to run the test cases.
cls | a struct MainParams * |
Definition at line 550 of file testing_api_loop.c.
References MainParams::commands, GNUNET_TESTING_run(), handle_result(), and MainParams::timeout.
Referenced by GNUNET_TESTING_main().
int GNUNET_TESTING_main | ( | struct GNUNET_TESTING_Command * | commands, |
struct GNUNET_TIME_Relative | timeout | ||
) |
Start a GNUnet scheduler event loop and run the testsuite.
Return 0 upon success. Expected to be called directly from main().
commands | the list of command to execute |
timeout | how long to wait for each command to execute |
Definition at line 562 of file testing_api_loop.c.
References commands, MainParams::commands, GNUNET_SCHEDULER_run(), loop_run(), MainParams::rv, and timeout.
void GNUNET_TESTING_async_fail | ( | struct GNUNET_TESTING_AsyncContext * | ac | ) |
The asynchronous command of ac has failed.
ac | command-specific context |
Definition at line 578 of file testing_api_loop.c.
References ac, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, and GNUNET_TESTING_interpreter_fail().
Referenced by child_completed_callback(), exp_cb(), and timeout_finish().
void GNUNET_TESTING_async_finish | ( | struct GNUNET_TESTING_AsyncContext * | ac | ) |
The asynchronous command of ac has finished.
ac | command-specific context |
Definition at line 592 of file testing_api_loop.c.
References ac, GNUNET_assert, GNUNET_NO, and GNUNET_OK.
Referenced by backchannel_check_run(), child_completed_callback(), do_timeout(), done_finish(), hello_iter_cb(), helper_mst(), notify_connect(), read_from_log(), and run_finish().