从test中覆盖序列成员

时间:2015-01-11 17:50:22

标签: uvm

这是我的简单代码段

class sample_sequence extends uvm_sequence#(sample_sequence_item);


rand int no_txn;
  `uvm_object_param_utils_begin(sample_sequence_item)
  `uvm_field_int(no_txn,UVM_ALL_ON)
  `uvm_object_utils_end

  rand sample_sequence_item sample_sequence_item_inst;
  function new(string name="sample_sequence");
    super.new(name);
  endfunction

  virtual task body();
    no_txn = 10;
    for(int i = 0;i<no_trn;i++) begin
      sample_sequence_item_inst = sample_sequence_item::type_id::create($sformatf("sample_sequence_item_%0d",i));
      sample_sequence_item_inst.addr = $urandom_range(0,20);

      start_item(sample_sequence_item_inst);
      finish_item(sample_sequence_item_inst);
    end


  endtask: body

endclass

序列只生成随机地址并发送给驱动程序。我想从测试中控制参数no_txn。

我可以使用序列的层次结构来实现,但是有没有基于UVM的工厂方法来覆盖它?

1 个答案:

答案 0 :(得分:0)

我取决于你如何开始序列。

如果直接在测试中启动它,则可以在随机化序列时添加约束:

class some_test extends uvm_test;
  // ...

  task run_phase(uvm_phase phase);
    sample_sequence seq = sample_seq::type_id::create("seq");
    if (!seq.randomize() with { no_txn == 5; })
      `uvm_fatal("RANDERR", "Randomization error")
    seq.start(sequencer);
  endtask
endclass

如果你正在扩展一个你开始的测试,就像我上面显示的那样(减去with块),那么你可以创建一个子类来添加一个特定的约束:

class some_other_sequence extends some_sequence;
  constraint do_5_items { no_txn == 5; }
endclass

在测试中的其他地方,您必须设置类型覆盖(我通常在end_of_elaboration_phase(...)函数中执行此操作)。您可以在UVM用户指南中阅读有关类型覆盖和工厂的更多信息。

相关问题