GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
gnunet_testing_ng_lib.h File Reference
#include "gnunet_util_lib.h"
#include "gnunet_testing_plugin.h"
#include "gnunet_testing_lib.h"
Include dependency graph for gnunet_testing_ng_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_Command
 A command to be run by the interpreter. More...
 
struct  GNUNET_TESTING_Timer
 Performance counter. More...
 
struct  GNUNET_TESTING_Trait
 A trait. More...
 

Macros

#define GNUNET_S(a)   #a
 API for writing an interpreter to test GNUnet components. More...
 
#define GNUNET_TESTING_FAIL(is)
 Print failing line number and trigger shutdown. More...
 
#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(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(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(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(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)
 Call op on all simple traits. More...
 
#define GNUNET_TESTING_INDEXED_TRAITS(op)
 Call op on all indexed traits. More...
 

Typedefs

typedef void(* GNUNET_TESTING_ResultCallback) (void *cls, enum GNUNET_GenericReturnValue rv)
 Function called with the final result of the test. More...
 

Functions

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...
 
const char * GNUNET_TESTING_interpreter_get_current_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_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_cmd_end (void)
 Create command array terminator. 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...
 
void GNUNET_TESTING_run (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...
 
int GNUNET_TESTING_has_in_name (const char *prog, const char *marker)
 Look for substring in a programs' name. More...
 
struct GNUNET_TESTING_CommandGNUNET_TESTING_interpreter_get_current_command (struct GNUNET_TESTING_Interpreter *is)
 Returns the actual running command. More...
 
enum GNUNET_GenericReturnValue GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command)
 Check if the command is running. More...
 
enum GNUNET_GenericReturnValue GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command)
 Check if a command is finished. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal (const char *label, const char *process_label, unsigned int process_index, 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...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch (const char *label, struct GNUNET_TESTING_Command *batch)
 Create a "batch" command. More...
 
struct GNUNET_PeerIdentityGNUNET_TESTING_get_pub_key (unsigned int num, const struct GNUNET_TESTING_System *tl_system)
 Retrieve the public key from the test system with the unique node id. 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" trait. More...
 
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
 Extract a trait. 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_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)
 

Macro Definition Documentation

◆ GNUNET_S

#define GNUNET_S (   a)    #a

API for writing an interpreter to test GNUnet components.

Author
Christian Grothoff chris.nosp@m.tian.nosp@m.@grot.nosp@m.hoff.nosp@m..org
Marcello Stanisci
t3sserakt Stringify operator.
Parameters
asome expression to stringify. Must NOT be a macro.
Returns
same expression as a constant string.

Definition at line 40 of file gnunet_testing_ng_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_NT_InterfaceScanner * is
Network scanner to determine network types.

Print failing line number and trigger shutdown.

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

Definition at line 49 of file gnunet_testing_ng_lib.h.

◆ GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT

#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT (   name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
GNUNET_TESTING_get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
type **ret); \
struct GNUNET_TESTING_Trait \
GNUNET_TESTING_make_trait_ ## name ( \
type * value);
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * value
Value of the record to add/remove.
const char * name
A command to be run by the interpreter.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

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

Definition at line 592 of file gnunet_testing_ng_lib.h.

◆ GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT

#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT (   name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
GNUNET_TESTING_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); \
} \
GNUNET_TESTING_make_trait_ ## name ( \
type * value) \
{ \
struct GNUNET_TESTING_Trait ret = { \
.trait_name = GNUNET_S (name), \
.ptr = (const void *) value \
}; \
return ret; \
}
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_S(a)
API for writing an interpreter to test GNUnet components.

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

Definition at line 606 of file gnunet_testing_ng_lib.h.

◆ GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT

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

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

Definition at line 634 of file gnunet_testing_ng_lib.h.

◆ GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT

#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT (   name,
  type 
)
Value:
enum GNUNET_GenericReturnValue \
GNUNET_TESTING_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); \
} \
GNUNET_TESTING_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 650 of file gnunet_testing_ng_lib.h.

◆ GNUNET_TESTING_SIMPLE_TRAITS

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

