GNUnet 0.21.1
testing_api_cmd_barrier_reached.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_testing_lib.h"
28#include "testing_cmds.h"
32#include "testing.h"
33
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
44{
50
55
59 const char *label;
60
64 const char *barrier_name;
65
66 /*
67 * The global numer of the node the cmd runs on.
68 */
69 unsigned int node_number;
70
74 unsigned int asynchronous_finish;
75
79 unsigned int running_on_master;
80};
81
82
89static void
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;
101
103 brs->barrier_name);
104 if (NULL == barrier)
105 {
106 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
107 barrier->name = brs->barrier_name;
109 barrier);
110 }
111 barrier->reached++;
113 {
114 GNUNET_assert (NULL != cmd);
117 barrier->name);
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 }
131
132 if (GNUNET_NO == brs->running_on_master)
133 {
134 char *terminator = "\0";
135
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}
148
149
156static void
158{
159 struct BarrierReachedState *brs = cls;
160
161 GNUNET_free (brs);
162}
163
164
176 const void **ret,
177 const char *trait,
178 unsigned int index)
179{
180 struct BarrierReachedState *brs = cls;
181 struct GNUNET_TESTING_AsyncContext *ac = &brs->ac;
182
183 struct GNUNET_TESTING_Trait traits[] = {
186 };
187
188 return GNUNET_TESTING_get_trait (traits,
189 ret,
190 trait,
191 index);
192}
193
194
208 const char *label,
209 const char *barrier_label,
210 unsigned int asynchronous_finish,
211 unsigned int node_number,
212 unsigned int running_on_master,
214{
215 struct BarrierReachedState *brs;
216
217 brs = GNUNET_new (struct BarrierReachedState);
218 brs->label = label;
219 brs->barrier_name = barrier_label;
228 &brs->ac);
229}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_TESTING_Interpreter * is
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
API to manage barriers.
Convenience API for writing testcases for GNUnet.
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.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_async_context(struct GNUNET_TESTING_AsyncContext *value)
void(* GNUNET_TESTING_cmd_helper_write_cb)(struct GNUNET_MessageHeader *message, size_t msg_length)
Callback function to write messages from the helper process running on a netjail node to the master p...
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
Struct with information for callbacks.
const char * barrier_name
The name of the barrier this commands wait (if finishing asynchronous) for or/and reaches.
const char * label
The label of this command.
unsigned int running_on_master
Is this cmd running on the master loop.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
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.
State each asynchronous command must have in its closure.
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.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
Global state of the interpreter, used by a command to access information about other commands.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
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_finish_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Finish all "barrier reached" commands attached to this barrier.
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...
void GNUNET_TESTING_add_barrier_(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.
static void barrier_reached_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
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.
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.
#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.
Message formats for communication between testing cmds helper and testcase plugins.