summaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c170
1 files changed, 166 insertions, 4 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 1711531c4..216dddfea 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -31,6 +31,7 @@
31 */ 31 */
32#include "platform.h" 32#include "platform.h"
33#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_arm_service.h"
34#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
35 36
36#define LOG(kind,...) \ 37#define LOG(kind,...) \
@@ -180,6 +181,22 @@ struct GNUNET_TESTING_Peer
180 struct GNUNET_OS_Process *main_process; 181 struct GNUNET_OS_Process *main_process;
181 182
182 /** 183 /**
184 * The handle to the peer's ARM service
185 */
186 struct GNUNET_ARM_Handle *ah;
187
188 /**
189 * The config of the peer
190 */
191 struct GNUNET_CONFIGURATION_Handle *cfg;
192
193 GNUNET_TESTING_PeerStartCallback cb;
194
195 void *cb_cls;
196
197 struct GNUNET_ARM_MonitorHandle *mh;
198
199 /**
183 * The cached identity of this peer. Will be populated on call to 200 * The cached identity of this peer. Will be populated on call to
184 * GNUNET_TESTING_peer_get_identity() 201 * GNUNET_TESTING_peer_get_identity()
185 */ 202 */
@@ -819,6 +836,8 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
819 GNUNET_asprintf (&default_config, "%s/config", uc.service_home); 836 GNUNET_asprintf (&default_config, "%s/config", uc.service_home);
820 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", 837 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
821 default_config); 838 default_config);
839 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
840 default_config);
822 GNUNET_free (default_config); 841 GNUNET_free (default_config);
823 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "SERVICEHOME", 842 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "SERVICEHOME",
824 uc.service_home); 843 uc.service_home);
@@ -876,7 +895,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
876 else 895 else
877 GNUNET_free (emsg_); 896 GNUNET_free (emsg_);
878 return NULL; 897 return NULL;
879 } 898 }
880 if (key_number >= system->total_hostkeys) 899 if (key_number >= system->total_hostkeys)
881 { 900 {
882 GNUNET_asprintf (&emsg_, 901 GNUNET_asprintf (&emsg_,
@@ -960,6 +979,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
960 } 979 }
961 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); 980 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
962 peer->cfgfile = config_filename; /* Free in peer_destroy */ 981 peer->cfgfile = config_filename; /* Free in peer_destroy */
982 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
963 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 983 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
964 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) 984 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary))
965 { 985 {
@@ -1035,6 +1055,92 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
1035} 1055}
1036 1056
1037 1057
1058void
1059GNUNET_TESTING_peer_service_start (struct GNUNET_TESTING_Peer *peer,
1060 const char *service_name,
1061 GNUNET_ARM_ResultCallback cont,
1062 void *cont_cls)
1063{
1064 GNUNET_ARM_request_service_start (peer->ah,
1065 service_name,
1066 GNUNET_OS_INHERIT_STD_ALL,
1067 GNUNET_TIME_UNIT_MINUTES,
1068 cont,
1069 cont_cls);
1070
1071}
1072
1073
1074void GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer,
1075 const char *service_name,
1076 GNUNET_ARM_ResultCallback cont,
1077 void *cont_cls)
1078{
1079 GNUNET_ARM_request_service_stop (peer->ah, service_name,
1080 GNUNET_TIME_UNIT_MINUTES,
1081 cont, cont_cls);
1082}
1083
1084static void
1085arm_start_result_cb (void *cls,
1086 struct GNUNET_ARM_Handle *arm,
1087 enum GNUNET_ARM_RequestStatus rs,
1088 const char *service,
1089 enum GNUNET_ARM_Result result)
1090{
1091 struct GNUNET_TESTING_Peer *peer = cls;
1092
1093 if ((GNUNET_ARM_REQUEST_SENT_OK != rs)
1094 || ! ((GNUNET_ARM_RESULT_STARTING == result)
1095 || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result)
1096 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)))
1097 {
1098 peer->cb (peer->cb_cls, peer, GNUNET_NO);
1099 return;
1100 }
1101 peer->cb (peer->cb_cls, peer, GNUNET_OK);
1102}
1103
1104/**
1105 * Function called whenever we connect to or disconnect from ARM.
1106 *
1107 * @param cls closure
1108 * @param arm handle to the ARM connection
1109 * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
1110 * GNUNET_SYSERR on error.
1111 */
1112static void
1113conn_status (void *cls, struct GNUNET_ARM_Handle *arm,
1114 int connected)
1115{
1116 struct GNUNET_TESTING_Peer *peer = cls;
1117
1118 peer->cb (peer->cb_cls, peer, connected);
1119}
1120
1121
1122int
1123GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer,
1124 GNUNET_TESTING_PeerStartCallback cb,
1125 void *cb_cls)
1126{
1127 if (NULL != peer->ah)
1128 {
1129 GNUNET_break (0);
1130 return GNUNET_SYSERR;
1131 }
1132 GNUNET_assert (NULL != (peer->cb = cb));
1133 peer->cb_cls = cb_cls;
1134 peer->ah = GNUNET_ARM_connect (peer->cfg, &conn_status, peer);
1135 if (NULL == peer->ah)
1136 return GNUNET_SYSERR;
1137 //GNUNET_TESTING_peer_service_start (peer, "arm", &arm_start_result_cb, peer);
1138 GNUNET_TESTING_peer_service_start (peer, "arm", NULL, NULL);
1139 return GNUNET_OK;
1140}
1141
1142
1143
1038/** 1144/**
1039 * Sends SIGTERM to the peer's main process 1145 * Sends SIGTERM to the peer's main process
1040 * 1146 *
@@ -1094,6 +1200,60 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1094 return GNUNET_SYSERR; 1200 return GNUNET_SYSERR;
1095 return GNUNET_OK; 1201 return GNUNET_OK;
1096} 1202}
1203
1204static void
1205arm_stop_result_cb (void *cls,
1206 struct GNUNET_ARM_Handle *arm,
1207 enum GNUNET_ARM_RequestStatus rs,
1208 const char *service,
1209 enum GNUNET_ARM_Result result)
1210{
1211 struct GNUNET_TESTING_Peer *peer = cls;
1212
1213 if ((GNUNET_ARM_REQUEST_SENT_OK != rs)
1214 || ! ((GNUNET_ARM_RESULT_STOPPED == result)
1215 || (GNUNET_ARM_RESULT_STOPPING == result)
1216 || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result)
1217 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)))
1218 {
1219 peer->cb (peer->cb_cls, peer, GNUNET_NO);
1220 return;
1221 }
1222 peer->cb (peer->cb_cls, peer, GNUNET_OK);
1223}
1224
1225
1226static void
1227arm_service_monitor (void *cls,
1228 struct GNUNET_ARM_MonitorHandle *arm,
1229 const char *service,
1230 enum GNUNET_ARM_ServiceStatus status)
1231{
1232 struct GNUNET_TESTING_Peer *peer = cls;
1233
1234 peer->mh = arm;
1235 if (GNUNET_ARM_SERVICE_STOPPED != status)
1236 return;
1237 if (0 != strcasecmp (service, "arm"))
1238 return;
1239 peer->cb (peer->cb_cls, peer, GNUNET_OK);
1240}
1241
1242
1243int
1244GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer,
1245 GNUNET_TESTING_PeerStartCallback cb,
1246 void *cb_cls)
1247{
1248 if (NULL == peer->ah)
1249 return GNUNET_SYSERR;
1250 GNUNET_assert (NULL != (peer->cb = cb));
1251 peer->cb_cls = cb_cls;
1252 /* if (NULL == peer->mh) */
1253 /* peer->mh = GNUNET_ARM_monitor (peer->cfg, &arm_service_monitor, peer); */
1254 GNUNET_TESTING_peer_service_stop (peer, "arm", NULL, NULL);
1255 return GNUNET_OK;
1256}
1097 1257
1098 1258
1099/** 1259/**
@@ -1107,11 +1267,13 @@ void
1107GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) 1267GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1108{ 1268{
1109 if (NULL != peer->main_process) 1269 if (NULL != peer->main_process)
1110 {
1111 GNUNET_break (0);
1112 GNUNET_TESTING_peer_stop (peer); 1270 GNUNET_TESTING_peer_stop (peer);
1113 } 1271 if (NULL != peer->mh)
1272 GNUNET_ARM_monitor_disconnect_and_free (peer->mh);
1273 if (NULL != peer->ah)
1274 GNUNET_ARM_disconnect_and_free (peer->ah);
1114 GNUNET_free (peer->cfgfile); 1275 GNUNET_free (peer->cfgfile);
1276 GNUNET_CONFIGURATION_destroy (peer->cfg);
1115 GNUNET_free (peer->main_binary); 1277 GNUNET_free (peer->main_binary);
1116 GNUNET_free (peer->args); 1278 GNUNET_free (peer->args);
1117 GNUNET_free_non_null (peer->id); 1279 GNUNET_free_non_null (peer->id);