In reply to dave_59:
Dave, a related question. Suppose I have a hierarchy of test classes:
class base_test extends uvm_test;
function new(string name="base_test", uvm_component parent=null);
super.new(name, parent);
endfunction
endclass
class derived_test extends base_test;
function new(string name="derived_test", uvm_component parent=null);
super.new(name, parent);
endfunction
endclass
and I don’t want users to run base_test, as it’s a base class which doesn’t do anything useful. If I put this code in base_test:
string l_testname;
$value$plusargs("UVM_TESTNAME=%s", l_testname);
if(l_testname == XXXX)
`uvm_fatal(my_name, "This is a base test and should not be run.")
What should I use for XXXX, to get a fatal when +UVM_TESTNAME=base_test, but not when +UVM_TESTNAME = derived_test? Yes, I can use a string literal but I have other applications for this kind of code so I’d like to be more general.
When +UVM_TESTNAME=base_test :
get_name returns uvm_test_top
get_full_name returns uvm_test_top
get_type_name returns base_test - the if is satisfied, the test will fatal (Good)
When +UVM_TESTNAME=derived_test :
get_name returns uvm_test_top
get_full_name returns uvm_test_top
get_type_name returns derived_test - the if is satisfied, the test will fatal (Bad)
I need a way to set XXXX to “base_test”, no matter which test is actually run. Again, I can do that with a string literal but is there a way to get the name of the class where the code actually lives?
One way that seems to work is to declare a local variable “my_name” in each test class, for example:
class base_test extends uvm_test;
string my_name = "base_test";
...
class derived_test extends base_test;
string my_name = "derived_test";
...
Then when (say) derived_test.build_phase calls super.build_phase, and base_test.build_phase contains my checking code:
$value$plusargs("UVM_TESTNAME=%s", l_testname);
if(l_testname == my_name)
`uvm_fatal(my_name, "This is a base test and should not be run.")
The check will fatal when +UVM_TESTNAME=base_test and will not fatal when +UVM_TESTNAME=derived_test. This only works if the derived classes declares their own local “my_name”, which they can set without disturbing the base_test variable my_name. This seems like bad OO practice, however. And it’s one more thing to have to remember.