tests/ports/stm32_hardware: Convert DMA test to use unittest.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -1,43 +1,59 @@
|
|||||||
from machine import SPI
|
|
||||||
# Regression test for DMA for DCache coherency bugs with cache line
|
# Regression test for DMA for DCache coherency bugs with cache line
|
||||||
# written originally for https://github.com/micropython/micropython/issues/13471
|
# written originally for https://github.com/micropython/micropython/issues/13471
|
||||||
|
|
||||||
# IMPORTANT: This test requires SPI2 MISO (pin Y8 on Pyboard D) to be connected to GND
|
# IMPORTANT: This test requires SPI2 MISO (pin Y8 on Pyboard D) to be connected to GND
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from machine import SPI
|
||||||
|
|
||||||
SPI_NUM = 2
|
SPI_NUM = 2
|
||||||
|
BAUDRATE = 5_000_000
|
||||||
|
|
||||||
spi = SPI(SPI_NUM, baudrate=5_000_000)
|
|
||||||
buf = bytearray(1024)
|
|
||||||
ok = True
|
|
||||||
|
|
||||||
for offs in range(0, len(buf)):
|
class Test(unittest.TestCase):
|
||||||
v = memoryview(buf)[offs : offs + 128]
|
@classmethod
|
||||||
spi.readinto(v, 0xFF)
|
def setUpClass(cls):
|
||||||
if not all(b == 0x00 for b in v):
|
cls.spi = SPI(SPI_NUM, baudrate=BAUDRATE)
|
||||||
print(offs, v.hex())
|
cls.skip_slow_test = False
|
||||||
ok = False
|
|
||||||
|
|
||||||
print("Variable offset fixed length " + ("OK" if ok else "FAIL"))
|
def test_variable_offset_fixed_length(self):
|
||||||
|
buf = bytearray(1024)
|
||||||
|
for offs in range(0, len(buf)):
|
||||||
|
v = memoryview(buf)[offs : offs + 128]
|
||||||
|
self.spi.readinto(v, 0xFF)
|
||||||
|
ok = all(b == 0x00 for b in v)
|
||||||
|
if not ok:
|
||||||
|
print(offs, v.hex())
|
||||||
|
self.skip_slow_test = True
|
||||||
|
self.assertTrue(ok)
|
||||||
|
|
||||||
# this takes around 30s to run, so skipped if already failing
|
def test_variable_offset_and_lengths(self):
|
||||||
if ok:
|
# this takes around 30s to run, so skipped if already failing
|
||||||
for op_len in range(1, 66):
|
if self.skip_slow_test:
|
||||||
wr = b"\xFF" * op_len
|
self.skipTest("already failing")
|
||||||
for offs in range(1, len(buf) - op_len - 1):
|
|
||||||
# Place some "sentinel" values before and after the DMA buffer
|
|
||||||
before = offs & 0xFF
|
|
||||||
after = (~offs) & 0xFF
|
|
||||||
buf[offs - 1] = before
|
|
||||||
buf[offs + op_len] = after
|
|
||||||
v = memoryview(buf)[offs : offs + op_len]
|
|
||||||
spi.write_readinto(wr, v)
|
|
||||||
if (
|
|
||||||
not all(b == 0x00 for b in v)
|
|
||||||
or buf[offs - 1] != before
|
|
||||||
or buf[offs + op_len] != after
|
|
||||||
):
|
|
||||||
print(v.hex())
|
|
||||||
print(hex(op_len), hex(offs), hex(buf[offs - 1]), hex(buf[offs + op_len]))
|
|
||||||
ok = False
|
|
||||||
|
|
||||||
print("Variable offset and lengths " + ("OK" if ok else "FAIL"))
|
buf = bytearray(1024)
|
||||||
|
for op_len in range(1, 66):
|
||||||
|
print(op_len)
|
||||||
|
wr = b"\xff" * op_len
|
||||||
|
for offs in range(1, len(buf) - op_len - 1):
|
||||||
|
# Place some "sentinel" values before and after the DMA buffer
|
||||||
|
before = offs & 0xFF
|
||||||
|
after = (~offs) & 0xFF
|
||||||
|
buf[offs - 1] = before
|
||||||
|
buf[offs + op_len] = after
|
||||||
|
v = memoryview(buf)[offs : offs + op_len]
|
||||||
|
self.spi.write_readinto(wr, v)
|
||||||
|
ok = (
|
||||||
|
all(b == 0x00 for b in v)
|
||||||
|
and buf[offs - 1] == before
|
||||||
|
and buf[offs + op_len] == after
|
||||||
|
)
|
||||||
|
if not ok:
|
||||||
|
print(v.hex())
|
||||||
|
print(hex(op_len), hex(offs), hex(buf[offs - 1]), hex(buf[offs + op_len]))
|
||||||
|
self.assertTrue(ok)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
Variable offset fixed length OK
|
|
||||||
Variable offset and lengths OK
|
|
||||||
Reference in New Issue
Block a user