File: run_block_bytecode_tests.m

package info (click to toggle)
dynare 6.5-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 67,796 kB
  • sloc: cpp: 79,110; ansic: 28,917; objc: 12,445; yacc: 4,537; pascal: 1,993; lex: 1,441; sh: 1,132; python: 634; makefile: 628; lisp: 163; xml: 18
file content (153 lines) | stat: -rw-r--r-- 7,692 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% 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/>.

% Implementation notes:
%
% 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').
% 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.

source_dir = getenv('source_root');
addpath([source_dir filesep 'tests' filesep 'utils']);
addpath([source_dir filesep 'matlab']);

% Test block_bytecode/ls2003.mod with various combinations of
% block/bytecode/solve_algo/stack_solve_algo
failedBlock = {};
cd block_bytecode
tic;
for blockFlag = 0:1
    for storageFlag = 0:2 % 0=M-file, 1=use_dll, 2=bytecode
        default_solve_algo = 2;
        default_stack_solve_algo = 0;
        if ~blockFlag && storageFlag ~= 2
            solve_algos = [1:4 9];
            stack_solve_algos = [0 1 6];
        elseif blockFlag && storageFlag ~= 2
            solve_algos = [1:4 6:9];
            stack_solve_algos = [0:4 6];
        else
            solve_algos = 1:9;
            stack_solve_algos = 0:6;
        end
        if isoctave || user_has_matlab_license('optimization_toolbox')
            solve_algos = [ 0 solve_algos ];
        end

        % Workaround for strange race condition related to the static/dynamic
        % files (especially when we switch to/from use_dll)
        if isoctave && exist('+ls2003_tmp')
            rmdir('+ls2003_tmp', 's');
            pause(1)
        end

        for i = 1:length(solve_algos)
            if ~blockFlag && storageFlag == 0 && (i == 1)
                % This is the reference simulation path against which all
                % other simulations will be tested
                try
                    old_path = path;
                    save wsMat
                    run_ls2003(blockFlag, storageFlag, solve_algos(i), default_stack_solve_algo)
                    load wsMat
                    path(old_path);
                    y_ref = oo_.endo_simul;
                    save('test.mat','y_ref');
                catch exception
                    load wsMat
                    path(old_path);
                    failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'];
                    printTestError(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], exception);
                    clear exception
                end
            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
                    path(old_path);
                    % Test against the reference simulation path
                    load('test.mat','y_ref');
                    diff = oo_.endo_simul - y_ref;
                    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) ')'];
                        if isoctave
                            exception.message = 'ERROR: simulation path differs from the reference path';
                        else
                            exception = MException('Dynare:simerr', 'ERROR: simulation path differs from the reference path');
                        end
                        printTestError(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], exception);
                        clear exception
                    end
                catch exception
                    load wsMat
                    path(old_path);
                    failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'];
                    printTestError(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], exception);
                    clear exception
                end
            end
        end
        for i = 1:length(stack_solve_algos)
            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
                path(old_path);
                % Test against the reference simulation path
                load('test.mat','y_ref');
                diff = oo_.endo_simul - y_ref;
                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)) ')'];
                    if isoctave
                        exception.message = 'ERROR: simulation path differs from the reference path';
                    else
                        exception = MException('Dynare:simerr', 'ERROR: simulation path difers from the reference path');
                    end
                    printTestError(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], exception);
                    clear exception
                end
            catch exception
                load wsMat
                path(old_path);
                failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'];
                printTestError(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(storageFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], exception);
                clear exception
            end
        end
    end
end

delete('wsMat.mat')

if size(failedBlock,2) > 0
    fprintf('\n*** Failed tests: %s\n', failedBlock{:})
end

fprintf('\n*** Elapsed time (in seconds): %.1f\n\n', toc);

quit(size(failedBlock,2) > 0)