# Individual tests extending from base test

**URL:** <https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811>\
**Category:** UVM\
**Tags:** UVM, Polymorphism\
**Created:** [November 16, 2019, 9:20am UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811 "2019-11-16T09:20:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvuvmsv](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@dvuvmsv](https://verificationacademy.com/forums/u/dvuvmsv)\
**Post date:** [November 16, 2019, 9:20am UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/1 "2019-11-16T09:20:13Z")

</div>

Hello,

I have a basic question in all other tests ( apb\_test\_1, apb\_test\_2, apb\_test\_3 )  
extending from apb\_base\_test. I have separate sequences for each test  
apb\_test\_1 has apb\_sequence\_1 which need to be run in sequencer  
apb\_test\_2 has apb\_sequence\_2 which need to be run in sequencer.

My question is since I am extending these tests from apb\_base\_test,  
can I skip these  
// 1. apb\_env env; virtual dut\_if if;  
// 2. function new  
// 3. build\_phase  
and directly write run\_phase() method, and start the corresponding sequencer  
OR  
Do I need to write all 1,2,3 above?

JeffD

```verilog
class apb_base_test extends uvm_test;
`uvm_component_utils(apb_base_test);
  
  apb_env env;
  virtual dut_if vif;
  
  function new(string name = "apb_base_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    env = apb_env::type_id::create("env", this);
    if (!uvm_config_db#(virtual dut_if)::get(this, "", "vif", vif)) begin
      `uvm_fatal("build_phase", "No virtual interface specified for this test instance")
    end 
    uvm_config_db#(virtual dut_if)::set( this, "env", "vif", vif);
  endfunction

  //Run phase - Create an abp_sequence and start it on the apb_sequencer
  task run_phase( uvm_phase phase );
    apb_sequence apb_seq;
    apb_seq = apb_sequence::type_id::create("apb_seq");
    phase.raise_objection( this, "Starting apb_base_seqin main phase" );
    $display("%t Starting sequence apb_seq run_phase",$time);
    apb_seq.start(env.agt.sqr);
    #100ns;
    phase.drop_objection( this , "Finished apb_seq in main phase" );
  endtask
  
endclass

class apb_test_1 extends apb_base_test;
  // Since I am extending from apb_base_test above, do I need to 
  // 1. apb_env env; virtual dut_if if;
  // 2. function new 
  // 3. build_phase
  // 4. 
endclass

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 16, 2019, 4:15pm UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/2 "2019-11-16T16:15:50Z")

</div>

_In reply to [dvuvmsv](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811):_

When extending _any_ class, you must define a new() if there are constructor arguments that need to be passed down.

You should _definitely not_ re-declare env or vif. The whole point of inheritance is using the variable declared in the base class.

Whether or not you override build\_phase or run\_phase depends on how different each test is. If the only different is which sequence to start, than you can use the build\_phase to set a factory override, and then you don’t need a different run\_phase for each test.

```verilog
class apb_test_1 extends apb_base_test;
 function new(string name = "apb_test_1", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    set_type_override_by_type(apb_sequence::get_type(), apb_sequence_1::get_type());
    super.build_phase(phase);
  endfunction
endclass

```

---

<div class="post-metadata">

**Author:** ![dvuvmsv](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@dvuvmsv](https://verificationacademy.com/forums/u/dvuvmsv)\
**Post date:** [November 17, 2019, 5:30am UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/3 "2019-11-17T05:30:00Z")

</div>

Thank you Dave for your response. You gave an example for factory override  
and that way we don’t need to have a run\_phase. Just override the apb\_sequence with apb\_sequence\_1

Otherwise we need to have the following with run\_phase.

class apb\_test\_1 extends apb\_base\_test;

`uvm\_component\_utils(apb\_test\_1);

function new(string name = “apb\_test\_1”, uvm\_component parent = null);  
super.new(name, parent);  
endfunction

function void build\_phase(uvm\_phase phase);  
super.build\_phase(phase);  
endfunction

task run\_phase( uvm\_phase phase );  
apb\_sequence\_1 apb\_seq\_1;  
apb\_seq\_1 = apb\_sequence\_1::type\_id::create(“apb\_seq\_1”);  
phase.raise\_objection( this, “Starting apb\_sequence\_1 in main phase” );  
$display(“%t Starting sequence apb\_seq\_1 run\_phase”,$time);  
apb\_seq\_1.start(env.agt.sqr);  
#100ns;  
phase.drop\_objection( this , “Finished apb\_seq\_1 in main phase” );  
endtask

endclass

---

<div class="post-metadata">

**Author:** ![dvuvmsv](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@dvuvmsv](https://verificationacademy.com/forums/u/dvuvmsv)\
**Post date:** [November 17, 2019, 6:15am UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/4 "2019-11-17T06:15:49Z")

</div>

Hi,

```
I need to specify a addr=32'100 and data=32'd200 using `uvm_do_with in a sequence.

```

Here I am not randomizing. When I run the test , I am not getting addr 32’d100 and data 32’d200. Is there anything wrong with this ?

class apb\_transaction extends uvm\_sequence\_item;

`uvm\_object\_utils(apb\_transaction)

//typedef for READ/Write transaction type  
typedef enum {READ, WRITE} kind\_e;  
rand bit [31:0] addr; //Address  
rand bit [31:0] data; //Data - For write or read response  
rand kind\_e pwrite; //command type

constraint c1{addr[31:0]\>=32’d0; addr[31:0] \<32’d256;};  
constraint c2{data[31:0]\>=32’d0; data[31:0] \<32’d256;};

function new (string name = “apb\_transaction”);  
super.new(name);  
endfunction

function string convert2string();  
return $psprintf(“pwrite=%s paddr=%0h data=%0h”,pwrite,addr,data);  
endfunction

endclass

class apb\_sequence\_2 extends uvm\_sequence#(apb\_transaction);  
`uvm\_object\_utils(apb\_sequence\_2)

function new (string name = “”);  
super.new(name);  
endfunction

task body();  
apb\_transaction rw\_trans\_2;  
repeat(1)  
begin  
rw\_trans\_2=new();  
`uvm\_do\_with(rw\_trans\_2, {rw\_trans\_2.addr == 32’d100;  
rw\_trans\_2.data == 32’d200;  
rw\_trans\_2.pwrite == WRITE;  
});

```
end

```

endtask

endclass

class apb\_test\_2 extends apb\_base\_test;

`uvm\_component\_utils(apb\_test\_2);

function new(string name = “apb\_test\_2”, uvm\_component parent = null);  
super.new(name, parent);  
endfunction

function void build\_phase(uvm\_phase phase);  
super.build\_phase(phase);  
endfunction

task run\_phase( uvm\_phase phase );  
apb\_sequence\_2 apb\_seq\_2;  
apb\_seq\_2 = apb\_sequence\_2::type\_id::create(“apb\_seq\_2”);  
phase.raise\_objection( this, “Starting apb\_sequence\_2 in main phase” );  
$display(“%t Starting sequence apb\_seq\_2 run\_phase”,$time);  
apb\_seq\_2.start(env.agt.sqr);  
#100ns;  
phase.drop\_objection( this , “Finished apb\_seq\_2 in main phase” );  
endtask

endclass

JeffD

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [November 17, 2019, 8:01am UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/5 "2019-11-17T08:01:22Z")

</div>

_In reply to [dvuvmsv](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/4):_

I see 2 weaknesses in your code:  
(1) constructing your seq\_item

```verilog
rw_trans_2=new();

```

It should be like this (using the create of the factory):

```verilog
rw_trans_2 = apb_transaction::type_id::create("rw_trans_2");

```

(2) never use $display in your UVM code use instead `uvm\_info

Both do not influence the seq\_item generation.  
But you do not show which test you are executing.

---

<div class="post-metadata">

**Author:** ![dvuvmsv](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@dvuvmsv](https://verificationacademy.com/forums/u/dvuvmsv)\
**Post date:** [November 17, 2019, 4:26pm UTC](https://verificationacademy.com/forums/t/individual-tests-extending-from-base-test/36811/6 "2019-11-17T16:26:29Z")

</div>

Thanks chr\_sue for the suggestions.  
I was able to get the specific address.  
It was a %h vs %d issue where the data was correct,  
but in a different format and I could’nt recognize

JeffD
