aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_testing_lib-new.h38
-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
4 files changed, 28 insertions, 152 deletions
diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h
index 7daa4ee7f..fc26eefa0 100644
--- a/src/include/gnunet_testing_lib-new.h
+++ b/src/include/gnunet_testing_lib-new.h
@@ -183,7 +183,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
183 * @param id identifier for the daemon, will be set 183 * @param id identifier for the daemon, will be set
184 */ 184 */
185void 185void
186GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 186GNUNET_TESTING_peer_get_identity (const struct GNUNET_TESTING_Peer *peer,
187 struct GNUNET_PeerIdentity *id); 187 struct GNUNET_PeerIdentity *id);
188 188
189 189
@@ -224,22 +224,11 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer);
224 * 224 *
225 * @param cls closure 225 * @param cls closure
226 * @param cfg configuration of the peer that was started 226 * @param cfg configuration of the peer that was started
227 */
228typedef void (*GNUNET_TESTING_TestMain)(void *cls,
229 const struct GNUNET_CONFIGURATION_Handle *cfg);
230
231
232/**
233 * Signature of the 'main' function for a (single-peer) testcase that
234 * is run using 'GNUNET_TESTING_system_run_restartable'.
235 *
236 * @param cls closure
237 * @param cfg configuration of the peer that was started
238 * @param peer identity of the peer that was created 227 * @param peer identity of the peer that was created
239 */ 228 */
240typedef void (*GNUNET_TESTING_RestartableTestMain)(void *cls, 229typedef void (*GNUNET_TESTING_TestMain)(void *cls,
241 const struct GNUNET_CONFIGURATION_Handle *cfg, 230 const struct GNUNET_CONFIGURATION_Handle *cfg,
242 const struct GNUNET_TESTING_Peer *peer); 231 struct GNUNET_TESTING_Peer *peer);
243 232
244 233
245/** 234/**
@@ -295,25 +284,6 @@ GNUNET_TESTING_service_run (const char *testdir,
295 284
296 285
297/** 286/**
298 * See GNUNET_TESTING_service_run.
299 * The only difference is that we handle the GNUNET_TESTING_Peer to
300 * the RestartableTestMain, so that the peer can be destroyed and re-created
301 * to simulate failure in tests.
302 *
303 * FIXME: change 'GNUNET_TESTING_TestMain' to have the 'restartable' signature
304 * and remove this extra function (in some sense, make this the primary one,
305 * but keep the old name).
306 */
307int
308GNUNET_TESTING_service_run_restartable (const char *testdir,
309 const char *service_name,
310 const char *cfgfilename,
311 GNUNET_TESTING_RestartableTestMain tm,
312 void *tm_cls);
313
314
315
316/**
317 * Sometimes we use the binary name to determine which specific 287 * Sometimes we use the binary name to determine which specific
318 * test to run. In those cases, the string after the last "_" 288 * test to run. In those cases, the string after the last "_"
319 * in 'argv[0]' specifies a string that determines the configuration 289 * in 'argv[0]' specifies a string that determines the configuration
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);