首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用cocotb打印日志消息

如何用cocotb打印日志消息
EN

Stack Overflow用户
提问于 2017-05-12 07:22:57
回答 1查看 477关注 0票数 2

在cocotb官方快速启动指南上,打印日志消息的方法是在dut对象上使用_log.info():

代码语言:javascript
复制
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的最后一个主版本中这样做,我有一个不推荐的警告:

代码语言:javascript
复制
/opt/cocotb/cocotb/handle.py:134: UserWarning: Use of log attribute is deprecated

那么,在最后一个版本的cocotb上记录信息的好方法是什么?

thx

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-19 04:08:52

从最新版本来看,_log似乎是用于获取记录器的适当属性。

我不认为这是粘贴自己的实际代码示例的问题,但可能是cocotb中的其他地方,它使用的是不推荐的log属性。

实际上,我自己也看到了这一点,并使用了一种粗略的方法来通过使用traceback模块并修改cocotb/handle.py中的SimHandleBase类中的__getattr____setattr__函数来确定调用的来源,如下所示:

代码语言:javascript
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43931743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档