27#ifndef GNUNET_TESTING_LIB_H
28#define GNUNET_TESTING_LIB_H
35#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
44#define GNUNET_TESTING_FAIL(is) \
47 GNUNET_TESTING_interpreter_fail (is); \
58#define GNUNET_TESTING_command_incomplete(is,label) \
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
61 "Command %s (%s:%u) did not complete (at %s)\n", \
65 GNUNET_TESTING_interpreter_current_cmd_get_label (is)); \
209#define GNUNET_TESTING_command_new(cls,label,run,cleanup,traits) \
210 GNUNET_TESTING_command_new_ac (cls,label,run,cleanup,traits,NULL)
551 unsigned int number_to_be_reached);
565 const char *barrier_label);
568#define GNUNET_TESTING_NETJAIL_START_SCRIPT "netjail_start_new.sh"
570#define GNUNET_TESTING_NETJAIL_STOP_SCRIPT "netjail_stop.sh"
583 const char *topology_cmd_label,
600 const char *topology_cmd_label);
612 const char *topology_data);
645 const char *finish_label,
661 const char *process_label,
687 unsigned long int expected_exit_code,
688 char *
const script_argv[]);
700 unsigned long int expected_exit_code,
720 const char *target_label,
721 unsigned int counter);
784#define GNUNET_TESTING_MAKE_PLUGIN(prefix,name,...) \
786 prefix ## _plugin_ ## name ## _init (void *cls) { \
787 const char *my_node_id = cls; (void) my_node_id; \
788 struct GNUNET_TESTING_Command commands[] = { \
790 GNUNET_TESTING_cmd_end () \
792 return GNUNET_TESTING_make_plugin (commands); \
795 prefix ## _plugin_ ## name ## _done (void *cls) { \
796 struct GNUNET_TESTING_PluginFunctions *api = cls; \
868#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \
869 enum GNUNET_GenericReturnValue \
870 prefix ## _get_trait_ ## name ( \
871 const struct GNUNET_TESTING_Command *cmd, \
873 struct GNUNET_TESTING_Trait \
874 prefix ## _make_trait_ ## name ( \
886#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix,name,type) \
887 enum GNUNET_GenericReturnValue \
888 prefix ## _get_trait_ ## name ( \
889 const struct GNUNET_TESTING_Command *cmd, \
892 if (NULL == cmd->traits) return GNUNET_SYSERR; \
893 return cmd->traits (cmd->cls, \
894 (const void **) ret, \
898 struct GNUNET_TESTING_Trait \
899 prefix ## _make_trait_ ## name ( \
902 struct GNUNET_TESTING_Trait ret = { \
903 .trait_name = GNUNET_S (name), \
904 .ptr = (const void *) value \
918#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \
919 enum GNUNET_GenericReturnValue \
920 prefix ## _get_trait_ ## name ( \
921 const struct GNUNET_TESTING_Command *cmd, \
922 unsigned int index, \
924 struct GNUNET_TESTING_Trait \
925 prefix ## _make_trait_ ## name ( \
926 unsigned int index, \
934#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \
935 enum GNUNET_GenericReturnValue \
936 prefix ## _get_trait_ ## name ( \
937 const struct GNUNET_TESTING_Command *cmd, \
938 unsigned int index, \
941 if (NULL == cmd->traits) return GNUNET_SYSERR; \
942 return cmd->traits (cmd->cls, \
943 (const void **) ret, \
947 struct GNUNET_TESTING_Trait \
948 prefix ## _make_trait_ ## name ( \
949 unsigned int index, \
952 struct GNUNET_TESTING_Trait ret = { \
954 .trait_name = GNUNET_S (name), \
955 .ptr = (const void *) value \
967#define GNUNET_TESTING_SIMPLE_TRAITS(op,prefix) \
968 op (prefix, process, struct GNUNET_OS_Process *) \
969 op (prefix, cmd, const struct GNUNET_TESTING_Command) \
970 op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
static int ret
Final status code.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
static struct GNUNET_TESTING_Interpreter * is
static struct VoipCommand commands[]
List of supported commands.
static void cleanup(void *cls)
Disconnect and shutdown.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
#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.
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec(const char *label, enum GNUNET_OS_ProcessStatusType expected_type, unsigned long int expected_exit_code, char *const script_argv[])
Command to execute a command.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(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 that may be asynchronous.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep(const char *label, struct GNUNET_TIME_Relative duration)
Sleep for duration.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_helpers(const char *label, const char *topology_cmd_label, struct GNUNET_TIME_Relative timeout)
Create command.
void(* GNUNET_TESTING_CommandRunRoutine)(void *cls, struct GNUNET_TESTING_Interpreter *is)
Signature of a function used to start executing a command of a test.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create(const char *label, unsigned int number_to_be_reached)
Command to create a barrier.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_setup(const char *label, const char *script, const char *topology_cmd_label)
This command executes a shell script to setup the netjail environment.
void GNUNET_TESTING_interpreter_current_cmd_touch(struct GNUNET_TESTING_Interpreter *is)
Update the last request time of the current command to the current time.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch(const char *label, struct GNUNET_TESTING_Command *batch)
Create a "batch" command.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_string(const char *label, const char *topology_data)
void GNUNET_TESTING_interpreter_commands_iterate(struct GNUNET_TESTING_Interpreter *is, bool asc, GNUNET_TESTING_CommandIterator cb, void *cb_cls)
Iterates over all of the top-level commands of an interpreter.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal(const char *label, const char *process_label, int signal)
Create a "signal" CMD.
void(* GNUNET_TESTING_CommandCleanupRoutine)(void *cls)
Signature of a function used to clean up resources allocated by a command.
void(* GNUNET_TESTING_CommandIterator)(void *cls, const struct GNUNET_TESTING_Command *cmd)
Callback over commands of an interpreter.
const char * GNUNET_TESTING_interpreter_current_cmd_get_label(struct GNUNET_TESTING_Interpreter *is)
Obtain label of the command being now run.
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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_file(const char *label, const char *filename)
void(* GNUNET_TESTING_ResultCallback)(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_TESTING_interpreter_skip(struct GNUNET_TESTING_Interpreter *is)
Skips the current test, the environment is not prepared correctly.
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.
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.
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.
void GNUNET_TESTING_interpreter_current_cmd_inc_tries(struct GNUNET_TESTING_Interpreter *is)
Increment the 'num_tries' counter for the current command.
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec_va(const char *label, enum GNUNET_OS_ProcessStatusType expected_type, unsigned long int expected_exit_code,...)
Command to execute a command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat(const char *label, struct GNUNET_TESTING_Timer *timers)
Obtain performance data from the interpreter.
int GNUNET_TESTING_main(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
Start a GNUnet scheduler event loop and run the testsuite.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_set_var(const char *name, struct GNUNET_TESTING_Command cmd)
Set variable to command as side-effect of running a command.
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.
struct GNUNET_TESTING_PluginFunctions * GNUNET_TESTING_make_plugin(const struct GNUNET_TESTING_Command *commands)
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
Central interpreter and command loop for writing an interpreter to test asynchronous systems.
#define GNUNET_TESTING_SIMPLE_TRAITS(op, prefix)
Call op on all simple traits needed by testing core logic.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_command(struct GNUNET_TESTING_Interpreter *is, const char *name)
Get command from hash map by variable name.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached(const char *label, const char *barrier_label)
If this command is executed the the process is signaling the master process that it reached a barrier...
GNUNET_GenericReturnValue
Named constants for return values.
GNUNET_OS_ProcessStatusType
Process status types.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
State each asynchronous command must have in its closure.
GNUNET_SCHEDULER_TaskCallback notify_finished
Function to call when async operation is done.
bool next_called
Set to true if interpreter_next() has already been called for this command.
struct GNUNET_TESTING_Interpreter * is
Interpreter we are part of.
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).
void * notify_finished_cls
Closure for notify_finished.
Structure with storage space for a label.
A command to be run by the interpreter.
GNUNET_TESTING_CommandCleanupRoutine cleanup
Clean up after the command.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
const char * name
Variable name for the command, NULL for none.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
struct GNUNET_TIME_Absolute last_req_time
When did we start the last run of this command? Delta to finish_time gives the latency for the last s...
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
bool asynchronous_finish
If "true", the interpreter should not immediately run the next command, even if this command did not ...
GNUNET_TESTING_CommandGetTraits traits
Extract information from a command that is useful for other commands.
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated....
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
GNUNET_TESTING_ResultCallback rc
Function to call with the test result.
void * rc_cls
Closure for rc.
The plugin API every test case plugin has to implement.
unsigned int num_commands
Number of commands summed up.
const char * prefix
For which type of commands.
struct GNUNET_TIME_Relative total_duration
Total time spend in all commands of this type.
unsigned int num_retries
Number of retries summed up.
struct GNUNET_TIME_Relative success_latency
Total time spend waiting for the successful execution in all commands of this type.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
const void * ptr
Pointer to the piece of data to offer.
unsigned int index
Index number associated with the trait.
const char * trait_name
Trait type, for example "reserve-pub" or "coin-priv".
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.