瀏覽代碼

test/py: add tests for the button commands

Adds tests for the button commands.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Philippe Reynes 3 年之前
父節點
當前提交
a6c6f0f0c8
共有 2 個文件被更改,包括 33 次插入0 次删除
  1. 14 0
      arch/sandbox/dts/test.dts
  2. 19 0
      test/py/tests/test_button.py

+ 14 - 0
arch/sandbox/dts/test.dts

@@ -51,6 +51,20 @@
 		#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";

+ 19 - 0
test/py/tests/test_button.py

@@ -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)