blob: 64e0571326224ba42322c780974e7281f1ce1367 [file] [log] [blame]
Stephen Warren68188202016-01-15 11:15:31 -07001# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
2#
3# SPDX-License-Identifier: GPL-2.0
4
5import pytest
6import time
7
8def test_sleep(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -07009 """Test the sleep command, and validate that it sleeps for approximately
10 the correct amount of time."""
Stephen Warren68188202016-01-15 11:15:31 -070011
Tom Rini42c62142016-10-14 19:12:31 -040012 if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
13 pytest.skip('sleep command not supported')
Stephen Warren68188202016-01-15 11:15:31 -070014 # 3s isn't too long, but is enough to cross a few second boundaries.
15 sleep_time = 3
16 tstart = time.time()
17 u_boot_console.run_command('sleep %d' % sleep_time)
18 tend = time.time()
19 elapsed = tend - tstart
Heinrich Schuchardte2ecac22017-10-13 22:28:31 +020020 assert elapsed >= (sleep_time - 0.01)
Stephen Warren33db1ee2016-02-04 16:11:50 -070021 if not u_boot_console.config.gdbserver:
22 # 0.25s margin is hopefully enough to account for any system overhead.
23 assert elapsed < (sleep_time + 0.25)