Jump to content
Sign in to follow this  
mrforever

problem about parameterized test and factory mechanism

Recommended Posts

Hi, all

 

I want to use the factory mechanism to write one reusable test, this is the codes

class my_test #(parameter TSID=0) extends uvm_test;
  typedef my_test #(TSID) this_typ;

  typedef uvm_component_registry #(my_test #(TSID), $sformatf("my_test%0d", TSID)) type_id;

  static function type_id get_type();
    return type_id::get();
  endfunction : get_type

  function new(string name = "my_test", uvm_component parent=null);
    super.new(name,parent);
  endfunction : new
  ...
endclass

But I met such a compile error:

 

Error-[NCE] Non-constant expression
  The following expression should be a constant.
  Expression: $sformatf("my_test%0d", TSID)
  Source info:   typedef uvm_component_registry #(my_test #(TSID), 
  $sformatf("my_test%0d", TSID)) type_id;
...
 
If the second parameter should be a constant or constant expression in 
  typedef uvm_component_registry #(my_test #(TSID), $sformatf("my_test%0d", TSID)) type_id;

then how can i distinguish the specialized test using TSID which is from run option (my original idea is that using parameter TSID to distinguish the different specialized test)?

 

Second problem, my_test is a generic class now, where should the specialized test define and how to define if my original idea is feasible?

 

Regards

Share this post


Link to post
Share on other sites

Hi Mrforever,

 

  I'm not sure what you're trying to do exactly. It depends how you use your parameter TSID, but can't you just retrieve it from the config_db? Config_db parameters can be set from the command line if necessary.

 

Alternatively you can just create a base class test with a default value for TSID, and override it to create customized test classes (different values of TSID). You can even declare TSID rand, and create randomized configurations of your tests.

 

regards

Alan

Share this post


Link to post
Share on other sites

This would work if you were using Questa; $sformatf is considered a constant function if all its arguments are constants as well. To work around this, you can add a string parameter.

class my_test #(parameter int TSID, string SID) extends uvm_test;
typedef uvm_component_registry #(my_test #(TSID,SID), SID)) type_id;

Note that in either case, my_test does not get registered with the factory by name unless there is an explicit specialization of that class. See http://go.mentor.com/mcem. You would have to create references to each specialization you wanted to look up by a string name.

typedef my_test#(1) my_test1;
typedef my_test#(2) my_test2;
typedef my_test#(3) my_test3;

This would give you the ability to lookup the three specializations by the names "my_test1", "my_test2", and "my_test3".

Share this post


Link to post
Share on other sites

Hi,

 

Instead of using uvm_component_registry why don't use `uvm_component_param_utils. It will automaticlly register your component with factory by calling uvm_component_registry

 

 

 

-Sai

This is not correct. A parameterized class does not get registered with the factory regardless of whether you use uvm_component_registry directly or the `uvm_component_params_util macro. There must be a specialization of the parameterized class for any static member to exist. See http://go.mentor.com/mcem.

Share this post


Link to post
Share on other sites

Hi Mrforever,

 

  I'm not sure what you're trying to do exactly. It depends how you use your parameter TSID, but can't you just retrieve it from the config_db? Config_db parameters can be set from the command line if necessary.

 

Alternatively you can just create a base class test with a default value for TSID, and override it to create customized test classes (different values of TSID). You can even declare TSID rand, and create randomized configurations of your tests.

 

regards

Alan

 

Hi Alan,

Hi, Dave 

    Thanks for your suggestion, I think i have found the problem. I think the factory mechanism should work at the compile-time, when i use run-time option to registered my_test #(TSID), vcs doesn't support it, i didn't take your suggestion to have a test, i don't know whether it will work.

Share this post


Link to post
Share on other sites

Folks,

 

We had some complaints about this thread.  If there is truly a tools-related issue, that should be directed to the vendor's support team. We shouldn't use these forums to suggest that users of vendor X would be better off with vendor Y.  If a vendor has something to promote, that should be handled in the "Simulator Specific" or "Commercial" forums.

 

=Adam Sherer

Accellera Promotions Committee Vice-Chair

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×