-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_caseInsensGetattr() causes simulation failure: broken interaction with dut due to calling dir(obj) #72
Comments
Well shoot, {'_def_file': '',
'_def_name': '',
'_discovered': False,
'_fullname': 'mymodule(GPI_MODULE)',
'_handle': <cocotb.simulator.gpi_sim_hdl at 0x600002c1d4d0>,
'_invalid_sub_handles': set(),
'_len': None,
'_log': <SimBaseLog cocotb.mymodule (INFO)>,
'_name': 'mymodule',
'_path': 'mymodule',
'_sub_handles': {'clk': ModifiableObject(mymodule.clk)},
'_type': 'GPI_MODULE'} |
In my case, dir(dut) does not show all signals, either. for i in signal_names:
try:
getattr(dut, i)
bus = AXI4Master(dut, ...) |
My problem is not that dir(dut) does not show all signals. It's that the simulation is completely empty/broken due to calling dir(dut) in the case-insensitive function. I'm using cocotbext-axi which derives some additional classes from the cocotb-bus Bus class, and my solution is just to monkeypatch the problematic "case insensitive" function, essentially removing that feature. import cocotbext.axi
# Patch a problematic section of cocotb_bus (doesn't work on MacOS) by removing
# the call to dir(obj) (as well as the case-insensitivity feature, for convenience).
def _caseInsensGetattr(self, obj, attr):
return getattr(obj, attr, None)
for attr in dir(cocotbext.axi):
obj = getattr(cocotbext.axi, attr)
if hasattr(obj, "_caseInsensGetattr"):
setattr(obj, "_caseInsensGetattr", _caseInsensGetattr) |
My colleague has reported that the case-insensitive feature is also causing issues using VCS as a backend on a RHEL platform; so this issue is actually not confined to just Verilator-on-MacOS as I originally thought! Can the cocotb-bus authors turn off the case-insensitive feature? Or at least default to: |
This commit should not have changed the default behavior of cocotb from case-sensitive to case-insensitive. The proper way to add patches like this to python code is for the default behavior to be unmodified. The new parameter value should not automatically assume you want case-insensitivity. Case insensitivity is a special situation that's only related to certain simulators; most simulators maintain case sensitive port names. I propose, simply changing the |
So this seems like a widespread problem. I didn't know other people are encountering the same issue related to that one case-insensitivity function, so thanks for referencing all the reported issues, @cmarqu. I was actually surprised that someone in my same group at work also encountered an issue with that same function and needed to set I think until that feature works as intended in all situations, we should at the very least disable it by setting the default value to False. To that end, please review this trivial PR: I don't particularly know why that feature is needed in the first place, but imagine it's due to some archaic toolchain and simply for convenience. I trust Alex Forencich (@alexforencich) had good reason to do so, but I think it needs more development done before we should make it the default behavior for all users of cocotb-bus. |
It seems the build pipeline for cocotb-bus is out of date so the CICD test results are not useful at the moment. Please consider the PR for submission regardless of this. I see this warning:
And this error:
Neither of which are related to my change, I think. |
This was actually a reported problem with the case-insensitivity change just 2 weeks after it was introduced. The change was made March 4 2021 and by March 15 2021 it was clear that it was incompatible with some simulators: I think we should roll it back or disable that feature until it works on more platforms and more/all backend simulators that are supported by Cocotb (ex: those listed in runner.py, for example). |
I'm working on fixing CI right now. |
Verilator's PLI has been very, very broken until quite recently. Seems like 5.020 is the minimum usable version; the cocotb docs should be updated to reflect this. There are still some problems, but dir() and case insensitive matching should work in 5.020. If not, then we need to figure out why. If you're using a release older than 5.020, then you need up upgrade. |
Works with Verilator 5.022 now, per discussion in #74. Closing this issue. |
We should open a separate issue for VCS, though. |
This is done in cocotb/cocotb#3740 |
I have a very strange but very repeatable problem running cocotb 1.8.1, cocotb_bus 0.2.1, and Verilator on [arm64] MacOS. Specifically, calling
dir(obj)
results in no DUT signals' values showing up in the resultant waves file. The signals generated by the testbench are still there, but basically dumping any signal that is part of the DUT to waves is somehow disturbed by callingdir(dut)
and nothing gets generated.I traced the problem to this somewhat specific add-on feature in
bus.py
which iterates throughdir(obj)
(where obj == dut in common cocotb testbench name conventions). The whole point is just to make something case insensitive for convenience but it's causing me a lot of problems because callingdir(obj)
apparently has undesirable side effects.I can recreate the issue not even involving cocotb_bus by just adding this at the top of my testbench:
I found that simply changing three characters in
cocotb_bus/bus.py
fromdir()
tovars()
fixes the problem. I'm not sure why that is. But I think since the dut object created by Cocotb defines a__dir__()
function, it should be used and it will be used if you callvars()
.More thoughts:
Searching through dirs() is not even what the code should be doing because that would include iteration over all these private member variables and possibly all superclasses (one of which, I'm assuming is causing the problem):
The cocotb_bus code should intead be iterating through the names of the public member variables, which include signal names, etc. of the dut. I'm assuming that somewhere deep in the Verilator/Cocotb interface, that list is generated and made available by the function
__dirs__()
and hence byvars(obj)
(contrary to what you might think from the name,dir(obj)
does not call__dirs__()
). Here's an explanation:https://stackoverflow.com/questions/980249/difference-between-dir-and-vars-keys-in-python
I suspect that what is happening is that the base classes are some compiled C++/Swig/CPython magic at the interface of Verilator and Cocotb, and therefore recursively looking at all the base class attributes is resulting in accessing something illegally and breaking the simulation / waves export. Interestingly, my colleague said it doesn't happen in Linux; I have verified (rather extensively) that this is the cause of the problem on MacOS.
TL;DR: please change that line to
vars(obj)
!The text was updated successfully, but these errors were encountered: