mrforever Posted February 7, 2014 Report Share Posted February 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
apfitch Posted February 11, 2014 Report Share Posted February 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
dave_59 Posted February 11, 2014 Report Share Posted February 11, 2014 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". Quote Link to comment Share on other sites More sharing options...
cool_cake20 Posted February 17, 2014 Report Share Posted February 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
dave_59 Posted February 17, 2014 Report Share Posted February 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
mrforever Posted February 18, 2014 Author Report Share Posted February 18, 2014 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. Quote Link to comment Share on other sites More sharing options...
Adam Sherilog Posted February 18, 2014 Report Share Posted February 18, 2014 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.