UVM糖果爱好者教程 - 28. 打印消息记录

在之前的文章中,我们解释了如何使用冗余度阈值来过滤消息。 本文解释如何将消息发送到一个或多个文件。

消息示例

举例来说,我们向功能覆盖率收集器添加了几个不同严重程度的消息宏。

class jelly_bean_fc_subscriber extends uvm_subscriber#( jelly_bean_transaction );
  // ...
  function void write( jelly_bean_transaction t );
    jb_tx = t;
    jelly_bean_cg.sample();

    //_SEVERITY_  _ID__  ___________________MESSAGE____________________
    `uvm_info   ( "id1", { t.color.name(), " ", t.flavor.name(), " 1" }, UVM_NONE )
    `uvm_info   ( "id2", { t.color.name(), " ", t.flavor.name(), " 2" }, UVM_NONE )
    `uvm_warning( "id1", { t.color.name(), " ", t.flavor.name(), " 3" } )
    `uvm_warning( "id2", { t.color.name(), " ", t.flavor.name(), " 4" } )
    `uvm_error  ( "id1", { t.color.name(), " ", t.flavor.name(), " 5" } )
    `uvm_error  ( "id2", { t.color.name(), " ", t.flavor.name(), " 6" } )
    `uvm_fatal  ( "id1", { t.color.name(), " ", t.flavor.name(), " 7" } )
    `uvm_fatal  ( "id2", { t.color.name(), " ", t.flavor.name(), " 8" } )
  endfunction: write
endclass: jelly_bean_fc_subscriber

下图总结了收集器中定义的消息。

准备工作

打开文件描述符

在本文中,我们将写入四个文件(default_file,warning_file,id1_file和warning_id1_file)。 我们在start_of_simulation_phase(第8到11行)中打开文件描述符。

class jelly_bean_test extends uvm_test;
  protected int default_fd; // file descriptor
  protected int warning_fd;
  protected int id1_fd;
  protected int warning_id1_fd;
  // ...
  function void start_of_simulation_phase( uvm_phase phase );
    default_fd     = $fopen( "default_file",     "w" );
    warning_fd     = $fopen( "warning_file",     "w" );
    id1_fd         = $fopen( "id1_file",         "w" );
    warning_id1_fd = $fopen( "warning_id1_file", "w" );
    // ...
  endfunction: start_of_simulation_phase
endclass: jelly_bean_test

设置报告操作

默认情况下,没有消息发送到文件,因为默认操作定义如下:

SeverityDefault ActionsDescription
UVM_INFOUVM_DISPLAYSends the message to the standard out
UVM_WARNINGUVM_DISPLAYSends the message to the standard out
UVM_ERRORUVM_DISPLAY | UVM_COUNTSends the message to the standard out;
Terminates the simulation if the number of messages exceeds the number specified by the +UVM_MAX_QUIT_COUNT (default is 0)
UVM_FATALUVM_DISPLAY | UVM_EXITSends the message to the standard out;
Terminates the simulation immediately

set_report_severity_action

为了将消息发送到文件,我们需要使用set_report_severity_action函数(第5至8行)将UVM_LOG操作添加到每个严重性。

class jelly_bean_test extends uvm_test;
  // ...
  function void start_of_simulation_phase( uvm_phase phase );
    // ...                                   _SEVERITY__  _______ACTIONS_______
    jb_env.jb_fc.set_report_severity_action( UVM_INFO,    UVM_DISPLAY | UVM_LOG );
    jb_env.jb_fc.set_report_severity_action( UVM_WARNING, UVM_DISPLAY | UVM_LOG );
    jb_env.jb_fc.set_report_severity_action( UVM_ERROR,   UVM_DISPLAY | UVM_LOG );
    jb_env.jb_fc.set_report_severity_action( UVM_FATAL,   UVM_DISPLAY | UVM_LOG );
    // ...
  endfunction: start_of_simulation_phase
endclass: jelly_bean_test

我们从UVM_ERROR和UVM_FATAL中删除了UVM_COUNT和UVM_EXIT动作,以便在遇到错误后继续进行仿真。不过,你应该把它们放在真正的验证平台上。

您可以使用set_report_id_action设置ID特定的操作,也可以使用set_report_severity_id_action设置特定于严重度和ID的操作。有关详细信息,请参阅UVM手册。

将消息发送到文件

set_report_default_file

如果您只想将消息定向到文件,则可以使用set_report_default_file函数。以下代码将功能覆盖收集器发布的消息发送到default_file(第5行)。

class jelly_bean_test extends uvm_test;
  // ...
  function void start_of_simulation_phase( uvm_phase phase );
    // ...                                FILE_DESCRIPTOR
    jb_env.jb_fc.set_report_default_file( default_fd );
  endfunction: start_of_simulation_phase
endclass: jelly_bean_test

当你运行一个仿真时,default_file将存储这样的消息:

