diff mbox

[U-Boot,V2,5/7] test/py: add test of basic shell functionality

Message ID 1449094708-14784-5-git-send-email-swarren@wwwdotorg.org
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Stephen Warren Dec. 2, 2015, 10:18 p.m. UTC
From: Stephen Warren <swarren@nvidia.com>

This tests whether the following features of the U-Boot shell:
- Execution of a directly entered command.
- Compound commands (; delimiter).
- Quoting of arguments containing spaces.
- Executing commands from environment variables.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 test/py/test_shell_basics.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 test/py/test_shell_basics.py

Comments

Simon Glass Dec. 19, 2015, 10:24 p.m. UTC | #1
On 2 December 2015 at 15:18, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> This tests whether the following features of the U-Boot shell:
> - Execution of a directly entered command.
> - Compound commands (; delimiter).
> - Quoting of arguments containing spaces.
> - Executing commands from environment variables.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  test/py/test_shell_basics.py | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>  create mode 100644 test/py/test_shell_basics.py

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

These sorts of tests are very valuable I think.
diff mbox

Patch

diff --git a/test/py/test_shell_basics.py b/test/py/test_shell_basics.py
new file mode 100644
index 000000000000..f47f840432e0
--- /dev/null
+++ b/test/py/test_shell_basics.py
@@ -0,0 +1,35 @@ 
+# Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0
+
+def test_shell_execute(uboot_console):
+    """Test any shell command"""
+    response = uboot_console.run_command("echo hello")
+    assert response.strip() == "hello"
+
+def test_shell_semicolon_two(uboot_console):
+    """Test two shell commands separate by a semi-colon"""
+    cmd = "echo hello; echo world"
+    response = uboot_console.run_command(cmd)
+    # This validation method ignores the exact whitespace between the strings
+    assert response.index("hello") < response.index("world")
+
+def test_shell_semicolon_three(uboot_console):
+    """Test three shell commands separate by a semi-colon"""
+    cmd = "setenv list 1; setenv list ${list}2; setenv list ${list}3; " + \
+        "echo ${list}"
+    response = uboot_console.run_command(cmd)
+    assert response.strip() == "123"
+    uboot_console.run_command("setenv list")
+
+def test_shell_run(uboot_console):
+    """Test the 'run' shell command"""
+    uboot_console.run_command("setenv foo 'setenv monty 1; setenv python 2'")
+    uboot_console.run_command("run foo")
+    response = uboot_console.run_command("echo $monty")
+    assert response.strip() == "1"
+    response = uboot_console.run_command("echo $python")
+    assert response.strip() == "2"
+    uboot_console.run_command("setenv foo")
+    uboot_console.run_command("setenv monty")
+    uboot_console.run_command("setenv python")