1. Chen Yong
  2. UVM
  3. Friday, 16 August 2019

When reading with " Using factory overrides " and tried example with uvm-factory-overrides.zip, I'm confused by this piece of code:

`ifdef DRV_STYLE1
// Substitute all instances of base_driver with driver2
set_type_override_by_type (base_driver::get_type(), spi_driver::get_type());
`elsif DRV_STYLE2
// Substitute only eth_driver in agnt2 with spi_driver - by calling the component to be replaced method
eth_driver::type_id::set_inst_override (spi_driver::get_type(), "m_top_env.m_agnt2.m_drv0", this);
`elsif DRV_STYLE3
// Substitute base_driver only in agnt0 - by calling the factory method
factory.set_inst_override_by_type (base_driver::get_type(), eth_driver::get_type(), {get_full_name(), ".m_top_env.m_agnt0.*"});

When I run test "feature_test" with "DRV_STYLE2" defined, simulator reports error as:

UVM_FATAL @ 0: reporter [FCTTYP] Factory did not return a component of type 'eth_driver #(T)'. A component of type 'spi_driver #(T)' was returned instead. Name=m_drv0 Parent=my_agent_v2 contxt=uvm_test_top.m_top_env.m_agnt2

This confused me. I think this piece of code is used to override eth_driver with spi_driver. The simulator seems returned with spi_driver as request. Why simulator report error? Thanks.
Responses (1)
Accepted Answer Pending Moderation
DRV_STYLE2 is expected to give an error and demonstrates that parent classes of a given type can be overridden by its children using the factory, but there will be a type error when a completely different class is returned by the factory. In this case, spi_driver and eth_driver are both children of base_driver. However they are different entities and cannot be substituted one for another. eth_driver_v2 however can be used to override eth_driver since they are related types.
  1. more than a month ago
  2. UVM
  3. # 1
  • Page :
  • 1

There are no replies made for this post yet.
Be one of the first to reply to this post!