Constrained randomization

In reply to dave_59:

Hi Dave,

Thank you very much for the detailed explanation.

My intention is not to randomize any of the transaction item variable from a test case rather, I was trying to control number of sequence to be generated from a test by randomizing the variable defined inside a sequence.

Here is what i meant. sram_test → sram_sequence → sram_transaction

class sram_test extends sram_base_test;

  sram_sequence sram_seq;

  `uvm_component_utils(sram_test)

  function new(input string name="sram_test", input uvm_component parent=null);
      super.new(name,parent);
  endfunction

  virtual function void build_phase(uvm_phase phase);

    super.build_phase(phase);
   
    sram_seq = sram_sequence::type_id::create( "sram_seq", this);
	uvm_config_db#(int)::set(this,"sram_ev.sram_agt.monitor", "check_enable", 1);
	uvm_config_db#(int)::set(this,"sram_ev.sram_agt.sram_seqr", "num_seq", 5);
	
	endfunction : build_phase

  task run_phase (uvm_phase phase);

     `uvm_info(get_type_name(), "Running sram_test ...", UVM_MEDIUM)
     phase.raise_objection(this);
	 sram_seq.randomize()
     sram_seq.start( sram_ev.sram_agt.sram_seqr);
     #1ns;
     phase.drop_objection(this);
     `uvm_info(get_type_name(), "sram_test end ", UVM_MEDIUM)

  endtask
     
endclass: test
class sram_sequence extends uvm_sequence# (sram_transaction, sram_transaction); //request and response types
	rand int item_cnt;
	`uvm_object_utils_begin(sram_sequence)
		`uvm_field_int(num_seq, UVM_ALL_ON);
	`uvm_object_utils_end
	`uvm_declare_p_sequencer(sram_sequencer);
	function new(string name ="sram_sequence");
		super.new(name);
	endfunction
	
	virtual task body();
		uvm_config_db #(int)::get(p_sequencer,"","num_seq",num_seq); 
		`uvm_info(get_type_name(),  $sformatf("number of sequences to be generated = %d", num_seq), UVM_MEDIUM );
		repeat(item_cnt)
		`uvm_do(req);
	endtask : body
endclass : sram_sequence
class sram_transaction extends uvm_sequence_item;
	rand bit [9:0] Addr;
	rand bit [31:0] DataIn;
	bit [31:0] DataOut;
	rand bit WbCyc;
	rand bit WbStrb;
	rand bit WbWr;
	constraint addreslimit {Addr < 500; }
	constraint datanotzero {DataIn !='0;	}

	constraint WbCyc_range { WbCyc dist { [0:1]:/ 2 }; }
	constraint WbStrb_range { WbStrb dist { [0:1]:/ 2 }; }
	constraint WbWr_range { WbWr dist {0:=3, 1:=7 }; } //P(0) = 3/10 ; P(1) = 7/10
	`uvm_object_utils_begin(sram_transaction )
		`uvm_field_int(Addr, UVM_ALL_ON) 
		`uvm_field_int(DataIn, UVM_ALL_ON)
		`uvm_field_int(WbCyc, UVM_ALL_ON)
		`uvm_field_int(WbStrb, UVM_ALL_ON)
		`uvm_field_int(WbWr, UVM_ALL_ON)
	`uvm_object_utils_end
	function new (string name ="sram_transaction ");
		super.new(name); //super is referring to the base class constructor function
	endfunction: new

endclass : sram_transaction