micropython/tests/extmod/time_time_ns.py
Jim Mussared 4216bc7d13 tests: Replace umodule with module everywhere.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00

25 lines
440 B
Python

# test time.time_ns()
try:
import time
time.sleep_us
time.time_ns
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
t0 = time.time_ns()
time.sleep_us(5000)
t1 = time.time_ns()
# Check that time_ns increases.
print(t0 < t1)
# Check that time_ns counts correctly, but be very lenient with the bounds (2ms to 50ms).
if 2000000 < t1 - t0 < 50000000:
print(True)
else:
print(t0, t1, t1 - t0)