xref: /rk3399_rockchip-uboot/test/py/tests/test_shell_basics.py (revision e8debf394fbba594fcfc267c61f8c6bbca395b06)
18b86c609SStephen Warren# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
28b86c609SStephen Warren#
38b86c609SStephen Warren# SPDX-License-Identifier: GPL-2.0
48b86c609SStephen Warren
58b86c609SStephen Warren# Test basic shell functionality, such as commands separate by semi-colons.
68b86c609SStephen Warren
78b86c609SStephen Warrendef test_shell_execute(u_boot_console):
8*e8debf39SStephen Warren    """Test any shell command."""
98b86c609SStephen Warren
108b86c609SStephen Warren    response = u_boot_console.run_command('echo hello')
118b86c609SStephen Warren    assert response.strip() == 'hello'
128b86c609SStephen Warren
138b86c609SStephen Warrendef test_shell_semicolon_two(u_boot_console):
14*e8debf39SStephen Warren    """Test two shell commands separate by a semi-colon."""
158b86c609SStephen Warren
168b86c609SStephen Warren    cmd = 'echo hello; echo world'
178b86c609SStephen Warren    response = u_boot_console.run_command(cmd)
188b86c609SStephen Warren    # This validation method ignores the exact whitespace between the strings
198b86c609SStephen Warren    assert response.index('hello') < response.index('world')
208b86c609SStephen Warren
218b86c609SStephen Warrendef test_shell_semicolon_three(u_boot_console):
22*e8debf39SStephen Warren    """Test three shell commands separate by a semi-colon, with variable
23*e8debf39SStephen Warren    expansion dependencies between them."""
248b86c609SStephen Warren
258b86c609SStephen Warren    cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
268b86c609SStephen Warren        'echo ${list}'
278b86c609SStephen Warren    response = u_boot_console.run_command(cmd)
288b86c609SStephen Warren    assert response.strip() == '123'
298b86c609SStephen Warren    u_boot_console.run_command('setenv list')
308b86c609SStephen Warren
318b86c609SStephen Warrendef test_shell_run(u_boot_console):
32*e8debf39SStephen Warren    """Test the "run" shell command."""
338b86c609SStephen Warren
348b86c609SStephen Warren    u_boot_console.run_command('setenv foo \"setenv monty 1; setenv python 2\"')
358b86c609SStephen Warren    u_boot_console.run_command('run foo')
368b86c609SStephen Warren    response = u_boot_console.run_command('echo $monty')
378b86c609SStephen Warren    assert response.strip() == '1'
388b86c609SStephen Warren    response = u_boot_console.run_command('echo $python')
398b86c609SStephen Warren    assert response.strip() == '2'
408b86c609SStephen Warren    u_boot_console.run_command('setenv foo')
418b86c609SStephen Warren    u_boot_console.run_command('setenv monty')
428b86c609SStephen Warren    u_boot_console.run_command('setenv python')
43