Skip to content

Commit

Permalink
tests: add test for sys/delay
Browse files Browse the repository at this point in the history
  • Loading branch information
maribu committed Jun 9, 2023
1 parent b84fc85 commit 2e4c4bc
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/sys/delay/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include ../Makefile.sys_common

LOW_POWER ?= 0

ifeq (1,$(LOW_POWER))
USEMODULE += ztimer_msec
else
USEMODULE += ztimer_usec
endif

USEMODULE += delay_us_spinning

include $(RIOTBASE)/Makefile.include
53 changes: 53 additions & 0 deletions tests/sys/delay/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* 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 Test application for the sys/delay
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/

#include <assert.h>
#include <stdio.h>

#include "delay.h"
#include "irq.h"
#include "led.h"

int main(void)
{
printf(
"Test Application for sys/delay\n"
"==============================\n"
"\n"
);

printf("Delay: 1 s\n");
delay_s(1);
printf("Done\n");
printf("Delay: 100 ms\n");
delay_ms(100);
printf("Done\n");

printf("Now blinking LED with a 100 μs pulse every 100 ms\n");
while (1) {
unsigned state = irq_disable();
LED0_ON;
delay_us_spinning(100);
LED0_OFF;
irq_restore(state);
delay_ms(100);
}
return 0;
}
34 changes: 34 additions & 0 deletions tests/sys/delay/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

# Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg
#
# 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.

# @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>

import sys
import time
from testrunner import run


def testfunc(child):
child.expect("Test Application for sys/delay")
child.expect(r"Delay: (\d+) s")
start = time.time()
expected = int(child.match.group(1))
child.expect("Done")
elapsed = time.time() - start
assert elapsed > expected

child.expect(r"Delay: (\d+) ms")
start = time.time()
expected = int(child.match.group(1))
child.expect("Done")
elapsed = time.time() - start
assert elapsed > expected / 1000


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

0 comments on commit 2e4c4bc

Please sign in to comment.