GNUnet 0.21.1
testing.h File Reference
Include dependency graph for testing.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CommandBarrierCrossable
 Message send to a child loop to inform the child loop about a barrier being advanced. More...
 
struct  CommandBarrierAttached
 Message send by a child loop to inform the master loop how much GNUNET_CMDS_BARRIER_REACHED messages the child will send. More...
 
struct  GNUNET_TESTING_CommandBarrierReached
 
struct  TestcasePlugin
 Handle for a plugin. More...
 
struct  CommandListEntry
 
struct  GNUNET_TESTING_Barrier
 

Functions

bool GNUNET_TESTING_cmd_batch_next_ (void *cls)
 Advance internal pointer to next command. More...
 
bool GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd)
 Test if this command is a batch command. More...
 
struct GNUNET_TESTING_CommandGNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd)
 Obtain what command the batch is at. More...
 
void GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd, unsigned int new_ip)
 Set what command the batch should be at. More...
 
bool GNUNET_TESTING_barrier_crossable_ (struct GNUNET_TESTING_Barrier *barrier)
 This function checks, if a barrier can be crossed, which actually means that the cmd representing the barrier is finished. More...
 
void GNUNET_TESTING_finish_barrier_ (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
 Finish all "barrier reached" commands attached to this barrier. More...
 
void GNUNET_TESTING_send_barrier_attach_ (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name, unsigned int global_node_number, unsigned int expected_reaches, GNUNET_TESTING_cmd_helper_write_cb write_message)
 Send message to master loop that cmds being attached to a barrier. More...
 
struct GNUNET_TESTING_NetjailNodeGNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier, unsigned int node_number)
 Getting a node from a map by global node number. More...
 
