micropython: add micropython component
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# Test the limits of bytecode generation.
|
||||
|
||||
body = " with f()()() as a:\n try:\n f()()()\n except Exception:\n pass\n"
|
||||
|
||||
# Test overflow of jump offset.
|
||||
for n in (430, 431, 432, 433):
|
||||
try:
|
||||
exec("cond = 0\nif cond:\n" + body * n + "else:\n print('cond false')\n")
|
||||
except MemoryError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
||||
|
||||
# Test changing size of code info (source line/bytecode mapping) due to changing
|
||||
# bytecode size in the final passes. This test is very specific to how the
|
||||
# code info is encoded, and how jump offsets shrink in the final passes. This
|
||||
# test should fail if the bytecode emitter doesn't correctly handle shrinking of
|
||||
# the code info section.
|
||||
exec(
|
||||
"""
|
||||
x = 0
|
||||
if x:
|
||||
"""
|
||||
+ body * 13
|
||||
+ """
|
||||
x = [1 if x else 123]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print(x)
|
||||
"""
|
||||
)
|
@@ -0,0 +1,5 @@
|
||||
cond false
|
||||
cond false
|
||||
RuntimeError
|
||||
RuntimeError
|
||||
[123]
|
@@ -0,0 +1,7 @@
|
||||
# copying a large dictionary
|
||||
|
||||
a = {i: 2 * i for i in range(1000)}
|
||||
b = a.copy()
|
||||
for i in range(1000):
|
||||
print(i, b[i])
|
||||
print(len(b))
|
@@ -0,0 +1,8 @@
|
||||
# create a large dictionary
|
||||
|
||||
d = {}
|
||||
x = 1
|
||||
while x < 1000:
|
||||
d[x] = x
|
||||
x += 1
|
||||
print(d[500])
|
@@ -0,0 +1,13 @@
|
||||
# The aim with this test is to hit the maximum resize/rehash size of a dict,
|
||||
# where there are no more primes in the table of growing allocation sizes.
|
||||
# This value is 54907 items.
|
||||
|
||||
d = {}
|
||||
try:
|
||||
for i in range(54908):
|
||||
d[i] = i
|
||||
except MemoryError:
|
||||
pass
|
||||
|
||||
# Just check the dict still has the first value
|
||||
print(d[0])
|
@@ -0,0 +1,36 @@
|
||||
# Test the limit of the number of arguments to a function call.
|
||||
# This currently tests the case of *args after many positional args.
|
||||
|
||||
|
||||
def f(*args):
|
||||
return len(args)
|
||||
|
||||
|
||||
def test(n):
|
||||
pos_args = ",".join(str(i) for i in range(n))
|
||||
s = "f({}, *(100, 101), 102, 103)".format(pos_args)
|
||||
try:
|
||||
return eval(s)
|
||||
except SyntaxError:
|
||||
return "SyntaxError"
|
||||
|
||||
|
||||
# If the port has at least 32-bits then this test should pass.
|
||||
print(test(29))
|
||||
|
||||
# This test should fail on all ports (overflows a small int).
|
||||
print(test(70))
|
||||
|
||||
# Check that there is a correct transition to the limit of too many args before *args.
|
||||
reached_limit = False
|
||||
for i in range(30, 70):
|
||||
result = test(i)
|
||||
if reached_limit:
|
||||
if result != "SyntaxError":
|
||||
print("FAIL")
|
||||
else:
|
||||
if result == "SyntaxError":
|
||||
reached_limit = True
|
||||
else:
|
||||
if result != i + 4:
|
||||
print("FAIL")
|
@@ -0,0 +1,2 @@
|
||||
33
|
||||
SyntaxError
|
19
components/language/micropython/tests/stress/gc_trace.py
Normal file
19
components/language/micropython/tests/stress/gc_trace.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# test that the GC can trace nested objects
|
||||
|
||||
try:
|
||||
import gc
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# test a big shallow object pointing to many unique objects
|
||||
lst = [[i] for i in range(200)]
|
||||
gc.collect()
|
||||
print(lst)
|
||||
|
||||
# test a deep object
|
||||
lst = [
|
||||
[[[[(i, j, k, l)] for i in range(3)] for j in range(3)] for k in range(3)] for l in range(3)
|
||||
]
|
||||
gc.collect()
|
||||
print(lst)
|
@@ -0,0 +1,6 @@
|
||||
# test large list sorting (should not stack overflow)
|
||||
l = list(range(2000))
|
||||
l.sort()
|
||||
print(l[0], l[-1])
|
||||
l.sort(reverse=True)
|
||||
print(l[0], l[-1])
|
89
components/language/micropython/tests/stress/qstr_limit.py
Normal file
89
components/language/micropython/tests/stress/qstr_limit.py
Normal file
@@ -0,0 +1,89 @@
|
||||
# Test interning qstrs that go over the limit of the maximum qstr length
|
||||
# (which is 255 bytes for the default configuration)
|
||||
|
||||
|
||||
def make_id(n, base="a"):
|
||||
return "".join(chr(ord(base) + i % 26) for i in range(n))
|
||||
|
||||
|
||||
# identifiers in parser
|
||||
for l in range(254, 259):
|
||||
g = {}
|
||||
var = make_id(l)
|
||||
try:
|
||||
exec(var + "=1", g)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
continue
|
||||
print(var in g)
|
||||
|
||||
# calling a function with kwarg
|
||||
def f(**k):
|
||||
print(k)
|
||||
|
||||
|
||||
for l in range(254, 259):
|
||||
try:
|
||||
exec("f({}=1)".format(make_id(l)))
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
|
||||
# type construction
|
||||
for l in range(254, 259):
|
||||
id = make_id(l)
|
||||
try:
|
||||
print(type(id, (), {}).__name__)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
|
||||
# hasattr, setattr, getattr
|
||||
class A:
|
||||
pass
|
||||
|
||||
|
||||
for l in range(254, 259):
|
||||
id = make_id(l)
|
||||
a = A()
|
||||
try:
|
||||
setattr(a, id, 123)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
try:
|
||||
print(hasattr(a, id), getattr(a, id))
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
|
||||
# format with keys
|
||||
for l in range(254, 259):
|
||||
id = make_id(l)
|
||||
try:
|
||||
print(("{" + id + "}").format(**{id: l}))
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
|
||||
# modulo format with keys
|
||||
for l in range(254, 259):
|
||||
id = make_id(l)
|
||||
try:
|
||||
print(("%(" + id + ")d") % {id: l})
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
|
||||
# import module
|
||||
# (different OS's have different results so only run those that are consistent)
|
||||
for l in (100, 101, 256, 257, 258):
|
||||
try:
|
||||
__import__(make_id(l))
|
||||
except ImportError:
|
||||
print("ok", l)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
|
||||
# import package
|
||||
for l in (100, 101, 102, 128, 129):
|
||||
try:
|
||||
exec("import " + make_id(l) + "." + make_id(l, "A"))
|
||||
except ImportError:
|
||||
print("ok", l)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
@@ -0,0 +1,43 @@
|
||||
True
|
||||
True
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst': 1}
|
||||
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu': 1}
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
|
||||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
True 123
|
||||
True 123
|
||||
RuntimeError 256
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
RuntimeError 258
|
||||
254
|
||||
255
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
254
|
||||
255
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
ok 100
|
||||
ok 101
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
ok 100
|
||||
ok 101
|
||||
ok 102
|
||||
RuntimeError 128
|
||||
RuntimeError 129
|
@@ -0,0 +1,8 @@
|
||||
def foo():
|
||||
foo()
|
||||
|
||||
|
||||
try:
|
||||
foo()
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
@@ -0,0 +1,13 @@
|
||||
# This tests that printing recursive data structure doesn't lead to segfault.
|
||||
try:
|
||||
import uio as io
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
l = [1, 2, 3, None]
|
||||
l[-1] = l
|
||||
try:
|
||||
print(l, file=io.StringIO())
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
@@ -0,0 +1 @@
|
||||
RuntimeError
|
@@ -0,0 +1,22 @@
|
||||
# test deeply recursive generators
|
||||
|
||||
# simple "yield from" recursion
|
||||
def gen():
|
||||
yield from gen()
|
||||
|
||||
|
||||
try:
|
||||
list(gen())
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
||||
|
||||
# recursion via an iterator over a generator
|
||||
def gen2():
|
||||
for x in gen2():
|
||||
yield x
|
||||
|
||||
|
||||
try:
|
||||
next(gen2())
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
@@ -0,0 +1,57 @@
|
||||
# This tests that recursion with iternext doesn't lead to segfault.
|
||||
try:
|
||||
enumerate
|
||||
filter
|
||||
map
|
||||
max
|
||||
zip
|
||||
except:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# We need to pick an N that is large enough to hit the recursion
|
||||
# limit, but not too large that we run out of heap memory.
|
||||
try:
|
||||
# large stack/heap, eg unix
|
||||
[0] * 80000
|
||||
N = 5000
|
||||
except:
|
||||
try:
|
||||
# medium, eg pyboard
|
||||
[0] * 10000
|
||||
N = 1000
|
||||
except:
|
||||
# small, eg esp8266
|
||||
N = 100
|
||||
|
||||
try:
|
||||
x = (1, 2)
|
||||
for i in range(N):
|
||||
x = enumerate(x)
|
||||
tuple(x)
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
||||
|
||||
try:
|
||||
x = (1, 2)
|
||||
for i in range(N):
|
||||
x = filter(None, x)
|
||||
tuple(x)
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
||||
|
||||
try:
|
||||
x = (1, 2)
|
||||
for i in range(N):
|
||||
x = map(max, x, ())
|
||||
tuple(x)
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
||||
|
||||
try:
|
||||
x = (1, 2)
|
||||
for i in range(N):
|
||||
x = zip(x)
|
||||
tuple(x)
|
||||
except RuntimeError:
|
||||
print("RuntimeError")
|
@@ -0,0 +1,4 @@
|
||||
RuntimeError
|
||||
RuntimeError
|
||||
RuntimeError
|
||||
RuntimeError
|
Reference in New Issue
Block a user