Skip to content

Commit 09ea901

Browse files
committed
tests/extmod: Add test to compare time_ns with time.
They should be close together. Signed-off-by: Damien George <[email protected]>
1 parent 1ec0c9b commit 09ea901

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/extmod/time_time_ns.py

+7
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@
2222
print(True)
2323
else:
2424
print(t0, t1, t1 - t0)
25+
26+
# Check that time.time() and time.time_ns() are within a second of each other.
27+
# Note that time.time() may return an int or float.
28+
for _ in range(10):
29+
t_s, t_ns = time.time(), time.time_ns()
30+
print(abs(t_s * 1_000 - t_ns // 1_000_000) <= 1_000)
31+
time.sleep_us(100_000)

tests/extmod/time_time_ns.py.exp

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
True
22
True
3+
True
4+
True
5+
True
6+
True
7+
True
8+
True
9+
True
10+
True
11+
True
12+
True

0 commit comments

Comments
 (0)