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