summaryrefslogtreecommitdiff
path: root/tests/extmod/machine_soft_timer.py
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2024-08-01 16:26:46 +1000
committerDamien George <damien@micropython.org>2024-08-02 10:27:53 +1000
commit9ba04cc7563ec934ca14d66aa18ae3563c8d1aea (patch)
treea24ce19aa7e8a0739e2b8ec1fcb9d8a780d372f5 /tests/extmod/machine_soft_timer.py
parentd1685a3f5f81f20e9eea26f1274bf6171b287814 (diff)
tests/extmod: Skip soft machine.Timer test on esp32 port.
Also rename the test to reflect that it's a soft timer test. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'tests/extmod/machine_soft_timer.py')
-rw-r--r--tests/extmod/machine_soft_timer.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/extmod/machine_soft_timer.py b/tests/extmod/machine_soft_timer.py
new file mode 100644
index 000000000..bff9af5b8
--- /dev/null
+++ b/tests/extmod/machine_soft_timer.py
@@ -0,0 +1,45 @@
+# test "soft" machine.Timer (no hardware ID)
+import sys
+
+
+if sys.platform == "esp32":
+ print("SKIP") # TODO: Implement soft timers for esp32 port
+ raise SystemExit
+
+
+try:
+ import time, machine as machine
+
+ machine.Timer
+except:
+ print("SKIP")
+ raise SystemExit
+
+# create and deinit
+t = machine.Timer(freq=1)
+t.deinit()
+
+# deinit again
+t.deinit()
+
+# create 2 and deinit
+t = machine.Timer(freq=1)
+t2 = machine.Timer(freq=1)
+t.deinit()
+t2.deinit()
+
+# create 2 and deinit in different order
+t = machine.Timer(freq=1)
+t2 = machine.Timer(freq=1)
+t2.deinit()
+t.deinit()
+
+# create one-shot timer with callback and wait for it to print (should be just once)
+t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot"))
+time.sleep_ms(5)
+t.deinit()
+
+# create periodic timer with callback and wait for it to print
+t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic"))
+time.sleep_ms(14)
+t.deinit()