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

tests/xtimer_now_irq/: New test for xtimer_now() with irq_disable()

This test checks, if the timer returns the correct time (xtimer_now_usec() is called), when interrupts are disabled. Specifically tested is if the time is correct after a low-level timer overflow.
This commit is contained in:
JulianHolzwarth 2020-01-03 17:55:31 +01:00
parent 99e8b04921
commit 921d9cf633
4 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,7 @@
include ../Makefile.tests_common
USEMODULE += xtimer
TEST_ON_CI_BLACKLIST += all
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,8 @@
# README for xtimer_now_irq test
This test checks, if the timer returns the correct time (xtimer_now_usec() is called), when interrupts are disabled. Specifically tested is if the time is correct after a low-level timer overflow.
When the returned value is incorrect the test will print: "ERROR: wrong time with interrupts disabled".
This test must be run over at least one full timer period. Meaning the test only finishes in reasonable short time on platforms with small timers up to 24 bit.
This test does not work for 32 bit timers.

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2020 Freie Universität Berlin,
*
* 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 testing xtimer_now_usec function with irq disabled
*
*
* @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
*
*/
#include <stdio.h>
#include "xtimer.h"
#include "irq.h"
#define TEST_COUNT 4
int main(void)
{
puts("xtimer_now_irq test application.\n");
uint8_t count = TEST_COUNT;
while (count) {
unsigned int state = irq_disable();
uint32_t t1 = xtimer_now_usec();
xtimer_spin(xtimer_ticks((uint32_t)(~XTIMER_MASK) / 2));
uint32_t t2 = xtimer_now_usec();
irq_restore(state);
if (t2 < t1) {
puts("ERROR: wrong time with interrupts disabled");
return -1;
}
puts("OK");
count --;
}
puts("SUCCESS");
return 0;
}

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
# Copyright (C) 2020 Freie Universität Berlin,
#
# 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 Julian Holzwarth <julian.holzwarth@fu-berlin.de>
import sys
from testrunner import run
TIMEOUT = 20
def testfunc(child):
for _ in range(4):
child.expect_exact("OK", timeout=TIMEOUT)
child.expect_exact("SUCCESS")
if __name__ == "__main__":
sys.exit(run(testfunc))