Skip to content

Commit

Permalink
tests: Normalized test interface and added a little bit of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lethalbit committed Jan 15, 2025
1 parent 150a646 commit d91b691
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 61 deletions.
472 changes: 446 additions & 26 deletions squishy/support/test.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/gateware/bootloader/test_bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from squishy.core.config import FlashConfig
from squishy.core.flash import Geometry
from squishy.support.test import SquishyGatewareTest, USBGatewarePHYTestHelpers
from squishy.support.test import USBGatewarePHYTest
from squishy.core.dfu import DFUState, DFUStatus


Expand Down Expand Up @@ -143,7 +143,7 @@ def elaborate(self, _) -> Module:
return m


class BootloaderTests(USBGatewarePHYTestHelpers, SquishyGatewareTest):
class BootloaderTests(USBGatewarePHYTest):
dut: SquishyBootloader = SquishyBootloader
dut_args = {
'serial_number': 'TEST',
Expand All @@ -152,7 +152,7 @@ class BootloaderTests(USBGatewarePHYTestHelpers, SquishyGatewareTest):
domains = (('sync', 170e6), )
platform = DUTPlatform()

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs, raw_record = _USB_RECORD)

def dfu_get_status(self, *, addr: int, exepected_status: DFUStatus, expected_state: DFUState):
Expand Down
8 changes: 3 additions & 5 deletions tests/gateware/bootloader/test_rev1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from torii.sim import Settle
from torii.test import ToriiTestCase

from squishy.support.test import SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers
from squishy.support.test import USBGatewareTest, DFUGatewareTest
from squishy.core.config import FlashConfig
from squishy.core.flash import Geometry

Expand Down Expand Up @@ -84,17 +84,15 @@ def elaborate(self, _) -> Module:

return m

class Rev1BootloaderTests(SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers):
class Rev1BootloaderTests(USBGatewareTest, DFUGatewareTest):
dut: DUTWrapper = DUTWrapper
dut_args = {}
domains = (('sync', 80e6), )
platform = DFUPlatform()

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

USBGatewareTestHelpers.setup_helper(self)

def spi_trans(self, *,
copi: tuple[int, ...] | None = None, cipo: tuple[int, ...] | None = None, partial: bool = False, continuation: bool = False
):
Expand Down
8 changes: 3 additions & 5 deletions tests/gateware/bootloader/test_rev2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from torii.sim import Settle
from torii.test import ToriiTestCase

from squishy.support.test import SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers
from squishy.support.test import USBGatewareTest, DFUGatewareTest
from squishy.core.config import FlashConfig
from squishy.core.flash import Geometry

Expand Down Expand Up @@ -114,17 +114,15 @@ def elaborate(self, _) -> Module:
return m


class Rev2BootloaderTests(SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers):
class Rev2BootloaderTests(USBGatewareTest, DFUGatewareTest):
dut: DUTWrapper = DUTWrapper
dut_args = {}
domains = (('sync', 80e6), ('supervisor', 36e6),)
platform = DUTPlatform()

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

USBGatewareTestHelpers.setup_helper(self)


def send_recv_supervisor(self, addr: int | None, data_in: int, data_out: int, term: bool = True):
self.assertEqual((yield _SUPERVISOR_RECORD.clk.i), 0)
Expand Down
7 changes: 6 additions & 1 deletion tests/gateware/peripherals/test_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from torii.test import ToriiTestCase
from torii.test.mock import MockPlatform


from squishy.support.test import SPIGatewareTest
from squishy.core.flash import Geometry
from squishy.core.config import FlashConfig
from squishy.gateware.peripherals.flash import SPIFlash
Expand Down Expand Up @@ -99,14 +101,17 @@ def elaborate(self, _) -> Module:
return m


class SPIFlashTests(ToriiTestCase):
class SPIFlashTests(SPIGatewareTest):
dut: DUTWrapper = DUTWrapper
dut_args = {
'resource': ('spi_flash_x1', 0)
}
domains = (('sync', 60e6), ('usb', 60e6))
platform = MockPlatform()

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def spi_trans(self, *,
copi: tuple[int, ...] | None = None, cipo: tuple[int, ...] | None = None, partial: bool = False, continuation: bool = False
):
Expand Down
6 changes: 5 additions & 1 deletion tests/gateware/peripherals/test_psram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from torii.test import ToriiTestCase
from torii.test.mock import MockPlatform

from squishy.support.test import SPIGatewareTest
from squishy.gateware.peripherals.spi import SPIController, SPICPOL
from squishy.gateware.peripherals.psram import SPIPSRAM, SPIPSRAMCmd

Expand Down Expand Up @@ -69,12 +70,15 @@ def elaborate(self, _) -> Module:
return m


class SPIPSRAMTests(ToriiTestCase):
class SPIPSRAMTests(SPIGatewareTest):
dut: DUTWrapper = DUTWrapper
dut_args = { }
domains = (('sync', 60e6), ('test', 60e6))
platform = MockPlatform()

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def fill_write_fifo(self, byte: int, idx: int):
final = idx == len(_PSRAM_DATA) - 1
do_cont = (idx & 1023) != 1023
Expand Down
18 changes: 15 additions & 3 deletions tests/gateware/peripherals/test_spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from torii.lib.soc.csr.bus import Multiplexer, Element

from squishy.support.test import SPIGatewareTest
from squishy.gateware.peripherals.spi import SPIInterface, SPIController, SPIPeripheral, SPIInterfaceMode, SPICPOL

