RVSCC/test/test_cache_memory.sv

65 lines
1.3 KiB
Systemverilog
Raw Normal View History

2023-02-28 17:22:02 +00:00
`include "timescale.sv"
2023-02-26 23:26:11 +00:00
module test_cache_memory ();
2023-02-28 17:22:02 +00:00
logic clk;
logic rst;
2023-02-26 23:26:11 +00:00
2023-03-02 19:56:34 +00:00
logic [dut.WaySize-1:0] write_way;
2023-02-28 17:22:02 +00:00
logic [dut.SetSize-1:0] set;
logic [dut.TagSize-1:0] tag;
logic write_enable;
logic [31:0] write_data;
logic [31:0] read_data;
2023-03-02 19:56:34 +00:00
logic read_valid;
logic [dut.WaySize-1:0] populate_way;
2023-02-28 17:22:02 +00:00
cache_memory #(
.ADDR_SIZE (32),
.NUM_SETS (4),
.NUM_WAYS (2),
.BLOCK_SIZE(32)
) dut (
2023-02-26 23:26:11 +00:00
.clk(clk),
.rst(rst),
2023-03-02 19:56:34 +00:00
.write_way(write_way),
2023-02-28 17:22:02 +00:00
.set(set),
.tag(tag),
.write_enable(write_enable),
.write_data(write_data),
.read_data(read_data),
2023-03-02 19:56:34 +00:00
.read_valid(read_valid),
.populate_way(populate_way)
2023-02-26 23:26:11 +00:00
);
2023-02-28 17:22:02 +00:00
localparam int ClockCycle = 2;
2023-03-02 19:56:34 +00:00
always #(ClockCycle/2) clk = !clk;
2023-02-28 17:22:02 +00:00
logic [31:0] write_value;
2023-02-26 23:26:11 +00:00
initial begin
clk = 0;
rst = 1;
2023-02-28 17:22:02 +00:00
#ClockCycle;
rst = 0;
2023-03-02 19:56:34 +00:00
write_way = 0;
2023-02-28 17:22:02 +00:00
set = 0;
tag = 27'($urandom);
2023-02-26 23:26:11 +00:00
write_enable = 1;
2023-02-28 17:22:02 +00:00
write_value = $urandom;
write_data = write_value;
#ClockCycle;
write_enable = 0;
tag += 1;
#1;
2023-03-02 19:56:34 +00:00
assert (read_valid == 0)
else $error("Valid flags does not match");
#ClockCycle;
2023-02-28 17:22:02 +00:00
tag -= 1;
2023-03-02 19:56:34 +00:00
#1;
assert (read_valid == 1)
2023-02-28 17:22:02 +00:00
else $error("Valid flags does not match");
$finish;
2023-02-26 23:26:11 +00:00
end
endmodule