mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
tests/stress: Improve qstr_limit test to run on minimal targets.
Changes here are: - Split out string format module sub-test to a separate test file, so it can be skipped on targets that don't have str% capabilities. - Print the whole type instead of `.__name__` to support targets that don't have `.__name__` enabled (this still tests the same thing). - Print `RuntimeError` exception message to be sure the correct exception is being raised. This test now runs on unix and zephyr minimal configurations. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -12,8 +12,8 @@ for l in range(254, 259):
|
||||
var = make_id(l)
|
||||
try:
|
||||
exec(var + "=1", g)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
continue
|
||||
print(var in g)
|
||||
|
||||
@@ -26,16 +26,16 @@ def f(**k):
|
||||
for l in range(254, 259):
|
||||
try:
|
||||
exec("f({}=1)".format(make_id(l)))
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
|
||||
# type construction
|
||||
for l in range(254, 259):
|
||||
id = make_id(l)
|
||||
try:
|
||||
print(type(id, (), {}).__name__)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
print(type(id, (), {}))
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
|
||||
|
||||
# hasattr, setattr, getattr
|
||||
@@ -48,28 +48,20 @@ for l in range(254, 259):
|
||||
a = A()
|
||||
try:
|
||||
setattr(a, id, 123)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
try:
|
||||
print(hasattr(a, id), getattr(a, id))
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, 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)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
|
||||
# import module
|
||||
# (different OS's have different results so only run those that are consistent)
|
||||
@@ -78,8 +70,8 @@ for l in (100, 101, 256, 257, 258):
|
||||
__import__(make_id(l))
|
||||
except ImportError:
|
||||
print("ok", l)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
|
||||
# import package
|
||||
for l in (100, 101, 102, 128, 129):
|
||||
@@ -87,5 +79,5 @@ for l in (100, 101, 102, 128, 129):
|
||||
exec("import " + make_id(l) + "." + make_id(l, "A"))
|
||||
except ImportError:
|
||||
print("ok", l)
|
||||
except RuntimeError:
|
||||
print("RuntimeError", l)
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
True
|
||||
True
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst': 1}
|
||||
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu': 1}
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
|
||||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
<class 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst'>
|
||||
<class 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu'>
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
True 123
|
||||
True 123
|
||||
RuntimeError 256
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
RuntimeError 258
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
RuntimeError name too long 258
|
||||
254
|
||||
255
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
254
|
||||
255
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
ok 100
|
||||
ok 101
|
||||
RuntimeError 256
|
||||
RuntimeError 257
|
||||
RuntimeError 258
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
ok 100
|
||||
ok 101
|
||||
ok 102
|
||||
RuntimeError 128
|
||||
RuntimeError 129
|
||||
RuntimeError name too long 128
|
||||
RuntimeError name too long 129
|
||||
|
||||
21
tests/stress/qstr_limit_str_modulo.py
Normal file
21
tests/stress/qstr_limit_str_modulo.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Test interning qstrs that go over the qstr length limit (255 bytes in default configuration).
|
||||
# The tests here are specifically for str formatting with %.
|
||||
|
||||
try:
|
||||
"" % ()
|
||||
except TypeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
def make_id(n, base="a"):
|
||||
return "".join(chr(ord(base) + i % 26) for i in range(n))
|
||||
|
||||
|
||||
# modulo format with keys
|
||||
for l in range(254, 259):
|
||||
id = make_id(l)
|
||||
try:
|
||||
print(("%(" + id + ")d") % {id: l})
|
||||
except RuntimeError as er:
|
||||
print("RuntimeError", er, l)
|
||||
5
tests/stress/qstr_limit_str_modulo.py.exp
Normal file
5
tests/stress/qstr_limit_str_modulo.py.exp
Normal file
@@ -0,0 +1,5 @@
|
||||
254
|
||||
255
|
||||
RuntimeError name too long 256
|
||||
RuntimeError name too long 257
|
||||
RuntimeError name too long 258
|
||||
Reference in New Issue
Block a user