test_shell_basics.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. def test_shell_execute(u_boot_console):
  6. """Test any shell command."""
  7. response = u_boot_console.run_command('echo hello')
  8. assert response.strip() == 'hello'
  9. def test_shell_semicolon_two(u_boot_console):
  10. """Test two shell commands separate by a semi-colon."""
  11. cmd = 'echo hello; echo world'
  12. response = u_boot_console.run_command(cmd)
  13. # This validation method ignores the exact whitespace between the strings
  14. assert response.index('hello') < response.index('world')
  15. def test_shell_semicolon_three(u_boot_console):
  16. """Test three shell commands separate by a semi-colon, with variable
  17. expansion dependencies between them."""
  18. cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
  19. 'echo ${list}'
  20. response = u_boot_console.run_command(cmd)
  21. assert response.strip() == '123'
  22. u_boot_console.run_command('setenv list')
  23. def test_shell_run(u_boot_console):
  24. """Test the "run" shell command."""
  25. u_boot_console.run_command('setenv foo \"setenv monty 1; setenv python 2\"')
  26. u_boot_console.run_command('run foo')
  27. response = u_boot_console.run_command('echo $monty')
  28. assert response.strip() == '1'
  29. response = u_boot_console.run_command('echo $python')
  30. assert response.strip() == '2'
  31. u_boot_console.run_command('setenv foo')
  32. u_boot_console.run_command('setenv monty')
  33. u_boot_console.run_command('setenv python')