aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-06-20 14:43:29 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-06-20 14:43:29 +0000
commita2cd9dd7848a038d7006c4766ced886c9538c956 (patch)
treea5fd16d25f2e84e2539b9c50876be0bd8a5c8335 /src/testing
parent7a35bd8a7522bb9166430d9967382cc1082d23ac (diff)
downloadgnunet-a2cd9dd7848a038d7006c4766ced886c9538c956.tar.gz
gnunet-a2cd9dd7848a038d7006c4766ced886c9538c956.zip
-fixing #2442
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-testing-run-service.c8
-rw-r--r--src/testing/test_testing_servicestartup.c3
-rw-r--r--src/testing/testing.c131
3 files changed, 24 insertions, 118 deletions
diff --git a/src/testing/gnunet-testing-run-service.c b/src/testing/gnunet-testing-run-service.c
index 72415e606..cbd4763c5 100644
--- a/src/testing/gnunet-testing-run-service.c
+++ b/src/testing/gnunet-testing-run-service.c
@@ -143,9 +143,9 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
143 */ 143 */
144static void 144static void
145testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 145testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
146 const struct GNUNET_TESTING_Peer *peer) 146 struct GNUNET_TESTING_Peer *peer)
147{ 147{
148 my_peer = (struct GNUNET_TESTING_Peer *) peer; 148 my_peer = peer;
149 if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing"))) 149 if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing")))
150 { 150 {
151 GNUNET_break (0); 151 GNUNET_break (0);
@@ -193,8 +193,8 @@ main (int argc, char *const *argv)
193 if (GNUNET_SYSERR == 193 if (GNUNET_SYSERR ==
194 GNUNET_GETOPT_run("gnunet-testing-run-service", options, argc, argv)) 194 GNUNET_GETOPT_run("gnunet-testing-run-service", options, argc, argv))
195 return 1; 195 return 1;
196 ret = GNUNET_TESTING_service_run_restartable ("gnunet_service_test", srv_name, 196 ret = GNUNET_TESTING_service_run ("gnunet_service_test", srv_name,
197 cfg_name, &testing_main, NULL); 197 cfg_name, &testing_main, NULL);
198 if (0 != ret) 198 if (0 != ret)
199 { 199 {
200 printf ("error\n"); 200 printf ("error\n");
diff --git a/src/testing/test_testing_servicestartup.c b/src/testing/test_testing_servicestartup.c
index 236e84789..0a69892b6 100644
--- a/src/testing/test_testing_servicestartup.c
+++ b/src/testing/test_testing_servicestartup.c
@@ -45,7 +45,8 @@ static int test_success;
45 * @param cfg the configuration with which the current testing service is run 45 * @param cfg the configuration with which the current testing service is run
46 */ 46 */
47static void 47static void
48test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 48test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
49 struct GNUNET_TESTING_Peer *peer)
49{ 50{
50 GNUNET_assert (NULL == cls); 51 GNUNET_assert (NULL == cls);
51 GNUNET_assert (NULL != cfg); 52 GNUNET_assert (NULL != cfg);
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 3e6cbbb0e..6d22c68ce 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -132,6 +132,10 @@ struct GNUNET_TESTING_System
132 */ 132 */
133struct GNUNET_TESTING_Peer 133struct GNUNET_TESTING_Peer
134{ 134{
135 /**
136 * The TESTING system associated with this peer
137 */
138 struct GNUNET_TESTING_System *system;
135 139
136 /** 140 /**
137 * Path to the configuration file for this peer. 141 * Path to the configuration file for this peer.
@@ -151,6 +155,11 @@ struct GNUNET_TESTING_Peer
151 * peer/service is currently not running. 155 * peer/service is currently not running.
152 */ 156 */
153 struct GNUNET_OS_Process *main_process; 157 struct GNUNET_OS_Process *main_process;
158
159 /**
160 * The keynumber of this peer's hostkey
161 */
162 uint32_t key_number;
154}; 163};
155 164
156 165
@@ -795,6 +804,8 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
795 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); 804 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
796 peer->cfgfile = config_filename; /* Free in peer_destroy */ 805 peer->cfgfile = config_filename; /* Free in peer_destroy */
797 peer->main_binary = GNUNET_strdup ("gnunet-service-arm"); 806 peer->main_binary = GNUNET_strdup ("gnunet-service-arm");
807 peer->system = system;
808 peer->key_number = key_number;
798 return peer; 809 return peer;
799} 810}
800 811
@@ -806,11 +817,12 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
806 * @param id identifier for the daemon, will be set 817 * @param id identifier for the daemon, will be set
807 */ 818 */
808void 819void
809GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 820GNUNET_TESTING_peer_get_identity (const struct GNUNET_TESTING_Peer *peer,
810 struct GNUNET_PeerIdentity *id) 821 struct GNUNET_PeerIdentity *id)
811{ 822{
812 GNUNET_assert (0); // FIXME-SREE. 823 GNUNET_CRYPTO_rsa_key_free (GNUNET_TESTING_hostkey_get (peer->system,
813 // *id = peer->id; 824 peer->key_number,
825 id));
814} 826}
815 827
816 828
@@ -931,33 +943,11 @@ struct ServiceContext
931 * Callback to signal service startup 943 * Callback to signal service startup
932 */ 944 */
933 GNUNET_TESTING_TestMain tm; 945 GNUNET_TESTING_TestMain tm;
934 946
935 /**
936 * Closure for the above callback
937 */
938 void *tm_cls;
939};
940
941
942/**
943 * Structure for holding service data
944 */
945struct RestartableServiceContext
946{
947 /**
948 * The configuration of the peer in which the service is run
949 */
950 const struct GNUNET_CONFIGURATION_Handle *cfg;
951
952 /**
953 * Callback to signal service startup
954 */
955 GNUNET_TESTING_RestartableTestMain tm;
956
957 /** 947 /**
958 * The peer in which the service is run. 948 * The peer in which the service is run.
959 */ 949 */
960 const struct GNUNET_TESTING_Peer *peer; 950 struct GNUNET_TESTING_Peer *peer;
961 951
962 /** 952 /**
963 * Closure for the above callback 953 * Closure for the above callback
@@ -978,22 +968,6 @@ service_run_main (void *cls,
978{ 968{
979 struct ServiceContext *sc = cls; 969 struct ServiceContext *sc = cls;
980 970
981 sc->tm (sc->tm_cls, sc->cfg);
982}
983
984
985/**
986 * Callback to be called when SCHEDULER has been started
987 *
988 * @param cls the ServiceContext
989 * @param tc the TaskContext
990 */
991static void
992service_run_restartable_main (void *cls,
993 const struct GNUNET_SCHEDULER_TaskContext *tc)
994{
995 struct RestartableServiceContext *sc = cls;
996
997 sc->tm (sc->tm_cls, sc->cfg, sc->peer); 971 sc->tm (sc->tm_cls, sc->cfg, sc->peer);
998} 972}
999 973
@@ -1066,77 +1040,8 @@ GNUNET_TESTING_service_run (const char *testdir,
1066 sc.cfg = cfg; 1040 sc.cfg = cfg;
1067 sc.tm = tm; 1041 sc.tm = tm;
1068 sc.tm_cls = tm_cls; 1042 sc.tm_cls = tm_cls;
1069 GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1070 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer))
1071 {
1072 GNUNET_TESTING_peer_destroy (peer);
1073 GNUNET_CONFIGURATION_destroy (cfg);
1074 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1075 return 1;
1076 }
1077 GNUNET_TESTING_peer_destroy (peer);
1078 GNUNET_CONFIGURATION_destroy (cfg);
1079 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1080 return 0;
1081}
1082
1083
1084
1085/**
1086 * See GNUNET_TESTING_service_run.
1087 * The only difference is that we handle the GNUNET_TESTING_Peer to
1088 * the RestartableTestMain, so that the peer can be destroyed and re-created
1089 * to simulate failure in tests.
1090 */
1091int
1092GNUNET_TESTING_service_run_restartable (const char *testdir,
1093 const char *service_name,
1094 const char *cfgfilename,
1095 GNUNET_TESTING_RestartableTestMain tm,
1096 void *tm_cls)
1097{
1098 struct RestartableServiceContext sc;
1099 struct GNUNET_TESTING_System *system;
1100 struct GNUNET_TESTING_Peer *peer;
1101 struct GNUNET_CONFIGURATION_Handle *cfg;
1102
1103 GNUNET_log_setup (testdir,
1104 "WARNING",
1105 NULL);
1106 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1");
1107 if (NULL == system)
1108 return 1;
1109 cfg = GNUNET_CONFIGURATION_create ();
1110 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1111 {
1112 LOG (GNUNET_ERROR_TYPE_ERROR,
1113 _("Failed to load configuration from %s\n"), cfgfilename);
1114 GNUNET_CONFIGURATION_destroy (cfg);
1115 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1116 return 1;
1117 }
1118 peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1119 if (NULL == peer)
1120 {
1121 GNUNET_CONFIGURATION_destroy (cfg);
1122 hostkeys_unload (system);
1123 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1124 return 1;
1125 }
1126 GNUNET_free (peer->main_binary);
1127 GNUNET_asprintf (&peer->main_binary, "gnunet-service-%s", service_name);
1128 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
1129 {
1130 GNUNET_TESTING_peer_destroy (peer);
1131 GNUNET_CONFIGURATION_destroy (cfg);
1132 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1133 return 1;
1134 }
1135 sc.cfg = cfg;
1136 sc.tm = tm;
1137 sc.tm_cls = tm_cls;
1138 sc.peer = peer; 1043 sc.peer = peer;
1139 GNUNET_SCHEDULER_run (&service_run_restartable_main, &sc); /* Scheduler loop */ 1044 GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1140 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer)) 1045 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer))
1141 { 1046 {
1142 GNUNET_TESTING_peer_destroy (peer); 1047 GNUNET_TESTING_peer_destroy (peer);