在cocotb官方快速启动指南上,打印日志消息的方法是在dut对象上使用_log.info():
import cocotb
from cocotb.triggers import Timer
@cocotb.test()
def my_first_test(dut):
"""
Try accessing the design
"""
dut._log.info("Running test!")
for cycle in range(10):
dut.clk = 0
yield Timer(1000)
dut.clk = 1
yield Timer(1000)
dut._log.info("Running test!")如果我在Cocotb的最后一个主版本中这样做,我有一个不推荐的警告:
/opt/cocotb/cocotb/handle.py:134: UserWarning: Use of log attribute is deprecated那么,在最后一个版本的cocotb上记录信息的好方法是什么?
thx
发布于 2017-05-19 04:08:52
从最新版本来看,_log似乎是用于获取记录器的适当属性。
我不认为这是粘贴自己的实际代码示例的问题,但可能是cocotb中的其他地方,它使用的是不推荐的log属性。
实际上,我自己也看到了这一点,并使用了一种粗略的方法来通过使用traceback模块并修改cocotb/handle.py中的SimHandleBase类中的__getattr__和__setattr__函数来确定调用的来源,如下所示:
import traceback
class SimHandleBase(object):
...
def __setattr__(self, name, value):
if name in self._compat_mapping:
if name not in _deprecation_warned:
warnings.warn("Use of %s attribute is deprecated" % name)
for line in traceback.format_stack(): # Inserted to print stack trace
print(line.strip()) # Inserted to print stack trace
_deprecation_warned[name] = True
return setattr(self, self._compat_mapping[name], value)
else:
return object.__setattr__(self, name, value)
def __getattr__(self, name):
if name in self._compat_mapping:
if name not in _deprecation_warned:
warnings.warn("Use of %s attribute is deprecated" % name)
for line in traceback.format_stack(): # Inserted to print stack trace
print(line.strip()) # Inserted to print stack trace
_deprecation_warned[name] = True
return getattr(self, self._compat_mapping[name])
else:
return object.__getattr__(self, name)https://stackoverflow.com/questions/43931743
复制相似问题