From df9e25353b2427ed7f85fc019c310103091d6d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Mon, 5 Nov 2018 08:41:34 +0100 Subject: [PATCH] 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. --- tests/trickle/main.c | 25 +++++++++++++------------ tests/trickle/tests/01-run.py | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/trickle/main.c b/tests/trickle/main.c index 79ce6f44fa..a57acda21c 100644 --- a/tests/trickle/main.c +++ b/tests/trickle/main.c @@ -31,36 +31,37 @@ #define FIRST_ROUND (5) #define SECOND_ROUND (12) -static uint32_t prev_now = 0, prev_diff = 0; +static uint32_t old_t = 0; static bool error = false; +static void callback(void *args); + +static trickle_t trickle = { .callback = { .func = &callback, + .args = NULL } }; + static void callback(void *args) { (void) args; uint32_t now = xtimer_now_usec(); - uint32_t diff = (uint32_t) (now - prev_now); - printf("now = %" PRIu32 ", prev_now = %" PRIu32 ", diff = %" PRIu32 - "\n", now, prev_now, diff); + printf("now = %" PRIu32 ", t = %" PRIu32 "\n", now, trickle.t); - 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; } - prev_now = now; - prev_diff = diff; + old_t = trickle.t; return; } -static trickle_t trickle = { .callback = { .func = &callback, - .args = NULL } }; - int main(void) { msg_t msg; unsigned counter = 0; - prev_now = xtimer_now_usec(); trickle_start(sched_active_pid, &trickle, TRICKLE_MSG, TR_IMIN, TR_IDOUBLINGS, TR_REDCONST); @@ -69,7 +70,7 @@ int main(void) while (!error) { if (counter == FIRST_ROUND) { - prev_diff = 0; + old_t = 0; trickle_reset_timer(&trickle); puts("[TRICKLE_RESET]"); } diff --git a/tests/trickle/tests/01-run.py b/tests/trickle/tests/01-run.py index 7ada364445..e6ecefd89d 100755 --- a/tests/trickle/tests/01-run.py +++ b/tests/trickle/tests/01-run.py @@ -14,12 +14,12 @@ def testfunc(child): child.expect_exact("[START]") 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]") 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]")