Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test execution speed and robustness when rebooting target. #47

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions tests/commonSetupTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ function setupBossdevice(testCase)

testCase.bd = bossdevice;
testCase.bd.targetObject.update;
testCase.waitTargetReady(testCase.bd.targetObject);
% Wait additional seconds since the target may respond ping but not be ready yet
pause(3);

fprintf('Wait 40s for target to reboot after update and set IP address in secondary interface.\n');
pause(40);
% Set Ethernet IP in secondary interface
bossapi.setEthernetInterface(testCase.bd.targetObject,'wm1','192.168.200.255/24');
end
Expand All @@ -33,10 +34,10 @@ function resetSgPath(testCase)
end

function rebootTarget(testCase)
if ~isempty(testCase.bd)
if ~isempty(testCase.bd) && testCase.bd.isConnected
disp('Rebooting bossdevice to teardown test class.');
testCase.bd.targetObject.reboot;
pause(30);
testCase.waitTargetReady(testCase.bd.targetObject);
end
end
end
Expand All @@ -50,4 +51,39 @@ function clearBossdeviceObj(testCase)
end
end

methods (Static, Access = protected)
function pingSuccesful = waitTargetReady(tgObj, numAttempts)
arguments
tgObj slrealtime.Target
numAttempts {mustBePositive,mustBeInteger} = 10
end

i = 1;
while i <= numAttempts
fprintf('Pinging target "%s" at "%s" (%i/%i)...\n',...
tgObj.TargetSettings.name, tgObj.TargetSettings.address, i, numAttempts);

[~, cmdout] = system(['ping ' tgObj.TargetSettings.address]);
pingSuccessful = ~contains(cmdout,"Request timed out.");

if ~pingSuccessful
i = i+1;
% Wait 3s before next ping attempt
pause(3);

else
% Ping successful
fprintf('Ping successful.\n');
pingSuccesful = true;
break;

end
end

assert(pingSuccessful,'Speedgoat target "%s" could not be reached in the IP address "%s".',...
tgObj.TargetSettings.name, tgObj.TargetSettings.address);

end
end

end
2 changes: 1 addition & 1 deletion toolbox/dependencies/+bossapi