aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2020-02-29 19:12:19 +0100
committerxrs <xrs@mail36.net>2020-05-21 22:46:48 +0200
commit4fa906387acd7e77d7521300602268927ddd9699 (patch)
tree5ae4ad50b09e7f4805370a54edd94b6c09ea9cc1
parent2679c684b9f48935debb3ae5456bd2c064fa7ad0 (diff)
downloadgnunet-4fa906387acd7e77d7521300602268927ddd9699.tar.gz
gnunet-4fa906387acd7e77d7521300602268927ddd9699.zip
separate testbed management from test logic
-rw-r--r--src/cadet/Makefile.am3
-rw-r--r--src/cadet/test_cadeT.c247
-rw-r--r--src/cadet/test_cadeT_util.c271
-rw-r--r--src/cadet/test_cadeT_util.h38
4 files changed, 317 insertions, 242 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index 572bdf4d9..80294a785 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -141,7 +141,8 @@ dep_cadet_test_lib = \
141 $(top_builddir)/src/statistics/libgnunetstatistics.la 141 $(top_builddir)/src/statistics/libgnunetstatistics.la
142 142
143test_cadet_2_channel_resumption_SOURCES = \ 143test_cadet_2_channel_resumption_SOURCES = \
144 test_cadeT.c 144 test_cadeT.c \
145 test_cadeT_util.c test_cadeT_util.h
145test_cadet_2_channel_resumption_LDADD = $(ld_cadet_test_lib) 146test_cadet_2_channel_resumption_LDADD = $(ld_cadet_test_lib)
146 147
147test_cadet_2_forward_SOURCES = \ 148test_cadet_2_forward_SOURCES = \
diff --git a/src/cadet/test_cadeT.c b/src/cadet/test_cadeT.c
index d4688273b..58b6db543 100644
--- a/src/cadet/test_cadeT.c
+++ b/src/cadet/test_cadeT.c
@@ -52,258 +52,23 @@
52#include "platform.h" 52#include "platform.h"
53#include "gnunet_testbed_service.h" 53#include "gnunet_testbed_service.h"
54#include "cadet.h" 54#include "cadet.h"
55#include <test_cadeT_util.h>
55 56
56#define REQUESTED_PEERS 2
57#define CONFIG "test_cadet.conf" 57#define CONFIG "test_cadet.conf"
58#define TESTPROGAM_NAME "test-cadet-channel-resumption" 58#define TESTPROGAM_NAME "test-cadet-channel-resumption"
59#define TIMEOUT_IN_SEC 5
60#define PORTNAME "cadet_port"
61
62/**
63 * Testbed operation for connecting to the services.
64 */
65static struct GNUNET_TESTBED_Operation *testbed_to_svc[2];
66
67/**
68 * Testbed operation for requesting peer information.
69 */
70static struct GNUNET_TESTBED_Operation *testbed_info_req[2];
71
72/**
73 * Port name kown by the two peers.
74 */
75static struct GNUNET_HashCode hashed_portname;
76
77/**
78 * Result of the test.
79 */
80static int test_result = 0;
81
82/**
83 * Counter for gathering peerinformation.
84 */
85static int peerinfo_cnt = 0;
86
87/**
88 * Structure for storing information of testbed peers.
89 */
90struct TEST_PEERS
91{
92 /**
93 * Index of the peer.
94 */
95 int idx;
96
97 /**
98 * Peer Identity.
99 */
100 struct GNUNET_PeerIdentity id;
101
102 /**
103 * Handle of TESTBED peer.
104 */
105 struct GNUNET_TESTBED_Peer *testbed_peer;
106
107 /**
108 * Testbed management is finished and test peer is ready for test logic.
109 */
110 int ready;
111
112 /**
113 * Channel of initiating peer.
114 */
115 struct GNUNET_CADET_Channel *channel;
116
117 /**
118 * CADET handle.
119 */
120 struct GNUNET_CADET_Handle *cadet;
121
122} test_peers[2];
123
124 59
125/****************************** TEST LOGIC ********************************/ 60/****************************** TEST LOGIC ********************************/
126 61
127// TBD 62void
128 63run_test ()
129/************************** TESBED MANAGEMENT *****************************/
130
131static void
132shutdown_task (void *cls)
133{
134 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
135
136 for (int i=0; i<REQUESTED_PEERS; i++)
137 GNUNET_TESTBED_operation_done (testbed_to_svc[i]);
138}
139
140static void
141timeout ()
142{
143 GNUNET_SCHEDULER_shutdown ();
144}
145
146static void
147disconnect_from_peer (void *cls,
148 void *op_result)
149{
150 struct GNUNET_CADET_Handle *cadet = op_result;
151
152 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
153
154 GNUNET_CADET_disconnect (cadet);
155}
156
157static void
158disconnect_channel (void *cls,
159 const struct GNUNET_CADET_Channel *channel)
160{ 64{
161 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); 65 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
162}
163
164static void *
165setup_initiating_peer (void *cls,
166 const struct GNUNET_CONFIGURATION_Handle *cfg)
167{
168 struct GNUNET_CADET_Handle *cadet;
169 struct GNUNET_CADET_Channel *channel;
170
171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
172
173 cadet = GNUNET_CADET_connect (cfg);
174 test_peers[0].cadet = cadet;
175
176 if (NULL == cadet)
177 GNUNET_SCHEDULER_shutdown ();
178
179 channel = GNUNET_CADET_channel_create (cadet,
180 NULL,
181 &test_peers[1].id,
182 &hashed_portname,
183 NULL,
184 &disconnect_channel,
185 NULL);
186 test_peers[0].channel = channel;
187
188 return cadet;
189}
190
191static void *
192handle_port_connects (void *cls,
193 struct GNUNET_CADET_Channel *channel,
194 const struct GNUNET_PeerIdentity *source)
195{
196 return NULL;
197}
198
199static void
200handle_port_disconnects (void *cls,
201 const struct GNUNET_CADET_Channel *channel)
202{
203}
204
205static void *
206setup_listening_peer (void *cls,
207 const struct GNUNET_CONFIGURATION_Handle *cfg)
208{
209 struct GNUNET_CADET_Handle *cadet;
210 struct GNUNET_CADET_Port *port;
211
212 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
213
214 cadet = GNUNET_CADET_connect (cfg);
215 test_peers[1].cadet = cadet;
216 66
217 if (NULL == cadet) 67 /**
218 GNUNET_SCHEDULER_shutdown (); 68 * Do testing here.
219 69 */
220 GNUNET_CRYPTO_hash (PORTNAME, sizeof(PORTNAME), &hashed_portname);
221 port = GNUNET_CADET_open_port (cadet, &hashed_portname,
222 &handle_port_connects,
223 NULL,
224 NULL,
225 &handle_port_disconnects,
226 NULL);
227
228 return cadet;
229}
230
231static void
232check_test_readyness (void *cls,
233 struct GNUNET_TESTBED_Operation *op,
234 void *ca_result,
235 const char *emsg)
236{
237 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
238}
239
240
241static int
242peerinfo_complete ()
243{
244 return (REQUESTED_PEERS == ++peerinfo_cnt) ? GNUNET_YES : GNUNET_NO;
245}
246
247static void
248connect_to_service (void *cb_cls,
249 struct GNUNET_TESTBED_Operation *op,
250 const struct GNUNET_TESTBED_PeerInformation *pinfo,
251 const char *emsg)
252{
253 struct TEST_PEERS *test_peer = cb_cls;
254
255 // Store peer ID.
256 test_peer->id = *(pinfo->result.id);
257
258 if (peerinfo_complete())
259 {
260 testbed_to_svc[1] =
261 GNUNET_TESTBED_service_connect (NULL, test_peers[1].testbed_peer,
262 "cadet",
263 &check_test_readyness, NULL,
264 &setup_listening_peer,
265 &disconnect_from_peer, NULL);
266 testbed_to_svc[0] =
267 GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer,
268 "cadet",
269 &check_test_readyness, NULL,
270 &setup_initiating_peer,
271 &disconnect_from_peer, NULL);
272 }
273} 70}
274 71
275static void
276connect_to_peers (void *cls,
277 struct GNUNET_TESTBED_RunHandle *h,
278 unsigned int num_peers,
279 struct GNUNET_TESTBED_Peer **peers,
280 unsigned int links_succeeded,
281 unsigned int links_failed)
282{
283 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
284
285 GNUNET_assert (0 == links_failed);
286
287 for (int i=0; i<num_peers; i++)
288 {
289 test_peers[i].ready = GNUNET_NO;
290 test_peers[i].idx = i;
291 test_peers[i].testbed_peer = peers[i];
292 }
293
294 testbed_info_req[0] = GNUNET_TESTBED_peer_get_information (peers[0],
295 GNUNET_TESTBED_PIT_IDENTITY,
296 &connect_to_service,
297 &test_peers[0]);
298 testbed_info_req[1] = GNUNET_TESTBED_peer_get_information (peers[1],
299 GNUNET_TESTBED_PIT_IDENTITY,
300 &connect_to_service,
301 &test_peers[1]);
302
303 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
304 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT_IN_SEC),
305 &timeout, NULL);
306}
307 72
308int 73int
309main (int argc, char *argv[]) 74main (int argc, char *argv[])
diff --git a/src/cadet/test_cadeT_util.c b/src/cadet/test_cadeT_util.c
new file mode 100644
index 000000000..89fe2a5f0
--- /dev/null
+++ b/src/cadet/test_cadeT_util.c
@@ -0,0 +1,271 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009 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 * @file cadet/test_cadeT_util.c
22 * @brief testcase for cadet.c
23 * @author xrs
24 */
25
26#include <test_cadeT_util.h>
27
28/**
29 * Testbed operation for connecting to the services.
30 */
31static struct GNUNET_TESTBED_Operation *testbed_to_svc[2];
32
33/**
34 * Testbed operation for requesting peer information.
35 */
36static struct GNUNET_TESTBED_Operation *testbed_info_req[2];
37
38/**
39 * Port name kown by the two peers.
40 */
41static struct GNUNET_HashCode hashed_portname;
42
43/**
44 * Result of the test.
45 */
46int test_result = 0;
47
48/**
49 * Counter for gathering peerinformation.
50 */
51static int peerinfo_cnt = 0;
52
53/**
54 * Structure for storing information of testbed peers.
55 */
56struct TEST_PEERS
57{
58 /**
59 * Index of the peer.
60 */
61 int idx;
62
63 /**
64 * Peer Identity.
65 */
66 struct GNUNET_PeerIdentity id;
67
68 /**
69 * Handle of TESTBED peer.
70 */
71 struct GNUNET_TESTBED_Peer *testbed_peer;
72
73 /**
74 * Testbed management is finished and test peer is ready for test logic.
75 */
76 int ready;
77
78 /**
79 * Channel of initiating peer.
80 */
81 struct GNUNET_CADET_Channel *channel;
82
83 /**
84 * CADET handle.
85 */
86 struct GNUNET_CADET_Handle *cadet;
87
88} test_peers[2];
89
90/************************** TESBED MANAGEMENT *****************************/
91
92static void
93shutdown_task (void *cls)
94{
95 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
96
97 for (int i=0; i<REQUESTED_PEERS; i++)
98 GNUNET_TESTBED_operation_done (testbed_to_svc[i]);
99}
100
101static void
102timeout ()
103{
104 GNUNET_SCHEDULER_shutdown ();
105}
106
107static void
108disconnect_from_peer (void *cls,
109 void *op_result)
110{
111 struct GNUNET_CADET_Handle *cadet = op_result;
112
113 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
114
115 GNUNET_CADET_disconnect (cadet);
116}
117
118static void
119disconnect_channel (void *cls,
120 const struct GNUNET_CADET_Channel *channel)
121{
122 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
123}
124
125static void *
126setup_initiating_peer (void *cls,
127 const struct GNUNET_CONFIGURATION_Handle *cfg)
128{
129 struct GNUNET_CADET_Handle *cadet;
130 struct GNUNET_CADET_Channel *channel;
131
132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
133
134 cadet = GNUNET_CADET_connect (cfg);
135 test_peers[0].cadet = cadet;
136
137 if (NULL == cadet)
138 GNUNET_SCHEDULER_shutdown ();
139
140 channel = GNUNET_CADET_channel_create (cadet,
141 NULL,
142 &test_peers[1].id,
143 &hashed_portname,
144 NULL,
145 &disconnect_channel,
146 NULL);
147 test_peers[0].channel = channel;
148
149 return cadet;
150}
151
152static void *
153handle_port_connects (void *cls,
154 struct GNUNET_CADET_Channel *channel,
155 const struct GNUNET_PeerIdentity *source)
156{
157 return NULL;
158}
159
160static void
161handle_port_disconnects (void *cls,
162 const struct GNUNET_CADET_Channel *channel)
163{
164}
165
166static void *
167setup_listening_peer (void *cls,
168 const struct GNUNET_CONFIGURATION_Handle *cfg)
169{
170 struct GNUNET_CADET_Handle *cadet;
171 struct GNUNET_CADET_Port *port;
172
173 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
174
175 cadet = GNUNET_CADET_connect (cfg);
176 test_peers[1].cadet = cadet;
177
178 if (NULL == cadet)
179 GNUNET_SCHEDULER_shutdown ();
180
181 GNUNET_CRYPTO_hash (PORTNAME, sizeof(PORTNAME), &hashed_portname);
182 port = GNUNET_CADET_open_port (cadet, &hashed_portname,
183 &handle_port_connects,
184 NULL,
185 NULL,
186 &handle_port_disconnects,
187 NULL);
188
189 return cadet;
190}
191
192
193static void
194check_test_readyness (void *cls,
195 struct GNUNET_TESTBED_Operation *op,
196 void *ca_result,
197 const char *emsg)
198{
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
200
201 if (GNUNET_OK)
202 run_test();
203}
204
205
206static int
207peerinfo_complete ()
208{
209 return (REQUESTED_PEERS == ++peerinfo_cnt) ? GNUNET_YES : GNUNET_NO;
210}
211
212void
213connect_to_service (void *cb_cls,
214 struct GNUNET_TESTBED_Operation *op,
215 const struct GNUNET_TESTBED_PeerInformation *pinfo,
216 const char *emsg)
217{
218 struct TEST_PEERS *test_peer = cb_cls;
219
220 // Store peer ID.
221 test_peer->id = *(pinfo->result.id);
222
223 if (peerinfo_complete())
224 {
225 testbed_to_svc[1] =
226 GNUNET_TESTBED_service_connect (NULL, test_peers[1].testbed_peer,
227 "cadet",
228 &check_test_readyness, NULL,
229 &setup_listening_peer,
230 &disconnect_from_peer, NULL);
231 testbed_to_svc[0] =
232 GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer,
233 "cadet",
234 &check_test_readyness, NULL,
235 &setup_initiating_peer,
236 &disconnect_from_peer, NULL);
237 }
238}
239
240void
241connect_to_peers (void *cls,
242 struct GNUNET_TESTBED_RunHandle *h,
243 unsigned int num_peers,
244 struct GNUNET_TESTBED_Peer **peers,
245 unsigned int links_succeeded,
246 unsigned int links_failed)
247{
248 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
249
250 GNUNET_assert (0 == links_failed);
251
252 for (int i=0; i<num_peers; i++)
253 {
254 test_peers[i].ready = GNUNET_NO;
255 test_peers[i].idx = i;
256 test_peers[i].testbed_peer = peers[i];
257 }
258
259 testbed_info_req[0] = GNUNET_TESTBED_peer_get_information (peers[0],
260 GNUNET_TESTBED_PIT_IDENTITY,
261 &connect_to_service,
262 &test_peers[0]);
263 testbed_info_req[1] = GNUNET_TESTBED_peer_get_information (peers[1],
264 GNUNET_TESTBED_PIT_IDENTITY,
265 &connect_to_service,
266 &test_peers[1]);
267
268 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
269 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT_IN_SEC),
270 &timeout, NULL);
271}
diff --git a/src/cadet/test_cadeT_util.h b/src/cadet/test_cadeT_util.h
new file mode 100644
index 000000000..361c10a26
--- /dev/null
+++ b/src/cadet/test_cadeT_util.h
@@ -0,0 +1,38 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009 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 * @file cadet/test_cadeT_util.h
22 * @brief testcase for cadet.c
23 * @author xrs
24 */
25
26#include "platform.h"
27#include "gnunet_testbed_service.h"
28#include "cadet.h"
29
30#define REQUESTED_PEERS 2
31#define TIMEOUT_IN_SEC 5
32#define PORTNAME "cadet_port"
33
34int test_result;
35
36void connect_to_peers ();
37
38void run_test ();