public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Philippe REYNES <philippe.reynes@softathome.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 3/3] cmd/button: return button status
Date: Mon, 14 Sep 2020 18:02:22 +0200 (CEST)	[thread overview]
Message-ID: <665652957.1007613.1600099342439.JavaMail.zimbra@softathome.com> (raw)
In-Reply-To: <20200914105056.174287-4-xypron.glpk@gmx.de>


> To make the button command useful in a shell script it should return the
> status of the button:
> 
> * 0 (true) - pressed, on
> * 1 (false) - not pressed, off
> 
> The button command takes only one argument. Correct maxargs.
> 
> Adjust the Python unit test.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Reviewed-by: Philippe Reynes <philippe.reynes@softathome.com>

> ---
> v2:
> adjust Python unit test
> ---
> cmd/button.c | 4 ++--
> test/py/tests/test_button.py | 34 ++++++++++++++++++++++++++--------
> 2 files changed, 28 insertions(+), 10 deletions(-)
> 
> diff --git a/cmd/button.c b/cmd/button.c
> index 84ad1653c7..64c5a8fa04 100644
> --- a/cmd/button.c
> +++ b/cmd/button.c
> @@ -75,11 +75,11 @@ int do_button(struct cmd_tbl *cmdtp, int flag, int argc,
> char *const argv[])
> 
> ret = show_button_state(dev);
> 
> - return 0;
> + return !ret;
> }
> 
> U_BOOT_CMD(
> - button, 4, 1, do_button,
> + button, 2, 1, do_button,
> "manage buttons",
> "<button_label> \tGet button state\n"
> "button list\t\tShow a list of buttons"
> diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py
> index eadd9dd613..3b7f148c8f 100644
> --- a/test/py/tests/test_button.py
> +++ b/test/py/tests/test_button.py
> @@ -4,16 +4,34 @@ import pytest
> 
> @pytest.mark.boardspec('sandbox')
> @pytest.mark.buildconfigspec('cmd_button')
> -def test_button_exit_statuses(u_boot_console):
> - """Test that non-input button commands correctly return the command
> - success/failure status."""
> +def test_button_list(u_boot_console):
> + """Test listing buttons"""
> 
> - expected_response = 'rc:0'
> response = u_boot_console.run_command('button list; echo rc:$?')
> - assert(expected_response in response)
> + assert('button1' in response)
> + assert('button2' in response)
> + assert('rc:0' in response)
> +
> + at pytest.mark.boardspec('sandbox')
> + at pytest.mark.buildconfigspec('cmd_button')
> + at pytest.mark.buildconfigspec('cmd_gpio')
> +def test_button_return_code(u_boot_console):
> + """Test correct reporting of the button status
> +
> + The sandbox gpio driver reports the last output value as input value.
> + We can use this in our test to emulate different input statuses.
> + """
> +
> + u_boot_console.run_command('gpio set a3; gpio input a3');
> + response = u_boot_console.run_command('button button1; echo rc:$?')
> + assert('on' in response)
> + assert('rc:0' in response)
> +
> + u_boot_console.run_command('gpio clear a3; gpio input a3');
> response = u_boot_console.run_command('button button1; echo rc:$?')
> - assert(expected_response in response)
> + assert('off' in response)
> + assert('rc:1' in response)
> 
> - expected_response = 'rc:1'
> response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
> - assert(expected_response in response)
> + assert('not found' in response)
> + assert('rc:1' in response)
> --
> 2.28.0

  reply	other threads:[~2020-09-14 16:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14 10:50 [PATCH v2 0/3] cmd/button: return button status Heinrich Schuchardt
2020-09-14 10:50 ` [PATCH v2 1/3] test: sharpen button label unit test Heinrich Schuchardt
2020-09-14 16:00   ` Philippe REYNES
2020-10-14 17:42   ` Tom Rini
2020-09-14 10:50 ` [PATCH v2 2/3] drivers: gpio: keep output value for input on sandbox Heinrich Schuchardt
2020-09-14 16:01   ` Philippe REYNES
2020-10-14 17:42   ` Tom Rini
2020-09-14 10:50 ` [PATCH v2 3/3] cmd/button: return button status Heinrich Schuchardt
2020-09-14 16:02   ` Philippe REYNES [this message]
2020-10-14 17:42   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=665652957.1007613.1600099342439.JavaMail.zimbra@softathome.com \
    --to=philippe.reynes@softathome.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox