8000 tests/stress: Add test for maximum length limit of qstrs. · rlangoy/micropython@1675b98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1675b98

Browse files
committed
tests/stress: Add test for maximum length limit of qstrs.
1 parent bc129f1 commit 1675b98

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

tests/stress/qstr_limit.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Test interning qstrs that go over the limit of the maximum qstr length
2+
# (which is 255 bytes for the default configuration)
3+
4+
def make_id(n, base='a'):
5+
return ''.join(chr(ord(base) + i % 26) for i in range(n))
6+
7+
# identifiers in parser
8+
for l in range(254, 259):
9+
g = {}
10+
var = make_id(l)
11+
try:
12+
exec(var + '=1', g)
13+
except RuntimeError:
14+
print('RuntimeError', l)
15+
continue
16+
print(var in g)
17+
18+
# calling a function with kwarg
19+
def f(**k):
20+
print(k)
21+
for l in range(254, 259):
22+
try:
23+
exec('f({}=1)'.format(make_id(l)))
24+
except RuntimeError:
25+
print('RuntimeError', l)
26+
27+
# type construction
28+
for l in range(254, 259):
29+
id = make_id(l)
30+
try:
31+
print(type(id, (), {}).__name__)
32+
except RuntimeError:
33+
print('RuntimeError', l)
34+
35+
# hasattr, setattr, getattr
36+
class A:
37+
pass
38+
for l in range(254, 259):
39+
id = make_id(l)
40+
a = A()
41+
try:
42+
setattr(a, id, 123)
43+
except RuntimeError:
44+
print('RuntimeError', l)
45+
try:
46+
print(hasattr(a, id), getattr(a, id))
47+
except RuntimeError:
48+
print('RuntimeError', l)
49+
50+
# format with keys
51+
for l in range(254, 259):
52+
id = make_id(l)
53+
try:
54+
print(('{' + id + '}').format(**{id: l}))
55+
except RuntimeError:
56+
print('RuntimeError', l)
57+
58+
# modulo format with keys
59+
for l in range(254, 259):
60+
id = make_id(l)
61+
try:
62+
print(('%(' + id + ')d') % {id: l})
63+
except RuntimeError:
64+
print('RuntimeError', l)
65+
66+
# import module
67+
# (different OS's have different results so only print those that are consistent)
68+
for l in range(150, 259):
69+
try:
70+
__import__(make_id(l))
71+
except ImportError:
72+
if l < 152:
73+
print('ok', l)
74+
except RuntimeError:
75+
if l > 255:
76+
print('RuntimeError', l)
77+
78+
# import package
79+
for l in range(125, 130):
80+
try:
81+
exec('import ' + make_id(l) + '.' + make_id(l, 'A'))
82+
except ImportError:
83+
print('ok', l)
84+
except RuntimeError:
85+
print('RuntimeError', l)

tests/stress/qstr_limit.py.exp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
True
2+
True
3+
RuntimeError 256
4+
RuntimeError 257
5+
RuntimeError 258
6+
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst': 1}
7+
{'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu': 1}
8+
RuntimeError 256
9+
RuntimeError 257
10+
RuntimeError 258
11+
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
12+
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu
13+
RuntimeError 256
14+
RuntimeError 257
15+
RuntimeError 258
16+
True 123
17+
True 123
18+
RuntimeError 256
19+
RuntimeError 256
20+
RuntimeError 257
21+
RuntimeError 257
22+
RuntimeError 258
23+
RuntimeError 258
24+
254
25+
255
26+
RuntimeError 256
27+
RuntimeError 257
28+
RuntimeError 258
29+
254
30+
255
31+
RuntimeError 256
32+
RuntimeError 257
33+
RuntimeError 258
34+
ok 150
35+
ok 151
36+
RuntimeError 256
37+
RuntimeError 257
38+
RuntimeError 258
39+
ok 125
40+
ok 126
41+
ok 127
42+
RuntimeError 128
43+
RuntimeError 129

0 commit comments

Comments
 (0)
0