Skip to content

tests: rename port-specific test dirs to start with port_, and add rp2 specific tests #13468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions tests/extmod/machine_i2s_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
import time, sys

# Configure pins based on the board.
# A board must have at least one instance to test, both TX and RX mode.
if "pyboard" in sys.platform:
i2s_id = 2
sck_pin = Pin("Y6")
ws_pin = Pin("Y5")
sd_tx_pin = sd_rx_pin = Pin("Y8")
i2s_instances = ((2, Pin("Y6"), Pin("Y5"), Pin("Y8"), Pin("Y8")),)
elif "rp2" in sys.platform:
i2s_id = 1
sck_pin = Pin(0)
ws_pin = Pin(1)
sd_tx_pin = sd_rx_pin = Pin(2)
i2s_instances = (
(0, Pin(0), Pin(1), Pin(2), Pin(2)),
(1, Pin(0), Pin(1), Pin(2), Pin(2)),
)
elif "mimxrt" in sys.platform:
i2s_id = 1
sck_pin = Pin(26)
ws_pin = Pin(27)
sd_tx_pin = Pin(7)
sd_rx_pin = Pin(8)
i2s_instances = (
(1, Pin("D26"), Pin("D27"), Pin("D7"), Pin("D8")),
(2, Pin("D4"), Pin("D3"), Pin("D2"), None),
)

TEST_BYTES = b"01234567"
RATE = 11025 # frames/sec


def test(mode, sd_pin, bits_per_sample, frame_format):
def test(i2s_id, sck_pin, ws_pin, sd_pin, mode, bits_per_sample, frame_format):
if sd_pin is None:
return

i2s = I2S(
i2s_id,
sck=sck_pin,
Expand All @@ -48,16 +48,16 @@ def test(mode, sd_pin, bits_per_sample, frame_format):
else:
channels = 2
bits_per_frame = bits_per_sample * channels
buf_len_250ms = bits_per_frame // 8 * RATE // 4
buf_len_200ms = bits_per_frame // 8 * RATE // 5

# Create test data and preload I2S buffers.
if mode == I2S.TX:
mode_str = "TX"
data = TEST_BYTES * (buf_len_250ms // len(TEST_BYTES))
data = TEST_BYTES * (buf_len_200ms // len(TEST_BYTES))
i2s.write(data)
else:
mode_str = "RX"
data = bytearray(len(TEST_BYTES) * (buf_len_250ms // len(TEST_BYTES)))
data = bytearray(len(TEST_BYTES) * (buf_len_200ms // len(TEST_BYTES)))
i2s.readinto(data)

# Time how long it takes to read/write 2 lots of data.
Expand All @@ -72,15 +72,27 @@ def test(mode, sd_pin, bits_per_sample, frame_format):

i2s.deinit()

# Print out test result, time should be in range of 500ms.
print(mode_str, bits_per_sample, channels, abs(dt - 500) <= 4)
# Time should be in range of 400ms.
time_in_range = abs(dt - 400) <= 4

# Print out test result if requested, or if time not in range.
if print_results or not time_in_range:
print(mode_str, bits_per_sample, channels, time_in_range)


print_results = True

for i2s_id, sck_pin, ws_pin, sd_tx_pin, sd_rx_pin in i2s_instances:
test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 16, I2S.MONO)
test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 16, I2S.STEREO)
test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 32, I2S.MONO)
test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 32, I2S.STEREO)
test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 16, I2S.MONO)
test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 16, I2S.STEREO)
test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 32, I2S.MONO)
test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 32, I2S.STEREO)

test(I2S.TX, sd_tx_pin, 16, I2S.MONO)
test(I2S.TX, sd_tx_pin, 16, I2S.STEREO)
test(I2S.TX, sd_tx_pin, 32, I2S.MONO)
test(I2S.TX, sd_tx_pin, 32, I2S.STEREO)
test(I2S.RX, sd_rx_pin, 16, I2S.MONO)
test(I2S.RX, sd_rx_pin, 16, I2S.STEREO)
test(I2S.RX, sd_rx_pin, 32, I2S.MONO)
test(I2S.RX, sd_rx_pin, 32, I2S.STEREO)
# For any remaining tests, don't print the results if they pass.
# This is to have the same output on all boards regardless of
# how many I2S instances they test.
print_results = False
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions tests/ports/rp2/rp2_dma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Test rp2.DMA functionality.

import time
import machine
import rp2

src = bytes(i & 0xFF for i in range(16 * 1024))

print("# test basic usage")

dma = rp2.DMA()
print(dma)
print(rp2.DMA.unpack_ctrl(dma.pack_ctrl()))
dma.read = 0
dma.write = 0
dma.count = 0
dma.ctrl = dma.pack_ctrl()
print(dma.read, dma.write, dma.count, dma.ctrl & 0x01FFFFFF, dma.channel, dma.registers)
dma.close()

# Test closing when already closed.
dma.close()

# Test using when closed.
try:
dma.active()
assert False
except ValueError:
print("ValueError")

# Test simple memory copy.
print("# test memory copy")
dest = bytearray(1024)
dma = rp2.DMA()
dma.config(read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(), trigger=False)
print(not any(dest))
dma.active(True)
while dma.active():
pass
print(dest[:8], dest[-8:])
dma.close()


# Test time taken for a large memory copy.
def run_and_time_dma(dma):
ticks_us = time.ticks_us
irq_state = machine.disable_irq()
t0 = ticks_us()
dma.active(True)
while dma.active():
pass
t1 = ticks_us()
machine.enable_irq(irq_state)
return time.ticks_diff(t1, t0)


print("# test timing")
dest = bytearray(16 * 1024)
dma = rp2.DMA()
dma.read = src
dma.write = dest
dma.count = len(dest) // 4
dma.ctrl = dma.pack_ctrl()
dt = run_and_time_dma(dma)
print(60 <= dt <= 90)
print(dest[:8], dest[-8:])
dma.close()

# Test using .config(trigger=True).
print("# test immediate trigger")
dest = bytearray(1024)
dma = rp2.DMA()
dma.config(read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(), trigger=True)
while dma.active():
pass
print(dest[:8], dest[-8:])
dma.close()

# Test the DMA.irq() method.
print("# test irq")
dest = bytearray(1024)
dma = rp2.DMA()
dma.irq(lambda _: print("irq fired"))
dma.config(
read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(irq_quiet=0), trigger=True
)
while dma.active():
pass
print(dest[:8], dest[-8:])
dma.close()
16 changes: 16 additions & 0 deletions tests/ports/rp2/rp2_dma.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# test basic usage
DMA(0)
{'inc_read': 1, 'high_pri': 0, 'write_err': 0, 'ring_sel': 0, 'enable': 1, 'treq_sel': 63, 'sniff_en': 0, 'irq_quiet': 1, 'read_err': 0, 'chain_to': 0, 'busy': 0, 'inc_write': 1, 'ring_size': 0, 'bswap': 0, 'size': 2, 'ahb_err': 0}
0 0 0 4161593 0 <memoryview>
ValueError
# test memory copy
True
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
# test timing
True
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
# test immediate trigger
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
# test irq
irq fired
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def run_script_on_remote_target(pyb, args, test_file, is_special):
"basics/bytes_compare3.py",
"basics/builtin_help.py",
"thread/thread_exc2.py",
"esp32/partition_ota.py",
"ports/esp32/partition_ota.py",
)
]

Expand Down Expand Up @@ -1036,16 +1036,16 @@ def main():
)
if args.target == "pyboard":
# run pyboard tests
test_dirs += ("float", "stress", "pyb", "inlineasm")
test_dirs += ("float", "stress", "inlineasm", "ports/stm32")
elif args.target in ("renesas-ra"):
test_dirs += ("float", "inlineasm", "renesas-ra")
test_dirs += ("float", "inlineasm", "ports/renesas-ra")
elif args.target == "rp2":
test_dirs += ("float", "stress", "inlineasm", "thread")
test_dirs += ("float", "stress", "inlineasm", "thread", "ports/rp2")
elif args.target in ("esp8266", "esp32", "minimal", "nrf"):
test_dirs += ("float",)
elif args.target == "wipy":
# run WiPy tests
test_dirs += ("wipy",)
test_dirs += ("ports/cc3200",)
elif args.target == "unix":
# run PC tests
test_dirs += (
Expand All @@ -1054,8 +1054,8 @@ def main():
"io",
"stress",
"unicode",
"unix",
"cmdline",
"ports/unix",
)
elif args.target == "qemu-arm":
if not args.write_exp:
Expand All @@ -1065,7 +1065,7 @@ def main():
test_dirs += (
"float",
"inlineasm",
"qemu-arm",
"ports/qemu-arm",
)
else:
# run tests from these directories
Expand Down
2 changes: 1 addition & 1 deletion tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ function ci_unix_build_helper {
}

function ci_unix_build_ffi_lib_helper {
$1 $2 -shared -o tests/unix/ffi_lib.so tests/unix/ffi_lib.c
$1 $2 -shared -o tests/ports/unix/ffi_lib.so tests/ports/unix/ffi_lib.c
}

function ci_unix_run_tests_helper {
Expand Down