diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-15 11:18:29 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-15 11:18:29 +0000 |
commit | 43591012109e35be84cc4dad5fb91d08b50fc853 (patch) | |
tree | 24d4bf1aa9a5c2f4b4e7903b91bb4761cde4f0ad | |
parent | 8b36455553e8e426d8771c78fe52211743607340 (diff) | |
download | gnunet-43591012109e35be84cc4dad5fb91d08b50fc853.tar.gz gnunet-43591012109e35be84cc4dad5fb91d08b50fc853.zip |
-use testing lib
-rw-r--r-- | src/vpn/Makefile.am | 8 | ||||
-rw-r--r-- | src/vpn/test_gnunet_vpn.c | 77 |
2 files changed, 10 insertions, 75 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 2af34f8e1..0f252990e 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -85,26 +85,26 @@ test_gnunet_vpn_4_over_SOURCES = \ | |||
85 | test_gnunet_vpn.c | 85 | test_gnunet_vpn.c |
86 | test_gnunet_vpn_4_over_LDADD = -lmicrohttpd @LIBCURL@ \ | 86 | test_gnunet_vpn_4_over_LDADD = -lmicrohttpd @LIBCURL@ \ |
87 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | 87 | $(top_builddir)/src/vpn/libgnunetvpn.la \ |
88 | $(top_builddir)/src/arm/libgnunetarm.la \ | 88 | $(top_builddir)/src/testing/libgnunettesting.la \ |
89 | $(top_builddir)/src/util/libgnunetutil.la | 89 | $(top_builddir)/src/util/libgnunetutil.la |
90 | 90 | ||
91 | test_gnunet_vpn_6_over_SOURCES = \ | 91 | test_gnunet_vpn_6_over_SOURCES = \ |
92 | test_gnunet_vpn.c | 92 | test_gnunet_vpn.c |
93 | test_gnunet_vpn_6_over_LDADD = -lmicrohttpd @LIBCURL@ \ | 93 | test_gnunet_vpn_6_over_LDADD = -lmicrohttpd @LIBCURL@ \ |
94 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | 94 | $(top_builddir)/src/vpn/libgnunetvpn.la \ |
95 | $(top_builddir)/src/arm/libgnunetarm.la \ | 95 | $(top_builddir)/src/testing/libgnunettesting.la \ |
96 | $(top_builddir)/src/util/libgnunetutil.la | 96 | $(top_builddir)/src/util/libgnunetutil.la |
97 | 97 | ||
98 | test_gnunet_vpn_4_to_6_SOURCES = \ | 98 | test_gnunet_vpn_4_to_6_SOURCES = \ |
99 | test_gnunet_vpn.c | 99 | test_gnunet_vpn.c |
100 | test_gnunet_vpn_4_to_6_LDADD = -lmicrohttpd @LIBCURL@ \ | 100 | test_gnunet_vpn_4_to_6_LDADD = -lmicrohttpd @LIBCURL@ \ |
101 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | 101 | $(top_builddir)/src/vpn/libgnunetvpn.la \ |
102 | $(top_builddir)/src/arm/libgnunetarm.la \ | 102 | $(top_builddir)/src/testing/libgnunettesting.la \ |
103 | $(top_builddir)/src/util/libgnunetutil.la | 103 | $(top_builddir)/src/util/libgnunetutil.la |
104 | 104 | ||
105 | test_gnunet_vpn_6_to_4_SOURCES = \ | 105 | test_gnunet_vpn_6_to_4_SOURCES = \ |
106 | test_gnunet_vpn.c | 106 | test_gnunet_vpn.c |
107 | test_gnunet_vpn_6_to_4_LDADD = -lmicrohttpd @LIBCURL@ \ | 107 | test_gnunet_vpn_6_to_4_LDADD = -lmicrohttpd @LIBCURL@ \ |
108 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | 108 | $(top_builddir)/src/vpn/libgnunetvpn.la \ |
109 | $(top_builddir)/src/arm/libgnunetarm.la \ | 109 | $(top_builddir)/src/testing/libgnunettesting.la \ |
110 | $(top_builddir)/src/util/libgnunetutil.la | 110 | $(top_builddir)/src/util/libgnunetutil.la |
diff --git a/src/vpn/test_gnunet_vpn.c b/src/vpn/test_gnunet_vpn.c index 4c941bd92..78bea39a7 100644 --- a/src/vpn/test_gnunet_vpn.c +++ b/src/vpn/test_gnunet_vpn.c | |||
@@ -27,26 +27,12 @@ | |||
27 | #include <curl/curl.h> | 27 | #include <curl/curl.h> |
28 | #include <microhttpd.h> | 28 | #include <microhttpd.h> |
29 | #include "gnunet_vpn_service.h" | 29 | #include "gnunet_vpn_service.h" |
30 | #include "gnunet_arm_service.h" | 30 | #include "gnunet_testing_lib-new.h" |
31 | 31 | ||
32 | #define PORT 48080 | 32 | #define PORT 48080 |
33 | 33 | ||
34 | #define START_ARM GNUNET_YES | ||
35 | |||
36 | #define VERBOSE GNUNET_NO | ||
37 | |||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
39 | 35 | ||
40 | struct PeerContext | ||
41 | { | ||
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
43 | struct GNUNET_PeerIdentity id; | ||
44 | #if START_ARM | ||
45 | struct GNUNET_OS_Process *arm_proc; | ||
46 | #endif | ||
47 | }; | ||
48 | |||
49 | static struct PeerContext p1; | ||
50 | 36 | ||
51 | /** | 37 | /** |
52 | * Return value for 'main'. | 38 | * Return value for 'main'. |
@@ -96,7 +82,6 @@ struct CBC | |||
96 | static struct CBC cbc; | 82 | static struct CBC cbc; |
97 | 83 | ||
98 | 84 | ||
99 | |||
100 | static size_t | 85 | static size_t |
101 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 86 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) |
102 | { | 87 | { |
@@ -388,7 +373,7 @@ mhd_main () | |||
388 | 373 | ||
389 | 374 | ||
390 | static void | 375 | static void |
391 | run (void *cls, char *const *args, const char *cfgfile, | 376 | run (void *cls, |
392 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 377 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
393 | { | 378 | { |
394 | struct in_addr v4; | 379 | struct in_addr v4; |
@@ -435,41 +420,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
435 | } | 420 | } |
436 | 421 | ||
437 | 422 | ||
438 | static void | ||
439 | setup_peer (struct PeerContext *p, const char *cfgname) | ||
440 | { | ||
441 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
442 | #if START_ARM | ||
443 | p->arm_proc = | ||
444 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
445 | "gnunet-service-arm", | ||
446 | "-c", cfgname, NULL); | ||
447 | #endif | ||
448 | GNUNET_assert (NULL != p->arm_proc); | ||
449 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
450 | } | ||
451 | |||
452 | |||
453 | static void | ||
454 | stop_peer (struct PeerContext *p) | ||
455 | { | ||
456 | #if START_ARM | ||
457 | if (NULL != p->arm_proc) | ||
458 | { | ||
459 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
460 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
461 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | ||
462 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | ||
464 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
465 | GNUNET_OS_process_destroy (p->arm_proc); | ||
466 | p->arm_proc = NULL; | ||
467 | } | ||
468 | #endif | ||
469 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
470 | } | ||
471 | |||
472 | |||
473 | /** | 423 | /** |
474 | * Test if the given AF is supported by this system. | 424 | * Test if the given AF is supported by this system. |
475 | * | 425 | * |
@@ -494,21 +444,11 @@ test_af (int af) | |||
494 | } | 444 | } |
495 | 445 | ||
496 | 446 | ||
497 | |||
498 | int | 447 | int |
499 | main (int argc, char *const *argv) | 448 | main (int argc, char *const *argv) |
500 | { | 449 | { |
501 | const char *type; | 450 | const char *type; |
502 | const char *bin; | 451 | const char *bin; |
503 | char *const argvx[] = { | ||
504 | "test_gnunet_vpn", | ||
505 | "-c", | ||
506 | "test_gnunet_vpn.conf", | ||
507 | NULL | ||
508 | }; | ||
509 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
510 | GNUNET_GETOPT_OPTION_END | ||
511 | }; | ||
512 | 452 | ||
513 | if (0 != ACCESS ("/dev/net/tun", R_OK)) | 453 | if (0 != ACCESS ("/dev/net/tun", R_OK)) |
514 | { | 454 | { |
@@ -577,20 +517,15 @@ main (int argc, char *const *argv) | |||
577 | "Required address families not supported by this system, skipping test.\n"); | 517 | "Required address families not supported by this system, skipping test.\n"); |
578 | return 0; | 518 | return 0; |
579 | } | 519 | } |
580 | |||
581 | |||
582 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 520 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
583 | { | 521 | { |
584 | fprintf (stderr, "failed to initialize curl\n"); | 522 | fprintf (stderr, "failed to initialize curl\n"); |
585 | return 2; | 523 | return 2; |
586 | } | 524 | } |
587 | setup_peer (&p1, "test_gnunet_vpn.conf"); | 525 | if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn", |
588 | GNUNET_log_setup ("test_gnunet_vpn", | 526 | "test_gnunet_vpn.conf", |
589 | "WARNING", | 527 | &run, NULL)) |
590 | NULL); | 528 | return 1; |
591 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
592 | "test_gnunet_vpn", "nohelp", options, &run, NULL); | ||
593 | stop_peer (&p1); | ||
594 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); | 529 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); |
595 | return global_ret; | 530 | return global_ret; |
596 | } | 531 | } |