aboutsummaryrefslogtreecommitdiff
path: root/test_brandt.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-11-29 14:44:54 +0100
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-11-29 14:44:54 +0100
commitaee7167739e666ea94c3b68c58a0f7aa1ede238e (patch)
tree395d599aec8e00428c14cf6c0b7469967b4d5089 /test_brandt.c
parentdf345104666d11a7e8c35254b4ed7a0187a256a2 (diff)
downloadlibbrandt-aee7167739e666ea94c3b68c58a0f7aa1ede238e.tar.gz
libbrandt-aee7167739e666ea94c3b68c58a0f7aa1ede238e.zip
use GNUNET_log in test_brandt
Diffstat (limited to 'test_brandt.c')
-rw-r--r--test_brandt.c79
1 files changed, 50 insertions, 29 deletions
diff --git a/test_brandt.c b/test_brandt.c
index 9d91260..47f3711 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -149,7 +149,7 @@ expected_outcome (uint16_t i, uint16_t *rlen)
149 { 149 {
150 if (cur_winner >= winners) 150 if (cur_winner >= winners)
151 { 151 {
152 weprintf ("got too many winners"); 152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "got too many winners\n");
153 _exit (1); 153 _exit (1);
154 } 154 }
155 ret[cur_winner].bidder = h; 155 ret[cur_winner].bidder = h;
@@ -168,7 +168,7 @@ bidder_start (void *arg)
168{ 168{
169 uint16_t i = *(uint16_t *)arg; 169 uint16_t i = *(uint16_t *)arg;
170 170
171 weprintf ("starting bidder %d", i); 171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "starting bidder %d\n", i);
172 BRANDT_bidder_start (tcase.ad[i], i, tcase.n); 172 BRANDT_bidder_start (tcase.ad[i], i, tcase.n);
173} 173}
174 174
@@ -179,8 +179,8 @@ transfer_message (void *arg)
179 struct msg *m = (struct msg *)arg; 179 struct msg *m = (struct msg *)arg;
180 struct msg_head *h = (struct msg_head *)m->buf; 180 struct msg_head *h = (struct msg_head *)m->buf;
181 181
182 weprintf ("xfer msg %d %x from %d to %d", ntohl ( 182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "xfer msg %d %p from %d to %d\n",
183 h->msg_type), arg, m->sender, m->receiver); 183 ntohl (h->msg_type), arg, m->sender, m->receiver);
184 BRANDT_got_message (tcase.ad[m->receiver], m->sender, m->buf, m->buf_len); 184 BRANDT_got_message (tcase.ad[m->receiver], m->sender, m->buf, m->buf_len);
185 GNUNET_free (m->buf); 185 GNUNET_free (m->buf);
186 GNUNET_free (m); 186 GNUNET_free (m);
@@ -194,7 +194,8 @@ cb_start (void *auction_closure)
194 194
195 if (tcase.n != *s) 195 if (tcase.n != *s)
196 { 196 {
197 weprintf ("start callback called from bidder"); 197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 "start callback called from bidder\n");
198 _exit (1); 199 _exit (1);
199 } 200 }
200 201
@@ -260,29 +261,40 @@ cb_result (void *auction_closure,
260 261
261 if (mustlen != results_len) 262 if (mustlen != results_len)
262 { 263 {
263 weprintf ("expected result len is: %d", mustlen); 264 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
264 weprintf ("computed result len is: %d (by agent %d)", results_len, *s); 265 "expected result len is: %d\n",
266 mustlen);
267 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
268 "computed result len is: %d (by agent %d)\n",
269 results_len,
270 *s);
265 tcase.ret = 1; 271 tcase.ret = 1;
266 goto quit; 272 goto quit;
267 } 273 }
268 274
269 if (0 == results_len) 275 if (0 == results_len && NULL != must)
270 { 276 {
271 weprintf ("expected result is: %p", must); 277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
272 weprintf ("computed result is: (nil) (by agent %d)", *s); 278 "expected result is: %p\n",
279 (void *)must);
280 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
281 "computed result is: (nil) (by agent %d)\n",
282 *s);
273 283
274 if (NULL != must) 284 tcase.ret = 1;
275 tcase.ret = 1;
276 } 285 }
277 286
278 for (uint16_t i = 0; i < results_len; i++) 287 for (uint16_t i = 0; i < results_len; i++)
279 { 288 {
280 weprintf ("expected result is: bidder %d got status %d with price %d", 289 GNUNET_log (
281 must[i].bidder, 290 GNUNET_ERROR_TYPE_INFO,
282 must[i].status, 291 "expected result is: bidder %d got status %d with price %d\n",
283 must[i].price); 292 must[i].bidder,
284 weprintf ( 293 must[i].status,
285 "computed result is: bidder %d got status %d with price %d (by agent %d)", 294 must[i].price);
295 GNUNET_log (
296 GNUNET_ERROR_TYPE_INFO,
297 "computed result is: bidder %d got status %d with price %d (by agent %d)\n",
286 results[i].bidder, 298 results[i].bidder,
287 results[i].status, 299 results[i].status,
288 results[i].price, 300 results[i].price,
@@ -321,7 +333,7 @@ run_auction (void *arg)
321 tcase.outcome_public); /* outcome public */ 333 tcase.outcome_public); /* outcome public */
322 if (!tcase.ad[tcase.n]) 334 if (!tcase.ad[tcase.n])
323 { 335 {
324 weprintf ("BRANDT_new() failed."); 336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_new() failed.\n");
325 _exit (1); 337 _exit (1);
326 } 338 }
327 339
@@ -336,7 +348,7 @@ run_auction (void *arg)
336 tcase.bids[i]); /* bid */ 348 tcase.bids[i]); /* bid */
337 if (!tcase.ad[i]) 349 if (!tcase.ad[i])
338 { 350 {
339 weprintf ("BRANDT_join() failed."); 351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_join() failed.\n");
340 tcase.ret = 1; 352 tcase.ret = 1;
341 return; 353 return;
342 } 354 }
@@ -351,7 +363,8 @@ run_auction (void *arg)
351 !tcase.ad[tcase.n]->seller_mode || /* todo: split out */ 363 !tcase.ad[tcase.n]->seller_mode || /* todo: split out */
352 tcase.ad[i]->seller_mode) 364 tcase.ad[i]->seller_mode)
353 { 365 {
354 weprintf ("error/mismatch in basic auction data"); 366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
367 "error/mismatch in basic auction data\n");
355 tcase.ret = 1; 368 tcase.ret = 1;
356 return; 369 return;
357 } 370 }
@@ -385,13 +398,16 @@ test_auction (uint16_t n,
385 tcase.outcome_public = outcome_public; 398 tcase.outcome_public = outcome_public;
386 tcase.ret = 0; 399 tcase.ret = 0;
387 400
388 weprintf ("######################################"); 401 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
389 weprintf ("testing %s auction with m = %d and %s outcome", 402 "######################################\n");
390 tcase.m > 0 ? "M+1ST PRICE" : "FIRST PRICE", 403 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
391 tcase.m, 404 "testing %s auction with m = %d and %s outcome\n",
392 tcase.outcome_public ? "PUBLIC" : "PRIVATE"); 405 tcase.m > 0 ? "M+1ST PRICE" : "FIRST PRICE",
393 /** \todo: output bids when migrating to GNUNET_log */ 406 tcase.m,
394 weprintf ("######################################"); 407 tcase.outcome_public ? "PUBLIC" : "PRIVATE");
408 /** \todo: output bids */
409 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
410 "######################################\n");
395 tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *); 411 tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *);
396 tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t); 412 tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t);
397 for (uint16_t i = 0; i <= tcase.n; i++) 413 for (uint16_t i = 0; i <= tcase.n; i++)
@@ -405,7 +421,9 @@ test_auction (uint16_t n,
405 BRANDT_destroy (tcase.ad[i]); 421 BRANDT_destroy (tcase.ad[i]);
406 if (!tcase.result_called[i]) 422 if (!tcase.result_called[i])
407 { 423 {
408 weprintf ("result callback not called for bidder %d", i); 424 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
425 "result callback not called for bidder %d\n",
426 i);
409 tcase.ret = 1; 427 tcase.ret = 1;
410 } 428 }
411 } 429 }
@@ -424,6 +442,9 @@ main (int argc, char *argv[])
424 int ret = 0; 442 int ret = 0;
425 struct GNUNET_CRYPTO_EccDlogContext *edc; 443 struct GNUNET_CRYPTO_EccDlogContext *edc;
426 444
445 if (GNUNET_OK != GNUNET_log_setup ("test_brandt", "WARNING", NULL))
446 return 1;
447
427 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); 448 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
428 BRANDT_init (edc); 449 BRANDT_init (edc);
429 450