GNUnet 0.21.2
testing_api_loop.h File Reference
Include dependency graph for testing_api_loop.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_PluginFunctions
 The plugin API every test case plugin has to implement. More...
 

Typedefs

typedef void(* GNUNET_TESTING_cmd_helper_write_cb) (const struct GNUNET_MessageHeader *message)
 Callback function to write messages from the helper process running on a netjail node to the master process. More...
 

Functions

void GNUNET_TESTING_loop_notify_parent_ (struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
 Send message to our parent. More...
 
void GNUNET_TESTING_loop_notify_children_ (struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
 Send message to all netjail children (if there are any). More...
 
void GNUNET_TESTING_interpreter_next_ (void *cls)
 Current command is done, run the next one. More...
 
void GNUNET_TESTING_interpreter_run_cmd_ (struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Command *cmd)
 
void GNUNET_TESTING_add_netjail_helper_ (struct GNUNET_TESTING_Interpreter *is, struct GNUNET_HELPER_Handle *helper)
 Adding a helper handle to the interpreter. More...
 
void GNUNET_TESTING_add_barrier_ (struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
 Add a barrier to the interpreter to share it with all children as an inherited barrier. More...
 
struct GNUNET_TESTING_BarrierGNUNET_TESTING_get_barrier2_ (struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_ShortHashCode *create_key)
 
struct GNUNET_TESTING_BarrierGNUNET_TESTING_get_barrier_ (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
 
unsigned int GNUNET_TESTING_barrier_count_ (struct GNUNET_TESTING_Interpreter *is)
 
void GNUNET_TESTING_barrier_iterate_ (struct GNUNET_TESTING_Interpreter *is, GNUNET_CONTAINER_ShortmapIterator cb, void *cb_cls)
 

Detailed Description

Author
t3sserakt

Definition in file testing_api_loop.h.

Typedef Documentation

◆ GNUNET_TESTING_cmd_helper_write_cb

typedef void(* GNUNET_TESTING_cmd_helper_write_cb) (const struct GNUNET_MessageHeader *message)

Callback function to write messages from the helper process running on a netjail node to the master process.

Parameters
messageThe message to write.

Definition at line 37 of file testing_api_loop.h.

Function Documentation

◆ GNUNET_TESTING_loop_notify_parent_()

void GNUNET_TESTING_loop_notify_parent_ ( struct GNUNET_TESTING_Interpreter is,
const struct GNUNET_MessageHeader hdr 
)

Send message to our parent.

Fails very hard if we do not have one.

Parameters
isThe interpreter loop.

Definition at line 267 of file testing_api_loop.c.

269{
270 /* We must have a parent */
271 if (NULL == is->parent_writer)
273 is->parent_writer (hdr);
274}
static struct GNUNET_TESTING_Interpreter * is
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
GNUNET_TESTING_cmd_helper_write_cb parent_writer
Function to call to send messages to our parent.

References GNUNET_TESTING_FAIL, is, and GNUNET_TESTING_Interpreter::parent_writer.

Referenced by barrier_reached_run(), and handle_helper_barrier_reached().

Here is the caller graph for this function:

◆ GNUNET_TESTING_loop_notify_children_()

void GNUNET_TESTING_loop_notify_children_ ( struct GNUNET_TESTING_Interpreter is,
const struct GNUNET_MessageHeader hdr 
)

Send message to all netjail children (if there are any).

Parameters
isThe interpreter loop.

Definition at line 241 of file testing_api_loop.c.

243{
245 "Send notification to children of type %u\n",
246 (unsigned int) ntohs (hdr->type));
247 for (unsigned int i = 0; i<is->n_helpers; i++)
248 {
249 struct SendContext *sctx;
250
251 sctx = GNUNET_new (struct SendContext);
252 sctx->is = is;
255 sctx);
256 sctx->send_handle
258 hdr,
259 false, /* never drop */
261 sctx);
262 }
263}
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, bool can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:613
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct SendContext * sender_tail
struct GNUNET_HELPER_Handle ** helpers
Array with handles of helper processes for communication with netjails.
struct SendContext * sender_head
unsigned int n_helpers
Size of the array helpers.
struct GNUNET_HELPER_SendHandle * send_handle
Handle to a send op.
struct GNUNET_TESTING_Interpreter * is
static void send_finished(void *cls, enum GNUNET_GenericReturnValue result)

References GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELPER_send(), GNUNET_log, GNUNET_new, GNUNET_TESTING_Interpreter::helpers, is, SendContext::is, GNUNET_TESTING_Interpreter::n_helpers, send_finished(), SendContext::send_handle, GNUNET_TESTING_Interpreter::sender_head, GNUNET_TESTING_Interpreter::sender_tail, and GNUNET_MessageHeader::type.

Referenced by barrier_reached_run(), handle_helper_barrier_crossable(), and handle_helper_barrier_reached().

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

◆ GNUNET_TESTING_interpreter_next_()

void GNUNET_TESTING_interpreter_next_ ( void *  cls)

Current command is done, run the next one.

Definition at line 353 of file testing_api_loop.c.

354{
355 static unsigned long long ipc;
356 static struct GNUNET_TIME_Absolute last_report;
357 struct GNUNET_TESTING_Interpreter *is = cls;
358 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
359
360 if (GNUNET_SYSERR == is->result)
361 return; /* ignore, we already failed! */
362
364 {
366 {
367 /* batch is done */
369 is->ip++;
370 }
371 }
372 else
373 {
375 is->ip++;
376 }
377
378 if (0 == (ipc % 1000))
379 {
380 if (0 != ipc)
382 "Interpreter executed 1000 instructions in %s\n",
385 true));
386 last_report = GNUNET_TIME_absolute_get ();
387 }
388 ipc++;
390 is);
391}
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_MESSAGE
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_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:436
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
A command to be run by the interpreter.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
int ip
Instruction pointer.
struct GNUNET_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
enum GNUNET_GenericReturnValue result
Result of the testcases, GNUNET_OK on success, GNUNET_SYSERR on failure, GNUNET_NO if undecided.
Time for absolute times used by GNUnet, in microseconds.
bool GNUNET_TESTING_cmd_batch_next_(void *cls)
Advance internal pointer to next command.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
static void interpreter_run(void *cls)
Run the main interpreter loop that performs exchange operations.