struct GNUNET_TESTING_BarrierGNUNET_TESTING_get_barrier_ (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
 Getting a barrier from the interpreter. More...
 
void GNUNET_TESTING_add_barrier_ (struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
 Add a barrier to the loop. More...
 

Function Documentation

◆ GNUNET_TESTING_cmd_batch_next_()

bool GNUNET_TESTING_cmd_batch_next_ ( void *  cls)

Advance internal pointer to next command.

Parameters
clsbatch internal state
Returns
true if we could advance, false if the batch has completed and cannot advance anymore

Definition at line 183 of file testing_api_cmd_batch.c.

184{
185 struct BatchState *bs = cls;
186
187 if (NULL == bs->batch[bs->batch_ip].run)
188 return false;
189 bs->batch[bs->batch_ip].finish_time
191 bs->batch_ip++;
192 return true;
193}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
State for a "batch" CMD.
unsigned int batch_ip
Internal command pointer.
struct GNUNET_TESTING_Command * batch
CMDs batch.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
GNUNET_TESTING_CommandRunRoutine run
Runs the command.

References BatchState::batch, BatchState::batch_ip, GNUNET_TESTING_Command::finish_time, GNUNET_TIME_absolute_get(), and GNUNET_TESTING_Command::run.

Referenced by interpreter_next().

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

◆ GNUNET_TESTING_cmd_is_batch_()

bool GNUNET_TESTING_cmd_is_batch_ ( const struct GNUNET_TESTING_Command cmd)

Test if this command is a batch command.

Returns
false if not, true if it is a batch command

Definition at line 197 of file testing_api_cmd_batch.c.

198{
199 return cmd->run == &batch_run;
200}
static void batch_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.

References batch_run(), and GNUNET_TESTING_Command::run.

Referenced by get_command(), GNUNET_TESTING_cmd_batch_get_current_(), GNUNET_TESTING_cmd_batch_set_current_(), GNUNET_TESTING_interpreter_fail(), and interpreter_next().

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

◆ GNUNET_TESTING_cmd_batch_get_current_()

struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current_ ( const struct GNUNET_TESTING_Command cmd)

Obtain what command the batch is at.

Returns
cmd current batch command

Definition at line 204 of file testing_api_cmd_batch.c.

205{
206 struct BatchState *bs = cmd->cls;
207
209 return &bs->batch[bs->batch_ip];
210}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * cls
Closure for all commands with command-specific context information.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.

References BatchState::batch, BatchState::batch_ip, GNUNET_TESTING_Command::cls, GNUNET_assert, and GNUNET_TESTING_cmd_is_batch_().

Referenced by get_command(), and GNUNET_TESTING_interpreter_fail().

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

◆ GNUNET_TESTING_cmd_batch_set_current_()

void GNUNET_TESTING_cmd_batch_set_current_ ( const struct GNUNET_TESTING_Command cmd,
unsigned int  new_ip 
)

Set what command the batch should be at.

Needed for loops. We may want to change this to take a label and/or expose it in the public API in the future. Not used for now.

Parameters
cmdcurrent batch command
new_ipwhere to move the IP

Definition at line 214 of file testing_api_cmd_batch.c.

216{
217 struct BatchState *bs = cmd->cls;
218
219 /* sanity checks */
221 /* actual logic */
222 bs->batch_ip = new_ip;
223}

References BatchState::batch_ip, GNUNET_TESTING_Command::cls, GNUNET_assert, and GNUNET_TESTING_cmd_is_batch_().

Here is the call graph for this function:

◆ GNUNET_TESTING_barrier_crossable_()

bool GNUNET_TESTING_barrier_crossable_ ( struct GNUNET_TESTING_Barrier barrier)

This function checks, if a barrier can be crossed, which actually means that the cmd representing the barrier is finished.

Parameters
barrierThe barrier in question.
Returns
true if we can cross the barrier, false if not.

Definition at line 81 of file testing_api_cmd_barrier.c.

82{
83 unsigned int expected_reaches = barrier->expected_reaches;
84 unsigned int reached = barrier->reached;
85 double percentage_to_be_reached = barrier->percentage_to_be_reached;
86 unsigned int number_to_be_reached = barrier->number_to_be_reached;
87 double percentage_reached = (double) reached / expected_reaches * 100;
88
90 "%u %f %f %u %u\n",
91 expected_reaches,
92 percentage_to_be_reached,
93 percentage_reached,
94 number_to_be_reached,
95 reached);
96
97 return ( ( (0 < percentage_to_be_reached) &&
98 (percentage_reached >= percentage_to_be_reached) ) ||
99 ( (0 < number_to_be_reached) &&
100 (reached >= number_to_be_reached) ) );
101}
@ GNUNET_ERROR_TYPE_DEBUG
unsigned int number_to_be_reached
Number of commands which need to reach the barrier to change state.
Definition: testing.h:209
double percentage_to_be_reached
Percentage of of commands which need to reach the barrier to change state.
Definition: testing.h:203
unsigned int reached
Number of commands which reached this barrier.
Definition: testing.h:197
unsigned int expected_reaches
Number of commands attached to this barrier.
Definition: testing.h:192
#define LOG(kind,...)
Generic logging shortcut.

References CommandBarrierAttached::expected_reaches, GNUNET_TESTING_Barrier::expected_reaches, GNUNET_ERROR_TYPE_DEBUG, LOG, GNUNET_TESTING_Barrier::number_to_be_reached, GNUNET_TESTING_Barrier::percentage_to_be_reached, and GNUNET_TESTING_Barrier::reached.

Referenced by barrier_reached(), and barrier_reached_run().

Here is the caller graph for this function:

◆ GNUNET_TESTING_finish_barrier_()

void GNUNET_TESTING_finish_barrier_ ( struct GNUNET_TESTING_Interpreter is,
const char *  barrier_name 
)

Finish all "barrier reached" commands attached to this barrier.

Parameters
barrierThe barrier in question.

Definition at line 851 of file testing_api_loop.c.

853{
854 struct CommandListEntry *pos;
855 struct GNUNET_TESTING_Barrier *barrier;
856
858 barrier_name);
859 if (NULL == barrier)
860 return;
861 while (NULL != (pos = barrier->cmds_head))
862 {
864 "command label %s\n",
865 pos->command->label.value);
866 if ( (GNUNET_NO == pos->command->ac->finished) &&
868 {
870 "command label %s finish\n",
871 pos->command->label.value);
873 }
874 else if (GNUNET_NO == pos->command->ac->finished)
875 {
877 }
879 barrier->cmds_tail,
880 pos);
882 "command entry label %s removed\n",
883 pos->command->label.value);
884 GNUNET_free (pos);
886 "command entry freed\n");
887 }
889 barrier);
890}
struct GNUNET_TESTING_Interpreter * is
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TESTING_Command * command
Definition: testing.h:148
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).
struct CommandListEntry * cmds_tail
Tail of the DLL with local commands the barrier is attached too.
Definition: testing.h:172
struct CommandListEntry * cmds_head
Head of the DLL with local commands the barrier is attached too.
Definition: testing.h:167
struct GNUNET_TESTING_CommandLabel label
Label for the command.
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 call finish, even if finish is non-NULL.
struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Getting a barrier from the interpreter.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
static void free_barrier_nodes(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)

