GNUnet 0.21.2
gnunet_testing_lib.h File Reference
#include "gnunet_util_lib.h"
Include dependency graph for gnunet_testing_lib.h:
This graph shows which files directly or indirectly include this file:

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_command_incomplete(is, label)
 Log an error message about a command not having run to completion. More...
 
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)    GNUNET_TESTING_command_new_ac (cls,label,run,cleanup,traits,NULL)
 Create a new command. More...
 
#define GNUNET_TESTING_NETJAIL_START_SCRIPT   "netjail_start_new.sh"
 
#define GNUNET_TESTING_NETJAIL_STOP_SCRIPT   "netjail_stop.sh"
 
#define GNUNET_TESTING_MAKE_PLUGIN(prefix, name, ...)
 
#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_SIMPLE_TRAITS(op, prefix)
 Call op on all simple traits needed by testing core 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_CommandIterator) (void *cls, const struct GNUNET_TESTING_Command *cmd)
 Callback over commands of an interpreter. More...
 
typedef void(* GNUNET_TESTING_ResultCallback) (void *cls, enum GNUNET_GenericReturnValue rv)
 Function called with the final result of the test. More...
 

Functions

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...
 
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. More...
 
void GNUNET_TESTING_set_label (struct GNUNET_TESTING_CommandLabel *label, const char *value)
 Set label to value. More...
 
const struct GNUNET_TESTING_CommandGNUNET_TESTING_interpreter_lookup_command (struct GNUNET_TESTING_Interpreter *is, const char *label)
 Lookup command by label. More...
 
const struct GNUNET_TESTING_CommandGNUNET_TESTING_interpreter_get_command (struct GNUNET_TESTING_Interpreter *is, const char *name)
 Get command from hash map by variable name. More...
 
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. More...
 
void GNUNET_TESTING_interpreter_current_cmd_inc_tries (struct GNUNET_TESTING_Interpreter *is)
 Increment the 'num_tries' counter for the current command. More...
 
const char * GNUNET_TESTING_interpreter_current_cmd_get_label (struct GNUNET_TESTING_Interpreter *is)
 Obtain label of the command being now run. More...
 
void GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
 Current command failed, clean up and fail the test case. More...
 
void GNUNET_TESTING_interpreter_skip (struct GNUNET_TESTING_Interpreter *is)
 Skips the current test, the environment is not prepared correctly. More...
 
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. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end (void)
 Create command array terminator. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch (const char *label, struct GNUNET_TESTING_Command *batch)
 Create a "batch" command. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat (const char *label, struct GNUNET_TESTING_Timer *timers)
 Obtain performance data from the interpreter. More...
 
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. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create (const char *label, unsigned int number_to_be_reached)
 Command to create a barrier. More...
 
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. More...
 
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. More...
 
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. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_file (const char *label, const char *filename)
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_string (const char *label, const char *topology_data)
 
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. More...
 
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. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal (const char *label, const char *process_label, int signal)
 Create a "signal" CMD. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep (const char *label, struct GNUNET_TIME_Relative duration)
 Sleep for duration. More...
 
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. More...
 
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. More...
 
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. More...
 
struct GNUNET_TESTING_InterpreterGNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
 Run the testsuite. More...
 
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. More...
 
struct GNUNET_TESTING_PluginFunctionsGNUNET_TESTING_make_plugin (const struct GNUNET_TESTING_Command *commands)
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end (void)
 "end" of traits array. More...
 
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. More...
 
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, struct GNUNET_OS_Process ***ret)
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process (struct GNUNET_OS_Process **value)
 
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_Command **ret)
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd (const struct GNUNET_TESTING_Command *value)
 
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)
 

Macro Definition Documentation

◆ GNUNET_TESTING_CMD_MAX_LABEL_LENGTH

#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH   127

Central interpreter and command loop for writing an interpreter to test asynchronous systems.

Author
Christian Grothoff chris.nosp@m.tian.nosp@m.@grot.nosp@m.hoff.nosp@m..org
Marcello Stanisci
t3sserakt Maximum length of label in command

Definition at line 35 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_FAIL

#define GNUNET_TESTING_FAIL (   is)
Value:
do { \
GNUNET_break (0); \
GNUNET_TESTING_interpreter_fail (is); \
return; \
} while (0)
static struct GNUNET_TESTING_Interpreter * is

Print failing line number and trigger shutdown.

Useful quite any time after the command "run" method has been called. Returns from the current function.

Definition at line 44 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_command_incomplete

#define GNUNET_TESTING_command_incomplete (   is,
  label 
)
Value:
do { \
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
"Command %s (%s:%u) did not complete (at %s)\n", \
label, \
__FILE__, \
__LINE__, \
} while (0)
const char * GNUNET_TESTING_interpreter_current_cmd_get_label(struct GNUNET_TESTING_Interpreter *is)
Obtain label of the command being now run.
@ GNUNET_ERROR_TYPE_ERROR

Log an error message about a command not having run to completion.

Parameters
isinterpreter
labelcommand label of the incomplete command

Definition at line 58 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_command_new

#define GNUNET_TESTING_command_new (   cls,
  label,
  run,
  cleanup,
  traits 
)     GNUNET_TESTING_command_new_ac (cls,label,run,cleanup,traits,NULL)

Create a new command.

Parameters
clsthe closure
labelthe Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
runthe run routing
cleanupthe cleanup function
traitsthe traits function (optional)
Returns
the command the function cannot fail

Definition at line 209 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_NETJAIL_START_SCRIPT

