Get a configuration class object in interface

Hi,

Can we set-get a configuration class object from a class in an interface?

I wish to write some assertions that involves making use of some configuration knobs. Is it possible?

In reply to adharshh:

You can pass the config object to the config_db and retrieve it in any other place.

In reply to chr_sue:

I tried that. I am setting config_db in test and getting it in interface.
//My Test
class test;

function build_phase;

uvm_config_db#(config_class)::set(this,“*”,“config_class”,c1);

endfunction

endclass

//My Interface code
interface intf;
function void config_fun;
config_class c1;
if(uvm_config_db#(config_class)::get(null,“”,“config_class”,c1))
$display(“values are %0p”,c1);
endfunction

Note : When displaying, its showing null,(Not able to get the config class).
Is the above syntax correct?

In reply to adharshh:

Can you change the context of set method and try again:


uvm_config_db#(config_class)::set(null,"*","config_class",c1);

In reply to cuonghle:

Even now its not working,after changing the context of set method.

what should i do to make it work.

Im Able to get the default values of configuration in interface but not the actual configuration values what we configure in test.

In reply to adharshh:

You have to indicate when the config object has been pased to the config_db. Because the interface is a static construct it does not belong to the dynmic part of your testbench. The static constructs will be build earlier than the dynamic ones.

In reply to adharshh:

Can you share where did you call the function “config_fun” in your interface?
I think you need to pass “null” as context (from root) so you are able to get in anywhere.

In reply to cuonghle:

You have to pass as the context ‘null’. This is indicating the path itself is considered as an absolute path. Becuase the interface does not belong to the dynamic part of your testbench this is required.

In reply to adharshh:

That’s the same situation. The get in the inital block will be executed before your dynamic testbench exists.