test_shell_basics.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
  3. # Test basic shell functionality, such as commands separate by semi-colons.
  4. import pytest
  5. pytestmark = pytest.mark.buildconfigspec('cmd_echo')
  6. def test_shell_execute(u_boot_console):
  7. """Test any shell command."""
  8. response = u_boot_console.run_command('echo hello')
  9. assert response.strip() == 'hello'
  10. def test_shell_semicolon_two(u_boot_console):
  11. """Test two shell commands separate by a semi-colon."""
  12. cmd = 'echo hello; echo world'
  13. response = u_boot_console.run_command(cmd)
  14. # This validation method ignores the exact whitespace between the strings
  15. assert response.index('hello') < response.index('world')
  16. def test_shell_semicolon_three(u_boot_console):
  17. """Test three shell commands separate by a semi-colon, with variable
  18. expansion dependencies between them."""
  19. cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
  20. 'echo ${list}'
  21. response = u_boot_console.run_command(cmd)
  22. assert response.strip() == '123'
  23. u_boot_console.run_command('setenv list')
  24. def test_shell_run(u_boot_console):
  25. """Test the "run" shell command."""
  26. u_boot_console.run_command('setenv foo \'setenv monty 1; setenv python 2\'')
  27. u_boot_console.run_command('run foo')
  28. response = u_boot_console.run_command('echo ${monty}')
  29. assert response.strip() == '1'
  30. response = u_boot_console.run_command('echo ${python}')
  31. assert response.strip() == '2'
  32. u_boot_console.run_command('setenv foo')
  33. u_boot_console.run_command('setenv monty')
  34. u_boot_console.run_command('setenv python')