From e49cada34116cfe7f5014efa6d0bf4996c0e3ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 1 Mar 2022 11:29:52 +0100 Subject: [PATCH] Testsuite: run_block_byte_tests_{matlab,octave}.m were not actually checking the results --- tests/run_block_byte_tests_matlab.m | 20 +++++++++++++------- tests/run_block_byte_tests_octave.m | 11 ++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/run_block_byte_tests_matlab.m b/tests/run_block_byte_tests_matlab.m index de922c032..f7d55899b 100644 --- a/tests/run_block_byte_tests_matlab.m +++ b/tests/run_block_byte_tests_matlab.m @@ -19,9 +19,13 @@ % % Before every call to Dynare, the contents of the workspace is saved in % 'wsMat.mat', and reloaded after Dynare has finished (this is necessary since -% Dynare does a 'clear -all'). Also note that we take care of clearing the -% 'exception' variable in all 'catch' block, because otherwise the next 'load -% wsMat' within a 'catch' block will overwrite the last exception. +% Dynare does a 'clear -all'). +% Note that we take care of clearing oo_ before saving the workspace, +% otherwise the newly created oo_ will be scratched upon loading, +% thus making the path comparison bogus. +% We also take care of clearing the 'exception' variable in all 'catch' +% block, because otherwise the next 'load wsMat' within a 'catch' block will +% overwrite the last exception. top_test_dir = getenv('TOP_TEST_DIR'); addpath([top_test_dir filesep 'utils']); @@ -80,6 +84,7 @@ for blockFlag = 0:1 else try old_path = path; + clear oo_ % Ensure that oo_.endo_simul won’t be overwritten when loading wsMat save wsMat run_ls2003(blockFlag, storageFlag, solve_algos(i), default_stack_solve_algo) load wsMat @@ -87,9 +92,9 @@ for blockFlag = 0:1 % Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if abs(diff) > options_.dynatol.x + if max(max(abs(diff))) > options_.dynatol.x failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; - exception = MException('ERROR: simulation path differs from the reference path'); + exception = MException('Dynare:simerr', 'ERROR: simulation path differs from the reference path'); printMakeCheckMatlabErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], exception); clear exception end @@ -106,6 +111,7 @@ for blockFlag = 0:1 num_block_tests = num_block_tests + 1; try old_path = path; + clear oo_ % Ensure that oo_.endo_simul won’t be overwritten when loading wsMat save wsMat run_ls2003(blockFlag, storageFlag, default_solve_algo, stack_solve_algos(i)) load wsMat @@ -113,9 +119,9 @@ for blockFlag = 0:1 % Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if abs(diff) > options_.dynatol.x + if max(max(abs(diff))) > options_.dynatol.x failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')']; - exception = MException('ERROR: simulation path difers from the reference path'); + exception = MException('Dynare:simerr', 'ERROR: simulation path difers from the reference path'); printMakeCheckMatlabErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], exception); clear exception end diff --git a/tests/run_block_byte_tests_octave.m b/tests/run_block_byte_tests_octave.m index d2533a142..6dcd4358b 100644 --- a/tests/run_block_byte_tests_octave.m +++ b/tests/run_block_byte_tests_octave.m @@ -20,6 +20,9 @@ ## Before every call to Dynare, the contents of the workspace is saved in ## 'wsOct', and reloaded after Dynare has finished (this is necessary since ## Dynare does a 'clear -all'). +## Note that we take care of clearing oo_ before saving the workspace, +## otherwise the newly created oo_ will be scratched upon loading, +## thus making the path comparison bogus. top_test_dir = getenv('TOP_TEST_DIR'); addpath([top_test_dir filesep 'utils']); @@ -53,7 +56,7 @@ for blockFlag = 0:1 # Workaround for strange race condition related to the static/dynamic # files (especially when we switch to/from use_dll) - rmdir('+ls2003_tmp', 's') + rmdir('+ls2003_tmp', 's'); pause(1) for i = 1:length(solve_algos) @@ -78,6 +81,7 @@ for blockFlag = 0:1 else try old_path = path; + clear oo_ # Ensure that oo_.endo_simul won’t be overwritten when loading wsOct save wsOct run_ls2003(blockFlag, storageFlag, solve_algos(i), default_stack_solve_algo) load wsOct @@ -85,7 +89,7 @@ for blockFlag = 0:1 ## Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if abs(diff) > options_.dynatol.x + if max(max(abs(diff))) > options_.dynatol.x failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; differr.message = ["ERROR: simulation path differs from the reference path" ]; printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], differr); @@ -102,6 +106,7 @@ for blockFlag = 0:1 num_block_tests = num_block_tests + 1; try old_path = path; + clear oo_ # Ensure that oo_.endo_simul won’t be overwritten when loading wsOct save wsOct run_ls2003(blockFlag, storageFlag, default_solve_algo, stack_solve_algos(i)) load wsOct @@ -109,7 +114,7 @@ for blockFlag = 0:1 ## Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if abs(diff) > options_.dynatol.x + if max(max(abs(diff))) > options_.dynatol.x failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')']; differr.message = ["ERROR: simulation path differs from the reference path" ]; printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], differr);