zephyr/tests/kernel/timer/timer_behavior/README
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

72 lines
3.1 KiB
Plaintext

# Test a timer implementations variance and long term drift
Records and calculates statistical values against a timer validating that.
1. Timer variance and standard deviation is below defined acceptable values.
2. Periodic timers do not drift in either direction from expected total time.
Timers are meant to be precise and accurate. This test validates an implementation is both.
--------------------------------------------------------------------------------
External tool testing
It's also possible to use an external tool, such as a logic analyzer, to
collect samples. The "kernel.timer.timer_behavior_external" test will toggle a
GPIO pin on every cycle - first cycle will be a rising edge. This test expects
a Python module to interface with the external tool, which will provide the
necessary statistics that the test will use to assert the test status.
GPIO pin
To enable external tool testing on a board, it must provide the compatible
"test-kernel-timer-behavior-external", with property "timeout-gpios" being the
GPIO pin that will be toggled each period.
External tool interface
In order to get data from the external tool, the test expects a Python module,
named on testcase.yaml, with the following interface:
run(seconds: float, options: str) -> {}
The `seconds` parameter defines for how long the data collection is expected
to run; `options` is a string defined on testcase.yaml with options known to
the external tool helper module. It should return a dictionary with the
following statistics, in seconds:
'mean': Mean time of each period
'stddev': Standard deviation from the mean time
'var': Variance from the mean time
'min': Minimum period registered
'max': Maximum period registered
'total_time': Total time, between first and last period.
Note that the collection may need to go a bit after the "seconds" parameter,
to account for expected drift in the test and between the DUT and the external
tool.
Twister
For Twister execute the external tool testing, the fixture "gpio_timerout"
must be available on the device. Also, testcase.yaml
"harness_config/pytest_args" from "kernel.timer.timer_behavior_external" must
have parameters "tool", with the name of a loadable Python module and
"tool-options", a string with options passed to the Python module helper.
Configuration options
At its heart, the external testing is actually comparing two clocks: one on
the board under test and one at the external tool (Zephyr implementation of
the timer also plays a role, and it's the real target of the test, but it
depends on the board's clock). Different clocks run at different speeds, so
they tend to drift. To be able to account for this drift, the external test
doesn't reuse CONFIG_TIMER_TEST_MAX_DRIFT and
CONFIG_TIMER_TEST_PERIOD_MAX_DRIFT_PERCENT, instead introducing
CONFIG_TIMER_EXTERNAL_TEST_MAX_DRIFT_PPM and
CONFIG_TIMER_EXTERNAL_TEST_PERIOD_MAX_DRIFT_PPM, that can be more finely tuned
for the hardware in question.
Also, CONFIG_TIMER_EXTERNAL_TEST_SYNC_DELAY is used to set a delay before a
test cycle starts, so that the external tool can be set up.