Meson build system: implement most of the testsuite

The tests that are individually listed in {M,O}_TRS_FILES of tests/Makefile.am
are still missing.
kalman-mex
Sébastien Villemot 2023-09-12 17:10:17 +02:00
parent 755138fb84
commit 8a79899189
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
4 changed files with 1239 additions and 36 deletions

File diff suppressed because it is too large Load Diff

98
scripts/test-driver Executable file
View File

@ -0,0 +1,98 @@
#!/bin/bash
# Executes one or several .mod or .m files in a separate directory, for the testsuite
set -e
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
subdir=${f%/*}
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
matlab_batch_flags=(-nodisplay -nodisplay -r)
fi
fi
fi
export DYNARE_BUILD_DIR=$build_root
export source_root
for test_file in "${test_files[@]}"; do
test_basename=${test_file##*/}
test_subdir=${test_file%/*}
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
xvfb-run -a "$matlab_octave_exe" --no-init-file --silent --no-history "$test_arg"
fi
done

1
tests/.gitignore vendored
View File

@ -148,6 +148,7 @@ wsOct
!/run_o_script.m
!/run_reporting_test_matlab.m
!/run_reporting_test_octave.m
!/run_mod_file.m
!/run_test_matlab.m
!/run_test_octave.m
!/shock_decomposition/example1_calib_shock_decomp_data.mat

47
tests/run_mod_file.m Normal file
View File

@ -0,0 +1,47 @@
% Copyright © 2011-2023 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
source_dir = getenv('source_root');
addpath([source_dir filesep 'tests' filesep 'utils']);
addpath([source_dir filesep 'matlab']);
if isoctave
load_octave_packages
end
fprintf('\n*** TESTING: %s ***\n\n', getenv('mod_file'));
tic;
% NB: all variables will be cleared by the call to Dynare
try
dynare(getenv('mod_file'), 'console')
testFailed = false;
catch exception
if isoctave
printMakeCheckOctaveErrMsg(getenv('mod_file'), exception);
else
printMakeCheckMatlabErrMsg(getenv('mod_file'), exception);
end
testFailed = true;
end
fprintf('\n*** Elapsed time (in seconds): %.1f\n\n', toc);
% Ensure proper termination and exit code
quit(testFailed)