clk = Signal(name = 'bus_clk' )
Expand All @@ -15,13 +16,17 @@
cipo = Signal(name = 'bus_cipo')


class SPIControllerCLKHighTests(ToriiTestCase):
class SPIControllerCLKHighTests(SPIGatewareTest):
dut: SPIController = SPIController
dut_args = {
'clk': clk, 'cipo': cipo, 'copi': copi, 'cs': cs, 'cpol': SPICPOL.HIGH
}
domains = (('sync', 170e6), )
platform = MockPlatform()

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def send_recv(self, d_out, d_in, ovlp = False):
self.assertEqual((yield clk), 1)
yield self.dut.wdat.eq(d_out)
Expand Down Expand Up @@ -76,13 +81,17 @@ def test_spi_controller(self):
yield Settle()
yield

class SPIControllerCLKLowTests(ToriiTestCase):
class SPIControllerCLKLowTests(SPIGatewareTest):
dut: SPIController = SPIController
dut_args = {
'clk': clk, 'cipo': cipo, 'copi': copi, 'cs': cs, 'cpol': SPICPOL.LOW
}
domains = (('sync', 170e6), )
platform = MockPlatform()

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def send_recv(self, d_out, d_in, ovlp = False):
self.assertEqual((yield clk), 0)
yield self.dut.wdat.eq(d_out)
Expand Down Expand Up @@ -206,12 +215,15 @@ def elaborate(self, _) -> Module:

return m

class SPIPeripheralTests(ToriiTestCase):
class SPIPeripheralTests(SPIGatewareTest):
dut: PeripheralDUTWrapper = PeripheralDUTWrapper
dut_args = { }
domains = (('sync', 100e6), ('test', 15e6))
platform = MockPlatform()

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def send_recv(self, addr: int | None, data_in: int, data_out: int, term: bool = True):
self.assertEqual((yield clk), 0)
# Select the peripheral so we go into `READ_ADDR`
Expand Down
14 changes: 5 additions & 9 deletions tests/gateware/usb/quirks/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from usb_construct.types import USBRequestRecipient, USBRequestType
from usb_construct.types.descriptors.microsoft import MicrosoftRequests

from squishy.support.test import SquishyGatewareTest, USBGatewareTestHelpers
from squishy.support.test import USBGatewareTest
from squishy.gateware.usb.quirks.windows import GetDescriptorSetHandler, WindowsRequestHandler

def _make_platform_descriptors():
Expand All @@ -29,18 +29,16 @@ def _make_platform_descriptors():
return (desc_collection, desc_collection.descriptors)


class GetDescriptorSetHandlerTests(SquishyGatewareTest, USBGatewareTestHelpers):
class GetDescriptorSetHandlerTests(USBGatewareTest):
_desc_collection, _descriptors = _make_platform_descriptors()
dut: GetDescriptorSetHandler = GetDescriptorSetHandler
dut_args = {
'desc_collection': _desc_collection
}

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

USBGatewareTestHelpers.setup_helper(self)


@ToriiTestCase.simulation
@ToriiTestCase.sync_domain(domain = 'usb')
Expand Down Expand Up @@ -132,18 +130,16 @@ def test_get_desc_set(self):
yield Settle()
yield

class WindowsRequestHandlerTests(SquishyGatewareTest, USBGatewareTestHelpers):
class WindowsRequestHandlerTests(USBGatewareTest):
_desc_collection, _descriptors = _make_platform_descriptors()
dut: WindowsRequestHandler = WindowsRequestHandler
dut_args = {
'descriptors': _desc_collection
}

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

USBGatewareTestHelpers.setup_helper(self)

@ToriiTestCase.simulation
@ToriiTestCase.sync_domain(domain = 'usb')
def test_windows_request(self):
Expand Down
13 changes: 5 additions & 8 deletions tests/gateware/usb/test_dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from torii.sim import Settle
from torii.test import ToriiTestCase

from squishy.support.test import SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers
from squishy.support.test import USBGatewareTest, DFUGatewareTest
from squishy.gateware.usb.dfu import DFURequestHandler, DFUState
from squishy.core.config import FlashConfig
from squishy.core.flash import Geometry
Expand Down Expand Up @@ -62,18 +62,17 @@ class DFUPlatform:
def request(self, name, number):
return _SPI_RECORD

class DFURequestHandlerStubTests(SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers):
class DFURequestHandlerStubTests(USBGatewareTest, DFUGatewareTest):
dut: DFURequestHandler = DFURequestHandler
dut_args = {
'configuration': 1,
'interface': 0,
'boot_stub': True
}

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

USBGatewareTestHelpers.setup_helper(self)

@ToriiTestCase.simulation
@ToriiTestCase.sync_domain(domain = 'usb')
Expand Down Expand Up @@ -114,16 +113,14 @@ def elaborate(self, platform) -> Module:
return m

# TODO(aki): We need to build a DUTWrapper for this test now
class DFURequestHandlerTests(SquishyGatewareTest, USBGatewareTestHelpers, DFUGatewareTestHelpers):
class DFURequestHandlerTests(USBGatewareTest, DFUGatewareTest):
dut: DUTWrapper = DUTWrapper
dut_args = {}
platform = DFUPlatform()

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

USBGatewareTestHelpers.setup_helper(self)

@ToriiTestCase.simulation
@ToriiTestCase.sync_domain(domain = 'usb')
def test_dfu_handler(self):
Expand Down

0 comments on commit d91b691

Please sign in to comment.