GNUnet 0.22.1
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 265 of file testing_api_loop.c.

267{
268 /* We must have a parent */
269 if (NULL == is->parent_writer)
271 is->parent_writer (hdr);
272}
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 239 of file testing_api_loop.c.

241{
243 "Send notification to children of type %u\n",
244 (unsigned int) ntohs (hdr->type));
245 for (unsigned int i = 0; i<is->n_helpers; i++)
246 {
247 struct SendContext *sctx;
248
249 sctx = GNUNET_new (struct SendContext);
250 sctx->is = is;
253 sctx);
254 sctx->send_handle
256 hdr,
257 false, /* never drop */
259 sctx);
260 }
261}
#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 351 of file testing_api_loop.c.

352{
353 static unsigned long long ipc;
354 static struct GNUNET_TIME_Absolute last_report;
355 struct GNUNET_TESTING_Interpreter *is = cls;
356 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
357
358 if (GNUNET_SYSERR == is->result)
359 return; /* ignore, we already failed! */
360
362 {
364 {
365 /* batch is done */
367 is->ip++;
368 }
369 }
370 else
371 {
373 is->ip++;
374 }
375
376 if (0 == (ipc % 1000))
377 {
378 if (0 != ipc)
380 "Interpreter executed 1000 instructions in %s\n",
383 true));
384 last_report = GNUNET_TIME_absolute_get ();
385 }
386 ipc++;
388 is);
389}
@ 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:1303
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:438
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:579
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 393 of file testing_api_loop.c.

396{
397 cmd->last_req_time
399 if (0 == cmd->num_tries)
400 cmd->start_time = cmd->last_req_time;
401 cmd->num_tries = 1;
402 if (NULL != cmd->name)
403 {
404 struct GNUNET_HashCode h_name = {0};
405
407 strlen (cmd->name),
408 &h_name);
410 is->vars,
411 &h_name,
412 cmd,
414 }
415 if (NULL != cmd->ac)
416 {
417 cmd->ac->is = is;
418 cmd->ac->finished = GNUNET_NO;
419 cmd->ac->next_called = false;
420 }
421 cmd->run (cmd->cls,
422 is);
423 if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) &&
424 ( (NULL == cmd->ac) ||
425 (cmd->asynchronous_finish) ) )
426 {
427 if (NULL != cmd->ac)
428 cmd->ac->next_called = true;
430 }
431}
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 701 of file testing_api_loop.c.

703{
705 is->n_helpers,
706 helper);
707}
#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 735 of file testing_api_loop.c.

737{
738 if (NULL == is->barriers)
739 is->barriers
741 true);
742 /* We always use the barrier we encountered
743 most recently under a given label, thus replace */
745 is->barriers,
746 &barrier->barrier_id,
747 barrier,
749}
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 711 of file testing_api_loop.c.

713{
715 create_key);
716}
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 720 of file testing_api_loop.c.

722{
723 struct GNUNET_ShortHashCode create_key;
724
725 if (NULL == is->barriers)
726 return NULL;
728 &create_key);
730 &create_key);
731}
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 753 of file testing_api_loop.c.

755{
757}
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 761 of file testing_api_loop.c.

765{
766 if (NULL != is->barriers)
768 cb,
769 cb_cls);
770}
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: