Stephen Warren | 1c8b4d5 | 2016-01-15 11:15:31 -0700 | [diff] [blame] | 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 | def test_sleep(u_boot_console): |
| 9 | '''Test the sleep command, and validate that it sleeps for approximately |
| 10 | the correct amount of time.''' |
| 11 | |
| 12 | # Do this before we time anything, to make sure U-Boot is already running. |
| 13 | # Otherwise, the system boot time is included in the time measurement. |
| 14 | u_boot_console.ensure_spawned() |
| 15 | |
| 16 | # 3s isn't too long, but is enough to cross a few second boundaries. |
| 17 | sleep_time = 3 |
| 18 | tstart = time.time() |
| 19 | u_boot_console.run_command('sleep %d' % sleep_time) |
| 20 | tend = time.time() |
| 21 | elapsed = tend - tstart |
| 22 | delta_to_expected = abs(elapsed - sleep_time) |
| 23 | # 0.25s margin is hopefully enough to account for any system overhead. |
| 24 | assert delta_to_expected < 0.25 |