]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test/py/tests: Add a test for the time command
authorLove Kumar <love.kumar@xilinx.com>
Mon, 12 Jul 2021 04:05:41 +0000 (22:05 -0600)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 12 Jul 2021 11:18:44 +0000 (13:18 +0200)
This test executes "time <sleep cmd>", and validate that it gives the
approximately the correct amount of command execution time.

Signed-off-by: Love Kumar <love.kumar@xilinx.com>
test/py/tests/test_sleep.py

index 392af29db2245f69bc9ef656075a1c0d6836162b..c4b41e71fe5c36f4f198e7222dad31d0413a45a5 100644 (file)
@@ -41,3 +41,23 @@ def test_sleep(u_boot_console):
     if not u_boot_console.config.gdbserver:
         # margin is hopefully enough to account for any system overhead.
         assert elapsed < (sleep_time + sleep_margin)
+
+def test_time(u_boot_console):
+    """Test the time command, and validate that it gives approximately the
+    correct amount of command execution time."""
+
+    sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True)
+    if not sleep_skip:
+        pytest.skip('sleep is not accurate')
+
+    if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
+        pytest.skip('sleep command not supported')
+
+    sleep_time = u_boot_console.config.env.get('env__sleep_time', 10)
+    sleep_margin = u_boot_console.config.env.get('env__sleep_margin', 0.25)
+    output = u_boot_console.run_command('time sleep %d' % sleep_time)
+    execute_time = float(output.split()[1])
+    assert sleep_time >= (execute_time - 0.01)
+    if not u_boot_console.config.gdbserver:
+        # margin is hopefully enough to account for any system overhead.
+        assert sleep_time < (execute_time + sleep_margin)