summaryrefslogtreecommitdiff
path: root/tb/top/test_mat.py
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-11-22 08:30:39 -0600
committerAlejandro Soto <alejandro@34project.org>2023-11-22 08:30:39 -0600
commitd6e962d5b4df637adfb706ae18ac70bd67fe28cd (patch)
treee55210924602679d620f312efa0bbfdad572c0b0 /tb/top/test_mat.py
parent08d2e52cd0120e5a04656cd7c180fc3f1c1f3117 (diff)
tb: add test_mat
Diffstat (limited to 'tb/top/test_mat.py')
-rw-r--r--tb/top/test_mat.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tb/top/test_mat.py b/tb/top/test_mat.py
new file mode 100644
index 0000000..1531e9c
--- /dev/null
+++ b/tb/top/test_mat.py
@@ -0,0 +1,28 @@
+from array import array
+import itertools, struct, random
+
+import cocotb
+from cocotb.clock import Clock
+from cocotb.triggers import Combine, ClockCycles, FallingEdge, RisingEdge, Timer, with_timeout
+from cocotb_bus.drivers import BitDriver
+from cocotb_bus.drivers.avalon import AvalonMaster, AvalonMemory
+
+@cocotb.test()
+async def fp_mat_mul(dut):
+ await cocotb.start(Clock(dut.clk, 2).start())
+
+ dut.rst_n.value = 1
+ await Timer(1)
+ dut.rst_n.value = 0
+ await Timer(1)
+ dut.rst_n.value = 1
+
+ for i in range(32):
+ await cmd.write(i, int.from_bytes(struct.pack('<e', i + 1), 'little'))
+
+ await ClockCycles(dut.clk, 50)
+ for i in range(4):
+ for j in range(4):
+ read, = struct.unpack('<e', (await cmd.read(i * 4 + j)).integer.to_bytes(2, 'little'))
+ expected = sum((1 + i * 4 + k) * (17 + k * 4 + j) for k in range(4))
+ assert read == expected, f'expected {expected} at ({i}, {j}), got {read}'