Parameterized UVM test

i just read this article posted in Patterns Library and have a try. However, it seems doesn’t work.
after check UVM source code, the test is instantiated with factory.create_component_by_name().
for parameterized component, type name is not registered into regedit even if explicitly implement get_type_name(),just following the example code of the article. i don’t know why get_type_name is not works when registry. is there anyone explain it? the result is when search for the registered component with given type name, it fail and return null. i’m really curious how does it works as author said. actually i find parameterized test registry is not success.
this is my code.

parameter NUM = 3;
class mytest#(int NUM) extends uvm_test;
typedef uvm_component_registry#(mytest#(NUM),$sformatf(“mytest#(%1d)”,NUM)) type_id;
static function type_id get_type();
return type_id::get();
endfunction

virtual function uvm_object_wrapper get_object_type();
return type_id::get();
endfunction

const static string type_name = $sformatf(“mytest#(%1d)”,NUM);
virtual function string get_type_name();
return type_name;
endfunction
//function new
//function build_phase
endclass

initial begin
run_test($sformatf(“mytest#(%1d)”,NUM));
end

In reply to jjych:

You need to create a parameterized typedef in your testbench so that it can be registered with the factory.

Here is a working example:


import uvm_pkg::*;
`include "uvm_macros.svh"

class mytest#(int NUM) extends uvm_test;
  typedef uvm_component_registry#(mytest#(NUM),$sformatf("mytest#(%1d)",NUM)) type_id;
  static function type_id get_type();
    return type_id::get();
  endfunction

  virtual function uvm_object_wrapper get_object_type();
    return type_id::get();
  endfunction

  const static string type_name = $sformatf("mytest#(%1d)",NUM);
  virtual function string get_type_name();
    return type_name;
  endfunction
  
  function new(string name="mytest", uvm_component parent=null);
    super.new(name, parent);
  endfunction
  //function build_phase
endclass

module testbench();
  parameter NUM = 3;
  typedef mytest#(NUM) mytest_typed;
  
  initial begin
    run_test($sformatf("mytest#(%1d)",NUM));
  end
endmodule

In reply to cgales:
thanks, it’s really works. why add a typedef can make registry successful for the parameterized class? could you explain more to me ? typedef can be used as alias name or pre-declare, but seems it has no relationship with uvm_factory registry. That’s why i ignored it when read article.

In reply to jjych:

i just read this article posted in Patterns Library and have a try.

Hi jjych,
Could you please attach a link to the article? Would like to read it as well.

In reply to Michael54:

https://verificationacademy.com/patterns-library/implementation-patterns/environment-patterns/parameterized-uvm-tests-pattern