Call op on all simple traits.

Definition at line 680 of file gnunet_testing_ng_lib.h.

◆ GNUNET_TESTING_INDEXED_TRAITS

#define GNUNET_TESTING_INDEXED_TRAITS (   op)
Value:
op (uint32, const uint32_t) \
op (uint64, const uint64_t) \
op (int64, const int64_t) \
op (uint, const unsigned int) \
op (string, const char) \
op (cmd, const struct GNUNET_TESTING_Command) \
op (uuid, const struct GNUNET_Uuid) \
op (time, const struct GNUNET_TIME_Absolute) \
op (absolute_time, const struct GNUNET_TIME_Absolute) \
op (relative_time, const struct GNUNET_TIME_Relative)
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
A UUID, a 128 bit "random" value.

Call op on all indexed traits.

Definition at line 688 of file gnunet_testing_ng_lib.h.

Typedef Documentation

◆ 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 350 of file gnunet_testing_ng_lib.h.

Function Documentation

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

Definition at line 167 of file testing_api_loop.c.

170 {
171  return get_command (is, label, GNUNET_YES);
172 }
@ GNUNET_YES
Definition: gnunet_common.h:97
const struct GNUNET_TESTING_Command * get_command(struct GNUNET_TESTING_Interpreter *is, const char *label, unsigned int future)

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

Only commands from current command to commands in the past are looked up.

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

Definition at line 184 of file testing_api_loop.c.

187 {
188  return get_command (is, label, GNUNET_NO);
189 }
@ GNUNET_NO
Definition: gnunet_common.h:94

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

Referenced by backchannel_check_run(), connect_peers_run(), run_finish(), send_simple_run(), start_peer_run(), stop_peer_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 furture are looked up.

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

Definition at line 201 of file testing_api_loop.c.

204 {
205  const struct GNUNET_TESTING_Command *cmd;
206 
207  cmd = get_command (is, label, GNUNET_NO);
208  if (NULL == cmd)
209  cmd = get_command (is, label, GNUNET_YES);
210  return cmd;
211 }
const char * label
Label for the command.

References get_command(), GNUNET_NO, GNUNET_YES, 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_get_current_label()

const char* GNUNET_TESTING_interpreter_get_current_label ( struct GNUNET_TESTING_Interpreter is)

Obtain label of the command being now run.

Parameters
isinterpreter state.
Returns
the label.

Definition at line 355 of file testing_api_loop.c.

357 {
358  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
359 
360  return cmd->label;
361 }

References is, and GNUNET_TESTING_Command::label.

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

307 {
308  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
309 
310  if (GNUNET_SYSERR == is->result)
311  {
312  GNUNET_break (0);
313  return; /* ignore, we already failed! */
314  }
315  if (NULL != cmd)
316  {
318  "Failed at command `%s'\n",
319  cmd->label);
320  while (GNUNET_TESTING_cmd_is_batch_ (cmd))
321  {
324  "Failed in batch at command `%s'\n",
325  cmd->label);
326  }
327  }
328  else
329  {
331  "Failed with CMD being NULL!\n");
332  }
333  is->result = GNUNET_SYSERR;
334  GNUNET_assert (NULL == is->final_task);
335  is->final_task = GNUNET_SCHEDULER_add_now (&finish_test,
336  is);
337 }
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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:1296
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 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_(), is, and GNUNET_TESTING_Command::label.

Referenced by GNUNET_TESTING_async_fail(), netjail_stop_run(), run_finish(), start_helper(), and start_peer_run().

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

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

579 {
580  GNUNET_assert (GNUNET_NO == ac->finished);
581  ac->finished = GNUNET_SYSERR;
583  if (NULL != ac->cont)
584  {
585  ac->cont (ac->cont_cls);
586  ac->cont = NULL;
587  }
588 }
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.

References ac, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, and GNUNET_TESTING_interpreter_fail().

Referenced by child_completed_callback(), exp_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 592 of file testing_api_loop.c.

