Skip to content

Commit c0c0928

Browse files
committed
[dv] Teach dv_base_test to accept an env_cfg object from db
This is designed so that a testbench has the option of creating the env_cfg object in place (and e.g. connecting up interfaces directly), which should be a little simpler, especially for passive environments. Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
1 parent 9547923 commit c0c0928

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

hw/dv/sv/dv_lib/dv_base_test.sv

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,30 @@ class dv_base_test #(type CFG_T = dv_base_env_cfg,
4848
if (!uvm_config_db#(uvm_object_wrapper)::get(this, "env", "cfg_type", cfg_type)) begin
4949
cfg_type = CFG_T::get_type();
5050
end
51-
base_cfg = cfg_type.create_object("cfg");
52-
if (!base_cfg) begin
53-
`uvm_fatal(`gfn, $sformatf("Failed to create object of type %p", cfg_type))
54-
end
5551

56-
// At this point, we will normally have just created an object of type CFG_T, but have a handle
57-
// to it with a weaker type. But we might have got an instance of some extension class if one is
58-
// passed as cfg_type. Either way, we should be able to cast the result to a CFG_T.
59-
if (!$cast(cfg, base_cfg)) begin
60-
`uvm_fatal(`gfn,
61-
$sformatf("Failed to cast object of type %p to expected CFG_T class.", cfg_type))
52+
// Now we know the config type, see whether one has been created by the testbench, configured
53+
// and supplied through uvm_config_db.
54+
//
55+
// Note that we do the lookup through CFG_T rather than cfg_type, because the latter is only
56+
// known at runtime. If there isn't a cfg object that has been provided, we create one ourselves
57+
// and call its initialize() method.
58+
if (!uvm_config_db#(CFG_T)::get(this, "env", "cfg", cfg)) begin
59+
base_cfg = cfg_type.create_object("cfg");
60+
if (!base_cfg) begin
61+
`uvm_fatal(`gfn, $sformatf("Failed to create object of type %p", cfg_type))
62+
end
63+
64+
// At this point, we will normally have just created an object of type CFG_T, but have a
65+
// handle to it with a weaker type. But we might have got an instance of some extension class
66+
// if one is passed as cfg_type. Either way, we should be able to cast the result to a CFG_T.
67+
if (!$cast(cfg, base_cfg)) begin
68+
`uvm_fatal(`gfn,
69+
$sformatf("Failed to cast object of type %p to expected CFG_T class.", cfg_type))
70+
end
71+
72+
cfg.initialize();
6273
end
6374

64-
cfg.initialize();
6575
`DV_CHECK_RANDOMIZE_FATAL(cfg)
6676

6777
// Try to retrieve a reset interface (if the testbench has provided one). If so, create an
@@ -91,7 +101,10 @@ class dv_base_test #(type CFG_T = dv_base_env_cfg,
91101

92102
void'($value$plusargs("cdc_instrumentation_enabled=%d", cfg.en_dv_cdc));
93103

104+
// Register cfg in the config db. This might already have been registered, but that shouldn't
105+
// matter.
94106
uvm_config_db#(CFG_T)::set(this, "*", "cfg", cfg);
107+
95108
env = ENV_T::type_id::create("env", this);
96109
endfunction : build_phase
97110

0 commit comments

Comments
 (0)