Skip to content

Commit

Permalink
tests/extmod: Add test to compare time_ns with time.
Browse files Browse the repository at this point in the history
They should be close together.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Oct 24, 2024
1 parent 1ec0c9b commit 09ea901
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/extmod/time_time_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@
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)
10 changes: 10 additions & 0 deletions tests/extmod/time_time_ns.py.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
True
True
True
True
True
True
True
True
True
True
True
True

0 comments on commit 09ea901

Please sign in to comment.