u_boot_console_sandbox.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (c) 2015 Stephen Warren
  2. # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
  3. #
  4. # SPDX-License-Identifier: GPL-2.0
  5. # Logic to interact with the sandbox port of U-Boot, running as a sub-process.
  6. import time
  7. from u_boot_spawn import Spawn
  8. from u_boot_console_base import ConsoleBase
  9. class ConsoleSandbox(ConsoleBase):
  10. """Represents a connection to a sandbox U-Boot console, executed as a sub-
  11. process."""
  12. def __init__(self, log, config):
  13. """Initialize a U-Boot console connection.
  14. Args:
  15. log: A multiplexed_log.Logfile instance.
  16. config: A "configuration" object as defined in conftest.py.
  17. Returns:
  18. Nothing.
  19. """
  20. super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
  21. def get_spawn(self):
  22. """Connect to a fresh U-Boot instance.
  23. A new sandbox process is created, so that U-Boot begins running from
  24. scratch.
  25. Args:
  26. None.
  27. Returns:
  28. A u_boot_spawn.Spawn object that is attached to U-Boot.
  29. """
  30. cmd = [
  31. self.config.build_dir + '/u-boot',
  32. '-d',
  33. self.config.build_dir + '/arch/sandbox/dts/test.dtb'
  34. ]
  35. return Spawn(cmd)
  36. def kill(self, sig):
  37. """Send a specific Unix signal to the sandbox process.
  38. Args:
  39. sig: The Unix signal to send to the process.
  40. Returns:
  41. Nothing.
  42. """
  43. self.log.action('kill %d' % sig)
  44. self.p.kill(sig)
  45. def validate_exited(self):
  46. """Determine whether the sandbox process has exited.
  47. If required, this function waits a reasonable time for the process to
  48. exit.
  49. Args:
  50. None.
  51. Returns:
  52. Boolean indicating whether the process has exited.
  53. """
  54. p = self.p
  55. self.p = None
  56. for i in xrange(100):
  57. ret = not p.isalive()
  58. if ret:
  59. break
  60. time.sleep(0.1)
  61. p.close()
  62. return ret