Go to the source code of this file.
Data Structures | |
struct | GNUNET_TESTING_AsyncContext |
State each asynchronous command must have in its closure. More... | |
struct | GNUNET_TESTING_CommandLabel |
Structure with storage space for a label. More... | |
struct | GNUNET_TESTING_Command |
A command to be run by the interpreter. More... | |
struct | GNUNET_TESTING_Timer |
Performance counter. More... | |
struct | GNUNET_TESTING_Trait |
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds. More... | |
Macros | |
#define | GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 |
Central interpreter and command loop for writing an interpreter to test asynchronous systems. More... | |
#define | GNUNET_TESTING_FAIL(is) |
Print failing line number and trigger shutdown. More... | |
#define | GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix, name, type) |
Create headers for a trait with name name for statically allocated data of type type. More... | |
#define | GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix, name, type) |
Create C implementation for a trait with name name for statically allocated data of type type. More... | |
#define | GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix, name, type) |
Create headers for a trait with name name for statically allocated data of type type. More... | |
#define | GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix, name, type) |
Create C implementation for a trait with name name for statically allocated data of type type. More... | |
#define | GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op, prefix) op (prefix, batch_cmds, struct GNUNET_TESTING_Command *) |
Call op on all simple traits needed by loop logic. More... | |
#define | GNUNET_TESTING_LOOP_INDEXED_TRAITS(op, prefix) op (prefix, cmd, const struct GNUNET_TESTING_Command) |
Call op on all indexed traits needed by loop logic. More... | |
Typedefs | |
typedef void(* | GNUNET_TESTING_CommandRunRoutine) (void *cls, struct GNUNET_TESTING_Interpreter *is) |
Signature of a function used to start executing a command of a test. More... | |
typedef void(* | GNUNET_TESTING_CommandCleanupRoutine) (void *cls) |
Signature of a function used to clean up resources allocated by a command. More... | |
typedef enum GNUNET_GenericReturnValue(* | GNUNET_TESTING_CommandGetTraits) (void *cls, const void **ret, const char *trait, unsigned int index) |
Signature of a function used to extract traits exposed by a command. More... | |
typedef void(* | GNUNET_TESTING_ResultCallback) (void *cls, enum GNUNET_GenericReturnValue rv) |
Function called with the final result of the test. More... | |
#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 |
Central interpreter and command loop for writing an interpreter to test asynchronous systems.
Definition at line 33 of file gnunet_testing_loop_lib.h.
#define GNUNET_TESTING_FAIL | ( | is | ) |
Print failing line number and trigger shutdown.
Useful quite any time after the command "run" method has been called.
Definition at line 41 of file gnunet_testing_loop_lib.h.
Create headers for a trait with name name for statically allocated data of type type.
prefix | symbol prefix to use |
name | name of the trait |
type | data type for the trait |
Definition at line 579 of file gnunet_testing_loop_lib.h.
Create C implementation for a trait with name name for statically allocated data of type type.
prefix | symbol prefix to use |
name | name of the trait |
type | data type for the trait |
Definition at line 597 of file gnunet_testing_loop_lib.h.
Create headers for a trait with name name for statically allocated data of type type.
prefix | symbol prefix to use |
name | name of the trait |
type | data type for the trait |
Definition at line 629 of file gnunet_testing_loop_lib.h.
Create C implementation for a trait with name name for statically allocated data of type type.
Definition at line 645 of file gnunet_testing_loop_lib.h.
#define GNUNET_TESTING_LOOP_SIMPLE_TRAITS | ( | op, | |
prefix | |||
) | op (prefix, batch_cmds, struct GNUNET_TESTING_Command *) |
Call op on all simple traits needed by loop logic.
op | operation to perform |
prefix | prefix to pass to op |
Definition at line 678 of file gnunet_testing_loop_lib.h.
#define GNUNET_TESTING_LOOP_INDEXED_TRAITS | ( | op, | |
prefix | |||
) | op (prefix, cmd, const struct GNUNET_TESTING_Command) |
Call op on all indexed traits needed by loop logic.
op | operation to perform |
prefix | prefix to pass to op |
Definition at line 688 of file gnunet_testing_loop_lib.h.
typedef void(* GNUNET_TESTING_CommandRunRoutine) (void *cls, struct GNUNET_TESTING_Interpreter *is) |
Signature of a function used to start executing a command of a test.
cls | closure |
is | interpreter running the command |
Definition at line 113 of file gnunet_testing_loop_lib.h.
typedef void(* GNUNET_TESTING_CommandCleanupRoutine) (void *cls) |
Signature of a function used to clean up resources allocated by a command.
cls | closure |
Definition at line 124 of file gnunet_testing_loop_lib.h.
typedef enum GNUNET_GenericReturnValue(* GNUNET_TESTING_CommandGetTraits) (void *cls, const void **ret, const char *trait, unsigned int index) |
Signature of a function used to extract traits exposed by a command.
cls | closure | |
[out] | ret | where to return the trait data |
trait | name of the trait to return | |
index | index of the trait (for traits that are indexed) |
Definition at line 124 of file gnunet_testing_loop_lib.h.
typedef void(* GNUNET_TESTING_ResultCallback) (void *cls, enum GNUNET_GenericReturnValue rv) |
Function called with the final result of the test.
FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g. GNUNET_EC_TESTING_*)
cls | closure |
rv | GNUNET_OK if the test passed |
Definition at line 404 of file gnunet_testing_loop_lib.h.
void GNUNET_TESTING_async_fail | ( | struct GNUNET_TESTING_AsyncContext * | ac | ) |
The asynchronous command of ac has failed.
ac | command-specific context |
Definition at line 514 of file testing_api_loop.c.
References GNUNET_TESTING_Command::ac, GNUNET_TESTING_AsyncContext::cont, GNUNET_TESTING_AsyncContext::cont_cls, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, GNUNET_TESTING_interpreter_fail(), and GNUNET_TESTING_AsyncContext::is.
Referenced by child_completed_callback(), exp_cb(), helper_mst(), 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 528 of file testing_api_loop.c.
References GNUNET_TESTING_Command::ac, GNUNET_TESTING_AsyncContext::cont, GNUNET_TESTING_AsyncContext::cont_cls, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, and GNUNET_OK.
Referenced by backchannel_check_run(), child_completed_callback(), do_timeout(), done_finish(), GNUNET_TESTING_finish_barrier_(), hello_iter_cb(), helper_mst(), notify_connect(), read_from_log(), run_finish(), send_run(), and send_simple_single().
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new | ( | void * | cls, |
const char * | label, | ||
GNUNET_TESTING_CommandRunRoutine | run, | ||
GNUNET_TESTING_CommandCleanupRoutine | cleanup, | ||
GNUNET_TESTING_CommandGetTraits | traits, | ||
struct GNUNET_TESTING_AsyncContext * | ac | ||
) |
Create a new command.
cls | the closure |
label | the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH |
run | the run routing |
cleanup | the cleanup function |
traits | the traits function (optional) |
the | async context |
Definition at line 666 of file testing_api_loop.c.
References GNUNET_TESTING_Command::ac, cleanup(), GNUNET_TESTING_Command::cls, GNUNET_assert, GNUNET_TESTING_set_label(), GNUNET_TESTING_Command::label, run(), and GNUNET_TESTING_Command::traits.
Referenced by GNUNET_CORE_cmd_connect_peers(), GNUNET_MESSENGER_cmd_join_room(), GNUNET_MESSENGER_cmd_start_service(), GNUNET_MESSENGER_cmd_stop_service(), GNUNET_TESTING_cmd_barrier_create(), GNUNET_TESTING_cmd_barrier_reached(), GNUNET_TESTING_cmd_batch(), GNUNET_TESTING_cmd_block_until_external_trigger(), GNUNET_TESTING_cmd_exec_bash_script(), GNUNET_TESTING_cmd_finish(), GNUNET_TESTING_cmd_local_test_prepared(), GNUNET_TESTING_cmd_netjail_start(), GNUNET_TESTING_cmd_netjail_start_cmds_helper(), GNUNET_TESTING_cmd_netjail_stop(), GNUNET_TESTING_cmd_send_peer_ready(), GNUNET_TESTING_cmd_start_peer(), GNUNET_TESTING_cmd_stop_cmds_helper(), GNUNET_TESTING_cmd_stop_peer(), GNUNET_TESTING_cmd_system_create(), GNUNET_TESTING_cmd_system_destroy(), GNUNET_TRANSPORT_cmd_backchannel_check(), GNUNET_TRANSPORT_cmd_connect_peers(), GNUNET_TRANSPORT_cmd_send_simple(), GNUNET_TRANSPORT_cmd_send_simple_performance(), GNUNET_TRANSPORT_cmd_start_peer(), and GNUNET_TRANSPORT_cmd_stop_peer().
void GNUNET_TESTING_set_label | ( | struct GNUNET_TESTING_CommandLabel * | label, |
const char * | value | ||
) |
Set label to value.
Asserts that value is not longer than GNUNET_TESTING_CMD_MAX_LABEL_LENGTH.
[out] | label | label to initialize |
value | value to store into label |
Definition at line 690 of file testing_api_loop.c.
References GNUNET_assert, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH, GNUNET_TESTING_Command::label, value, and GNUNET_TESTING_CommandLabel::value.
Referenced by GNUNET_TESTING_cmd_batch(), GNUNET_TESTING_command_new(), and GNUNET_TESTING_DHTU_cmd_send().
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 193 of file testing_api_loop.c.
References get_command(), 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.
is | interpreter to lookup command in |
label | label of the command to lookup. |
Definition at line 204 of file testing_api_loop.c.
References get_command(), is, and GNUNET_TESTING_Command::label.
Referenced by backchannel_check_run(), connect_peers_run(), join_room_run(), run_finish(), send_simple_run(), start_peer_run(), start_service_run(), stop_peer_run(), stop_service_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 future are looked up.
is | interpreter to lookup command in |
label | label of the command to lookup. |
Definition at line 215 of file testing_api_loop.c.
References get_command(), is, and GNUNET_TESTING_Command::label.
Referenced by notify_connect().
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 479 of file testing_api_loop.c.
References GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Interpreter::final_task, 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_(), GNUNET_TESTING_Interpreter::ip, is, GNUNET_TESTING_Command::label, GNUNET_TESTING_Interpreter::result, and GNUNET_TESTING_CommandLabel::value.
Referenced by connect_peers_run(), exec_bash_script_run(), GNUNET_TESTING_async_fail(), join_room_run(), netjail_start_run(), netjail_stop_run(), on_message_cb(), run_finish(), start_helper(), start_peer_run(), and start_service_run().
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_make_unblocking | ( | struct GNUNET_TESTING_Command | cmd | ) |
Turn asynchronous command into non-blocking command by setting asynchronous_finish to true.
Modifies (and then returns) cmd simply setting the bit. By default, most commands are blocking, and by wrapping the command construction in this function a blocking command can be turned into an asynchronous command where the interpreter continues after initiating the asynchronous action. Does nothing if the command is fundamentally synchronous.
[in,out] | cmd | command to make non-blocking |
Definition at line 188 of file testing_api_cmd_finish.c.
References GNUNET_assert, and run_finish().
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_finish | ( | const char * | finish_label, |
const char * | cmd_ref, | ||
struct GNUNET_TIME_Relative | timeout | ||
) |
Create (synchronous) command that waits for another command to finish.
If cmd_ref did not finish after timeout, this command will fail the test case.
finish_label | label for this command |
cmd_ref | reference to a previous command which we should wait for (call finish() on) |
timeout | how long to wait at most for cmd_ref to finish |
Definition at line 171 of file testing_api_cmd_finish.c.
References FinishState::ac, FinishState::async_label, cleanup_finish(), GNUNET_new, GNUNET_TESTING_command_new(), run_finish(), timeout, and FinishState::timeout.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_rewind_ip | ( | const char * | label, |
const char * | target_label, | ||
unsigned int | counter | ||
) |
Make the instruction pointer point to target_label only if counter is greater than zero.
label | command label |
target_label | label of the new instruction pointer's destination after the jump; must be before the current instruction |
counter | counts how many times the rewinding is to happen. |
struct GNUNET_TESTING_Interpreter * GNUNET_TESTING_run | ( | const 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 array 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 627 of file testing_api_loop.c.
References GNUNET_TESTING_Interpreter::barriers, GNUNET_TESTING_Interpreter::cmds_n, commands, GNUNET_TESTING_Interpreter::commands, do_timeout(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc_large, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), interpreter_run(), is, GNUNET_TESTING_Interpreter::rc, GNUNET_TESTING_Interpreter::rc_cls, GNUNET_TESTING_Interpreter::task, timeout, and GNUNET_TESTING_Interpreter::timeout_task.
Referenced by loop_run().
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(). FIXME: Why is this commands array here not const?
commands | the list of command to execute |
timeout | how long to wait for each command to execute |
Definition at line 778 of file testing_api_loop.c.
References commands, MainParams::commands, GNUNET_SCHEDULER_run(), loop_run(), MainParams::rv, and timeout.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end | ( | void | ) |
Create command array terminator.
Definition at line 706 of file testing_api_loop.c.
References GNUNET_TESTING_Command::run.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch | ( | const char * | label, |
struct GNUNET_TESTING_Command * | batch | ||
) |
Create a "batch" command.
Such command takes a end_CMD-terminated array of CMDs and executed them. Once it hits the end CMD, it passes the control to the next top-level CMD, regardless of it being another batch or ordinary CMD.
label | the command label. |
batch | array of CMDs to execute. |
Definition at line 155 of file testing_api_cmd_batch.c.
References BatchState::batch, batch_cleanup(), batch_run(), batch_traits(), GNUNET_new, GNUNET_new_array, GNUNET_TESTING_command_new(), GNUNET_TESTING_set_label(), BatchState::label, and GNUNET_TESTING_Command::run.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat | ( | struct GNUNET_TESTING_Timer * | timers | ) |
Obtain performance data from the interpreter.
[in,out] | timers | what commands (by label) to obtain runtimes for |
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end | ( | void | ) |
"end" of traits array.
Because traits are offered into arrays, this type of trait is used to mark the end of such arrays; useful when iterating over those.
"end" of traits array.
Usually, commands offer several traits, and put them in arrays.
Definition at line 52 of file testing_api_traits.c.
References end.
Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), block_until_external_trigger_traits(), connect_peers_traits(), local_test_prepared_traits(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), and system_create_traits().
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait | ( | const struct GNUNET_TESTING_Trait * | traits, |
const void ** | ret, | ||
const char * | trait, | ||
unsigned int | index | ||
) |
Obtain value of a trait from a command.
traits | the array of all the traits. | |
[out] | ret | where to store the result. |
trait | type of the trait to extract. | |
index | index number of the trait to extract. |
Obtain value of a trait from a command.
traits | the traits array. |
ret | where to store the result. |
trait | type of the trait to extract. |
index | index number of the object to extract. |
Definition at line 74 of file testing_api_traits.c.
References GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_Trait::index, GNUNET_TESTING_Trait::ptr, ret, and GNUNET_TESTING_Trait::trait_name.
Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), block_until_external_trigger_traits(), connect_peers_traits(), local_test_prepared_traits(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), and system_create_traits().
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_batch_cmds | ( | const struct GNUNET_TESTING_Command * | cmd, |
struct GNUNET_TESTING_Command *** | ret | ||
) |
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_batch_cmds | ( | struct GNUNET_TESTING_Command ** | value | ) |
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd | ( | const struct GNUNET_TESTING_Command * | cmd, |
unsigned int | index, | ||
const struct GNUNET_TESTING_Command ** | ret | ||
) |
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd | ( | unsigned int | index, |
const struct GNUNET_TESTING_Command * | value | ||
) |