aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-31 20:03:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-31 20:03:26 +0000
commit1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a (patch)
treedc96fc0e785a67d31091dddddae1e7a72711de4e /src/testing
parentb4cdd9e449679b5d38cdffef9e130b0dc7105b20 (diff)
downloadgnunet-1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a.tar.gz
gnunet-1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a.zip
- ARM based peer start stop
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am12
-rw-r--r--src/testing/test_testing_peerstartup2.c176
-rw-r--r--src/testing/testing.c170
3 files changed, 353 insertions, 5 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 2b0cb9879..02a62e57f 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -21,6 +21,7 @@ libgnunettesting_la_SOURCES = \
21 testing.c 21 testing.c
22libgnunettesting_la_LIBADD = \ 22libgnunettesting_la_LIBADD = \
23 $(top_builddir)/src/util/libgnunetutil.la \ 23 $(top_builddir)/src/util/libgnunetutil.la \
24 $(top_builddir)/src/arm/libgnunetarm.la \
24 $(LTLIBINTL) 25 $(LTLIBINTL)
25libgnunettesting_la_LDFLAGS = \ 26libgnunettesting_la_LDFLAGS = \
26 $(GN_LIB_LDFLAGS) \ 27 $(GN_LIB_LDFLAGS) \
@@ -53,14 +54,17 @@ gnunet_testing_DEPENDENCIES = \
53 54
54check_PROGRAMS = \ 55check_PROGRAMS = \
55 test_testing_portreservation \ 56 test_testing_portreservation \
57 test_testing_servicestartup \
56 test_testing_peerstartup \ 58 test_testing_peerstartup \
57 test_testing_servicestartup 59 test_testing_peerstartup2
58 60
59if ENABLE_TEST_RUN 61if ENABLE_TEST_RUN
60TESTS = \ 62TESTS = \
61 test_testing_portreservation \ 63 test_testing_portreservation \
62 test_testing_peerstartup \ 64 test_testing_peerstartup \
65 test_testing_peerstartup2 \
63 test_testing_servicestartup 66 test_testing_servicestartup
67
64endif 68endif
65 69
66test_testing_portreservation_SOURCES = \ 70test_testing_portreservation_SOURCES = \
@@ -75,6 +79,12 @@ test_testing_peerstartup_LDADD = \
75 $(top_builddir)/src/testing/libgnunettesting.la \ 79 $(top_builddir)/src/testing/libgnunettesting.la \
76 $(top_builddir)/src/util/libgnunetutil.la 80 $(top_builddir)/src/util/libgnunetutil.la
77 81
82test_testing_peerstartup2_SOURCES = \
83 test_testing_peerstartup2.c
84test_testing_peerstartup2_LDADD = \
85 $(top_builddir)/src/testing/libgnunettesting.la \
86 $(top_builddir)/src/util/libgnunetutil.la
87
78test_testing_servicestartup_SOURCES = \ 88test_testing_servicestartup_SOURCES = \
79 test_testing_servicestartup.c 89 test_testing_servicestartup.c
80test_testing_servicestartup_LDADD = \ 90test_testing_servicestartup_LDADD = \
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c
new file mode 100644
index 000000000..45d2280c7
--- /dev/null
+++ b/src/testing/test_testing_peerstartup2.c
@@ -0,0 +1,176 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testing/test_testing_new_peerstartup.c
23 * @brief test case for testing peer startup and shutdown using new testing
24 * library
25 * @author Sree Harsha Totakura
26 */
27
28#include "platform.h"
29#include "gnunet_configuration_lib.h"
30#include "gnunet_os_lib.h"
31#include "gnunet_testing_lib.h"
32
33#define LOG(kind,...) \
34 GNUNET_log (kind, __VA_ARGS__)
35
36/**
37 * The status of the test
38 */
39int status;
40
41/**
42 * The testing context
43 */
44struct TestingContext
45{
46 /**
47 * The testing system
48 */
49 struct GNUNET_TESTING_System *system;
50
51 /**
52 * The peer which has been started by the testing system
53 */
54 struct GNUNET_TESTING_Peer *peer;
55
56 /**
57 * The running configuration of the peer
58 */
59 struct GNUNET_CONFIGURATION_Handle *cfg;
60};
61
62
63static void
64do_shutdown2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
65{
66 struct TestingContext *test_ctx = cls;
67
68 if (NULL != test_ctx->peer)
69 GNUNET_TESTING_peer_destroy (test_ctx->peer);
70 if (NULL != test_ctx->cfg)
71 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
72 if (NULL != test_ctx->system)
73 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
74 GNUNET_free (test_ctx);
75
76}
77
78static void
79peer_stop_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
80{
81 GNUNET_break (GNUNET_NO == success);
82 status = GNUNET_OK;
83 GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
84}
85
86
87/**
88 * Task for shutdown
89 *
90 * @param cls the testing context
91 * @param tc the tast context
92 */
93static void
94do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95{
96 struct TestingContext *test_ctx = cls;
97
98 GNUNET_assert (NULL != test_ctx);
99 if (NULL != test_ctx->peer)
100 {
101 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer,
102 &peer_stop_cb,
103 test_ctx));
104 }
105 else
106 do_shutdown (test_ctx, tc);
107}
108
109static void
110ps_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
111{
112 struct TestingContext *test_ctx = cls;
113
114 GNUNET_break (GNUNET_YES == success);
115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
116 &do_shutdown, test_ctx);
117}
118
119
120/**
121 * Main point of test execution
122 */
123static void
124run (void *cls, char *const *args, const char *cfgfile,
125 const struct GNUNET_CONFIGURATION_Handle *cfg)
126{
127 struct TestingContext *test_ctx;
128 char *emsg;
129 struct GNUNET_PeerIdentity id;
130
131 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
132 test_ctx->system =
133 GNUNET_TESTING_system_create ("test-gnunet-testing",
134 "127.0.0.1", NULL);
135 emsg = NULL;
136 if (NULL == test_ctx->system)
137 goto end;
138 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
139 test_ctx->peer =
140 GNUNET_TESTING_peer_configure (test_ctx->system,
141 test_ctx->cfg,
142 0, &id, &emsg);
143 if (NULL == test_ctx->peer)
144 {
145 if (NULL != emsg)
146 printf ("Test failed upon error: %s", emsg);
147 goto end;
148 }
149 if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer,
150 &ps_cb, test_ctx))
151 goto end;
152 return;
153
154 end:
155 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
156 GNUNET_free_non_null (emsg);
157}
158
159
160int main (int argc, char *argv[])
161{
162 struct GNUNET_GETOPT_CommandLineOption options[] = {
163 GNUNET_GETOPT_OPTION_END
164 };
165
166 status = GNUNET_SYSERR;
167 if (GNUNET_OK !=
168 GNUNET_PROGRAM_run (argc, argv,
169 "test_testing_new_peerstartup",
170 "test case for peerstartup using new testing library",
171 options, &run, NULL))
172 return 1;
173 return (GNUNET_OK == status) ? 0 : 1;
174}
175
176/* end of test_testing_peerstartup.c */
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);