aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-30 12:56:48 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-30 12:56:48 +0000
commitfd65db578913be3c6612fb8777a179d98af48991 (patch)
treedf6603dfc803941eae5da1d2605e8d11d5d580c4
parente22f71507f3ea87ca5d86fd279e80833195b3227 (diff)
downloadgnunet-fd65db578913be3c6612fb8777a179d98af48991.tar.gz
gnunet-fd65db578913be3c6612fb8777a179d98af48991.zip
-minor cleanups in testing
-rw-r--r--src/include/platform.h8
-rw-r--r--src/testing/testing_group.c9
-rw-r--r--src/testing/testing_new.c137
3 files changed, 102 insertions, 52 deletions
diff --git a/src/include/platform.h b/src/include/platform.h
index 7383e48ad..9a5d1646d 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -241,6 +241,14 @@ atoll (const char *nptr);
241#define O_LARGEFILE 0 241#define O_LARGEFILE 0
242#endif 242#endif
243 243
244/**
245 * AI_NUMERICSERV not defined in windows. Then we just do without.
246 */
247#ifndef AI_NUMERICSERV
248#define AI_NUMERICSERV 0
249#endif
250
251
244#if defined(__sparc__) 252#if defined(__sparc__)
245#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; }) 253#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
246#else 254#else
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 245ebd3d9..75c0e617d 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -1504,9 +1504,7 @@ GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32
1504 ""); 1504 "");
1505 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", ""); 1505 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", "");
1506 1506
1507 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", 1507 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat",
1508 "USE_LOCALADDR", "YES");
1509 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
1510 "USE_LOCALADDR", "YES"); 1508 "USE_LOCALADDR", "YES");
1511 GNUNET_free_non_null (control_host); 1509 GNUNET_free_non_null (control_host);
1512 GNUNET_free (allowed_hosts); 1510 GNUNET_free (allowed_hosts);
@@ -1534,10 +1532,7 @@ GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32
1534 } 1532 }
1535 else 1533 else
1536 { 1534 {
1537 1535 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat",
1538 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
1539 "USE_LOCALADDR", "YES");
1540 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
1541 "USE_LOCALADDR", "YES"); 1536 "USE_LOCALADDR", "YES");
1542 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", 1537 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO",
1543 "127.0.0.1"); 1538 "127.0.0.1");
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
index 4f9494bea..2828e0f16 100644
--- a/src/testing/testing_new.c
+++ b/src/testing/testing_new.c
@@ -39,19 +39,12 @@
39#define TIME_REL_SEC(sec) \ 39#define TIME_REL_SEC(sec) \
40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) 40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
41 41
42/**
43 * AI_NUMERICSERV not defined in windows. A hack to keep on going.
44 */
45#if !defined (AI_NUMERICSERV)
46#define AI_NUMERICSERV 0
47#endif
48 42
49/** 43/**
50 * Size of a hostkey when written to a file 44 * Size of a hostkey when written to a file
51 */ 45 */
52#ifndef HOSTKEYFILESIZE
53#define HOSTKEYFILESIZE 914 46#define HOSTKEYFILESIZE 914
54#endif 47
55 48
56/** 49/**
57 * Handle for a system on which GNUnet peers are executed; 50 * Handle for a system on which GNUnet peers are executed;
@@ -71,7 +64,7 @@ struct GNUNET_TESTING_System
71 char *controller; 64 char *controller;
72 65
73 /** 66 /**
74 * Hostkeys data 67 * Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes.
75 */ 68 */
76 char *hostkeys_data; 69 char *hostkeys_data;
77 70
@@ -195,7 +188,6 @@ void
195GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 188GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
196 int remove_paths) 189 int remove_paths)
197{ 190{
198 GNUNET_assert (NULL != system);
199 if (NULL != system->hostkeys_data) 191 if (NULL != system->hostkeys_data)
200 { 192 {
201 GNUNET_break (0); /* Use GNUNET_TESTING_hostkeys_unload() */ 193 GNUNET_break (0); /* Use GNUNET_TESTING_hostkeys_unload() */
@@ -299,7 +291,6 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
299 uint16_t bucket; 291 uint16_t bucket;
300 uint16_t pos; 292 uint16_t pos;
301 293
302 GNUNET_assert (NULL != system);
303 port_buckets = (GNUNET_YES == is_tcp) ? 294 port_buckets = (GNUNET_YES == is_tcp) ?
304 system->reserved_tcp_ports : system->reserved_udp_ports; 295 system->reserved_tcp_ports : system->reserved_udp_ports;
305 bucket = port / 32; 296 bucket = port / 32;
@@ -431,8 +422,8 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
431 return GNUNET_SYSERR; 422 return GNUNET_SYSERR;
432 if (key_number >= system->total_hostkeys) 423 if (key_number >= system->total_hostkeys)
433 { 424 {
434 LOG (GNUNET_ERROR_TYPE_DEBUG, 425 LOG (GNUNET_ERROR_TYPE_ERROR,
435 "Key number %u doesn't exist\n", key_number); 426 _("Key number %u does not exist\n"), key_number);
436 return GNUNET_SYSERR; 427 return GNUNET_SYSERR;
437 } 428 }
438 private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data + 429 private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data +
@@ -440,8 +431,8 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
440 HOSTKEYFILESIZE); 431 HOSTKEYFILESIZE);
441 if (NULL == private_key) 432 if (NULL == private_key)
442 { 433 {
443 LOG (GNUNET_ERROR_TYPE_DEBUG, 434 LOG (GNUNET_ERROR_TYPE_ERROR,
444 "Error while decoding key %u\n", key_number); 435 _("Error while decoding key %u\n"), key_number);
445 return GNUNET_SYSERR; 436 return GNUNET_SYSERR;
446 } 437 }
447 GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key); 438 GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key);
@@ -626,9 +617,14 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
626 system->path_counter++); 617 system->path_counter++);
627 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "SERVICEHOME", 618 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "SERVICEHOME",
628 uc.service_home); 619 uc.service_home);
620 /* make PORTs and UNIXPATHs unique */
629 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); 621 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
622 /* allow connections to services from system controller host */
630 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); 623 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
631 /* FIXME: add other options which enable communication with controller */ 624 /* enable loopback-based connections between peers */
625 GNUNET_CONFIGURATION_set_value_string (cfg,
626 "nat",
627 "USE_LOCALADDR", "YES");
632 GNUNET_free (uc.service_home); 628 GNUNET_free (uc.service_home);
633 return uc.status; 629 return uc.status;
634} 630}
@@ -658,17 +654,34 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
658 char *service_home; 654 char *service_home;
659 char hostkey_filename[128]; 655 char hostkey_filename[128];
660 char *config_filename; 656 char *config_filename;
661 size_t bytes_written;
662 size_t n;
663
664 657
665 if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg)) 658 if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg))
659 {
660 GNUNET_asprintf (emsg,
661 _("Failed to create configuration for peer (not enough free ports?)\n"));
662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
663 "%s", *emsg);
666 return NULL; 664 return NULL;
665 }
667 if (key_number >= system->total_hostkeys) 666 if (key_number >= system->total_hostkeys)
667 {
668 GNUNET_asprintf (emsg,
669 _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
670 (unsigned int) system->total_hostkeys);
671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
672 "%s", *emsg);
668 return NULL; 673 return NULL;
674 }
669 if ((NULL != id) && 675 if ((NULL != id) &&
670 (GNUNET_SYSERR == GNUNET_TESTING_hostkey_get (system, key_number, id))) 676 (GNUNET_SYSERR == GNUNET_TESTING_hostkey_get (system, key_number, id)))
677 {
678 GNUNET_asprintf (emsg,
679 _("Failed to initialize hostkey for peer %u\n"),
680 (unsigned int) key_number);
681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
682 "%s", *emsg);
671 return NULL; 683 return NULL;
684 }
672 GNUNET_assert (GNUNET_OK == 685 GNUNET_assert (GNUNET_OK ==
673 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", 686 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
674 "SERVICE_HOME", 687 "SERVICE_HOME",
@@ -681,27 +694,36 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
681 | GNUNET_DISK_PERM_USER_WRITE); 694 | GNUNET_DISK_PERM_USER_WRITE);
682 if (NULL == fd) 695 if (NULL == fd)
683 { 696 {
684 GNUNET_break (0); return NULL; 697 GNUNET_break (0);
698 return NULL;
685 } 699 }
686 bytes_written = 0; 700 if (HOSTKEYFILESIZE !=
687 do 701 GNUNET_DISK_file_write (fd, system->hostkeys_data
702 + (key_number * HOSTKEYFILESIZE),
703 HOSTKEYFILESIZE))
688 { 704 {
689 n = GNUNET_DISK_file_write (fd, system->hostkeys_data 705 GNUNET_asprintf (emsg,
690 + (key_number * HOSTKEYFILESIZE), 706 _("Failed to write hostkey file for peer %u: %s\n"),
691 HOSTKEYFILESIZE - bytes_written); 707 (unsigned int) key_number,
692 GNUNET_assert (GNUNET_SYSERR != n); 708 STRERROR (errno));
693 bytes_written += n; 709 GNUNET_DISK_file_close (fd);
710 return NULL;
694 } 711 }
695 while (bytes_written < HOSTKEYFILESIZE);
696 GNUNET_DISK_file_close (fd); 712 GNUNET_DISK_file_close (fd);
697 fd = NULL;
698 GNUNET_asprintf (&config_filename, "%s\\config", service_home); 713 GNUNET_asprintf (&config_filename, "%s\\config", service_home);
699 GNUNET_free (service_home); 714 GNUNET_free (service_home);
700 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename)) 715 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
701 return NULL; 716 {
717 GNUNET_asprintf (emsg,
718 _("Failed to write configuration file `%s' for peer %u: %s\n"),
719 config_filename,
720 (unsigned int) key_number,
721 STRERROR (errno));
722 return NULL;
723 }
702 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); 724 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
703 peer->cfgfile = config_filename; /* Free in peer_destroy */ 725 peer->cfgfile = config_filename; /* Free in peer_destroy */
704 peer->main_binary = GNUNET_strdup ("gnunet-arm"); 726 peer->main_binary = GNUNET_strdup ("gnunet-service-arm");
705 return peer; 727 return peer;
706} 728}
707 729
@@ -716,13 +738,23 @@ int
716GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) 738GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
717{ 739{
718 if (NULL != peer->main_process) 740 if (NULL != peer->main_process)
741 {
742 GNUNET_break (0);
719 return GNUNET_SYSERR; 743 return GNUNET_SYSERR;
744 }
720 GNUNET_assert (NULL != peer->cfgfile); 745 GNUNET_assert (NULL != peer->cfgfile);
721 peer->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, 746 peer->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL,
722 peer->main_binary, "-c", 747 peer->main_binary, "-c",
723 peer->cfgfile, 748 peer->cfgfile,
724 "-s", "-q", NULL); 749 NULL);
725 GNUNET_assert (NULL != peer->main_process); 750 if (NULL == peer->main_process)
751 {
752 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
753 _("Failed to start `%s': %s\n"),
754 peer->main_binary,
755 STRERROR (errno));
756 return GNUNET_SYSERR;
757 }
726 return GNUNET_OK; 758 return GNUNET_OK;
727} 759}
728 760
@@ -737,8 +769,11 @@ int
737GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) 769GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
738{ 770{
739 if (NULL == peer->main_process) 771 if (NULL == peer->main_process)
772 {
773 GNUNET_break (0);
740 return GNUNET_SYSERR; 774 return GNUNET_SYSERR;
741 GNUNET_assert (0 == GNUNET_OS_process_kill (peer->main_process, SIGTERM)); 775 }
776 (void) GNUNET_OS_process_kill (peer->main_process, SIGTERM);
742 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (peer->main_process)); 777 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (peer->main_process));
743 GNUNET_OS_process_destroy (peer->main_process); 778 GNUNET_OS_process_destroy (peer->main_process);
744 peer->main_process = NULL; 779 peer->main_process = NULL;
@@ -758,9 +793,7 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
758{ 793{
759 if (NULL != peer->main_process) 794 if (NULL != peer->main_process)
760 { 795 {
761 LOG (GNUNET_ERROR_TYPE_WARNING, 796 GNUNET_break (0);
762 _("%s called when peer is still running. Use GNUNET_TESTING_peer_stop()\n"),
763 __func__);
764 GNUNET_TESTING_peer_stop (peer); 797 GNUNET_TESTING_peer_stop (peer);
765 } 798 }
766 GNUNET_free (peer->cfgfile); 799 GNUNET_free (peer->cfgfile);
@@ -769,7 +802,6 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
769} 802}
770 803
771 804
772
773/** 805/**
774 * Start a single peer and run a test using the testing library. 806 * Start a single peer and run a test using the testing library.
775 * Starts a peer using the given configuration and then invokes the 807 * Starts a peer using the given configuration and then invokes the
@@ -843,6 +875,20 @@ check_service_status (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
843} 875}
844 876
845 877
878static void
879service_run_main (void *cls,
880 const struct GNUNET_SCHEDULER_TaskContext *tc)
881{
882 struct ServiceContext *sc = cls;
883
884 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
885 &stop_service, sc);
886 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC(3), &check_service_status, sc);
887
888 // sc->tm (tm_cls);
889}
890
891
846/** 892/**
847 * Start a single service (no ARM, except of course if the given 893 * Start a single service (no ARM, except of course if the given
848 * service name is 'arm') and run a test using the testing library. 894 * service name is 'arm') and run a test using the testing library.
@@ -875,25 +921,26 @@ GNUNET_TESTING_service_run (const char *tmppath,
875 GNUNET_assert (NULL != service_name); 921 GNUNET_assert (NULL != service_name);
876 GNUNET_snprintf (uval, sizeof (uval), "gnunet-service-%s", service_name); 922 GNUNET_snprintf (uval, sizeof (uval), "gnunet-service-%s", service_name);
877 sc = GNUNET_malloc (sizeof (struct ServiceContext)); 923 sc = GNUNET_malloc (sizeof (struct ServiceContext));
924
925 // FIXME: GNUNET_TESTING_peer_start...
878 if (NULL == cfgfilename) 926 if (NULL == cfgfilename)
879 sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval); 927 sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval, NULL);
880 else 928 else
881 sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval, 929 sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval,
882 "-c", cfgfilename); 930 "-c", cfgfilename, NULL);
883 if (NULL == sc->main_process) 931 if (NULL == sc->main_process)
884 { 932 {
885 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to start process %s\n", service_name); 933 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start process %s\n", service_name);
886 GNUNET_free (sc); 934 GNUNET_free (sc);
887 return 1; 935 return 1;
888 } 936 }
889 sc->tm = tm; 937 sc->tm = tm;
890 sc->tm_cls = tm_cls; 938 sc->tm_cls = tm_cls;
891 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 939 GNUNET_SCHEDULER_run (&service_run_main, sc);
892 &stop_service, sc); 940 // FIXME: GNUNET_TESTING_peer_stop...
893 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC(3), &check_service_status, sc); 941 GNUNET_free (sc);
894 return 0; 942 return 0;
895} 943}
896 944
897 945
898
899/* end of testing_new.c */ 946/* end of testing_new.c */