UVM基础之-------uvm report机制的使用

后面的例子我会继续补充:

1. 由于uvm默认定义的message格式比较长,很是不利于debug过程当中的分析使用,通常状况下,开始使用uvm,都要利用uvm_report_server从新定义message输出的格式。下面给出一个例子:用于将name和ID限定在同一个width。

class my_report_server extends uvm_report_server;
  int name_width = 20;
  int id_width   = 20;
 
  function string pad(string s, int width);
    if ( s.len() == width )
      return s;
 
    // s is short. Pad at the end.
    if ( s.len() < width )
      return {s, {(width - s.len()){" "}}};
    else                  
        // s is too long. truncate.
      return s.substr(s.len()-width, s.len()-1);
  endfunction
 
  function string compose_message(
    uvm_severity severity,
    string name,
    string id,
    string message,
    string filename,
    int    line
  );
  // Make the width be exactly name_width
  // and id_width.
 
name = pad(name, name_width);
    id   = pad(id,     id_width);
 
    return super.compose_message(
     severity, name, id, message, filename, line);
    endfunction
  endclass

前面文章中讲过,uvm_report_server类在整个环境中是一个单态类,因此在uvm_test层用set_server将继承的类替换原来的uvm_report_server类就能够了
class test extends uvm_test;
 
  // Make my report server.
  begin
    my_report_server my_report_server_inst;
    my_report_server_inst = new();
 
    // Configure.
    my_report_server_inst.name_width = 28;
    my_report_server_inst.id_width   = 20;
 
    // Set.
    uvm_report_server::set_server(
      my_report_server_inst);
  end


2. 使用catcher对一些message执行CATCH或者THROW的操做:
class my_report_catcher
  extends uvm_report_catcher;
 
  string            id;
  string            filename;
  string            name;
  string            message;
  int               line;
  int               verbosity;
  uvm_severity      severity;
  uvm_report_object client;
 
function new(string name = "my_report_catcher");
    super.new(name);
  endfunction
 
  function action_e catch();
    uvm_severity_type usv;
 
    id              = get_id();
    filename        = get_fname();
    line            = get_line();
    severity        = get_severity();
    verbosity       = get_verbosity();
    message         = get_message();
 
    client          = get_client();
    name            = client.get_full_name();
 
    usv = uvm_severity_type'(severity);
 
    // Process this message.
    // Decide THROW or CATCH.
    ...
    return THROW;
  endfunction
endclass

class test extends uvm_test;
  ...
  my_report_catcher my_report_catcher_inst;
  my_report_catcher_inst =
    new("my_report_catcher_inst");
  uvm_report_cb::add(null,
    my_report_catcher_inst, UVM_APPEND);

3. 经过ID实现对message的精细控制,这部份内容在前面代码中有介绍,这里不展开在说的还有另外一方面缘由,咱们在debug的时候一般但愿log尽可能的彻底,所以不推荐使用ID去过滤message,也不推荐将log根据ID打印到不一样的file当中,由于这两种作法,一种限制的log的完整性,有可能缺失咱们须要的关键的信息,而另外一种则是由于message的打印通常是按照时间顺序进行,将log打印到不一样的file,将破坏这种先后时间关系,不利于进行debug。所以比较推荐的方式是,尽可能将全部的message打印到一个文件,而后经过脚本,从这个文件中根据ID提取你须要debug信息。

这里面有个原则,是别人跟我说的,我以为很是有道理: 当你在debug一个问题的时候,trace的很长世间才找到问题发生的点(TB 或者DUT的缘由),你要在这个问题发生点加上一行打印,帮助你之后去debug。这就是message的意义所在。

4. 因为使用在环境中使用的uvc愈来愈多,不可避免的就是log的数量将打印的很是多,如何使用uvm控制和管理log的输出,这也是一个比较值得研究的问题。


相关文章
相关标签/搜索