How to use uvm component variables using $root or uvm_top or uvm_test_top?

Hello All,

I want to access driver or environment variables using $root or uvm_top or uvm_test_top?

Thanks,
Dipak Jatiya

In reply to Dipak_jatiya:

This is a bad idea, because you have to use hierarchical paths. This limits the reusability of your code.

In reply to Dipak_jatiya:

$root refers to your top module. Components like driver/env are created in test, so you can access these from anywhere (including from top module) using e.g.,

$root.uvm_test_top.env_h.agent_h.drv_h.var_name;
$root.uvm_top.env_h.agent_h.drv_h.var_name;

Or you can use uvm_top/uvm_test_top (refers to test instance) from tests or testbench environment below test hierarchy,

uvm_test_top.env_h.agent_h.drv_h.var_name;
uvm_top.env_h.agent_h.drv_h.var_name;

In reply to MayurKubavat:

Hi Mayur,

I’ve tried the above things but can’t get the test name instance from above.

Get below Error while using

  1. $root.uvm_test_top.y and uvm_test_top.y
    Failed to find ‘uvm_test_top’ in hierarchical name '/$root/uvm_test_top/y

  2. uvm_top.uvm_test_top.y
    Field/method name (uvm_test_top) not in ‘uvm_top’

In short i can’t get the test variable using uvm_test_top.
I’m using this from driver run phase.

Thanks,
Dipak Jatiya

Why not to use configDB in such case if you know which heir and which variable your driver need to know!

not getting why you have to access TB variable using heir. If you could tell us more about your problem it would be more helpful.

In reply to Dipak_jatiya:

If you want to avoid using hierarchical paths. You can use uvm_utils#()::find().

For example, in the test, you know the component instance, you can do

if you want to access a driver, $root.uvm_test_top.m_env.m_agent.m_driver

You can do

agent_driver m_agent_driver;

m_agent_driver = uvm_utils#(agent_driver)::find(m_env)

In reply to MayurKubavat:

Hi,
What is the difference between uvm_top and uvm_test_top? Can You Say in hierarchical order