Calling a static method from class type given by plusarg

Hi,

Is it possible from a string that holds a class type name, to call to a function declared in that class. The function can be defined static if it helps.
For my particular issue, that type is going to be a component (well, a test) and the string will come from a plusarg.

for example:


class my_base_test extends uvm_test;
//factory
//new
  static extern virtual function void do_test_stuff();
endclass : my_base_test
//external implementation of do_test_stuff



class a_test extends my_base_test ;
//factory
//new
  static extern virtual function void do_test_stuff();
endclass : a_test 
//external implementation of do_test_stuff




class b_test extends my_base_test ;
//factory
//new
  static extern virtual function void do_test_stuff();
endclass : b_test 
//external implementation of do_test_stuff



class my_object extends uvm_object ;
//factory
//new
  extern virtual function void do_object_stuff();
endclass : a_test 

function void my_object::do_object_stuff();
  string some_test_name; //not the test that is actually running
  $value$plusargs("SOME_TEST_NAME=%0s", some_test_name)

  magically_call_for_do_test_stuff_defined_in_type(name_of_the_plusarg_test);

endfucntion : do_object_stuff


to make it clear, the test that i’ll actually be running is neither a_test or b_test. Rather some other test but I will want to pass via plusarg the test from which I want to invoke do_test_stuff().
do_test_stuff() in reality is just class overrides but I need to import some overrides from some tests to some other tests.

Thanks,
Nimrod

In reply to nimrodw:

What you are trying to do is exactly the purpose behind a uvm_sequence where its body() method is your do_test_stuff() method. More specifically, what we call a virtual sequence which has no connection to and does not send truncations to a driver. But let me make a few comments on the approach you have take so far.

Making your method static does not help, it actually hurts. Methods cannot be virtual and static simultaneously. The purpose of a virtual method is looking at an object handle dynamically and choosing which virtual override to call at execution time.

You are extending the classes from uvm_test, which is a uvm_component. You can only create components at time 0 as part of the build_phase. And your really should only be creating components as part of testbench hierarchy and expect to use the UVM phases tThere is overhead in using components even if you do not take advantage of these features). You can use uvm_object instead, but I will later ask you to use uvm_sequence.

Since you are registering these classes with the factory, you can use the factory method or set_type_override_by_name or create_object_by_name using the string retrieved from the command line. And you might want to look at the UVM’s command line processor in case you need to retrieve multiple test strings at the same time.

uvm_factory f;
my_base_test mbt;
string some_test_name;

f= uvm_factory::get();
if (!$value$plusargs("SOME_TEST_NAME=%0s", some_test_name))
    some_test_name = "my_test_base"); // or generate an error
if (!$cast(mbt, f.create_object_by_name(some_test_name,,"mbt") !! mbt == null)
    `uvm_fatal("",{"Unable to create: ",some_test_name})
mbt.do_test_stuff();

If you replace my_base_test with uvm_sequence, you would just need to change the last line to
mbt.start(); which calls the body() method for you.

The benefits of of using uvm_sequence are

  • Using a standardized methodology that makes it easier for other people to read and maintain.
  • Traceability of method calls in messages and debugging if these calls are made from a sequence or invoke other sequences.