References GNUNET_TESTING_Command::cls, GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Command::finish_time, GNUNET_ERROR_TYPE_MESSAGE, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TESTING_cmd_batch_next_(), GNUNET_TESTING_cmd_is_batch_(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), interpreter_run(), GNUNET_TESTING_Interpreter::ip, is, GNUNET_TESTING_Interpreter::result, and GNUNET_TESTING_Interpreter::task.

Referenced by batch_run(), GNUNET_TESTING_async_finish(), and GNUNET_TESTING_interpreter_run_cmd_().

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

◆ GNUNET_TESTING_interpreter_run_cmd_()

void GNUNET_TESTING_interpreter_run_cmd_ ( struct GNUNET_TESTING_Interpreter is,
struct GNUNET_TESTING_Command cmd 
)

Definition at line 395 of file testing_api_loop.c.

398{
399 cmd->last_req_time
401 if (0 == cmd->num_tries)
402 cmd->start_time = cmd->last_req_time;
403 cmd->num_tries = 1;
404 if (NULL != cmd->name)
405 {
406 struct GNUNET_HashCode h_name;
407
409 strlen (cmd->name),
410 &h_name);
412 is->vars,
413 &h_name,
414 cmd,
416 }
417 if (NULL != cmd->ac)
418 {
419 cmd->ac->is = is;
420 cmd->ac->finished = GNUNET_NO;
421 cmd->ac->next_called = false;
422 }
423 cmd->run (cmd->cls,
424 is);
425 if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) &&
426 ( (NULL == cmd->ac) ||
427 (cmd->asynchronous_finish) ) )
428 {
429 if (NULL != cmd->ac)
430 cmd->ac->next_called = true;
432 }
433}
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
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.
@ GNUNET_NO
A 512-bit hashcode.
bool next_called
Set to true if interpreter_next() has already been called for this command.
struct GNUNET_TESTING_Interpreter * is
Interpreter we are part of.
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).
const char * name
Variable name for the command, NULL for none.
struct GNUNET_TIME_Absolute last_req_time
When did we start the last run of this command? Delta to finish_time gives the latency for the last s...
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
bool asynchronous_finish
If "true", the interpreter should not immediately run the next command, even if this command did not ...
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated....
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
struct GNUNET_CONTAINER_MultiHashMap * vars
Hash map mapping variable names to commands.
void GNUNET_TESTING_interpreter_next_(void *cls)
Current command is done, run the next one.

