summaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_peer_reconfiguration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_peer_reconfiguration.c')
-rw-r--r--src/testbed/test_testbed_api_peer_reconfiguration.c114
1 files changed, 58 insertions, 56 deletions
diff --git a/src/testbed/test_testbed_api_peer_reconfiguration.c b/src/testbed/test_testbed_api_peer_reconfiguration.c
index 40791a9cc..91955c13d 100644
--- a/src/testbed/test_testbed_api_peer_reconfiguration.c
+++ b/src/testbed/test_testbed_api_peer_reconfiguration.c
@@ -47,12 +47,13 @@ static struct GNUNET_TESTBED_Operation *op;
47/** 47/**
48 * Abort task identifier 48 * Abort task identifier
49 */ 49 */
50static struct GNUNET_SCHEDULER_Task * abort_task; 50static struct GNUNET_SCHEDULER_Task *abort_task;
51 51
52/** 52/**
53 * States in this test 53 * States in this test
54 */ 54 */
55enum { 55enum
56{
56 /** 57 /**
57 * Test has just been initialized 58 * Test has just been initialized
58 */ 59 */
@@ -73,14 +74,14 @@ enum {
73 * Fail testcase 74 * Fail testcase
74 */ 75 */
75#define FAIL_TEST(cond, ret) do { \ 76#define FAIL_TEST(cond, ret) do { \
76 if (!(cond)) { \ 77 if (! (cond)) { \
77 GNUNET_break(0); \ 78 GNUNET_break (0); \
78 if (NULL != abort_task) \ 79 if (NULL != abort_task) \
79 GNUNET_SCHEDULER_cancel (abort_task); \ 80 GNUNET_SCHEDULER_cancel (abort_task); \
80 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ 81 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
81 ret; \ 82 ret; \
82 } \ 83 } \
83 } while (0) 84} while (0)
84 85
85 86
86/** 87/**
@@ -89,16 +90,16 @@ enum {
89 * @param cls NULL 90 * @param cls NULL
90 */ 91 */
91static void 92static void
92do_abort(void *cls) 93do_abort (void *cls)
93{ 94{
94 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); 95 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
95 abort_task = NULL; 96 abort_task = NULL;
96 if (NULL != op) 97 if (NULL != op)
97 { 98 {
98 GNUNET_TESTBED_operation_done(op); 99 GNUNET_TESTBED_operation_done (op);
99 op = NULL; 100 op = NULL;
100 } 101 }
101 GNUNET_SCHEDULER_shutdown(); 102 GNUNET_SCHEDULER_shutdown ();
102} 103}
103 104
104 105
@@ -110,29 +111,29 @@ do_abort(void *cls)
110 * @param event information about the event 111 * @param event information about the event
111 */ 112 */
112static void 113static void
113controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 114controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
114{ 115{
115 if (STATE_PEER_STARTED != state) 116 if (STATE_PEER_STARTED != state)
116 return; 117 return;
117 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) 118 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
118 { 119 {
119 GNUNET_TESTBED_operation_done(op); 120 GNUNET_TESTBED_operation_done (op);
120 op = NULL; 121 op = NULL;
121 FAIL_TEST(0, return ); 122 FAIL_TEST (0, return );
122 } 123 }
123 if (NULL != event->details.operation_finished.emsg) 124 if (NULL != event->details.operation_finished.emsg)
124 { 125 {
125 fprintf(stderr, "Operation failed: %s\n", 126 fprintf (stderr, "Operation failed: %s\n",
126 event->details.operation_finished.emsg); 127 event->details.operation_finished.emsg);
127 GNUNET_TESTBED_operation_done(op); 128 GNUNET_TESTBED_operation_done (op);
128 op = NULL; 129 op = NULL;
129 FAIL_TEST(0, return ); 130 FAIL_TEST (0, return );
130 } 131 }
131 GNUNET_TESTBED_operation_done(op); 132 GNUNET_TESTBED_operation_done (op);
132 state = STATE_PEER_RECONFIGURED; 133 state = STATE_PEER_RECONFIGURED;
133 GNUNET_SCHEDULER_cancel(abort_task); 134 GNUNET_SCHEDULER_cancel (abort_task);
134 abort_task = NULL; 135 abort_task = NULL;
135 GNUNET_SCHEDULER_shutdown(); 136 GNUNET_SCHEDULER_shutdown ();
136} 137}
137 138
138 139
@@ -149,27 +150,28 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
149 * failed 150 * failed
150 */ 151 */
151static void 152static void
152test_master(void *cls, 153test_master (void *cls,
153 struct GNUNET_TESTBED_RunHandle *h, 154 struct GNUNET_TESTBED_RunHandle *h,
154 unsigned int num_peers, 155 unsigned int num_peers,
155 struct GNUNET_TESTBED_Peer **peers_, 156 struct GNUNET_TESTBED_Peer **peers_,
156 unsigned int links_succeeded, 157 unsigned int links_succeeded,
157 unsigned int links_failed) 158 unsigned int links_failed)
158{ 159{
159 struct GNUNET_CONFIGURATION_Handle *cfg; 160 struct GNUNET_CONFIGURATION_Handle *cfg;
160 161
161 FAIL_TEST(NUM_PEERS == num_peers, return ); 162 FAIL_TEST (NUM_PEERS == num_peers, return );
162 state = STATE_PEER_STARTED; 163 state = STATE_PEER_STARTED;
163 peers = peers_; 164 peers = peers_;
164 cfg = GNUNET_CONFIGURATION_create(); 165 cfg = GNUNET_CONFIGURATION_create ();
165 FAIL_TEST(GNUNET_OK == GNUNET_CONFIGURATION_load 166 FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load
166 (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return ); 167 (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"),
167 op = GNUNET_TESTBED_peer_update_configuration(peers[0], cfg); 168 return );
168 GNUNET_CONFIGURATION_destroy(cfg); 169 op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg);
169 FAIL_TEST(NULL != op, return ); 170 GNUNET_CONFIGURATION_destroy (cfg);
170 abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 171 FAIL_TEST (NULL != op, return );
171 (GNUNET_TIME_UNIT_SECONDS, 30), 172 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
172 &do_abort, NULL); 173 (GNUNET_TIME_UNIT_SECONDS, 30),
174 &do_abort, NULL);
173} 175}
174 176
175 177
@@ -177,15 +179,15 @@ test_master(void *cls,
177 * Main function 179 * Main function
178 */ 180 */
179int 181int
180main(int argc, char **argv) 182main (int argc, char **argv)
181{ 183{
182 state = STATE_INIT; 184 state = STATE_INIT;
183 (void)GNUNET_TESTBED_test_run("test_testbed_api_peer_reconfiguration", 185 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration",
184 "test_testbed_api.conf", 186 "test_testbed_api.conf",
185 NUM_PEERS, 187 NUM_PEERS,
186 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, 188 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED,
187 &controller_cb, NULL, 189 &controller_cb, NULL,
188 &test_master, NULL); 190 &test_master, NULL);
189 if (STATE_PEER_RECONFIGURED != state) 191 if (STATE_PEER_RECONFIGURED != state)
190 return 1; 192 return 1;
191 return 0; 193 return 0;