Skip to content
Snippets Groups Projects
Unverified Commit e7189a3c authored by Sebastian Meiling's avatar Sebastian Meiling Committed by GitHub
Browse files

Merge pull request #7912 from cgundogan/pr/tests_trickle

tests: trickle: extend trickle test to print SUCCESS/FAILURE
parents 6501e71f 06f61bb2
No related branches found
No related tags found
No related merge requests found
...@@ -4,3 +4,6 @@ include ../Makefile.tests_common ...@@ -4,3 +4,6 @@ include ../Makefile.tests_common
USEMODULE += trickle USEMODULE += trickle
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include
test:
tests/01-run.py
# Trickle Test
This test starts a trickle timer and roughly checks the diff between two
intervals to be greater than the diff of previous intervals.
After `5` callbacks, the trickle timer is reset and ends after another `7`
callbacks with either `[SUCCESS]` or `[FAILURE]`. The application exits with
`[FAILURE]` as soon as one diff is *not* greater than the previous diff.
...@@ -24,18 +24,32 @@ ...@@ -24,18 +24,32 @@
#include "thread.h" #include "thread.h"
#include "msg.h" #include "msg.h"
#define Q_LEN (8)
#define TRICKLE_MSG (0xfeef) #define TRICKLE_MSG (0xfeef)
#define TR_IMIN (8) #define TR_IMIN (8)
#define TR_IDOUBLINGS (20) #define TR_IDOUBLINGS (20)
#define TR_REDCONST (10) #define TR_REDCONST (10)
#define FIRST_ROUND (5)
#define SECOND_ROUND (12)
static msg_t _msg_q[Q_LEN]; static uint32_t prev_now = 0, prev_diff = 0;
static bool error = false;
static void callback(void *args) static void callback(void *args)
{ {
(void) args; (void) args;
printf("now: %" PRIu32 "\n", 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
"\n", now, prev_now, diff);
if (prev_diff >= diff) {
error = true;
}
prev_now = now;
prev_diff = diff;
return; return;
} }
...@@ -45,13 +59,26 @@ static trickle_t trickle = { .callback.func = &callback, ...@@ -45,13 +59,26 @@ static trickle_t trickle = { .callback.func = &callback,
int main(void) int main(void)
{ {
msg_t msg; msg_t msg;
unsigned counter = 0;
msg_init_queue(_msg_q, Q_LEN);
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);
while (1) { puts("[START]");
while (!error) {
if (counter == FIRST_ROUND) {
prev_diff = 0;
trickle_reset_timer(&trickle);
puts("[TRICKLE_RESET]");
}
else if (counter == SECOND_ROUND) {
puts("[SUCCESS]");
return 0;
}
counter++;
msg_receive(&msg); msg_receive(&msg);
switch (msg.type) { switch (msg.type) {
...@@ -63,5 +90,7 @@ int main(void) ...@@ -63,5 +90,7 @@ int main(void)
} }
} }
return 0; puts("[FAILURE]");
return 1;
} }
#!/usr/bin/env python3
# Copyright (C) 2017 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import os
import sys
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
def testfunc(child):
child.expect_exact("[START]")
for i in range(5):
child.expect(u"now = \d+, prev_now = \d+, diff = \d+")
child.expect_exact("[TRICKLE_RESET]")
for i in range(7):
child.expect(u"now = \d+, prev_now = \d+, diff = \d+")
child.expect_exact("[SUCCESS]")
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment