diff options
Diffstat (limited to 'src/testing/testing_api_cmd_block_until_all_peers_started.c')
-rw-r--r-- | src/testing/testing_api_cmd_block_until_all_peers_started.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c new file mode 100644 index 000000000..8659fbb46 --- /dev/null +++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c | |||
@@ -0,0 +1,128 @@ | |||
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 | struct BlockState | ||
36 | { | ||
37 | unsigned int *all_peers_started; | ||
38 | }; | ||
39 | |||
40 | |||
41 | static int | ||
42 | block_until_all_peers_started_traits (void *cls, | ||
43 | const void **ret, | ||
44 | const char *trait, | ||
45 | unsigned int index) | ||
46 | { | ||
47 | return GNUNET_OK; | ||
48 | } | ||
49 | |||
50 | |||
51 | static void | ||
52 | block_until_all_peers_started_cleanup (void *cls, | ||
53 | const struct GNUNET_TESTING_Command *cmd) | ||
54 | { | ||
55 | struct BlockState *bs = cls; | ||
56 | |||
57 | GNUNET_free (bs); | ||
58 | } | ||
59 | |||
60 | |||
61 | static void | ||
62 | block_until_all_peers_started_run (void *cls, | ||
63 | const struct GNUNET_TESTING_Command *cmd, | ||
64 | struct GNUNET_TESTING_Interpreter *is) | ||
65 | { | ||
66 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
67 | "block_until_all_peers_started_run!\n"); | ||
68 | } | ||
69 | |||
70 | |||
71 | static int | ||
72 | block_until_all_peers_started_finish (void *cls, | ||
73 | GNUNET_SCHEDULER_TaskCallback cont, | ||
74 | void *cont_cls) | ||
75 | { | ||
76 | struct BlockState *bs = cls; | ||
77 | unsigned int *ret = bs->all_peers_started; | ||
78 | |||
79 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
80 | "We got here 10\n"); | ||
81 | |||
82 | if (GNUNET_YES == *ret) | ||
83 | { | ||
84 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
85 | "We do not need to block anymore!\n"); | ||
86 | cont (cont_cls); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
91 | "You shall not pass!\n"); | ||
92 | } | ||
93 | |||
94 | return *ret; | ||
95 | } | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Create command. | ||
100 | * | ||
101 | * @param label name for command. | ||
102 | * @return command. | ||
103 | */ | ||
104 | struct GNUNET_TESTING_Command | ||
105 | GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, | ||
106 | unsigned int * | ||
107 | all_peers_started) | ||
108 | { | ||
109 | struct BlockState *bs; | ||
110 | |||
111 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
112 | "we have all_peers_started: %u\n", | ||
113 | *all_peers_started); | ||
114 | |||
115 | bs = GNUNET_new (struct BlockState); | ||
116 | bs->all_peers_started = all_peers_started; | ||
117 | |||
118 | struct GNUNET_TESTING_Command cmd = { | ||
119 | .cls = bs, | ||
120 | .label = label, | ||
121 | .run = &block_until_all_peers_started_run, | ||
122 | .finish = &block_until_all_peers_started_finish, | ||
123 | .cleanup = &block_until_all_peers_started_cleanup, | ||
124 | .traits = &block_until_all_peers_started_traits | ||
125 | }; | ||
126 | |||
127 | return cmd; | ||
128 | } | ||