tests: Improve test hardware configuration by putting board-specific settings in target_wiring
module
#17954
+166
−164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
There are currently a few "hardware" tests that need external board connections to be made for them to work, eg bridging a pair of pins. Eg all tests in
tests/extmod_hardware
need some kind of connection.Along with the physical connections -- which are different for each board -- there needs to be corresponding Python settings, eg which UART instance to use and which pins for TX/RX.
These settings are currently hard-coded in each test file. That has a few problems:
tests/extmod_hardware/machine_pwm.py
)This PR aims to solve all the above problems by splitting the board-specific settings out into separate files, one for each board (or port). They are placed in the
tests/target_wiring/
directory. Therun-tests.py
test runner then loads the appropriate configuration for the target that is being tested, sends it to the board so it's available asimport target_wiring
(without needing a filesystem), and then executes the test (only tests that needtarget_wiring
have it loaded).This PR adds support for this
target_wiring
module, and converts all the existingmachine.UART
tests to use it.Testing
Tested locally on PYBV10 and ESP32-S2. Still needs further testing once we decide this is the way forward.
Trade-offs and Alternatives
Although the idea is straightforward, there were many decisions to make in the implementation:
target_wiring
module follows a hierarchy: if an exact match for the board name is found (viasys.implementation._build
) then that's used, otherwise there's a possible wildcard match on the board name (eg for PYB* boards, they can all use the same config), otherwise there's a match on the port name (eg rp2 boards can all use the same config). This allows a lot of flexibility (maybe too much?).target_wiring
module to the board without using the filesystem or VFS hook. It just evaluates a new class calledtarget_wiring
with the body of the class the script with the settings. This should be pretty minimal and work on targets without a filesystem/VFS.extmod/machine_uart*.py
tests ... they are not strictly hardware tests (they don't require external connections) but they do need to know which UART instance to use, and they can reuse the same instance used byextmod_hardware/machine_uart*.py
tests. Hopefully this won't be an issue, but it does confuse somewhat which tests requiretarget_wiring
configuration and which don't (ie it's no longer as simple as saying that onlyextmod_hardware/
tests needtarget_wiring
).uart_loopback_args
anduart_loopback_kwargs
. This shows the general problem that the approach may not scale well if lots of tests need subtly different configurations, egI2CTarget
will need a loopback configuration (4 pins) and a non-loopback configuration (another 2 pins). To make it work, the config for these either need to be named differently, or selected very carefully so the pins can overlap.extmod_hardware/machine_pwm.py
can reuse the UART loopback pins, but probably they should be named differently, in case they can't be reused.run-tests.py
for zephyr, or exposesys.implementation._build
on that port).target_wiring
module (without usingrun-tests.py
) requires the user to explicitly copy across the correcttarget_wiring.py
file to their device.target_wiring.py
on the device then it is overridden by the one injected byrun-tests.py
. I think this is desired behaviour, so you don't have a stale/old file on there that messes up the test.run-tests.py
for the user to select/override whichtarget_wiring.py
module to use, eg for custom boards, eg for Octoprobe.