test_sleep.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. """
  11. def test_sleep(u_boot_console):
  12. """Test the sleep command, and validate that it sleeps for approximately
  13. the correct amount of time."""
  14. sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True)
  15. if not sleep_skip:
  16. pytest.skip('sleep is not accurate')
  17. if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
  18. pytest.skip('sleep command not supported')
  19. # 3s isn't too long, but is enough to cross a few second boundaries.
  20. sleep_time = 3
  21. tstart = time.time()
  22. u_boot_console.run_command('sleep %d' % sleep_time)
  23. tend = time.time()
  24. elapsed = tend - tstart
  25. assert elapsed >= (sleep_time - 0.01)
  26. if not u_boot_console.config.gdbserver:
  27. # 0.25s margin is hopefully enough to account for any system overhead.
  28. assert elapsed < (sleep_time + 0.25)