GNUnet  0.20.0
testing_api_cmd_barrier_reached.c File Reference

Command to signal barrier was reached. More...

Include dependency graph for testing_api_cmd_barrier_reached.c:

Go to the source code of this file.

Data Structures

struct  BarrierReachedState
 Struct with information for callbacks. More...


#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...


static void barrier_reached_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run the command. More...
static void barrier_reached_cleanup (void *cls)
 Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof. More...
static enum GNUNET_GenericReturnValue barrier_reached_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Offer internal data from a "batch" CMD, to other commands. More...
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached (const char *label, const char *barrier_label, unsigned int asynchronous_finish, unsigned int node_number, unsigned int running_on_master, GNUNET_TESTING_cmd_helper_write_cb write_message)
 Create command. More...

Detailed Description

Command to signal barrier was reached.


Definition in file testing_api_cmd_barrier_reached.c.

Macro Definition Documentation


#define LOG (   kind,
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 37 of file testing_api_cmd_barrier_reached.c.

Function Documentation

◆ barrier_reached_run()

static void barrier_reached_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 

Run the command.

isthe interpreter state.

Definition at line 90 of file testing_api_cmd_barrier_reached.c.

92 {
93  struct BarrierReachedState *brs = cls;
94  struct GNUNET_TESTING_Barrier *barrier;
95  struct GNUNET_TESTING_Command *cmd =
97  struct CommandListEntry *cle;
98  size_t msg_length;
100  size_t name_len;
102  barrier = TST_interpreter_get_barrier (is, brs->barrier_name);
103  if (NULL == barrier)
104  {
105  barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
106  barrier->name = brs->barrier_name;
107  TST_interpreter_add_barrier (is, barrier);
109  "barrier %s added locally\n",
110  brs->barrier_name);
111  }
112  barrier->reached++;
113  if (GNUNET_TESTING_barrier_crossable (barrier))
114  {
115  GNUNET_assert (NULL != cmd);
118  }
119  else if (GNUNET_NO == brs->asynchronous_finish)
120  {
121  cle = GNUNET_new (struct CommandListEntry);
122  cle->command = cmd;
124  barrier->cmds_tail,
125  cle);
127  "added cle for %p %s\n",
128  barrier,
129  barrier->name);
130  }
132  if (GNUNET_NO == brs->running_on_master)
133  {
134  char *terminator = "\0";
136  name_len = strlen (barrier->name);
137  msg_length = sizeof(struct GNUNET_TESTING_CommandBarrierReached)
138  + name_len + 1;
139  msg = GNUNET_malloc (msg_length);
140  msg->header.size = htons ((uint16_t) msg_length);
142  msg->node_number = brs->node_number;
143  memcpy (&msg[1], barrier->name, name_len + 1);
144  memcpy (&msg[name_len + 1],terminator,1);
145  brs->write_message ((struct GNUNET_MessageHeader *) msg, msg_length);
146  }
147 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_TESTING_Interpreter * is
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
Struct with information for callbacks.
const char * barrier_name
The name of the barrier this commands wait (if finishing asynchronous) for or/and reaches.
unsigned int running_on_master
Is this cmd running on the master loop.
unsigned int asynchronous_finish
If this command will block.
GNUNET_TESTING_cmd_helper_write_cb write_message
Callback to write messages to the master loop.
struct GNUNET_TESTING_Command * command
Definition: testing.h:148
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.
const char * name
Name of the barrier.
Definition: testing.h:182
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
unsigned int reached
Number of commands which reached this barrier.
Definition: testing.h:197
A command to be run by the interpreter.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
void TST_interpreter_add_barrier(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.
struct GNUNET_TESTING_Barrier * TST_interpreter_get_barrier(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Getting a barrier from the interpreter.
void TST_interpreter_finish_attached_cmds(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Finish all "barrier reached" comands attached to this barrier.
unsigned int 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...
#define LOG(kind,...)
Generic logging shortcut.
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.

References GNUNET_TESTING_Command::asynchronous_finish, BarrierReachedState::asynchronous_finish, BarrierReachedState::barrier_name, GNUNET_TESTING_Barrier::cmds_head, GNUNET_TESTING_Barrier::cmds_tail, CommandListEntry::command, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED, GNUNET_new, GNUNET_NO, GNUNET_TESTING_barrier_crossable(), GNUNET_TESTING_interpreter_get_current_command(), GNUNET_YES, is, LOG, msg, GNUNET_TESTING_Barrier::name, BarrierReachedState::node_number, GNUNET_TESTING_Barrier::reached, BarrierReachedState::running_on_master, GNUNET_MessageHeader::size, TST_interpreter_add_barrier(), TST_interpreter_finish_attached_cmds(), TST_interpreter_get_barrier(), GNUNET_MessageHeader::type, and BarrierReachedState::write_message.

Here is the call graph for this function:

◆ barrier_reached_cleanup()

static void barrier_reached_cleanup ( void *  cls)

Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.


Definition at line 157 of file testing_api_cmd_barrier_reached.c.

158 {
159  struct BarrierReachedState *brs = cls;
161  GNUNET_free (brs);
162 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

◆ barrier_reached_traits()

static enum GNUNET_GenericReturnValue barrier_reached_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 

Offer internal data from a "batch" CMD, to other commands.

traitname of the trait.
indexindex number of the object to offer.
GNUNET_OK on success.

Definition at line 157 of file testing_api_cmd_barrier_reached.c.

179 {
180  struct BarrierReachedState *brs = cls;
181  struct GNUNET_TESTING_AsyncContext *ac = &brs->ac;
183  struct GNUNET_TESTING_Trait traits[] = {
186  };
188  return GNUNET_TESTING_get_trait (traits,
189  ret,
190  trait,
191  index);
192 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_async_context(struct GNUNET_TESTING_AsyncContext *value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" 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.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
State each asynchronous command must have in its closure.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.

◆ GNUNET_TESTING_cmd_barrier_reached()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached ( const char *  label,
const char *  barrier_label,
unsigned int  asynchronous_finish,
unsigned int  node_number,
unsigned int  running_on_master,
GNUNET_TESTING_cmd_helper_write_cb  write_message 

Create command.

If this command is executed the the process is signaling the master process that it reached a barrier.

labelname for command.
barrier_labelThe name of the barrier we wait for (if finishing asynchronous) and which will be reached.
asynchronous_finishIf GNUNET_YES this command will not block.
node_numberThe global numer of the node the cmd runs on.
running_on_masterIs this cmd running on the master loop.
write_messageCallback to write messages to the master loop.

Definition at line 157 of file testing_api_cmd_barrier_reached.c.

214 {
215  struct BarrierReachedState *brs;
217  brs = GNUNET_new (struct BarrierReachedState);
218  brs->label = label;
219  brs->barrier_name = barrier_label;
221  brs->node_number = node_number;
224  return GNUNET_TESTING_command_new (brs, label,
228  &brs->ac);
229 }
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
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.
const char * label
The label of this command.
static void barrier_reached_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static enum GNUNET_GenericReturnValue barrier_reached_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.
static void barrier_reached_cleanup(void *cls)
Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.