GNUnet 0.22.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:93
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:143
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 517 of file testing_api_loop.c.

518{
522}
@ 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 526 of file testing_api_loop.c.

527{
529 ac->finished = GNUNET_OK;
530 if (NULL != ac->notify_finished)
531 {
533 ac->notify_finished = NULL;
534 }
535 if (! ac->next_called)
536 {
537 ac->next_called = true;
539 }
540}
@ 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:916
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:130
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 145 of file testing_api_loop.c.

148{
149 if (NULL == label)
150 {
152 "Attempt to lookup command for empty label\n");
153 return NULL;
154 }
155 for (int i = is->ip; i >= 0; i--)
156 {
157 const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
158
159 /* Give precedence to top-level commands. */
160 if ( (NULL != cmd->run) &&
161 (0 == strcmp (cmd->label.value,
162 label)) )
163 return cmd;
164
166 {
167 struct GNUNET_TESTING_Command **batch;
168 const struct GNUNET_TESTING_Command *current;
169 const struct GNUNET_TESTING_Command *icmd;
170 const struct GNUNET_TESTING_Command *match;
171
174 &current));
177 &batch));
178 /* We must do the loop forward, but we can find the last match */
179 match = NULL;
180 for (unsigned int j = 0;
181 NULL != (icmd = &(*batch)[j])->run;
182 j++)
183 {
184 if (current == icmd)
185 break; /* do not go past current command */
186 if ( (NULL != icmd->run) &&
187 (0 == strcmp (icmd->label.value,
188 label)) )
189 match = icmd;
190 }
191 if (NULL != match)
192 return match;
193 }
194 }
196 "Command `%s' not found\n",
197 label);
198 return NULL;
199}
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 203 of file testing_api_loop.c.

206{
207 const struct GNUNET_TESTING_Command *cmd;
208 struct GNUNET_HashCode h_name = {0};
209
211 strlen (name),
212 &h_name);
214 &h_name);
215 if (NULL == cmd)
217 "Command not found by variable name: %s\n",
218 name);
219 return cmd;
220}
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 808 of file testing_api_loop.c.

810{
813}
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 817 of file testing_api_loop.c.

819{
821}
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 825 of file testing_api_loop.c.

827{
828 return is->commands[is->ip].label.value;
829}

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 463 of file testing_api_loop.c.

464{
465 struct GNUNET_TESTING_Command *cmd
466 = &is->commands[is->ip];
467
468 if (GNUNET_SYSERR == is->result)
469 {
470 GNUNET_break (0);
471 return; /* ignore, we already failed! */
472 }
473 if (NULL == cmd)
474 {
476 "Failed with CMD being NULL!\n");
477 }
478 else
479 {
480 const struct GNUNET_TESTING_Command *pos = cmd;
481
483 "Failed during command `%s'\n",
484 cmd->label.value);
485 while (GNUNET_TESTING_cmd_is_batch_ (pos))
486 {
489 &pos));
491 "Failed in batch during command `%s'\n",
492 pos->label.value);
493 }
494 }
495 if (NULL != is->timeout_task)
496 {
498 is->timeout_task = NULL;
499 }
501 GNUNET_assert (NULL == is->final_task);
503 is);
504}
#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:979
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:1303
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 508 of file testing_api_loop.c.

510{
511 is->skip = true;
513}
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 774 of file testing_api_loop.c.

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

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 706 of file testing_api_cmd_netjail_start_cmds_helper.c.

710{
711 struct NetJailState *ns;
712
713 ns = GNUNET_new (struct NetJailState);
714 ns->topology_cmd_label = topology_cmd_label;
715 ns->timeout = timeout;
717 label,
721 &ns->ac);
722}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
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;
206 if (NULL != topology_string)
207 {
210 }
212 ts,
213 label,
214 &run,
215 &cleanup,
216 traits,
217 NULL);
218}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * topology_alloc
Same as topology_string, but set if we need to release the memory.
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_strdup, GNUNET_TESTING_command_new_ac(), TopologyState::label, run(), TopologyState::topology_alloc, 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().

Referenced by main().

Here is the call graph for this function:
Here is the caller 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.

Referenced by main().

Here is the call graph for this function:
Here is the caller 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}
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 1005 of file testing_api_loop.c.

1008{
1009 struct RewindIpState *ris;
1010
1011 ris = GNUNET_new (struct RewindIpState);
1013 ris->counter = counter;
1014 return GNUNET_TESTING_command_new (ris,
1015 label,
1018 NULL);
1019}
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 602 of file testing_api_loop.c.

606{
608
612 &do_timeout,
613 is);
614 is->rc = rc;
615 is->rc_cls = rc_cls;
616 setup_is (is,
617 NULL,
618 commands);
619 return is;
620}
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:1276
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:724
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 677 of file testing_api_loop.c.

679{
681 struct GNUNET_TESTING_Command *commands_copy;
682 unsigned int i;
683
684 for (i = 0; NULL != commands[i].run; i++)
685 ;
686 commands_copy = GNUNET_malloc_large ( (i + 1)
687 * sizeof (struct
689 memcpy (commands_copy,
690 commands,
691 sizeof (struct GNUNET_TESTING_Command) * i + 1);
692
694 api->cls = (void *) commands_copy;
696 return api;
697}
#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: