xref: /rk3399_rockchip-uboot/test/py/tests/test_sleep.py (revision 2b2c6e51e7d69f715a1501702fe33589afe6190d)
11c8b4d5fSStephen Warren# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
21c8b4d5fSStephen Warren#
31c8b4d5fSStephen Warren# SPDX-License-Identifier: GPL-2.0
41c8b4d5fSStephen Warren
51c8b4d5fSStephen Warrenimport pytest
61c8b4d5fSStephen Warrenimport time
71c8b4d5fSStephen Warren
81c8b4d5fSStephen Warrendef test_sleep(u_boot_console):
9e8debf39SStephen Warren    """Test the sleep command, and validate that it sleeps for approximately
10e8debf39SStephen Warren    the correct amount of time."""
111c8b4d5fSStephen Warren
12*2b2c6e51STom Rini    if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
13*2b2c6e51STom Rini        pytest.skip('sleep command not supported')
141c8b4d5fSStephen Warren    # 3s isn't too long, but is enough to cross a few second boundaries.
151c8b4d5fSStephen Warren    sleep_time = 3
161c8b4d5fSStephen Warren    tstart = time.time()
171c8b4d5fSStephen Warren    u_boot_console.run_command('sleep %d' % sleep_time)
181c8b4d5fSStephen Warren    tend = time.time()
191c8b4d5fSStephen Warren    elapsed = tend - tstart
2089ab8410SStephen Warren    assert elapsed >= sleep_time
2189ab8410SStephen Warren    if not u_boot_console.config.gdbserver:
221c8b4d5fSStephen Warren        # 0.25s margin is hopefully enough to account for any system overhead.
2389ab8410SStephen Warren        assert elapsed < (sleep_time + 0.25)
24