diff options
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.c | 169 |
1 files changed, 0 insertions, 169 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 deleted file mode 100644 index 9360dd02e..000000000 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ /dev/null | |||
@@ -1,169 +0,0 @@ | |||
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 | #include "gnunet_testing_netjail_lib.h" | ||
30 | |||
31 | /** | ||
32 | * Generic logging shortcut | ||
33 | */ | ||
34 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
35 | |||
36 | |||
37 | /** | ||
38 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
39 | * | ||
40 | */ | ||
41 | static void | ||
42 | block_until_all_peers_started_cleanup (void *cls) | ||
43 | { | ||
44 | struct BlockState *bs = cls; | ||
45 | |||
46 | GNUNET_free (bs); | ||
47 | } | ||
48 | |||
49 | static int | ||
50 | block_until_external_trigger_traits (void *cls, | ||
51 | const void **ret, | ||
52 | const char *trait, | ||
53 | unsigned int index) | ||
54 | { | ||
55 | struct BlockState *bs = cls; | ||
56 | struct GNUNET_TESTING_AsyncContext *ac = &bs->ac; | ||
57 | struct GNUNET_TESTING_Trait traits[] = { | ||
58 | { | ||
59 | .index = 0, | ||
60 | .trait_name = "async_context", | ||
61 | .ptr = (const void *) ac, | ||
62 | }, | ||
63 | { | ||
64 | .index = 1, | ||
65 | .trait_name = "block_state", | ||
66 | .ptr = (const void *) bs, | ||
67 | }, | ||
68 | GNUNET_TESTING_trait_end () | ||
69 | }; | ||
70 | |||
71 | return GNUNET_TESTING_get_trait (traits, | ||
72 | ret, | ||
73 | trait, | ||
74 | index); | ||
75 | } | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Function to get the trait with the internal command state BlockState. | ||
80 | * | ||
81 | * * @param[out] ac struct BlockState. | ||
82 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
83 | */ | ||
84 | int | ||
85 | GNUNET_TESTING_get_trait_block_state ( | ||
86 | const struct GNUNET_TESTING_Command *cmd, | ||
87 | struct BlockState **bs) | ||
88 | { | ||
89 | return cmd->traits (cmd->cls, | ||
90 | (const void **) bs, | ||
91 | "block_state", | ||
92 | (unsigned int) 1); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Function to get the trait with the async context. | ||
98 | * | ||
99 | * @param[out] ac struct GNUNET_TESTING_AsyncContext. | ||
100 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
101 | */ | ||
102 | int | ||
103 | GNUNET_TESTING_get_trait_async_context ( | ||
104 | const struct GNUNET_TESTING_Command *cmd, | ||
105 | struct GNUNET_TESTING_AsyncContext **ac) | ||
106 | { | ||
107 | return cmd->traits (cmd->cls, | ||
108 | (const void **) ac, | ||
109 | "async_context", | ||
110 | (unsigned int) 0); | ||
111 | } | ||
112 | |||
113 | |||
114 | /** | ||
115 | * This function does nothing but to start the cmd. | ||
116 | * | ||
117 | */ | ||
118 | static void | ||
119 | block_until_all_peers_started_run (void *cls, | ||
120 | struct GNUNET_TESTING_Interpreter *is) | ||
121 | { | ||
122 | struct BlockState *bs = cls; | ||
123 | struct GNUNET_TESTING_Command *cmd = | ||
124 | GNUNET_TESTING_interpreter_get_current_command (is); | ||
125 | |||
126 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
127 | "block %s running %u!\n", | ||
128 | bs->label, | ||
129 | bs->asynchronous_finish); | ||
130 | if (GNUNET_YES == bs->asynchronous_finish) | ||
131 | { | ||
132 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
133 | "block %s running asynchronous!\n", | ||
134 | bs->label); | ||
135 | cmd->asynchronous_finish = bs->asynchronous_finish; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
141 | * Create command. | ||
142 | * | ||
143 | * @param label name for command. | ||
144 | * @param all_peers_started Flag which will be set from outside. | ||
145 | * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL. | ||
146 | * @return command. | ||
147 | */ | ||
148 | struct GNUNET_TESTING_Command | ||
149 | GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
150 | const char *label) | ||
151 | { | ||
152 | struct BlockState *bs; | ||
153 | |||
154 | bs = GNUNET_new (struct BlockState); | ||
155 | bs->label = label; | ||
156 | bs->asynchronous_finish = GNUNET_NO; | ||
157 | { | ||
158 | struct GNUNET_TESTING_Command cmd = { | ||
159 | .cls = bs, | ||
160 | .label = label, | ||
161 | .run = &block_until_all_peers_started_run, | ||
162 | .ac = &bs->ac, | ||
163 | .cleanup = &block_until_all_peers_started_cleanup, | ||
164 | .traits = block_until_external_trigger_traits | ||
165 | }; | ||
166 | |||
167 | return cmd; | ||
168 | } | ||
169 | } | ||