UVM_INFO /home/runner/env.svh(40) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 1
UVM_INFO /home/runner/env.svh(41) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 2
UVM_WARNING /home/runner/env.svh(42) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 3
UVM_WARNING /home/runner/env.svh(43) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 4
UVM_ERROR /home/runner/env.svh(44) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 5
UVM_ERROR /home/runner/env.svh(45) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 6
UVM_FATAL /home/runner/env.svh(46) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 7
UVM_FATAL /home/runner/env.svh(47) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 8

设置严重性特定的文件

set_report_severity_file

如果要将具有特定严重性的消息定向至单独的文件,则可以使用set_report_severity_file函数执行此操作。例如,可以按照以下方式(第5行)将具有UVM_WARNING严重性的消息存储到warning_file:

class jelly_bean_test extends uvm_test;
  // ...
  function void start_of_simulation_phase( uvm_phase phase );
    // ...                                 _SEVERITY__  FILE_DESCRIPTOR
    jb_env.jb_fc.set_report_severity_file( UVM_WARNING, warning_fd );
  endfunction: start_of_simulation_phase
endclass: jelly_bean_test

请注意,在我们的例子中,我们仍然像上一节那样设置默认文件。特定于严重性的文件优先于默认文件。

当你运行一个仿真时,default_file将存储这样的消息:

UVM_INFO /home/runner/env.svh(40) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 1
UVM_INFO /home/runner/env.svh(41) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 2
UVM_ERROR /home/runner/env.svh(44) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 5
UVM_ERROR /home/runner/env.svh(45) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 6
UVM_FATAL /home/runner/env.svh(46) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 7
UVM_FATAL /home/runner/env.svh(47) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 8

warning_file将存储这样的消息:

UVM_WARNING /home/runner/env.svh(42) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 3
UVM_WARNING /home/runner/env.svh(43) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 4

设置ID特定的文件

set_report_id_file

如果要将带有特定ID的消息引导至单独的文件,可以使用set_report_id_file函数执行此操作。例如,您可以按如下方式(第5行)将带有“id1”的消息存储到id1_file中:

class jelly_bean_test extends uvm_test;
  // ...
  function void start_of_simulation_phase( uvm_phase phase );
    // ...                           _ID__  FILE_DESCRIPTOR
    jb_env.jb_fc.set_report_id_file( "id1", id1_fd );
  endfunction: start_of_simulation_phase
endclass: jelly_bean_test

请注意,在我们的示例中,我们仍然像前面章节中那样设置默认文件和特定于严重性的文件。特定于ID的文件优先于特定严重性的文件(和缺省文件)。

当你运行一个仿真时,default_file将存储这样的消息:

UVM_INFO /home/runner/env.svh(41) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 2
UVM_ERROR /home/runner/env.svh(45) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 6
UVM_FATAL /home/runner/env.svh(47) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 8

warning_file将存储这样的消息:

UVM_WARNING /home/runner/env.svh(43) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 4

id1_file将存储这样的消息:

UVM_INFO /home/runner/env.svh(40) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 1
UVM_WARNING /home/runner/env.svh(42) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 3
UVM_ERROR /home/runner/env.svh(44) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 5
UVM_FATAL /home/runner/env.svh(46) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 7

设置严重性和ID特定的文件

set_report_severity_id_file

如果您确实想要将具有特定严重性和特定ID的消息定向到单独的文件,则可以使用set_report_severity_id_file函数执行此操作。例如,您可以按如下方式(第5行)将具有UVM_WARNING严重性和“id1”的消息存储到warning_id1_file:

class jelly_bean_test extends uvm_test;
  // ...
  function void start_of_simulation_phase( uvm_phase phase );
    // ...                                    _SEVERITY__  _ID__  FILE_DESCRIPTOR
    jb_env.jb_fc.set_report_severity_id_file( UVM_WARNING, "id1", warning_id1_fd );
  endfunction: start_of_simulation_phase
endclass: jelly_bean_test

请注意,在我们的示例中,我们仍像前面章节中那样设置默认文件,严重性特定文件和ID特定文件。严重性和特定于ID的文件的优先级最高。

当你运行一个仿真时,default_file将存储这样的消息:

UVM_INFO /home/runner/env.svh(41) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 2
UVM_ERROR /home/runner/env.svh(45) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 6
UVM_FATAL /home/runner/env.svh(47) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 8

warning_file将存储这样的消息:

UVM_WARNING /home/runner/env.svh(43) @ 25: uvm_test_top.jb_env.jb_fc [id2] GREEN BUBBLE_GUM 4

id1_file将存储这样的消息:

UVM_INFO /home/runner/env.svh(40) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 1
UVM_ERROR /home/runner/env.svh(44) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 5
UVM_FATAL /home/runner/env.svh(46) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 7

最后,warning_id1_file将存储这样的消息:

UVM_WARNING /home/runner/env.svh(42) @ 25: uvm_test_top.jb_env.jb_fc [id1] GREEN BUBBLE_GUM 3

与往常一样,您可以在EDA Playground上查看和运行代码。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值