Replaced isim with xsim in tests/tools/autotest.sh, removed xst support
[yosys.git] / tests / tools / autotest.sh
1 #!/bin/bash
2
3 libs=""
4 genvcd=false
5 use_xsim=false
6 use_modelsim=false
7 verbose=false
8 keeprunning=false
9 backend_opts="-noattr -noexpr"
10 scriptfiles=""
11 scriptopt=""
12 toolsdir="$(cd $(dirname $0); pwd)"
13
14 if [ ! -f $toolsdir/cmp_tbdata -o $toolsdir/cmp_tbdata.c -nt $toolsdir/cmp_tbdata ]; then
15 ( set -ex; gcc -Wall -o $toolsdir/cmp_tbdata $toolsdir/cmp_tbdata.c; ) || exit 1
16 fi
17
18 while getopts xml:wkvrs:p: opt; do
19 case "$opt" in
20 x)
21 use_xsim=true ;;
22 m)
23 use_modelsim=true ;;
24 l)
25 libs="$libs $(cd $(dirname $OPTARG); pwd)/$(basename $OPTARG)";;
26 w)
27 genvcd=true ;;
28 k)
29 keeprunning=true ;;
30 v)
31 verbose=true ;;
32 r)
33 backend_opts="$backend_opts -norename" ;;
34 s)
35 [[ "$OPTARG" == /* ]] || OPTARG="$PWD/$OPTARG"
36 scriptfiles="$scriptfiles $OPTARG" ;;
37 p)
38 scriptopt="$OPTARG" ;;
39 *)
40 echo "Usage: $0 [-x|-m] [-w] [-k] [-v] [-r] [-l libs] [-s script] [-p cmdstring] verilog-files\n" >&2
41 exit 1
42 esac
43 done
44
45 create_ref() {
46 cp "$1" "$2.v"
47 }
48
49 compile_and_run() {
50 exe="$1"; output="$2"; shift 2
51 if $use_modelsim; then
52 altver=$( ls -v /opt/altera/ | grep '^[0-9]' | tail -n1; )
53 /opt/altera/$altver/modelsim_ase/bin/vlib work
54 /opt/altera/$altver/modelsim_ase/bin/vlog "$@"
55 /opt/altera/$altver/modelsim_ase/bin/vsim -c -do 'run -all; exit;' testbench | grep '#OUT#' > "$output"
56 elif $use_xsim; then
57 (
58 set +x
59 files=( "$@" )
60 xilver=$( ls -v /opt/Xilinx/Vivado/ | grep '^[0-9]' | tail -n1; )
61 /opt/Xilinx/Vivado/$xilver/bin/xvlog "${files[@]}"
62 /opt/Xilinx/Vivado/$xilver/bin/xelab -R work.testbench | grep '#OUT#' > "$output"
63 )
64 else
65 iverilog -s testbench -o "$exe" "$@"
66 vvp -n "$exe" > "$output"
67 fi
68 }
69
70 shift $((OPTIND - 1))
71
72 for fn
73 do
74 bn=${fn%.v}
75 if [ "$bn" == "$fn" ]; then
76 echo "Invalid argument: $fn" >&2
77 exit 1
78 fi
79 [[ "$bn" == *_tb ]] && continue
80 echo -n "Test: $bn "
81
82 rm -f ${bn}.{err,log}
83 mkdir -p ${bn}.out
84 rm -rf ${bn}.out/*
85
86 body() {
87 cd ${bn}.out
88 cp ../$fn $fn
89 if [ ! -f ../${bn}_tb.v ]; then
90 "$toolsdir"/../../yosys -b autotest -o ${bn}_tb.v $fn
91 else
92 cp ../${bn}_tb.v ${bn}_tb.v
93 fi
94 if $genvcd; then sed -i 's,// \$dump,$dump,g' ${bn}_tb.v; fi
95 create_ref $fn ${bn}_ref
96 compile_and_run ${bn}_tb_ref ${bn}_out_ref ${bn}_tb.v ${bn}_ref.v $libs
97 if $genvcd; then mv testbench.vcd ${bn}_ref.vcd; fi
98
99 test_count=0
100 test_passes() {
101 "$toolsdir"/../../yosys -b "verilog $backend_opts" "$@" -o ${bn}_syn${test_count}.v $fn $scriptfiles
102 compile_and_run ${bn}_tb_syn${test_count} ${bn}_out_syn${test_count} \
103 ${bn}_tb.v ${bn}_syn${test_count}.v $libs \
104 "$toolsdir"/../../techlibs/common/simlib.v \
105 "$toolsdir"/../../techlibs/common/simcells.v
106 if $genvcd; then mv testbench.vcd ${bn}_syn${test_count}.vcd; fi
107 $toolsdir/cmp_tbdata ${bn}_out_ref ${bn}_out_syn${test_count}
108 test_count=$(( test_count + 1 ))
109 }
110
111 if [ -n "$scriptfiles" ]; then
112 test_passes
113 elif [ -n "$scriptopt" ]; then
114 test_passes -p "$scriptopt"
115 else
116 test_passes -p "hierarchy; proc; opt; memory; opt; fsm; opt"
117 test_passes -p "hierarchy; proc; opt; memory; opt; fsm; opt; techmap; opt; abc -dff; opt"
118 fi
119 touch ../${bn}.log
120 }
121
122 if $verbose; then
123 echo ".."
124 echo "Output written to console." > ${bn}.err
125 ( set -ex; body; )
126 else
127 ( set -ex; body; ) > ${bn}.err 2>&1
128 fi
129
130 if [ -f ${bn}.log ]; then
131 mv ${bn}.err ${bn}.log
132 echo "-> ok"
133 else echo "-> ERROR!"; $keeprunning || exit 1; fi
134 done
135
136 exit 0