diff mbox series

[7/7] test/py: add tests for the button commands

Message ID 1594644972-2588-7-git-send-email-philippe.reynes@softathome.com
State Accepted
Commit a6c6f0f0c8880b2f3d04784eef49f85b78d0f29e
Headers show
Series [1/7] dm: button: add an uclass for button | expand

Commit Message

Philippe REYNES July 13, 2020, 12:56 p.m. UTC
Adds tests for the button commands.

Signed-off-by: Philippe Reynes <philippe.reynes at softathome.com>
---
 arch/sandbox/dts/test.dts    | 14 ++++++++++++++
 test/py/tests/test_button.py | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 test/py/tests/test_button.py

Comments

Simon Glass July 15, 2020, 1:05 a.m. UTC | #1
Hi Philippe,

On Mon, 13 Jul 2020 at 06:56, Philippe Reynes
<philippe.reynes at softathome.com> wrote:
>
> Adds tests for the button commands.
>
> Signed-off-by: Philippe Reynes <philippe.reynes at softathome.com>
> ---
>  arch/sandbox/dts/test.dts    | 14 ++++++++++++++
>  test/py/tests/test_button.py | 19 +++++++++++++++++++
>  2 files changed, 33 insertions(+)
>  create mode 100644 test/py/tests/test_button.py

Reviewed-by: Simon Glass <sjg at chromium.org>

But please also add a test/dm/button.c test that tests the uclass and
sandbox device.

Regards,
Simon
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 5ce5e28..101d729 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -51,6 +51,20 @@ 
 		#sound-dai-cells = <1>;
 	};
 
+	buttons {
+		compatible = "button-gpio";
+
+		summer {
+			gpios = <&gpio_a 3 0>;
+			label = "summer";
+		};
+
+		christmas {
+			gpios = <&gpio_a 4 0>;
+			label = "christmas";
+		};
+	};
+
 	cros_ec: cros-ec {
 		reg = <0 0>;
 		compatible = "google,cros-ec-sandbox";
diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py
new file mode 100644
index 0000000..98067a9
--- /dev/null
+++ b/test/py/tests/test_button.py
@@ -0,0 +1,19 @@ 
+# SPDX-License-Identifier: GPL-2.0+
+
+import pytest
+
+ at pytest.mark.boardspec('sandbox')
+ at 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."""
+
+    expected_response = 'rc:0'
+    response = u_boot_console.run_command('button list; echo rc:$?')
+    assert(expected_response in response)
+    response = u_boot_console.run_command('button summer; echo rc:$?')
+    assert(expected_response in response)
+
+    expected_response = 'rc:1'
+    response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
+    assert(expected_response in response)