GNUnet 0.21.1
gnunet_testing_loop_lib.h File Reference
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_MAKE_DECL_SIMPLE_TRAIT(prefix, name, type)
 Create headers for a trait with name name for statically allocated data of type type. More...
 
#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix, name, type)
 Create C implementation for a trait with name name for statically allocated data of type type. More...
 
#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix, name, type)
 Create headers for a trait with name name for statically allocated data of type type. More...
 
#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix, name, type)
 Create C implementation for a trait with name name for statically allocated data of type type. More...
 
#define GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op, prefix)    op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
 Call op on all simple traits needed by loop logic. More...
 
#define GNUNET_TESTING_LOOP_INDEXED_TRAITS(op, prefix)    op (prefix, cmd, const struct GNUNET_TESTING_Command)
 Call op on all indexed traits needed by loop logic. More...
 

Typedefs

typedef void(* GNUNET_TESTING_CommandRunRoutine) (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Signature of a function used to start executing a command of a test. More...
 
typedef void(* GNUNET_TESTING_CommandCleanupRoutine) (void *cls)
 Signature of a function used to clean up resources allocated by a command. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_TESTING_CommandGetTraits) (void *cls, const void **ret, const char *trait, unsigned int index)
 Signature of a function used to extract traits exposed by a command. More...
 
typedef void(* GNUNET_TESTING_ResultCallback) (void *cls, enum GNUNET_GenericReturnValue rv)
 Function called with the final result of the test. More...
 

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 (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. 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_future_command (struct GNUNET_TESTING_Interpreter *is, const char *label)
 Lookup command by label. 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_lookup_command_all (struct GNUNET_TESTING_Interpreter *is, const char *label)
 Lookup command by label. More...
 
void GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
 Current command failed, clean up and fail the test case. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_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_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 (struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
 Start a GNUnet scheduler event loop and run the testsuite. 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 (struct GNUNET_TESTING_Timer *timers)
 Obtain performance data from the interpreter. More...
 
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_batch_cmds (const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Command ***ret)
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_batch_cmds (struct GNUNET_TESTING_Command **value)
 
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const struct GNUNET_TESTING_Command **ret)
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd (unsigned int index, const struct GNUNET_TESTING_Command *value)
 

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 33 of file gnunet_testing_loop_lib.h.

◆ GNUNET_TESTING_FAIL

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

Print failing line number and trigger shutdown.

Useful quite any time after the command "run" method has been called.

Definition at line 41 of file gnunet_testing_loop_lib.h.

◆ 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 * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
A command to be run by the interpreter.

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 579 of file gnunet_testing_loop_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:59
#define GNUNET_S(a)
Stringify operator.
@ GNUNET_SYSERR
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.

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 597 of file gnunet_testing_loop_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, \

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 629 of file gnunet_testing_loop_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 645 of file gnunet_testing_loop_lib.h.

◆ GNUNET_TESTING_LOOP_SIMPLE_TRAITS

#define GNUNET_TESTING_LOOP_SIMPLE_TRAITS (   op,
  prefix 
)     op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)

Call op on all simple traits needed by loop logic.

Parameters
opoperation to perform
prefixprefix to pass to op

Definition at line 678 of file gnunet_testing_loop_lib.h.

◆ GNUNET_TESTING_LOOP_INDEXED_TRAITS

#define GNUNET_TESTING_LOOP_INDEXED_TRAITS (   op,
  prefix 
)     op (prefix, cmd, const struct GNUNET_TESTING_Command)

Call op on all indexed traits needed by loop logic.

Parameters
opoperation to perform
prefixprefix to pass to op

Definition at line 688 of file gnunet_testing_loop_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.

Parameters
clsclosure
isinterpreter running the command

Definition at line 113 of file gnunet_testing_loop_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 124 of file gnunet_testing_loop_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 124 of file gnunet_testing_loop_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.

FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g. GNUNET_EC_TESTING_*)

Parameters
clsclosure
rvGNUNET_OK if the test passed

Definition at line 404 of file gnunet_testing_loop_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 514 of file testing_api_loop.c.

515{
519 if (NULL != ac->cont)
520 {
521 ac->cont (ac->cont_cls);
522 ac->cont = NULL;
523 }
524}
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_SCHEDULER_TaskCallback cont
Function to call when done.
void * cont_cls
Closure for cont.
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::cont, GNUNET_TESTING_AsyncContext::cont_cls, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, GNUNET_TESTING_interpreter_fail(), and GNUNET_TESTING_AsyncContext::is.

Referenced by child_completed_callback(), exp_cb(), helper_mst(), and timeout_finish().

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->cont)
533 {
534 ac->cont (ac->cont_cls);
535 ac->cont = NULL;
536 }
537}
@ GNUNET_OK

References GNUNET_TESTING_Command::ac, GNUNET_TESTING_AsyncContext::cont, GNUNET_TESTING_AsyncContext::cont_cls, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, and GNUNET_OK.

Referenced by backchannel_check_run(), child_completed_callback(), do_timeout(), done_finish(), GNUNET_TESTING_finish_barrier_(), hello_iter_cb(), helper_mst(), notify_connect(), read_from_log(), run_finish(), send_run(), and send_simple_single().

Here is the caller graph for this function:

◆ GNUNET_TESTING_command_new()

struct GNUNET_TESTING_Command GNUNET_TESTING_command_new ( void *  cls,
const char *  label,
GNUNET_TESTING_CommandRunRoutine  run,
GNUNET_TESTING_CommandCleanupRoutine  cleanup,
GNUNET_TESTING_CommandGetTraits  traits,
struct GNUNET_TESTING_AsyncContext ac 
)

Create a new command.

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

Definition at line 666 of file testing_api_loop.c.

672{
673 struct GNUNET_TESTING_Command cmd = {
674 .cls = cls,
675 .run = run,
676 .ac = ac,
677 .cleanup = cleanup,
678 .traits = traits
679 };
680
681 GNUNET_assert (NULL != run);
682 if (NULL != label)
684 label);
685 return cmd;
686}
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.
GNUNET_TESTING_CommandGetTraits traits
Extract information from a command that is useful for other commands.
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 GNUNET_TESTING_Command::traits.

Referenced by GNUNET_CORE_cmd_connect_peers(), GNUNET_MESSENGER_cmd_join_room(), GNUNET_MESSENGER_cmd_start_service(), GNUNET_MESSENGER_cmd_stop_service(), GNUNET_TESTING_cmd_barrier_create(), GNUNET_TESTING_cmd_barrier_reached(), GNUNET_TESTING_cmd_batch(), GNUNET_TESTING_cmd_block_until_external_trigger(), GNUNET_TESTING_cmd_exec_bash_script(), GNUNET_TESTING_cmd_finish(), GNUNET_TESTING_cmd_local_test_prepared(), GNUNET_TESTING_cmd_netjail_start(), GNUNET_TESTING_cmd_netjail_start_cmds_helper(), GNUNET_TESTING_cmd_netjail_stop(), GNUNET_TESTING_cmd_send_peer_ready(), GNUNET_TESTING_cmd_start_peer(), GNUNET_TESTING_cmd_stop_cmds_helper(), GNUNET_TESTING_cmd_stop_peer(), GNUNET_TESTING_cmd_system_create(), GNUNET_TESTING_cmd_system_destroy(), GNUNET_TRANSPORT_cmd_backchannel_check(), GNUNET_TRANSPORT_cmd_connect_peers(), GNUNET_TRANSPORT_cmd_send_simple(), GNUNET_TRANSPORT_cmd_send_simple_performance(), GNUNET_TRANSPORT_cmd_start_peer(), and GNUNET_TRANSPORT_cmd_stop_peer().

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

