mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 06:23:53 +01:00
Merge pull request #7912 from cgundogan/pr/tests_trickle
tests: trickle: extend trickle test to print SUCCESS/FAILURE
This commit is contained in:
commit
e7189a3ce0
@ -4,3 +4,6 @@ include ../Makefile.tests_common
|
||||
USEMODULE += trickle
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
||||
|
||||
7
tests/trickle/README.md
Normal file
7
tests/trickle/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# 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 @@
|
||||
#include "thread.h"
|
||||
#include "msg.h"
|
||||
|
||||
#define Q_LEN (8)
|
||||
#define TRICKLE_MSG (0xfeef)
|
||||
#define TR_IMIN (8)
|
||||
#define TR_IDOUBLINGS (20)
|
||||
#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)
|
||||
{
|
||||
(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;
|
||||
}
|
||||
|
||||
@ -45,13 +59,26 @@ static trickle_t trickle = { .callback.func = &callback,
|
||||
int main(void)
|
||||
{
|
||||
msg_t msg;
|
||||
|
||||
msg_init_queue(_msg_q, Q_LEN);
|
||||
unsigned counter = 0;
|
||||
|
||||
trickle_start(sched_active_pid, &trickle, TRICKLE_MSG, TR_IMIN,
|
||||
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);
|
||||
|
||||
switch (msg.type) {
|
||||
@ -63,5 +90,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
puts("[FAILURE]");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
29
tests/trickle/tests/01-run.py
Executable file
29
tests/trickle/tests/01-run.py
Executable file
@ -0,0 +1,29 @@
|
||||
#!/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))
|
||||
Loading…
x
Reference in New Issue
Block a user