aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-08-31 13:48:59 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-08-31 13:48:59 +0000
commit721db5457eebf6e0d713cde2585ba298dbcfe1b7 (patch)
tree26c601343f30f3447fcc3a33f5eccec1d3373b64 /src
parentc0d23c3d48800d92773a7e65cf1eb19998da98b5 (diff)
downloadgnunet-721db5457eebf6e0d713cde2585ba298dbcfe1b7.tar.gz
gnunet-721db5457eebf6e0d713cde2585ba298dbcfe1b7.zip
moving code to generate cfg name used in every test to testing lib
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_transport_api.c27
-rw-r--r--src/transport/test_transport_api_multiaddress.c26
-rw-r--r--src/transport/test_transport_api_reliability.c9
-rw-r--r--src/transport/test_transport_api_unreliability.c9
-rw-r--r--src/transport/transport-testing.c40
-rw-r--r--src/transport/transport-testing.h15
6 files changed, 74 insertions, 52 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 365b833da..15f490947 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -233,6 +233,7 @@ run (void *cls, char *const *args, const char *cfgfile,
233 NULL); 233 NULL);
234} 234}
235 235
236
236static int 237static int
237check () 238check ()
238{ 239{
@@ -273,30 +274,8 @@ main (int argc, char *argv[])
273#endif 274#endif
274 NULL); 275 NULL);
275 276
276 char *pch = strdup (argv[0]);
277 char *backup = pch;
278 char *filename = NULL;
279 char *dotexe;
280 int nat_res; 277 int nat_res;
281 278
282 /* get executable filename */
283 pch = strtok (pch, "/");
284 while (pch != NULL)
285 {
286 pch = strtok (NULL, "/");
287 if (pch != NULL)
288 filename = pch;
289 }
290 /* remove "lt-" */
291 filename = strstr (filename, "tes");
292 if (NULL != (dotexe = strstr (filename, ".exe")))
293 dotexe[0] = '\0';
294
295 /* create cfg filename */
296 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
297 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
298 GNUNET_free (backup);
299
300 if ((strstr (argv[0], "tcp_nat") != NULL) || 279 if ((strstr (argv[0], "tcp_nat") != NULL) ||
301 (strstr (argv[0], "udp_nat") != NULL)) 280 (strstr (argv[0], "udp_nat") != NULL))
302 { 281 {
@@ -315,6 +294,10 @@ main (int argc, char *argv[])
315 } 294 }
316 295
317 } 296 }
297
298 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1);
299 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2);
300
318 ret = check (); 301 ret = check ();
319 302
320 GNUNET_free (cfg_file_p1); 303 GNUNET_free (cfg_file_p1);
diff --git a/src/transport/test_transport_api_multiaddress.c b/src/transport/test_transport_api_multiaddress.c
index 1dc16dd01..8204610d7 100644
--- a/src/transport/test_transport_api_multiaddress.c
+++ b/src/transport/test_transport_api_multiaddress.c
@@ -289,30 +289,8 @@ main (int argc, char *argv[])
289#endif 289#endif
290 NULL); 290 NULL);
291 291
292 char *pch = strdup (argv[0]);
293 char *backup = pch;
294 char *filename = NULL;
295 char *dotexe;
296 int nat_res; 292 int nat_res;
297 293
298 /* get executable filename */
299 pch = strtok (pch, "/");
300 while (pch != NULL)
301 {
302 pch = strtok (NULL, "/");
303 if (pch != NULL)
304 filename = pch;
305 }
306 /* remove "lt-" */
307 filename = strstr (filename, "tes");
308 if (NULL != (dotexe = strstr (filename, ".exe")))
309 dotexe[0] = '\0';
310
311 /* create cfg filename */
312 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
313 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
314 GNUNET_free (backup);
315
316 if ((strstr (argv[0], "tcp_nat") != NULL) || 294 if ((strstr (argv[0], "tcp_nat") != NULL) ||
317 (strstr (argv[0], "udp_nat") != NULL)) 295 (strstr (argv[0], "udp_nat") != NULL))
318 { 296 {
@@ -331,6 +309,10 @@ main (int argc, char *argv[])
331 } 309 }
332 310
333 } 311 }
312
313 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1);
314 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2);
315
334 ret = check (); 316 ret = check ();
335 317
336 GNUNET_free (cfg_file_p1); 318 GNUNET_free (cfg_file_p1);
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 8f48008a6..55db67877 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -436,10 +436,6 @@ main (int argc, char *argv[])
436 if (NULL != (dotexe = strstr (filename, ".exe"))) 436 if (NULL != (dotexe = strstr (filename, ".exe")))
437 dotexe[0] = '\0'; 437 dotexe[0] = '\0';
438 438
439 /* create cfg filename */
440 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
441 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
442
443 split = strstr (src_name, "."); 439 split = strstr (src_name, ".");
444 if (split != NULL) 440 if (split != NULL)
445 { 441 {
@@ -469,10 +465,15 @@ main (int argc, char *argv[])
469 return 0; 465 return 0;
470 } 466 }
471 } 467 }
468
469 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1);
470 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2);
471
472 ret = check (); 472 ret = check ();
473 473
474 GNUNET_free (cfg_file_p1); 474 GNUNET_free (cfg_file_p1);
475 GNUNET_free (cfg_file_p2); 475 GNUNET_free (cfg_file_p2);
476
476 GNUNET_free_non_null (test_name); 477 GNUNET_free_non_null (test_name);
477 478
478 return ret; 479 return ret;
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index 020d8614e..6f6f481fc 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -499,10 +499,6 @@ main (int argc, char *argv[])
499 if (NULL != (dotexe = strstr (filename, ".exe"))) 499 if (NULL != (dotexe = strstr (filename, ".exe")))
500 dotexe[0] = '\0'; 500 dotexe[0] = '\0';
501 501
502 /* create cfg filename */
503 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
504 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
505
506 split = strstr (src_name, "."); 502 split = strstr (src_name, ".");
507 if (split != NULL) 503 if (split != NULL)
508 { 504 {
@@ -532,10 +528,15 @@ main (int argc, char *argv[])
532 return 0; 528 return 0;
533 } 529 }
534 } 530 }
531
532 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1);
533 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2);
534
535 ret = check (); 535 ret = check ();
536 536
537 GNUNET_free (cfg_file_p1); 537 GNUNET_free (cfg_file_p1);
538 GNUNET_free (cfg_file_p2); 538 GNUNET_free (cfg_file_p2);
539
539 GNUNET_free_non_null (test_name); 540 GNUNET_free_non_null (test_name);
540 541
541 return ret; 542 return ret;
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 162024eb4..3ee471453 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -341,5 +341,45 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel
341 GNUNET_free (cc); 341 GNUNET_free (cc);
342} 342}
343 343
344/*
345 * Some utility functions
346 */
347
348/**
349 * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
350 * if existing ".exe"-prefix and adds the peer-number
351 * @param file filename of the test, e.g. argv[0]
352 * @param cfgname where to write the result
353 * @param count peer number
354 */
355void
356GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
357 int count)
358{
359 char *pch = strdup (file);
360 char *backup = pch;
361 char *filename = NULL;
362 char *dotexe;
363
364
365 /* get executable filename */
366 pch = strtok (pch, "/");
367 while (pch != NULL)
368 {
369 pch = strtok (NULL, "/");
370 if (pch != NULL)
371 filename = pch;
372 }
373 /* remove "lt-" */
374 filename = strstr (filename, "tes");
375 if (NULL != (dotexe = strstr (filename, ".exe")))
376 dotexe[0] = '\0';
377
378 /* create cfg filename */
379 GNUNET_asprintf (cfgname, "%s_peer%u.conf", filename, count);
380
381 GNUNET_free (backup);
382}
383
344 384
345/* end of transport_testing.h */ 385/* end of transport_testing.h */
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 3e5486eb7..7899279dc 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -118,4 +118,19 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
118void 118void
119GNUNET_TRANSPORT_TESTING_connect_peers_cancel (void *cc); 119GNUNET_TRANSPORT_TESTING_connect_peers_cancel (void *cc);
120 120
121/*
122 * Some utility functions
123 */
124
125/**
126 * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
127 * if existing ".exe"-prefix and adds the peer-number
128 * @param file filename of the test, e.g. argv[0]
129 * @param cfgname where to write the result
130 * @param count peer number
131 */
132void
133GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
134 int count);
135
121/* end of transport_testing.h */ 136/* end of transport_testing.h */