use GNUNET_log in test_brandt

This commit is contained in:
Markus Teich 2016-11-29 14:44:54 +01:00
parent df34510466
commit aee7167739

View File

@ -149,7 +149,7 @@ expected_outcome (uint16_t i, uint16_t *rlen)
{ {
if (cur_winner >= winners) if (cur_winner >= winners)
{ {
weprintf ("got too many winners"); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "got too many winners\n");
_exit (1); _exit (1);
} }
ret[cur_winner].bidder = h; ret[cur_winner].bidder = h;
@ -168,7 +168,7 @@ bidder_start (void *arg)
{ {
uint16_t i = *(uint16_t *)arg; uint16_t i = *(uint16_t *)arg;
weprintf ("starting bidder %d", i); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "starting bidder %d\n", i);
BRANDT_bidder_start (tcase.ad[i], i, tcase.n); BRANDT_bidder_start (tcase.ad[i], i, tcase.n);
} }
@ -179,8 +179,8 @@ transfer_message (void *arg)
struct msg *m = (struct msg *)arg; struct msg *m = (struct msg *)arg;
struct msg_head *h = (struct msg_head *)m->buf; struct msg_head *h = (struct msg_head *)m->buf;
weprintf ("xfer msg %d %x from %d to %d", ntohl ( GNUNET_log (GNUNET_ERROR_TYPE_INFO, "xfer msg %d %p from %d to %d\n",
h->msg_type), arg, m->sender, m->receiver); ntohl (h->msg_type), arg, m->sender, m->receiver);
BRANDT_got_message (tcase.ad[m->receiver], m->sender, m->buf, m->buf_len); BRANDT_got_message (tcase.ad[m->receiver], m->sender, m->buf, m->buf_len);
GNUNET_free (m->buf); GNUNET_free (m->buf);
GNUNET_free (m); GNUNET_free (m);
@ -194,7 +194,8 @@ cb_start (void *auction_closure)
if (tcase.n != *s) if (tcase.n != *s)
{ {
weprintf ("start callback called from bidder"); GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"start callback called from bidder\n");
_exit (1); _exit (1);
} }
@ -260,29 +261,40 @@ cb_result (void *auction_closure,
if (mustlen != results_len) if (mustlen != results_len)
{ {
weprintf ("expected result len is: %d", mustlen); GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
weprintf ("computed result len is: %d (by agent %d)", results_len, *s); "expected result len is: %d\n",
mustlen);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"computed result len is: %d (by agent %d)\n",
results_len,
*s);
tcase.ret = 1; tcase.ret = 1;
goto quit; goto quit;
} }
if (0 == results_len) if (0 == results_len && NULL != must)
{ {
weprintf ("expected result is: %p", must); GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
weprintf ("computed result is: (nil) (by agent %d)", *s); "expected result is: %p\n",
(void *)must);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"computed result is: (nil) (by agent %d)\n",
*s);
if (NULL != must)
tcase.ret = 1; tcase.ret = 1;
} }
for (uint16_t i = 0; i < results_len; i++) for (uint16_t i = 0; i < results_len; i++)
{ {
weprintf ("expected result is: bidder %d got status %d with price %d", GNUNET_log (
GNUNET_ERROR_TYPE_INFO,
"expected result is: bidder %d got status %d with price %d\n",
must[i].bidder, must[i].bidder,
must[i].status, must[i].status,
must[i].price); must[i].price);
weprintf ( GNUNET_log (
"computed result is: bidder %d got status %d with price %d (by agent %d)", GNUNET_ERROR_TYPE_INFO,
"computed result is: bidder %d got status %d with price %d (by agent %d)\n",
results[i].bidder, results[i].bidder,
results[i].status, results[i].status,
results[i].price, results[i].price,
@ -321,7 +333,7 @@ run_auction (void *arg)
tcase.outcome_public); /* outcome public */ tcase.outcome_public); /* outcome public */
if (!tcase.ad[tcase.n]) if (!tcase.ad[tcase.n])
{ {
weprintf ("BRANDT_new() failed."); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_new() failed.\n");
_exit (1); _exit (1);
} }
@ -336,7 +348,7 @@ run_auction (void *arg)
tcase.bids[i]); /* bid */ tcase.bids[i]); /* bid */
if (!tcase.ad[i]) if (!tcase.ad[i])
{ {
weprintf ("BRANDT_join() failed."); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_join() failed.\n");
tcase.ret = 1; tcase.ret = 1;
return; return;
} }
@ -351,7 +363,8 @@ run_auction (void *arg)
!tcase.ad[tcase.n]->seller_mode || /* todo: split out */ !tcase.ad[tcase.n]->seller_mode || /* todo: split out */
tcase.ad[i]->seller_mode) tcase.ad[i]->seller_mode)
{ {
weprintf ("error/mismatch in basic auction data"); GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"error/mismatch in basic auction data\n");
tcase.ret = 1; tcase.ret = 1;
return; return;
} }
@ -385,13 +398,16 @@ test_auction (uint16_t n,
tcase.outcome_public = outcome_public; tcase.outcome_public = outcome_public;
tcase.ret = 0; tcase.ret = 0;
weprintf ("######################################"); GNUNET_log (GNUNET_ERROR_TYPE_INFO,
weprintf ("testing %s auction with m = %d and %s outcome", "######################################\n");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"testing %s auction with m = %d and %s outcome\n",
tcase.m > 0 ? "M+1ST PRICE" : "FIRST PRICE", tcase.m > 0 ? "M+1ST PRICE" : "FIRST PRICE",
tcase.m, tcase.m,
tcase.outcome_public ? "PUBLIC" : "PRIVATE"); tcase.outcome_public ? "PUBLIC" : "PRIVATE");
/** \todo: output bids when migrating to GNUNET_log */ /** \todo: output bids */
weprintf ("######################################"); GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"######################################\n");
tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *); tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *);
tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t); tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t);
for (uint16_t i = 0; i <= tcase.n; i++) for (uint16_t i = 0; i <= tcase.n; i++)
@ -405,7 +421,9 @@ test_auction (uint16_t n,
BRANDT_destroy (tcase.ad[i]); BRANDT_destroy (tcase.ad[i]);
if (!tcase.result_called[i]) if (!tcase.result_called[i])
{ {
weprintf ("result callback not called for bidder %d", i); GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"result callback not called for bidder %d\n",
i);
tcase.ret = 1; tcase.ret = 1;
} }
} }
@ -424,6 +442,9 @@ main (int argc, char *argv[])
int ret = 0; int ret = 0;
struct GNUNET_CRYPTO_EccDlogContext *edc; struct GNUNET_CRYPTO_EccDlogContext *edc;
if (GNUNET_OK != GNUNET_log_setup ("test_brandt", "WARNING", NULL))
return 1;
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
BRANDT_init (edc); BRANDT_init (edc);