Skip to content
Snippets Groups Projects
Commit b31b09e2 authored by Federico Felici's avatar Federico Felici Committed by Olivier Sauter
Browse files

Rework gdat tests using matlab.unittest.TestCase

parent 385b63f6
Branches
Tags
1 merge request!4Feature/testsuite
function [passed,results] = run_gdat_tests(test_case)
% test runner for gdat
% F. Felici, EPFL federico.felici@epfl.ch
if nargin==0
test_case = 'all'; % deafult
end
%% populate suite
switch test_case
case 'all'
suite = matlab.unittest.TestSuite.fromClass(?test_requestnames);
otherwise
error('not yet implemented')
end
%% run it
fprintf('Start test case: %s\n%s\n\n',test_case,datestr(now));
results = run(suite);
disp(table(results));
fprintf('\nTotal test duration: %5.2fs\n',sum(table(results).Duration))
%% display results
if all([results.Passed])
fprintf('\nPassed all tests\n')
passed = true;
else
fprintf('\nSome tests Failed or Incomplete\n')
if any([results.Incomplete])
fprintf('\nIncomplete:\n')
disp(table(results([results.Incomplete])))
end
if any([results.Failed])
fprintf('\nFailed:\n')
disp(table(results([results.Failed])));
end
passed = false;
end
end
classdef test_requestnames < matlab.unittest.TestCase
properties(TestParameter)
gdat_test_params = get_gdat_test_params();
end
methods(TestClassSetup)
function testMDS(testCase)
testCase.assumeFalse(~exist('mdsdata','file'),'mdsdata not found - is mds on path?');
% other environment checks here
end
end
methods(Test)
function test_gdat_call(testCase,gdat_test_params)
machine = gdat_test_params{1};
shot = gdat_test_params{2};
gdat_request = gdat_test_params{3};
gdat_call = sprintf(['gdat_' lower(machine) '(%d,''%s'')'],shot,gdat_request);
testCase.log(sprintf('gdat_call: %s\n',gdat_call));
gdat_out = verifyWarningFree(testCase,eval(gdat_call),...
'Warning issued from gdat call:\n %s\n',gdat_call);
% add content checks of gdat_out here
end
end
end
function test_params = get_gdat_test_params()
machines = {'AUG','TCV'};
test_params = cell(0,1); % init
for im = 1:numel(machines)
% get requests for this machine
machine = machines{im};
[gd0,~] = gdat('machine',machine);
request_list = gd0.gdat_request;
% get test shot list for this machine
shots = get_shots(machine);
for ishot = 1:numel(shots)
shot = shots(ishot);
for ireq = 1:numel(request_list)
% populate cell of test parameters
test_params = [test_params;{{machine,shot,request_list{ireq}}}]; %#ok<AGROW>
end
end
end
end
function shot = get_shots(machine)
switch machine
case 'AUG'
shot = 30594;
case 'TCV'
shot = 48836;
otherwise
error('no shot defined for this machine')
end
end
%
% methods(TestClassSetup)
% function getShot(testCase,machine)
% switch machine
% case 'AUG'
% testCase.shot = 30594;
% case 'TCV'
% testCase.shot = 48836;
% end
% end
% end
%
% end
%
% if nverbose>=2 && nverbose ~= 11
% doplot = true;
% else
% doplot = false;
% end
%
% %% get request list
% if isempty(machine)
% [gd0,gp0] = gdat;
% else
% [gd0,gp0] = gdat('machine',machine);
% end
% if isempty(machine)
% machine = gp0.machine;
% end
% request_list = gd0.gdat_request;
%
% %% get default test shot for each machine
%
%
% %% 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
% 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);
% else
% gdat_call{ireq} = sprintf(['gdat_' lower(machine) '(%d,''%s'',''doplot'',%d)'],shot,myrequest,doplot);
% end
%
% % 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
% end
% end
%
% pass = all(~err);
%
%
% 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 = '';
% end
%
% function [err,telaps,gdat_result] = do_gdat_call(gdat_call,nverbose)
% if nverbose >= 11
% fprintf('\n calling %s...\n',gdat_call);
% end
%
% tic
% try
% [gdat_result,~,err] = eval(gdat_call);
% catch ME
% err = -1;
% gdat_result.data = [];
% getReport(ME); %,'extended');
% end
% telaps = toc; % elapsed time
% end
\ No newline at end of file
#!/bin/bash
# testing script for Continuous Integration
# F. Felici federico.felici@epfl.ch
## test type
if [[ -z "$1" ]]
then
echo 'usage:'
echo ' Run matlab tests: '
echo ' ./test_script.sh $matlabversion $test_to_run'
echo ' will call required matlab and run >>test_matlab($test_to_run)'
echo ' $matlabcommand is the command used to launch the correct matlab version'
echo ' works on SPC lac clusters for now'
exit 1
fi
matlabbin=$1
testargument=$2
matlabcmd="$matlabbin -nodesktop -nosplash -noFigureWindows"
matlab_call="tests_matlab('$testargument')"
full_cmd="$matlabcmd -r $matlab_call";
echo $full_cmd
$full_cmd ## execute
CODE=$?
echo "exit with CODE" $CODE
exit $CODE
function tests_matlab(test_case)
% function to call tests from test_script.sh
try
fprintf('\n Running test file: %s\n',mfilename('fullpath'));
fprintf(' Time: %s\n',datestr(now));
passed = run_gdat_tests(test_case); % add a call to your test script here, with optional test_case input
exit_code = int32(~passed); % convert to bash shell convention
catch ME
disp(getReport(ME))
exit_code = 1;
end
exit(exit_code);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment