1 # Testsuite environment
3 # This file defines the shell functions to analyse a file, elaborate or run
4 # a design. There are version for expected success and expected failure.
6 # Every test should source and use this file.
8 # Note: the executable must be set in the GHDL environment variable
10 # User defined variables (can be set to run the testsuite in some
11 # configuration, such as optimization or debugging):
14 # Testbench flags. Can be used to run the whole testsuite under a specific
15 # flag (like -O, -g). Should not be set in testsuite.sh files.
22 # Exit in case of failure in shell scripts.
26 ANSI_NOCOLOR
="\033[0m"
30 # Optionally disable colors
31 if [ -z "$ENABLECOLOR" ]; then unset ANSI_NOCOLOR ANSI_RED ANSI_BLUE ANSI_GREEN
; fi
33 if [ x
"$GHDL" = x
]; then
34 echo "error: GHDL environment variable is not defined"
38 PYTHON
=${PYTHON:-python3}
40 # Analyze files (no error expected)
44 "$GHDL" -a $GHDL_STD_FLAGS $GHDL_FLAGS "$@"
63 verilog_run
$t.v tb_
$t.v $
*
65 synth
--out=verilog
$t.v $
* -e > syn_
$t.v
66 echo "run tb for synthesized $1"
67 verilog_run syn_
$t.v tb_
$t.v $
*
70 # Analyze files (failure expected)
73 echo "try to analyze $@"
74 # for arg in $@; do echo "arg: $arg"; done
75 if ! "$GHDL" -a --expect-failure $GHDL_STD_FLAGS $GHDL_FLAGS "$@" ; then
76 echo "Failure expected"
81 # Elaborate a design (no error expected)
82 # Note: somewhat deprecated, use elab_simulate instead;
83 # unless ghdl_has_feature needs to be used between elab and simulate
87 "$GHDL" -e $GHDL_STD_FLAGS $GHDL_FLAGS $@
90 # Elaborate a design (failure expected)
91 # Note: somewhat deprecated, use elab_simulate_failure instead;
92 # unless ghdl_has_feature needs to be used between elab and simulate
95 echo "elaborate (failure expected) $@"
96 "$GHDL" -e --expect-failure $GHDL_STD_FLAGS $GHDL_FLAGS $@
99 # Simulate a design (no error expected)
100 # Note: somewhat deprecated, use elab_simulate instead;
101 # unless ghdl_has_feature needs to be used between elab and simulate
104 echo "simulate $@ ($GHDL_FLAGS $@)" >&2
105 "$GHDL" -r $GHDL_STD_FLAGS $GHDL_FLAGS "$@"
109 # Simulate a design (failure expected)
110 # Note: somewhat deprecated, use elab_simulate_failure instead;
111 # unless ghdl_has_feature needs to be used between elab and simulate
114 echo "simulate (failure expected) $@" >&2
115 "$GHDL" -r $GHDL_STD_FLAGS $GHDL_FLAGS $@
--expect-failure
119 # Elaborate and simulate a design (no error expected)
122 echo "elaborate and simulate $@"
123 "$GHDL" --elab-run $GHDL_STD_FLAGS $GHDL_FLAGS $@
126 # Elaborate and simulate a design (failure expected)
127 elab_simulate_failure
()
129 echo "elaborate and simulate (failure expected) $@"
130 "$GHDL" --elab-run $GHDL_STD_FLAGS $GHDL_FLAGS $@
--expect-failure
135 echo "Synthesis of $@" >&2
136 "$GHDL" --synth $GHDL_STD_FLAGS $GHDL_SYNTH_FLAGS $GHDL_FLAGS $@
141 echo "try to synthesize $@"
142 # for arg in $@; do echo "arg: $arg"; done
143 if ! "$GHDL" --synth --expect-failure $GHDL_STD_FLAGS $GHDL_FLAGS "$@" ; then
144 echo "Failure expected"
149 # Synthesis of a single file
152 synth
$1.vhdl
-e > syn_
$1.vhdl
155 # Synthesis of a single file and analyze the result
158 synth
$1.vhdl
-e > syn_
$1.vhdl
160 synth
--out=verilog
$1.vhdl
-e > syn_
$1.v
161 verilog_compile syn_
$1.v
164 # Analyze and test $1
165 # Then synthesize and test the result
168 # Extract the first unit
172 analyze $
* $t.vhdl tb_
$t.vhdl
176 synth $
* $t.vhdl
-e $t > syn_
$t.vhdl
177 synth
--out=verilog $
* $t.vhdl
-e $t > syn_
$t.v
178 analyze $
* syn_
$t.vhdl tb_
$t.vhdl
179 verilog_compile syn_
$t.v
180 elab_simulate tb_
$t --ieee-asserts=disable-at-0
--assert-level=error
184 # Check if a C compiler is installed on this system
185 c_compiler_is_available
()
193 # Check if a feature is present
196 "$GHDL" -r $GHDL_STD_FLAGS $GHDL_FLAGS $1 --has-feature=$2
199 ghdl_is_interpretation
()
201 "$GHDL" --version |
grep -q interpretation
211 # Run a program (failure expected)
214 echo "run (failure expected) $@"
216 echo "failure expected";
221 # Be sure vpi can be used
224 if [ "$OS" = "Windows_NT" ]; then
225 # Need to put the directory containing libghdlvpi.dll in the path.
226 vpi_lib
=`$GHDL --vpi-library-dir-unix`
227 echo vpi_lib
: $vpi_lib
228 PATH
="$PATH:$vpi_lib"
232 # Clean the environment
235 if [ $# -eq 0 ]; then
236 echo "Remove work library"
237 "$GHDL" --remove $GHDL_STD_FLAGS
241 echo "Remove work library"
242 "$GHDL" --remove $1 ;;
244 echo "Remove $1 library"
245 "$GHDL" --remove $GHDL_STD_FLAGS --work=$1 ;;
251 # Like diff but ignore CR ('\r') end-of-line on windows (as the reference file
252 # was generated on a UNIX platform).
253 # The --strip-trailing-cr option is available with GNU diff but not on BSD
257 if [ "$OS" = "Windows_NT" ]; then
258 diff --strip-trailing-cr $@
267 if [ x
"$GHWDUMP" = x
]; then
269 */*) export GHWDUMP
=$
(dirname $GHDL)/ghwdump
;;
270 *) export GHWDUMP
=ghwdump
;;
274 "$GHWDUMP" -ths "$1".ghw
> "$1".txt
277 # Compare the dump of a GHW wave and a previous golden dump
281 if diff_nocr
"$1".txt golden_
"$1".txt
; then
282 echo "The ghw dump matches."
284 echo "The ghw dump does not match what is expected."