zephyr/tests/kernel/timer/timer_behavior/pytest/conftest.py
Ederson de Souza 22ba9456de tests/kernel/timer/timer_behavior: Add support for external tool
This patch adds a way to simplify using an external tool to measure
timer behaviour on Zephyr. It modifies the timer behaviour
jitter_drift.c tests to toggle a GPIO pin (defined via a new DTS
compatible, "test-kernel-timer-behavior-external") that can be connected
to an external tool, such as a logic analyzer, to measure timer
behaviour.

This GPIO pin toggle is behind a new CONFIG_TIMER_EXTERNAL_TEST Kconfig.

A new pytest test is added so that it can collect the statistics from
the external tool and assert some measurements. To collect statistics
from the external tool, one needs to provide a Python module which
provides a `run(seconds, config)` method, that will perform the test and
return the statistics. Check the README file for more information about
this interface.

Finally, this on twister, this new test is behind a new fixture,
"gpio-timerout".

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-09-27 20:25:09 -04:00

42 lines
1.1 KiB
Python

# Copyright (c) 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
import pytest
from pathlib import Path
def pytest_addoption(parser):
parser.addoption('--tool')
parser.addoption('--tool-options')
parser.addoption('--sys-clock-hw-cycles-per-sec', default=None)
@pytest.fixture()
def tool(request):
return request.config.getoption('--tool')
@pytest.fixture()
def tool_options(request):
return request.config.getoption('--tool-options')
@pytest.fixture()
def config(request):
build_dir = Path(request.config.getoption('--build-dir'))
file_name = build_dir / 'zephyr' / '.config'
cfgs = {}
with open(file_name) as fp:
for line in fp:
if line.startswith('CONFIG_'):
k, v = line.split('=', maxsplit=1)
cfgs[k[7:]] = v
return cfgs
@pytest.fixture()
def sys_clock_hw_cycles_per_sec(request, config):
if request.config.getoption('--sys-clock-hw-cycles-per-sec'):
return int(request.config.getoption('--sys-clock-hw-cycles-per-sec'))
return int(config['SYS_CLOCK_HW_CYCLES_PER_SEC'])