Skip to content

Commit 4832683

Browse files
committed
restore tests/unix; deleted by mistake
1 parent d220557 commit 4832683

15 files changed

+804
-0
lines changed

tests/unix/extra_coverage.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
try:
2+
extra_coverage
3+
except NameError:
4+
print("SKIP")
5+
raise SystemExit
6+
7+
import errno
8+
import io
9+
10+
data = extra_coverage()
11+
12+
# test hashing of str/bytes that have an invalid hash
13+
print(data[0], data[1])
14+
print(hash(data[0]))
15+
print(hash(data[1]))
16+
print(hash(bytes(data[0], "utf8")))
17+
print(hash(str(data[1], "utf8")))
18+
19+
# test streams
20+
stream = data[2] # has set_error and set_buf. Write always returns error
21+
stream.set_error(errno.EAGAIN) # non-blocking error
22+
print(stream.read()) # read all encounters non-blocking error
23+
print(stream.read(1)) # read 1 byte encounters non-blocking error
24+
print(stream.readline()) # readline encounters non-blocking error
25+
print(stream.readinto(bytearray(10))) # readinto encounters non-blocking error
26+
print(stream.write(b"1")) # write encounters non-blocking error
27+
print(stream.write1(b"1")) # write1 encounters non-blocking error
28+
stream.set_buf(b"123")
29+
print(stream.read(4)) # read encounters non-blocking error after successful reads
30+
stream.set_buf(b"123")
31+
print(stream.read1(4)) # read1 encounters non-blocking error after successful reads
32+
stream.set_buf(b"123")
33+
print(stream.readline(4)) # readline encounters non-blocking error after successful reads
34+
try:
35+
print(stream.ioctl(0, 0)) # ioctl encounters non-blocking error; raises OSError
36+
except OSError:
37+
print("OSError")
38+
stream.set_error(0)
39+
print(stream.ioctl(0, bytearray(10))) # successful ioctl call
40+
41+
stream2 = data[3] # is textio
42+
print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream
43+
44+
# test BufferedWriter with stream errors
45+
stream.set_error(errno.EAGAIN)
46+
buf = io.BufferedWriter(stream, 8)
47+
print(buf.write(bytearray(16)))
48+
49+
# function defined in C++ code
50+
print("cpp", extra_cpp_coverage())
51+
52+
# test user C module mixed with C++ code
53+
import cppexample
54+
55+
print(cppexample.cppfunc(1, 2))
56+
57+
# test basic import of frozen scripts
58+
import frzstr1
59+
60+
print(frzstr1.__file__)
61+
import frzmpy1
62+
63+
print(frzmpy1.__file__)
64+
65+
# test import of frozen packages with __init__.py
66+
import frzstr_pkg1
67+
68+
print(frzstr_pkg1.__file__, frzstr_pkg1.x)
69+
import frzmpy_pkg1
70+
71+
print(frzmpy_pkg1.__file__, frzmpy_pkg1.x)
72+
73+
# test import of frozen packages without __init__.py
74+
from frzstr_pkg2.mod import Foo
75+
76+
print(Foo.x)
77+
from frzmpy_pkg2.mod import Foo
78+
79+
print(Foo.x)
80+
81+
# test raising exception in frozen script
82+
try:
83+
import frzmpy2
84+
except ZeroDivisionError:
85+
print("ZeroDivisionError")
86+
87+
# test importing various objects
88+
import frzmpy3
89+
90+
# test for MP_QSTR_NULL regression
91+
from frzqstr import returns_NULL
92+
93+
print(returns_NULL())
94+
95+
# test for freeze_mpy
96+
import frozentest
97+
98+
print(frozentest.__file__)
99+
100+
# test for builtin sub-packages
101+
from example_package.foo import bar
102+
103+
print(bar)
104+
bar.f()
105+
import example_package
106+
107+
print(example_package, example_package.foo, example_package.foo.bar)
108+
example_package.f()
109+
example_package.foo.f()
110+
example_package.foo.bar.f()
111+
print(bar == example_package.foo.bar)
112+
from example_package.foo import f as foo_f
113+
114+
foo_f()
115+
print(foo_f == example_package.foo.f)

