2023-09-12 17:10:17 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Executes one or several .mod or .m files in a separate directory, for the testsuite
|
|
|
|
|
|
|
|
set -e
|
2023-09-20 13:07:30 +02:00
|
|
|
shopt -s extglob
|
2023-09-12 17:10:17 +02:00
|
|
|
|
|
|
|
if (($# < 7 )); then
|
|
|
|
echo "Usage: $0 build_for matlab_octave_exe matlab_octave_version matlab_arch source_root build_root test_file(s) [-- extra_file(s)]" 2>&1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
build_for=$1
|
|
|
|
matlab_octave_exe=$2
|
|
|
|
matlab_octave_version=$3
|
|
|
|
matlab_arch=$4
|
|
|
|
source_root=$5
|
|
|
|
build_root=$6
|
|
|
|
shift 6
|
|
|
|
|
|
|
|
test_files=()
|
|
|
|
while (($# > 0)); do
|
|
|
|
if [[ $1 == "--" ]]; then
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
test_files+=("$1")
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
extra_files=("$@")
|
|
|
|
|
|
|
|
# Create and populate the temporary directory
|
|
|
|
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
|
|
|
|
cleanup ()
|
|
|
|
{
|
|
|
|
rm -rf "${tmpdir}"
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
for f in "${test_files[@]}" "${extra_files[@]}"; do
|
2023-09-20 13:07:30 +02:00
|
|
|
# NB: for computing the subdir, we do not use ${f%/*}, because the latter does not
|
|
|
|
# work with files which are not in a subdir (i.e. no slash in the filename).
|
|
|
|
# We rather use pattern substitution (and we use an extended pattern of the
|
|
|
|
# form *(pattern-list), hence the extglob option above).
|
|
|
|
subdir=${f/%*([^\/])/}
|
2023-09-12 17:10:17 +02:00
|
|
|
mkdir -p "${tmpdir}/${subdir}"
|
|
|
|
cp "${source_root}/tests/${f}" "${tmpdir}/${f}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# If testing with MATLAB, compute the right batch flags
|
|
|
|
if [[ $build_for == matlab ]]; then
|
|
|
|
# Check whether MATLAB version is ⩾ 9.6
|
|
|
|
IFS=. read -r -a split_version <<< "$matlab_octave_version"
|
|
|
|
if ((split_version[0] > 9 || (split_version[0] == 9 && split_version[1] >= 6) )); then
|
|
|
|
if [[ $matlab_arch == win64 ]]; then
|
|
|
|
matlab_batch_flags=(-noFigureWindows -batch)
|
|
|
|
else
|
|
|
|
matlab_batch_flags=(-nodisplay -batch)
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [[ $matlab_arch == win64 ]]; then
|
|
|
|
matlab_batch_flags=(-nosplash -automation -wait -sd "$source_root"/tests -r)
|
|
|
|
else
|
2023-09-26 16:54:53 +02:00
|
|
|
matlab_batch_flags=(-nosplash -nodisplay -r)
|
2023-09-12 17:10:17 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
export DYNARE_BUILD_DIR=$build_root
|
|
|
|
export source_root
|
|
|
|
|
|
|
|
for test_file in "${test_files[@]}"; do
|
|
|
|
test_basename=${test_file##*/}
|
2023-09-20 13:07:30 +02:00
|
|
|
# See the remark above for computing the subdir
|
|
|
|
test_subdir=${test_file/%*([^\/])/}
|
2023-09-12 17:10:17 +02:00
|
|
|
if [[ $test_file =~ \.mod$ ]]; then
|
|
|
|
export mod_file=$test_basename
|
|
|
|
if [[ $build_for == matlab ]]; then
|
|
|
|
test_arg=run_mod_file
|
|
|
|
else
|
|
|
|
test_arg=run_mod_file.m
|
|
|
|
fi
|
|
|
|
cp "${source_root}"/tests/run_mod_file.m "${tmpdir}"/"${test_subdir}"
|
|
|
|
elif [[ $test_file =~ \.m$ ]]; then
|
|
|
|
if [[ $build_for == matlab ]]; then
|
|
|
|
test_arg=${test_basename%.m}
|
|
|
|
else
|
|
|
|
test_arg=$test_basename
|
|
|
|
fi
|
|
|
|
echo "Running $test_file"
|
|
|
|
else
|
|
|
|
echo "Unsupported file extension: $test_file" 2>&1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd "${tmpdir}"/"${test_subdir}"
|
|
|
|
if [[ $build_for == matlab ]]; then
|
|
|
|
"$matlab_octave_exe" "${matlab_batch_flags[@]}" "$test_arg"
|
|
|
|
else
|
2023-10-13 20:14:25 +02:00
|
|
|
unset XDG_SESSION_TYPE # Ensure that Wayland will not be used if in a desktop session
|
|
|
|
# We cannot use the --no-window-system option, and we have to use xvfb
|
|
|
|
# See the following Octave bug: https://savannah.gnu.org/bugs/?62101
|
|
|
|
# (this affects at least tests/shock_decomposition/ls2003_plot.mod)
|
2023-09-12 17:10:17 +02:00
|
|
|
xvfb-run -a "$matlab_octave_exe" --no-init-file --silent --no-history "$test_arg"
|
|
|
|
fi
|
|
|
|
done
|