test_sleep.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  3. import pytest
  4. import time
  5. """
  6. Note: This test doesn't rely on boardenv_* configuration values but they can
  7. change test behavior.
  8. # Setup env__sleep_accurate to False if time is not accurate on your platform
  9. env__sleep_accurate = False
  10. # Setup env__sleep_time time in seconds board is set to sleep
  11. env__sleep_time = 3
  12. # Setup env__sleep_margin set a margin for any system overhead
  13. env__sleep_margin = 0.25
  14. """
  15. def test_sleep(u_boot_console):
  16. """Test the sleep command, and validate that it sleeps for approximately
  17. the correct amount of time."""
  18. sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True)
  19. if not sleep_skip:
  20. pytest.skip('sleep is not accurate')
  21. if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
  22. pytest.skip('sleep command not supported')
  23. # 3s isn't too long, but is enough to cross a few second boundaries.
  24. sleep_time = u_boot_console.config.env.get('env__sleep_time', 3)
  25. sleep_margin = u_boot_console.config.env.get('env__sleep_margin', 0.25)
  26. tstart = time.time()
  27. u_boot_console.run_command('sleep %d' % sleep_time)
  28. tend = time.time()
  29. elapsed = tend - tstart
  30. assert elapsed >= (sleep_time - 0.01)
  31. if not u_boot_console.config.gdbserver:
  32. # margin is hopefully enough to account for any system overhead.
  33. assert elapsed < (sleep_time + sleep_margin)