test: trickle: fix condition for success

The current test implementation wrongly assumes that the diff between
two fired events (e1, e2) must always increase. That is not true, as
event e1 may reside on the upper part of [I/2, I) and e2 on the lower
part of [I, 2*I).

This commit fixes the test to look at the actual time that was randonmly
chosen from both intervals (t1, t2). Given that the intervals are
doubled, t1 must always be smaller than t2.
This commit is contained in:
Cenk Gündoğan 2018-11-05 08:41:34 +01:00
parent 8130874a1a
commit df9e25353b
2 changed files with 15 additions and 14 deletions

View File

@ -31,36 +31,37 @@
#define FIRST_ROUND (5) #define FIRST_ROUND (5)
#define SECOND_ROUND (12) #define SECOND_ROUND (12)
static uint32_t prev_now = 0, prev_diff = 0; static uint32_t old_t = 0;
static bool error = false; static bool error = false;
static void callback(void *args);
static trickle_t trickle = { .callback = { .func = &callback,
.args = NULL } };
static void callback(void *args) static void callback(void *args)
{ {
(void) args; (void) args;
uint32_t now = xtimer_now_usec(); uint32_t now = xtimer_now_usec();
uint32_t diff = (uint32_t) (now - prev_now);
printf("now = %" PRIu32 ", prev_now = %" PRIu32 ", diff = %" PRIu32 printf("now = %" PRIu32 ", t = %" PRIu32 "\n", now, trickle.t);
"\n", now, prev_now, diff);
if (prev_diff >= diff) { /* previous `t` is chosen from a smaller interval [I/2, I).
* Current `t` is chosen from interval [I, 2*I).
* Hence, `old_t` must be smaller than current `t` */
if (old_t >= trickle.t) {
error = true; error = true;
} }
prev_now = now; old_t = trickle.t;
prev_diff = diff;
return; return;
} }
static trickle_t trickle = { .callback = { .func = &callback,
.args = NULL } };
int main(void) int main(void)
{ {
msg_t msg; msg_t msg;
unsigned counter = 0; unsigned counter = 0;
prev_now = xtimer_now_usec();
trickle_start(sched_active_pid, &trickle, TRICKLE_MSG, TR_IMIN, trickle_start(sched_active_pid, &trickle, TRICKLE_MSG, TR_IMIN,
TR_IDOUBLINGS, TR_REDCONST); TR_IDOUBLINGS, TR_REDCONST);
@ -69,7 +70,7 @@ int main(void)
while (!error) { while (!error) {
if (counter == FIRST_ROUND) { if (counter == FIRST_ROUND) {
prev_diff = 0; old_t = 0;
trickle_reset_timer(&trickle); trickle_reset_timer(&trickle);
puts("[TRICKLE_RESET]"); puts("[TRICKLE_RESET]");
} }

View File

@ -14,12 +14,12 @@ def testfunc(child):
child.expect_exact("[START]") child.expect_exact("[START]")
for i in range(5): for i in range(5):
child.expect(u"now = \d+, prev_now = \d+, diff = \d+") child.expect(u"now = \\d+, t = \\d+")
child.expect_exact("[TRICKLE_RESET]") child.expect_exact("[TRICKLE_RESET]")
for i in range(7): for i in range(7):
child.expect(u"now = \d+, prev_now = \d+, diff = \d+") child.expect(u"now = \\d+, t = \\d+")
child.expect_exact("[SUCCESS]") child.expect_exact("[SUCCESS]")