-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'schwarz-modelling_mi_transactions_with_object' into 'de…
…vel' Modelování, posílání a přijímání transakcí v MI driveru, monitoru a testu přes objekt See merge request ndk/ndk-fpga!70
- Loading branch information
Showing
10 changed files
with
620 additions
and
311 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# scoreboard.py: Custom scoreboard for MI Pipe Test | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Ondřej Schwarz <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from cocotb_bus.scoreboard import Scoreboard as BaseScoreboard | ||
from cocotbext.ofm.mi.transaction import MiTransaction | ||
from cocotb.utils import hexdiffs | ||
from cocotb.result import TestFailure | ||
|
||
|
||
class Scoreboard(BaseScoreboard): | ||
"""Custom scoreboard for MI Pipe Test""" | ||
|
||
def __init__(self, dut, reorder_depth=0, fail_immediately=True): | ||
super().__init__(dut, reorder_depth=reorder_depth, fail_immediately=fail_immediately) | ||
|
||
def compare(self, got: MiTransaction, exp: MiTransaction, log, strict_type=True): | ||
"""Custom compare function for MI Pipe Test | ||
Args: | ||
got: object from MiTransaction class passed by the monitor | ||
exp: object from MiTransaction class passed by the test | ||
log: logging object | ||
strict_type: if type of the transaction should be compared | ||
""" | ||
|
||
# Type comparison | ||
if strict_type and type(got) != type(exp): | ||
self.errors += 1 | ||
log.error("Received transaction type is different than expected") | ||
log.info("Received: %s but expected %s" % | ||
(str(type(got)), str(type(exp)))) | ||
if self._imm: | ||
raise TestFailure("Received transaction of wrong type. " | ||
"Set strict_type=False to avoid this.") | ||
return | ||
|
||
elif not strict_type: | ||
raise NotImplementedError("Non-strict type not implemented for MI Pipe Test.") | ||
|
||
# Comparing modeled and received values | ||
strgot, strexp = [], [] | ||
|
||
if got.trans_type != exp.trans_type: | ||
return | ||
|
||
for i in ["addr", "data", ("be", "byte_enable")]: | ||
item, text = i if isinstance(i, tuple) else (i, i) | ||
if getattr(got, item) != getattr(exp, item): | ||
self.errors += 1 | ||
strgot.append(f"{text}: {hex(getattr(got, item))}") | ||
strexp.append(f"{text}: {hex(getattr(exp, item))}") | ||
|
||
if self.errors > 0: | ||
log.error("Received transaction differed from expected output") | ||
log.info(f"Expected: {'; '.join(strexp)}") | ||
log.info(f"Received: {'; '.join(strgot)}") | ||
|
||
log.warning("Difference:\n%s" % hexdiffs('; '.join(strexp), '; '.join(strgot))) | ||
if self._imm: | ||
raise TestFailure("Received transaction differed from expected " | ||
"transaction") | ||
else: | ||
try: | ||
log.debug("Received expected transaction %d bytes" % | ||
(len(got))) | ||
log.debug(repr(got)) | ||
except Exception: | ||
pass |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# proxymonitor.py: ProxyMonitor | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Ondřej Schwarz <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from cocotb_bus.monitors import BusMonitor | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class ProxyMonitor(BusMonitor, ABC): | ||
""" | ||
Generic Proxy Monitor used for redirecting traffic from cocotb BusMonitor | ||
and running it through a filter. It automatically connects to the _recv | ||
function of the passed BusMonitor. | ||
Attributes: | ||
_item_cnt(int): number of items which successfully passed through the filter. | ||
""" | ||
|
||
def __init__(self, monitor: BusMonitor): | ||
""" | ||
Args: | ||
monitor: BusMonitor which this class is to be the proxy for. | ||
""" | ||
super().__init__(monitor.entity, monitor.name, monitor.clock) | ||
monitor.add_callback(self.monitor_callback) | ||
self._item_cnt = 0 | ||
|
||
@property | ||
def item_cnt(self): | ||
return self._item_cnt | ||
|
||
def monitor_callback(self, *args, **kwargs) -> None: | ||
""" | ||
Callback connected to the passed BusMonitor's _recv function. | ||
The received transaction is run through a filter and then | ||
passed on through the _recv function. | ||
""" | ||
filtered_transaction = self._filter_transaction(*args, **kwargs) | ||
|
||
if filtered_transaction is None: | ||
return | ||
|
||
self._recv(filtered_transaction) | ||
self._item_cnt += 1 | ||
|
||
@abstractmethod | ||
def _filter_transaction(self, transaction, *args, **kwargs) -> any: | ||
""" | ||
Filter function used in function monitor_callback. It is ment to be redefined | ||
for specific usecases. | ||
The placeholder filter implemented here lets all the transactions through. | ||
""" | ||
return transaction | ||
|
||
async def _monitor_recv(self): | ||
""" | ||
This function must be implemented in every BusMonitor child, however, here it has | ||
no use. However, it may be redifined for specific usecases. | ||
""" | ||
pass |
Oops, something went wrong.