diff options
| author | Damien George | 2020-09-24 12:37:02 +1000 |
|---|---|---|
| committer | Damien George | 2020-10-01 14:20:42 +1000 |
| commit | d4b61b00172ccc231307e3ef33f66f28cb6b051f (patch) | |
| tree | 193b39ce0aa2a542d6f3ea6c96aadbe8f523858b /tests/extmod | |
| parent | 905a18aafefbe04aa2beceb84885c29aa156b975 (diff) | |
extmod/utime_mphal: Add generic utime.time_ns() function.
It requires mp_hal_time_ns() to be provided by a port. This function
allows very accurate absolute timestamps.
Enabled on unix, windows, stm32, esp8266 and esp32.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/extmod')
| -rw-r--r-- | tests/extmod/utime_time_ns.py | 24 | ||||
| -rw-r--r-- | tests/extmod/utime_time_ns.py.exp | 2 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/extmod/utime_time_ns.py b/tests/extmod/utime_time_ns.py new file mode 100644 index 000000000..8f3890f1c --- /dev/null +++ b/tests/extmod/utime_time_ns.py @@ -0,0 +1,24 @@ +# test utime.time_ns() + +try: + import utime + + utime.sleep_us + utime.time_ns +except (ImportError, AttributeError): + print("SKIP") + raise SystemExit + + +t0 = utime.time_ns() +utime.sleep_us(1000) +t1 = utime.time_ns() + +# Check that time_ns increases. +print(t0 < t1) + +# Check that time_ns counts correctly, but be very lenient with the upper bound (50ms). +if 950000 < t1 - t0 < 50000000: + print(True) +else: + print(t0, t1, t1 - t0) diff --git a/tests/extmod/utime_time_ns.py.exp b/tests/extmod/utime_time_ns.py.exp new file mode 100644 index 000000000..dbde42265 --- /dev/null +++ b/tests/extmod/utime_time_ns.py.exp @@ -0,0 +1,2 @@ +True +True |
