summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-01-13 17:35:18 +1100
committerDamien George <damien.p.george@gmail.com>2020-01-22 17:31:18 +1100
commitcfddc6a8c773c204bd748124aa7c445cba1d4891 (patch)
tree4399358ace57d7c8fd46d728eb736ed9b4256ca7
parentf70373c7b255a465300517c41a058909b4d3cea2 (diff)
downloadmicropython-cfddc6a8c773c204bd748124aa7c445cba1d4891.tar.gz
micropython-cfddc6a8c773c204bd748124aa7c445cba1d4891.zip
tests/extmod: Add basic machine.Timer test.
-rw-r--r--tests/extmod/machine_timer.py37
-rw-r--r--tests/extmod/machine_timer.py.exp4
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/extmod/machine_timer.py b/tests/extmod/machine_timer.py
new file mode 100644
index 0000000000..b7e6a280f9
--- /dev/null
+++ b/tests/extmod/machine_timer.py
@@ -0,0 +1,37 @@
+# test machine.Timer
+
+try:
+ import utime, umachine 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'))
+utime.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'))
+utime.sleep_ms(14)
+t.deinit()
diff --git a/tests/extmod/machine_timer.py.exp b/tests/extmod/machine_timer.py.exp
new file mode 100644
index 0000000000..2dd85ba67d
--- /dev/null
+++ b/tests/extmod/machine_timer.py.exp
@@ -0,0 +1,4 @@
+one-shot
+periodic
+periodic
+periodic