You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅运行继承自uvm_test的子类测试类?父类同步执行问题咨询

UVM测试类继承执行问题解答

问题场景

用+UVMTESTNAME=test2指定运行继承自test1的test2测试类时,发现test1的run_phase逻辑也被执行了。担心如果后续有1000个继承层级的测试类,运行最底层的测试类时会触发所有父类的phase逻辑,想确认这是UVM的固有特性还是代码实现有误。

相关代码

test1类代码

class test1 extends test_base;
  `uvm_component_utils(test1)
   main_ahb_sequence seq;

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
    
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    seq = main_ahb_sequence::type_id::create("seq", this);  
    if(!seq.randomize())
    `uvm_error("rand failed", UVM_LOW)
  endfunction
    
  task run_phase(uvm_phase phase);
    phase.raise_objection(this);  
    seq.start(ahb0.sequencer);
    phase.drop_objection(this);
  endtask
endclass

test2类代码

class test2 extends test1;
  `uvm_component_utils(test2)
   
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
 
  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    factory.print();
  endfunction
 
  task run_phase(uvm_phase phase);
    super.run_phase(phase);
    phase.raise_objection(this);
    `uvm_info("TEST2", "THIS is run_phase from test2", UVM_LOW);
    phase.drop_objection(this);
  endtask
 
endclass

原因分析

这不是UVM的固有特性,问题出在代码实现上:

  • UVM只会实例化+UVMTESTNAME指定的测试类,不会额外实例化父类test1。
  • 但test2的run_phase中显式调用了super.run_phase(phase);,这会触发父类test1的run_phase逻辑执行,所以你会看到test1的序列也在运行。

解决方案

如果希望仅执行test2自己的run_phase逻辑,直接去掉test2中run_phase里的super.run_phase(phase);语句即可。

如果需要复用父类的部分逻辑,不要直接调用整个父类phase方法,而是把父类中可复用的逻辑提取成单独的任务/函数,在子类中按需调用。

内容的提问来源于stack exchange,提问作者bu-ral

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 16:07:38