]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test/py: sleep: Add a test for the time command
authorLove Kumar <love.kumar@amd.com>
Wed, 27 Sep 2023 05:03:55 +0000 (10:33 +0530)
committerTom Rini <trini@konsulko.com>
Mon, 9 Oct 2023 19:24:31 +0000 (15:24 -0400)
Execute "time <sleep cmd>", and validate that it gives the approximately
the correct amount of command execution time.

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

index 392af29db2245f69bc9ef656075a1c0d6836162b..66a57434bff7eaad83f5228d0169f94cf1f93427 100644 (file)
@@ -41,3 +41,21 @@ 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)
+
+@pytest.mark.buildconfigspec("cmd_misc")
+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")
+
+    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)