diff options
Diffstat (limited to 'tests')
19 files changed, 415 insertions, 196 deletions
diff --git a/tests/micropython/viper_ptr16_load_boundary.py b/tests/micropython/viper_ptr16_load_boundary.py index ccaaa0909a..0d4c3105b6 100644 --- a/tests/micropython/viper_ptr16_load_boundary.py +++ b/tests/micropython/viper_ptr16_load_boundary.py @@ -2,24 +2,38 @@ GET_TEMPLATE = """ @micropython.viper -def get{off}(src: ptr16) -> int: - return src[{off}] -print(b[{off} * 2:({off} + 1) * 2]) +def get{off}(src: ptr16) -> uint: + return uint(src[{off}]) +print(hex(get{off}(buffer))) """ +BIT_THRESHOLDS = (5, 8, 11, 12) +SIZE = 2 + + @micropython.viper def get_index(src: ptr16, i: int) -> int: return src[i] -b = bytearray(5000) -b[28:38] = b"0123456789" -b[252:262] = b"ABCDEFGHIJ" -b[4092:4102] = b"KLMNOPQRST" +def data(start, len): + output = bytearray(len) + for idx in range(len): + output[idx] = (start + idx) & 0xFF + return output + + +buffer = bytearray((((1 << max(BIT_THRESHOLDS)) + 1) // 1024) * 1024) +val = 0 +for bit in BIT_THRESHOLDS: + print("---", bit) + pre, idx, post = ((1 << bit) - (2 * SIZE), (1 << bit) - (1 * SIZE), 1 << bit) + buffer[pre:post] = data(val, 3 * SIZE) + val = val + (3 * SIZE) -for pre, idx, post in (15, 16, 17), (127, 128, 129), (2047, 2048, 2049): - print(get_index(b, pre), get_index(b, idx), get_index(b, post)) + pre, idx, post = pre // SIZE, idx // SIZE, post // SIZE + print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post))) exec(GET_TEMPLATE.format(off=pre)) exec(GET_TEMPLATE.format(off=idx)) exec(GET_TEMPLATE.format(off=post)) diff --git a/tests/micropython/viper_ptr16_load_boundary.py.exp b/tests/micropython/viper_ptr16_load_boundary.py.exp index 4b8c184c13..56f1d32290 100644 --- a/tests/micropython/viper_ptr16_load_boundary.py.exp +++ b/tests/micropython/viper_ptr16_load_boundary.py.exp @@ -1,12 +1,20 @@ -13106 13620 14134 -bytearray(b'23') -bytearray(b'45') -bytearray(b'67') -17475 17989 18503 -bytearray(b'CD') -bytearray(b'EF') -bytearray(b'GH') -20045 20559 21073 -bytearray(b'MN') -bytearray(b'OP') -bytearray(b'QR') +--- 5 +0x100 0x302 0x504 +0x100 +0x302 +0x504 +--- 8 +0x706 0x908 0xb0a +0x706 +0x908 +0xb0a +--- 11 +0xd0c 0xf0e 0x1110 +0xd0c +0xf0e +0x1110 +--- 12 +0x1312 0x1514 0x1716 +0x1312 +0x1514 +0x1716 diff --git a/tests/micropython/viper_ptr16_store_boundary.py b/tests/micropython/viper_ptr16_store_boundary.py index e0a4f84557..1694c61ac0 100644 --- a/tests/micropython/viper_ptr16_store_boundary.py +++ b/tests/micropython/viper_ptr16_store_boundary.py @@ -4,38 +4,50 @@ SET_TEMPLATE = """ @micropython.viper def set{off}(dest: ptr16): dest[{off}] = {val} -set{off}(b) -print(b[{off} * 2:({off} + 1) * 2]) +set{off}(buffer) +print(hex(get_index(buffer, {off}))) """ -TEST_DATA = ( - (15, (0x4241, 0x4443, 0x4645)), - (127, (0x4847, 0x4A49, 0x4C4B)), - (2047, (0x4E4D, 0x504F, 0x5251)), -) +BIT_THRESHOLDS = (5, 8, 11, 12) +SIZE = 2 +MASK = (1 << (8 * SIZE)) - 1 @micropython.viper -def set_index(dest: ptr16, i: int, val: int): +def set_index(dest: ptr16, i: int, val: uint): dest[i] = val -@micropython.viper -def set_index(dest: ptr16, i: int, val: int): - dest[i] = val - - -b = bytearray(5000) -for start, vals in TEST_DATA: - for i, v in enumerate(vals): - set_index(b, start + i, v) - print(b[(start + i) * 2 : (start + i + 1) * 2]) - - -for i in range(len(b)): - b[i] = 0 - - -for start, vals in TEST_DATA: - for i, v in enumerate(vals): - exec(SET_TEMPLATE.format(off=start + i, val=v + 0x0101)) +def get_index(src, i): + return src[i * SIZE] + (src[(i * SIZE) + 1] << 8) + + +buffer = bytearray(((1 << max(BIT_THRESHOLDS) + 1) // 1024) * 1024) +next = 1 +val = 0 +for bit in BIT_THRESHOLDS: + print("---", bit) + pre, idx, post = ( + (((1 << bit) - (2 * SIZE)) // SIZE), + (((1 << bit) - (1 * SIZE)) // SIZE), + ((1 << bit) // SIZE), + ) + val = (val << 8) + next + next += 1 + set_index(buffer, pre, val & MASK) + val = (val << 8) + next + next += 1 + set_index(buffer, idx, val & MASK) + val = (val << 8) + next + next += 1 + set_index(buffer, post, val & MASK) + val = (val << 8) + next + next += 1 + print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post))) + exec(SET_TEMPLATE.format(off=pre, val=val & MASK)) + val = (val << 8) + next + next += 1 + exec(SET_TEMPLATE.format(off=idx, val=val & MASK)) + val = (val << 8) + next + next += 1 + exec(SET_TEMPLATE.format(off=post, val=val & MASK)) diff --git a/tests/micropython/viper_ptr16_store_boundary.py.exp b/tests/micropython/viper_ptr16_store_boundary.py.exp index b56fe6695f..1c084da2d9 100644 --- a/tests/micropython/viper_ptr16_store_boundary.py.exp +++ b/tests/micropython/viper_ptr16_store_boundary.py.exp @@ -1,18 +1,20 @@ -bytearray(b'AB') -bytearray(b'CD') -bytearray(b'EF') -bytearray(b'GH') -bytearray(b'IJ') -bytearray(b'KL') -bytearray(b'MN') -bytearray(b'OP') -bytearray(b'QR') -bytearray(b'BC') -bytearray(b'DE') -bytearray(b'FG') -bytearray(b'HI') -bytearray(b'JK') -bytearray(b'LM') -bytearray(b'NO') -bytearray(b'PQ') -bytearray(b'RS') +--- 5 +0x1 0x102 0x203 +0x304 +0x405 +0x506 +--- 8 +0x607 0x708 0x809 +0x90a +0xa0b +0xb0c +--- 11 +0xc0d 0xd0e 0xe0f +0xf10 +0x1011 +0x1112 +--- 12 +0x1213 0x1314 0x1415 +0x1516 +0x1617 +0x1718 diff --git a/tests/micropython/viper_ptr32_load_boundary.py b/tests/micropython/viper_ptr32_load_boundary.py index 6954bd46b2..971d1113c4 100644 --- a/tests/micropython/viper_ptr32_load_boundary.py +++ b/tests/micropython/viper_ptr32_load_boundary.py @@ -2,24 +2,38 @@ GET_TEMPLATE = """ @micropython.viper -def get{off}(src: ptr32) -> int: - return src[{off}] -print(b[{off} * 4:({off} + 1) * 4]) +def get{off}(src: ptr32) -> uint: + return uint(src[{off}]) +print(hex(get{off}(buffer))) """ +BIT_THRESHOLDS = (5, 8, 11, 12) +SIZE = 4 + + @micropython.viper def get_index(src: ptr32, i: int) -> int: return src[i] -b = bytearray(5000) -b[24:43] = b"0123456789ABCDEFGHIJ" -b[248:268] = b"KLMNOPQRSTUVWXYZabcd" -b[4088:4108] = b"efghijklmnopqrstuvwx" +def data(start, len): + output = bytearray(len) + for idx in range(len): + output[idx] = (start + idx) & 0xFF + return output + + +buffer = bytearray((((1 << max(BIT_THRESHOLDS)) + 1) // 1024) * 1024) +val = 0 +for bit in BIT_THRESHOLDS: + print("---", bit) + pre, idx, post = (((1 << bit) - (2 * SIZE)), ((1 << bit) - (1 * SIZE)), (1 << bit)) + buffer[pre:post] = data(val, 3 * SIZE) + val = val + (3 * SIZE) -for pre, idx, post in (7, 8, 9), (63, 64, 65), (1023, 1024, 1025): - print(get_index(b, pre), get_index(b, idx), get_index(b, post)) + pre, idx, post = pre // SIZE, idx // SIZE, post // SIZE + print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post))) exec(GET_TEMPLATE.format(off=pre)) exec(GET_TEMPLATE.format(off=idx)) exec(GET_TEMPLATE.format(off=post)) diff --git a/tests/micropython/viper_ptr32_load_boundary.py.exp b/tests/micropython/viper_ptr32_load_boundary.py.exp index a58e703f91..1e22a8b361 100644 --- a/tests/micropython/viper_ptr32_load_boundary.py.exp +++ b/tests/micropython/viper_ptr32_load_boundary.py.exp @@ -1,12 +1,20 @@ -926299444 1111570744 1178944579 -bytearray(b'4567') -bytearray(b'89AB') -bytearray(b'CDEF') -1381060687 1448432723 1515804759 -bytearray(b'OPQR') -bytearray(b'STUV') -bytearray(b'WXYZ') -1818978921 1886350957 1953722993 -bytearray(b'ijkl') -bytearray(b'mnop') -bytearray(b'qrst') +--- 5 +0x3020100 0x7060504 0xb0a0908 +0x3020100 +0x7060504 +0xb0a0908 +--- 8 +0xf0e0d0c 0x13121110 0x17161514 +0xf0e0d0c +0x13121110 +0x17161514 +--- 11 +0x1b1a1918 0x1f1e1d1c 0x23222120 +0x1b1a1918 +0x1f1e1d1c +0x23222120 +--- 12 +0x27262524 0x2b2a2928 0x2f2e2d2c +0x27262524 +0x2b2a2928 +0x2f2e2d2c diff --git a/tests/micropython/viper_ptr32_store_boundary.py b/tests/micropython/viper_ptr32_store_boundary.py index 243ff5cd9c..5109abb9dc 100644 --- a/tests/micropython/viper_ptr32_store_boundary.py +++ b/tests/micropython/viper_ptr32_store_boundary.py @@ -1,35 +1,58 @@ # Test boundary conditions for various architectures -TEST_DATA = ( - (3, (0x04030201, 0x08070605, 0x0C0B0A09)), - (63, (0x100F0E0D, 0x14131211, 0x18171615)), - (1023, (0x1C1B1A19, 0x201F1E1D, 0x24232221)), -) - SET_TEMPLATE = """ @micropython.viper def set{off}(dest: ptr32): - dest[{off}] = {val} & 0x3FFFFFFF -set{off}(b) -print(b[{off} * 4:({off} + 1) * 4]) + dest[{off}] = {val} +set{off}(buffer) +print(hex(get_index(buffer, {off}))) """ +BIT_THRESHOLDS = (5, 8, 11, 12) +SIZE = 4 +MASK = (1 << (8 * SIZE)) - 1 + @micropython.viper -def set_index(dest: ptr32, i: int, val: int): +def set_index(dest: ptr32, i: int, val: uint): dest[i] = val -b = bytearray(5000) -for start, vals in TEST_DATA: - for i, v in enumerate(vals): - set_index(b, start + i, v) - print(b[(start + i) * 4 : (start + i + 1) * 4]) - -for i in range(len(b)): - b[i] = 0 - - -for start, vals in TEST_DATA: - for i, v in enumerate(vals): - exec(SET_TEMPLATE.format(off=start + i, val=v + 0x01010101)) +def get_index(src, i): + return ( + src[i * SIZE] + + (src[(i * SIZE) + 1] << 8) + + (src[(i * SIZE) + 2] << 16) + + (src[(i * SIZE) + 3] << 24) + ) + + +buffer = bytearray(((1 << max(BIT_THRESHOLDS) + 1) // 1024) * 1024) +next = 1 +val = 0 +for bit in BIT_THRESHOLDS: + print("---", bit) + pre, idx, post = ( + (((1 << bit) - (2 * SIZE)) // SIZE), + (((1 << bit) - (1 * SIZE)) // SIZE), + ((1 << bit) // SIZE), + ) + val = (val << 8) + next + next += 1 + set_index(buffer, pre, val & MASK) + val = (val << 8) + next + next += 1 + set_index(buffer, idx, val & MASK) + val = (val << 8) + next + next += 1 + set_index(buffer, post, val & MASK) + val = (val << 8) + next + next += 1 + print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post))) + exec(SET_TEMPLATE.format(off=pre, val=val & MASK)) + val = (val << 8) + next + next += 1 + exec(SET_TEMPLATE.format(off=idx, val=val & MASK)) + val = (val << 8) + next + next += 1 + exec(SET_TEMPLATE.format(off=post, val=val & MASK)) diff --git a/tests/micropython/viper_ptr32_store_boundary.py.exp b/tests/micropython/viper_ptr32_store_boundary.py.exp index 89f09fbc7a..67b114d335 100644 --- a/tests/micropython/viper_ptr32_store_boundary.py.exp +++ b/tests/micropython/viper_ptr32_store_boundary.py.exp @@ -1,18 +1,20 @@ -bytearray(b'\x01\x02\x03\x04') -bytearray(b'\x05\x06\x07\x08') -bytearray(b'\t\n\x0b\x0c') -bytearray(b'\r\x0e\x0f\x10') -bytearray(b'\x11\x12\x13\x14') -bytearray(b'\x15\x16\x17\x18') -bytearray(b'\x19\x1a\x1b\x1c') -bytearray(b'\x1d\x1e\x1f ') -bytearray(b'!"#$') -bytearray(b'\x02\x03\x04\x05') -bytearray(b'\x06\x07\x08\t') -bytearray(b'\n\x0b\x0c\r') -bytearray(b'\x0e\x0f\x10\x11') -bytearray(b'\x12\x13\x14\x15') -bytearray(b'\x16\x17\x18\x19') -bytearray(b'\x1a\x1b\x1c\x1d') -bytearray(b'\x1e\x1f !') -bytearray(b'"#$%') +--- 5 +0x1 0x102 0x10203 +0x1020304 +0x2030405 +0x3040506 +--- 8 +0x4050607 0x5060708 0x6070809 +0x708090a +0x8090a0b +0x90a0b0c +--- 11 +0xa0b0c0d 0xb0c0d0e 0xc0d0e0f +0xd0e0f10 +0xe0f1011 +0xf101112 +--- 12 +0x10111213 0x11121314 0x12131415 +0x13141516 +0x14151617 +0x15161718 diff --git a/tests/micropython/viper_ptr8_load_boundary.py b/tests/micropython/viper_ptr8_load_boundary.py index bcb17a1e1f..57e06da570 100644 --- a/tests/micropython/viper_ptr8_load_boundary.py +++ b/tests/micropython/viper_ptr8_load_boundary.py @@ -2,24 +2,37 @@ GET_TEMPLATE = """ @micropython.viper -def get{off}(src: ptr8) -> int: - return src[{off}] -print(get{off}(b)) +def get{off}(src: ptr8) -> uint: + return uint(src[{off}]) +print(hex(get{off}(buffer))) """ +BIT_THRESHOLDS = (5, 8, 11, 12) +SIZE = 1 + + @micropython.viper def get_index(src: ptr8, i: int) -> int: return src[i] -b = bytearray(5000) -b[30:32] = b"123" -b[254:256] = b"456" -b[4094:4096] = b"789" +def data(start, len): + output = bytearray(len) + for idx in range(len): + output[idx] = (start + idx) & 0xFF + return output + + +buffer = bytearray((((1 << max(BIT_THRESHOLDS)) + 1) // 1024) * 1024) +val = 0 +for bit in BIT_THRESHOLDS: + print("---", bit) + pre, idx, post = (((1 << bit) - (2 * SIZE)), ((1 << bit) - (1 * SIZE)), (1 << bit)) + buffer[pre:post] = data(val, 3 * SIZE) + val = val + (3 * SIZE) -for pre, idx, post in (30, 31, 32), (254, 255, 256), (4094, 4095, 4096): - print(get_index(b, pre), get_index(b, idx), get_index(b, post)) + print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post))) exec(GET_TEMPLATE.format(off=pre)) exec(GET_TEMPLATE.format(off=idx)) exec(GET_TEMPLATE.format(off=post)) diff --git a/tests/micropython/viper_ptr8_load_boundary.py.exp b/tests/micropython/viper_ptr8_load_boundary.py.exp index 7cbd1ac78c..a0e423686b 100644 --- a/tests/micropython/viper_ptr8_load_boundary.py.exp +++ b/tests/micropython/viper_ptr8_load_boundary.py.exp @@ -1,12 +1,20 @@ -49 50 51 -49 -50 -51 -52 53 54 -52 -53 -54 -55 56 57 -55 -56 -57 +--- 5 +0x0 0x1 0x2 +0x0 +0x1 +0x2 +--- 8 +0x3 0x4 0x5 +0x3 +0x4 +0x5 +--- 11 +0x6 0x7 0x8 +0x6 +0x7 +0x8 +--- 12 +0x9 0xa 0xb +0x9 +0xa +0xb diff --git a/tests/micropython/viper_ptr8_store_boundary.py b/tests/micropython/viper_ptr8_store_boundary.py index ad51268454..e1fe6dcae3 100644 --- a/tests/micropython/viper_ptr8_store_boundary.py +++ b/tests/micropython/viper_ptr8_store_boundary.py @@ -1,30 +1,49 @@ # Test boundary conditions for various architectures -TEST_DATA = ((49, 30, 3), (52, 254, 3), (55, 4094, 3)) - SET_TEMPLATE = """ @micropython.viper def set{off}(dest: ptr8): dest[{off}] = {val} -set{off}(b) -print(b[{off}]) +set{off}(buffer) +print(hex(get_index(buffer, {off}))) """ +BIT_THRESHOLDS = (5, 8, 11, 12) +SIZE = 1 +MASK = (1 << (8 * SIZE)) - 1 + @micropython.viper -def set_index(dest: ptr8, i: int, val: int): +def set_index(dest: ptr8, i: int, val: uint): dest[i] = val -b = bytearray(5000) -for val, start, count in TEST_DATA: - for i in range(count): - set_index(b, start + i, val + i) - print(b[start : start + count]) - -for i in range(len(b)): - b[i] = 0 - -for val, start, count in TEST_DATA: - for i in range(count): - exec(SET_TEMPLATE.format(off=start + i, val=val + i + 16)) +def get_index(src: ptr8, i: int): + return src[i] + + +buffer = bytearray(((1 << max(BIT_THRESHOLDS) + 1) // 1024) * 1024) +next = 1 +val = 0 +for bit in BIT_THRESHOLDS: + print("---", bit) + pre, idx, post = (((1 << bit) - (2 * SIZE)), ((1 << bit) - (1 * SIZE)), (1 << bit)) + val = (val << 8) + next + next += 1 + set_index(buffer, pre, val & MASK) + val = (val << 8) + next + next += 1 + set_index(buffer, idx, val & MASK) + val = (val << 8) + next + next += 1 + set_index(buffer, post, val & MASK) + val = (val << 8) + next + next += 1 + print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post))) + exec(SET_TEMPLATE.format(off=pre, val=val & MASK)) + val = (val << 8) + next + next += 1 + exec(SET_TEMPLATE.format(off=idx, val=val & MASK)) + val = (val << 8) + next + next += 1 + exec(SET_TEMPLATE.format(off=post, val=val & MASK)) diff --git a/tests/micropython/viper_ptr8_store_boundary.py.exp b/tests/micropython/viper_ptr8_store_boundary.py.exp index a35cb3ac9e..6b0f7ce13e 100644 --- a/tests/micropython/viper_ptr8_store_boundary.py.exp +++ b/tests/micropython/viper_ptr8_store_boundary.py.exp @@ -1,12 +1,20 @@ -bytearray(b'123') -bytearray(b'456') -bytearray(b'789') -65 -66 -67 -68 -69 -70 -71 -72 -73 +--- 5 +0x1 0x2 0x3 +0x4 +0x5 +0x6 +--- 8 +0x7 0x8 0x9 +0xa +0xb +0xc +--- 11 +0xd 0xe 0xf +0x10 +0x11 +0x12 +--- 12 +0x13 0x14 0x15 +0x16 +0x17 +0x18 diff --git a/tests/misc/sys_settrace_cov.py b/tests/misc/sys_settrace_cov.py new file mode 100644 index 0000000000..579c8a4a25 --- /dev/null +++ b/tests/misc/sys_settrace_cov.py @@ -0,0 +1,23 @@ +import sys + +try: + sys.settrace +except AttributeError: + print("SKIP") + raise SystemExit + + +def trace_tick_handler(frame, event, arg): + print("FRAME", frame) + print("LASTI", frame.f_lasti) + return None + + +def f(): + x = 3 + return x + + +sys.settrace(trace_tick_handler) +f() +sys.settrace(None) diff --git a/tests/misc/sys_settrace_cov.py.exp b/tests/misc/sys_settrace_cov.py.exp new file mode 100644 index 0000000000..423d78ec42 --- /dev/null +++ b/tests/misc/sys_settrace_cov.py.exp @@ -0,0 +1,2 @@ +FRAME <frame at 0x\[0-9a-f\]\+, file '\.\*/sys_settrace_cov.py', line \\d\+, code f> +LASTI \\d\+ diff --git a/tests/multi_net/tcp_accept_recv.py b/tests/multi_net/tcp_accept_recv.py index dee14e3b97..4108a6f8a3 100644 --- a/tests/multi_net/tcp_accept_recv.py +++ b/tests/multi_net/tcp_accept_recv.py @@ -1,30 +1,73 @@ -# Test recv on socket that just accepted a connection +# Test recv on listening socket after accept(), with various listen() arguments import socket PORT = 8000 +# Test cases for listen() function +LISTEN_ARGS = [None, 0, 1, 2] # None means no argument + # Server def instance0(): multitest.globals(IP=multitest.get_network_ip()) - s = socket.socket() - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1]) - s.listen(1) multitest.next() - s.accept() - try: - print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN - except OSError as er: - print(er.errno in (107, 128)) - s.close() + + test_num = 0 + for blocking_mode in [True, False]: + for listen_arg in LISTEN_ARGS: + test_num += 1 + s = socket.socket() + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1]) + + # Call listen with or without argument based on test case + if listen_arg is None: + print(f"Test case {test_num}/8: listen() blocking={blocking_mode}") + s.listen() + else: + print(f"Test case {test_num}/8: listen({listen_arg}) blocking={blocking_mode}") + s.listen(listen_arg) + + # Signal client that server is ready + multitest.broadcast(f"server_ready_{test_num}") + + # Wait for client connection + c, _ = s.accept() + + # Set blocking mode after accept + s.setblocking(blocking_mode) + + try: + print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN + except OSError as er: + # Verify the error code is either 107 (ENOTCONN) or 128 (ENOTCONN on Windows) + print(er.errno in (107, 128)) + + # Cleanup + c.close() + s.close() + + # Signal client we're done with this test case + multitest.broadcast(f"server_done_{test_num}") # Client def instance1(): multitest.next() - s = socket.socket() - s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) - s.send(b"GET / HTTP/1.0\r\n\r\n") - s.close() + + test_num = 0 + for blocking_mode in [True, False]: + for _ in LISTEN_ARGS: + test_num += 1 + # Wait for server to be ready + multitest.wait(f"server_ready_{test_num}") + + # Connect to server + s = socket.socket() + s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) + s.send(b"GET / HTTP/1.0\r\n\r\n") + s.close() + + # Wait for server to finish this test case + multitest.wait(f"server_done_{test_num}") diff --git a/tests/ports/unix/extra_coverage.py.exp b/tests/ports/unix/extra_coverage.py.exp index ac64edde69..ed21ced242 100644 --- a/tests/ports/unix/extra_coverage.py.exp +++ b/tests/ports/unix/extra_coverage.py.exp @@ -69,8 +69,8 @@ argv atexit byteorder exc_info executable exit getsizeof implementation intern maxsize modules path platform print_exception ps1 -ps2 stderr stdin stdout -tracebacklimit version version_info +ps2 settrace stderr stdin +stdout tracebacklimit version version_info ementation # attrtuple (start=1, stop=2, step=3) diff --git a/tests/ports/webassembly/py_proxy_has.mjs b/tests/ports/webassembly/py_proxy_has.mjs index 8881776fdb..37df0ae179 100644 --- a/tests/ports/webassembly/py_proxy_has.mjs +++ b/tests/ports/webassembly/py_proxy_has.mjs @@ -9,3 +9,5 @@ x = [] const x = mp.globals.get("x"); console.log("no_exist" in x); console.log("sort" in x); +console.log(Symbol.toStringTag in x); +console.log(Symbol.iterator in x); diff --git a/tests/ports/webassembly/py_proxy_has.mjs.exp b/tests/ports/webassembly/py_proxy_has.mjs.exp index 1d474d5255..7565230c01 100644 --- a/tests/ports/webassembly/py_proxy_has.mjs.exp +++ b/tests/ports/webassembly/py_proxy_has.mjs.exp @@ -1,2 +1,4 @@ false true +false +true diff --git a/tests/run-tests.py b/tests/run-tests.py index 628fde9d30..faf1d2e3b4 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -16,7 +16,7 @@ import threading import tempfile # Maximum time to run a PC-based test, in seconds. -TEST_TIMEOUT = 30 +TEST_TIMEOUT = float(os.environ.get('MICROPY_TEST_TIMEOUT', 30)) # See stackoverflow.com/questions/2632199: __file__ nor sys.argv[0] # are guaranteed to always work, this one should though. @@ -95,6 +95,7 @@ class __FS: return __File() vfs.mount(__FS(), '/__vfstest') os.chdir('/__vfstest') +{import_prologue} __import__('__injected_test') """ @@ -353,6 +354,7 @@ special_tests = [ "micropython/meminfo.py", "basics/bytes_compare3.py", "basics/builtin_help.py", + "misc/sys_settrace_cov.py", "thread/thread_exc2.py", "ports/esp32/partition_ota.py", ) @@ -1130,6 +1132,8 @@ class append_filter(argparse.Action): def main(): + global injected_import_hook_code + cmd_parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="""Run and manage tests for MicroPython. @@ -1239,8 +1243,20 @@ the last matching regex is used: action="store_true", help="re-run only the failed tests", ) + cmd_parser.add_argument( + "--begin", + metavar="PROLOGUE", + default=None, + help="prologue python file to execute before module import", + ) args = cmd_parser.parse_args() + prologue = "" + if args.begin: + with open(args.begin, "rt") as source: + prologue = source.read() + injected_import_hook_code = injected_import_hook_code.replace("{import_prologue}", prologue) + if args.print_failures: for out in glob(os.path.join(args.result_dir, "*.out")): testbase = out[:-4] |