Monday, 28 December 2015

UVM_ERROR demoter code

/*!
* \brief report_catcher_err_info_demoter_c
* UVM_ERROT to UVM_INFO Demoter, demote UVM_ERROR based on ID or MESSAGE of UVM_ERROR.
*/
class report_catcher_err_info_demoter_c #(int no_of_err_msg = 1,int no_of_err_id = 0) extends uvm_report_catcher;
`uvm_object_utils(report_catcher_err_info_demoter_c)
int unsigned no_of_err_msg_demoted[]; /*! \param */
int unsigned no_of_err_id_demoted[]; /*! \param */
string exp_err[]; /*! \param */
string exp_id[]; /*! \param */
int unsigned string_offset; /*! \param */
//If we want that error should exactly the same as given, than make this bit 1
bit exact_match_msg[]; /*! \param */
/*!
* \brief Constructor
* Create a new transaction instance
* \parameter: name - Instance name of the transaction
*/
extern function new(string name = "report_catcher_err_info_demoter_c");
/*!
* \brief Function pattern_match_f
* Function used to match two string given as input arguments.
* If string matches it will return 1 else return 0.
* It is used to compare a message or ID of an error with
* expected error message or ID.
*/
extern function bit pattern_match_f(
input string str1, /*! \param string Output of get_message() or get_id() */
input string str2, /*! \param string Actual string which is demoted */
input bit ext_match, /*! \param bit used to represent exact_match_msg on/off */
input int unsigned err_num, /*! \param int used to represent Err num */
input bit msg_or_id /*! \param bit used to represent string is message or id, 1->msg, 0->id */
);
/*!
* \brief Function catch
* If severity is UVM_ERROR then change it to UVM_INFO.
*/
extern function action_e catch();
endclass : report_catcher_err_info_demoter_c
view raw uvm_demoter1.sv hosted with ❤ by GitHub

-------------------------------------------------------------------------------------------------------------------------------
function report_catcher_err_info_demoter_c::new(string name = "report_catcher_err_info_demoter_c");
super.new(name);
//dynamic array of size no_of_err_msg(no of error messages to be converted in to uvm_info)
exp_err = new[no_of_err_msg];
//dynamic array of size no_of_err_id(no of error messages to be converted in to uvm_info with help of error id)
exp_id = new[no_of_err_id];
no_of_err_msg_demoted = new[no_of_err_msg];
no_of_err_id_demoted = new[no_of_err_id];
exact_match_msg = new[no_of_err_msg];
string_offset = 0;
endfunction : new
function bit report_catcher_err_info_demoter_c::pattern_match_f(
input string str1,
input string str2,
input bit ext_match,
input int unsigned err_num,
input bit msg_or_id
);
int unsigned length_of_str1;
int unsigned length_of_str2;
bit match;
length_of_str1 = str1.len();
length_of_str2 = str2.len();
`uvm_info(get_name(), $sformatf("length of str1=%0d, length of str2=%0d", length_of_str1, length_of_str2), UVM_HIGH)
// Length comparision
if (length_of_str2 == 0) // compare with null
begin
if (msg_or_id == 1'b1)
begin
`uvm_info(get_name(), $sformatf("Length of Expected Err message is ZERO, Doing nothing for err num %0d of err msg"), UVM_LOW)
end
else
begin
`uvm_info(get_name(), $sformatf("Length of Expected Err message is ZERO, Doing nothing for err num %0d of err id"), UVM_LOW)
end
return 0;
end
else if(ext_match == 0)
begin
//lenght of expected error message can be same or less than actual error message
if(length_of_str2 > length_of_str1)
begin
return 0;
end
end
else
begin
//length of expected error message and actual message should same
if(length_of_str2 != length_of_str1)
begin
return 0;
end
end
//for(int i = string_offset; i < length_of_str2 ; i++)
for(int i = string_offset; i < (string_offset + length_of_str1 - length_of_str2 + 1) ; i++)
begin
if(str1.substr(i,i + length_of_str2 - 1) == str2)
begin
match = 1'b1;
return 1;
end
end
if (match == 1'b0)
begin
return 0;
end
endfunction : pattern_match_f
view raw uvm_demoter2.sv hosted with ❤ by GitHub

-------------------------------------------------------------------------------------------------------------------------------
function action_e report_catcher_err_info_demoter_c::catch();
//if(get_severity() == UVM_ERROR || get_severity() == UVM_INFO)
if(get_severity() == UVM_ERROR)
begin
if(no_of_err_msg > 0)
begin
for(int i=0; i < no_of_err_msg; i++)
begin
if(pattern_match_f(.str1(get_message()), .str2(exp_err[i]), .ext_match(exact_match_msg[i]), .err_num(i), .msg_or_id(1))
begin
set_severity(UVM_INFO);
set_action(UVM_NO_ACTION);
set_verbosity(UVM_HIGH);
no_of_err_msg_demoted[i] ++;
end
end
end
if(no_of_err_id > 0)
begin
for(int i=0; i < no_of_err_id; i++)
begin
if(pattern_match_f(.str1(get_id()), .str2(exp_id[i]), .ext_match(0), .err_num(i), .msg_or_id(0))
begin
set_severity(UVM_INFO);
set_action(UVM_NO_ACTION);
set_verbosity(UVM_HIGH);
no_of_err_id_demoted[i] ++;
end
end
end
end
return THROW;
endfunction
view raw uvm_demoter3.sv hosted with ❤ by GitHub

1 comment:

  1. You would have use uvm_re_match instead of creating custom logic.

    ReplyDelete