blob: 0024d5f7f6194a0267ba4fc04ba124ac556f457c [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
Michal Simeke710ab72017-05-15 14:29:02 +02007import pytest
8
9pytestmark = pytest.mark.buildconfigspec('cmd_echo')
10
Stephen Warren9367d4d2016-01-15 11:15:28 -070011def test_shell_execute(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070012 """Test any shell command."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070013
14 response = u_boot_console.run_command('echo hello')
15 assert response.strip() == 'hello'
16
17def test_shell_semicolon_two(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070018 """Test two shell commands separate by a semi-colon."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070019
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
25def test_shell_semicolon_three(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070026 """Test three shell commands separate by a semi-colon, with variable
27 expansion dependencies between them."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070028
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
35def test_shell_run(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070036 """Test the "run" shell command."""
Stephen Warren9367d4d2016-01-15 11:15:28 -070037
Stephen Warren3deb8962016-01-26 13:41:31 -070038 u_boot_console.run_command('setenv foo "setenv monty 1; setenv python 2"')
Stephen Warren9367d4d2016-01-15 11:15:28 -070039 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')