]> git.ipfire.org Git - people/ms/u-boot.git/blob - test/py/tests/test_sleep.py
test: py: Add an option to skip sleep test
[people/ms/u-boot.git] / test / py / tests / test_sleep.py
1 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
2 #
3 # SPDX-License-Identifier: GPL-2.0
4
5 import pytest
6 import time
7
8 """
9 Note: This test doesn't rely on boardenv_* configuration values but they can
10 change test behavior.
11
12 # Setup env__sleep_accurate to False if time is not accurate on your platform
13 env__sleep_accurate = False
14
15 """
16
17 def test_sleep(u_boot_console):
18 """Test the sleep command, and validate that it sleeps for approximately
19 the correct amount of time."""
20
21 sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True)
22 if not sleep_skip:
23 pytest.skip('sleep is not accurate')
24
25 if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
26 pytest.skip('sleep command not supported')
27 # 3s isn't too long, but is enough to cross a few second boundaries.
28 sleep_time = 3
29 tstart = time.time()
30 u_boot_console.run_command('sleep %d' % sleep_time)
31 tend = time.time()
32 elapsed = tend - tstart
33 assert elapsed >= (sleep_time - 0.01)
34 if not u_boot_console.config.gdbserver:
35 # 0.25s margin is hopefully enough to account for any system overhead.
36 assert elapsed < (sleep_time + 0.25)