提高UVM Sequences 復(fù)用程度的3大準(zhǔn)則
sequence的編寫和調(diào)試是非常體現(xiàn)驗證工程師編碼能力的地方之一,如果每一個sequnce都有著完全不同的工作模式,那么維護(hù)起來非常痛苦。
網(wǎng)絡(luò)上有一個段子,程序員最討厭4件事情:1、寫文檔2、別人不寫文檔3、寫注釋4、別人不寫注釋
想象一下,如果你驗證同事離職,交接給你上百個定向且詭異的測試用例或者sequence?你會不會立馬想去重構(gòu)。
sequences 由多個事務(wù)激勵組成,在UVM中其繼承自參數(shù)化類uvm_sequence。通過這些事務(wù)觸發(fā)一些驗證工程師希望觸及的場景,而sequence的分層會創(chuàng)建一些更加復(fù)雜的場景激勵。驗證空間隨著設(shè)計規(guī)模指數(shù)級上升,驗證激勵自然也會越來越復(fù)雜。
class usb_simple_sequence extends uvm_sequence #(usb_transfer); rand int unsigned sequence_length; constraint reasonable_seq_len { sequence_length < 10 }; //Constructor function new(string name=”usb_simple_bulk_sequence”); super.new(name); endfunction //Register with factory `uvm_object_utils(usb_simple_bulk_sequence) //the body() task is the actual logic of the sequence virtual task body(); repeat(sequence_length) `uvm_do_with(req, { //Setting the device_id to 2 req.device_id == 8’d2; //Setting transfer type to BULK req.type == usb_transfer::BULK_TRANSFER; }) endtask : body endclass |
class usb_simple_bulk_test extends uvm_test; … virtual function void build_phase(uvm_phase phase ); … uvm_config_db#(uvm_object_wrapper)::set(this, "sequencer_obj. main_phase","default_sequence", usb_simple_sequence::type_id::get()); … endfunction : build_phase endclass |
1、只在base sequence 類中的pre_start和post_start任務(wù)中raising objections和 dropping objections來管理測試用例的開始和結(jié)束。通過這種方式,能夠減少每一個sequence子類中的相關(guān)phase控制代碼。
task pre_start() if(starting_phase != null) starting_phase.raise_objection(this); endtask : pre_start task post_start() if(starting_phase != null) starting_phase.drop_objection(this); endtask : post_start |
class usb_simple_bulk_test extends uvm_test; usb_simple_sequence seq; … virtual function void main_phase(uvm_phase phase ); … //User need to set the starting_phase as sequence start method is explicitly called to invoke the sequence seq.starting_phase = phase; seq.start(); … endfunction : main_phase endclass |
class usb_simple_sequence extends uvm_sequence #(usb_transfer); rand int unsigned sequence_length; constraint reasonable_seq_len { sequence_length < 10 }; … virtual task body(); usb_transfer::type_enum local_type; bit[7:0] local_device_id; //Get the values for the variables in case toplevel //test/sequence sets it. uvm_config_db#(int unsigned)::get(null, get_full_name(), “sequence_length”, sequence_length); uvm_config_db#(usb_transfer::type_enum)::get(null, get_full_name(), “l(fā)ocal_type”, local_type); uvm_config_db#(bit[7:0])::get(null, get_full_name(),? “l(fā)ocal_device_id”, local_device_id); repeat(sequence_length) `uvm_do_with(req, { req.device_id == local_device_id; req.type == local_type; }) endtask : body endclass |
uvm_config_db#()::set
中使用的參數(shù)類型和字符串(第三個參數(shù))應(yīng)該與uvm_config_db#()::get
中使用的類型相匹配,否則將無法正確配置。這個地方如果出錯會非常痛苦,但好在不需要經(jīng)常修改,痛苦一次就好。另外,這幾個配置項是隨機(jī)類型,相應(yīng)的配置值也需要滿足約束范圍。3、在創(chuàng)建復(fù)雜sequence的時候盡量去復(fù)用簡單的sequence。例如,在下面的sequence 中順序發(fā)送不同的sequnce(層次化和模塊化,永遠(yuǎn)是編碼規(guī)范之一):
class usb_complex_sequence extends uvm_sequence #(usb_transfer); //Object of simple sequence used for sending bulk transfer usb_simple_sequence simp_seq_bulk; //Object of simple sequence used for sending interrupt transfer usb_simple_sequence simp_seq_int; … virtual task body(); //Variable for getting device_id for bulk transfer bit[7:0] local_device_id_bulk; //Variable for getting device_id for interrupt transfer bit[7:0] local_device_id_int; //Variable for getting sequence length for bulk int unsigned local_seq_len_bulk; //Variable for getting sequence length for interrupt int unsigned local_seq_len_int; //Get the values for the variables in case top level //test/sequence sets it. uvm_config_db#(int unsigned)::get(null, get_full_name(), “l(fā)ocal_seq_len_bulk”,local_seq_len_bulk); uvm_config_db#(int unsigned)::get(null, get_full_name(), “l(fā)ocal_seq_len_int”,local_seq_len_int); uvm_config_db#(bit[7:0])::get(null, get_full_name(), “l(fā)ocal_device_id_bulk”,local_device_id_bulk); uvm_config_db#(bit[7:0])::get(null, get_full_name(), “l(fā)ocal_device_id_int”,local_device_id_int); //Set the values for the variables to the lowerlevel //sequence/sequence item, which we got from //above uvm_config_db::get. //Setting the values for bulk sequence uvm_config_db#(int unsigned)::set(null, {get_full_name(),”.”, ”simp_seq_bulk”}, “sequence_length”,local_seq_len_bulk); uvm_config_db#(usb_transfer::type_enum)::set(null, {get_full_name(), “.”,“simp_seq_bulk”} , “l(fā)ocal_type”,usb_transfer::BULK_TRANSFER); uvm_config_db#(bit[7:0])::set(null, {get_full_name(), “.”, ”simp_seq_bulk”}, “l(fā)ocal_device_id”,local_device_id_bulk); //Setting the values for interrupt sequence uvm_config_db#(int unsigned)::set(null, {get_full_name(),”.”, ”simp_seq_int”}, “sequence_length”,local_ seq_len_int); uvm_config_db#(usb_transfer::type_enum)::set(null, {get_full_name(), “.”,“simp_seq_int”} , “l(fā)ocal_type”,usb_transfer::INT_TRANSFER); uvm_config_db#(bit[7:0])::set(null,{get_full_name(),“.”, ”simp_seq_bulk”},“l(fā)ocal_device_id”,local_device_id_int); `uvm_do(simp_seq_bulk) simp_seq_bulk.get_response(); `uvm_send(simp_seq_int) simp_seq_int.get_response(); endtask : body endclass |