Skip to content

Commit 3cce743

Browse files
authored
Merge pull request #245 from miek/test_reorg
Reorganise tests/CI
2 parents b6097ae + c575b0b commit 3cce743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3755
-3821
lines changed

.github/workflows/simulate.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ jobs:
1515
strategy:
1616
max-parallel: 5
1717
matrix:
18-
python-version: [3.9]
18+
python-version:
19+
- '3.8'
20+
- '3.9'
21+
- '3.10'
22+
- '3.11'
23+
- '3.12'
1924

25+
name: test (${{ matrix.python-version }})
2026
steps:
2127
- uses: actions/checkout@v1
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
28+
- name: Set up PDM
29+
uses: pdm-project/setup-pdm@v4
2430
with:
2531
python-version: ${{ matrix.python-version }}
2632
- name: Install dependencies
2733
run: |
28-
python -m pip install --upgrade pip
29-
pip install tox tox-gh-actions
30-
- name: Test with tox
31-
run: tox
34+
pdm install
35+
- name: Run tests
36+
run: pdm run test

luna/gateware/architecture/car.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from amaranth import Signal, Module, ClockDomain, ClockSignal, Elaboratable, Instance, ResetSignal
1313

1414
from ..utils.cdc import stretch_strobe_signal
15-
from ..test import LunaGatewareTestCase, usb_domain_test_case, sync_test_case
1615

1716

1817
class PHYResetController(Elaboratable):
@@ -95,39 +94,6 @@ def elaborate(self, platform):
9594

9695

9796

