Generator Modülü
Gün 6: Bitirme Projesi - Bölüm 1 | Rastgele ve yönlendirilmiş test üretici
Kaynak Kod
// =============================================================================
// GUN 6 - Konu 3: Generator - Rastgele Uyarici Uretici
// =============================================================================
class ALU_Generator;
mailbox #(ALU_Transaction) gen2drv;
int num_transactions;
event done;
function new(mailbox #(ALU_Transaction) mbx, int num = 100);
this.gen2drv = mbx;
this.num_transactions = num;
endfunction
// Base run task must be virtual to be overridden
virtual task run();
ALU_Transaction txn;
$display("[Generator] Random tests starting...");
for (int i = 0; i < num_transactions; i++) begin
txn = new();
assert(txn.randomize()) else $fatal(1, "Randomize Error!");
gen2drv.put(txn);
end
-> done;
endtask
endclass
// Derived generator for corner cases
class ALU_Corner_Generator extends ALU_Generator;
function new(mailbox #(ALU_Transaction) mbx, int num = 100);
super.new(mbx, num);
endfunction
virtual task run();
ALU_Transaction txn;
logic [7:0] corners [] = '{0, 1, 8'h7F, 8'h80, 8'hFE, 8'hFF};
$display("[Corner_Generator] Corner cases starting...");
foreach (corners[i]) begin
foreach (corners[j]) begin
for (int op = 0; op < 8; op++) begin
// Skip invalid shift operations where operand_b is greater than 7
// to prevent constraint solver conflicts with c_shift_range
if ((op == ALU_Transaction::OP_SHL || op == ALU_Transaction::OP_SHR) && corners[j] > 7) begin
continue;
end
txn = new();
assert(txn.randomize() with {
operand_a == corners[i];
operand_b == corners[j];
opcode == ALU_Transaction::opcode_e'(op);
}) else $fatal(1, "Randomize Error!");
gen2drv.put(txn);
end
end
end
-> done;
endtask
endclass