Hi Shilji,
I understand that you want to automate Simulink Test harness with spreadhseet based vectors. To automate the Simulink Test Harness with a spreadsheet-based test vector in Jenkins, you can follow these steps:
Install Required Plugins in Jenkins
Create a New Job in Jenkins
Source Code Management:
- Select Git and configure your repository URL and credentials.
Additional Behaviors:
- Set up the following pattern to ignore builds if only HTML files have been committed to the SCM :
Build Triggers:
- Since you are using Gerrit, you can set up a webhook in Gerrit to trigger the Jenkins job on code push. You can refer to the following documentation about 'Gerrit Trigger Plugin' : https://plugins.jenkins.io/gerrit-trigger/
Build Step:
- Add a build step to execute a MATLAB script that programatically reads values from spreadsheet and runs the test harness with the following code:
Here, 'runHarness' is a .M file containing code to read data from an .XLSX file, create variables in the base workspace, and run the test harness. The test harness takes values from the base workspace for computation.
Here’s an example MATLAB script for simulating an internal test harness for the ‘Product’ block:
blockPath = [model, '/TestSubsystem'];
blockHandle = getSimulinkBlockHandle([model, '/TestSubsystem']);
table= readtable('Book1.xlsx');
harnessName = 'TestSubsystemHarness';
sltest.harness.open(blockHandle, harnessName);
sltest.harness.close(blockHandle);
actualResults = simOut.yout{1}.Values.Data;
testPassed = isequal(actualResults, Expected);
reportFile = 'TestReport.html';
file=fullfile('Report', reportFile)
fprintf(fid, '<html><body>\n');
fprintf(fid, '<h1>Test Report</h1>\n');
fprintf(fid, '<p>Test passed: Results match </p>\n');
fprintf(fid, '<p>Test failed: Results do not match</p>\n');
fprintf(fid, '<p>%s</p>\n', Expected);
fprintf(fid, '</body></html>\n');
fprintf(fid, '</body></html>\n');
Post-Build Actions:
- You can execute a .BAT or .SH file depending on the OS of the Jenkins environment to push the generated report to the repository.
Here’s an example batch script:
git add Report/TestReport.html
git commit -m "Add Simulink test report"
git push -f origin HEAD:main
Hope this helps!