593 {
594  GNUNET_assert (GNUNET_NO == ac->finished);
595  ac->finished = GNUNET_OK;
596  if (NULL != ac->cont)
597  {
598  ac->cont (ac->cont_cls);
599  ac->cont = NULL;
600  }
601 }
@ GNUNET_OK
Definition: gnunet_common.h:95

References ac, GNUNET_assert, GNUNET_NO, and GNUNET_OK.

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

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 1 of file testing_api_cmd_end.c.

31 {
32  static struct GNUNET_TESTING_Command cmd = {
33  .label = NULL
34  };
35 
36  return cmd;
37 }

References GNUNET_TESTING_Command::label.

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

Parameters
cmdcommand to make synchronous.
Returns
a finish-command.

Definition at line 155 of file testing_api_cmd_finish.c.

194 {
195  /* do not permit this function to be used on
196  a finish command! */
197  GNUNET_assert (cmd.run != &run_finish);
198  cmd.asynchronous_finish = true;
199  return cmd;
200 }
void(* run)(void *cls, struct GNUNET_TESTING_Interpreter *is)
Runs the command.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
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.

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

172 {
173  struct FinishState *finish_state;
174 
175  finish_state = GNUNET_new (struct FinishState);
176  finish_state->async_label = cmd_ref;
177  finish_state->timeout = timeout;
178  {
179  struct GNUNET_TESTING_Command cmd = {
180  .cls = finish_state,
181  .label = finish_label,
182  .run = &run_finish,
183  .ac = &finish_state->ac,
184  .cleanup = &cleanup_finish
185  };
186 
187  return cmd;
188  }
189 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
#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?
void * cls
Closure for all commands with command-specific context information.
static void cleanup_finish(void *cls)
Cleanup state of a finish command.

◆ 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()

void GNUNET_TESTING_run ( 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 list of command to execute
timeouthow long to wait for each command to execute
rcfunction to call with the final result
rc_clsclosure for rc

Definition at line 471 of file testing_api_loop.c.

475 {
477  unsigned int i;
478 
480  is->rc = rc;
481  is->rc_cls = rc_cls;
482  /* get the number of commands */
483  for (i = 0; NULL != commands[i].label; i++)
484  ;
485  is->cmds_n = i + 1;
486  is->commands = GNUNET_new_array (is->cmds_n,
487  struct GNUNET_TESTING_Command);
488  memcpy (is->commands,
489  commands,
490  sizeof (struct GNUNET_TESTING_Command) * i);
491  is->timeout_task
493  &do_timeout,
494  is);
496  is);
497 }
static struct VoipCommand commands[]
List of supported commands.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
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:1269
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 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 commands, do_timeout(), GNUNET_new, GNUNET_new_array, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), interpreter_run(), is, GNUNET_TESTING_Interpreter::rc, GNUNET_TESTING_Interpreter::rc_cls, and timeout.

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

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

564 {
565  struct MainParams mp = {
566  .commands = commands,
567  .timeout = timeout,
568  .rv = EXIT_SUCCESS
569  };
570 
572  &mp);
573  return mp.rv;
574 }
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:720
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_has_in_name()

int GNUNET_TESTING_has_in_name ( const char *  prog,
const char *  marker 
)

Look for substring in a programs' name.

Parameters
progprogram's name to look into
markerchunk to find in prog // FIXME: this does not belong here! => libgnunetutil, maybe? // FIXME: return bool? document return value!

◆ GNUNET_TESTING_interpreter_get_current_command()

struct GNUNET_TESTING_Command* GNUNET_TESTING_interpreter_get_current_command ( struct GNUNET_TESTING_Interpreter is)

Returns the actual running command.

Parameters
isGlobal state of the interpreter, used by a command to access information about other commands.
Returns
The actual running command.

Definition at line 348 of file testing_api_loop.c.

350 {
351  return &is->commands[is->ip];
352 }

References is.

Referenced by block_until_all_peers_started_run(), and do_timeout().

Here is the caller graph for this function:

◆ GNUNET_TESTING_running()

enum GNUNET_GenericReturnValue GNUNET_TESTING_running ( const struct GNUNET_TESTING_Command command)

Check if the command is running.

