test/py: add tests for the button commands
authorPhilippe Reynes <philippe.reynes@softathome.com>
Fri, 24 Jul 2020 16:19:51 +0000 (18:19 +0200)
committerSimon Glass <sjg@chromium.org>
Wed, 29 Jul 2020 01:30:39 +0000 (19:30 -0600)
Adds tests for the button commands.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
arch/sandbox/dts/test.dts
test/py/tests/test_button.py [new file with mode: 0644]

index 2325ec6..491893a 100644 (file)
                #sound-dai-cells = <1>;
        };
 
+       buttons {
+               compatible = "gpio-keys";
+
+               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 (file)
index 0000000..98067a9
--- /dev/null
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+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."""
+
+    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)