Added a test for the Memory Content File inclusion using $readmemb
authorRodrigo Alejandro Melo <rodrigomelo9@gmail.com>
Sat, 1 Feb 2020 20:41:10 +0000 (17:41 -0300)
committerRodrigo Alejandro Melo <rodrigomelo9@gmail.com>
Sat, 1 Feb 2020 20:41:10 +0000 (17:41 -0300)
Signed-off-by: Rodrigo Alejandro Melo <rodrigomelo9@gmail.com>
tests/memfile/.gitignore [new file with mode: 0644]
tests/memfile/memory.v [new file with mode: 0644]
tests/memfile/run-test.sh [new file with mode: 0755]

diff --git a/tests/memfile/.gitignore b/tests/memfile/.gitignore
new file mode 100644 (file)
index 0000000..61b0d42
--- /dev/null
@@ -0,0 +1 @@
+temp*
diff --git a/tests/memfile/memory.v b/tests/memfile/memory.v
new file mode 100644 (file)
index 0000000..57106ea
--- /dev/null
@@ -0,0 +1,23 @@
+// A memory initialized with an external file
+
+module memory (
+    input             clk_i,
+    input             we_i,
+    input       [5:0] addr_i,
+    input      [31:0] data_i,
+    output reg [31:0] data_o
+);
+
+parameter MEMFILE = "";
+
+reg [31:0] mem [0:63];
+
+initial $readmemb(MEMFILE,mem);
+
+always @(posedge clk_i) begin
+    if (we_i)
+        mem[addr_i] <= data_i;
+    data_o <= mem[addr_i];
+end
+
+endmodule
diff --git a/tests/memfile/run-test.sh b/tests/memfile/run-test.sh
new file mode 100755 (executable)
index 0000000..3a88b81
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+echo "* Creating Memory Content Files"
+
+for i in {1..64}
+do
+       echo "00001111000000001111111100000000" >> tempfile1.dat
+done
+
+mkdir -p temp
+cp tempfile1.dat temp/tempfile2.dat
+
+cd ..
+
+echo "* Running from the parent directory"
+echo "  * Memory Content File: tempfile1.dat"
+../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory"
+echo "  * Memory Content File: temp/tempfile2.dat"
+../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory"
+
+cd memfile
+
+echo "* Running from the same directory"
+echo "  * Memory Content File: tempfile1.dat"
+../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory"
+echo "  * Memory Content File: temp/tempfile2.dat"
+../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory"
+
+cd temp
+
+echo "* Running from a child directory"
+echo "  * Memory Content File: tempfile1.dat"
+../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory"
+echo "  * Memory Content File: temp/tempfile2.dat"
+../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory"
+echo "  * Memory Content File: tempfile2.dat"
+../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory"
+
+echo "* Done"