#define GNUNET_TESTING_NETJAIL_START_SCRIPT   "netjail_start_new.sh"

Definition at line 568 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_NETJAIL_STOP_SCRIPT

#define GNUNET_TESTING_NETJAIL_STOP_SCRIPT   "netjail_stop.sh"

Definition at line 570 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_MAKE_PLUGIN

#define GNUNET_TESTING_MAKE_PLUGIN (   prefix,
  name,
  ... 
)
Value:
void * \
prefix ## _plugin_ ## name ## _init (void *cls) { \
const char *my_node_id = cls; (void) my_node_id; \
__VA_ARGS__, \
GNUNET_TESTING_cmd_end () \
}; \
} \
void * \
prefix ## _plugin_ ## name ## _done (void *cls) { \
struct GNUNET_TESTING_PluginFunctions *api = cls; \
GNUNET_free (api); \
return NULL; \
}
static const char * my_node_id
static struct VoipCommand commands[]
List of supported commands.
static char * name
Name (label) of the records to list.
struct GNUNET_TESTING_PluginFunctions * GNUNET_TESTING_make_plugin(const struct GNUNET_TESTING_Command *commands)
A command to be run by the interpreter.
The plugin API every test case plugin has to implement.

Definition at line 784 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT

#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT (   prefix,
  name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
prefix ## _get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
type * *ret); \
struct GNUNET_TESTING_Trait \
prefix ## _make_trait_ ## name ( \
type * value);
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.

Create headers for a trait with name name for statically allocated data of type type.

Parameters
prefixsymbol prefix to use
namename of the trait
typedata type for the trait

Definition at line 868 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT

#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT (   prefix,
  name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
prefix ## _get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
type * *ret) \
{ \
if (NULL == cmd->traits) return GNUNET_SYSERR; \
return cmd->traits (cmd->cls, \
(const void **) ret, \
0); \
} \
prefix ## _make_trait_ ## name ( \
type * value) \
{ \
struct GNUNET_TESTING_Trait ret = { \
.trait_name = GNUNET_S (name), \
.ptr = (const void *) value \
}; \
return ret; \
}
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:66
#define GNUNET_S(a)
Stringify operator.
@ GNUNET_SYSERR
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

Create C implementation for a trait with name name for statically allocated data of type type.

Parameters
prefixsymbol prefix to use
namename of the trait
typedata type for the trait

Definition at line 886 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT

#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT (   prefix,
  name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
prefix ## _get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
unsigned int index, \
type * *ret); \
struct GNUNET_TESTING_Trait \
prefix ## _make_trait_ ## name ( \
unsigned int index, \
type * value);

Create headers for a trait with name name for statically allocated data of type type.

Parameters
prefixsymbol prefix to use
namename of the trait
typedata type for the trait

Definition at line 918 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT

#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT (   prefix,
  name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
prefix ## _get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
unsigned int index, \
type * *ret) \
{ \
if (NULL == cmd->traits) return GNUNET_SYSERR; \
return cmd->traits (cmd->cls, \
(const void **) ret, \
index); \
} \
prefix ## _make_trait_ ## name ( \
unsigned int index, \
type * value) \
{ \
struct GNUNET_TESTING_Trait ret = { \
.index = index, \
.trait_name = GNUNET_S (name), \
.ptr = (const void *) value \
}; \
return ret; \
}

Create C implementation for a trait with name name for statically allocated data of type type.

Definition at line 934 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_SIMPLE_TRAITS

#define GNUNET_TESTING_SIMPLE_TRAITS (   op,
  prefix 
)
Value:
op (prefix, cmd, const struct GNUNET_TESTING_Command) \
op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
process($line, $c)
Definition: log.php:48

Call op on all simple traits needed by testing core logic.

Parameters
opoperation to perform
prefixprefix to pass to op

Definition at line 967 of file gnunet_testing_lib.h.

Typedef Documentation

◆ GNUNET_TESTING_CommandRunRoutine

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.

Runs the command. Note that upon return, the interpreter will not automatically run the next command if this is an asynchronous command unless the command was wrapped in GNUNET_TESTING_cmd_make_unblocking(), as the command may then continue asynchronously in other scheduler tasks. In this case, GNUNET_TESTING_async_finish() must be called to run the next task.

Parameters
clsclosure
isinterpreter running the command

Definition at line 145 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_CommandCleanupRoutine

typedef void(* GNUNET_TESTING_CommandCleanupRoutine) (void *cls)

Signature of a function used to clean up resources allocated by a command.

Parameters
clsclosure

Definition at line 157 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_CommandGetTraits

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.

Parameters
clsclosure
[out]retwhere to return the trait data
traitname of the trait to return
indexindex of the trait (for traits that are indexed)
Returns
GNUNET_OK on success

Definition at line 157 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_CommandIterator

typedef void(* GNUNET_TESTING_CommandIterator) (void *cls, const struct GNUNET_TESTING_Command *cmd)

Callback over commands of an interpreter.

Parameters
clsclosure
cmda command to process

Definition at line 430 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_ResultCallback

typedef void(* GNUNET_TESTING_ResultCallback) (void *cls, enum GNUNET_GenericReturnValue rv)

Function called with the final result of the test.

Parameters
clsclosure
rvGNUNET_OK if the test passed

Definition at line 732 of file gnunet_testing_lib.h.

Function Documentation

◆ GNUNET_TESTING_async_fail()

void GNUNET_TESTING_async_fail ( struct GNUNET_TESTING_AsyncContext ac)

The asynchronous command of ac has failed.

Parameters
accommand-specific context

