Skip to content
Snippets Groups Projects
test_all_requestnames.m 5.42 KiB
Newer Older
function [pass,request_list,err,telaps,skipped,gdat_results] = test_all_requestnames(varargin)
% [pass,request_list,err,telaps,skipped,gdat_results] = test_all_requestnames(varargin);
Federico Felici's avatar
Federico Felici committed
% test function to run all requestnames
%  pass = test_all_requestnames; % default test
%  pass = test_all_requestnames('param1',value1,'param2',value2,...); %
Federico Felici's avatar
Federico Felici committed
%    INPUT PARAMETERS (optional)
%       machine: string of machine name (e.g. 'aug'). (default: gdat internal default)
%       testmode: depth of test: 'reduced' or 'full' (default: 'reduced') or cell array of requests to test
%       nverbose: 0 for silent, 1/11 for text, 2/12 for plots (default: 1) 1/2 will not write skipped signals, calling..., 11/12 will write all
Federico Felici's avatar
Federico Felici committed
%    OUTPUTS
%       pass: single boolean indicating pass/fail of test
%                    pass means all error codes were zero
%       request_list: list of requests
%       err:     error code of tested requests
%       telaps:  elapsed time for tested requests
%       skipped: boolean flag indicating whether request was skipped
%
% Example for quick test:
%  [pass,request_list,err,telaps,skipped,gdat_results] = test_all_requestnames('machine','tcv','testmode',{'ip','q_rho'});
%
Federico Felici's avatar
Federico Felici committed
[machine,testmode,nverbose] = parse_inputs(varargin{:});

%
  doplot = true;
Federico Felici's avatar
Federico Felici committed
else
  doplot = false;
Federico Felici's avatar
Federico Felici committed
end

%% get request list
if isempty(machine)
  [gd0,gp0] = gdat;
else
  [gd0,gp0] = gdat('machine',machine);
end
Federico Felici's avatar
Federico Felici committed
if isempty(machine)
  machine = gp0.machine;
Federico Felici's avatar
Federico Felici committed
end
request_list = gd0.gdat_request;

%% get default test shot for each machine
switch upper(machine)
 case 'AUG'
  shot = 30594;
 case 'TCV'
  shot = 48836;
Federico Felici's avatar
Federico Felici committed
end

%% possibly skip some since they take too long for a reduced test
if iscell(testmode)
  skip = setdiff(request_list,testmode);
  testmode_not_in_list = setdiff(testmode,request_list);
  if ~isempty(testmode_not_in_list)
    if nverbose >= 1
      disp('***********************************************************************')
      warning(['following input requests nt in request_list: ' testmode_not_in_list{:}]);
      disp('***********************************************************************')
    end
  end
else
  switch testmode
   case 'reduced'
    skip = skip_list(machine);
   case 'full'
    skip = ''; % skip none
   otherwise
    error('invalid testmode, should be ''reduced'' or ''full''');
  end
Federico Felici's avatar
Federico Felici committed
end

%% init
Nreq = numel(gd0.gdat_request);
err = zeros(Nreq,1);
telaps = zeros(Nreq,1);
skipped = false(Nreq,1);
gdat_call = cell(Nreq,1);

%% call gdat requests in a loop
for ireq = 1:Nreq
  myrequest = request_list{ireq};
  if ~ismember(myrequest,skip)
    % build request string
    if strcmp(myrequest,'transp')
      shotfile_user='PUETTI';
      gdat_call{ireq} = sprintf(['gdat_' lower(machine) '(%d,''%s'',''doplot'',%d,''exp_name'',''%s'')'],shot,myrequest,doplot,shotfile_user);
      gdat_call{ireq} = sprintf(['gdat_' lower(machine) '(%d,''%s'',''doplot'',%d)'],shot,myrequest,doplot);
    % eval call
    [err(ireq),telaps(ireq),gdat_results{ireq}] = do_gdat_call(gdat_call{ireq},nverbose);
    skipped(ireq) = false;
    pause(0.1)
  else
    % skip
    err(ireq) = 0;
    telaps(ireq) = 0;
    skipped(ireq) = true;
    if nverbose>=11; fprintf('\n skipping gdat request ''%s''\n',myrequest); end
Federico Felici's avatar
Federico Felici committed

pass = all(~err);

%% Summary display
if nverbose
  summary_display(request_list,telaps,err,gdat_call,skipped,nverbose)
  if pass
    fprintf('passed %s tests\n',mfilename());
  else
    fprintf('test FAILED: %s.m\n',mfilename());
  end
Federico Felici's avatar
Federico Felici committed
end

function [machine,testmode,verbose] = parse_inputs(varargin)
p = inputParser;
p.addOptional('machine','');
p.addOptional('testmode','reduced');
p.addOptional('nverbose',1);
p.parse(varargin{:});

machine  = p.Results.machine;
testmode = p.Results.testmode;
verbose  = p.Results.nverbose;

function skip = skip_list(machine)
switch upper(machine)
 case 'AUG'
  skip = {'cxrs','transp','te_rho','ne_rho','nete_rho','ece_rho','eced_rho','cxrs_rho','eqdsk','equil'};
 otherwise
  warning('no list to skip defined for machine ''%s''',machine);
  skip = '';
function [err,telaps,gdat_result] = do_gdat_call(gdat_call,nverbose)
  fprintf('\n calling %s...\n',gdat_call);
  [gdat_result,~,err] = eval(gdat_call);
Federico Felici's avatar
Federico Felici committed
catch ME
  err = -1;
  getReport(ME); %,'extended');
Federico Felici's avatar
Federico Felici committed
end
telaps = toc; % elapsed time

function summary_display(request_list,telaps,err,gdat_call,skipped,nverbose)
Federico Felici's avatar
Federico Felici committed
%%
Nreq = numel(request_list);

if any(err==0)
  fprintf('\n\n  PASSED:\n')
  print_header();
  for ireq=1:Nreq
Federico Felici's avatar
Federico Felici committed
    if ~skipped(ireq) && ~err(ireq)
      print_result(request_list{ireq},telaps(ireq),err(ireq),gdat_call{ireq})
  fprintf('\n\n  SKIPPED:\n')
  print_header();
  for ireq=1:Nreq
Federico Felici's avatar
Federico Felici committed
    if skipped(ireq)
      fprintf('   %-20s%-20s\n',request_list{ireq},'skipped');
Federico Felici's avatar
Federico Felici committed
end

if any(err~=0)
  fprintf('\n\n  FAILED:\n')
  print_header();
  for ireq=1:Nreq
Federico Felici's avatar
Federico Felici committed
    if ~skipped(ireq) && (err(ireq)~=0)
      print_result(request_list{ireq},telaps(ireq),err(ireq),gdat_call{ireq})
Federico Felici's avatar
Federico Felici committed
end

fprintf('\n\n   total test time: %2.2f[s]\n\n',sum(telaps));


function print_header()
fprintf('   %-60s\n',char(repmat(int8('-'),1,60)))
fprintf('   %-20s%-20s%-10s%-100s\n','request','time_elapsed[''s'']','errorcode','gdat call')
fprintf('   %-60s\n',char(repmat(int8('-'),1,60)))
Federico Felici's avatar
Federico Felici committed

function print_result(req,telaps,err,callstr)
fprintf('   %-20s%-20.2f%-10d%-100s\n',req,telaps,err,callstr);