blob: ccef24d7f7b84e80847961afa79356c6b8538249 [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
Michal Simek3f090a22017-12-08 15:47:18 +01008"""
9Note: This test doesn't rely on boardenv_* configuration values but they can
10change test behavior.
11
12# Setup env__sleep_accurate to False if time is not accurate on your platform
13env__sleep_accurate = False
14
15"""
16
Stephen Warren68188202016-01-15 11:15:31 -070017def test_sleep(u_boot_console):
Stephen Warren75e731e2016-01-26 13:41:30 -070018 """Test the sleep command, and validate that it sleeps for approximately
19 the correct amount of time."""
Stephen Warren68188202016-01-15 11:15:31 -070020
Michal Simek3f090a22017-12-08 15:47:18 +010021 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
Tom Rini42c62142016-10-14 19:12:31 -040025 if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
26 pytest.skip('sleep command not supported')
Stephen Warren68188202016-01-15 11:15:31 -070027 # 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
Heinrich Schuchardte2ecac22017-10-13 22:28:31 +020033 assert elapsed >= (sleep_time - 0.01)
Stephen Warren33db1ee2016-02-04 16:11:50 -070034 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)