Definition at line 519 of file testing_api_loop.c.

520{
524}
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TESTING_Interpreter * is
Interpreter we are part of.
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.

References GNUNET_TESTING_Command::ac, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, GNUNET_TESTING_interpreter_fail(), and GNUNET_TESTING_AsyncContext::is.

Referenced by barrier_reached_run(), child_completed_callback(), conn_status(), exp_cb(), handle_helper_barrier_reached(), handle_helper_local_finished(), helper_mst(), stop_cb(), and timeout_finish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_async_finish()

void GNUNET_TESTING_async_finish ( struct GNUNET_TESTING_AsyncContext ac)

The asynchronous command of ac has finished.

Parameters
accommand-specific context

Definition at line 528 of file testing_api_loop.c.

529{
531 ac->finished = GNUNET_OK;
532 if (NULL != ac->notify_finished)
533 {
535 ac->notify_finished = NULL;
536 }
537 if (! ac->next_called)
538 {
539 ac->next_called = true;
541 }
542}
@ GNUNET_OK
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.
void * notify_finished_cls
Closure for notify_finished.
void GNUNET_TESTING_interpreter_next_(void *cls)
Current command is done, run the next one.

References GNUNET_TESTING_Command::ac, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_TESTING_interpreter_next_(), GNUNET_TESTING_AsyncContext::is, GNUNET_TESTING_AsyncContext::next_called, GNUNET_TESTING_AsyncContext::notify_finished, and GNUNET_TESTING_AsyncContext::notify_finished_cls.

Referenced by backchannel_check_run(), barrier_reached_run(), child_completed_callback(), conn_status(), do_timeout(), done_finish(), handle_helper_barrier_crossable(), handle_helper_barrier_reached(), handle_helper_local_finished(), hello_iter_cb(), notify_connect(), read_from_log(), run_finish(), send_run(), send_simple_single(), and stop_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_command_new_ac()

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.

Parameters
clsthe closure
labelthe Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
runthe run routing
cleanupthe cleanup function
traitsthe traits function (optional)
acthe async context, NULL if command is always synchronous
Returns
the command the function cannot fail

Definition at line 34 of file testing_api_cmds.c.

41{
42 struct GNUNET_TESTING_Command cmd = {
43 .cls = cls,
44 .run = run,
45 .ac = ac,
46 .cleanup = cleanup,
47 .traits = traits
48 };
49
50 GNUNET_assert (NULL != run);
51 if (NULL != label)
53 label);
54 return cmd;
55}
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.
Definition: gnunet-arm.c:917
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
struct GNUNET_TESTING_CommandLabel label
Label for the command.
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
void * cls
Closure for all commands with command-specific context information.
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.

References GNUNET_TESTING_Command::ac, cleanup(), GNUNET_TESTING_Command::cls, GNUNET_assert, GNUNET_TESTING_set_label(), GNUNET_TESTING_Command::label, run(), and traits().

Referenced by GNUNET_CORE_cmd_connect_peers(), GNUNET_TESTING_ARM_cmd_start_peer(), GNUNET_TESTING_cmd_barrier_reached(), GNUNET_TESTING_cmd_exec(), GNUNET_TESTING_cmd_exec_va(), GNUNET_TESTING_cmd_finish(), GNUNET_TESTING_cmd_load_topology_from_file(), GNUNET_TESTING_cmd_load_topology_from_string(), GNUNET_TESTING_cmd_netjail_setup(), GNUNET_TESTING_cmd_netjail_start_helpers(), GNUNET_TESTING_cmd_stop_peer(), GNUNET_TRANSPORT_cmd_backchannel_check(), GNUNET_TRANSPORT_cmd_connect_peers(), GNUNET_TRANSPORT_cmd_send_simple_performance(), and GNUNET_TRANSPORT_cmd_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_set_label()

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.

Parameters
[out]labellabel to initialize
valuevalue to store into label

Definition at line 59 of file testing_api_cmds.c.

62{
63 size_t len;
64
65 len = strlen (value);
66 GNUNET_assert (len <=
68 memcpy (label->value,
69 value,
70 len + 1);
71}
#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
Central interpreter and command loop for writing an interpreter to test asynchronous systems.

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_ac(), and GNUNET_TESTING_DHTU_cmd_send().

Here is the caller graph for this function:

◆ GNUNET_TESTING_interpreter_lookup_command()

const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command ( struct GNUNET_TESTING_Interpreter is,
const char *  label 
)

Lookup command by label.

Parameters
isinterpreter to lookup command in
labellabel of the command to lookup.
Returns
the command, if it is found, or NULL.

Definition at line 147 of file testing_api_loop.c.

150{
151 if (NULL == label)
152 {
154 "Attempt to lookup command for empty label\n");
155 return NULL;
156 }
157 for (int i = is->ip; i >= 0; i--)
158 {
159 const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
160
161 /* Give precedence to top-level commands. */
162 if ( (NULL != cmd->run) &&
163 (0 == strcmp (cmd->label.value,
164 label)) )
165 return cmd;
166
168 {
169 struct GNUNET_TESTING_Command **batch;
170 const struct GNUNET_TESTING_Command *current;
171 const struct GNUNET_TESTING_Command *icmd;
172 const struct GNUNET_TESTING_Command *match;
173
176 &current));
179 &batch));
180 /* We must do the loop forward, but we can find the last match */
181 match = NULL;
182 for (unsigned int j = 0;
183 NULL != (icmd = &(*batch)[j])->run;
184 j++)
185 {
186 if (current == icmd)
187 break; /* do not go past current command */
188 if ( (NULL != icmd->run) &&
189 (0 == strcmp (icmd->label.value,
190 label)) )
191 match = icmd;
192 }
193 if (NULL != match)
194 return match;
195 }
196 }
198 "Command `%s' not found\n",
199 label);
200 return NULL;
201}
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_Command **ret)
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_batch_cmds(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Command ***ret)
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_WARNING
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
int ip
Instruction pointer.
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.

