1*1c8b4d5fSStephen Warren# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 2*1c8b4d5fSStephen Warren# 3*1c8b4d5fSStephen Warren# SPDX-License-Identifier: GPL-2.0 4*1c8b4d5fSStephen Warren 5*1c8b4d5fSStephen Warrenimport pytest 6*1c8b4d5fSStephen Warrenimport time 7*1c8b4d5fSStephen Warren 8*1c8b4d5fSStephen Warrendef test_sleep(u_boot_console): 9*1c8b4d5fSStephen Warren '''Test the sleep command, and validate that it sleeps for approximately 10*1c8b4d5fSStephen Warren the correct amount of time.''' 11*1c8b4d5fSStephen Warren 12*1c8b4d5fSStephen Warren # Do this before we time anything, to make sure U-Boot is already running. 13*1c8b4d5fSStephen Warren # Otherwise, the system boot time is included in the time measurement. 14*1c8b4d5fSStephen Warren u_boot_console.ensure_spawned() 15*1c8b4d5fSStephen Warren 16*1c8b4d5fSStephen Warren # 3s isn't too long, but is enough to cross a few second boundaries. 17*1c8b4d5fSStephen Warren sleep_time = 3 18*1c8b4d5fSStephen Warren tstart = time.time() 19*1c8b4d5fSStephen Warren u_boot_console.run_command('sleep %d' % sleep_time) 20*1c8b4d5fSStephen Warren tend = time.time() 21*1c8b4d5fSStephen Warren elapsed = tend - tstart 22*1c8b4d5fSStephen Warren delta_to_expected = abs(elapsed - sleep_time) 23*1c8b4d5fSStephen Warren # 0.25s margin is hopefully enough to account for any system overhead. 24*1c8b4d5fSStephen Warren assert delta_to_expected < 0.25 25