aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_block_until_external_trigger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_block_until_external_trigger.c')
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
new file mode 100644
index 000000000..2439afeaf
--- /dev/null
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -0,0 +1,139 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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
21/**
22 * @file testing_api_cmd_block_until_all_peers_started.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30/**
31 * Generic logging shortcut
32 */
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
34
35/**
36 * Struct with information for callbacks.
37 *
38 */
39struct BlockState
40{
41 /**
42 * Flag to indicate if all peers have started.
43 *
44 */
45 unsigned int *stop_blocking;
46};
47
48
49/**
50 * Trait function of this cmd does nothing.
51 *
52 */
53static int
54block_until_all_peers_started_traits (void *cls,
55 const void **ret,
56 const char *trait,
57 unsigned int index)
58{
59 return GNUNET_OK;
60}
61
62
63/**
64 * The cleanup function of this cmd frees resources the cmd allocated.
65 *
66 */
67static void
68block_until_all_peers_started_cleanup (void *cls,
69 const struct GNUNET_TESTING_Command *cmd)
70{
71 struct BlockState *bs = cls;
72
73 GNUNET_free (bs);
74}
75
76
77/**
78 * This function does nothing but to start the cmd.
79 *
80 */
81static void
82block_until_all_peers_started_run (void *cls,
83 const struct GNUNET_TESTING_Command *cmd,
84 struct GNUNET_TESTING_Interpreter *is)
85{
86 LOG (GNUNET_ERROR_TYPE_DEBUG,
87 "block_until_all_peers_started_run!\n");
88}
89
90
91/**
92 * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
93 *
94 */
95static int
96block_until_all_peers_started_finish (void *cls,
97 GNUNET_SCHEDULER_TaskCallback cont,
98 void *cont_cls)
99{
100 struct BlockState *bs = cls;
101 unsigned int *ret = bs->stop_blocking;
102
103 if (GNUNET_YES == *ret)
104 {
105 cont (cont_cls);
106 }
107
108 return *ret;
109}
110
111
112/**
113 * Create command.
114 *
115 * @param label name for command.
116 * @param all_peers_started Flag which will be set from outside.
117 * @return command.
118 */
119struct GNUNET_TESTING_Command
120GNUNET_TESTING_cmd_block_until_external_trigger (const char *label,
121 unsigned int *
122 stop_blocking)
123{
124 struct BlockState *bs;
125
126 bs = GNUNET_new (struct BlockState);
127 bs->stop_blocking = stop_blocking;
128
129 struct GNUNET_TESTING_Command cmd = {
130 .cls = bs,
131 .label = label,
132 .run = &block_until_all_peers_started_run,
133 .finish = &block_until_all_peers_started_finish,
134 .cleanup = &block_until_all_peers_started_cleanup,
135 .traits = &block_until_all_peers_started_traits
136 };
137
138 return cmd;
139}