Hi Petr,
On 2026-10-13T16:33:33, Petr Hodina via B4 Relay
<[email protected]> wrote:
> test: button: add test for monitor subcommand
>
> Run 'button monitor 200' on sandbox and check that the output lists
> button1 and button2 and that the command returns 0 after the timeout.
>
> Signed-off-by: Petr Hodina <[email protected]>
>
> test/py/tests/test_button.py | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
> diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py
> @@ -37,3 +37,23 @@ def test_button_return_code(ubman):
> + response = ubman.run_command('button monitor 200; echo rc:$?')
> + assert('Button monitor' in response)
> + assert('button1' in response)
> + assert('button2' in response)
> + assert('rc:0' in response)
This only checks that the labels are printed. It doesn't check the
state shown next to each one, which is the point of the command.
Please can you set the state first with 'gpio set a3; gpio input a3',
as test_button_return_code() does, and check that button1 shows 'on'?
Checking for 'off' after 'gpio clear a3' would also be worthwhile.
Note that button3-5 in test.dts are listed too, so it may be easier to
match the whole line for button1 (label padded to 15 characters, then
the state).
The Ctrl-C path is the main new behaviour in v2/v3 and has no test.
You could run 'button monitor 0' with run_command(...,
wait_for_prompt=False), then call ubman.ctrlc() and check that the
prompt comes back, as test_ums.py does. This would also cover the 'run
forever' case.
Regards,
Simon