-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild_matlab.m
97 lines (82 loc) · 3.72 KB
/
build_matlab.m
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
clc;
clear;
% TO DO
% Move this to some special folder, let's not leave it in root
% isfunction bums out if there are trailing empty lines, check that
% There is a bunch of exceptions in the real CI, yet the process is not
% stopped!
% There are exceptions for "windowstyle docked" because there is no display
% Magnetoshield requires MPT
installMatlabAndSimulink
pkgMATLAB = 0;
pkgSimulink = 0;
supportpkg=matlabshared.supportpkg.getInstalled; % Query for installed support packages
for i=1:length(supportpkg)
pkgMATLAB = pkgMATLAB + strcmp(supportpkg(i).Name,'MATLAB Support Package for Arduino Hardware');
pkgpSimulink = pkgSimulink + strcmp(supportpkg(i).Name,'Simulink Support Package for Arduino Hardware');
end
if ~pkgMATLAB
disp('WARNING! Arduino HW package for MATLAB not found. Open Add-Ons > Get Hardware Support Packages.')
end
if ~pkgSimulink
disp('WARNING! Arduino HW package for Simulink not found. Open Add-Ons > Get Hardware Support Packages.')
end
testFailedCI = 0; % Flag to tell if any test has failed
cd matlab/examples/ % Move to examples folder
exampleList = {'OptoShield','HeatShield','LinkShield','MotoShield','FloatShield','MagnetoShield','BoBShield','TugShield'};
testScripts(exampleList) % Finds and tests all scripts, excludes exceptions caused by lack of hardware packages or physical hardware
if testFailedCI
error('+++++++++++ At least one of the tests failed! +++++++++++ '); % Try-catch will prevent MATALAB from throwing an overall error. This fails the CI process.%end
else
disp('+++++++++++ All tests passed. +++++++++++ ');
end
function testScripts(exampleList)
for i=1:length(exampleList);
cd(exampleList{i})
for i=1:length(listDir())
dirContents=listDir();
file = dirContents(i).name; %Full file name with extension
scr = dirContents(i).name(1:end-2); %Script name to launch
if ~isfunction(file)
try
pause('off')
warning('off')
CI_Testing = 'true'; %Passed to scripts to turn off clearing screen
fprintf(['************************ Testing "',scr])
fprintf(['"...'])
run(scr) % All scripts, sans the file extensions
catch exceptionCI
exceptionCIKnown = {
'MATLAB:serial:fopen:opfailed', % Failed to open serial port
'MATLAB:hwsdk:general:boardNotDetected', % No hardware board
'MATLAB:hwsdk:general:invalidAddressPCMac' % Has HW extension, but no such address
'' % This empty identificator is for the Hardware Support Package
};
knownID = 0; % Assume it is an unknown error
for i=1:length(exceptionCIKnown) % For the length of known exceptions (missing hardware)
knownID = knownID+strcmp(exceptionCI.identifier,exceptionCIKnown{i});
end
if ~knownID
testFailedCI = 1;
failFunctionCI(exceptionCI);
else
fprintf(' WARNING: Not fully tested! ')
end
end
fprintf('************************ PASS.\n')
end
end
cd .. % Switch to next directory
end
end
function failFunctionCI(exceptionCI)
fprintf('************************ FAIL.\n')
exceptionCI
rethrow(exceptionCI) % Only if you want to stop CI instantly on the first
%error.
end
function out = listDir
persistent dirContents
dirContents=dir('**/*.m');
out = dirContents;
end