test_shell_basics.py 1.6 KB

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