tests/unix/extra_coverage.py.exp

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# mp_printf
2+
-123 +123 123
3+
-0123
4+
123
5+
123
6+
1ABCDEF
7+
ab abc ' abc' ' True' 'Tru'
8+
9+
false true
10+
(null)
11+
-2147483648
12+
2147483648
13+
80000000
14+
80000000
15+
abc
16+
%
17+
# GC
18+
0x0
19+
0x0
20+
# GC part 2
21+
pass
22+
# tracked allocation
23+
m_tracked_head = 0x0
24+
0 1
25+
1 1
26+
2 1
27+
3 1
28+
4 1
29+
5 1
30+
6 1
31+
7 1
32+
0 1
33+
1 1
34+
2 1
35+
3 1
36+
4 1
37+
5 1
38+
6 1
39+
7 1
40+
m_tracked_head = 0x0
41+
# vstr
42+
tests
43+
sts
44+
45+
test
46+
tes
47+
RuntimeError:
48+
RuntimeError:
49+
# repl
50+
ame__
51+
port
52+
53+
builtins micropython __future__ _asyncio
54+
_thread aesio array audiocore
55+
audiomixer audiomp3 binascii bitmapfilter
56+
bitmaptools cexample cmath codeop
57+
collections cppexample displayio errno
58+
example_package floppyio gc
59+
hashlib heapq io jpegio
60+
json locale math os
61+
platform qrio rainbowio random
62+
re select struct synthio
63+
sys time traceback uctypes
64+
ulab zlib
65+
me
66+
67+
rainbowio random
68+
69+
argv atexit byteorder exc_info
70+
executable exit getsizeof implementation
71+
intern maxsize modules path
72+
platform print_exception ps1
73+
ps2 stderr stdin stdout
74+
tracebacklimit version version_info
75+
ementation
76+
# attrtuple
77+
(start=1, stop=2, step=3)
78+
# str
79+
1
80+
# bytearray
81+
data
82+
# mpz
83+
1
84+
12345678
85+
0
86+
0
87+
0
88+
0
89+
0
90+
1
91+
12345
92+
6
93+
# runtime utils
94+
TypeError: unsupported type for __abs__: 'str'
95+
TypeError: unsupported types for __divmod__: 'str', 'str'
96+
1
97+
2
98+
OverflowError: overflow converting long int to machine word
99+
OverflowError: overflow converting long int to machine word
100+
ValueError:
101+
Warning: test
102+
# format float
103+
?
104+
+1e+00
105+
+1e+00
106+
# binary
107+
123
108+
456
109+
# VM
110+
2 1
111+
# scheduler
112+
sched(0)=1
113+
sched(1)=1
114+
sched(2)=1
115+
sched(3)=1
116+
sched(4)=0
117+
unlocked
118+
0
119+
1
120+
2
121+
3
122+
KeyboardInterrupt:
123+
KeyboardInterrupt:
124+
10
125+
# ringbuf
126+
99 0
127+
98 1
128+
22
129+
99 0
130+
97 2
131+
aa55
132+
99 0
133+
0 99
134+
-1
135+
1 98
136+
-1
137+
2 97
138+
0
139+
cc99
140+
99 0
141+
0
142+
11bb
143+
0
144+
22ff
145+
-1
146+
-1
147+
# pairheap
148+
create: 0 0 0 0
149+
pop all: 0 1 2 3
150+
create: 7 6 5 4 3 2 1 0
151+
pop all: 0 1 2 3 4 5 6 7
152+
create: 1 - - 1 1 1 1 1 1
153+
pop all: 1 2
154+
create: 1 1 1 1 2 2
155+
pop all: 2 4
156+
create: 1 1 1 1 1
157+
pop all: 1 3 4
158+
create: 3 3 3 1 1 1
159+
pop all: 1 2 4 5
160+
# mp_obj_is_type
161+
1 1
162+
0 0
163+
1 1
164+
1 1
165+
0 0
166+
1 1
167+
# end coverage.c
168+
0123456789 b'0123456789'
169+
7300
170+
7300
171+
7300
172+
7300
173+
None
174+
None
175+
None
176+
None
177+
None
178+
None
179+
b'123'
180+
b'123'
181+
b'123'
182+
OSError
183+
0
184+
None
185+
None
186+
cpp None
187+
(3, 'hellocpp')
188+
frzstr1
189+
frzstr1.py
190+
frzmpy1
191+
frzmpy1.py
192+
frzstr_pkg1.__init__
193+
frzstr_pkg1/__init__.py 1
194+
frzmpy_pkg1.__init__
195+
frzmpy_pkg1/__init__.py 1
196+
frzstr_pkg2.mod
197+
1
198+
frzmpy_pkg2.mod
199+
1
200+
ZeroDivisionError
201+
\
202+
203+
X
204+
'\x1b'
205+
b'\x00\xff'
206+
NULL
207+
uPy
208+
a long string that is not interned
209+
a string that has unicode αβγ chars
210+
b'bytes 1234\x01'
211+
123456789
212+
0
213+
1
214+
2
215+
3
216+
frozentest.py
217+
example_package.__init__
218+
<module 'example_package.foo.bar'>
219+
example_package.foo.bar.f
220+
<module 'example_package'> <module 'example_package.foo'> <module 'example_package.foo.bar'>
221+
example_package.f
222+
example_package.foo.f
223+
example_package.foo.bar.f
224+
True
225+
example_package.foo.f
226+
True

tests/unix/ffi_callback.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
try:
2+
import ffi
3+
except ImportError:
4+
print("SKIP")
5+
raise SystemExit
6+
7+
8+
def ffi_open(names):
9+
err = None
10+
for n in names:
11+
try:
12+
mod = ffi.open(n)
13+
return mod
14+
except OSError as e:
15+
err = e
16+
raise err
17+
18+
19+
libc = ffi_open(("libc.so", "libc.so.0", "libc.so.6", "libc.dylib"))
20+
21+
qsort = libc.func("v", "qsort", "piip")
22+
23+
24+
def cmp(pa, pb):
25+
a = ffi.as_bytearray(pa, 1)
26+
b = ffi.as_bytearray(pb, 1)
27+
# print("cmp:", a, b)
28+
return a[0] - b[0]
29+
30+
31+
cmp_c = ffi.callback("i", cmp, "pp")
32+
33+
s = bytearray(b"foobar")
34+
print("org string:", s)
35+
qsort(s, len(s), 1, cmp_c)
36+
print("qsort'ed:", s)

tests/unix/ffi_callback.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org string: bytearray(b'foobar')
2+
qsort'ed: bytearray(b'abfoor')

0 commit comments

Comments
 (0)