References GNUNET_TESTING_Interpreter::commands, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_TESTING_cmd_is_batch_(), GNUNET_TESTING_get_trait_batch_cmds(), GNUNET_TESTING_get_trait_cmd(), GNUNET_TESTING_Interpreter::ip, is, GNUNET_TESTING_Command::label, run(), GNUNET_TESTING_Command::run, and GNUNET_TESTING_CommandLabel::value.

Referenced by backchannel_check_run(), connect_peers_run(), join_room_run(), netjail_exec_run(), netjail_start_run(), rewind_ip_run(), run_finish(), send_simple_run(), signal_run(), start_peer_run(), start_service_run(), stop_peer_run(), and stop_service_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_interpreter_get_command()

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.

Parameters
isinterpreter state.
namename of the variable to get command by
Returns
the command, if it is found, or NULL.

Definition at line 205 of file testing_api_loop.c.

208{
209 const struct GNUNET_TESTING_Command *cmd;
210 struct GNUNET_HashCode h_name;
211
213 strlen (name),
214 &h_name);
216 &h_name);
217 if (NULL == cmd)
219 "Command not found by variable name: %s\n",
220 name);
221 return cmd;
222}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * vars
Hash map mapping variable names to commands.

References GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, is, name, and GNUNET_TESTING_Interpreter::vars.

Here is the call graph for this function:

◆ GNUNET_TESTING_interpreter_current_cmd_touch()

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.

Parameters
[in,out]isinterpreter state where to show that we are doing something

Definition at line 810 of file testing_api_loop.c.

812{
815}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
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...

References GNUNET_TESTING_Interpreter::commands, GNUNET_TIME_absolute_get(), GNUNET_TESTING_Interpreter::ip, is, and GNUNET_TESTING_Command::last_req_time.

Here is the call graph for this function:

◆ GNUNET_TESTING_interpreter_current_cmd_inc_tries()

void GNUNET_TESTING_interpreter_current_cmd_inc_tries ( struct GNUNET_TESTING_Interpreter is)

Increment the 'num_tries' counter for the current command.

Parameters
[in,out]isinterpreter state where to increment the counter

Definition at line 819 of file testing_api_loop.c.

821{
823}
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated....

References GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Interpreter::ip, is, and GNUNET_TESTING_Command::num_tries.

◆ GNUNET_TESTING_interpreter_current_cmd_get_label()

const char * GNUNET_TESTING_interpreter_current_cmd_get_label ( struct GNUNET_TESTING_Interpreter is)

Obtain label of the command being now run.

Parameters
isinterpreter state.
Returns
the label.

Definition at line 827 of file testing_api_loop.c.

829{
830 return is->commands[is->ip].label.value;
831}

References GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Interpreter::ip, is, GNUNET_TESTING_Command::label, and GNUNET_TESTING_CommandLabel::value.

◆ GNUNET_TESTING_interpreter_fail()

void GNUNET_TESTING_interpreter_fail ( struct GNUNET_TESTING_Interpreter is)

Current command failed, clean up and fail the test case.

Parameters
isinterpreter state.

Definition at line 465 of file testing_api_loop.c.

466{
467 struct GNUNET_TESTING_Command *cmd
468 = &is->commands[is->ip];
469
470 if (GNUNET_SYSERR == is->result)
471 {
472 GNUNET_break (0);
473 return; /* ignore, we already failed! */
474 }
475 if (NULL == cmd)
476 {
478 "Failed with CMD being NULL!\n");
479 }
480 else
481 {
482 const struct GNUNET_TESTING_Command *pos = cmd;
483
485 "Failed during command `%s'\n",
486 cmd->label.value);
487 while (GNUNET_TESTING_cmd_is_batch_ (pos))
488 {
491 &pos));
493 "Failed in batch during command `%s'\n",
494 pos->label.value);
495 }
496 }
497 if (NULL != is->timeout_task)
498 {
500 is->timeout_task = NULL;
501 }
503 GNUNET_assert (NULL == is->final_task);
505 is);
506}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
struct GNUNET_SCHEDULER_Task * final_task
Final task that returns the result.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
enum GNUNET_GenericReturnValue result
Result of the testcases, GNUNET_OK on success, GNUNET_SYSERR on failure, GNUNET_NO if undecided.
static void finish_test(void *cls)
Finish the test run, return the final result.

References GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Interpreter::final_task, finish_test(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TESTING_cmd_is_batch_(), GNUNET_TESTING_get_trait_cmd(), GNUNET_TESTING_Interpreter::ip, is, GNUNET_TESTING_Command::label, GNUNET_TESTING_Interpreter::result, GNUNET_TESTING_Interpreter::timeout_task, and GNUNET_TESTING_CommandLabel::value.

Referenced by connect_peers_run(), do_shutdown(), GNUNET_TESTING_async_fail(), GNUNET_TESTING_interpreter_skip(), join_room_run(), on_message_cb(), rewind_ip_run(), seek_batch(), start_peer_run(), and start_service_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_interpreter_skip()

void GNUNET_TESTING_interpreter_skip ( struct GNUNET_TESTING_Interpreter is)

Skips the current test, the environment is not prepared correctly.

Parameters
isinterpreter state.

Definition at line 510 of file testing_api_loop.c.

512{
513 is->skip = true;
515}
bool skip
Is the real result to "skip" because we could not get the environment working?

References GNUNET_TESTING_interpreter_fail(), is, and GNUNET_TESTING_Interpreter::skip.

Referenced by netjail_start_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_interpreter_commands_iterate()

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.

Parameters
[in]isinterpreter to iterate over
asctrue in execution order, false for reverse execution order
cbfunction to call on each command
cb_clsclosure for cb

Definition at line 776 of file testing_api_loop.c.

781{
782 unsigned int start;
783 unsigned int end;
784 int inc;
785
786 if (asc)
787 {
788 inc = 1;
789 start = 0;
790 end = is->ip;
791 }
792 else
793 {
794 inc = -1;
795 start = is->ip;
796 end = 0;
797 }
798 for (unsigned int off = start; off != end + inc; off += inc)
799 {
800 const struct GNUNET_TESTING_Command *cmd
801 = &is->commands[off];
802
803 cb (cb_cls,
804 cmd);
805 }
806}
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34

References GNUNET_TESTING_Interpreter::commands, end, GNUNET_TESTING_Interpreter::ip, is, and start.

Referenced by stat_run().

Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_end()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end ( void  )

Create command array terminator.

Returns
a end-command.

Definition at line 85 of file testing_api_cmds.c.

86{
87 struct GNUNET_TESTING_Command cmd = {
88 .run = NULL
89 };
90
91 return cmd;
92}

References GNUNET_TESTING_Command::run.

Referenced by main().

Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_batch()

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.

Parameters
labelthe command label.
batcharray of CMDs to execute.
Returns
the command.

Definition at line 150 of file testing_api_cmd_batch.c.

152{
153 struct BatchState *bs;
154 unsigned int i;
155
156 bs = GNUNET_new (struct BatchState);
158 label);
159 /* Get number of commands. */
160 for (i = 0; NULL != batch[i].run; i++)
161 /* noop */
162 ;
163
164 bs->batch = GNUNET_new_array (i + 1,
166 memcpy (bs->batch,
167 batch,
168 sizeof (struct GNUNET_TESTING_Command) * i);
170 label,
171 &batch_run,
173 &batch_traits);
174}
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
Create a new command.
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
State for a "batch" CMD.
struct GNUNET_TESTING_CommandLabel label
Our label.
struct GNUNET_TESTING_Command * batch
CMDs batch.
static void batch_cleanup(void *cls)
Cleanup the state from a "reserve status" CMD, and possibly cancel a pending operation thereof.
static void batch_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static enum GNUNET_GenericReturnValue batch_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.

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.

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_stat()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat ( const char *  label,
struct GNUNET_TESTING_Timer timers 
)

Obtain performance data from the interpreter.

Parameters
labelcommand label.
[in,out]timersNULL-prefix terminated array that specifies what commands (by label) to obtain runtimes for
Returns
the command

Definition at line 150 of file testing_api_cmd_stat.c.

152{
153 return GNUNET_TESTING_command_new ((void *) timers,
154 label,
155 &stat_run,
156 NULL,
157 NULL);
158}
static void stat_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run a "stat" CMD.

References GNUNET_TESTING_command_new, and stat_run().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_set_var()

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.

Parameters
namename of the variable to set
cmdcommand to set to variable when run
Returns
modified command

Definition at line 75 of file testing_api_cmds.c.

78{
79 cmd.name = name;
80 return cmd;
81}
const char * name
Variable name for the command, NULL for none.

References GNUNET_TESTING_Command::name.

Referenced by start_testcase().

Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_barrier_create()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create ( const char *  label,
unsigned int  number_to_be_reached 
)

Command to create a barrier.

Parameters
labelThe label of this command.
number_to_be_reachedIf this number of processes reached this barrier, all processes waiting at this barrier can pass it.

Definition at line 91 of file testing_api_cmd_barrier_create.c.

94{
95 struct GNUNET_TESTING_Barrier *barrier;
96
97 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
99 &barrier->barrier_id);
100 barrier->expected_reaches = number_to_be_reached;
101 return GNUNET_TESTING_command_new (barrier,
102 label,
106}
An entry for a barrier list.
struct GNUNET_ShortHashCode barrier_id
unsigned int expected_reaches
Number of total commands expected to be reached by the barrier.
void GNUNET_TESTING_barrier_name_hash_(const char *barrier_name, struct GNUNET_ShortHashCode *bkey)
static enum GNUNET_GenericReturnValue barrier_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "barrier" CMD, to other commands.
static void barrier_cleanup(void *cls)
Cleanup the state from a "barrier" CMD, and possibly cancel a pending operation thereof.
static void barrier_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.

References barrier_cleanup(), GNUNET_TESTING_Barrier::barrier_id, barrier_run(), barrier_traits(), GNUNET_TESTING_Barrier::expected_reaches, GNUNET_new, GNUNET_TESTING_barrier_name_hash_(), and GNUNET_TESTING_command_new.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_barrier_reached()

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.

If this command is synchronous it will block.

Parameters
labelname for command.
barrier_labelThe name of the barrier we waited for and which was reached.
Returns
command.

Definition at line 173 of file testing_api_cmd_barrier_reached.c.

