add intial test cases
This commit is contained in:
+222
-22
@@ -16,7 +16,12 @@ module cpu_tb_top;
|
|||||||
always #5 clk = ~clk;
|
always #5 clk = ~clk;
|
||||||
|
|
||||||
// IF instantiation
|
// IF instantiation
|
||||||
cpu_if #(.DataSize(DataSize), .AddrSize(AddrSize)) cpu_if(.clk(clk));
|
cpu_if #(
|
||||||
|
.DataSize(DataSize),
|
||||||
|
.AddrSize(AddrSize)
|
||||||
|
) cpu_if (
|
||||||
|
.clk(clk)
|
||||||
|
);
|
||||||
|
|
||||||
// DUT instantiation
|
// DUT instantiation
|
||||||
chip_top dut (
|
chip_top dut (
|
||||||
@@ -50,7 +55,7 @@ module cpu_tb_top;
|
|||||||
function void assertion_fail(input string message);
|
function void assertion_fail(input string message);
|
||||||
assertion_errors++;
|
assertion_errors++;
|
||||||
$error($stime, " ASSERT: %s\n", message);
|
$error($stime, " ASSERT: %s\n", message);
|
||||||
endfunction: assertion_fail
|
endfunction : assertion_fail
|
||||||
|
|
||||||
// Initialize both memories through the DUT's external memory port
|
// Initialize both memories through the DUT's external memory port
|
||||||
task automatic init_memories();
|
task automatic init_memories();
|
||||||
@@ -68,10 +73,10 @@ module cpu_tb_top;
|
|||||||
mon.log_transactions = 1'b1;
|
mon.log_transactions = 1'b1;
|
||||||
sb.log_transactions = 1'b1;
|
sb.log_transactions = 1'b1;
|
||||||
$display($stime, " TB: Memory initialization complete\n");
|
$display($stime, " TB: Memory initialization complete\n");
|
||||||
endtask: init_memories
|
endtask : init_memories
|
||||||
|
|
||||||
// Queue external reads on a memory window
|
// Queue external reads on a memory window
|
||||||
task automatic readback(input int window, input int num_words, input int start_word=0);
|
task automatic readback(input int window, input int num_words, input int start_word = 0);
|
||||||
logic [AddrSize-1:0] base;
|
logic [AddrSize-1:0] base;
|
||||||
|
|
||||||
case (window)
|
case (window)
|
||||||
@@ -86,19 +91,19 @@ module cpu_tb_top;
|
|||||||
end
|
end
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (4) @(cpu_if.cb);
|
repeat (4) @(cpu_if.cb);
|
||||||
endtask: readback
|
endtask : readback
|
||||||
|
|
||||||
task automatic preload_dmem(input logic [31:0] values [$], input int start_word=0);
|
task automatic preload_dmem(input logic [31:0] values[$], input int start_word = 0);
|
||||||
foreach (values[i]) begin
|
foreach (values[i]) begin
|
||||||
seqr.send_write_trans(word_addr(DSRAM_BASE, start_word + i), values[i]);
|
seqr.send_write_trans(word_addr(DSRAM_BASE, start_word + i), values[i]);
|
||||||
end
|
end
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (2) @(cpu_if.cb);
|
repeat (2) @(cpu_if.cb);
|
||||||
endtask: preload_dmem
|
endtask : preload_dmem
|
||||||
|
|
||||||
// Run a directed test
|
// Run a directed test
|
||||||
task automatic run_directed(input string name, const ref logic [31:0] program_words [$],
|
task automatic run_directed(input string name, const ref logic [31:0] program_words[$],
|
||||||
input int max_cycles=2000, input int dmem_words=16);
|
input int max_cycles = 2000, input int dmem_words = 16);
|
||||||
$display("");
|
$display("");
|
||||||
$display("=================================================================");
|
$display("=================================================================");
|
||||||
$display(" TEST: %s", name);
|
$display(" TEST: %s", name);
|
||||||
@@ -118,19 +123,19 @@ module cpu_tb_top;
|
|||||||
$display($stime, " TB: Skipping %s readback after CPU timeout\n", name);
|
$display($stime, " TB: Skipping %s readback after CPU timeout\n", name);
|
||||||
drv.reset_task();
|
drv.reset_task();
|
||||||
end
|
end
|
||||||
endtask: run_directed
|
endtask : run_directed
|
||||||
|
|
||||||
// Basic smoke test for loading, running, and observing a program that halts
|
// Basic smoke test for loading, running, and observing a program that halts
|
||||||
task automatic run_smoke_test();
|
task automatic run_smoke_test();
|
||||||
logic [31:0] smoke_prog [$];
|
logic [31:0] smoke_prog[$];
|
||||||
smoke_prog = '{ EBREAK_WORD };
|
smoke_prog = '{EBREAK_WORD};
|
||||||
run_directed("smoke_ebreak", smoke_prog, 100, 1);
|
run_directed("smoke_ebreak", smoke_prog, 100, 1);
|
||||||
endtask: run_smoke_test
|
endtask : run_smoke_test
|
||||||
|
|
||||||
// Smoke test for stopping the CPU from outside the program
|
// Smoke test for stopping the CPU from outside the program
|
||||||
// Readback is skipped because the CPU stops before the program completes
|
// Readback is skipped because the CPU stops before the program completes
|
||||||
task automatic run_external_halt_smoke();
|
task automatic run_external_halt_smoke();
|
||||||
logic [31:0] long_prog [$];
|
logic [31:0] long_prog[$];
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++) begin
|
for (int i = 0; i < 32; i++) begin
|
||||||
long_prog.push_back(asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)));
|
long_prog.push_back(asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)));
|
||||||
@@ -151,13 +156,13 @@ module cpu_tb_top;
|
|||||||
repeat (12) @(cpu_if.cb);
|
repeat (12) @(cpu_if.cb);
|
||||||
drv.halt_cpu_now();
|
drv.halt_cpu_now();
|
||||||
drv.reset_task();
|
drv.reset_task();
|
||||||
endtask: run_external_halt_smoke
|
endtask : run_external_halt_smoke
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TEST PROGRAM
|
// TEST PROGRAM
|
||||||
logic [31:0] prog [$];
|
logic [31:0] prog[$];
|
||||||
logic [31:0] data [$];
|
logic [31:0] data[$];
|
||||||
|
|
||||||
int NUM_RANDOM_PROGRAMS = 20;
|
int NUM_RANDOM_PROGRAMS = 20;
|
||||||
int NUM_RANDOM_XBAR = 300;
|
int NUM_RANDOM_XBAR = 300;
|
||||||
@@ -204,7 +209,194 @@ module cpu_tb_top;
|
|||||||
};
|
};
|
||||||
run_directed("addi_positive", prog);
|
run_directed("addi_positive", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("add_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("addi_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(-1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("addi_negative", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm('h123)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("add_typical", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)), EBREAK_WORD};
|
||||||
|
run_directed("addi_typical", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)), EBREAK_WORD};
|
||||||
|
run_directed("addi_negative_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(1), .rs1(0), .rs2(1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sub_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm('h23)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(2), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sub_typical", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(32)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_oob", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(32)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_oob", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_zero", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_zero", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_one", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_one", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(4)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_typical", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(4)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_typical", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(0)), EBREAK_WORD};
|
||||||
|
run_directed("lw_zero_offset", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_zero_offset", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(4)), EBREAK_WORD};
|
||||||
|
run_directed("lw_positive", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_positive", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(64)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(1), .imm(-4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_negative", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(64)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(2), .imm(-4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_negative", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_LW), .rd(0), .rs1(0), .imm(0)), EBREAK_WORD};
|
||||||
|
run_directed("lw_x0", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_x0", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(1), .imm(8)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_not_taken", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(1), .rs2(2), .imm(8)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(3), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(3), .rs1(0), .imm(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_typical", prog);
|
||||||
|
|
||||||
|
prog = '{EBREAK_WORD, asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1))};
|
||||||
|
run_directed("ebreak_immediately", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(3)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(1), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(0), .imm(-8)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_backward_loop", prog);
|
||||||
|
|
||||||
// CONSTRAINED-RANDOM TESTS
|
// CONSTRAINED-RANDOM TESTS
|
||||||
// TODO: Add constrained-randomized testing for cpu_seq_item and cpu_xbar_item
|
// TODO: Add constrained-randomized testing for cpu_seq_item and cpu_xbar_item
|
||||||
@@ -262,13 +454,21 @@ module cpu_tb_top;
|
|||||||
end
|
end
|
||||||
|
|
||||||
wire rst = cpu_if.reset;
|
wire rst = cpu_if.reset;
|
||||||
// TODO: Add the required protocol or control assertions from the testplan
|
|
||||||
|
|
||||||
// Example assertion
|
// Example assertion
|
||||||
// It checks one interface rule and sends failures through the testbench counter
|
// It checks one interface rule and sends failures through the testbench counter
|
||||||
NO_SIMULTANEOUS_READ_WRITE:
|
NO_SIMULTANEOUS_READ_WRITE :
|
||||||
assert property (@(posedge clk) disable iff (rst)
|
assert property (@(posedge clk) disable iff (rst) !(cpu_if.w_en && cpu_if.r_en))
|
||||||
!(cpu_if.w_en && cpu_if.r_en))
|
|
||||||
else assertion_fail("w_en_i and r_en_i were asserted together");
|
else assertion_fail("w_en_i and r_en_i were asserted together");
|
||||||
|
|
||||||
endmodule: cpu_tb_top
|
X0_REMAINS_0 :
|
||||||
|
assert property (@(posedge clk) disable iff (rst) dut.register_crossbar[0] == 32'b0)
|
||||||
|
else assertion_fail("x0 is nonzero");
|
||||||
|
|
||||||
|
STABLE_WHEN_DISABLED :
|
||||||
|
assert property (@(posedge clk) disable iff (rst)
|
||||||
|
(!cpu_if.en_cpu || !cpu_if.cpu_active) |=> ($stable(
|
||||||
|
dut.register_crossbar
|
||||||
|
)))
|
||||||
|
else assertion_fail("register file/pc changed while cpu inactive");
|
||||||
|
endmodule : cpu_tb_top
|
||||||
|
|||||||
Reference in New Issue
Block a user