What is the difference between tb =new("tb", this); and tb=new();?

,

Hi.
I’m trying to know the difference between tb =new(“tb”, this); and tb=new();
I thought both are the same but case1 has no Error. but case2 has got error.

What equivalent to tb =new(“tb”, this);?

case1.

class base_test extends uvm_test;
  `uvm_component_utils(base_test)
  test_tb tb;

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction : new

  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    tb = new("tb", this);
  endfunction : build_phase
  
endclass : base_test

case2

class base_test extends uvm_test;
  `uvm_component_utils(base_test)
  test_tb tb;

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction : new

  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    tb = new();
  endfunction : build_phase
  
endclass : base_test

I got error message when I ran case2 as the following.
tb = new() <==== Task/function call or sequence/instance does not specify all required formal argument
What is the difference between them? for new?

I didn’t get it what am I supposed to do to resolve this?

In reply to UVM_LOVE:

All the uvm component constructors will be expecting two arguments (string name, which is used to refer the component & uvm_component parent, which gives the information about who is creating the component) similar to the constructor you mentioned in test class.

For TB the parent will be the test as test is creating the tb, and handle name itself will be used as string to refer the tb. But in the build phase of test while calling the constructor of TB you did not pass the value for those arguments so you are getting the error, it is mandatory to pass those arguments as in case1

In UVM you have to create the components & objects using the factory method create , it is not recommended to create by calling the constructor directly

In reply to shanthi:

In reply to UVM_LOVE:
All the uvm component constructors will be expecting two arguments (string name, which is used to refer the component & uvm_component parent, which gives the information about who is creating the component) similar to the constructor you mentioned in test class.
For TB the parent will be the test as test is creating the tb, and handle name itself will be used as string to refer the tb. But in the build phase of test while calling the constructor of TB you did not pass the value for those arguments so you are getting the error, it is mandatory to pass those arguments as in case1
In UVM you have to create the components & objects using the factory method create , it is not recommended to create by calling the constructor directly

Sorry this is not an answer what I want.

In reply to UVM_LOVE:

In reply to shanthi:
Sorry this is not an answer what I want.

If this is not the answer what you want you could try to ask more concise questions, even the error message is showing what you need to do to fix it.

I believe the error you see is due to the constructor prototype of a uvm_component requires 2 arguments as described in the previous answer you got, You are omitting them both so the tool reports this as an error.

This assuming tb_test is a uvm_component, as you are not showing its source code, specially the constructor.

HTH,
R