How to choose a testcase class from command line on SV

Hi,
I am having testcase classes as one base and 2 derived classes. How can i choose a particular test from command line in native SystemVerilog. i.e. I am trying to achieve it by Polymorphism. But I do not know how to change the string type of command line extractor value($value$plusargs) to class type to achieve polymorphism. I know it is easy to do that in UVM with +UVM_TESTNAME=test1 / +UVM_TESTNAME=test2 / +UVM_TESTNAME=test_base. Please suggest me here.

code snippet:

class test_base;
virtual task run();
  int addr;
  int data;
  $display("I am from Test Base class");
  addr = 10;
  data = 10;
endtask
endclass

class test1 extends test_base;
task run();
  int addr;
  int data;
  $display("I am from Test1 derived class");
  addr = 20;
  data = 20;
endtask
endclass

class test2 extends test_base;
task run();
  int addr;
  int data;
  $display("I am from Test2 derived class");
  addr = 30;
  data = 30;
endtask
endclass

module top;
string test_name;
test_base test;
//typedef class T;

initial begin
test = new();
if($value$plusargs("TEST_CASE=%s",test_name)) begin // I am passing TEST_CASE=test1
  test_name t1; // how to change the string type to class type??
  test = t1;
  test.run(); // trying to run derived class test by override the virtual method run
  $display("test_name = %s", test_name);
end
else begin
test.run(); // running base class test
end
$finish;
end
endmodule

In reply to vadivelan014:

You can do it brute force with a case statement

case (test_name)
"test_base" : test = new();
"test1" : test = test1::new();
"test2" : test = test2::new();
endcase

Or you can build your own factory can look-up the class by a string name in an associative array. If you want to understand how the factory works, check out my new SystemVerilog OOP course, especially the third session.

In reply to dave_59:

Hi Dave,
Thanks for the solution. For now i am using your “case statement” solution. As you suggested i will look into the factory work flow to create my own factory to do the same work, because every time i need to manually add a new test object under case statement, if any.

Thanks,
Vadivelan