Difficulty: Easy · Puzzle 5 of 6 · Topic: Sequences and Sequencers
UVM 1.2. A virtual sequence uses `p_sequencer` to reach the sub-sequencers. The test starts it with `vseq.start(null)`, because 'a virtual sequence has no sequencer of its own'. What happens?
class top_vseq extends uvm_sequence;
`uvm_object_utils(top_vseq)
`uvm_declare_p_sequencer(top_vsqr)
function new(string name = "top_vseq"); super.new(name); endfunction
task body();
sub_seq s = sub_seq::type_id::create("s");
s.start(p_sequencer.a_sqr);
endtask
endclass
// in the test run_phase
top_vseq vseq = top_vseq::type_id::create("vseq");
vseq.start(null);Where does p_sequencer get its value?
1) p_sequencer is set from m_sequencer when the sequence is started. With start(null) there is no sequencer, so p_sequencer remains null.
2) The $cast generated by `uvm_declare_p_sequencer` succeeds with a null source, so there is no UVM message at start.
3) body() then dereferences `p_sequencer.a_sqr`: a null-handle error at that line.
4) Fix: instantiate a virtual sequencer (`top_vsqr`) in the env, give it handles to the real sequencers, and start the sequence on it: `vseq.start(env.vsqr)`.Answer: p_sequencer stays null; body() dies on a null dereference at `p_sequencer.a_sqr`. Start the vseq on a virtual sequencer.
Not run here: The UVM library is not installed here, so this cannot be executed; p_sequencer is declared by the `uvm_declare_p_sequencer macro and set by uvm_sequence_base::start.. The answer follows the language rules and the solution steps above.
start(null) is legal and produces no warning; it works only if the body never touches p_sequencer or m_sequencer. And starting on a sequencer of the wrong type is a different failure: `uvm_declare_p_sequencer` then raises a UVM_FATAL (DCLPSQ) at start.
Is a virtual sequencer required for virtual sequences? Model answer: no; a virtual sequence can also hold plain handles to the real sequencers and be started with start(null), but then the handles must be assigned by hand and there is no p_sequencer; the virtual sequencer is the conventional way to give every virtual sequence the same, typed access.