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