aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 22:34:49 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 22:34:49 +0000
commitc0b81510ffe194dc662c3a6267d5e66a69873c4b (patch)
tree5ad5cc473d6993523be80bcf1430230e224d9216 /src/transport/transport-testing.h
parenta7345f7436c421fd15e18e87ec399ea93b6dde03 (diff)
downloadgnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.tar.gz
gnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.zip
-start to refactor testcases for sanity
Diffstat (limited to 'src/transport/transport-testing.h')
-rw-r--r--src/transport/transport-testing.h208
1 files changed, 128 insertions, 80 deletions
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index b3d6f2a2b..fc017e377 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V. 3 Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,9 +21,11 @@
21/** 21/**
22 * @file transport-testing.h 22 * @file transport-testing.h
23 * @brief testing lib for transport service 23 * @brief testing lib for transport service
24 *
25 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff
26 */ 26 */
27#ifndef TRANSPORT_TESTING_H
28#define TRANSPORT_TESTING_H
27#include "platform.h" 29#include "platform.h"
28#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
29#include "gnunet_hello_lib.h" 31#include "gnunet_hello_lib.h"
@@ -31,56 +33,45 @@
31#include "gnunet_testing_lib.h" 33#include "gnunet_testing_lib.h"
32 34
33 35
34struct GNUNET_TRANSPORT_TESTING_ConnectRequest;
35
36
37/** 36/**
38 * Context for a single peer 37 * Context for a single peer
39 */ 38 */
40struct PeerContext; 39struct GNUNET_TRANSPORT_TESTING_PeerContext;
41 40
42/** 41/**
43 * Callback when two peers are connected and both have called the connect callback 42 * Definition for a transport testing handle
44 * to notify clients about a new peer
45 */ 43 */
46typedef void 44struct GNUNET_TRANSPORT_TESTING_Handle;
47(*GNUNET_TRANSPORT_TESTING_start_cb) (struct PeerContext *p, 45
48 void *cls);
49 46
50/** 47/**
51 * Callback when two peers are connected and both have called the connect callback 48 * Callback when two peers are connected and both have called the connect callback
52 * to notify clients about a new peer 49 * to notify clients about a new peer
53 */ 50 */
54typedef void 51typedef void
55(*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext *p1, 52(*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
56 struct PeerContext *p2, 53 void *cls);
57 void *cls);
58
59 54
60/**
61 * Definition for a transport testing handle
62 */
63struct GNUNET_TRANSPORT_TESTING_handle;
64 55
65/** 56/**
66 * Context for a single peer 57 * Context for a single peer
67 */ 58 */
68struct PeerContext 59struct GNUNET_TRANSPORT_TESTING_PeerContext
69{ 60{
70 /** 61 /**
71 * Next element in the DLL 62 * Next element in the DLL
72 */ 63 */
73 struct PeerContext *next; 64 struct GNUNET_TRANSPORT_TESTING_PeerContext *next;
74 65
75 /** 66 /**
76 * Previous element in the DLL 67 * Previous element in the DLL
77 */ 68 */
78 struct PeerContext *prev; 69 struct GNUNET_TRANSPORT_TESTING_PeerContext *prev;
79 70
80 /** 71 /**
81 * Transport testing handle this peer belongs to 72 * Transport testing handle this peer belongs to
82 */ 73 */
83 struct GNUNET_TRANSPORT_TESTING_handle *tth; 74 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
84 75
85 /** 76 /**
86 * Peer's configuration 77 * Peer's configuration
@@ -135,7 +126,7 @@ struct PeerContext
135 /** 126 /**
136 * Startup completed callback 127 * Startup completed callback
137 */ 128 */
138 GNUNET_TRANSPORT_TESTING_start_cb start_cb; 129 GNUNET_TRANSPORT_TESTING_StartCallback start_cb;
139 130
140 /** 131 /**
141 * Peers HELLO Message 132 * Peers HELLO Message
@@ -154,23 +145,29 @@ struct PeerContext
154}; 145};
155 146
156 147
148/**
149 * Handle for a request to connect two peers.
150 */
157struct GNUNET_TRANSPORT_TESTING_ConnectRequest 151struct GNUNET_TRANSPORT_TESTING_ConnectRequest
158{ 152{
159 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next; 153 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next;
160 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev; 154 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev;
161 struct PeerContext *p1; 155 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
162 struct PeerContext *p2; 156 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
163 struct GNUNET_SCHEDULER_Task *tct; 157 struct GNUNET_SCHEDULER_Task *tct;
164 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; 158 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
165 struct GNUNET_TRANSPORT_OfferHelloHandle *oh; 159 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
166 GNUNET_TRANSPORT_TESTING_connect_cb cb; 160 GNUNET_SCHEDULER_TaskCallback cb;
167 void *cb_cls; 161 void *cb_cls;
168 int p1_c; 162 int p1_c;
169 int p2_c; 163 int p2_c;
170}; 164};
171 165
172 166
173struct GNUNET_TRANSPORT_TESTING_handle 167/**
168 * Handle for a test run.
169 */
170struct GNUNET_TRANSPORT_TESTING_Handle
174{ 171{
175 /** 172 /**
176 * Testing library system handle 173 * Testing library system handle
@@ -190,16 +187,34 @@ struct GNUNET_TRANSPORT_TESTING_handle
190 /** 187 /**
191 * head DLL of peers 188 * head DLL of peers
192 */ 189 */
193 struct PeerContext *p_head; 190 struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head;
194 191
195 /** 192 /**
196 * tail DLL of peers 193 * tail DLL of peers
197 */ 194 */
198 struct PeerContext *p_tail; 195 struct GNUNET_TRANSPORT_TESTING_PeerContext *p_tail;
199}; 196};
200 197
201 198
202/** 199/**
200 * Initialize the transport testing
201 *
202 * @return transport testing handle
203 */
204struct GNUNET_TRANSPORT_TESTING_Handle *
205GNUNET_TRANSPORT_TESTING_init (void);
206
207
208/**
209 * Clean up the transport testing
210 *
211 * @param tth transport testing handle
212 */
213void
214GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
215
216
217/**
203 * Start a peer with the given configuration 218 * Start a peer with the given configuration
204 * 219 *
205 * @param tth the testing handle 220 * @param tth the testing handle
@@ -212,50 +227,46 @@ struct GNUNET_TRANSPORT_TESTING_handle
212 * @param cb_cls closure for callback 227 * @param cb_cls closure for callback
213 * @return the peer context 228 * @return the peer context
214 */ 229 */
215struct PeerContext * 230struct GNUNET_TRANSPORT_TESTING_PeerContext *
216GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, 231GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
217 const char *cfgname, 232 const char *cfgname,
218 int peer_id, 233 int peer_id,
219 GNUNET_TRANSPORT_ReceiveCallback rec, 234 GNUNET_TRANSPORT_ReceiveCallback rec,
220 GNUNET_TRANSPORT_NotifyConnect nc, 235 GNUNET_TRANSPORT_NotifyConnect nc,
221 GNUNET_TRANSPORT_NotifyDisconnect nd, 236 GNUNET_TRANSPORT_NotifyDisconnect nd,
222 GNUNET_TRANSPORT_TESTING_start_cb start_cb, 237 GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
223 void *cb_cls); 238 void *cb_cls);
224 239
225 240
226/** 241/**
227 * shutdown the given peer 242 * Shutdown the given peer
228 * 243 *
229 * @param tth the testing handle
230 * @param p the peer 244 * @param p the peer
231 */ 245 */
232void 246void
233GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, 247GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
234 struct PeerContext *pc);
235 248
236 249
237/** 250/**
238 * Restart the given peer 251 * Stops and restarts the given peer, sleeping (!) for 5s in between.
239 * 252 *
240 * @param p the peer 253 * @param p the peer
241 * @param cfgname the cfg file used to restart
242 * @param restart_cb restart callback 254 * @param restart_cb restart callback
243 * @param cb_cls callback closure 255 * @param cb_cls callback closure
244 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 256 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
245 */ 257 */
246int 258int
247GNUNET_TRANSPORT_TESTING_restart_peer (struct PeerContext *p, 259GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
248 const char *cfgname, 260 GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
249 GNUNET_TRANSPORT_TESTING_start_cb restart_cb,
250 void *cb_cls); 261 void *cb_cls);
251 262
252 263
264
253/** 265/**
254 * Connect the given peers and call the callback when both peers report the 266 * Connect the given peers and call the callback when both peers
255 * inbound connection. Remarks: start_peer's notify_connect callback can be called 267 * report the inbound connection. Remarks: start_peer's notify_connect
256 * before. 268 * callback can be called before.
257 * 269 *
258 * @param tth transport testing handle
259 * @param p1 peer 1 270 * @param p1 peer 1
260 * @param p2 peer 2 271 * @param p2 peer 2
261 * @param cb the callback to call when both peers notified that they are connected 272 * @param cb the callback to call when both peers notified that they are connected
@@ -263,48 +274,85 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct PeerContext *p,
263 * @return a connect request handle 274 * @return a connect request handle
264 */ 275 */
265struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 276struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
266GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth, 277GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
267 struct PeerContext *p1, 278 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
268 struct PeerContext *p2, 279 GNUNET_SCHEDULER_TaskCallback cb,
269 GNUNET_TRANSPORT_TESTING_connect_cb cb,
270 void *cls); 280 void *cls);
271 281
272 282
273/** 283/**
274 * Cancel the request to connect two peers 284 * Cancel the request to connect two peers. You MUST cancel the
275 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully 285 * request if you stop the peers before the peers connected
276 * @param tth testing 286 * succesfully.
287 *
277 * @param cc a connect request handle 288 * @param cc a connect request handle
278 */ 289 */
279void 290void
280GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *tth, 291GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
281 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 292
293/* ********************** high-level process functions *************** */
282 294
283 295
284/** 296/**
285 * Clean up the transport testing 297 * Main function of a testcase. Called with the initial setup data
286 * @param tth transport testing handle 298 * for the test as derived from the source name and the binary name.
299 *
300 * @param cls closure
301 * @param tth initialized testing handle
302 * @param test_plugin name of the plugin (if available)
303 * @param num_peers number of entries in the @a cfg_file array
304 * @param cfg_files array of names of configuration files for the peers
287 */ 305 */
288void 306typedef void
289GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth); 307(*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls,
308 struct GNUNET_TRANSPORT_TESTING_Handle *tth,
309 const char *test_plugin,
310 unsigned int num_peers,
311 const char *cfg_files[]);
290 312
291 313
292/** 314/**
293 * Initialize the transport testing 315 * Setup testcase. Calls @a check with the data the test needs.
294 * @return transport testing handle 316 *
317 * @param argv0 binary name (argv[0])
318 * @param filename source file name (__FILE__)
319 * @param num_peers number of peers to start
320 * @param check main function to run
321 * @param check_cls closure for @a check
322 * @return #GNUNET_OK on success
295 */ 323 */
296struct GNUNET_TRANSPORT_TESTING_handle * 324int
297GNUNET_TRANSPORT_TESTING_init (void); 325GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
326 const char *filename,
327 unsigned int num_peers,
328 GNUNET_TRANSPORT_TESTING_CheckCallback check,
329 void *check_cls);
298 330
299 331
300/** 332/**
301 * Extracts the test filename from an absolute file name and removes the extension 333 * Setup testcase. Calls @a check with the data the test needs.
334 *
335 * @param num_peers number of peers to start
336 * @param check main function to run
337 * @param check_cls closure for @a check
338 * @return #GNUNET_OK on success
339 */
340#define GNUNET_TRANSPORT_TESTING_main(num_peers,check,check_cls) \
341 GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls)
342
343
344/* ********************** low-level filename functions *************** */
345
346
347/**
348 * Extracts the test filename from an absolute file name and removes
349 * the extension.
350 *
302 * @param file absolute file name 351 * @param file absolute file name
303 * @param dest where to store result 352 * @return resulting test name
304 */ 353 */
305void 354char *
306GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, 355GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
307 char **dest);
308 356
309 357
310/** 358/**
@@ -312,12 +360,11 @@ GNUNET_TRANSPORT_TESTING_get_test_name (const char *file,
312 * if existing ".exe"-prefix and adds the peer-number 360 * if existing ".exe"-prefix and adds the peer-number
313 * 361 *
314 * @param file filename of the test, e.g. argv[0] 362 * @param file filename of the test, e.g. argv[0]
315 * @param dest where to write the filename
316 * @param count peer number 363 * @param count peer number
364 * @return configuration name to use
317 */ 365 */
318void 366char *
319GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, 367GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
320 char **dest,
321 int count); 368 int count);
322 369
323 370
@@ -325,21 +372,22 @@ GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
325 * Extracts the plugin anme from an absolute file name and the test name 372 * Extracts the plugin anme from an absolute file name and the test name
326 * @param file absolute file name 373 * @param file absolute file name
327 * @param test test name 374 * @param test test name
328 * @param dest where to store result 375 * @return the plugin name
329 */ 376 */
330void 377char *
331GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable, 378GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
332 const char *testname, 379 const char *testname);
333 char **pluginname);
334 380
335 381
336/** 382/**
337 * Extracts the filename from an absolute file name and removes the extenstion 383 * Extracts the filename from an absolute file name and removes the
384 * extenstion
385 *
338 * @param file absolute file name 386 * @param file absolute file name
339 * @param dest where to store result 387 * @return the source name
340 */ 388 */
341void 389char *
342GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file, 390GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file);
343 char **testname);
344 391
392#endif
345/* end of transport_testing.h */ 393/* end of transport_testing.h */