Skip to content

Commit

Permalink
tests/ztimer_xsec: add a simple high level ztimer test
Browse files Browse the repository at this point in the history
  • Loading branch information
kfessel committed Mar 30, 2021
1 parent f29057b commit df16d6f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/ztimer_xsec/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include ../Makefile.tests_common

USEMODULE += ztimer
USEMODULE += ztimer_usec
USEMODULE += ztimer_msec
USEMODULE += ztimer_sec

include $(RIOTBASE)/Makefile.include
9 changes: 9 additions & 0 deletions tests/ztimer_xsec/Makefile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-leonardo \
arduino-nano \
arduino-uno \
atmega328p \
nucleo-f031k6 \
stm32f030f4-demo \
#
10 changes: 10 additions & 0 deletions tests/ztimer_xsec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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 of described
in the ztimer documentation with LOG_LEVEL LOG_INFO some timing information
for human analysis is provided
7 changes: 7 additions & 0 deletions tests/ztimer_xsec/app.config.test
Original file line number Diff line number Diff line change
@@ -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
83 changes: 83 additions & 0 deletions tests/ztimer_xsec/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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"

#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_WARNING
#endif

#include "log.h"

typedef struct named_lock {
char *name;
mutex_t mut;
} named_lock_t;

void release(void *arg);

static named_lock_t sec_lock = { .name = "SEC", .mut = MUTEX_INIT };
static named_lock_t msec_lock = { .name = "MSEC", .mut = MUTEX_INIT };
static named_lock_t usec_lock = { .name = "USEC", .mut = MUTEX_INIT };

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;

LOG_INFO("time: %" PRIu32 "\n", ztimer_now(ZTIMER_USEC));

printf("unlocking %s\n", e->name);
mutex_unlock(&e->mut);
}

int main(void)
{
/*prelock*/
mutex_lock( &sec_lock.mut);
mutex_lock(&msec_lock.mut);
mutex_lock(&usec_lock.mut);

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, 100000);

LOG_INFO("time: %" PRIu32 "\n", 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("SUCCESS!\n");
return 0;
}
23 changes: 23 additions & 0 deletions tests/ztimer_xsec/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -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("unlocking USEC")
child.expect_exact("unlocking MSEC")
child.expect_exact("unlocking SEC")
child.expect_exact("SUCCESS!")


if __name__ == "__main__":
sys.exit(run(testfunc))

0 comments on commit df16d6f

Please sign in to comment.