Parameters
cmdThe command to check.
Returns
GNUNET_NO if the command is not running, GNUNET_YES if it is running.

Definition at line 427 of file testing_api_loop.c.

447 {
448  return 0 != command->start_time.abs_value_us && 0 ==
449  command->finish_time.abs_value_us;
450 }
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
uint64_t abs_value_us
The actual value.

◆ GNUNET_TESTING_finished()

enum GNUNET_GenericReturnValue GNUNET_TESTING_finished ( struct GNUNET_TESTING_Command command)

Check if a command is finished.

Parameters
cmdThe command to check.
Returns
GNUNET_NO if the command is not finished, GNUNET_YES if it is finished.

Definition at line 427 of file testing_api_loop.c.

461 {
464  command->finish_time,
465  now);
466  return 0 < diff.rel_value_us;
467 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:110
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:420
uint64_t rel_value_us
The actual value.

◆ GNUNET_TESTING_cmd_signal()

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

Create a "signal" CMD.

Parameters
labelcommand label.
process_labellabel of a command that has a process trait
process_indexindex of the process trait at process_label // FIXME: enum? needed?
signalsignal to send to process.
Returns
the command.

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

157 {
158  struct BatchState *bs;
159  unsigned int i;
160 
161  bs = GNUNET_new (struct BatchState);
162  bs->label = label;
163  /* Get number of commands. */
164  for (i = 0; NULL != batch[i].label; i++)
165  /* noop */
166  ;
167 
168  bs->batch = GNUNET_new_array (i + 1,
169  struct GNUNET_TESTING_Command);
170  memcpy (bs->batch,
171  batch,
172  sizeof (struct GNUNET_TESTING_Command) * i);
173  {
174  struct GNUNET_TESTING_Command cmd = {
175  .cls = bs,
176  .label = label,
177  .run = &batch_run,
178  .cleanup = &batch_cleanup,
179  .traits = &batch_traits
180  };
181 
182  return cmd;
183  }
184 }
State for a "batch" CMD.
const char * 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.

◆ GNUNET_TESTING_get_pub_key()

struct GNUNET_PeerIdentity* GNUNET_TESTING_get_pub_key ( unsigned int  num,
const struct GNUNET_TESTING_System tl_system 
)

Retrieve the public key from the test system with the unique node id.

Parameters
numThe unique node id.
tl_systemThe test system.
Returns
The peer identity wrapping the public key.

Definition at line 2172 of file testing.c.

2174 {
2176  struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
2178  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
2180 
2181  priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2182  num,
2183  peer);
2184 
2186  pub_key);
2187  peer->public_key = *pub_key;
2188  GNUNET_free (priv_key);
2189  GNUNET_free (pub_key);
2190  return peer;
2191 }
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:197
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:714
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_free, GNUNET_new, GNUNET_TESTING_hostkey_get(), and peer.

Referenced by add_search_string(), connect_peers_run(), and notify_connect().

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

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" trait.

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

Definition at line 1 of file testing_api_traits.c.

45 {
46  struct GNUNET_TESTING_Trait end = {
47  .index = 0,
48  .trait_name = NULL,
49  .ptr = NULL
50  };
51 
52  return end;
53 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34

Referenced by block_until_external_trigger_traits(), start_peer_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 
)

Extract a trait.

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.

Extract a trait.

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

70 {
71  for (unsigned int i = 0; NULL != traits[i].trait_name; i++)
72  {
73  if ( (0 == strcmp (trait, traits[i].trait_name)) &&
74  (index == traits[i].index) )
75  {
76  *ret = (void *) traits[i].ptr;
77  return GNUNET_OK;
78  }
79  }
81  "Trait %s/%u not found.\n",
82  trait, index);
83 
84  return GNUNET_SYSERR;
85 }
@ GNUNET_ERROR_TYPE_INFO
const char * trait_name
Trait type, for example "reserve-pub" or "coin-priv".

References end.

Referenced by block_until_external_trigger_traits(), start_peer_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_process()

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

◆ GNUNET_TESTING_make_trait_process()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process ( struct GNUNET_OS_Process **  value)