aboutsummaryrefslogtreecommitdiff
path: root/src/service/testing/testing_api_cmd_block_until_external_trigger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/testing/testing_api_cmd_block_until_external_trigger.c')
-rw-r--r--src/service/testing/testing_api_cmd_block_until_external_trigger.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/service/testing/testing_api_cmd_block_until_external_trigger.c b/src/service/testing/testing_api_cmd_block_until_external_trigger.c
new file mode 100644
index 000000000..fc312cdc9
--- /dev/null
+++ b/src/service/testing/testing_api_cmd_block_until_external_trigger.c
@@ -0,0 +1,119 @@
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 "testing_cmds.h"
29#include "gnunet_testing_plugin.h"
30#include "gnunet_testing_barrier.h"
31#include "gnunet_testing_netjail_lib.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38
39/**
40 * The cleanup function of this cmd frees resources the cmd allocated.
41 *
42 */
43static void
44block_until_all_peers_started_cleanup (void *cls)
45{
46 struct BlockState *bs = cls;
47
48 GNUNET_free (bs);
49}
50
51
52static int
53block_until_external_trigger_traits (void *cls,
54 const void **ret,
55 const char *trait,
56 unsigned int index)
57{
58 struct GNUNET_TESTING_BlockState *bs = cls;
59 struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
60 struct GNUNET_TESTING_Trait traits[] = {
61 GNUNET_TESTING_make_trait_async_context (ac),
62 GNUNET_TESTING_make_trait_block_state (bs),
63 GNUNET_TESTING_trait_end ()
64 };
65
66 return GNUNET_TESTING_get_trait (traits,
67 ret,
68 trait,
69 index);
70}
71
72
73/**
74 * This function does nothing but to start the cmd.
75 *
76 */
77static void
78block_until_all_peers_started_run (void *cls,
79 struct GNUNET_TESTING_Interpreter *is)
80{
81 struct GNUNET_TESTING_BlockState *bs = cls;
82 struct GNUNET_TESTING_Command *cmd =
83 GNUNET_TESTING_interpreter_get_current_command (is);
84
85 LOG (GNUNET_ERROR_TYPE_DEBUG,
86 "block %s running %u!\n",
87 bs->label,
88 bs->asynchronous_finish);
89 if (GNUNET_YES == bs->asynchronous_finish)
90 {
91 LOG (GNUNET_ERROR_TYPE_DEBUG,
92 "block %s running asynchronous!\n",
93 bs->label);
94 cmd->asynchronous_finish = bs->asynchronous_finish;
95 }
96}
97
98
99/**
100 * Create command.
101 *
102 * @param label name for command.
103 * @return command.
104 */
105struct GNUNET_TESTING_Command
106GNUNET_TESTING_cmd_block_until_external_trigger (
107 const char *label)
108{
109 struct GNUNET_TESTING_BlockState *bs;
110
111 bs = GNUNET_new (struct GNUNET_TESTING_BlockState);
112 bs->label = label;
113 return GNUNET_TESTING_command_new (bs,
114 label,
115 &block_until_all_peers_started_run,
116 &block_until_all_peers_started_cleanup,
117 &block_until_external_trigger_traits,
118 &bs->ac);
119}