Skip to content
Snippets Groups Projects
Commit c31984a3 authored by Federico Felici's avatar Federico Felici
Browse files

start adding test suite

parent 5580b78d
No related branches found
No related tags found
No related merge requests found
# Define stages
stages:
- test
# MATLABCMD: Command used to launch correct matlab version for tests, builds..
# TESTCASE: Input into matlab test script to choose which tests to run.
# GIT_SUBMODULE_STRATEGY: Way to handle gitlab submodules - Recurse into all submodules
# BUILD_DIR/TEST_DIR: Target directory for builds/tests
# CLEAN: Set 1 to force cleaning of target directories
variables: # default values
MATLABCMD: "matlab960"
TESTCASE: ""
GIT_STRATEGY: none
GIT_SUBMODULE_STRATEGY: none
CLEAN: 0
TIMEOUT: "2h"
# TESTS
.test-template:
stage: test
tags:
- scd
before_script:
- hostname && date
- echo "Testing with $MATLABCMD, $TESTCASE"
- chmod u+x ./test_script.sh
script:
# Call test script with timeout to kill it
- timeout -s 9 $TIMEOUT ./test_script.sh $MATLABCMD $TESTCASE
interruptible: true
unit-tests:
extends: .test-template
variables:
TESTCASE: "unit"
template-tests:
extends: .test-template
variables:
TESTCASE: "template"
function [passed,results] = run_rtccode_tests(test_case)
% test runner for rtccode
% F. Felici, EPFL federico.felici@epfl.ch
if nargin==0 || isempty(test_case)
test_case = 'algos'; % default
end
test_case = lower(test_case);
%% Import some classes we need
import matlab.unittest.selectors.HasTag;
import matlab.unittest.constraints.ContainsSubstring;
import matlab.unittest.selectors.HasName;
%% initialize paths
rtccode_paths
%% populate suite
switch lower(test_case)
case 'algos'
fprintf('populating test suite with all SCDalgo tests... \n')
suite = testsuite('algos','IncludingSubfolders',true,'superclass','SCDalgo_test');
fprintf('done \n')
case 'unit'
s = HasTag('Unit');
suite = [matlab.unittest.TestSuite.fromFolder('core/tests',s),...
matlab.unittest.TestSuite.fromFolder(fullfile('tbx','tests'),s),...
testsuite(fullfile('core','classes'),'IncludingSubfolders',true)];
case 'expcodes'
s = HasTag('expcodes');
suite = matlab.unittest.TestSuite.fromFolder('core/tests',s);
otherwise
error('unknown test_case %s',test_case)
end
assert(~isempty(suite),'empty test suite');
%% 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;
elseif any([results.Failed])
fprintf('\nSome tests Failed\n')
disp(table(results([results.Failed])))
passed = false;
elseif any([results.Incomplete])
fprintf('\nSome tests Incomplete\n')
disp(table(results([results.Incomplete])));
passed = true; % pass tests even if some were skipped
else
error('something is very wrong - please check')
end
#!/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
source rtccode_env.sh
matlabcmd="$matlabbin -nodisplay"
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_scdds_core_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.
Finish editing this message first!
Please register or to comment