176{
177 struct BarrierReachedState *brs;
178
179 brs = GNUNET_new (struct BarrierReachedState);
180 brs->label = label;
181 brs->barrier_name = barrier_label;
183 brs,
184 label,
188 &brs->ac);
189}
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 with information for callbacks.
const char * barrier_name
The name of the barrier this commands wait (if finishing asynchronous) for or/and reaches.
const char * label
The label of this command.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
static void barrier_reached_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static enum GNUNET_GenericReturnValue barrier_reached_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.
static void barrier_reached_cleanup(void *cls)
Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.

References BarrierReachedState::ac, BarrierReachedState::barrier_name, barrier_reached_cleanup(), barrier_reached_run(), barrier_reached_traits(), GNUNET_new, GNUNET_TESTING_command_new_ac(), and BarrierReachedState::label.

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_netjail_start_helpers()

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.

Parameters
labelName for the command.
topology_datatopology data
timeoutBefore this timeout is reached this cmd MUST finish.
Returns
command.

Definition at line 580 of file testing_api_cmd_netjail_start_cmds_helper.c.

584{
585 struct NetJailState *ns;
586
587 ns = GNUNET_new (struct NetJailState);
588 ns->topology_cmd_label = topology_cmd_label;
589 ns->timeout = timeout;
591 label,
595 &ns->ac);
596}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
Struct to hold information for callbacks.
const char * topology_cmd_label
Configuration file for the test topology.
static void netjail_exec_cleanup(void *cls)
Code to clean up resource this cmd used.
static void netjail_exec_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
This function starts a helper process for each node.
static enum GNUNET_GenericReturnValue netjail_exec_traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_new, GNUNET_TESTING_command_new_ac(), netjail_exec_cleanup(), netjail_exec_run(), netjail_exec_traits(), ns, timeout, and NetJailState::topology_cmd_label.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_netjail_setup()

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.

Parameters
labelname for command.
scriptwhich script to run, e.g. GNUNET_TESTING_NETJAIL_START_SCRIPT
topology_configConfiguration file for the test topology.
read_fileFlag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
Returns
command.

Definition at line 205 of file testing_api_cmd_netjail_start.c.

209{
210 struct NetJailState *ns;
211
212 ns = GNUNET_new (struct NetJailState);
213 ns->script = script;
214 ns->topology_cmd_label = topology_cmd_label;
216 ns,
217 label,
220 NULL,
221 &ns->ac);
222}
const char * script
Start or stop?
static void netjail_start_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which setup the network namespaces.
static void netjail_start_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.

References GNUNET_new, GNUNET_TESTING_command_new_ac(), netjail_start_cleanup(), netjail_start_run(), ns, NetJailState::script, and NetJailState::topology_cmd_label.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_load_topology_from_file()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_file ( const char *  label,
const char *  filename 
)

Definition at line 177 of file testing_api_cmd_get_topo.c.

180{
181 struct TopologyState *ts;
182
183 ts = GNUNET_new (struct TopologyState);
184 ts->label = label;
185 ts->file_name = file_name;
187 ts,
188 label,
189 &run,
190 &cleanup,
191 traits,
192 NULL);
193}
static char * file_name
Dump file name.
const char * file_name
A string with the name of the topology file.
const char * label
The label of the command.
static void run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which setup the network namespaces.
static void cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References cleanup(), file_name, TopologyState::file_name, GNUNET_new, GNUNET_TESTING_command_new_ac(), TopologyState::label, run(), and traits().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_load_topology_from_string()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_string ( const char *  label,
const char *  topology_data 
)

Definition at line 197 of file testing_api_cmd_get_topo.c.

200{
201 struct TopologyState *ts;
202
204 ts = GNUNET_new (struct TopologyState);
205 ts->label = label;
208 ts,
209 label,
210 &run,
211 &cleanup,
212 traits,
213 NULL);
214}
const char * topology_string
A string with the name of the topology file, if read_file is true, otherwise a string containing the ...

References cleanup(), GNUNET_assert, GNUNET_new, GNUNET_TESTING_command_new_ac(), TopologyState::label, run(), TopologyState::topology_string, topology_string, and traits().

Referenced by main(), and start_testcase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_make_unblocking()

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.

Parameters
[in,out]cmdcommand to make non-blocking
Returns
a finish-command.

Definition at line 209 of file testing_api_cmd_finish.c.

211{
212 /* do not permit this function to be used on
213 a finish command! */
214 GNUNET_assert (cmd.run != &run_finish);
215 cmd.asynchronous_finish = true;
216 return cmd;
217}
bool asynchronous_finish
If "true", the interpreter should not immediately run the next command, even if this command did not ...
static void run_finish(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run method of the command created by the interpreter to wait for another command to finish.

References GNUNET_assert, and run_finish().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_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.

Parameters
finish_labellabel for this command
cmd_refreference to a previous command which we should wait for (call finish() on)
timeouthow long to wait at most for cmd_ref to finish
Returns
a finish-command.

Definition at line 188 of file testing_api_cmd_finish.c.

192{
193 struct FinishState *finish_state;
194
195 finish_state = GNUNET_new (struct FinishState);
196 finish_state->async_label = cmd_ref;
197 finish_state->timeout = timeout;
199 finish_state,
200 finish_label,
201 &run_finish,
203 NULL,
204 &finish_state->ac);
205}
Struct to use for command-specific context information closure of a command waiting for another comma...
struct GNUNET_TESTING_AsyncContext ac
Function to call when done.
const char * async_label
Label of the asynchronous command the synchronous command of this closure waits for.
struct GNUNET_TIME_Relative timeout
How long to wait until finish fails hard?
static void cleanup_finish(void *cls)
Cleanup state of a finish command.

