Merge pull request #8260 from smlng/enh/tests/xtimer_msg

tests: enhance xtimer_msg and add auto test script
This commit is contained in:
Alexandre Abadie 2017-12-15 10:25:43 +01:00 committed by GitHub
commit e6b334739a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 18 deletions

View File

@ -5,3 +5,6 @@ BOARD_INSUFFICIENT_MEMORY := nucleo32-f031
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include
test:
tests/01-run.py

View File

@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2013 INRIA
* 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
@ -12,24 +13,23 @@
* @{
*
* @file
* @brief xtimer_msg test application
* @brief xtimer_msg test application
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
*
* @author Sebastian Meiling <s@mlng.net>
* @}
*/
#include <stdio.h>
#include <time.h>
#include "xtimer.h"
#include "thread.h"
#include "msg.h"
char timer_stack[THREAD_STACKSIZE_MAIN];
char timer_stack_local[THREAD_STACKSIZE_MAIN];
char timer_stack[THREAD_STACKSIZE_DEFAULT];
char timer_stack_local[THREAD_STACKSIZE_DEFAULT];
struct timer_msg {
xtimer_t timer;
@ -38,19 +38,20 @@ struct timer_msg {
msg_t msg;
};
struct timer_msg msg_a = { .interval = 2*(1000000), .text = "Hello World", };
struct timer_msg msg_b = { .interval = 5*(1000000), .text = "This is a Test" };
struct timer_msg msg_a = { .interval = (2 * US_PER_SEC),
.text = "Hello World" };
struct timer_msg msg_b = { .interval = (5 * US_PER_SEC),
.text = "This is a Test" };
void *timer_thread(void *arg)
{
(void) arg;
timex_t now;
printf("This is thread %" PRIkernel_pid "\n", thread_getpid());
/* we need a queue if the second message arrives while the first is still processed */
/* without a queue, the message would get lost */
/* because of the way this timer works, there can be max 1 queued message */
/* The queue is required to avoid loss of a 2nd message, when the 1st is
* still processed. The timing ensures that at most 1 message is queued.
*/
msg_t msgq[1];
msg_init_queue(msgq, 1);
@ -58,12 +59,12 @@ void *timer_thread(void *arg)
msg_t m;
msg_receive(&m);
struct timer_msg *tmsg = m.content.ptr;
xtimer_now_timex(&now);
uint32_t now = xtimer_now_usec();
printf("now=%" PRIu32 ":%" PRIu32 " -> every %" PRIu32 ".%" PRIu32 "s: %s\n",
now.seconds,
now.microseconds,
tmsg->interval / 1000000,
tmsg->interval % 1000000,
(now / US_PER_SEC),
(now % US_PER_SEC),
tmsg->interval / US_PER_SEC,
tmsg->interval % US_PER_SEC,
tmsg->text);
tmsg->msg.type = 12345;
@ -83,7 +84,7 @@ void *timer_thread_local(void *arg)
msg_receive(&m);
uint32_t now = xtimer_now_usec();
int sec = now / 1000000;
int sec = now / US_PER_SEC;
int min = sec / 60;
int hr = sec / 3600;
printf("sec=%d min=%d hour=%d\n", sec, min, hr);
@ -120,7 +121,7 @@ int main(void)
"timer local");
while (1) {
xtimer_usleep(1*1000000);
xtimer_sleep(1);
msg_try_send(&m, pid2);
}
}

View File

@ -0,0 +1,32 @@
#!/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
def testfunc(child):
# 1st check for periodic 2s Hello World message, i.e., 2 output + 1 msg
for _ in range(7):
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"now=\d+:\d+ -> every 2.0s: Hello World")
# 2nd check for periodic 5s test message, i.e., 5 output + 1 msg
for _ in range(3):
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"sec=\d+ min=\d+ hour=\d+")
child.expect(r"now=\d+:\d+ -> every 5.0s: This is a Test")
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
from testrunner import run
sys.exit(run(testfunc))