diff options
Diffstat (limited to 'src/lib/testing/testing_api_loop.h')
-rw-r--r-- | src/lib/testing/testing_api_loop.h | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/lib/testing/testing_api_loop.h b/src/lib/testing/testing_api_loop.h new file mode 100644 index 000000000..2a3047183 --- /dev/null +++ b/src/lib/testing/testing_api_loop.h | |||
@@ -0,0 +1,163 @@ | |||
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 | |||
21 | /** | ||
22 | * @file testing_api_loop.h | ||
23 | * @brief | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #ifndef TESTING_API_LOOP_H | ||
27 | #define TESTING_API_LOOP_H | ||
28 | |||
29 | #include "testing_api_barrier.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Callback function to write messages from the helper process running on a netjail node to the master process. | ||
34 | * | ||
35 | * @param message The message to write. | ||
36 | */ | ||
37 | typedef void | ||
38 | (*GNUNET_TESTING_cmd_helper_write_cb) ( | ||
39 | const struct GNUNET_MessageHeader *message); | ||
40 | |||
41 | |||
42 | /** | ||
43 | * The plugin API every test case plugin has to implement. | ||
44 | */ | ||
45 | struct GNUNET_TESTING_PluginFunctions | ||
46 | { | ||
47 | |||
48 | /** | ||
49 | * Closure to pass to start_testcase. | ||
50 | */ | ||
51 | void *cls; | ||
52 | |||
53 | /** | ||
54 | * Function to be implemented for each test case plugin which starts the test case on a netjail node. | ||
55 | * | ||
56 | * @param topology_data A file name for the file containing the topology configuration, or a string containing | ||
57 | * the topology configuration. | ||
58 | * @param barrier_count length of the @a barriers array | ||
59 | * @param barriers inherited barriers | ||
60 | * @param write_message Callback function to write messages from the helper process running on a | ||
61 | * netjail node to the master process. | ||
62 | * @param finish_cb Callback function which writes a message from the helper process running on a netjail | ||
63 | * node to the master process * signaling that the test case running on the netjail node finished. | ||
64 | * @return Returns The struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node. | ||
65 | */ | ||
66 | struct GNUNET_TESTING_Interpreter * | ||
67 | (*start_testcase) ( | ||
68 | void *cls, | ||
69 | const char *topology_data, | ||
70 | uint32_t barrier_count, | ||
71 | const struct GNUNET_ShortHashCode *barriers, | ||
72 | GNUNET_TESTING_cmd_helper_write_cb write_message, | ||
73 | GNUNET_TESTING_ResultCallback finish_cb, | ||
74 | void *finish_cb_cls); | ||
75 | |||
76 | }; | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Send message to our parent. Fails very hard if | ||
81 | * we do not have one. | ||
82 | * | ||
83 | * @param is The interpreter loop. | ||
84 | */ | ||
85 | void | ||
86 | GNUNET_TESTING_loop_notify_parent_ ( | ||
87 | struct GNUNET_TESTING_Interpreter *is, | ||
88 | const struct GNUNET_MessageHeader *hdr); | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Send message to all netjail children (if there | ||
93 | * are any). | ||
94 | * | ||
95 | * @param is The interpreter loop. | ||
96 | */ | ||
97 | void | ||
98 | GNUNET_TESTING_loop_notify_children_ ( | ||
99 | struct GNUNET_TESTING_Interpreter *is, | ||
100 | const struct GNUNET_MessageHeader *hdr); | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Current command is done, run the next one. | ||
105 | */ | ||
106 | void | ||
107 | GNUNET_TESTING_interpreter_next_ (void *cls); | ||
108 | |||
109 | |||
110 | void | ||
111 | GNUNET_TESTING_interpreter_run_cmd_ ( | ||
112 | struct GNUNET_TESTING_Interpreter *is, | ||
113 | struct GNUNET_TESTING_Command *cmd); | ||
114 | |||
115 | /** | ||
116 | * Adding a helper handle to the interpreter. | ||
117 | * | ||
118 | * @param is The interpreter. | ||
119 | * @param helper The helper handle. | ||
120 | */ | ||
121 | void | ||
122 | GNUNET_TESTING_add_netjail_helper_ ( | ||
123 | struct GNUNET_TESTING_Interpreter *is, | ||
124 | struct GNUNET_HELPER_Handle *helper); | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Add a barrier to the interpreter to share it with | ||
129 | * all children as an inherited barrier. | ||
130 | * | ||
131 | * @param is The interpreter. | ||
132 | * @param barrier The barrier to add. | ||
133 | */ | ||
134 | void | ||
135 | GNUNET_TESTING_add_barrier_ ( | ||
136 | struct GNUNET_TESTING_Interpreter *is, | ||
137 | struct GNUNET_TESTING_Barrier *barrier); | ||
138 | |||
139 | |||
140 | struct GNUNET_TESTING_Barrier * | ||
141 | GNUNET_TESTING_get_barrier2_ ( | ||
142 | struct GNUNET_TESTING_Interpreter *is, | ||
143 | const struct GNUNET_ShortHashCode *create_key); | ||
144 | |||
145 | |||
146 | struct GNUNET_TESTING_Barrier * | ||
147 | GNUNET_TESTING_get_barrier_ ( | ||
148 | struct GNUNET_TESTING_Interpreter *is, | ||
149 | const char *barrier_name); | ||
150 | |||
151 | |||
152 | unsigned int | ||
153 | GNUNET_TESTING_barrier_count_ ( | ||
154 | struct GNUNET_TESTING_Interpreter *is); | ||
155 | |||
156 | |||
157 | void | ||
158 | GNUNET_TESTING_barrier_iterate_ ( | ||
159 | struct GNUNET_TESTING_Interpreter *is, | ||
160 | GNUNET_CONTAINER_ShortmapIterator cb, | ||
161 | void *cb_cls); | ||
162 | |||
163 | #endif | ||