diff --git a/tests/ztimer_xsec/Makefile b/tests/ztimer_xsec/Makefile new file mode 100644 index 0000000000..baa0f6980e --- /dev/null +++ b/tests/ztimer_xsec/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +USEMODULE += ztimer +USEMODULE += ztimer_usec +USEMODULE += ztimer_msec +USEMODULE += ztimer_sec + +include $(RIOTBASE)/Makefile.include diff --git a/tests/ztimer_xsec/Makefile.ci b/tests/ztimer_xsec/Makefile.ci new file mode 100644 index 0000000000..d220123487 --- /dev/null +++ b/tests/ztimer_xsec/Makefile.ci @@ -0,0 +1,11 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-nano \ + arduino-uno \ + atmega328p \ + atmega328p-xplained-mini\ + nucleo-f031k6 \ + nucleo-l011k4 \ + stm32f030f4-demo \ + # diff --git a/tests/ztimer_xsec/README.md b/tests/ztimer_xsec/README.md new file mode 100644 index 0000000000..5887a0242d --- /dev/null +++ b/tests/ztimer_xsec/README.md @@ -0,0 +1,12 @@ +# Introduction + +This application tests the high abstraction level ztimer clocks usec, msec and sec +by locking three mutexes and waiting for them to +be unlocked by ZTIMER_USEC, ZTIMER_MSEC and ZTIMER_SEC +The tests succeeds if the board running the test does not get stuck. + +ZTIMER_MSEC and ZTIMER_SEC will be configured following the rules described +in the ztimer documentation (one may want to use extra ztimer_perih_*). +Timing information is provided for human analysis it is not checked by automatic +testing, since they are system and runtime dependent, there are other tests +that (partially) cover the accuracy of timers. diff --git a/tests/ztimer_xsec/app.config.test b/tests/ztimer_xsec/app.config.test new file mode 100644 index 0000000000..d39df143ba --- /dev/null +++ b/tests/ztimer_xsec/app.config.test @@ -0,0 +1,7 @@ +# this file enables modules defined in Kconfig. Do not use this file for +# application configuration. This is only needed during migration. +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_PERIPH_TIMER=y +CONFIG_MODULE_ZTIMER_USEC=y +CONFIG_MODULE_ZTIMER_MSEC=y +CONFIG_MODULE_ZTIMER_SEC=y diff --git a/tests/ztimer_xsec/main.c b/tests/ztimer_xsec/main.c new file mode 100644 index 0000000000..993edfa344 --- /dev/null +++ b/tests/ztimer_xsec/main.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2021 TUBA Freiberg + * + * 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 high level ztimer test application + * + * @author Karl Fessel + * + * + * @} + */ + +#include + +#include "ztimer.h" +#include "mutex.h" + +/* only header information is used we do not need to use MODULE_TIMEX */ +#include "timex.h" + +typedef struct named_lock { + char *name; + mutex_t mut; + uint32_t release_time; +} named_lock_t; + +void release(void *arg); + +static named_lock_t sec_lock = { .name = "SEC", .mut = MUTEX_INIT_LOCKED }; +static named_lock_t msec_lock = { .name = "MSEC", .mut = MUTEX_INIT_LOCKED }; +static named_lock_t usec_lock = { .name = "USEC", .mut = MUTEX_INIT_LOCKED }; + +static ztimer_t sec_tim = { .callback = release, .arg = &sec_lock }; +static ztimer_t msec_tim = { .callback = release, .arg = &msec_lock }; +static ztimer_t usec_tim = { .callback = release, .arg = &usec_lock }; + +void release(void *arg) +{ + named_lock_t *e = arg; + + e->release_time = (uint32_t)ztimer_now(ZTIMER_USEC); + puts(e->name); + mutex_unlock(&e->mut); +} + +int main(void) +{ + puts("starting ztimers"); + /* start a timer on each high level ztimer*/ + ztimer_set(ZTIMER_SEC, &sec_tim, 1); + ztimer_set(ZTIMER_MSEC, &msec_tim, 200); + ztimer_set(ZTIMER_USEC, &usec_tim, 100 * US_PER_MS); + + printf("time %s:\t%" PRIu32 "\n", "Wait", (uint32_t)ztimer_now(ZTIMER_USEC)); + + puts("waiting for locks"); + /* wait for mutexes */ + mutex_lock(&sec_lock.mut); + mutex_lock(&msec_lock.mut); + mutex_lock(&usec_lock.mut); + + printf("time %s:\t%" PRIu32 "\n", sec_lock.name, sec_lock.release_time); + printf("time %s:\t%" PRIu32 "\n", msec_lock.name, msec_lock.release_time); + printf("time %s:\t%" PRIu32 "\n", usec_lock.name, usec_lock.release_time); + + printf("SUCCESS!\n"); + return 0; +} diff --git a/tests/ztimer_xsec/tests/01-run.py b/tests/ztimer_xsec/tests/01-run.py new file mode 100755 index 0000000000..4d365cec82 --- /dev/null +++ b/tests/ztimer_xsec/tests/01-run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2021 TUBA Freiberg +# +# 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_exact("starting ztimers") + child.expect_exact("waiting for locks") + child.expect_exact("USEC") + child.expect_exact("MSEC") + child.expect_exact("SEC") + child.expect_exact("SUCCESS!") + + +if __name__ == "__main__": + sys.exit(run(testfunc))