четверг, 15 марта 2012 г.

Override default uvm report server

Note: this article is just a translation from Russian one (Пример переопределения сервера ovm (uvm)).

Extending a default uvm report server can be useful in following cases:
  1. send messages from uvm to your own message collector;
  2. call callback at some condition, e.g. create transaction stream of errors (created with uvm_report_error) so one could browse them in waveform viewer
  3. change message format, e.g.change modeling time format or, more useful, printing errors in red colour
  4. replace summary report printed at the end of test run. As a rule, regression automation script greps (filters) test output and detects whether test has passed or failed. In case you have such legacy scripts it can be easier to replace uvm server rather than rewrite scripts.
As known, uvm report server implemented as singleton (singleton pattern at wiki). Using singleton is required for storage of one base of messages(namely, counters for each message type, dictionary of message [id], etc.).

uvm_report_server is implemented in class uvm_report_global_server (view source of ovm_report_server.svh).
Pay attention to static ovm_report_server global_report_server = null; and constructor if (global_report_server == null) global_report_server = new;

Let's illustrate how to override uvm_report_server: lets colour all errors and fatal errors in red:
  1. So we create coloured_report_server inheriting from uvm_report_server and override virtual compose_message which does the actual formatting (also there is virtual summarize function which is called at the end of simulation and prints message stats, you can override it as well)
  2. create coloured_report_server object and set reference to it in uvm_report_global_server.

import uvm_pkg::*;

`define BLACK(str)   {`"\033[30m`",str,`"\033[0m`"}
`define RED(str)     {`"\033[31m`",str,`"\033[0m`"}
`define GREEN(str)   {`"\033[32m`",str,`"\033[0m`"}
`define YELLOW(str)  {`"\033[33m`",str,`"\033[0m`"}
`define BLUE(str)    {`"\033[34m`",str,`"\033[0m`"}
`define MAGENTA(str) {`"\033[35m`",str,`"\033[0m`"}
`define CYAN(str)    {`"\033[36m`",str,`"\033[0m`"}
`define WHITE(str)   {`"\033[37m`",str,`"\033[0m`"}

`define BOLD(str)    {`"\033[1m`",str,`"\033[0m`"}

class coloured_report_server extends uvm_report_server;

    function string compose_message(
            uvm_severity severity,
            string name,
            string id,
            string message,
            string filename,
            int    line
        string result;
        if ((severity==UVM_ERROR) || (severity==UVM_FATAL))
            result=super.compose_message(severity, `RED(name), `RED(id), `RED(message), filename, line);
            result=super.compose_message(severity, name, id, message, filename, line);
        return result;
//you can overload virtual function void summarize(UVM_FILE file=0);

module coloured_server_test;
   initial begin
     coloured_report_server new_server;
     uvm_report_global_server glob;

   initial begin:printing_block
     #1; //delay is needed for the first initial to finish
     uvm_report_info("info",$sformatf("info from: '%m'"));
     uvm_report_error("error-id", "printing in red"); 

To run the snippet one should compile it with uvm support enabled. Most simulators support -uvm options which will autocompile the package and link all required libraries.

$mysimulator -uvm coloured_report_server.sv

Log output should look like this (header and summary omitted for clarity):

 UVM_INFO @ 1: reporter [info] info from: 'coloured_server_test.printing_block'
UVM_ERROR @ 1: reporter [error-id] printing in red

PS. It's worth mentioning that colorizing is inserting of escape sequences into output log. This may affect the grepping result of log. In case of info message we will be able to find it:
$ grep 'reporter \[info\]' simulation.log --> will find the info
but in case we are trying to find error-id with brackets the error won't be found as line turned into [31mreporter [0m [ [31merror-id [0m] [31m
$ grep 'reporter \[error-id\]' simulation.log --> won't find error-id

Комментариев нет:

Отправить комментарий