Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 1 | # 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 | |
| 7 | def test_shell_execute(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 8 | """Test any shell command.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 9 | |
| 10 | response = u_boot_console.run_command('echo hello') |
| 11 | assert response.strip() == 'hello' |
| 12 | |
| 13 | def test_shell_semicolon_two(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 14 | """Test two shell commands separate by a semi-colon.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 15 | |
| 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 | |
| 21 | def test_shell_semicolon_three(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 22 | """Test three shell commands separate by a semi-colon, with variable |
| 23 | expansion dependencies between them.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 24 | |
| 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 | |
| 31 | def test_shell_run(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 32 | """Test the "run" shell command.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 33 | |
Stephen Warren | 3deb896 | 2016-01-26 13:41:31 -0700 | [diff] [blame] | 34 | u_boot_console.run_command('setenv foo "setenv monty 1; setenv python 2"') |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 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') |