GNUnet 0.21.2
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_api_loop.h"
29#include "testing_cmds.h"
30
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
41{
46
50 const char *label;
51
55 const char *barrier_name;
56
57};
58
59
66static void
69{
70 struct BarrierReachedState *brs = cls;
71 struct GNUNET_TESTING_Barrier *barrier;
72
74 brs->barrier_name);
75 if (NULL == barrier)
76 {
78 "No barrier `%s'\n",
79 brs->barrier_name);
81 return;
82 }
83 if (barrier->satisfied)
84 {
86 return;
87 }
89 barrier->cnt_waiting,
90 &brs->ac);
91 if (barrier->inherited)
92 {
94 .header.size = htons (sizeof (cbr)),
96 };
97
99 &cbr.barrier_key);
101 &cbr.header);
102 return;
103 }
104 barrier->reached++;
105 if (barrier->reached == barrier->expected_reaches)
106 {
108 .header.size = htons (sizeof (cbs)),
110 };
111
113 &cbs.barrier_key);
114 barrier->satisfied = true;
116 &cbs.header);
117 }
118 if (barrier->satisfied)
119 {
121 for (unsigned int i = 0; i<barrier->cnt_waiting; i++)
123 GNUNET_array_grow (barrier->waiting,
124 barrier->cnt_waiting,
125 0);
126 return;
127 }
128}
129
130
137static void
139{
140 struct BarrierReachedState *brs = cls;
141
142 GNUNET_free (brs);
143}
144
145
157 const void **ret,
158 const char *trait,
159 unsigned int index)
160{
161 struct GNUNET_TESTING_Trait traits[] = {
163 };
164
166 ret,
167 trait,
168 index);
169}
170
171
174 const char *label,
175 const char *barrier_label)
176{
177 struct BarrierReachedState *brs;
178
179 brs = GNUNET_new (struct BarrierReachedState);
180 brs->label = label;
181 brs->barrier_name = barrier_label;
183 brs,
184 label,
188 &brs->ac);
189}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(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 that may be asynchronous.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
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.
#define GNUNET_log(kind,...)
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_ERROR_TYPE_ERROR
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE
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.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
State each asynchronous command must have in its closure.
An entry for a barrier list.
bool inherited
Did we inherit the barrier from our parent loop?
unsigned int reached
Number of times the barrier has been reached.
unsigned int expected_reaches
Number of total commands expected to be reached by the barrier.
struct GNUNET_TESTING_AsyncContext ** waiting
Context of barrier reached commands of our local interpreter that are currently blocked on this barri...
unsigned int cnt_waiting
Length of the waiting array.
bool satisfied
Did we reach expected_reaches? Used in particular if inherited is true and we cannot compute locally.
Child to parent: I reached the given barrier, increment the counter (or pass to grandparent).
Definition: testing_cmds.h:78
struct GNUNET_ShortHashCode barrier_key
Definition: testing_cmds.h:80
struct GNUNET_MessageHeader header
Definition: testing_cmds.h:79
Parent to child: this barrier was satisfied.
Definition: testing_cmds.h:100
struct GNUNET_MessageHeader header
Definition: testing_cmds.h:101
struct GNUNET_ShortHashCode barrier_key
Definition: testing_cmds.h:102
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
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.
void GNUNET_TESTING_barrier_name_hash_(const char *barrier_name, struct GNUNET_ShortHashCode *bkey)
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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached(const char *label, const char *barrier_label)
If this command is executed the the process is signaling the master process that it reached a barrier...
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
void GNUNET_TESTING_loop_notify_parent_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
Send message to our parent.
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).
Message formats for communication between testing cmds helper and testcase plugins.