summaryrefslogtreecommitdiff
path: root/tests/extmod/time_time_ns.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-10-24 17:56:50 +1100
committerDamien George <damien@micropython.org>2024-10-24 23:24:09 +1100
commit09ea901317810e9e8fbd564cdbf8d50b3569d07f (patch)
tree71a8eb278480d178bcddef19e43b8a059b1e17f1 /tests/extmod/time_time_ns.py
parent1ec0c9b886450e0f4d9f88817a8553e7177fb27f (diff)
tests/extmod: Add test to compare time_ns with time.
They should be close together. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/extmod/time_time_ns.py')
-rw-r--r--tests/extmod/time_time_ns.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/extmod/time_time_ns.py b/tests/extmod/time_time_ns.py
index 3ef58e56a..eab7b3a5d 100644
--- a/tests/extmod/time_time_ns.py
+++ b/tests/extmod/time_time_ns.py
@@ -22,3 +22,10 @@ if 2000000 < t1 - t0 < 50000000:
print(True)
else:
print(t0, t1, t1 - t0)
+
+# Check that time.time() and time.time_ns() are within a second of each other.
+# Note that time.time() may return an int or float.
+for _ in range(10):
+ t_s, t_ns = time.time(), time.time_ns()
+ print(abs(t_s * 1_000 - t_ns // 1_000_000) <= 1_000)
+ time.sleep_us(100_000)