References GNUNET_TESTING_Command::ac, GNUNET_TESTING_Command::asynchronous_finish, GNUNET_TESTING_Command::cls, GNUNET_TESTING_AsyncContext::finished, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE, GNUNET_CRYPTO_hash(), GNUNET_NO, GNUNET_TESTING_cmd_is_batch_(), GNUNET_TESTING_interpreter_next_(), GNUNET_TIME_absolute_get(), GNUNET_TESTING_AsyncContext::is, is, GNUNET_TESTING_Command::last_req_time, GNUNET_TESTING_Command::name, GNUNET_TESTING_AsyncContext::next_called, GNUNET_TESTING_Command::num_tries, GNUNET_TESTING_Command::run, GNUNET_TESTING_Command::start_time, and GNUNET_TESTING_Interpreter::vars.

Referenced by batch_run(), and interpreter_run().

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

◆ GNUNET_TESTING_add_netjail_helper_()

void GNUNET_TESTING_add_netjail_helper_ ( struct GNUNET_TESTING_Interpreter is,
struct GNUNET_HELPER_Handle helper 
)

Adding a helper handle to the interpreter.

Parameters
isThe interpreter.
helperThe helper handle.

Definition at line 703 of file testing_api_loop.c.

705{
707 is->n_helpers,
708 helper);
709}
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).

References GNUNET_array_append, GNUNET_TESTING_Interpreter::helpers, is, and GNUNET_TESTING_Interpreter::n_helpers.

Referenced by start_helper().

Here is the caller graph for this function:

◆ GNUNET_TESTING_add_barrier_()

void GNUNET_TESTING_add_barrier_ ( struct GNUNET_TESTING_Interpreter is,
struct GNUNET_TESTING_Barrier barrier 
)

Add a barrier to the interpreter to share it with all children as an inherited barrier.

Parameters
isThe interpreter.
barrierThe barrier to add.

Definition at line 737 of file testing_api_loop.c.

739{
740 if (NULL == is->barriers)
741 is->barriers
743 true);
744 /* We always use the barrier we encountered
745 most recently under a given label, thus replace */
747 is->barriers,
748 &barrier->barrier_id,
749 barrier,
751}
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).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_ShortHashCode barrier_id
struct GNUNET_CONTAINER_MultiShortmap * barriers
Map with barriers for this loop.

References GNUNET_TESTING_Barrier::barrier_id, GNUNET_TESTING_Interpreter::barriers, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE, GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_put(), and is.

Referenced by barrier_run().

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

◆ GNUNET_TESTING_get_barrier2_()

struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier2_ ( struct GNUNET_TESTING_Interpreter is,
const struct GNUNET_ShortHashCode create_key 
)

Definition at line 713 of file testing_api_loop.c.

715{
717 create_key);
718}
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.

References GNUNET_TESTING_Interpreter::barriers, GNUNET_CONTAINER_multishortmap_get(), and is.

Referenced by GNUNET_TESTING_get_barrier_(), handle_helper_barrier_crossable(), and handle_helper_barrier_reached().

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

◆ GNUNET_TESTING_get_barrier_()

struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier_ ( struct GNUNET_TESTING_Interpreter is,
const char *  barrier_name 
)

Definition at line 722 of file testing_api_loop.c.

724{
725 struct GNUNET_ShortHashCode create_key;
726
727 if (NULL == is->barriers)
728 return NULL;
730 &create_key);
732 &create_key);
733}
A 256-bit hashcode.
void GNUNET_TESTING_barrier_name_hash_(const char *barrier_name, struct GNUNET_ShortHashCode *bkey)
struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier2_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_ShortHashCode *create_key)

References GNUNET_TESTING_Interpreter::barriers, GNUNET_TESTING_barrier_name_hash_(), GNUNET_TESTING_get_barrier2_(), and is.

Referenced by barrier_reached_run().

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

◆ GNUNET_TESTING_barrier_count_()

unsigned int GNUNET_TESTING_barrier_count_ ( struct GNUNET_TESTING_Interpreter is)

Definition at line 755 of file testing_api_loop.c.

757{
759}
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.

References GNUNET_TESTING_Interpreter::barriers, GNUNET_CONTAINER_multishortmap_size(), and is.

Referenced by send_start_messages().

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

◆ GNUNET_TESTING_barrier_iterate_()

void GNUNET_TESTING_barrier_iterate_ ( struct GNUNET_TESTING_Interpreter is,
GNUNET_CONTAINER_ShortmapIterator  cb,
void *  cb_cls 
)

Definition at line 763 of file testing_api_loop.c.

767{
768 if (NULL != is->barriers)
770 cb,
771 cb_cls);
772}
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.

References GNUNET_TESTING_Interpreter::barriers, GNUNET_CONTAINER_multishortmap_iterate(), and is.

Referenced by send_start_messages().

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