tests: add ztimer test applications
This commit is contained in:
parent
39980d5ea3
commit
779e47966a
8
tests/ztimer_msg/Makefile
Normal file
8
tests/ztimer_msg/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += ztimer_usec
|
||||
|
||||
# uncomment this to test using ztimer msec on rtt
|
||||
#USEMODULE += ztimer_msec ztimer_periph_rtt
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
8
tests/ztimer_msg/Makefile.ci
Normal file
8
tests/ztimer_msg/Makefile.ci
Normal file
@ -0,0 +1,8 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
arduino-duemilanove \
|
||||
arduino-nano \
|
||||
arduino-uno \
|
||||
atmega328p \
|
||||
nucleo-f031k6 \
|
||||
stm32f030f4-demo \
|
||||
#
|
||||
9
tests/ztimer_msg/README.md
Normal file
9
tests/ztimer_msg/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Overview
|
||||
|
||||
This test application is a direct translation of xtimer_msg to the ztimer API.
|
||||
It is meant mostly as a means to do size comparisons, thus tries to be as close
|
||||
as possible to the original.
|
||||
|
||||
One notable change is the option to choose a different ztimer clock.
|
||||
By default, the test will use ZTIMER_USEC, unless ZTIMER_MSEC is compiled in,
|
||||
which will be used in that case.
|
||||
136
tests/ztimer_msg/main.c
Normal file
136
tests/ztimer_msg/main.c
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2015-19 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
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @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 "ztimer.h"
|
||||
#include "thread.h"
|
||||
#include "msg.h"
|
||||
#include "timex.h"
|
||||
|
||||
#ifdef MODULE_ZTIMER_MSEC
|
||||
#define ZTIMER ZTIMER_MSEC
|
||||
#define TICKS_PER_SEC MS_PER_SEC
|
||||
#else
|
||||
#define ZTIMER ZTIMER_USEC
|
||||
#define TICKS_PER_SEC US_PER_SEC
|
||||
#endif
|
||||
|
||||
char timer_stack[THREAD_STACKSIZE_DEFAULT];
|
||||
char timer_stack_local[THREAD_STACKSIZE_DEFAULT];
|
||||
|
||||
struct timer_msg {
|
||||
ztimer_t timer;
|
||||
uint32_t interval;
|
||||
char *text;
|
||||
msg_t msg;
|
||||
};
|
||||
|
||||
struct timer_msg msg_a = { .interval = (2 * TICKS_PER_SEC),
|
||||
.text = "Hello World" };
|
||||
struct timer_msg msg_b = { .interval = (5 * TICKS_PER_SEC),
|
||||
.text = "This is a Test" };
|
||||
|
||||
void *timer_thread(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
|
||||
printf("This is thread %" PRIkernel_pid "\n", thread_getpid());
|
||||
|
||||
/* 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);
|
||||
|
||||
while (1) {
|
||||
msg_t m;
|
||||
msg_receive(&m);
|
||||
struct timer_msg *tmsg = m.content.ptr;
|
||||
uint32_t now = ztimer_now(ZTIMER);
|
||||
printf("now=%" PRIu32 ":%" PRIu32 " -> every %" PRIu32 ".%" PRIu32 "s: %s\n",
|
||||
(now / TICKS_PER_SEC),
|
||||
(now % TICKS_PER_SEC),
|
||||
tmsg->interval / TICKS_PER_SEC,
|
||||
tmsg->interval % TICKS_PER_SEC,
|
||||
tmsg->text);
|
||||
|
||||
tmsg->msg.type = 12345;
|
||||
tmsg->msg.content.ptr = tmsg;
|
||||
ztimer_set_msg(ZTIMER, &tmsg->timer, tmsg->interval, &tmsg->msg, thread_getpid());
|
||||
}
|
||||
}
|
||||
|
||||
void *timer_thread_local(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
|
||||
printf("This is thread %" PRIkernel_pid "\n", thread_getpid());
|
||||
|
||||
while (1) {
|
||||
msg_t m;
|
||||
msg_receive(&m);
|
||||
|
||||
uint32_t now = ztimer_now(ZTIMER);
|
||||
int sec = now / TICKS_PER_SEC;
|
||||
int min = sec / 60;
|
||||
int hr = sec / 3600;
|
||||
printf("sec=%d min=%d hour=%d\n", sec, min, hr);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
msg_t m;
|
||||
kernel_pid_t pid = thread_create(
|
||||
timer_stack,
|
||||
sizeof(timer_stack),
|
||||
THREAD_PRIORITY_MAIN - 1,
|
||||
THREAD_CREATE_STACKTEST,
|
||||
timer_thread,
|
||||
NULL,
|
||||
"timer");
|
||||
|
||||
puts("sending 1st msg");
|
||||
m.content.ptr = &msg_a;
|
||||
msg_try_send(&m, pid);
|
||||
|
||||
puts("sending 2nd msg");
|
||||
m.content.ptr = &msg_b;
|
||||
msg_try_send(&m, pid);
|
||||
|
||||
kernel_pid_t pid2 = thread_create(
|
||||
timer_stack_local,
|
||||
sizeof(timer_stack_local),
|
||||
THREAD_PRIORITY_MAIN - 1,
|
||||
THREAD_CREATE_STACKTEST,
|
||||
timer_thread_local,
|
||||
NULL,
|
||||
"timer local");
|
||||
|
||||
while (1) {
|
||||
ztimer_sleep(ZTIMER, 1 * TICKS_PER_SEC);
|
||||
msg_try_send(&m, pid2);
|
||||
}
|
||||
}
|
||||
30
tests/ztimer_msg/tests/01-run.py
Executable file
30
tests/ztimer_msg/tests/01-run.py
Executable file
@ -0,0 +1,30 @@
|
||||
#!/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 sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
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.exit(run(testfunc))
|
||||
6
tests/ztimer_overhead/Makefile
Normal file
6
tests/ztimer_overhead/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
DEVELHELP ?= 0
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += ztimer_overhead ztimer_usec
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
7
tests/ztimer_overhead/README.md
Normal file
7
tests/ztimer_overhead/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Introduction
|
||||
|
||||
This test application sets up a ztimer_periph at 1MHz, then measures 1024
|
||||
times how much overhead ztimer adds.
|
||||
|
||||
It uses the "ztimer_overhead()" function. See it's documentation for more
|
||||
information.
|
||||
56
tests/ztimer_overhead/main.c
Normal file
56
tests/ztimer_overhead/main.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup test
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief ztimer overhead test application
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "ztimer.h"
|
||||
#include "ztimer/overhead.h"
|
||||
|
||||
#define BASE 1000
|
||||
#define SAMPLES 1024
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t total = 0;
|
||||
|
||||
uint16_t min = 0xFFFF;
|
||||
uint16_t max = 0;
|
||||
|
||||
/* unset configured adjustment */
|
||||
/* ZTIMER_USEC->adjust = 0; */
|
||||
|
||||
unsigned n = SAMPLES;
|
||||
while (n--) {
|
||||
unsigned overhead = ztimer_overhead(ZTIMER_USEC, BASE);
|
||||
total += overhead;
|
||||
if (overhead < min) {
|
||||
min = overhead;
|
||||
}
|
||||
else if (overhead > max) {
|
||||
max = overhead;
|
||||
}
|
||||
}
|
||||
|
||||
printf("min=%u max=%u avg=%" PRIu32 "\n", min, max, (total / SAMPLES));
|
||||
|
||||
return 0;
|
||||
}
|
||||
18
tests/ztimer_overhead/tests/01-run.py
Executable file
18
tests/ztimer_overhead/tests/01-run.py
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
#
|
||||
# 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 sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"min=\d+ max=\d+ avg=\d+\r\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
||||
Loading…
x
Reference in New Issue
Block a user