summaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_peers_manage_services.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_peers_manage_services.c')
-rw-r--r--src/testbed/test_testbed_api_peers_manage_services.c141
1 files changed, 71 insertions, 70 deletions
diff --git a/src/testbed/test_testbed_api_peers_manage_services.c b/src/testbed/test_testbed_api_peers_manage_services.c
index d6597890f..6d4f8196a 100644
--- a/src/testbed/test_testbed_api_peers_manage_services.c
+++ b/src/testbed/test_testbed_api_peers_manage_services.c
@@ -47,17 +47,18 @@ static struct GNUNET_TESTBED_Operation *op;
47/** 47/**
48 * dummy pointer 48 * dummy pointer
49 */ 49 */
50static void *dummy_cls = (void *)0xDEAD0001; 50static void *dummy_cls = (void *) 0xDEAD0001;
51 51
52/** 52/**
53 * Abort task identifier 53 * Abort task identifier
54 */ 54 */
55static struct GNUNET_SCHEDULER_Task * abort_task; 55static struct GNUNET_SCHEDULER_Task *abort_task;
56 56
57/** 57/**
58 * States in this test 58 * States in this test
59 */ 59 */
60enum { 60enum
61{
61 /** 62 /**
62 * Test has just been initialized 63 * Test has just been initialized
63 */ 64 */
@@ -88,14 +89,14 @@ enum {
88 * Fail testcase 89 * Fail testcase
89 */ 90 */
90#define FAIL_TEST(cond, ret) do { \ 91#define FAIL_TEST(cond, ret) do { \
91 if (!(cond)) { \ 92 if (! (cond)) { \
92 GNUNET_break(0); \ 93 GNUNET_break (0); \
93 if (NULL != abort_task) \ 94 if (NULL != abort_task) \
94 GNUNET_SCHEDULER_cancel (abort_task); \ 95 GNUNET_SCHEDULER_cancel (abort_task); \
95 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ 96 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
96 ret; \ 97 ret; \
97 } \ 98 } \
98 } while (0) 99} while (0)
99 100
100 101
101/** 102/**
@@ -104,16 +105,16 @@ enum {
104 * @param cls NULL 105 * @param cls NULL
105 */ 106 */
106static void 107static void
107do_abort(void *cls) 108do_abort (void *cls)
108{ 109{
109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); 110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
110 abort_task = NULL; 111 abort_task = NULL;
111 if (NULL != op) 112 if (NULL != op)
112 { 113 {
113 GNUNET_TESTBED_operation_done(op); 114 GNUNET_TESTBED_operation_done (op);
114 op = NULL; 115 op = NULL;
115 } 116 }
116 GNUNET_SCHEDULER_shutdown(); 117 GNUNET_SCHEDULER_shutdown ();
117} 118}
118 119
119 120
@@ -126,38 +127,38 @@ do_abort(void *cls)
126 * operation has executed successfully. 127 * operation has executed successfully.
127 */ 128 */
128static void 129static void
129op_comp_cb(void *cls, 130op_comp_cb (void *cls,
130 struct GNUNET_TESTBED_Operation *op, 131 struct GNUNET_TESTBED_Operation *op,
131 const char *emsg) 132 const char *emsg)
132{ 133{
133 FAIL_TEST(cls == dummy_cls, return ); 134 FAIL_TEST (cls == dummy_cls, return );
134 FAIL_TEST(NULL == emsg, return ); 135 FAIL_TEST (NULL == emsg, return );
135 GNUNET_TESTBED_operation_done(op); 136 GNUNET_TESTBED_operation_done (op);
136 op = NULL; 137 op = NULL;
137 switch (state) 138 switch (state)
138 { 139 {
139 case STATE_PEERS_STARTED: 140 case STATE_PEERS_STARTED:
140 state = STATE_SERVICE_DOWN; 141 state = STATE_SERVICE_DOWN;
141 op = GNUNET_TESTBED_peer_manage_service(dummy_cls, 142 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
142 peers[1], 143 peers[1],
143 "topology", 144 "topology",
144 op_comp_cb, 145 op_comp_cb,
145 dummy_cls, 146 dummy_cls,
146 0); 147 0);
147 GNUNET_assert(NULL != op); 148 GNUNET_assert (NULL != op);
148 break; 149 break;
149 150
150 case STATE_SERVICE_DOWN: 151 case STATE_SERVICE_DOWN:
151 state = STATE_SERVICE_UP; 152 state = STATE_SERVICE_UP;
152 GNUNET_SCHEDULER_cancel(abort_task); 153 GNUNET_SCHEDULER_cancel (abort_task);
153 abort_task = NULL; 154 abort_task = NULL;
154 state = STATE_OK; 155 state = STATE_OK;
155 GNUNET_SCHEDULER_shutdown(); 156 GNUNET_SCHEDULER_shutdown ();
156 break; 157 break;
157 158
158 default: 159 default:
159 FAIL_TEST(0, return ); 160 FAIL_TEST (0, return );
160 } 161 }
161} 162}
162 163
163 164
@@ -174,26 +175,26 @@ op_comp_cb(void *cls,
174 * failed 175 * failed
175 */ 176 */
176static void 177static void
177test_master(void *cls, 178test_master (void *cls,
178 struct GNUNET_TESTBED_RunHandle *h, 179 struct GNUNET_TESTBED_RunHandle *h,
179 unsigned int num_peers, 180 unsigned int num_peers,
180 struct GNUNET_TESTBED_Peer **peers_, 181 struct GNUNET_TESTBED_Peer **peers_,
181 unsigned int links_succeeded, 182 unsigned int links_succeeded,
182 unsigned int links_failed) 183 unsigned int links_failed)
183{ 184{
184 FAIL_TEST(NUM_PEERS == num_peers, return ); 185 FAIL_TEST (NUM_PEERS == num_peers, return );
185 state = STATE_PEERS_STARTED; 186 state = STATE_PEERS_STARTED;
186 peers = peers_; 187 peers = peers_;
187 op = GNUNET_TESTBED_peer_manage_service(dummy_cls, 188 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
188 peers[1], 189 peers[1],
189 "topology", 190 "topology",
190 op_comp_cb, 191 op_comp_cb,
191 dummy_cls, 192 dummy_cls,
192 1); 193 1);
193 FAIL_TEST(NULL != op, return ); 194 FAIL_TEST (NULL != op, return );
194 abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 195 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
195 (GNUNET_TIME_UNIT_MINUTES, 1), 196 (GNUNET_TIME_UNIT_MINUTES, 1),
196 &do_abort, NULL); 197 &do_abort, NULL);
197} 198}
198 199
199 200
@@ -201,14 +202,14 @@ test_master(void *cls,
201 * Main function 202 * Main function
202 */ 203 */
203int 204int
204main(int argc, char **argv) 205main (int argc, char **argv)
205{ 206{
206 state = STATE_INIT; 207 state = STATE_INIT;
207 (void)GNUNET_TESTBED_test_run("test_testbed_api_peers_manage_services", 208 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peers_manage_services",
208 "test_testbed_api.conf", 209 "test_testbed_api.conf",
209 NUM_PEERS, 210 NUM_PEERS,
210 1LL, NULL, NULL, 211 1LL, NULL, NULL,
211 &test_master, NULL); 212 &test_master, NULL);
212 if (STATE_OK != state) 213 if (STATE_OK != state)
213 return 1; 214 return 1;
214 return 0; 215 return 0;