2020-09-24 03:37:02 +01:00
|
|
|
# test utime.time_ns()
|
|
|
|
|
|
|
|
try:
|
|
|
|
import utime
|
|
|
|
|
|
|
|
utime.sleep_us
|
|
|
|
utime.time_ns
|
|
|
|
except (ImportError, AttributeError):
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
|
|
|
t0 = utime.time_ns()
|
2021-02-01 07:44:28 +00:00
|
|
|
utime.sleep_us(5000)
|
2020-09-24 03:37:02 +01:00
|
|
|
t1 = utime.time_ns()
|
|
|
|
|
|
|
|
# Check that time_ns increases.
|
|
|
|
print(t0 < t1)
|
|
|
|
|
2021-02-01 07:44:28 +00:00
|
|
|
# Check that time_ns counts correctly, but be very lenient with the bounds (2ms to 50ms).
|
|
|
|
if 2000000 < t1 - t0 < 50000000:
|
2020-09-24 03:37:02 +01:00
|
|
|
print(True)
|
|
|
|
else:
|
|
|
|
print(t0, t1, t1 - t0)
|