update constrained random testing + final directed tests
This commit is contained in:
+163
-12
@@ -158,15 +158,163 @@ module cpu_tb_top;
|
||||
drv.reset_task();
|
||||
endtask : run_external_halt_smoke
|
||||
|
||||
// 1.29: rst_i asserted mid-program must clear the register file even
|
||||
// though the program never reaches ebreak
|
||||
task automatic run_reset_while_running();
|
||||
logic [31:0] reset_prog[$];
|
||||
|
||||
reset_prog = '{
|
||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
||||
EBREAK_WORD
|
||||
};
|
||||
|
||||
$display("");
|
||||
$display("=================================================================");
|
||||
$display(" TEST: reset_while_running");
|
||||
$display("=================================================================");
|
||||
sb.set_test("reset_while_running");
|
||||
|
||||
drv.reset_task();
|
||||
seqr.load_program(reset_prog);
|
||||
seqr.wait_for_empty();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
drv.start_cpu();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
cpu_if.cb.reset <= 1;
|
||||
repeat (4) @(cpu_if.cb);
|
||||
cpu_if.cb.reset <= 0;
|
||||
repeat (2) @(cpu_if.cb);
|
||||
readback(2, 1, 1);
|
||||
endtask : run_reset_while_running
|
||||
|
||||
// 1.30: halt_cpu_i pulsed mid-program must stop the CPU short of
|
||||
// completion. x1's partial count and cpu_active can't go through the
|
||||
// scoreboard's exact-match checker (the ref model only predicts a
|
||||
// completed run), so this test reads the external port directly and
|
||||
// checks the result itself.
|
||||
task automatic run_external_halt();
|
||||
logic [31:0] halt_prog[$];
|
||||
logic [31:0] x1_value;
|
||||
|
||||
for (int i = 0; i < 32; i++) begin
|
||||
halt_prog.push_back(asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)));
|
||||
end
|
||||
halt_prog.push_back(EBREAK_WORD);
|
||||
|
||||
$display("");
|
||||
$display("=================================================================");
|
||||
$display(" TEST: external_halt");
|
||||
$display("=================================================================");
|
||||
sb.set_test("external_halt");
|
||||
|
||||
drv.reset_task();
|
||||
seqr.load_program(halt_prog);
|
||||
seqr.wait_for_empty();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
drv.start_cpu();
|
||||
repeat (12) @(cpu_if.cb);
|
||||
drv.halt_cpu_now();
|
||||
|
||||
if (cpu_if.cpu_active) begin
|
||||
assertion_fail("external_halt: cpu_active did not deassert after halt_cpu_now()");
|
||||
end
|
||||
|
||||
drv.xbar_read(word_addr(REG_BASE, 1));
|
||||
x1_value = cpu_if.cb.rdata;
|
||||
$display($stime, " TB: external_halt observed x1 = 0x%08x\n", x1_value);
|
||||
if (x1_value >= 32) begin
|
||||
assertion_fail($sformatf("external_halt: x1 = 0x%08x did not stop short of 32", x1_value));
|
||||
end
|
||||
|
||||
drv.reset_task();
|
||||
endtask : run_external_halt
|
||||
|
||||
// 1.31: external access to the first and last ISRAM words
|
||||
task automatic run_isram_boundary_words();
|
||||
$display("");
|
||||
$display("=================================================================");
|
||||
$display(" TEST: isram_boundary_words");
|
||||
$display("=================================================================");
|
||||
sb.set_test("isram_boundary_words");
|
||||
|
||||
drv.reset_task();
|
||||
seqr.send_write_trans(word_addr(ISRAM_BASE, 0), asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(5)
|
||||
));
|
||||
seqr.send_write_trans(word_addr(ISRAM_BASE, 1023), EBREAK_WORD);
|
||||
seqr.wait_for_empty();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
readback(0, 1, 0);
|
||||
readback(0, 1, 1023);
|
||||
endtask : run_isram_boundary_words
|
||||
|
||||
// 1.32: external access to the first and last DSRAM words
|
||||
task automatic run_dsram_boundary_words();
|
||||
$display("");
|
||||
$display("=================================================================");
|
||||
$display(" TEST: dsram_boundary_words");
|
||||
$display("=================================================================");
|
||||
sb.set_test("dsram_boundary_words");
|
||||
|
||||
drv.reset_task();
|
||||
seqr.send_write_trans(word_addr(DSRAM_BASE, 0), 32'hA5A5A5A5);
|
||||
seqr.send_write_trans(word_addr(DSRAM_BASE, 1023), 32'h5A5A5A5A);
|
||||
seqr.wait_for_empty();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
readback(1, 1, 0);
|
||||
readback(1, 1, 1023);
|
||||
endtask : run_dsram_boundary_words
|
||||
|
||||
int NUM_RANDOM_PROGRAMS = 50;
|
||||
int NUM_RANDOM_XBAR = 300;
|
||||
|
||||
// For every random CPU program:
|
||||
// 1. print an iteration label so the seed and failure are reproducible,
|
||||
// 2. reset the CPU and call init_memories() before gen_program(),
|
||||
// 3. wait for program writes, run with the supplied bounded helper,
|
||||
// 4. queue the register and relevant memory reads needed by the scoreboard.
|
||||
// Keep randomized external-port traffic in a phase where the CPU is stopped.
|
||||
// The README explains why memory must be reinitialized every iteration.
|
||||
task automatic run_constrained_random_tests();
|
||||
int min_len = 2;
|
||||
int max_len = 50;
|
||||
int max_cycles = 2000;
|
||||
int dmem_words = 16;
|
||||
|
||||
drv.reset_task();
|
||||
init_memories();
|
||||
seqr.gen_xbar(NUM_RANDOM_XBAR);
|
||||
seqr.wait_for_empty();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
|
||||
for (int i = 0; i < NUM_RANDOM_PROGRAMS; i++) begin
|
||||
int len = $urandom_range(min_len, max_len);
|
||||
string name = $sformatf("random_gen_%0d_len_%0d", i, len);
|
||||
sb.set_test(name);
|
||||
|
||||
drv.reset_task();
|
||||
init_memories();
|
||||
seqr.gen_program(len);
|
||||
seqr.wait_for_empty();
|
||||
repeat (2) @(cpu_if.cb);
|
||||
drv.run_program(max_cycles);
|
||||
|
||||
if (drv.last_run_completed) begin
|
||||
readback(2, REG_COUNT);
|
||||
readback(1, dmem_words);
|
||||
end else begin
|
||||
$display($stime, " TB: Skipping %s readback after CPU timeout\n", name);
|
||||
drv.reset_task();
|
||||
end
|
||||
end
|
||||
endtask : run_constrained_random_tests
|
||||
|
||||
// TEST PROGRAM
|
||||
logic [31:0] prog[$];
|
||||
logic [31:0] data[$];
|
||||
|
||||
int NUM_RANDOM_PROGRAMS = 20;
|
||||
int NUM_RANDOM_XBAR = 300;
|
||||
|
||||
initial begin
|
||||
int total_errors;
|
||||
|
||||
@@ -398,16 +546,19 @@ module cpu_tb_top;
|
||||
};
|
||||
run_directed("beq_backward_loop", prog);
|
||||
|
||||
// CONSTRAINED-RANDOM TESTS
|
||||
// TODO: Add constrained-randomized testing for cpu_seq_item and cpu_xbar_item
|
||||
// For every random CPU program:
|
||||
// 1. print an iteration label so the seed and failure are reproducible,
|
||||
// 2. reset the CPU and call init_memories() before gen_program(),
|
||||
// 3. wait for program writes, run with the supplied bounded helper,
|
||||
// 4. queue the register and relevant memory reads needed by the scoreboard.
|
||||
// Keep randomized external-port traffic in a phase where the CPU is stopped.
|
||||
// The README explains why memory must be reinitialized every iteration.
|
||||
// 1.33: bulk register readback inside run_directed already reads x0
|
||||
// and x31 (index 0 and REG_COUNT-1), so no dedicated task is needed.
|
||||
prog = '{asm_instr(.op(OP_ADDI), .rd(31), .rs1(0), .imm(-1)), EBREAK_WORD};
|
||||
run_directed("external_register_boundary_reads", prog);
|
||||
|
||||
// CHIP-LEVEL DIRECTED TESTS
|
||||
run_reset_while_running();
|
||||
run_external_halt();
|
||||
run_isram_boundary_words();
|
||||
run_dsram_boundary_words();
|
||||
|
||||
// CONSTRAINED-RANDOM TESTS
|
||||
run_constrained_random_tests();
|
||||
|
||||
// TEST FINISH
|
||||
repeat (20) @(cpu_if.cb);
|
||||
|
||||
Reference in New Issue
Block a user