1# 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
7import pytest
8
9pytestmark = pytest.mark.buildconfigspec('cmd_echo')
10
11def test_shell_execute(u_boot_console):
12    """Test any shell command."""
13
14    response = u_boot_console.run_command('echo hello')
15    assert response.strip() == 'hello'
16
17def test_shell_semicolon_two(u_boot_console):
18    """Test two shell commands separate by a semi-colon."""
19
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):
26    """Test three shell commands separate by a semi-colon, with variable
27    expansion dependencies between them."""
28
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):
36    """Test the "run" shell command."""
37
38    u_boot_console.run_command('setenv foo "setenv monty 1; setenv python 2"')
39    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')
47