test_brandt: actually check the outcome correctnes
This commit is contained in:
parent
5a9e4cca40
commit
f9394ba742
129
test_brandt.c
129
test_brandt.c
@ -38,10 +38,49 @@ struct msg {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct test {
|
||||||
|
uint16_t ret;
|
||||||
|
uint16_t m;
|
||||||
|
uint16_t outcome_public;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static uint16_t *id;
|
static uint16_t *id;
|
||||||
|
static uint16_t *result_called;
|
||||||
static struct BRANDT_Auction **ad;
|
static struct BRANDT_Auction **ad;
|
||||||
static uint16_t bidders = 3;
|
static uint16_t unexpected_result;
|
||||||
static uint16_t prizes = 8;
|
|
||||||
|
/* TEST CONFIGURATION */
|
||||||
|
static const uint16_t bidders = 4;
|
||||||
|
static const uint16_t prizes = 3;
|
||||||
|
static const uint16_t bids[] = { 1, 2, 0, 2 };
|
||||||
|
|
||||||
|
|
||||||
|
static struct BRANDT_Result *
|
||||||
|
expected_outcome (uint16_t m, uint16_t outcome_public, uint16_t i)
|
||||||
|
{
|
||||||
|
int32_t highest_bidder = -1;
|
||||||
|
int32_t highest_bid = -1;
|
||||||
|
struct BRANDT_Result *ret;
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < bidders; i++)
|
||||||
|
{
|
||||||
|
if (bids[i] > highest_bid)
|
||||||
|
{
|
||||||
|
highest_bid = bids[i];
|
||||||
|
highest_bidder = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!outcome_public && !(i == highest_bidder || i == bidders))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ret = GNUNET_new (struct BRANDT_Result);
|
||||||
|
ret->bidder = highest_bidder;
|
||||||
|
ret->price = highest_bid;
|
||||||
|
ret->status = BRANDT_bidder_won;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -134,27 +173,49 @@ cb_result (void *auction_closure,
|
|||||||
struct BRANDT_Result results[],
|
struct BRANDT_Result results[],
|
||||||
uint16_t results_len)
|
uint16_t results_len)
|
||||||
{
|
{
|
||||||
uint16_t *s = (uint16_t *)auction_closure;
|
uint16_t *s = (uint16_t *)auction_closure;
|
||||||
|
struct BRANDT_Result *must = expected_outcome (ad[*s]->m,
|
||||||
|
ad[*s]->outcome_public,
|
||||||
|
*s);
|
||||||
|
|
||||||
if (0 == results_len)
|
if (0 == results_len)
|
||||||
weprintf ("result from agent %d: none", *s);
|
{
|
||||||
|
weprintf ("result from agent %d: %p", *s, must);
|
||||||
|
weprintf ("expected result is: (nil)");
|
||||||
|
|
||||||
|
if (NULL != must)
|
||||||
|
unexpected_result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint16_t i = 0; i < results_len; i++)
|
for (uint16_t i = 0; i < results_len; i++)
|
||||||
|
{
|
||||||
weprintf ("result from agent %d: bidder %d got status %d with price %d",
|
weprintf ("result from agent %d: bidder %d got status %d with price %d",
|
||||||
*s,
|
*s,
|
||||||
results[i].bidder,
|
results[i].bidder,
|
||||||
results[i].status,
|
results[i].status,
|
||||||
results[i].price);
|
results[i].price);
|
||||||
|
weprintf ("expected result is: bidder %d got status %d with price %d",
|
||||||
|
must[i].bidder,
|
||||||
|
must[i].status,
|
||||||
|
must[i].price);
|
||||||
|
|
||||||
|
if (NULL == must ||
|
||||||
|
must[i].bidder != results[i].bidder ||
|
||||||
|
must[i].status != results[i].status ||
|
||||||
|
must[i].price != results[i].price)
|
||||||
|
unexpected_result = 1;
|
||||||
|
}
|
||||||
|
result_called[*s] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_new_join (void *arg)
|
run_auction (void *arg)
|
||||||
{
|
{
|
||||||
int *ret = arg;
|
struct test *asetup = arg;
|
||||||
const char description[] = "test description for test_new_join";
|
const char description[] = "test description for test_auctions";
|
||||||
void *desc;
|
void *desc;
|
||||||
size_t desc_len;
|
size_t desc_len;
|
||||||
|
|
||||||
ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *);
|
ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *);
|
||||||
|
|
||||||
@ -168,9 +229,9 @@ run_new_join (void *arg)
|
|||||||
sizeof (description),
|
sizeof (description),
|
||||||
GNUNET_TIME_absolute_get (),
|
GNUNET_TIME_absolute_get (),
|
||||||
GNUNET_TIME_UNIT_MINUTES,
|
GNUNET_TIME_UNIT_MINUTES,
|
||||||
prizes, /* amount of possible prizes */
|
prizes, /* number of prizes */
|
||||||
0, /* m */
|
asetup->m, /* m */
|
||||||
1); /* outcome public */
|
asetup->outcome_public); /* outcome public */
|
||||||
if (!ad[bidders])
|
if (!ad[bidders])
|
||||||
{
|
{
|
||||||
weprintf ("BRANDT_new() failed.");
|
weprintf ("BRANDT_new() failed.");
|
||||||
@ -187,7 +248,7 @@ run_new_join (void *arg)
|
|||||||
desc_len,
|
desc_len,
|
||||||
description,
|
description,
|
||||||
sizeof (description),
|
sizeof (description),
|
||||||
3); /* bid */
|
bids[i]); /* bid */
|
||||||
if (!ad[i])
|
if (!ad[i])
|
||||||
{
|
{
|
||||||
weprintf ("BRANDT_join() failed.");
|
weprintf ("BRANDT_join() failed.");
|
||||||
@ -208,26 +269,48 @@ run_new_join (void *arg)
|
|||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ret = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_new_join ()
|
test_auctions ()
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
id = GNUNET_new_array (bidders + 1, uint16_t);
|
id = GNUNET_new_array (bidders + 1, uint16_t);
|
||||||
for (uint16_t i = 0; i <= bidders; i++)
|
for (uint16_t i = 0; i <= bidders; i++)
|
||||||
id[i] = i;
|
id[i] = i;
|
||||||
|
|
||||||
GNUNET_SCHEDULER_run (&run_new_join, &ret);
|
for (size_t atype = 0; atype < auction_last; atype++)
|
||||||
|
{
|
||||||
|
if (auction_firstPrice != atype) /* others not yet implemented */
|
||||||
|
continue;
|
||||||
|
|
||||||
for (uint16_t i = 0; i <= bidders; i++)
|
for (size_t oc = 0; oc < outcome_last; oc++)
|
||||||
BRANDT_destroy (ad[i]);
|
{
|
||||||
|
struct test asetup;
|
||||||
|
|
||||||
return ret;
|
result_called = GNUNET_new_array (bidders + 1, uint16_t);
|
||||||
|
unexpected_result = 0;
|
||||||
|
asetup.ret = 0;
|
||||||
|
asetup.m = atype;
|
||||||
|
asetup.outcome_public = oc;
|
||||||
|
GNUNET_SCHEDULER_run (&run_auction, &asetup);
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i <= bidders; i++)
|
||||||
|
{
|
||||||
|
BRANDT_destroy (ad[i]);
|
||||||
|
if (!result_called[i])
|
||||||
|
{
|
||||||
|
weprintf ("result callback not called for bidder %d", i);
|
||||||
|
unexpected_result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unexpected_result)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -239,7 +322,7 @@ main (int argc, char *argv[])
|
|||||||
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
|
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
|
||||||
BRANDT_init (edc);
|
BRANDT_init (edc);
|
||||||
|
|
||||||
RUN (test_new_join);
|
RUN (test_auctions);
|
||||||
|
|
||||||
GNUNET_CRYPTO_ecc_dlog_release (edc);
|
GNUNET_CRYPTO_ecc_dlog_release (edc);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -191,7 +191,7 @@ test_setup_auction_data ()
|
|||||||
ad[i].n = bidders;
|
ad[i].n = bidders;
|
||||||
ad[i].i = i;
|
ad[i].i = i;
|
||||||
ad[i].k = prizes;
|
ad[i].k = prizes;
|
||||||
ad[i].b = 2 * i;
|
ad[i].b = i;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ main (int argc, char *argv[])
|
|||||||
struct GNUNET_CRYPTO_EccDlogContext *edc;
|
struct GNUNET_CRYPTO_EccDlogContext *edc;
|
||||||
|
|
||||||
bidders = 3;
|
bidders = 3;
|
||||||
prizes = 6;
|
prizes = 3;
|
||||||
|
|
||||||
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
|
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
|
||||||
BRANDT_init (edc);
|
BRANDT_init (edc);
|
||||||
|
Loading…
Reference in New Issue
Block a user