692{
693 size_t len;
694
695 len = strlen (value);
696 GNUNET_assert (len <=
698 memcpy (label->value,
699 value,
700 len + 1);
701}
#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(), and GNUNET_TESTING_DHTU_cmd_send().

Here is the caller graph for this function:

◆ GNUNET_TESTING_interpreter_lookup_future_command()

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

Lookup command by label.

Only future commands are looked up.

Parameters
isinterpreter to lookup command in
labellabel of the command to lookup.
Returns
the command, if it is found, or NULL.
Deprecated:
(still in use in a very odd way)

Definition at line 193 of file testing_api_loop.c.

196{
197 return get_command (is,
198 label,
199 true);
200}
static const struct GNUNET_TESTING_Command * get_command(struct GNUNET_TESTING_Interpreter *is, const char *label, bool future)
Lookup command by label.

References get_command(), is, and GNUNET_TESTING_Command::label.

Here is the call 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 204 of file testing_api_loop.c.

207{
208 return get_command (is,
209 label,
210 false);
211}

References get_command(), is, and GNUNET_TESTING_Command::label.

Referenced by backchannel_check_run(), connect_peers_run(), join_room_run(), run_finish(), send_simple_run(), start_peer_run(), start_service_run(), stop_peer_run(), stop_service_run(), stop_testing_system_run(), and system_destroy_run().

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

◆ GNUNET_TESTING_interpreter_lookup_command_all()

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

Lookup command by label.

All commands, first into the past, then into the future are looked up.

Parameters
isinterpreter to lookup command in
labellabel of the command to lookup.
Returns
the command, if it is found, or NULL.
Deprecated:
(still in use in a very odd way)

Definition at line 215 of file testing_api_loop.c.

218{
219 const struct GNUNET_TESTING_Command *cmd;
220
221 cmd = get_command (is,
222 label,
223 false);
224 if (NULL == cmd)
225 cmd = get_command (is,
226 label,
227 true);
228 return cmd;
229}

References get_command(), is, and GNUNET_TESTING_Command::label.

Referenced by notify_connect().

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

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

480{
481 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
482
483 if (GNUNET_SYSERR == is->result)
484 {
485 GNUNET_break (0);
486 return; /* ignore, we already failed! */
487 }
488 if (NULL != cmd)
489 {
491 "Failed at command `%s'\n",
492 cmd->label.value);
493 while (GNUNET_TESTING_cmd_is_batch_ (cmd))
494 {
497 "Failed in batch at command `%s'\n",
498 cmd->label.value);
499 }
500 }
501 else
502 {
504 "Failed with CMD being NULL!\n");
505 }
507 GNUNET_assert (NULL == is->final_task);
509 is);
510}
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
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.
int ip
Instruction pointer.
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
enum GNUNET_GenericReturnValue result
Result of the testcases, GNUNET_OK on success.
struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current_(const struct GNUNET_TESTING_Command *cmd)
Obtain what command the batch is at.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
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_SCHEDULER_add_now(), GNUNET_SYSERR, GNUNET_TESTING_cmd_batch_get_current_(), GNUNET_TESTING_cmd_is_batch_(), GNUNET_TESTING_Interpreter::ip, is, GNUNET_TESTING_Command::label, GNUNET_TESTING_Interpreter::result, and GNUNET_TESTING_CommandLabel::value.

Referenced by connect_peers_run(), exec_bash_script_run(), GNUNET_TESTING_async_fail(), join_room_run(), netjail_start_run(), netjail_stop_run(), on_message_cb(), run_finish(), start_helper(), start_peer_run(), and start_service_run().

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 188 of file testing_api_cmd_finish.c.

189{
190 /* do not permit this function to be used on
191 a finish command! */
192 GNUNET_assert (cmd.run != &run_finish);
193 cmd.asynchronous_finish = true;
194 return cmd;
195}
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
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 171 of file testing_api_cmd_finish.c.

174{
175 struct FinishState *finish_state;
176
177 finish_state = GNUNET_new (struct FinishState);
178 finish_state->async_label = cmd_ref;
179 finish_state->timeout = timeout;
180 return GNUNET_TESTING_command_new (finish_state, finish_label,
181 &run_finish,
183 NULL, &finish_state->ac);
184}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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(), run_finish(), timeout, and FinishState::timeout.

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.

Parameters
labelcommand label
target_labellabel of the new instruction pointer's destination after the jump; must be before the current instruction
countercounts how many times the rewinding is to happen.

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

