1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #10328 from cgundogan/pr/trickle_test

test: trickle: fix condition for success
This commit is contained in:
Cenk Gündoğan 2018-11-05 17:55:51 +01:00 committed by GitHub
commit f6043e048e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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]")