xref: /rk3399_rockchip-uboot/test/py/tests/test_shell_basics.py (revision 6b83c38d7a195f0e93cd6ff069a69105cb59a091)
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
7*6b83c38dSMichal Simekimport pytest
8*6b83c38dSMichal Simek
9*6b83c38dSMichal Simekpytestmark = pytest.mark.buildconfigspec('cmd_echo')
10*6b83c38dSMichal Simek
118b86c609SStephen Warrendef test_shell_execute(u_boot_console):
12e8debf39SStephen Warren    """Test any shell command."""
138b86c609SStephen Warren
148b86c609SStephen Warren    response = u_boot_console.run_command('echo hello')
158b86c609SStephen Warren    assert response.strip() == 'hello'
168b86c609SStephen Warren
178b86c609SStephen Warrendef test_shell_semicolon_two(u_boot_console):
18e8debf39SStephen Warren    """Test two shell commands separate by a semi-colon."""
198b86c609SStephen Warren
208b86c609SStephen Warren    cmd = 'echo hello; echo world'
218b86c609SStephen Warren    response = u_boot_console.run_command(cmd)
228b86c609SStephen Warren    # This validation method ignores the exact whitespace between the strings
238b86c609SStephen Warren    assert response.index('hello') < response.index('world')
248b86c609SStephen Warren
258b86c609SStephen Warrendef test_shell_semicolon_three(u_boot_console):
26e8debf39SStephen Warren    """Test three shell commands separate by a semi-colon, with variable
27e8debf39SStephen Warren    expansion dependencies between them."""
288b86c609SStephen Warren
298b86c609SStephen Warren    cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
308b86c609SStephen Warren        'echo ${list}'
318b86c609SStephen Warren    response = u_boot_console.run_command(cmd)
328b86c609SStephen Warren    assert response.strip() == '123'
338b86c609SStephen Warren    u_boot_console.run_command('setenv list')
348b86c609SStephen Warren
358b86c609SStephen Warrendef test_shell_run(u_boot_console):
36e8debf39SStephen Warren    """Test the "run" shell command."""
378b86c609SStephen Warren
38a2ec5606SStephen Warren    u_boot_console.run_command('setenv foo "setenv monty 1; setenv python 2"')
398b86c609SStephen Warren    u_boot_console.run_command('run foo')
408b86c609SStephen Warren    response = u_boot_console.run_command('echo $monty')
418b86c609SStephen Warren    assert response.strip() == '1'
428b86c609SStephen Warren    response = u_boot_console.run_command('echo $python')
438b86c609SStephen Warren    assert response.strip() == '2'
448b86c609SStephen Warren    u_boot_console.run_command('setenv foo')
458b86c609SStephen Warren    u_boot_console.run_command('setenv monty')
468b86c609SStephen Warren    u_boot_console.run_command('setenv python')
47