diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-25 19:15:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-25 19:15:01 +0000 |
commit | 703f79ac9ec77195dcfbf957da8622ff0ca324c3 (patch) | |
tree | ed821ff67f6466181be4b20541ab8922dd0c86dc /src | |
parent | c6c5352edfdaeed1321a73635e6ac201cbb21f98 (diff) | |
download | gnunet-703f79ac9ec77195dcfbf957da8622ff0ca324c3.tar.gz gnunet-703f79ac9ec77195dcfbf957da8622ff0ca324c3.zip |
-fixing testcases
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/test_ats_solver_alternative_after_delete_address.c | 115 |
1 files changed, 78 insertions, 37 deletions
diff --git a/src/ats/test_ats_solver_alternative_after_delete_address.c b/src/ats/test_ats_solver_alternative_after_delete_address.c index aa04e82d5..8a14b384e 100644 --- a/src/ats/test_ats_solver_alternative_after_delete_address.c +++ b/src/ats/test_ats_solver_alternative_after_delete_address.c | |||
@@ -18,7 +18,7 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_solver_add_address.c | 21 | * @file ats/test_ats_solver_alternative_after_delete_address.c |
22 | * @brief solver test: add 2 addresses, request address, delete, expect alternative | 22 | * @brief solver test: add 2 addresses, request address, delete, expect alternative |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
@@ -92,19 +92,19 @@ static uint32_t test_ats_count; | |||
92 | /** | 92 | /** |
93 | * Test state | 93 | * Test state |
94 | */ | 94 | */ |
95 | static int addresses_added = GNUNET_NO; | 95 | static int addresses_added; |
96 | 96 | ||
97 | static int first_address_suggested = GNUNET_NO; | 97 | static int first_address_suggested; |
98 | 98 | ||
99 | static int first_address_deleted = GNUNET_NO; | 99 | static int first_address_deleted; |
100 | 100 | ||
101 | static int second_address_deleted = GNUNET_NO; | 101 | static int second_address_deleted; |
102 | 102 | ||
103 | static int second_address_suggested = GNUNET_YES; | 103 | static int second_address_suggested = GNUNET_YES; |
104 | 104 | ||
105 | static struct GNUNET_HELLO_Address *first_suggestion = NULL; | 105 | static struct GNUNET_HELLO_Address *first_suggestion; |
106 | 106 | ||
107 | static struct GNUNET_HELLO_Address *second_suggestion = NULL; | 107 | static struct GNUNET_HELLO_Address *second_suggestion; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * 1st Address we will destroy. | 110 | * 1st Address we will destroy. |
@@ -118,8 +118,9 @@ static struct GNUNET_ATS_AddressRecord *ar2; | |||
118 | 118 | ||
119 | 119 | ||
120 | static int | 120 | static int |
121 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | 121 | stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, |
122 | int is_persistent); | 122 | int is_persistent); |
123 | |||
123 | 124 | ||
124 | static void | 125 | static void |
125 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 126 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -159,6 +160,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
159 | ret = GNUNET_SYSERR; | 160 | ret = GNUNET_SYSERR; |
160 | } | 161 | } |
161 | 162 | ||
163 | |||
162 | static void | 164 | static void |
163 | end_badly_now () | 165 | end_badly_now () |
164 | { | 166 | { |
@@ -170,6 +172,7 @@ end_badly_now () | |||
170 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 172 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
171 | } | 173 | } |
172 | 174 | ||
175 | |||
173 | static void | 176 | static void |
174 | address_suggest_cb (void *cls, | 177 | address_suggest_cb (void *cls, |
175 | const struct GNUNET_PeerIdentity *peer, | 178 | const struct GNUNET_PeerIdentity *peer, |
@@ -178,7 +181,8 @@ address_suggest_cb (void *cls, | |||
178 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 181 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
179 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 182 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
180 | { | 183 | { |
181 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received a sugggestion for peer `%s' : `%s'\n", | 184 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
185 | "Received a sugggestion for peer `%s' : `%s'\n", | ||
182 | GNUNET_i2s (&address->peer), (char *) address->address); | 186 | GNUNET_i2s (&address->peer), (char *) address->address); |
183 | 187 | ||
184 | if (GNUNET_NO == first_address_suggested) | 188 | if (GNUNET_NO == first_address_suggested) |
@@ -199,17 +203,32 @@ address_suggest_cb (void *cls, | |||
199 | return; | 203 | return; |
200 | } | 204 | } |
201 | 205 | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received 1st sugggestion for peer `%s' : `%s'\n", | 206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
207 | "Received 1st sugggestion for peer `%s' : `%s'\n", | ||
203 | GNUNET_i2s (&address->peer), (char *) address->address); | 208 | GNUNET_i2s (&address->peer), (char *) address->address); |
204 | 209 | ||
205 | first_suggestion = GNUNET_HELLO_address_copy (address); | 210 | first_suggestion = GNUNET_HELLO_address_copy (address); |
206 | first_address_suggested = GNUNET_YES; | 211 | first_address_suggested = GNUNET_YES; |
207 | 212 | ||
208 | 213 | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 1st address for peer `%s' : `%s'\n", | 214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
210 | GNUNET_i2s (&address->peer), (char *) address->address); | 215 | "Deleting 1st address for peer `%s' : `%s'\n", |
211 | GNUNET_ATS_address_destroy (ar); | 216 | GNUNET_i2s (&address->peer), |
212 | ar = NULL; | 217 | (char *) address->address); |
218 | if (0 == (strcmp ((char *) address->address, | ||
219 | "test"))) | ||
220 | { | ||
221 | GNUNET_assert (NULL != ar); | ||
222 | GNUNET_ATS_address_destroy (ar); | ||
223 | ar = NULL; | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | GNUNET_assert (NULL != ar2); | ||
228 | GNUNET_ATS_address_destroy (ar2); | ||
229 | ar2 = NULL; | ||
230 | } | ||
231 | |||
213 | first_address_deleted = GNUNET_YES; | 232 | first_address_deleted = GNUNET_YES; |
214 | 233 | ||
215 | return; | 234 | return; |
@@ -229,20 +248,33 @@ address_suggest_cb (void *cls, | |||
229 | if (0 != memcmp (address->address, first_suggestion->address, | 248 | if (0 != memcmp (address->address, first_suggestion->address, |
230 | (first_suggestion->address_length < address->address_length) ? first_suggestion->address_length : address->address_length)) | 249 | (first_suggestion->address_length < address->address_length) ? first_suggestion->address_length : address->address_length)) |
231 | { | 250 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received 2nd sugggestion for peer `%s' : `%s'\n", | 251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
233 | GNUNET_i2s (&address->peer), (char *) address->address); | 252 | "Received 2nd sugggestion for peer `%s' : `%s'\n", |
253 | GNUNET_i2s (&address->peer), | ||
254 | (char *) address->address); | ||
234 | second_suggestion = GNUNET_HELLO_address_copy (address); | 255 | second_suggestion = GNUNET_HELLO_address_copy (address); |
235 | second_address_suggested = GNUNET_YES; | 256 | second_address_suggested = GNUNET_YES; |
236 | 257 | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer `%s' : `%s'\n", | 258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
238 | GNUNET_i2s (&address->peer), (char *) address->address); | 259 | "Deleting 2nd address for peer `%s' : `%s'\n", |
239 | GNUNET_ATS_address_destroy (ar2); | 260 | GNUNET_i2s (&address->peer), |
240 | ar2 = NULL; | 261 | (char *) address->address); |
262 | if (NULL != ar) | ||
263 | { | ||
264 | GNUNET_assert (NULL == ar2); | ||
265 | GNUNET_ATS_address_destroy (ar); | ||
266 | ar = NULL; | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | GNUNET_assert (NULL != ar2); | ||
271 | GNUNET_ATS_address_destroy (ar2); | ||
272 | ar2 = NULL; | ||
273 | } | ||
241 | second_address_deleted = GNUNET_YES; | 274 | second_address_deleted = GNUNET_YES; |
242 | return; | 275 | return; |
243 | } | 276 | } |
244 | } | 277 | } |
245 | |||
246 | } | 278 | } |
247 | if (GNUNET_YES == second_address_deleted) | 279 | if (GNUNET_YES == second_address_deleted) |
248 | { | 280 | { |
@@ -250,17 +282,18 @@ address_suggest_cb (void *cls, | |||
250 | if ((ntohl(bandwidth_in.value__) == 0) && | 282 | if ((ntohl(bandwidth_in.value__) == 0) && |
251 | (ntohl(bandwidth_out.value__) == 0)) | 283 | (ntohl(bandwidth_out.value__) == 0)) |
252 | { | 284 | { |
253 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS tells me to disconnect\n"); | 285 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
286 | "ATS tells me to disconnect\n"); | ||
254 | GNUNET_SCHEDULER_add_now (&end, NULL); | 287 | GNUNET_SCHEDULER_add_now (&end, NULL); |
255 | return; | 288 | return; |
256 | } | 289 | } |
257 | else | 290 | else |
258 | { | 291 | { |
259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Expected disconnect but received address `%s' with bandwidth \n", | 292 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
260 | (char *) address->address); | 293 | "Expected disconnect but received address `%s' with bandwidth \n", |
294 | (char *) address->address); | ||
261 | } | 295 | } |
262 | } | 296 | } |
263 | return; | ||
264 | } | 297 | } |
265 | 298 | ||
266 | 299 | ||
@@ -269,11 +302,15 @@ stat_cb(void *cls, const char *subsystem, | |||
269 | const char *name, uint64_t value, | 302 | const char *name, uint64_t value, |
270 | int is_persistent) | 303 | int is_persistent) |
271 | { | 304 | { |
272 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | 305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
273 | subsystem,name, value); | 306 | "ATS statistics: `%s' `%s' %llu\n", |
307 | subsystem, | ||
308 | name, | ||
309 | value); | ||
274 | if ((GNUNET_NO == addresses_added) && (value == 2)) | 310 | if ((GNUNET_NO == addresses_added) && (value == 2)) |
275 | { | 311 | { |
276 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All addresses added, requesting....\n"); | 312 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
313 | "All addresses added, requesting....\n"); | ||
277 | /* We have 2 addresses, so we can request */ | 314 | /* We have 2 addresses, so we can request */ |
278 | addresses_added = GNUNET_YES; | 315 | addresses_added = GNUNET_YES; |
279 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | 316 | GNUNET_ATS_suggest_address (sched_ats, &p.id); |
@@ -283,8 +320,9 @@ stat_cb(void *cls, const char *subsystem, | |||
283 | 320 | ||
284 | 321 | ||
285 | static void | 322 | static void |
286 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | 323 | run (void *cls, |
287 | struct GNUNET_TESTING_Peer *peer) | 324 | const struct GNUNET_CONFIGURATION_Handle *mycfg, |
325 | struct GNUNET_TESTING_Peer *peer) | ||
288 | { | 326 | { |
289 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 327 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
290 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 328 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
@@ -295,7 +333,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
295 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 333 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
296 | if (sched_ats == NULL) | 334 | if (sched_ats == NULL) |
297 | { | 335 | { |
298 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | 336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
337 | "Could not connect to ATS scheduling!\n"); | ||
299 | end_badly_now (); | 338 | end_badly_now (); |
300 | return; | 339 | return; |
301 | } | 340 | } |
@@ -314,7 +353,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
314 | 353 | ||
315 | /* Adding address without session */ | 354 | /* Adding address without session */ |
316 | test_session = NULL; | 355 | test_session = NULL; |
317 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | 356 | create_test_address (&test_addr, "test", test_session, |
357 | "test", strlen ("test") + 1); | ||
318 | test_hello_address.peer = p.id; | 358 | test_hello_address.peer = p.id; |
319 | test_hello_address.transport_name = test_addr.plugin; | 359 | test_hello_address.transport_name = test_addr.plugin; |
320 | test_hello_address.address = test_addr.addr; | 360 | test_hello_address.address = test_addr.addr; |
@@ -322,7 +362,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
322 | 362 | ||
323 | /* Adding alternative address without session */ | 363 | /* Adding alternative address without session */ |
324 | test_session = NULL; | 364 | test_session = NULL; |
325 | create_test_address (&alt_test_addr, "test", test_session, "alt_test", strlen ("alt_test") + 1); | 365 | create_test_address (&alt_test_addr, "test", test_session, |
366 | "alt_test", strlen ("alt_test") + 1); | ||
326 | alt_test_hello_address.peer = p.id; | 367 | alt_test_hello_address.peer = p.id; |
327 | alt_test_hello_address.transport_name = alt_test_addr.plugin; | 368 | alt_test_hello_address.transport_name = alt_test_addr.plugin; |
328 | alt_test_hello_address.address = alt_test_addr.addr; | 369 | alt_test_hello_address.address = alt_test_addr.addr; |
@@ -344,12 +385,12 @@ main (int argc, char *argv[]) | |||
344 | char *sep; | 385 | char *sep; |
345 | char *src_filename = GNUNET_strdup (__FILE__); | 386 | char *src_filename = GNUNET_strdup (__FILE__); |
346 | char *test_filename = GNUNET_strdup (argv[0]); | 387 | char *test_filename = GNUNET_strdup (argv[0]); |
347 | char *config_file; | 388 | const char *config_file; |
348 | char *solver; | 389 | char *solver; |
349 | 390 | ||
350 | ret = 0; | 391 | ret = 0; |
351 | 392 | ||
352 | if (NULL == (sep = (strstr (src_filename,".c")))) | 393 | if (NULL == (sep = (strstr (src_filename, ".c")))) |
353 | { | 394 | { |
354 | GNUNET_break (0); | 395 | GNUNET_break (0); |
355 | return -1; | 396 | return -1; |
@@ -396,4 +437,4 @@ main (int argc, char *argv[]) | |||
396 | return ret; | 437 | return ret; |
397 | } | 438 | } |
398 | 439 | ||
399 | /* end of file test_ats_solver_add_address.c */ | 440 | /* end of file test_ats_solver_alternative_after_delete_address.c */ |