aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-07-26 18:22:54 +0000
committerNathan S. Evans <evans@in.tum.de>2011-07-26 18:22:54 +0000
commit81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd (patch)
tree35b65462b9209af4bd610552bb485ad22487400e /src/testing
parentbf4a9d8364675b34ac18d505e508006e2b773670 (diff)
downloadgnunet-81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd.tar.gz
gnunet-81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd.zip
start service
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.c89
-rw-r--r--src/testing/testing_group.c129
2 files changed, 211 insertions, 7 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 79c67e89c..a079390ad 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -1043,12 +1043,12 @@ GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon)
1043 1043
1044 1044
1045/** 1045/**
1046 * Stops a GNUnet daemon. 1046 * Starts a GNUnet daemon service which has been previously stopped.
1047 * 1047 *
1048 * @param d the daemon for which the service should be started 1048 * @param d the daemon for which the service should be started
1049 * @param service the name of the service to start 1049 * @param service the name of the service to start
1050 * @param timeout how long to wait for process for shutdown to complete 1050 * @param timeout how long to wait for process for shutdown to complete
1051 * @param cb function called once the daemon was stopped 1051 * @param cb function called once the service starts
1052 * @param cb_cls closure for cb 1052 * @param cb_cls closure for cb
1053 */ 1053 */
1054void 1054void
@@ -1069,13 +1069,9 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
1069 d->phase = SP_START_DONE; 1069 d->phase = SP_START_DONE;
1070 } 1070 }
1071 1071
1072#if DEBUG_TESTING
1073 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1074 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1075#endif
1076 if (d->churned_services == NULL) 1072 if (d->churned_services == NULL)
1077 { 1073 {
1078 d->dead_cb(d->dead_cb_cls, "No service has been churned off yet!!"); 1074 d->cb(d->cb_cls, &d->id, d->cfg, d, "No service has been churned off yet!!");
1079 return; 1075 return;
1080 } 1076 }
1081 d->phase = SP_SERVICE_START; 1077 d->phase = SP_SERVICE_START;
@@ -1132,6 +1128,85 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
1132} 1128}
1133 1129
1134/** 1130/**
1131 * Starts a GNUnet daemon's service.
1132 *
1133 * @param d the daemon for which the service should be started
1134 * @param service the name of the service to start
1135 * @param timeout how long to wait for process for startup
1136 * @param cb function called once gnunet-arm returns
1137 * @param cb_cls closure for cb
1138 */
1139void
1140GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
1141 char *service,
1142 struct GNUNET_TIME_Relative timeout,
1143 GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls)
1144{
1145 char *arg;
1146 d->cb = cb;
1147 d->cb_cls = cb_cls;
1148
1149 GNUNET_assert(service != NULL);
1150 GNUNET_assert(d->running == GNUNET_YES);
1151 GNUNET_assert(d->phase == SP_START_DONE);
1152
1153#if DEBUG_TESTING
1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1155 _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s (&d->id));
1156#endif
1157
1158 d->phase = SP_SERVICE_START;
1159
1160 /* Check if this is a local or remote process */
1161 if (NULL != d->hostname)
1162 {
1163#if DEBUG_TESTING
1164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1165 "Starting gnunet-arm with config `%s' on host `%s'.\n",
1166 d->cfgfile, d->hostname);
1167#endif
1168
1169 if (d->username != NULL)
1170 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1171 else
1172 arg = GNUNET_strdup (d->hostname);
1173
1174 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1175#if !DEBUG_TESTING
1176 "-q",
1177#endif
1178 arg, "gnunet-arm",
1179#if DEBUG_TESTING
1180 "-L", "DEBUG",
1181#endif
1182 "-c", d->cfgfile, "-i", service, "-q",
1183 NULL);
1184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1185 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n",
1186 arg, "gnunet-arm", d->cfgfile, service);
1187 GNUNET_free (arg);
1188 }
1189 else
1190 {
1191#if DEBUG_TESTING
1192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1193 "Starting gnunet-arm with config `%s' locally.\n",
1194 d->cfgfile);
1195#endif
1196 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
1197 "gnunet-arm",
1198#if DEBUG_TESTING
1199 "-L", "DEBUG",
1200#endif
1201 "-c", d->cfgfile, "-i", service, "-q",
1202 NULL);
1203 }
1204
1205 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1206 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1207}
1208
1209/**
1135 * Start a peer that has previously been stopped using the daemon_stop 1210 * Start a peer that has previously been stopped using the daemon_stop
1136 * call (and files weren't deleted and the allow restart flag) 1211 * call (and files weren't deleted and the allow restart flag)
1137 * 1212 *
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 7986d1b5f..ba4b29150 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -279,6 +279,33 @@ struct PeerRestartContext
279 struct GNUNET_TESTING_Daemon *daemon; 279 struct GNUNET_TESTING_Daemon *daemon;
280}; 280};
281 281
282struct ServiceStartContext
283{
284 struct GNUNET_TESTING_PeerGroup *pg;
285 unsigned int remaining;
286 GNUNET_TESTING_NotifyCompletion cb;
287 unsigned int outstanding;
288 char *service;
289 struct GNUNET_TIME_Relative timeout;
290 void *cb_cls;
291};
292
293/**
294 * Individual shutdown context for a particular peer.
295 */
296struct PeerServiceStartContext
297{
298 /**
299 * Pointer to the high level start context.
300 */
301 struct ServiceStartContext *start_ctx;
302
303 /**
304 * The daemon handle for the peer to start the service on.
305 */
306 struct GNUNET_TESTING_Daemon *daemon;
307};
308
282struct CreateTopologyContext 309struct CreateTopologyContext
283{ 310{
284 311
@@ -5605,6 +5632,66 @@ schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5605 } 5632 }
5606} 5633}
5607 5634
5635/**
5636 * Callback for informing us about a successful
5637 * or unsuccessful churn start call.
5638 *
5639 * @param cls a struct ServiceStartContext *startup_ctx
5640 * @param id the peer identity of the started peer
5641 * @param cfg the handle to the configuration of the peer
5642 * @param d handle to the daemon for the peer
5643 * @param emsg NULL on success, non-NULL on failure
5644 *
5645 */
5646void
5647service_start_callback(void *cls,
5648 const struct GNUNET_PeerIdentity *id,
5649 const struct GNUNET_CONFIGURATION_Handle *cfg,
5650 struct GNUNET_TESTING_Daemon *d,
5651 const char *emsg)
5652{
5653 struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *)cls;
5654
5655 if (emsg != NULL)
5656 {
5657 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5658 "Service start failed with error `%s'\n", emsg);
5659 }
5660
5661 startup_ctx->outstanding--;
5662 startup_ctx->remaining--;
5663
5664 if (startup_ctx->remaining == 0)
5665 {
5666 startup_ctx->cb (startup_ctx->cb_cls, NULL);
5667 GNUNET_free (startup_ctx->service);
5668 GNUNET_free (startup_ctx);
5669 }
5670}
5671
5672static void
5673schedule_service_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5674{
5675 struct PeerServiceStartContext *peer_ctx = cls;
5676 struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx;
5677
5678 if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh)
5679 GNUNET_SCHEDULER_add_delayed (
5680 GNUNET_TIME_relative_multiply (
5681 GNUNET_TIME_UNIT_MILLISECONDS,
5682 100),
5683 &schedule_service_start, peer_ctx);
5684 else
5685 {
5686
5687 GNUNET_TESTING_daemon_start_service (peer_ctx->daemon,
5688 startup_ctx->service,
5689 startup_ctx->timeout,
5690 &service_start_callback, startup_ctx);
5691 GNUNET_free (peer_ctx);
5692 }
5693}
5694
5608 5695
5609static void 5696static void
5610internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 5697internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -6635,6 +6722,48 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg,
6635 GNUNET_free_non_null (stopped_permute); 6722 GNUNET_free_non_null (stopped_permute);
6636} 6723}
6637 6724
6725/*
6726 * Start a given service for each of the peers in the peer group.
6727 *
6728 * @param pg handle for the peer group
6729 * @param service the service to start
6730 * @param timeout how long to wait for operations to finish before
6731 * giving up
6732 * @param cb function to call once finished
6733 * @param cb_cls closure for cb
6734 *
6735 */
6736void
6737GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg,
6738 char *service,
6739 struct GNUNET_TIME_Relative timeout,
6740 GNUNET_TESTING_NotifyCompletion cb,
6741 void *cb_cls)
6742{
6743 struct ServiceStartContext *start_ctx;
6744 struct PeerServiceStartContext *peer_start_ctx;
6745 unsigned int i;
6746
6747 GNUNET_assert(service != NULL);
6748
6749 start_ctx = GNUNET_malloc(sizeof(struct ServiceStartContext));
6750 start_ctx->pg = pg;
6751 start_ctx->remaining = pg->total;
6752 start_ctx->cb = cb;
6753 start_ctx->cb_cls = cb_cls;
6754 start_ctx->service = GNUNET_strdup(service);
6755
6756 for (i = 0; i < pg->total; i++)
6757 {
6758#if DEBUG_START
6759 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up service %s on peer %d!\n", service, stopped_arr[stopped_permute[i]]);
6760#endif
6761 peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext));
6762 peer_start_ctx->start_ctx = start_ctx;
6763 peer_start_ctx->daemon = pg->peers[i].daemon;
6764 GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx);
6765 }
6766}
6638 6767
6639/** 6768/**
6640 * Restart all peers in the given group. 6769 * Restart all peers in the given group.