Last active
November 6, 2018 02:32
-
-
Save sagar5258/9d28b9f201fda7be37b03c9cf20614ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class my_object extends uvm_object; | |
| integer a; | |
| `uvm_object_utils_begin(my_object) | |
| `uvm_field_int(a, UVM_DEFAULT | UVM_DEC) | |
| `uvm_object_utils_end | |
| function new(string name = "my_object"); | |
| super.new(name); | |
| endfunction : new | |
| endclass : my_object | |
| class my_env extends uvm_env; | |
| int unsigned idx; // will get auto configured | |
| // won't get auto configured as it is not registered in factory using `uvm_field_* macro | |
| int unsigned idx1; | |
| // will get auto configured as it is set using uvm_config_db#(int)::set | |
| bit [47:0] idx2; | |
| // won't get auto configured as it is set using uvm_config_db#(bit[47:0])::set | |
| bit [47:0] idx22; | |
| logic [127:0] idx3; // will get auto configured | |
| string abc; // will get auto configured | |
| // will get auto configured as it is set using base type (uvm_config_db#(uvm_object)::set) | |
| my_object obj1; | |
| // won't get auto configured as it is set using extended type (uvm_config_db#(my_object)::set) | |
| my_object obj2; | |
| // Unpack Array won't get auto configured | |
| int ary_int[5]; | |
| // Real variable won't get auto configured | |
| real r1; | |
| `uvm_component_utils_begin(my_env) | |
| `uvm_field_int(idx, UVM_DEFAULT | UVM_DEC) | |
| //`uvm_field_int(idx1, UVM_DEFAULT | UVM_DEC) | |
| `uvm_field_int(idx2, UVM_DEFAULT | UVM_HEX) | |
| `uvm_field_int(idx22, UVM_DEFAULT | UVM_HEX) | |
| `uvm_field_int(idx3, UVM_DEFAULT | UVM_HEX) | |
| `uvm_field_string(abc, UVM_DEFAULT) | |
| `uvm_field_object(obj1, UVM_DEFAULT) | |
| `uvm_field_object(obj2, UVM_DEFAULT) | |
| `uvm_field_sarray_int(ary_int, UVM_DEFAULT) | |
| `uvm_field_real(r1, UVM_DEFAULT) | |
| `uvm_component_utils_end | |
| function new (string name = "my_env", uvm_component parent = null); | |
| super.new(name, parent); | |
| endfunction : new | |
| function void build_phase (uvm_phase phase); | |
| super.build_phase(phase); | |
| //if (!uvm_config_db#(my_cfg)::get(this, "", "cfg", cfg)) begin | |
| // `uvm_fatal(get_name(), $sformatf("Need to set cfg for this")) | |
| //end | |
| `uvm_info(get_name(), $sformatf("In ENV build_phase \n%s", this.sprint()), UVM_LOW) | |
| endfunction : build_phase | |
| endclass : my_env | |
| class my_test extends uvm_test; | |
| my_env env; | |
| int unsigned idx; | |
| int unsigned idx1; | |
| bit [47:0] idx2; | |
| bit [47:0] idx22; | |
| logic [127:0] idx3; | |
| string abc; | |
| my_object obj1; | |
| my_object obj2; | |
| int ary_int[10]; | |
| real r1; | |
| `uvm_component_utils_begin(my_test) | |
| `uvm_field_object(env, UVM_DEFAULT) | |
| `uvm_field_int(idx, UVM_DEFAULT | UVM_DEC) | |
| `uvm_field_int(idx1, UVM_DEFAULT | UVM_DEC) | |
| `uvm_field_int(idx2, UVM_DEFAULT | UVM_HEX) | |
| `uvm_field_int(idx22, UVM_DEFAULT | UVM_HEX) | |
| `uvm_field_int(idx3, UVM_DEFAULT | UVM_HEX) | |
| `uvm_field_string(abc, UVM_DEFAULT) | |
| `uvm_field_object(obj1, UVM_DEFAULT) | |
| `uvm_field_object(obj2, UVM_DEFAULT) | |
| `uvm_field_sarray_int(ary_int, UVM_DEFAULT) | |
| `uvm_field_real(r1, UVM_DEFAULT) | |
| `uvm_component_utils_end | |
| function new (string name = "my_test", uvm_component parent = null); | |
| super.new(name, parent); | |
| endfunction : new | |
| function void build_phase (uvm_phase phase); | |
| super.build_phase(phase); | |
| env = my_env :: type_id :: create ("env", this); | |
| obj1 = my_object:: type_id ::create ("obj1"); | |
| obj2 = my_object:: type_id ::create ("obj2"); | |
| idx = 5; | |
| idx1 = 25; | |
| idx2 = 48'hFFFF_FFFF_FFFF; | |
| idx22 = 48'hFFFF_FFFF_FFFF; | |
| idx3 = 531; | |
| abc = "auto_config"; | |
| obj1.a = 10; | |
| obj2.a = 10; | |
| for(int unsigned i=0; i< $size(ary_int); i++) begin | |
| ary_int[i] = i; | |
| end | |
| r1 = 543.123456; | |
| uvm_config_db#(int)::set(this, "env", "idx", this.idx); | |
| uvm_config_db#(int)::set(this, "env", "idx1", this.idx1); | |
| uvm_config_db#(int)::set(this, "env", "idx2", this.idx2); | |
| uvm_config_db#(bit[47:0])::set(this, "env", "idx22", this.idx22); // Not working | |
| uvm_config_db#(int)::set(this, "env", "idx3", this.idx3); | |
| uvm_config_db#(string)::set(this, "env", "abc", this.abc); | |
| uvm_config_db#(uvm_object)::set(this, "env", "obj1", this.obj1); | |
| uvm_config_db#(my_object)::set(this, "env", "obj2", this.obj2); // Not working | |
| for(int unsigned i=0; i< $size(ary_int); i++) begin | |
| uvm_config_db#(int)::set(this, "env", $sformatf("ary_int_%0d", i), this.ary_int[i]); | |
| end | |
| uvm_config_db#(real)::set(this, "env", "r1", this.r1); | |
| endfunction : build_phase | |
| endclass : my_test | |
| module top(); | |
| initial begin | |
| run_test("my_test"); | |
| end | |
| endmodule : top | |
| //Output: | |
| // UVM_INFO apply_config_setting_to_get_resource_2.sv(63) @ 0: uvm_test_top.env [env] In ENV build_phase | |
| // --------------------------------------------- | |
| // Name Type Size Value | |
| // --------------------------------------------- | |
| // env my_env - @352 | |
| // idx integral 32 'd5 | |
| // idx2 integral 48 'hffffffffffff | |
| // idx22 integral 48 'h0 | |
| // idx3 integral 128 'h213 | |
| // abc string 11 auto_config | |
| // obj1 my_object - @361 | |
| // a integral 32 'd10 | |
| // obj2 object - <null> | |
| // ary_int sa(integral) 5 - | |
| // [0] integral 32 'h0 | |
| // [1] integral 32 'h0 | |
| // [2] integral 32 'h0 | |
| // [3] integral 32 'h0 | |
| // [4] integral 32 'h0 | |
| // r1 real 64 0.000000 | |
| // --------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment