aboutsummaryrefslogtreecommitdiff
path: root/src/testing/test_testing_peerstartup2.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-31 20:48:06 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-31 20:48:06 +0000
commit36291b73fab94a984ae4f7314f983e18492238be (patch)
treec5a2d753c04ebedcf236b0b31018789afbaf7e85 /src/testing/test_testing_peerstartup2.c
parent1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a (diff)
downloadgnunet-36291b73fab94a984ae4f7314f983e18492238be.tar.gz
gnunet-36291b73fab94a984ae4f7314f983e18492238be.zip
support for asynchronous peer start/stop and service start/stop using ARM API
Diffstat (limited to 'src/testing/test_testing_peerstartup2.c')
-rw-r--r--src/testing/test_testing_peerstartup2.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c
index 45d2280c7..25b9ba2ea 100644
--- a/src/testing/test_testing_peerstartup2.c
+++ b/src/testing/test_testing_peerstartup2.c
@@ -33,6 +33,15 @@
33#define LOG(kind,...) \ 33#define LOG(kind,...) \
34 GNUNET_log (kind, __VA_ARGS__) 34 GNUNET_log (kind, __VA_ARGS__)
35 35
36
37#define FAIL_TEST(cond) \
38 do { \
39 if ((!(cond)) && (GNUNET_OK == status)) { \
40 status = GNUNET_SYSERR; \
41 } \
42 } while (0) \
43
44
36/** 45/**
37 * The status of the test 46 * The status of the test
38 */ 47 */
@@ -57,6 +66,17 @@ struct TestingContext
57 * The running configuration of the peer 66 * The running configuration of the peer
58 */ 67 */
59 struct GNUNET_CONFIGURATION_Handle *cfg; 68 struct GNUNET_CONFIGURATION_Handle *cfg;
69
70 /**
71 * State
72 */
73 enum {
74 PEER_INIT,
75
76 PEER_STARTED,
77
78 PEER_STOPPED
79 } state;
60}; 80};
61 81
62 82
@@ -75,14 +95,6 @@ do_shutdown2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
75 95
76} 96}
77 97
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 98
87/** 99/**
88 * Task for shutdown 100 * Task for shutdown
@@ -98,22 +110,35 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 GNUNET_assert (NULL != test_ctx); 110 GNUNET_assert (NULL != test_ctx);
99 if (NULL != test_ctx->peer) 111 if (NULL != test_ctx->peer)
100 { 112 {
101 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer, 113 FAIL_TEST (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer,
102 &peer_stop_cb, 114 GNUNET_TIME_UNIT_MINUTES));
103 test_ctx)); 115
104 } 116 }
105 else 117 else
106 do_shutdown (test_ctx, tc); 118 do_shutdown (test_ctx, tc);
107} 119}
108 120
121
109static void 122static void
110ps_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) 123peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
111{ 124{
112 struct TestingContext *test_ctx = cls; 125 struct TestingContext *test_ctx = cls;
113 126
114 GNUNET_break (GNUNET_YES == success); 127 switch (test_ctx->state)
115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 128 {
116 &do_shutdown, test_ctx); 129 case PEER_INIT:
130 FAIL_TEST (GNUNET_YES == success);
131 test_ctx->state = PEER_STARTED;
132 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
133 &do_shutdown, test_ctx);
134 break;
135 case PEER_STARTED:
136 FAIL_TEST (GNUNET_NO == success);
137 GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
138 break;
139 case PEER_STOPPED:
140 FAIL_TEST (0);
141 }
117} 142}
118 143
119 144
@@ -137,9 +162,11 @@ run (void *cls, char *const *args, const char *cfgfile,
137 goto end; 162 goto end;
138 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); 163 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
139 test_ctx->peer = 164 test_ctx->peer =
140 GNUNET_TESTING_peer_configure (test_ctx->system, 165 GNUNET_TESTING_peer_configure2 (test_ctx->system,
141 test_ctx->cfg, 166 test_ctx->cfg,
142 0, &id, &emsg); 167 0, &id, &emsg,
168 &peer_status_cb,
169 test_ctx);
143 if (NULL == test_ctx->peer) 170 if (NULL == test_ctx->peer)
144 { 171 {
145 if (NULL != emsg) 172 if (NULL != emsg)
@@ -147,11 +174,12 @@ run (void *cls, char *const *args, const char *cfgfile,
147 goto end; 174 goto end;
148 } 175 }
149 if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer, 176 if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer,
150 &ps_cb, test_ctx)) 177 GNUNET_TIME_UNIT_MINUTES))
151 goto end; 178 goto end;
152 return; 179 return;
153 180
154 end: 181 end:
182 FAIL_TEST (0);
155 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 183 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
156 GNUNET_free_non_null (emsg); 184 GNUNET_free_non_null (emsg);
157} 185}
@@ -163,7 +191,7 @@ int main (int argc, char *argv[])
163 GNUNET_GETOPT_OPTION_END 191 GNUNET_GETOPT_OPTION_END
164 }; 192 };
165 193
166 status = GNUNET_SYSERR; 194 status = GNUNET_OK;
167 if (GNUNET_OK != 195 if (GNUNET_OK !=
168 GNUNET_PROGRAM_run (argc, argv, 196 GNUNET_PROGRAM_run (argc, argv,
169 "test_testing_new_peerstartup", 197 "test_testing_new_peerstartup",