summaryrefslogtreecommitdiff
path: root/tests/micropython
diff options
context:
space:
mode:
authorTony DiCola <tony@tonydicola.com>2016-10-20 23:01:13 +0000
committerTony DiCola <tony@tonydicola.com>2016-10-20 23:01:13 +0000
commit00a44fa36cd1e35a438c4b89b5cef0bc82787c7a (patch)
tree4800a6984902e043e3fc437adcdfcd665f83e220 /tests/micropython
parent1f13f870b8f6554d9cd5570de221a6886e065b64 (diff)
parent3967ca7390ff8257728ef6237b93977b63bde41d (diff)
Merge remote-tracking branch 'micropython/master'
Conflicts: README.md - Kept Adafruit README.md intact. py/emitglue.c - Added xtensa architecture as an OR of the define. zephyr/README.md - Fixed spelling mistake.
Diffstat (limited to 'tests/micropython')
-rw-r--r--tests/micropython/emg_exc.py20
-rw-r--r--tests/micropython/emg_exc.py.exp1
-rw-r--r--tests/micropython/heap_lock.py14
-rw-r--r--tests/micropython/heap_lock.py.exp2
-rw-r--r--tests/micropython/heapalloc.py13
-rw-r--r--tests/micropython/opt_level.py14
-rw-r--r--tests/micropython/opt_level.py.exp4
-rw-r--r--tests/micropython/viper_args.py8
8 files changed, 67 insertions, 9 deletions
diff --git a/tests/micropython/emg_exc.py b/tests/micropython/emg_exc.py
new file mode 100644
index 000000000..d228e6faa
--- /dev/null
+++ b/tests/micropython/emg_exc.py
@@ -0,0 +1,20 @@
+# test that emergency exceptions work
+
+import micropython
+import sys
+
+# some ports need to allocate heap for the emg exc
+try:
+ micropython.alloc_emergency_exception_buf(256)
+except AttributeError:
+ pass
+
+def f():
+ micropython.heap_lock()
+ try:
+ raise ValueError(1)
+ except ValueError as er:
+ sys.print_exception(er)
+ micropython.heap_unlock()
+
+f()
diff --git a/tests/micropython/emg_exc.py.exp b/tests/micropython/emg_exc.py.exp
new file mode 100644
index 000000000..82b10b5f5
--- /dev/null
+++ b/tests/micropython/emg_exc.py.exp
@@ -0,0 +1 @@
+ValueError:
diff --git a/tests/micropython/heap_lock.py b/tests/micropython/heap_lock.py
new file mode 100644
index 000000000..0f0a70eff
--- /dev/null
+++ b/tests/micropython/heap_lock.py
@@ -0,0 +1,14 @@
+# check that heap_lock/heap_unlock work as expected
+
+import micropython
+
+micropython.heap_lock()
+
+try:
+ print([])
+except MemoryError:
+ print('MemoryError')
+
+micropython.heap_unlock()
+
+print([])
diff --git a/tests/micropython/heap_lock.py.exp b/tests/micropython/heap_lock.py.exp
new file mode 100644
index 000000000..67b208cfc
--- /dev/null
+++ b/tests/micropython/heap_lock.py.exp
@@ -0,0 +1,2 @@
+MemoryError
+[]
diff --git a/tests/micropython/heapalloc.py b/tests/micropython/heapalloc.py
index 2dc7fa5e7..a651158ca 100644
--- a/tests/micropython/heapalloc.py
+++ b/tests/micropython/heapalloc.py
@@ -1,6 +1,6 @@
# check that we can do certain things without allocating heap memory
-import gc
+import micropython
def f1(a):
print(a)
@@ -28,12 +28,7 @@ def test():
f2(i, i) # 2 args
f3(1, 2, 3, 4) # function with lots of local state
-# call h with heap allocation disabled and all memory used up
-gc.disable()
-try:
- while True:
- 'a'.lower # allocates 1 cell for boundmeth
-except MemoryError:
- pass
+# call test() with heap allocation disabled
+micropython.heap_lock()
test()
-gc.enable()
+micropython.heap_unlock()
diff --git a/tests/micropython/opt_level.py b/tests/micropython/opt_level.py
new file mode 100644
index 000000000..4e2f2f4ea
--- /dev/null
+++ b/tests/micropython/opt_level.py
@@ -0,0 +1,14 @@
+import micropython as micropython
+
+# check we can get and set the level
+micropython.opt_level(0)
+print(micropython.opt_level())
+micropython.opt_level(1)
+print(micropython.opt_level())
+
+# check that the optimisation levels actually differ
+micropython.opt_level(0)
+exec('print(__debug__)')
+micropython.opt_level(1)
+exec('print(__debug__)')
+exec('assert 0')
diff --git a/tests/micropython/opt_level.py.exp b/tests/micropython/opt_level.py.exp
new file mode 100644
index 000000000..74b3dd74e
--- /dev/null
+++ b/tests/micropython/opt_level.py.exp
@@ -0,0 +1,4 @@
+0
+1
+True
+False
diff --git a/tests/micropython/viper_args.py b/tests/micropython/viper_args.py
index ca2a5e670..2aebe1b04 100644
--- a/tests/micropython/viper_args.py
+++ b/tests/micropython/viper_args.py
@@ -26,3 +26,11 @@ def f4(x1:int, x2:int, x3:int, x4:int):
f4(1, 2, 3, 4)
# only up to 4 arguments currently supported
+
+# test compiling *x, **x, * args (currently unsupported at runtime)
+@micropython.viper
+def f(*x, **y):
+ pass
+@micropython.viper
+def f(*):
+ pass