Main Content

Compare Results from Different Polyspace Runs by Using MATLAB Scripts

This topic shows how to run Polyspace® by using MATLAB® scripts, save each result in a separate folder, and see only new or unreviewed results compared to the last run.

If your project consists of legacy code, it is often beneficial to run a preliminary analysis. In the subsequent runs, you can focus only on results related to newly added code.

Review Only New Results Compared to Last Run

To see only new results, specify that the current run must import results and comments from the results folder of the last run.

This script saves results of each Polyspace run in a separate folder and compares each result set with the result set from the previous run.

  • The first time you run the script, all results are new and stored in the variable newResTable.

  • If you run the script a second time without modifying the files in between, there are no new results. The variable newResTable contains an empty table and an appropriate message is displayed.

    If you modify files in between two runs, the variable newResTable contains only results related to the modifications.

proj = polyspace.Project;

% Specify sources and includes
sourceFile = fullfile(polyspaceroot, 'polyspace', ... 
    'examples', 'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c');
includeFolder = fullfile(polyspaceroot, 'polyspace', ... 
    'examples', 'cxx', 'Bug_Finder_Example', 'sources');

% Create results folder name based on time of analysis
runTime = datetime('now','Format',"d_MMM_y_H'h'_m'm'");
resultsFolder = ['results_', char(runTime)];

% Configure analysis
proj.Configuration.Sources = {sourceFile};
proj.Configuration.TargetCompiler.Compiler = 'gnu4.9';
proj.Configuration.EnvironmentSettings.IncludeFolders = {includeFolder};
proj.Configuration.ResultsDir = fullfile(pwd, resultsFolder);
 
% Set up import from previous results if a previous result folder exists
if isfile('lastResultFolder.mat')
    load('lastResultFolder.mat', 'lastResultsFolder');
    proj.Configuration.ImportComments =  fullfile(pwd, lastResultsFolder);
end
lastResultsFolder = resultsFolder;
save('lastResultFolder.mat', 'lastResultsFolder');

% Run analysis
bfStatus = run(proj, 'bugFinder');

% Read results
resObj = proj.Results;
resTable = getResults(resObj);
matches = (resTable.New == 'yes');
newResTable = resTable(matches ,:);
if isempty(newResTable)
    disp('There are no new results.')
end
The key functions used in this example are:

  • polyspace.Project: Run a Polyspace analysis and read the results to a table.

    • To specify a results folder, use the property Configuration.ResultsDir.

    • To specify a previous results folder to import results from, use the property Configuration.ImportComments.

  • datetime: Read the current time, convert to an appropriate format, and append it to the results folder name.

  • load and save: Load the previous results folder name from a MAT-file lastResultFolder.mat and save the current results folder name to the MAT file for subsequent runs.

Review New Results and Unreviewed Results from Last Run

Instead of focusing on new results only, you can choose to focus on unreviewed results. Unreviewed results include new results and results from the last run that were not assigned a status in the Polyspace user interface.

To focus on unreviewed results, replace this section of the previous script:

% Read results
resObj = proj.Results;
resTable = getResults(resObj);
matches = (resTable.New == 'yes');
newResTable = resTable(matches ,:);
if isempty(newResTable)
    disp('There are no new results.')
end
with this section:
% Read results
resObj = proj.Results;
resTable = getResults(resObj);
matches = (resTable.Status == 'Unreviewed');
unrevResTable = resTable(matches ,:);
if isempty(unrevResTable)
    disp('There are no unreviewed results.')
end

See Also

| | |

Related Topics