References FinishState::ac, FinishState::async_label, cleanup_finish(), GNUNET_new, GNUNET_TESTING_command_new_ac(), run_finish(), timeout, and FinishState::timeout.

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_signal()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal ( const char *  label,
const char *  process_label,
int  signal 
)

Create a "signal" CMD.

Parameters
labelcommand label.
process_labellabel of a command that has a process trait
signalsignal to send to process.
Returns
the command.
Parameters
labelcommand label.
processhandle to the process to signal.
signalsignal to send.
Returns
the command.

Definition at line 105 of file testing_api_cmd_signal.c.

109{
110 struct SignalState *ss;
111
112 ss = GNUNET_new (struct SignalState);
114 ss->signal = signal;
116 label,
117 &signal_run,
119 NULL);
120}
State for a "signal" CMD.
const char * process_label
Label of the process to send the signal to.
int signal
The signal to send to the process.
static void signal_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static void signal_cleanup(void *cls)
Cleanup the state from a "signal" CMD.

References GNUNET_new, GNUNET_TESTING_command_new, SignalState::process_label, SignalState::signal, signal_cleanup(), and signal_run().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_sleep()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep ( const char *  label,
struct GNUNET_TIME_Relative  duration 
)

Sleep for duration.

Parameters
labelcommand label.
durationtime to sleep
Returns
the command.

◆ GNUNET_TESTING_cmd_exec()

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.

Parameters
labelLabel of the command.

Definition at line 187 of file testing_api_cmd_exec.c.

192{
193 struct BashScriptState *bss;
194 unsigned int cnt;
195
196 cnt = 0;
197 while (NULL != script_argv[cnt])
198 cnt++;
199 bss = GNUNET_new (struct BashScriptState);
200 bss->args = GNUNET_new_array (cnt + 1,
201 char *);
202 for (unsigned int i = 0; i<cnt; i++)
203 bss->args[i] = GNUNET_strdup (script_argv[i]);
207 bss,
208 label,
211 &traits,
212 &bss->ac);
213}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char ** args
NULL-terminated array of command-line arguments.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
enum GNUNET_OS_ProcessStatusType expected_type
unsigned long int expected_exit_code
static void exec_bash_script_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static void exec_bash_script_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run method of the command created by the interpreter to wait for another command to finish.

References BashScriptState::ac, BashScriptState::args, exec_bash_script_cleanup(), exec_bash_script_run(), BashScriptState::expected_exit_code, BashScriptState::expected_type, GNUNET_new, GNUNET_new_array, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), and traits().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_exec_va()

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.

Parameters
labelLabel of the command.

Definition at line 217 of file testing_api_cmd_exec.c.

222{
223 struct BashScriptState *bss;
224 va_list ap;
225 const char *arg;
226 unsigned int cnt;
227
228 bss = GNUNET_new (struct BashScriptState);
229 va_start (ap,
231 cnt = 1;
232 while (NULL != (arg = va_arg (ap,
233 const char *)))
234 cnt++;
235 va_end (ap);
236 bss->args = GNUNET_new_array (cnt,
237 char *);
238 cnt = 0;
239 va_start (ap,
241 while (NULL != (arg = va_arg (ap,
242 const char *)))
243 bss->args[cnt++] = GNUNET_strdup (arg);
244 va_end (ap);
248 bss,
249 label,
252 &traits,
253 &bss->ac);
254}

References BashScriptState::ac, find_typedefs::arg, BashScriptState::args, exec_bash_script_cleanup(), exec_bash_script_run(), BashScriptState::expected_exit_code, BashScriptState::expected_type, GNUNET_new, GNUNET_new_array, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), and traits().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_rewind_ip()

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.

Note that the command that will be executed next in this case is the one AFTER target_label, as the command we jump to is skipped by the advancing IP after the rewind.

Parameters
labelcommand label
target_labellabel of the new instruction pointer's destination after the jump; must be before the current instruction (and the command at the target_label itself will not be run, but the one afterwards)
countercounts how many times the rewinding is to happen.

Definition at line 1007 of file testing_api_loop.c.

1010{
1011 struct RewindIpState *ris;
1012
1013 ris = GNUNET_new (struct RewindIpState);
1015 ris->counter = counter;
1016 return GNUNET_TESTING_command_new (ris,
1017 label,
1020 NULL);
1021}
State for a "rewind" CMD.
const char * target_label
Instruction pointer to set into the interpreter.
unsigned int counter
How many times this set should take place.
static void rewind_ip_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the "rewind" CMD.
static void rewind_ip_free(void *cls)

References RewindIpState::counter, GNUNET_new, GNUNET_TESTING_command_new, rewind_ip_free(), rewind_ip_run(), and RewindIpState::target_label.

Here is the call graph for this function:

◆ GNUNET_TESTING_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.

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.

Parameters
commandsthe array of command to execute
timeouthow long to wait for each command to execute
rcfunction to call with the final result
rc_clsclosure for rc
Returns
The interpreter.

Definition at line 604 of file testing_api_loop.c.

608{
610
614 &do_timeout,
615 is);
616 is->rc = rc;
617 is->rc_cls = rc_cls;
618 setup_is (is,
619 NULL,
620 commands);
621 return is;
622}
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
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.
static void setup_is(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_TESTING_Command *bcommand, const struct GNUNET_TESTING_Command *commands)
static void do_timeout(void *cls)
Function run when the test terminates (good or bad) with timeout.

