test_sleep.py 658 B

1234567891011121314151617181920
  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. delta_to_expected = abs(elapsed - sleep_time)
  16. # 0.25s margin is hopefully enough to account for any system overhead.
  17. assert delta_to_expected < 0.25