Q165FreeDesign Verification
End run phase with a forever monitor
Interview prompt
Question
A test owns finite traffic and also starts a forever monitor in run_phase. Show how the test ends without waiting for the monitor to return. The supplied finite sequence is a 40 ns traffic adapter and owns all test work; no additional drain obligation remains after it returns. The supplied monitor adapter records one tick per nanosecond and runs forever. Complete lifetime_test.run_phase; the remaining registered UVM context is provided.
Candidate starting point
Implementation scaffold
package phase_lifetime_pkg;
timeunit 1ns;
timeprecision 1ps;
import uvm_pkg::*;
`include "uvm_macros.svh"
class finite_traffic_seq extends uvm_sequence #(uvm_sequence_item);
`uvm_object_utils(finite_traffic_seq)
function new(string name = "finite_traffic_seq"); super.new(name); endfunction
// Supplied bounded traffic adapter: completion owns all of its test work.
task body(); repeat (4) #10ns; endtask
endclass
class traffic_agent extends uvm_agent;
`uvm_component_utils(traffic_agent)
function new(string name, uvm_component parent); super.new(name, parent); endfunction
uvm_sequencer #(uvm_sequence_item) seqr;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
seqr = uvm_sequencer#(uvm_sequence_item)::type_id::create("seqr", this);
endfunction
endclass
class traffic_env extends uvm_env;
`uvm_component_utils(traffic_env)
function new(string name, uvm_component parent); super.new(name, parent); endfunction
traffic_agent agent;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agent = traffic_agent::type_id::create("agent", this);
endfunction
endclass
class lifetime_test extends uvm_test;
`uvm_component_utils(lifetime_test)
traffic_env env;
finite_traffic_seq traffic_seq;
int unsigned monitor_ticks = 0;
function new(string name, uvm_component parent); super.new(name, parent); endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = traffic_env::type_id::create("env", this);
traffic_seq = finite_traffic_seq::type_id::create("traffic_seq");
endfunction
// Supplied monitor adapter deliberately never returns.
task monitor_forever(); forever begin #1ns; monitor_ticks++; end endtask
task run_phase(uvm_phase phase);
// TODO: own finite traffic with one objection, start the forever monitor
// concurrently, and allow phase completion without joining that monitor.
endtask
endclass
endpackage
module phase_lifetime_example;
import uvm_pkg::*;
import phase_lifetime_pkg::*;
initial run_test("lifetime_test");
endmodule
Reviewed example
Trace one case
Input
traffic completes, the last objection drops, and no new objection is raised during drain timeExpected output
run phase ends; the forever monitor is terminated; later phases runThe forever process belongs to the task phase and does not prevent phase completion after objections and drain handling finish.
What to cover
Requirements
- Raise the objection before starting finite traffic.
- Drop it only after all test-owned traffic completes.
- Explain what happens to forever processes spawned by the task phase.
- State the default effect of UVM's finish_on_completion setting.
