xref: /OK3568_Linux_fs/u-boot/test/py/tests/test_shell_basics.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun# Test basic shell functionality, such as commands separate by semi-colons.
6*4882a593Smuzhiyun
7*4882a593Smuzhiyunimport pytest
8*4882a593Smuzhiyun
9*4882a593Smuzhiyunpytestmark = pytest.mark.buildconfigspec('cmd_echo')
10*4882a593Smuzhiyun
11*4882a593Smuzhiyundef test_shell_execute(u_boot_console):
12*4882a593Smuzhiyun    """Test any shell command."""
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun    response = u_boot_console.run_command('echo hello')
15*4882a593Smuzhiyun    assert response.strip() == 'hello'
16*4882a593Smuzhiyun
17*4882a593Smuzhiyundef test_shell_semicolon_two(u_boot_console):
18*4882a593Smuzhiyun    """Test two shell commands separate by a semi-colon."""
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun    cmd = 'echo hello; echo world'
21*4882a593Smuzhiyun    response = u_boot_console.run_command(cmd)
22*4882a593Smuzhiyun    # This validation method ignores the exact whitespace between the strings
23*4882a593Smuzhiyun    assert response.index('hello') < response.index('world')
24*4882a593Smuzhiyun
25*4882a593Smuzhiyundef test_shell_semicolon_three(u_boot_console):
26*4882a593Smuzhiyun    """Test three shell commands separate by a semi-colon, with variable
27*4882a593Smuzhiyun    expansion dependencies between them."""
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun    cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
30*4882a593Smuzhiyun        'echo ${list}'
31*4882a593Smuzhiyun    response = u_boot_console.run_command(cmd)
32*4882a593Smuzhiyun    assert response.strip() == '123'
33*4882a593Smuzhiyun    u_boot_console.run_command('setenv list')
34*4882a593Smuzhiyun
35*4882a593Smuzhiyundef test_shell_run(u_boot_console):
36*4882a593Smuzhiyun    """Test the "run" shell command."""
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun    u_boot_console.run_command('setenv foo "setenv monty 1; setenv python 2"')
39*4882a593Smuzhiyun    u_boot_console.run_command('run foo')
40*4882a593Smuzhiyun    response = u_boot_console.run_command('echo $monty')
41*4882a593Smuzhiyun    assert response.strip() == '1'
42*4882a593Smuzhiyun    response = u_boot_console.run_command('echo $python')
43*4882a593Smuzhiyun    assert response.strip() == '2'
44*4882a593Smuzhiyun    u_boot_console.run_command('setenv foo')
45*4882a593Smuzhiyun    u_boot_console.run_command('setenv monty')
46*4882a593Smuzhiyun    u_boot_console.run_command('setenv python')
47