1 | function varargout=runme(varargin)
|
---|
2 | %RUNME - test deck for ISSM nightly runs
|
---|
3 | %
|
---|
4 | % In a test deck directory (tests/Vertification/NightlyRun for example)
|
---|
5 | % The following command will launch all the existing tests:
|
---|
6 | % >> runme
|
---|
7 | % To run the tests 101 and 102:
|
---|
8 | % >> runme('id',[101 102])
|
---|
9 | % etc...
|
---|
10 | %
|
---|
11 | % Available options:
|
---|
12 | % 'id' followed by the list of ids requested
|
---|
13 | % 'exclude' ids to be excluded from the test
|
---|
14 | % 'benchmark' 'all' (all of them)
|
---|
15 | % 'nightly' (nightly run)
|
---|
16 | % 'ismip' : validation of ismip-hom tests
|
---|
17 | % 'eismint': validation of eismint tests
|
---|
18 | % 'thermal': validation of thermal tests
|
---|
19 | % 'mesh' : validation of mesh tests
|
---|
20 | % 'adolc' : validation of adolc tests
|
---|
21 | % 'slr' : validation of slr tests
|
---|
22 | % 'qmu' : validation of dakota tests
|
---|
23 | % ...
|
---|
24 | % 'procedure' 'check' : run the test (default)
|
---|
25 | % 'update': update the archive
|
---|
26 | % 'valgrind': check for memory leaks (default value of md.debug.valgrind needs to be changed manually)
|
---|
27 | % 'stoponerror' 1 or 0
|
---|
28 | %
|
---|
29 | % Usage:
|
---|
30 | % runme(varargin);
|
---|
31 | %
|
---|
32 | % Examples:
|
---|
33 | % runme;
|
---|
34 | % runme('exclude',101);
|
---|
35 | % runme('id',102,'procedure','update');
|
---|
36 |
|
---|
37 | % runme('procedure','valgrind','stoponerror',1,'exclude','IdFromString('Dak'));
|
---|
38 |
|
---|
39 | %Check inputs
|
---|
40 | % {{{
|
---|
41 | if nargout>1
|
---|
42 | help runme
|
---|
43 | error('runme error message: bad usage');
|
---|
44 | end
|
---|
45 |
|
---|
46 | %recover options
|
---|
47 | options=pairoptions(varargin{:});
|
---|
48 | % }}}
|
---|
49 |
|
---|
50 | %Process options
|
---|
51 | %GET benchmark {{{
|
---|
52 | benchmark=getfieldvalue(options,'benchmark','nightly');
|
---|
53 | if ~ismember(benchmark,{'all','nightly','ismip','eismint','thermal','mesh','validation','tranforcing','adolc','slr','qmu'})
|
---|
54 | disp('runme warning: benchmark not supported, defaulting to test ''nightly''')
|
---|
55 | benchmark='nightly';
|
---|
56 | end
|
---|
57 | % }}}
|
---|
58 | %GET procedure {{{
|
---|
59 | procedure=getfieldvalue(options,'procedure','check');
|
---|
60 | if ~ismember(procedure,{'check','update','valgrind'})
|
---|
61 | disp('runme warning: procedure not supported, defaulting to test ''check''')
|
---|
62 | procedure='check';
|
---|
63 | end
|
---|
64 | % }}}
|
---|
65 | %GET output {{{
|
---|
66 | output=getfieldvalue(options,'output','none');
|
---|
67 | if ~ismember(output,{'nightly','none'})
|
---|
68 | disp('runme warning: output not supported, defaulting to test ''none''')
|
---|
69 | output='none';
|
---|
70 | end
|
---|
71 | % }}}
|
---|
72 | %GET RANK and NUMPROCS for multithreaded runs {{{
|
---|
73 | rank=getfieldvalue(options,'rank',1);
|
---|
74 | numprocs=getfieldvalue(options,'numprocs',1);
|
---|
75 | if (numprocs<rank), numprocs=1; end
|
---|
76 | % }}}
|
---|
77 | %GET ids {{{
|
---|
78 | flist=dir;%use dir, as it seems to act OS independent
|
---|
79 | list_ids=[];
|
---|
80 | for i=1:numel(flist),
|
---|
81 | if ( strncmp(flist(i).name,'test',4) &... %File name must start with 'test'
|
---|
82 | strncmp(fliplr(flist(i).name),fliplr('.m'),2)&... %File name must end by '.m'
|
---|
83 | ~strcmp(flist(i).name,'test.m')) %File name must be different than 'test.m'
|
---|
84 | id=str2num(flist(i).name(5:end-2));
|
---|
85 | if isempty(id),
|
---|
86 | disp(['WARNING: ignore file ' flist(i).name ]);
|
---|
87 | else
|
---|
88 | list_ids(end+1)=eval(flist(i).name(5:end-2)); %Keep test id only (skip 'test' and '.m')
|
---|
89 | end
|
---|
90 | end
|
---|
91 | end
|
---|
92 | [i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
|
---|
93 | list_ids=list_ids(i1:i2);
|
---|
94 |
|
---|
95 | test_ids=getfieldvalue(options,'id',list_ids);
|
---|
96 | test_ids=intersect(test_ids,list_ids);
|
---|
97 | % }}}
|
---|
98 | %GET exclude {{{
|
---|
99 | exclude_ids=getfieldvalue(options,'exclude',[]);
|
---|
100 | exclude_ids=[exclude_ids];
|
---|
101 | pos=find(ismember(test_ids,exclude_ids));
|
---|
102 | test_ids(pos)=[];
|
---|
103 | % }}}
|
---|
104 | %Process Ids according to benchmarks{{{
|
---|
105 | if strcmpi(benchmark,'nightly'),
|
---|
106 | test_ids=intersect(test_ids,[1:999]);
|
---|
107 | elseif strcmpi(benchmark,'validation'),
|
---|
108 | test_ids=intersect(test_ids,[1001:1999]);
|
---|
109 | elseif strcmpi(benchmark,'ismip'),
|
---|
110 | test_ids=intersect(test_ids,[1101:1199]);
|
---|
111 | elseif strcmpi(benchmark,'eismint'),
|
---|
112 | test_ids=intersect(test_ids,[1201:1299]);
|
---|
113 | elseif strcmpi(benchmark,'thermal'),
|
---|
114 | test_ids=intersect(test_ids,[1301:1399]);
|
---|
115 | elseif strcmpi(benchmark,'mesh'),
|
---|
116 | test_ids=intersect(test_ids,[1401:1499]);
|
---|
117 | elseif strcmpi(benchmark,'tranforcing'),
|
---|
118 | test_ids=intersect(test_ids,[1501:1502]);
|
---|
119 | elseif strcmpi(benchmark,'referential'),
|
---|
120 | test_ids=intersect(test_ids,[1601:1602]);
|
---|
121 | elseif strcmpi(benchmark,'slr'),
|
---|
122 | test_ids=intersect(test_ids,[2001:2500]);
|
---|
123 | elseif strcmpi(benchmark,'adolc'),
|
---|
124 | test_ids=intersect(test_ids,[3001:3200]);
|
---|
125 | elseif strcmpi(benchmark,'qmu'),
|
---|
126 | test_ids=intersect(test_ids,[218 234 235 412:414 417 418 420]);
|
---|
127 | end
|
---|
128 | % }}}
|
---|
129 |
|
---|
130 | %Loop over tests and launch sequence
|
---|
131 | root=pwd;
|
---|
132 | for id=test_ids,
|
---|
133 | disp(sprintf('%s%i%s','----------------starting:',id,'-----------------------'));
|
---|
134 | try,
|
---|
135 | %Execute test
|
---|
136 | cd(root);
|
---|
137 | id_string='N/A';
|
---|
138 | id_string=IdToName(id);
|
---|
139 | run(['test' num2str(id)]);
|
---|
140 |
|
---|
141 | %UPDATE ARCHIVE?
|
---|
142 | archive_name=['Archive' num2str(id) ];
|
---|
143 | if strcmpi(procedure,'update'),
|
---|
144 | delete(['../Archives/' archive_name '.arch'])
|
---|
145 | for k=1:length(field_names),
|
---|
146 | field=field_values{k};
|
---|
147 | archwrite(['../Archives/' archive_name '.arch'],[archive_name '_field' num2str(k)], field);
|
---|
148 | end
|
---|
149 | disp(sprintf(['File ./../Archives/' archive_name '.arch saved\n']));
|
---|
150 |
|
---|
151 | %CHECK for memory leaks?
|
---|
152 | elseif strcmpi(procedure,'valgrind'),
|
---|
153 | fields = fieldnames(md.results);
|
---|
154 | for i=1:numel(fields)
|
---|
155 | if ~isfield(md.results.(fields{i}),'errlog'),
|
---|
156 | disp(['Skipping ' fields{i}]);
|
---|
157 | continue;
|
---|
158 | else
|
---|
159 | disp(['Extracting results of ' fields{i}]);
|
---|
160 | end
|
---|
161 | results = md.results.(fields{i});
|
---|
162 | errlog = cellstr(results(1).errlog);
|
---|
163 |
|
---|
164 | %Check leaks
|
---|
165 | lines = strfind(errlog,'definitely lost:');
|
---|
166 | lines = find(~cellfun(@isempty,lines));
|
---|
167 | leaks = 0;
|
---|
168 | for j=1:numel(lines)
|
---|
169 | Line = errlog(lines(j));
|
---|
170 | Numbers = sscanf(Line{1},'==%i== definitely lost: %s bytes in %i blocks',[1 Inf]);
|
---|
171 | leaks = leaks + str2num(strrep(char(Numbers(2:end-1)),',',''));
|
---|
172 | end
|
---|
173 | %Check conditional jumps
|
---|
174 | lines = strfind(errlog,'Conditional jump or move depends on uninitialised value');
|
---|
175 | lines = find(~cellfun(@isempty,lines));
|
---|
176 | jumps = numel(lines);
|
---|
177 | %Check invalid read/write
|
---|
178 | lines = strfind(errlog,'Invalid');
|
---|
179 | lines = find(~cellfun(@isempty,lines));
|
---|
180 | inval = numel(lines);
|
---|
181 | if leaks==0,
|
---|
182 | disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind mem. leaks'],id,id_string));
|
---|
183 | else
|
---|
184 | disp(sprintf(['ERROR difference: %i > 0 test id: %i test name: %s field: valgrind mem. leaks'],leaks,id,id_string));
|
---|
185 | disp('STOP');
|
---|
186 | return;
|
---|
187 | end
|
---|
188 | if jumps==0,
|
---|
189 | disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind cond. jumps'],id,id_string));
|
---|
190 | else
|
---|
191 | disp(sprintf(['ERROR difference: %i > 0 test id: %i test name: %s field: valgrind cond. jumps'],jumps,id,id_string));
|
---|
192 | disp('STOP');
|
---|
193 | return;
|
---|
194 | end
|
---|
195 | if inval==0,
|
---|
196 | disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind invalid read/write'],id,id_string));
|
---|
197 | else
|
---|
198 | disp(sprintf(['ERROR difference: %i > 0 test id: %i test name: %s field: valgrind invalid read/write'],inval,id,id_string));
|
---|
199 | disp('STOP');
|
---|
200 | return;
|
---|
201 | end
|
---|
202 | end
|
---|
203 |
|
---|
204 | %ELSE: CHECK TEST
|
---|
205 | else,
|
---|
206 | for k=1:length(field_names),
|
---|
207 |
|
---|
208 | try,
|
---|
209 | %Get field and tolerance
|
---|
210 | field=field_values{k};
|
---|
211 | fieldname=field_names{k};
|
---|
212 | tolerance=field_tolerances{k};
|
---|
213 |
|
---|
214 | %compare to archive
|
---|
215 | %our output is in the correct order (n,1) or (1,1), so we do not need to transpose again
|
---|
216 | archive_cell=archread(['../Archives/' archive_name '.arch'],[archive_name '_field' num2str(k)]);
|
---|
217 | archive=archive_cell{1};
|
---|
218 | error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive(:)))+eps));
|
---|
219 |
|
---|
220 | %disp test result
|
---|
221 | if (error_diff>tolerance | isnan(error_diff));
|
---|
222 | disp(sprintf(['ERROR difference: %-7.2g > %7.2g test id: %i test name: %s field: %s'],...
|
---|
223 | error_diff,tolerance,id,id_string,fieldname));
|
---|
224 | if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
|
---|
225 | else
|
---|
226 | disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
|
---|
227 | error_diff,tolerance,id,id_string,fieldname));
|
---|
228 | end
|
---|
229 |
|
---|
230 | catch me2
|
---|
231 |
|
---|
232 | %something went wrong, print failure message:
|
---|
233 | message=getReport(me2);
|
---|
234 | fprintf('%s',message);
|
---|
235 | if strcmpi(output,'nightly')
|
---|
236 | fid=fopen([issmdir() '/nightlylog/matlaberror.log'], 'at');
|
---|
237 | fprintf(fid,'%s',message);
|
---|
238 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
239 | fclose(fid);
|
---|
240 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
241 | else
|
---|
242 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
243 | fprintf('%s',message);
|
---|
244 | if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
|
---|
245 | end
|
---|
246 | continue;
|
---|
247 | end
|
---|
248 | end
|
---|
249 | end
|
---|
250 | catch me,
|
---|
251 |
|
---|
252 | %something went wrong, print failure message:
|
---|
253 | message=getReport(me);
|
---|
254 | fprintf('%s',message);
|
---|
255 | if strcmpi(output,'nightly')
|
---|
256 | fid=fopen([issmdir() '/nightlylog/matlaberror.log'], 'at');
|
---|
257 | fprintf(fid,'%s',message);
|
---|
258 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
259 | fclose(fid);
|
---|
260 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
261 | else
|
---|
262 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
263 | rethrow(me);
|
---|
264 | if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
|
---|
265 | end
|
---|
266 | end
|
---|
267 | disp(sprintf('%s%i%s','----------------finished:',id,'-----------------------'));
|
---|
268 | end
|
---|