98-
class PHYResetControllerTest(LunaGatewareTestCase):
99-
FRAGMENT_UNDER_TEST = PHYResetController
100-
101-
def initialize_signals(self):
102-
yield self.dut.trigger.eq(0)
103-
104-
@sync_test_case
105-
def test_power_on_reset(self):
106-
107-
#
108-
# After power-on, the PHY should remain in reset for a while.
109-
#
110-
yield
111-
self.assertEqual((yield self.dut.phy_reset), 1)
112-
113-
yield from self.advance_cycles(30)
114-
self.assertEqual((yield self.dut.phy_reset), 1)
115-
116-
yield from self.advance_cycles(60)
117-
self.assertEqual((yield self.dut.phy_reset), 1)
118-
119-
#
120-
# Then, after the relevant reset time, it should resume being unasserted.
121-
#
122-
yield from self.advance_cycles(31)
123-
self.assertEqual((yield self.dut.phy_reset), 0)
124-
self.assertEqual((yield self.dut.phy_stop), 1)
125-
126-
yield from self.advance_cycles(120)
127-
self.assertEqual((yield self.dut.phy_stop), 0)
128-
129-
130-
13197
class LunaDomainGenerator(Elaboratable, metaclass=ABCMeta):
13298
""" Helper that generates the clock domains used in a LUNA board.
13399

luna/gateware/debug/console.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
from amaranth import Signal, Module, Cat, Elaboratable, Array
11-
from ..test.utils import LunaGatewareTestCase, sync_test_case
1211

1312

1413
class DebugConsole(Elaboratable):

luna/gateware/debug/ila.py

Lines changed: 1 addition & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import os
1111
import sys
1212
import math
13-
import unittest
1413
import tempfile
1514
import subprocess
1615

@@ -24,8 +23,7 @@
2423

2524
from ..stream import StreamInterface
2625
from ..interface.uart import UARTMultibyteTransmitter
27-
from ..interface.spi import SPIDeviceInterface, SPIBus, SPIGatewareTestCase
28-
from ..test.utils import LunaGatewareTestCase, sync_test_case
26+
from ..interface.spi import SPIDeviceInterface, SPIBus
2927

3028

3129
class IntegratedLogicAnalyzer(Elaboratable):
@@ -172,105 +170,6 @@ def elaborate(self, platform):
172170
return m
173171

174172

175-
class IntegratedLogicAnalyzerTest(LunaGatewareTestCase):
176-
177-
def instantiate_dut(self):
178-
self.input_a = Signal()
179-
self.input_b = Signal(30)
180-
self.input_c = Signal()
181-
182-
return IntegratedLogicAnalyzer(
183-
signals=[self.input_a, self.input_b, self.input_c],
184-
sample_depth = 32
185-
)
186-
187-
188-
def initialize_signals(self):
189-
yield self.input_a .eq(0)
190-
yield self.input_b .eq(0)
191-
yield self.input_c .eq(0)
192-
193-
194-
def provide_all_signals(self, value):
195-
all_signals = Cat(self.input_a, self.input_b, self.input_c)
196-
yield all_signals.eq(value)
197-
198-
199-
def assert_sample_value(self, address, value):
200-
""" Helper that asserts a ILA sample has a given value. """
201-
202-
yield self.dut.captured_sample_number.eq(address)
203-
yield
204-
# Delay a clock to allow the block ram to latch the new value
205-
yield
206-
try:
207-
self.assertEqual((yield self.dut.captured_sample), value)
208-
return
209-
except AssertionError:
210-
pass
211-
212-
# Generate an appropriate exception.
213-
actual_value = (yield self.dut.captured_sample)
214-
message = "assertion failed: at address 0x{:08x}: {:08x} != {:08x} (expected)".format(address, actual_value, value)
215-
raise AssertionError(message)
216-
217-
218-
@sync_test_case
219-
def test_sampling(self):
220-
221-
# Quick helper that generates simple, repetitive samples.
222-
def sample_value(i):
223-
return i | (i << 8) | (i << 16) | (0xFF << 24)
224-
225-
yield from self.provide_all_signals(0xDEADBEEF)
226-
yield
227-
228-
# Before we trigger, we shouldn't be capturing any samples,
229-
# and we shouldn't be complete.
230-
self.assertEqual((yield self.dut.sampling), 0)
231-
self.assertEqual((yield self.dut.complete), 0)
232-
233-
# Advance a bunch of cycles, and ensure we don't start sampling.
234-
yield from self.advance_cycles(10)
235-
self.assertEqual((yield self.dut.sampling), 0)
236-
237-
# Set a new piece of data for a couple of cycles.
238-
yield from self.provide_all_signals(0x01234567)
239-
yield
240-
yield from self.provide_all_signals(0x89ABCDEF)
241-
yield
242-
243-
# Finally, trigger the capture.
244-
yield from self.provide_all_signals(sample_value(0))
245-
yield from self.pulse(self.dut.trigger, step_after=False)
246-
247-
yield from self.provide_all_signals(sample_value(1))
248-
yield
249-
250-
# After we pulse our trigger strobe, we should be sampling.
251-
self.assertEqual((yield self.dut.sampling), 1)
252-
253-
# Populate the memory with a variety of interesting signals;
254-
# and continue afterwards for a couple of cycles to make sure
255-
# these don't make it into our sample buffer.
256-
for i in range(2, 34):
257-
yield from self.provide_all_signals(sample_value(i))
258-
yield
259-
260-
# We now should be done with our sampling.
261-
self.assertEqual((yield self.dut.sampling), 0)
262-
self.assertEqual((yield self.dut.complete), 1)
263-
264-
# Validate the memory values that were captured.
265-
for i in range(32):
266-
yield from self.assert_sample_value(i, sample_value(i))
267-
268-
# All of those reads shouldn't change our completeness.
269-
self.assertEqual((yield self.dut.sampling), 0)
270-
self.assertEqual((yield self.dut.complete), 1)
271-
272-
273-
274173
class SyncSerialILA(Elaboratable):
275174
""" Super-simple ILA that reads samples out over a simple unidirectional SPI.
276175
Create a receiver for this object by calling apollo_fpga.ila_receiver_for(<this>).
@@ -430,60 +329,6 @@ def elaborate(self, platform):
430329
return m
431330

432331

