1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/ztimer_xsec: add a simple high level ztimer test

This commit is contained in:
Karl Fessel 2021-03-30 13:55:13 +02:00
parent c9e17196de
commit febfa5bc62
6 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,8 @@
include ../Makefile.tests_common
USEMODULE += ztimer
USEMODULE += ztimer_usec
USEMODULE += ztimer_msec
USEMODULE += ztimer_sec
include $(RIOTBASE)/Makefile.include

View File

@ -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 \
#

View File

@ -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.

View File

@ -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

77
tests/ztimer_xsec/main.c Normal file
View File

@ -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 <karl.fessel@ovgu.de>
*
*
* @}
*/
#include <stdio.h>
#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;
}

View File

@ -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))