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 | |
Michal Simek | e710ab7 | 2017-05-15 14:29:02 +0200 | [diff] [blame] | 7 | import pytest |
| 8 | |
| 9 | pytestmark = pytest.mark.buildconfigspec('cmd_echo') |
| 10 | |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 11 | def test_shell_execute(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 12 | """Test any shell command.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 13 | |
| 14 | response = u_boot_console.run_command('echo hello') |
| 15 | assert response.strip() == 'hello' |
| 16 | |
| 17 | def test_shell_semicolon_two(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 18 | """Test two shell commands separate by a semi-colon.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 19 | |
| 20 | cmd = 'echo hello; echo world' |
| 21 | response = u_boot_console.run_command(cmd) |
| 22 | # This validation method ignores the exact whitespace between the strings |
| 23 | assert response.index('hello') < response.index('world') |
| 24 | |
| 25 | def test_shell_semicolon_three(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 26 | """Test three shell commands separate by a semi-colon, with variable |
| 27 | expansion dependencies between them.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 28 | |
| 29 | cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \ |
| 30 | 'echo ${list}' |
| 31 | response = u_boot_console.run_command(cmd) |
| 32 | assert response.strip() == '123' |
| 33 | u_boot_console.run_command('setenv list') |
| 34 | |
| 35 | def test_shell_run(u_boot_console): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 36 | """Test the "run" shell command.""" |
Stephen Warren | 9367d4d | 2016-01-15 11:15:28 -0700 | [diff] [blame] | 37 | |
Stephen Warren | 3deb896 | 2016-01-26 13:41:31 -0700 | [diff] [blame] | 38 | 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] | 39 | u_boot_console.run_command('run foo') |
| 40 | response = u_boot_console.run_command('echo $monty') |
| 41 | assert response.strip() == '1' |
| 42 | response = u_boot_console.run_command('echo $python') |
| 43 | assert response.strip() == '2' |
| 44 | u_boot_console.run_command('setenv foo') |
| 45 | u_boot_console.run_command('setenv monty') |
| 46 | u_boot_console.run_command('setenv python') |