References commands, do_timeout(), GNUNET_new, GNUNET_SCHEDULER_add_delayed(), is, GNUNET_TESTING_Interpreter::rc, GNUNET_TESTING_Interpreter::rc_cls, setup_is(), timeout, and GNUNET_TESTING_Interpreter::timeout_task.

Referenced by loop_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_main()

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.

Return 0 upon success. Expected to be called directly from main().

Parameters
commandsthe list of command to execute
timeouthow long to wait for each command to execute
Returns
EXIT_SUCCESS on success, EXIT_FAILURE on failure

Definition at line 127 of file testing_api_main.c.

130{
131 struct MainParams mp = {
133 .timeout = timeout,
134 .rv = EXIT_SUCCESS
135 };
136
138 &mp);
139 return mp.rv;
140}
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:725
Closure for loop_run().
int rv
Set to #EXIT_FAILURE on error.
const struct GNUNET_TESTING_Command * commands
NULL-label terminated array of commands.
static void loop_run(void *cls)
Main function to run the test cases.

References commands, MainParams::commands, GNUNET_SCHEDULER_run(), loop_run(), MainParams::rv, and timeout.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_make_plugin()

struct GNUNET_TESTING_PluginFunctions * GNUNET_TESTING_make_plugin ( const struct GNUNET_TESTING_Command commands)

Definition at line 679 of file testing_api_loop.c.

681{
683 struct GNUNET_TESTING_Command *commands_copy;
684 unsigned int i;
685
686 for (i = 0; NULL != commands[i].run; i++)
687 ;
688 commands_copy = GNUNET_malloc_large ( (i + 1)
689 * sizeof (struct
691 memcpy (commands_copy,
692 commands,
693 sizeof (struct GNUNET_TESTING_Command) * i + 1);
694
696 api->cls = (void *) commands_copy;
698 return api;
699}
#define GNUNET_malloc_large(size)
Wrapper around malloc.
void * cls
Closure to pass to start_testcase.
struct GNUNET_TESTING_Interpreter *(* start_testcase)(void *cls, const char *topology_data, uint32_t barrier_count, const struct GNUNET_ShortHashCode *barriers, GNUNET_TESTING_cmd_helper_write_cb write_message, GNUNET_TESTING_ResultCallback finish_cb, void *finish_cb_cls)
Function to be implemented for each test case plugin which starts the test case on a netjail node.
static struct GNUNET_TESTING_Interpreter * start_testcase(void *cls, const char *topology_data, uint32_t inherited_barrier_count, const struct GNUNET_ShortHashCode *inherited_barriers, GNUNET_TESTING_cmd_helper_write_cb parent_writer, GNUNET_TESTING_ResultCallback finish_cb, void *finish_cb_cls)

References GNUNET_TESTING_PluginFunctions::cls, commands, GNUNET_malloc_large, GNUNET_new, start_testcase(), and GNUNET_TESTING_PluginFunctions::start_testcase.

Here is the call graph for this function:

◆ GNUNET_TESTING_trait_end()

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.

Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), connect_peers_traits(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), stop_peer_traits(), system_create_traits(), and traits().

Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait()

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.

Parameters
traitsthe array of all the traits.
[out]retwhere to store the result.
traittype of the trait to extract.
indexindex number of the trait to extract.
Returns
GNUNET_OK when the trait is found.

Obtain value of a trait from a command.

Parameters
traitsthe traits array.
retwhere to store the result.
traittype of the trait to extract.
indexindex number of the object to extract.
Returns
GNUNET_OK if no error occurred, GNUNET_SYSERR otherwise.

Definition at line 62 of file testing_api_traits.c.

66{
67 for (unsigned int i = 0; NULL != traits[i].trait_name; i++)
68 {
69 if ( (0 == strcmp (trait, traits[i].trait_name)) &&
70 (index == traits[i].index) )
71 {
72 *ret = (void *) traits[i].ptr;
73 return GNUNET_OK;
74 }
75 }
77 "Trait %s/%u not found.\n",
78 trait, index);
79
80 return GNUNET_SYSERR;
81}
@ GNUNET_ERROR_TYPE_INFO

References GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_Trait::index, GNUNET_TESTING_Trait::ptr, ret, GNUNET_TESTING_Trait::trait_name, and traits().

Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), connect_peers_traits(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), stop_peer_traits(), system_create_traits(), and traits().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait_process()

enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_process ( const struct GNUNET_TESTING_Command cmd,
struct GNUNET_OS_Process ***  ret 
)

Referenced by signal_run().

Here is the caller graph for this function:

◆ GNUNET_TESTING_make_trait_process()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process ( struct GNUNET_OS_Process **  value)

Referenced by start_peer_traits(), and traits().

Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait_cmd()

enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd ( const struct GNUNET_TESTING_Command cmd,
const struct GNUNET_TESTING_Command **  ret 
)

Referenced by GNUNET_TESTING_interpreter_fail(), GNUNET_TESTING_interpreter_lookup_command(), and seek_batch().

Here is the caller graph for this function:

◆ GNUNET_TESTING_make_trait_cmd()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd ( const struct GNUNET_TESTING_Command value)

Referenced by batch_traits().

Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait_batch_cmds()

enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_batch_cmds ( const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTING_Command ***  ret 
)

Referenced by do_stat(), GNUNET_TESTING_interpreter_lookup_command(), and seek_batch().

Here is the caller graph for this function:

◆ GNUNET_TESTING_make_trait_batch_cmds()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_batch_cmds ( struct GNUNET_TESTING_Command **  value)

Referenced by batch_traits().

Here is the caller graph for this function: