mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-21 13:16:41 +00:00
tests/memfile: Test dump_meminit
Change tests/memfile to a mktest, moving the prior run-test.sh contents into a new read_dir.sh. Add dump.ys (and friends) for testing dump_meminit.
This commit is contained in:
parent
7d79c11ca9
commit
3787ea19cd
7 changed files with 152 additions and 49 deletions
2
Makefile
2
Makefile
|
|
@ -914,6 +914,7 @@ MK_TEST_DIRS += tests/verific
|
|||
endif
|
||||
endif
|
||||
MK_TEST_DIRS += tests/verilog
|
||||
MK_TEST_DIRS += tests/memfile
|
||||
|
||||
# Tests that don't generate .mk
|
||||
SH_TEST_DIRS =
|
||||
|
|
@ -935,7 +936,6 @@ SH_TEST_DIRS += tests/proc
|
|||
SH_TEST_DIRS += tests/blif
|
||||
SH_TEST_DIRS += tests/arch
|
||||
SH_TEST_DIRS += tests/rpc
|
||||
SH_TEST_DIRS += tests/memfile
|
||||
SH_TEST_DIRS += tests/fmt
|
||||
SH_TEST_DIRS += tests/cxxrtl
|
||||
SH_TEST_DIRS += tests/liberty
|
||||
|
|
|
|||
1
tests/memfile/.gitignore
vendored
1
tests/memfile/.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
temp*
|
||||
*.mem
|
||||
|
|
|
|||
62
tests/memfile/dump.ys
Normal file
62
tests/memfile/dump.ys
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# create sub dir
|
||||
!mkdir -p temp
|
||||
# remove output files
|
||||
!rm -f gold.m.mem
|
||||
!rm -f temp/gold.m.mem
|
||||
|
||||
# load test design
|
||||
read_rtlil dump_gold.il
|
||||
design -save gold
|
||||
|
||||
# dump_meminit sets INIT_FILE and unsets INIT
|
||||
select -assert-any t:$__MEMORY r:INIT %i
|
||||
select -assert-none t:$__MEMORY r:INIT_FILE %i
|
||||
dump_meminit
|
||||
select -assert-none t:$__MEMORY r:INIT %i
|
||||
select -assert-any t:$__MEMORY r:INIT_FILE %i
|
||||
# memory written to file
|
||||
!test -f gold.m.mem
|
||||
# file name in INIT_FILE
|
||||
select -assert-any t:$__MEMORY r:INIT_FILE=gold.m.mem %i
|
||||
|
||||
design -load gold
|
||||
dump_meminit -prefix temp/
|
||||
# memory written to sub directory
|
||||
!test -f temp/gold.m.mem
|
||||
# sub directory in INIT_FILE
|
||||
select -assert-any t:$__MEMORY r:INIT_FILE=temp/gold.m.mem %i
|
||||
|
||||
# dump_gate.v calls $readmemh with memory output from dump_gold.il
|
||||
design -reset
|
||||
read_verilog dump_gate.v
|
||||
proc
|
||||
design -save gate_proc
|
||||
|
||||
# infer memory for gate
|
||||
memory -nomap
|
||||
select -assert-any t:$mem_v2
|
||||
design -save gate_memory
|
||||
|
||||
# memory read from output of dump_meminit has the same value as the RTLIL
|
||||
select -assert-any t:$mem_v2 r:INIT=32'hdeadbeef %i
|
||||
|
||||
design -load gold
|
||||
select -assert-any t:$__MEMORY r:INIT=32'hdeadbeef %i
|
||||
|
||||
# dump_meminit does nothing if there are no cells with INIT
|
||||
design -load gate_proc
|
||||
select -assert-none r:INIT
|
||||
dump_meminit
|
||||
select -assert-none r:INIT_FILE
|
||||
|
||||
# change cell type since INIT_FILE param is invalid on $mem_v2
|
||||
design -load gate_memory
|
||||
chtype -set $__MEMORY gate/m
|
||||
|
||||
# dump_meminit on parsed memory
|
||||
select -assert-none r:INIT_FILE
|
||||
dump_meminit
|
||||
select -assert-any r:INIT_FILE=gate.m.mem
|
||||
|
||||
# gold and gate dumps are identical
|
||||
!diff -s gate.m.mem gold.m.mem
|
||||
19
tests/memfile/dump_gate.v
Normal file
19
tests/memfile/dump_gate.v
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
module gate (
|
||||
input clk, wen,
|
||||
input [2:0] addr,
|
||||
input [3:0] wdata,
|
||||
output [3:0] rdata
|
||||
);
|
||||
|
||||
reg [3:0] m [7:0];
|
||||
initial
|
||||
$readmemh("gold.m.mem", m);
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (wen)
|
||||
m[addr] <= wdata;
|
||||
else
|
||||
rdata <= m[addr];
|
||||
end
|
||||
|
||||
endmodule
|
||||
17
tests/memfile/dump_gold.il
Normal file
17
tests/memfile/dump_gold.il
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module \gold
|
||||
wire input 1 \clk
|
||||
wire input 1 \wen
|
||||
wire input 3 \addr
|
||||
wire input 4 \wdata
|
||||
wire input 4 \rdata
|
||||
cell $__MEMORY \m
|
||||
parameter \WIDTH 4
|
||||
parameter \ABITS 3
|
||||
parameter \INIT 32'11011110101011011011111011101111
|
||||
connect \PORT_A_CLK \clk
|
||||
connect \PORT_A_ADDR \addr
|
||||
connect \PORT_A_WR_DATA \wdata
|
||||
connect \PORT_A_WR_EN \wen
|
||||
connect \PORT_A_RD_DATA \rdata
|
||||
end
|
||||
end
|
||||
49
tests/memfile/read_dir.sh
Executable file
49
tests/memfile/read_dir.sh
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p temp
|
||||
cp content1.dat temp/content2.dat
|
||||
|
||||
cd ..
|
||||
|
||||
echo "Running from the parent directory with content1.dat"
|
||||
../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"content1.dat\" memory"
|
||||
echo "Running from the parent directory with temp/content2.dat"
|
||||
../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
echo "Running from the parent directory with memfile/temp/content2.dat"
|
||||
../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"memfile/temp/content2.dat\" memory"
|
||||
|
||||
cd memfile
|
||||
|
||||
echo "Running from the same directory with content1.dat"
|
||||
../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content1.dat\" memory"
|
||||
echo "Running from the same directory with temp/content2.dat"
|
||||
../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
|
||||
cd temp
|
||||
|
||||
echo "Running from a child directory with content1.dat"
|
||||
../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"content1.dat\" memory"
|
||||
echo "Running from a child directory with temp/content2.dat"
|
||||
../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
echo "Running from a child directory with content2.dat"
|
||||
../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
|
||||
cd ..
|
||||
|
||||
echo "Checking a failure when zero length filename is provided"
|
||||
if ../../yosys -qp "read_verilog memory.v"; then
|
||||
echo "The execution should fail but it didn't happen, which is WRONG."
|
||||
exit 1
|
||||
else
|
||||
echo "Execution failed, which is OK."
|
||||
fi
|
||||
|
||||
echo "Checking a failure when not existing filename is provided"
|
||||
if ../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content3.dat\" memory"; then
|
||||
echo "The execution should fail but it didn't happen, which is WRONG."
|
||||
exit 1
|
||||
else
|
||||
echo "Execution failed, which is OK."
|
||||
fi
|
||||
|
|
@ -1,49 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p temp
|
||||
cp content1.dat temp/content2.dat
|
||||
|
||||
cd ..
|
||||
|
||||
echo "Running from the parent directory with content1.dat"
|
||||
../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"content1.dat\" memory"
|
||||
echo "Running from the parent directory with temp/content2.dat"
|
||||
../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
echo "Running from the parent directory with memfile/temp/content2.dat"
|
||||
../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"memfile/temp/content2.dat\" memory"
|
||||
|
||||
cd memfile
|
||||
|
||||
echo "Running from the same directory with content1.dat"
|
||||
../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content1.dat\" memory"
|
||||
echo "Running from the same directory with temp/content2.dat"
|
||||
../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
|
||||
cd temp
|
||||
|
||||
echo "Running from a child directory with content1.dat"
|
||||
../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"content1.dat\" memory"
|
||||
echo "Running from a child directory with temp/content2.dat"
|
||||
../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
echo "Running from a child directory with content2.dat"
|
||||
../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
|
||||
|
||||
cd ..
|
||||
|
||||
echo "Checking a failure when zero length filename is provided"
|
||||
if ../../yosys -qp "read_verilog memory.v"; then
|
||||
echo "The execution should fail but it didn't happen, which is WRONG."
|
||||
exit 1
|
||||
else
|
||||
echo "Execution failed, which is OK."
|
||||
fi
|
||||
|
||||
echo "Checking a failure when not existing filename is provided"
|
||||
if ../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content3.dat\" memory"; then
|
||||
echo "The execution should fail but it didn't happen, which is WRONG."
|
||||
exit 1
|
||||
else
|
||||
echo "Execution failed, which is OK."
|
||||
fi
|
||||
set -eu
|
||||
source ../gen-tests-makefile.sh
|
||||
generate_mk --bash --yosys-scripts
|
||||
Loading…
Add table
Add a link
Reference in a new issue