References GNUNET_TESTING_Command::ac, GNUNET_TESTING_Command::asynchronous_finish, GNUNET_TESTING_Barrier::cmds_head, GNUNET_TESTING_Barrier::cmds_tail, CommandListEntry::command, GNUNET_TESTING_AsyncContext::finished, free_barrier_nodes(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_TESTING_async_finish(), GNUNET_TESTING_get_barrier_(), GNUNET_YES, is, GNUNET_TESTING_Command::label, and GNUNET_TESTING_CommandLabel::value.

Referenced by barrier_reached(), barrier_reached_run(), and tokenizer_cb().

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

◆ GNUNET_TESTING_send_barrier_attach_()

void GNUNET_TESTING_send_barrier_attach_ ( struct GNUNET_TESTING_Interpreter is,
const char *  barrier_name,
unsigned int  global_node_number,
unsigned int  expected_reaches,
GNUNET_TESTING_cmd_helper_write_cb  write_message 
)

Send message to master loop that cmds being attached to a barrier.

FIXME: Unused function

Parameters
isThe interpreter loop.
barrier_nameThe name of the barrier to attach to.
subnet_numberThe number of the subnet.
node_numberThe node to inform.
write_messageCallback to write messages to the master loop.

Definition at line 55 of file testing_api_cmd_barrier.c.

61{
62 // FIXME: avoid useless malloc!
63 struct CommandBarrierAttached *atm = GNUNET_new (struct
65 size_t msg_length = sizeof(struct CommandBarrierAttached);
66 size_t name_len;
67
68 name_len = strlen (barrier_name) + 1;
70 atm->header.size = htons ((uint16_t) msg_length);
72 atm->node_number = global_node_number;
73 memcpy (&atm[1], barrier_name, name_len);
74 write_message ((struct GNUNET_MessageHeader *) atm, msg_length);
75
76 GNUNET_free (atm);
77}
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED
Message send by a child loop to inform the master loop how much GNUNET_CMDS_BARRIER_REACHED messages ...
Definition: testing.h:49
uint32_t expected_reaches
How often the child loop will reach the barrier.
Definition: testing.h:58
uint32_t node_number
The number of the node the barrier is running on.
Definition: testing.h:63
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED.
Definition: testing.h:53
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References CommandBarrierAttached::expected_reaches, GNUNET_free, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED, GNUNET_new, CommandBarrierAttached::header, CommandBarrierAttached::node_number, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and write_message().

Here is the call graph for this function:

◆ GNUNET_TESTING_barrier_get_node()

struct GNUNET_TESTING_NetjailNode * GNUNET_TESTING_barrier_get_node ( struct GNUNET_TESTING_Barrier barrier,
unsigned int  node_number 
)

Getting a node from a map by global node number.

FIXME: This is a barrier helper function not related to a command but it is implemented in the *_cmd_barrier.c file. Maybe move into a separate file like testing_barrier.c; see also can barrier advance above

Parameters
nodesThe map.
node_numberThe global node number.
Returns
The node.

Definition at line 165 of file testing_api_cmd_barrier.c.

167{
168 struct GNUNET_HashCode hc;
170
171 GNUNET_CRYPTO_hash (&node_number,
172 sizeof(node_number),
173 &hc);
174 memcpy (&key,
175 &hc,
176 sizeof (key));
178 &key);
179}
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_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.
A 512-bit hashcode.
A 256-bit hashcode.
struct GNUNET_CONTAINER_MultiShortmap * nodes
Hash map containing the global known nodes which are not natted.
Definition: testing.h:177

References GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_hash(), key, and GNUNET_TESTING_Barrier::nodes.

Referenced by barrier_attached().

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 
)

Getting a barrier from the interpreter.

Parameters
isThe interpreter.
barrier_nameThe name of the barrier.
Returns
The barrier.

Definition at line 804 of file testing_api_loop.c.

806{
807 struct GNUNET_HashCode hc;
808 struct GNUNET_ShortHashCode create_key;
809
810 GNUNET_CRYPTO_hash (barrier_name,
811 strlen (barrier_name),
812 &hc);
813 memcpy (&create_key,
814 &hc,
815 sizeof (create_key));
817 &create_key);
818}
struct GNUNET_CONTAINER_MultiShortmap * barriers
Map with barriers for this loop.

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

Referenced by barrier_attached(), barrier_reached(), barrier_reached_run(), GNUNET_TESTING_finish_barrier_(), and start_helper().

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

Parameters
isThe interpreter.
barrierThe barrier to add.

Add a barrier to the loop.

Parameters
isThe interpreter.
barrierThe barrier to add.

Definition at line 828 of file testing_api_loop.c.

830{
831 struct GNUNET_HashCode hc;
832 struct GNUNET_ShortHashCode create_key;
833
835 "Adding barrier %s locally\n",
836 barrier->name);
837 GNUNET_CRYPTO_hash (barrier->name,
838 strlen (barrier->name),
839 &hc);
840 memcpy (&create_key,
841 &hc,
842 sizeof (create_key));
844 &create_key,
845 barrier,
847}
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
const char * name
Name of the barrier.
Definition: testing.h:182

References GNUNET_TESTING_Interpreter::barriers, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, is, and GNUNET_TESTING_Barrier::name.

Referenced by barrier_reached_run(), barrier_run(), and start_helper().

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