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的輸出,這也是一個比較值得研究的問題。


相關文章
相關標籤/搜索