`timescale 1ns/1ns
module test;// 这个简单示例展示了如何使用 uvm_test_done 异议机制来协调测试结束活动。// 若想了解在完整环境中使用测试结束协调的示例,请参考 xbus 示例。//// 在本例中,组件设置了一个 10 时间单位的排空时间(drain time)。// 组件随后启动了 4 个进程,这些进程消耗不同的时间。// 当最后一个进程完成(时间为 50)时,排空时间开始生效。// 测试在时间 60 结束。//// 该示例还展示了组件异议回调的用法。// 本例中使用了 dropped 回调,但 raised 和 all_dropped 的工作方式类似,// 只是 all_dropped 是一个耗时的任务。
import uvm_pkg::*;
`include "uvm_macros.svh"classsimple_test extends uvm_test;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction :new// Register with the factory.
`uvm_component_utils(simple_test)virtual task run_phase(uvm_phase phase);// Set a drain time on the objection if neededuvm_report_info("drain","Setting drain time of 10", UVM_NONE);
uvm_test_done.set_drain_time(this,10);// Run a bunch of processes in parallel
fork
doit(35);doit(25);doit(50);doit(15);
join
endtask
// A simple task that consumes some time.
task doit(time delay);staticint s_inst =0;int inst = s_inst++;//Raise an objection before starting the activity
uvm_test_done.raise_objection(this);uvm_report_info("doit", $sformatf("Starting doit (%0d) with delay %0t",
inst, delay), UVM_NONE);#delay;uvm_report_info("doit", $sformatf("Ending doit (%0d)", inst), UVM_NONE);//Drop the objection when done
uvm_test_done.drop_objection(this);
endtask
// Use an objection callback do something when objections are raised or// dropped (or all dropped). This example prints some information on each// drop.virtual function voiddropped(uvm_objection objection,
uvm_object source_obj, string description,int count);uvm_report_info("dropped",
$sformatf("%d objection(s) dropped from %s, total count is now %0d",
count, source_obj.get_full_name, objection.get_objection_total(this)),
UVM_NONE);
endfunction
endclass : simple_test
// Run the test
initial
run_test("simple_test");
endmodule
以下是实际仿真结果:
--------------------------------------------------------