Skip to content

Commit 24df3e6

Browse files
committed
MVB Hash Table Simple - cocotb [HOTFIX]: update the Cocotb test to be compatible with the new MVB drivers and monitors
1 parent 6af0f2d commit 24df3e6

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

comp/mvb_tools/storage/mvb_hash_table_simple/cocotb/cocotb_test.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from cocotbext.ofm.utils.servicer import Servicer
3030
from cocotbext.ofm.utils.device import get_dtb
3131
from cocotbext.ofm.utils.math import ceildiv
32+
from cocotbext.ofm.mvb.transaction import MvbTrClassic
3233

3334
import itertools
3435
from math import log2
@@ -117,7 +118,7 @@ def load_file(self, path: str, params: dict) -> (dict, list, list, dict):
117118
out_keys.append(mvb_key)
118119
out_data[mvb_key] = data
119120

120-
table.append([h, (mvb_key << (self.stream_out._item_width * 8 + 1)) + ((data << 1) + 1)])
121+
table.append([h, (mvb_key << ((self.stream_out.item_widths["data"] // 8) * 8 + 1)) + ((data << 1) + 1)])
121122

122123
out_config.append(table)
123124

@@ -175,9 +176,9 @@ async def run_test(dut, config_file: str = "test_configs/test_config_1B.yaml", c
175176
cocotb.log.debug(f"TABLE_CAPACITY: {table_capacity}")
176177

177178
"""Asserting that the read configuration match configuration of the drivers connected to the component."""
178-
assert mvb_items == tb.stream_in._items
179-
assert mvb_key_width_bytes == tb.stream_in._item_width
180-
assert data_out_width_bytes == tb.stream_out._item_width
179+
assert mvb_items == tb.stream_in.items
180+
assert mvb_key_width_bytes == tb.stream_in.item_widths["data"] // 8 # FIXME
181+
assert data_out_width_bytes == tb.stream_out.item_widths["data"] // 8 # FIXME
181182
assert hash_width == log2(table_capacity)
182183

183184
"""Loading configuration from a config file"""
@@ -237,10 +238,14 @@ async def run_test(dut, config_file: str = "test_configs/test_config_1B.yaml", c
237238
for transaction in random_packets(item_width, item_width, pkt_count):
238239
int_transaction = int.from_bytes(transaction, "little")
239240

241+
mvb_tr = MvbTrClassic()
240242
if int_transaction in model_keys:
241-
tb.model((model_data[int_transaction].to_bytes(data_out_width_bytes, 'little'), 1))
243+
mvb_tr.data = model_data[int_transaction]
244+
vld = 1
242245
else:
243-
tb.model(((0).to_bytes(data_out_width_bytes, 'little'), 0))
246+
mvb_tr.data = 0
247+
vld = 0
248+
tb.model((mvb_tr, vld))
244249

245250
cocotb.log.info(f"generated transaction: {transaction.hex()}")
246251
tb.stream_in.append(transaction)

comp/mvb_tools/storage/mvb_hash_table_simple/cocotb/monitors.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,35 @@
55
# SPDX-License-Identifier: BSD-3-Clause
66

77
from cocotbext.ofm.mvb.monitors import MVBMonitor
8+
from cocotbext.ofm.mvb.transaction import MvbTrClassic
89

910

1011
class MVB_HASH_TABLE_SIMPLE_Monitor(MVBMonitor):
1112
_signals = ["data", "match", "vld", "src_rdy", "dst_rdy"]
1213

13-
def receive_data(self, data, offset):
14+
def recv_bytes(self, vld):
15+
data_val = self.bus.data.value
16+
data_val.big_endian = False
17+
data_bytes = data_val.buff
18+
1419
match_val = self.bus.match.value
1520
match_val.big_endian = False
1621

1722
self.log.debug(f"MATCH: {match_val}")
1823

19-
if match_val[offset] == 1:
20-
self._recv((data[offset*self._item_width:(offset+1)*self._item_width], 1))
21-
else:
22-
self._recv((self._item_width * b'\x00', 0))
24+
item_bytes = self._item_widths["data"] // 8
25+
for i in range(self._items):
26+
# Mask and shift the Valid signal per each Item
27+
if vld & 1:
28+
if match_val & 1:
29+
# Getting the data slice (Item) from the "bytes" transaction
30+
data_b = data_bytes[i*item_bytes : (i+1)*item_bytes]
31+
# Converting the data slice (Item) to the MvbTrClassic object
32+
mvb_tr = MvbTrClassic.from_bytes(data_b)
33+
self._recv((mvb_tr, 1))
34+
else:
35+
mvb_tr = MvbTrClassic()
36+
mvb_tr.data = 0
37+
self._recv((mvb_tr, 0))
38+
match_val >>= 1
39+
vld >>= 1

0 commit comments

Comments
 (0)