test_sleep.py 698 B

123456789101112131415161718192021
  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. # 3s isn't too long, but is enough to cross a few second boundaries.
  10. sleep_time = 3
  11. tstart = time.time()
  12. u_boot_console.run_command('sleep %d' % sleep_time)
  13. tend = time.time()
  14. elapsed = tend - tstart
  15. assert elapsed >= sleep_time
  16. if not u_boot_console.config.gdbserver:
  17. # 0.25s margin is hopefully enough to account for any system overhead.
  18. assert elapsed < (sleep_time + 0.25)