test_sleep.py 826 B

1234567891011121314151617181920212223
  1. # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  2. #
  3. # SPDX-License-Identifier: GPL-2.0
  4. import pytest
  5. import time
  6. def test_sleep(u_boot_console):
  7. """Test the sleep command, and validate that it sleeps for approximately
  8. the correct amount of time."""
  9. if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
  10. pytest.skip('sleep command not supported')
  11. # 3s isn't too long, but is enough to cross a few second boundaries.
  12. sleep_time = 3
  13. tstart = time.time()
  14. u_boot_console.run_command('sleep %d' % sleep_time)
  15. tend = time.time()
  16. elapsed = tend - tstart
  17. assert elapsed >= sleep_time
  18. if not u_boot_console.config.gdbserver:
  19. # 0.25s margin is hopefully enough to account for any system overhead.
  20. assert elapsed < (sleep_time + 0.25)