433-
class SyncSerialReadoutILATest(SPIGatewareTestCase):
434-
435-
def instantiate_dut(self):
436-
self.input_signal = Signal(12)
437-
return SyncSerialILA(
438-
signals=[self.input_signal],
439-
sample_depth=16,
440-
clock_polarity=1,
441-
clock_phase=0
442-
)
443-
444-
def initialize_signals(self):
445-
yield self.input_signal.eq(0xF00)
446-
447-
@sync_test_case
448-
def test_spi_readout(self):
449-
input_signal = self.input_signal
450-
451-
# Trigger the test while offering our first sample.
452-
yield
453-
yield from self.pulse(self.dut.trigger, step_after=False)
454-
455-
# Provide the remainder of our samples.
456-
for i in range(1, 16):
457-
yield input_signal.eq(0xF00 | i)
458-
yield
459-
460-
# Wait a few cycles to account for delays in
461-
# the sampling pipeline.
462-
yield from self.advance_cycles(5)
463-
464-
# We've now captured a full set of samples.
465-
# We'll test reading them out.
466-
self.assertEqual((yield self.dut.complete), 1)
467-
468-
# Start the transaction, and exchange 16 bytes of data.
469-
yield self.dut.spi.cs.eq(1)
470-
yield
471-
472-
# Read our our result over SPI...
473-
data = yield from self.spi_exchange_data(b"\0" * 32)
474-
475-
# ... and ensure it matches what was sampled.
476-
i = 0
477-
while data:
478-
datum = data[0:4]
479-
del data[0:4]
480-
481-
expected = b"\x00\x00\x0f" + bytes([i])
482-
self.assertEqual(datum, expected)
483-
i += 1
484-
485-
486-
487332

488333
class StreamILA(Elaboratable):
489334
""" Super-simple ILA that outputs its samples over a Stream.
@@ -674,53 +519,6 @@ def elaborate(self, platform):
674519

675520
return m
676521

677-
class StreamILATest(LunaGatewareTestCase):
678-
679-
def instantiate_dut(self):
680-
self.input_signal = Signal(12)
681-
return StreamILA(
682-
signals=[self.input_signal],
683-
sample_depth=16
684-
)
685-
686-
def initialize_signals(self):
687-
yield self.input_signal.eq(0xF00)
688-
689-
@sync_test_case
690-
def test_stream_readout(self):
691-
input_signal = self.input_signal
692-
stream = self.dut.stream
693-
694-
# Trigger the ILA with the first sample
695-
yield
696-
yield from self.pulse(self.dut.trigger, step_after=False)
697-
698-
# Fill up the ILA with the remaining samples
699-
for i in range(1, 16):
700-
yield input_signal.eq(0xF00 | i)
701-
yield
702-
703-
# Wait a few cycles to allow the ILA to fully finish processing
704-
yield from self.advance_cycles(6)
705-
# Stream should now be presenting valid data
706-
self.assertEqual((yield stream.valid), 1)
707-
708-
# Now we want to stream out the samples from the ILA
709-
yield stream.ready.eq(1)
710-
yield
711-
self.assertEqual((yield stream.first), 1)
712-
713-
# Read out data from the stream until it signals completion
714-
data = []
715-
while not (yield stream.last):
716-
if (yield stream.valid):
717-
data.append((yield stream.payload))
718-
yield
719-
720-
# Match read data to what should have been sampled
721-
for i, datum in enumerate(data):
722-
self.assertEqual(datum, 0xF00 | i)
723-
724522

725523
class AsyncSerialILA(Elaboratable):
726524
""" Super-simple ILA that reads samples out over a UART connection.
@@ -1031,7 +829,3 @@ def _read_samples(self):
1031829
# Fetch all of our samples from the given device.
1032830
all_samples = self._port.read(total_to_read)
1033831
return list(self._split_samples(all_samples))
1034-
1035-
1036-
if __name__ == "__main__":
1037-
unittest.main()

0 commit comments

Comments
 (0)