blob: b69edf26ef0761ff434792e147e46aaba7aa6677 [file] [log] [blame]
Stephen Warren1c8b4d52016-01-15 11:15:31 -07001# SPDX-License-Identifier: GPL-2.0
Tom Rini83d290c2018-05-06 17:58:06 -04002# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warren1c8b4d52016-01-15 11:15:31 -07003
4import pytest
5import time
6
Michal Simek040f5f12017-12-08 15:47:18 +01007"""
8Note: This test doesn't rely on boardenv_* configuration values but they can
9change test behavior.
10
11# Setup env__sleep_accurate to False if time is not accurate on your platform
12env__sleep_accurate = False
13
14"""
15
Stephen Warren1c8b4d52016-01-15 11:15:31 -070016def test_sleep(u_boot_console):
Stephen Warrene8debf32016-01-26 13:41:30 -070017 """Test the sleep command, and validate that it sleeps for approximately
18 the correct amount of time."""
Stephen Warren1c8b4d52016-01-15 11:15:31 -070019
Michal Simek040f5f12017-12-08 15:47:18 +010020 sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True)
21 if not sleep_skip:
22 pytest.skip('sleep is not accurate')
23
Tom Rini2b2c6e52016-10-14 19:12:31 -040024 if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
25 pytest.skip('sleep command not supported')
Stephen Warren1c8b4d52016-01-15 11:15:31 -070026 # 3s isn't too long, but is enough to cross a few second boundaries.
27 sleep_time = 3
28 tstart = time.time()
29 u_boot_console.run_command('sleep %d' % sleep_time)
30 tend = time.time()
31 elapsed = tend - tstart
Heinrich Schuchardt6c7c3dc2017-10-13 22:28:31 +020032 assert elapsed >= (sleep_time - 0.01)
Stephen Warren89ab8412016-02-04 16:11:50 -070033 if not u_boot_console.config.gdbserver:
34 # 0.25s margin is hopefully enough to account for any system overhead.
35 assert elapsed < (sleep_time + 0.25)