yosys/tests/gen-tests-makefile.sh

112 lines
2.3 KiB
Bash
Raw Normal View History

set -eu
YOSYS_BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../ >/dev/null 2>&1 && pwd)"
# $ generate_target target_name test_command
generate_target() {
target_name=$1
test_command=$2
2020-09-16 12:58:16 -05:00
echo "all: $target_name"
echo ".PHONY: $target_name"
echo "$target_name:"
printf "\t@%s\n" "$test_command"
printf "\t@echo 'Passed %s'\n" "$target_name"
}
# $ generate_ys_test ys_file [yosys_args]
generate_ys_test() {
ys_file=$1
yosys_args_=${2:-}
generate_target "$ys_file" "\"$YOSYS_BASEDIR/yosys\" -ql ${ys_file%.*}.log $yosys_args_ $ys_file"
}
2024-11-28 08:14:15 -06:00
# $ generate_tcl_test tcl_file [yosys_args]
generate_tcl_test() {
tcl_file=$1
yosys_args_=${2:-}
generate_target "$tcl_file" "\"$YOSYS_BASEDIR/yosys\" -ql ${tcl_file%.*}.log $yosys_args_ $tcl_file"
}
# $ generate_bash_test bash_file
generate_bash_test() {
bash_file=$1
generate_target "$bash_file" "bash -v $bash_file >${bash_file%.*}.log 2>&1"
}
# $ generate_tests [-y|--yosys-scripts] [-s|--prove-sv] [-b|--bash] [-a|--yosys-args yosys_args]
generate_tests() {
do_ys=false
2024-11-28 08:14:15 -06:00
do_tcl=false
do_sv=false
do_sh=false
yosys_args=""
while [[ $# -gt 0 ]]; do
arg="$1"
case "$arg" in
-y|--yosys-scripts)
do_ys=true
shift
;;
2024-11-28 08:14:15 -06:00
-t|--tcl-scripts)
do_tcl=true
shift
;;
-s|--prove-sv)
do_sv=true
shift
;;
-b|--bash)
do_sh=true
shift
;;
-a|--yosys-args)
yosys_args+="$2"
shift
shift
;;
*)
echo >&2 "Unknown argument: $1"
exit 1
esac
done
2024-11-28 08:14:15 -06:00
if [[ ! ( $do_ys = true || $do_tcl = true || $do_sv = true || $do_sh = true ) ]]; then
echo >&2 "Error: No file types selected"
exit 1
fi
echo ".PHONY: all"
2020-09-16 12:58:16 -05:00
echo "all:"
if [[ $do_ys = true ]]; then
for x in *.ys; do
generate_ys_test "$x" "$yosys_args"
done
fi;
2024-11-28 08:14:15 -06:00
if [[ $do_tcl = true ]]; then
for x in *.tcl; do
generate_tcl_test "$x" "$yosys_args"
done
fi;
if [[ $do_sv = true ]]; then
for x in *.sv; do
if [ ! -f "${x%.sv}.ys" ]; then
generate_ys_test "$x" "-p \"prep -top top; async2sync; sat -enable_undef -verify -prove-asserts\" $yosys_args"
fi;
done
fi;
if [[ $do_sh == true ]]; then
for s in *.sh; do
if [ "$s" != "run-test.sh" ]; then
generate_bash_test "$s"
fi
done
fi
}
run_tests() {
generate_tests "$@" > run-test.mk
exec ${MAKE:-make} -f run-test.mk
}