-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_raster/test_midi: add some coverage
- Loading branch information
Showing
6 changed files
with
157 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# Copyright (c) 2024 Seb Holzapfel, apfelaudio UG <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CERN-OHL-S-2.0 | ||
""" | ||
Multi-channel oscilloscope and vectorscope SoC peripherals. | ||
""" | ||
|
||
from amaranth import * | ||
from amaranth.lib import wiring, data, stream | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Copyright (c) 2024 Seb Holzapfel, apfelaudio UG <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CERN-OHL-S-2.0 | ||
|
||
import sys | ||
import unittest | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Copyright (c) 2024 Seb Holzapfel, apfelaudio UG <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CERN-OHL-S-2.0 | ||
|
||
import unittest | ||
|
||
from amaranth import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2024 Seb Holzapfel, apfelaudio UG <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CERN-OHL-S-2.0 | ||
|
||
import math | ||
import sys | ||
import unittest | ||
|
||
from amaranth import * | ||
from amaranth.sim import * | ||
from amaranth.lib import wiring | ||
from tiliqua import midi, test_util | ||
|
||
from amaranth_soc import csr | ||
from amaranth_soc.csr import wishbone | ||
|
||
class MidiTests(unittest.TestCase): | ||
|
||
def test_midi(self): | ||
|
||
dut = midi.MidiDecode() | ||
|
||
async def testbench(ctx): | ||
ctx.set(dut.i.valid, 1) | ||
ctx.set(dut.i.payload, 0x92) | ||
await ctx.tick() | ||
ctx.set(dut.i.payload, 0x48) | ||
await ctx.tick() | ||
ctx.set(dut.i.payload, 0x96) | ||
await ctx.tick() | ||
p = ctx.get(dut.o.payload) | ||
self.assertEqual(p.midi_type, midi.MessageType.NOTE_ON) | ||
self.assertEqual(p.midi_channel, 2) | ||
self.assertEqual(p.midi_payload.note_on.note, 0x48) | ||
self.assertEqual(p.midi_payload.note_on.velocity, 0x96) | ||
|
||
sim = Simulator(dut) | ||
sim.add_clock(1e-6) | ||
sim.add_testbench(testbench) | ||
with sim.write_vcd(vcd_file=open("test_midi.vcd", "w")): | ||
sim.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright (c) 2024 Seb Holzapfel, apfelaudio UG <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CERN-OHL-S-2.0 | ||
|
||
import math | ||
import sys | ||
import unittest | ||
|
||
from amaranth import * | ||
from amaranth.sim import * | ||
from amaranth.lib import wiring | ||
from tiliqua import raster, test_util, eurorack_pmod | ||
|
||
from amaranth_soc import csr | ||
from amaranth_soc.csr import wishbone | ||
|
||
from amaranth_future import fixed | ||
|
||
class RasterTests(unittest.TestCase): | ||
|
||
def test_persist(self): | ||
|
||
class FakeBusMaster: | ||
addr_width = 30 | ||
|
||
dut = raster.Persistance( | ||
fb_base=0x0, | ||
bus_master=FakeBusMaster(), | ||
fb_size=(1280, 720) | ||
) | ||
|
||
async def testbench(ctx): | ||
ctx.set(dut.enable, 1) | ||
# Simulate N burst accesses | ||
for _ in range(4): | ||
while not ctx.get(dut.bus.stb): | ||
await ctx.tick() | ||
# Simulate acks delayed from stb | ||
await ctx.tick().repeat(8) | ||
ctx.set(dut.bus.ack, 1) | ||
while ctx.get(dut.bus.stb): | ||
# for all burst accesses, simulate full intensity. | ||
ctx.set(dut.bus.dat_r, 0xffffffff) | ||
if ctx.get(dut.bus.we): | ||
# for all burst reads, verify intensity of every | ||
# pixel is reduced as expected | ||
self.assertEqual(ctx.get(dut.bus.dat_w), | ||
0xefefefef) | ||
await ctx.tick() | ||
ctx.set(dut.bus.ack, 0) | ||
|
||
sim = Simulator(dut) | ||
sim.add_clock(1e-6) | ||
sim.add_testbench(testbench) | ||
with sim.write_vcd(vcd_file=open("test_persist.vcd", "w")): | ||
sim.run() | ||
|
||
def test_stroke(self): | ||
|
||
class FakeBusMaster: | ||
addr_width = 30 | ||
|
||
dut = raster.Stroke( | ||
fb_base=0x0, | ||
bus_master=FakeBusMaster(), | ||
fb_size=(1280, 720) | ||
) | ||
|
||
async def stimulus(ctx): | ||
for n in range(0, sys.maxsize): | ||
ctx.set(dut.i.valid, 1) | ||
ctx.set(dut.i.payload, [0, 0, 0, 0]) | ||
await ctx.tick() | ||
ctx.set(dut.i.valid, 0) | ||
await ctx.tick().repeat(128) | ||
|
||
async def testbench(ctx): | ||
ctx.set(dut.enable, 1) | ||
# Simulate some acks delayed from stb | ||
for _ in range(16): | ||
while not ctx.get(dut.bus.stb): | ||
await ctx.tick() | ||
await ctx.tick().repeat(8) | ||
ctx.set(dut.bus.ack, 1) | ||
await ctx.tick() | ||
ctx.set(dut.bus.ack, 0) | ||
await ctx.tick() | ||
|
||
sim = Simulator(dut) | ||
sim.add_clock(1e-6) | ||
sim.add_testbench(testbench) | ||
sim.add_process(stimulus) | ||
with sim.write_vcd(vcd_file=open("test_stroke.vcd", "w")): | ||
sim.run() |