631{
633 unsigned int i;
634
636 is->rc = rc;
637 is->rc_cls = rc_cls;
639 false);
640 /* get the number of commands */
641 for (i = 0; NULL != commands[i].run; i++)
642 ;
643 is->cmds_n = i + 1;
645 "Got %u commands\n",
646 i);
647 is->commands = GNUNET_malloc_large ( (i + 1)
648 * sizeof (struct
650 GNUNET_assert (NULL != is->commands);
651 memcpy (is->commands,
652 commands,
653 sizeof (struct GNUNET_TESTING_Command) * i);
656 &do_timeout,
657 is);
659 is);
660
661 return is;
662}
static struct VoipCommand commands[]
List of supported commands.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_malloc_large(size)
Wrapper around malloc.
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.
struct GNUNET_CONTAINER_MultiShortmap * barriers
Map with barriers for this loop.
unsigned int cmds_n
Number of GNUNET_TESTING_Command in commands.
void * rc_cls
Closure for rc.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
struct GNUNET_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
static void do_timeout(void *cls)
Function run when the test terminates (good or bad) with timeout.
static void interpreter_run(void *cls)
Run the main interpreter loop that performs exchange operations.

References GNUNET_TESTING_Interpreter::barriers, GNUNET_TESTING_Interpreter::cmds_n, commands, GNUNET_TESTING_Interpreter::commands, do_timeout(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc_large, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), interpreter_run(), is, GNUNET_TESTING_Interpreter::rc, GNUNET_TESTING_Interpreter::rc_cls, GNUNET_TESTING_Interpreter::task, timeout, and GNUNET_TESTING_Interpreter::timeout_task.

Referenced by loop_run().

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

◆ GNUNET_TESTING_main()

int GNUNET_TESTING_main ( struct GNUNET_TESTING_Command commands,
struct GNUNET_TIME_Relative  timeout 
)

Start a GNUnet scheduler event loop and run the testsuite.

Return 0 upon success. Expected to be called directly from main(). FIXME: Why is this commands array here not const?

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

780{
781 struct MainParams mp = {
783 .timeout = timeout,
784 .rv = EXIT_SUCCESS
785 };
786
788 &mp);
789 return mp.rv;
790}
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.
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.

Here is the call 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 706 of file testing_api_loop.c.

707{
708 struct GNUNET_TESTING_Command cmd = {
709 .run = NULL
710 };
711
712 return cmd;
713}

References GNUNET_TESTING_Command::run.

◆ 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 155 of file testing_api_cmd_batch.c.

157{
158 struct BatchState *bs;
159 unsigned int i;
160
161 bs = GNUNET_new (struct BatchState);
163 label);
164 /* Get number of commands. */
165 for (i = 0; NULL != batch[i].run; i++)
166 /* noop */
167 ;
168
169 bs->batch = GNUNET_new_array (i + 1,
171 memcpy (bs->batch,
172 batch,
173 sizeof (struct GNUNET_TESTING_Command) * i);
175 label,
176 &batch_run,
178 &batch_traits, NULL);
179}
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.
#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 ( struct GNUNET_TESTING_Timer timers)

Obtain performance data from the interpreter.

Parameters
[in,out]timerswhat commands (by label) to obtain runtimes for
Returns
the command

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

"end" of traits array.

Usually, commands offer several traits, and put them in arrays.

Definition at line 52 of file testing_api_traits.c.

53{
54 struct GNUNET_TESTING_Trait end = {
55 .index = 0,
56 .trait_name = NULL,
57 .ptr = NULL
58 };
59
60 return end;
61}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34

References end.

Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), block_until_external_trigger_traits(), connect_peers_traits(), local_test_prepared_traits(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), and system_create_traits().

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 74 of file testing_api_traits.c.

78{
79 for (unsigned int i = 0; NULL != traits[i].trait_name; i++)
80 {
81 if ( (0 == strcmp (trait, traits[i].trait_name)) &&
82 (index == traits[i].index) )
83 {
84 *ret = (void *) traits[i].ptr;
85 return GNUNET_OK;
86 }
87 }
89 "Trait %s/%u not found.\n",
90 trait, index);
91
92 return GNUNET_SYSERR;
93}
@ GNUNET_ERROR_TYPE_INFO
const char * trait_name
Trait type, for example "reserve-pub" or "coin-priv".

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

Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), block_until_external_trigger_traits(), connect_peers_traits(), local_test_prepared_traits(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), and system_create_traits().

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 get_command().

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)

◆ GNUNET_TESTING_get_trait_cmd()

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

◆ GNUNET_TESTING_make_trait_cmd()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd ( unsigned int  index,
const struct GNUNET_TESTING_Command value 
)

Referenced by batch_traits().

Here is the caller graph for this function: