How to track progress with programmatically run Test Manager (sltest.te​stmanager.​run)?

8 visualizzazioni (ultimi 30 giorni)
Hello,
Simulink Test Manager is very handy and allows to track the progress in its window (sltestmgr).
But I could not find how to track its execution programmatically after running command sltest.testmanager.run.
I tried using timers but they seem to not be able to disrupt the command, as if it was atomic. I assume that this is one of limitations mentioned here: https://www.mathworks.com/help/matlab/ref/timer.html
The only callbacks that affect Command Window (e.x. disp() ) are Setup Callbacks but due to the Test Execution Order they are useless in that case.
Such progress tracking is much needed especially when using long or many test cases.

Risposte (1)

Samay Sagar
Samay Sagar il 24 Mag 2024
Although the built-in sltest.testmanager.run command does not provide a direct way to monitor progress in real-time, a workaround can be employed to achieve progress tracking by leveraging a combination of callbacks, event listeners, and custom logging mechanisms. Here is a structured approach to accomplish this:
1. Set Up Custom Logging in Test Scripts: Modify test cases to include custom logging statements at critical points. This can help to track progress manually through log files or variables.
disp('Starting test case 1');
% Your test code here
disp('Completed test case 1');
2. Use Event Listeners: Create event listeners to capture events during the test execution. These listeners can log the progress to a file or variable that can be monitored.
function setupListeners()
% Create a listener for test case start
tcListenerStart = addlistener(sltest.testmanager.TestCaseEventData, ...
'TestCaseStarted', @(src, event) logProgress(event, 'started'));
% Create a listener for test case completion
tcListenerEnd = addlistener(sltest.testmanager.TestCaseEventData, ...
'TestCaseCompleted', @(src, event) logProgress(event, 'completed'));
end
function logProgress(event, status)
message = sprintf('Test Case %s %s', event.TestCase.Name, status);
disp(message);
logProgressToFile(message);
end
function logProgressToFile(message)
fid = fopen('test_progress.log', 'a');
fprintf(fid, '%s: %s\n', datestr(now, 'HH:MM:SS'), message);
fclose(fid);
end
3. Polling Mechanism: Implement a polling mechanism that periodically checks the status of the test execution. Although this might not provide real-time updates, it can give a near-real-time view of the progress.
function monitorProgress()
while true
pause(10); % Adjust the polling interval as needed
checkProgress();
end
end
function checkProgress()
% Replace this with actual logic to check the test manager's status
% For example, read a log file or check a global variable
fid = fopen('test_progress.log', 'r');
if fid == -1
disp('Log file not found');
return;
end
logContents = fread(fid, '*char')';
fclose(fid);
disp(logContents);
end
For more information about “addlistener”,fopen” and “fclose”, refer the following documentation:

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by