[U-Boot] [PATCH V4 5/8] test/py: add test of basic shell functionality
Stephen Warren
swarren at wwwdotorg.org
Fri Jan 15 19:15:28 CET 2016
From: Stephen Warren <swarren at 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 at nvidia.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
v4:
- No changes.
v3:
- Move test scripts into a sub-directory.
Suggested by Michal Simek.
- s/uboot/u[-_]boot/g. Suggested by Simon Glass.
- s/"/'/g. Suggested by Simon Glass.
- Add more documentation. Suggested by Simon Glass.
- Move relevant edits to command_ut.c into this patch from a later one.
Suggested by Simon Glass.
---
test/command_ut.c | 16 ---------------
test/py/tests/test_shell_basics.py | 42 ++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 16 deletions(-)
create mode 100644 test/py/tests/test_shell_basics.py
diff --git a/test/command_ut.c b/test/command_ut.c
index c086abe3ed3e..43bd2c1771fe 100644
--- a/test/command_ut.c
+++ b/test/command_ut.c
@@ -27,10 +27,6 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
run_command("setenv check", 0);
#endif
- /* commands separated by ; */
- run_command_list("setenv list 1; setenv list ${list}1", -1, 0);
- assert(!strcmp("11", getenv("list")));
-
/* commands separated by \n */
run_command_list("setenv list 1\n setenv list ${list}1", -1, 0);
assert(!strcmp("11", getenv("list")));
@@ -39,11 +35,6 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
run_command_list("setenv list 1${list}\n", -1, 0);
assert(!strcmp("111", getenv("list")));
- /* three commands in a row */
- run_command_list("setenv list 1\n setenv list ${list}2; "
- "setenv list ${list}3", -1, 0);
- assert(!strcmp("123", getenv("list")));
-
/* a command string with \0 in it. Stuff after \0 should be ignored */
run_command("setenv list", 0);
run_command_list(test_cmd, sizeof(test_cmd), 0);
@@ -62,13 +53,6 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
assert(run_command_list("false", -1, 0) == 1);
assert(run_command_list("echo", -1, 0) == 0);
- run_command("setenv foo 'setenv monty 1; setenv python 2'", 0);
- run_command("run foo", 0);
- assert(getenv("monty") != NULL);
- assert(!strcmp("1", getenv("monty")));
- assert(getenv("python") != NULL);
- assert(!strcmp("2", getenv("python")));
-
#ifdef CONFIG_SYS_HUSH_PARSER
run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
run_command("run foo", 0);
diff --git a/test/py/tests/test_shell_basics.py b/test/py/tests/test_shell_basics.py
new file mode 100644
index 000000000000..719ce611d71c
--- /dev/null
+++ b/test/py/tests/test_shell_basics.py
@@ -0,0 +1,42 @@
+# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0
+
+# Test basic shell functionality, such as commands separate by semi-colons.
+
+def test_shell_execute(u_boot_console):
+ '''Test any shell command.'''
+
+ response = u_boot_console.run_command('echo hello')
+ assert response.strip() == 'hello'
+
+def test_shell_semicolon_two(u_boot_console):
+ '''Test two shell commands separate by a semi-colon.'''
+
+ cmd = 'echo hello; echo world'
+ response = u_boot_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(u_boot_console):
+ '''Test three shell commands separate by a semi-colon, with variable
+ expansion dependencies between them.'''
+
+ cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
+ 'echo ${list}'
+ response = u_boot_console.run_command(cmd)
+ assert response.strip() == '123'
+ u_boot_console.run_command('setenv list')
+
+def test_shell_run(u_boot_console):
+ '''Test the "run" shell command.'''
+
+ u_boot_console.run_command('setenv foo \"setenv monty 1; setenv python 2\"')
+ u_boot_console.run_command('run foo')
+ response = u_boot_console.run_command('echo $monty')
+ assert response.strip() == '1'
+ response = u_boot_console.run_command('echo $python')
+ assert response.strip() == '2'
+ u_boot_console.run_command('setenv foo')
+ u_boot_console.run_command('setenv monty')
+ u_boot_console.run_command('setenv python')
--
2.7.0
More information about the U-Boot
mailing list