tests/xtimer_overhead: initial commit
This commit is contained in:
parent
698f313f6f
commit
34e03a0c7f
6
tests/xtimer_overhead/Makefile
Normal file
6
tests/xtimer_overhead/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
DEVELHELP ?= 0
|
||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
USEMODULE += xtimer
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
3
tests/xtimer_overhead/README.md
Normal file
3
tests/xtimer_overhead/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Introduction
|
||||||
|
|
||||||
|
This test application measures 1024 times how much overhead xtimer adds.
|
||||||
58
tests/xtimer_overhead/main.c
Normal file
58
tests/xtimer_overhead/main.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
* 2020 Freie Universität Berlin
|
||||||
|
* 2020 Inria
|
||||||
|
*
|
||||||
|
* 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 test
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief xtimer overhead test application
|
||||||
|
*
|
||||||
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "xtimer.h"
|
||||||
|
|
||||||
|
#define BASE 1000
|
||||||
|
#define SAMPLES 1024
|
||||||
|
|
||||||
|
int32_t xtimer_overhead(uint32_t base);
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
uint32_t total = 0;
|
||||||
|
|
||||||
|
int32_t min = INT32_MAX;
|
||||||
|
int32_t max = INT32_MIN;
|
||||||
|
|
||||||
|
unsigned n = SAMPLES;
|
||||||
|
while (n--) {
|
||||||
|
int32_t overhead = xtimer_overhead(BASE);
|
||||||
|
total += labs(overhead);
|
||||||
|
if (overhead < min) {
|
||||||
|
min = overhead;
|
||||||
|
}
|
||||||
|
else if (overhead > max) {
|
||||||
|
max = overhead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("min=%" PRIi32 " max=%" PRIi32 " avg_diff=%" PRIi32 "\n", min, max,
|
||||||
|
(total / SAMPLES));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
48
tests/xtimer_overhead/overhead.c
Normal file
48
tests/xtimer_overhead/overhead.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
* 2020 Freie Universität Berlin
|
||||||
|
* 2020 Inria
|
||||||
|
*
|
||||||
|
* 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 sys_xtimer_overhead
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief xtimer overhead measurement functions
|
||||||
|
*
|
||||||
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "xtimer.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
volatile uint32_t *val;
|
||||||
|
} callback_arg_t;
|
||||||
|
|
||||||
|
static void _callback(void *arg)
|
||||||
|
{
|
||||||
|
callback_arg_t *callback_arg = (callback_arg_t *)arg;
|
||||||
|
|
||||||
|
*callback_arg->val = xtimer_now_usec();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t xtimer_overhead(uint32_t base)
|
||||||
|
{
|
||||||
|
volatile uint32_t after = 0;
|
||||||
|
uint32_t pre;
|
||||||
|
|
||||||
|
callback_arg_t arg = { .val = &after };
|
||||||
|
xtimer_t t = { .callback = _callback, .arg = &arg };
|
||||||
|
|
||||||
|
pre = xtimer_now_usec();
|
||||||
|
xtimer_set(&t, base);
|
||||||
|
while (!after) {}
|
||||||
|
return after - pre - base;
|
||||||
|
}
|
||||||
18
tests/xtimer_overhead/tests/01-run.py
Executable file
18
tests/xtimer_overhead/tests/01-run.py
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
#
|
||||||
|
# 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(r"min=-?\d+ max=-?\d+ avg_diff=\d+\r\n")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(run(testfunc))
|
||||||
Loading…
x
Reference in New Issue
Block a user