blob: 32e5f83015d34ef3fe7e37590780d7c094dbfcc8 [file] [log] [blame]
Stephen Warren9367d4d2016-01-15 11:15:28 -07001# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
2#
3# SPDX-License-Identifier: GPL-2.0
4
5# Test basic shell functionality, such as commands separate by semi-colons.
6
7def test_shell_execute(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -07008 """Test any shell command."""
Stephen Warren9367d4d2016-01-15 11:15:28 -07009
10 response = u_boot_console.run_command('echo hello')
11 assert response.strip() == 'hello'
12
13def test_shell_semicolon_two(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070014 """Test two shell commands separate by a semi-colon."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070015
16 cmd = 'echo hello; echo world'
17 response = u_boot_console.run_command(cmd)
18 # This validation method ignores the exact whitespace between the strings
19 assert response.index('hello') < response.index('world')
20
21def test_shell_semicolon_three(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070022 """Test three shell commands separate by a semi-colon, with variable
23 expansion dependencies between them."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070024
25 cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
26 'echo ${list}'
27 response = u_boot_console.run_command(cmd)
28 assert response.strip() == '123'
29 u_boot_console.run_command('setenv list')
30
31def test_shell_run(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070032 """Test the "run" shell command."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070033
34 u_boot_console.run_command('setenv foo \"setenv monty 1; setenv python 2\"')
35 u_boot_console.run_command('run foo')
36 response = u_boot_console.run_command('echo $monty')
37 assert response.strip() == '1'
38 response = u_boot_console.run_command('echo $python')
39 assert response.strip() == '2'
40 u_boot_console.run_command('setenv foo')
41 u_boot_console.run_command('setenv monty')
42 u_boot_console.run_command('setenv python')