In reply to warnerrs:
Hi thanks for the explanation, I appreciate it.
Still it’s disappointing that it doesn’t work from uvm_test, calling a sequence from a testcase is probably the most common action in verification… Not having an concise way to do that is unfortunate.
I did try rewriting it but encountered additional problems. Seq.create() must be used instead of create_item, this requires knowledge of the sequence type. We also need to know where the macro was called from. Is it possible to access this information without a reflection mechanism?
Here’s an attempt at it but maybe a lost cause. start_item/finish_item will give compile error when used in uvm_test.
- 1st branch uses create, randomize, start and the
- 2nd branch uses create_item, randomize, start_item, finish_item
`define uvm_do_from_test(SEQ_TYPE, SEQ_OR_ITEM, SEQR, PRIORITY, CONSTRAINTS) \
begin \
uvm_sequence_base __seq; \
if (this.get_full_name() == "uvm_test_top") begin \
SEQ_OR_ITEM = SEQ_TYPE::type_id::create(\"SEQ_OR_ITEM\"); \
if (!(SEQ_OR_ITEM.randomize() with CONSTRAINTS)) \
`uvm_fatal(get_type_name(),$sformatf("Sequence randomization failed")) \
SEQ_OR_ITEM.start(SEQR); \
end else begin \
`uvm_create_on(SEQ_OR_ITEM, SEQR) \
if (!$cast(__seq,SEQ_OR_ITEM)) start_item(SEQ_OR_ITEM, PRIORITY); \
if (!(SEQ_OR_ITEM.randomize() with CONSTRAINTS)) \
`uvm_fatal(get_type_name(),$sformatf("Sequence randomization failed")) \
if (!$cast(__seq,SEQ_OR_ITEM)) finish_item(SEQ_OR_ITEM, PRIORITY); \
end \
end