aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/torture
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2016-04-08 16:08:23 +0200
committerClifford Wolf <clifford@clifford.at>2016-04-08 16:08:23 +0200
commit33c0aaf5ded02bf947411749eac188bda70e1f67 (patch)
tree9d4d304f6eb5eec8068e095136ca52267db87cea /scripts/torture
parent548abd6cce79c987cb051dd9e73caebafc3bcf40 (diff)
downloadpicorv32-33c0aaf5ded02bf947411749eac188bda70e1f67.tar.gz
picorv32-33c0aaf5ded02bf947411749eac188bda70e1f67.zip
Single test support in scripts/torture/
Diffstat (limited to 'scripts/torture')
-rw-r--r--scripts/torture/Makefile8
-rw-r--r--scripts/torture/run_single_test.sh18
-rw-r--r--scripts/torture/test.sh28
-rw-r--r--scripts/torture/testbench.v83
4 files changed, 115 insertions, 22 deletions
diff --git a/scripts/torture/Makefile b/scripts/torture/Makefile
index c28da05..79cc906 100644
--- a/scripts/torture/Makefile
+++ b/scripts/torture/Makefile
@@ -1,6 +1,6 @@
-run_signle_test: riscv-torture/build.ok riscv-isa-sim/build.ok
- bash run_single_test.sh
+test: riscv-torture/build.ok riscv-isa-sim/build.ok
+ bash test.sh
riscv-torture/build.ok: riscv-torture-rv32.diff
rm -rf riscv-torture
@@ -22,7 +22,7 @@ riscv-isa-sim/build.ok: riscv-fesvr/build.ok
clean:
rm -rf riscv-torture riscv-fesvr riscv-isa-sim
- rm -f test.S test.elf test.ref
+ rm -f test.S test.elf test.bin test.hex test.ref test.vvp
-.PHONY: run_signle_test clean
+.PHONY: test clean
diff --git a/scripts/torture/run_single_test.sh b/scripts/torture/run_single_test.sh
deleted file mode 100644
index 81f48ae..0000000
--- a/scripts/torture/run_single_test.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-set -ex
-
-
-## Generate test case
-
-cd riscv-torture
-./sbt generator/run
-cp output/test.S ../test.S
-cd ..
-
-
-## Compile test case and create reference
-
-riscv32-unknown-elf-gcc -m32 -ffreestanding -nostdlib -Wl,-Bstatic,-T,sections.lds -o test.elf test.S
-LD_LIBRARY_PATH="./riscv-isa-sim:./riscv-fesvr" ./riscv-isa-sim/spike test.elf > test.ref
-
diff --git a/scripts/torture/test.sh b/scripts/torture/test.sh
new file mode 100644
index 0000000..3b3e5c2
--- /dev/null
+++ b/scripts/torture/test.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+set -ex
+
+
+## Generate test case
+
+if ! test -f test.S; then
+ cd riscv-torture
+ ./sbt generator/run
+ cp output/test.S ../test.S
+ cd ..
+fi
+
+
+## Compile test case and create reference
+
+riscv32-unknown-elf-gcc -m32 -ffreestanding -nostdlib -Wl,-Bstatic,-T,sections.lds -o test.elf test.S
+LD_LIBRARY_PATH="./riscv-isa-sim:./riscv-fesvr" ./riscv-isa-sim/spike test.elf > test.ref
+riscv32-unknown-elf-objcopy -O binary test.elf test.bin
+python3 ../../firmware/makehex.py test.bin 4096 > test.hex
+
+
+## Run test
+
+iverilog -o test.vvp testbench.v ../../picorv32.v
+vvp test.vvp +hex=test.hex +ref=test.ref
+
diff --git a/scripts/torture/testbench.v b/scripts/torture/testbench.v
new file mode 100644
index 0000000..abc3027
--- /dev/null
+++ b/scripts/torture/testbench.v
@@ -0,0 +1,83 @@
+module testbench (
+`ifdef VERILATOR
+ input clk
+`endif
+);
+`ifndef VERILATOR
+ reg clk = 1;
+ always #5 clk = ~clk;
+`endif
+ reg resetn = 0;
+ wire trap;
+
+ wire mem_valid;
+ wire mem_instr;
+ reg mem_ready;
+ wire [31:0] mem_addr;
+ wire [31:0] mem_wdata;
+ wire [3:0] mem_wstrb;
+ reg [31:0] mem_rdata;
+
+ picorv32 #(
+ ) uut (
+ .clk (clk ),
+ .resetn (resetn ),
+ .trap (trap ),
+ .mem_valid (mem_valid ),
+ .mem_instr (mem_instr ),
+ .mem_ready (mem_ready ),
+ .mem_addr (mem_addr ),
+ .mem_wdata (mem_wdata ),
+ .mem_wstrb (mem_wstrb ),
+ .mem_rdata (mem_rdata )
+ );
+
+ reg [1023:0] hex_filename;
+ reg [1023:0] ref_filename;
+
+ reg [31:0] memory [0:4095];
+ reg [31:0] memory_ref [0:4095];
+ integer i, errcount;
+
+ initial begin
+ if ($value$plusargs("hex=%s", hex_filename)) $readmemh(hex_filename, memory);
+ if ($value$plusargs("ref=%s", ref_filename)) $readmemh(ref_filename, memory_ref);
+ // $dumpfile("testbench.vcd");
+ // $dumpvars(0, testbench);
+
+ repeat (10) @(posedge clk);
+ resetn <= 1;
+ end
+
+ always @(posedge clk) begin
+ mem_ready <= 0;
+ mem_rdata <= 'bx;
+
+ if (!trap || !resetn) begin
+ if (mem_valid && !mem_ready && resetn) begin
+ mem_ready <= 1;
+ if (mem_wstrb) begin
+ if (mem_wstrb[0]) memory[mem_addr >> 2][ 7: 0] <= mem_wdata[ 7: 0];
+ if (mem_wstrb[1]) memory[mem_addr >> 2][15: 8] <= mem_wdata[15: 8];
+ if (mem_wstrb[2]) memory[mem_addr >> 2][23:16] <= mem_wdata[23:16];
+ if (mem_wstrb[3]) memory[mem_addr >> 2][31:24] <= mem_wdata[31:24];
+ end else begin
+ mem_rdata <= memory[mem_addr >> 2];
+ end
+ end
+ end else begin
+ errcount = 0;
+ for (i=0; i < 4096; i=i+1) begin
+ if (memory[i] !== memory_ref[i]) begin
+ $display("Signature check failed at %04x: mem=%08x ref=%08x", i << 2, memory[i], memory_ref[i]);
+ errcount = errcount + 1;
+ end
+ end
+ if (errcount)
+ $display("FAILED: Got %1d errors for %1s/%1s!", errcount, hex_filename, ref_filename);
+ else
+ $display("PASSED %1s/%1s.", hex_filename, ref_filename);
+ $finish;
+ end
+ end
+endmodule