Main Content

getSummary

View number of Polyspace results organized by results type (Bug Finder) or color and file (Code Prover)

To summarise coding rule violations, use 'codingStandards' as the resultsType. (since R2024b) For information, see Version History.

Description

resSummary = getSummary(resObj, resultsType) returns the distribution of results of type resultsType in a Polyspace® results set, resObj. The results set resObj can be a Bug Finder results set denoted by a polyspace.BugFinderResults object or a Code Prover results set denoted by a polyspace.CodeProverResults (Polyspace Code Prover) object.

For instance:

  • If you choose to see Bug Finder defects, you can see how many defects of each type are present in the result set, for instance, how many non-initialized variables or declaration mismatches.

  • If you choose to see Code Prover run-time checks, you see how many red, orange, gray and green checks are present in each file.

  • If you choose to see coding standard violation, you see violation of supported coding standards.

example

Examples

collapse all

This example shows how to read Bug Finder analysis results from MATLAB®.

Copy a demo result set to a temporary folder.

resPath=fullfile(polyspaceroot,'polyspace','examples','cxx','Bug_Finder_Example', ...
'Module_1','BF_Result');
userResPath = tempname;
copyfile(resPath,userResPath);

Create the results object.

resObj = polyspace.BugFinderResults(userResPath);

Read results to MATLAB tables using the object.

resSummary = getSummary(resObj, 'defects');
resTable = getResults(resObj);

Check for violations of supported coding standards in the demo file numerical.c. Configure these options:

  • Specify GCC 4.9 as your compiler.

  • Save the results in a results subfolder of the current working folder.

proj = polyspace.Project

% Configure analysis
proj.Configuration.Sources = {fullfile(polyspaceroot, 'polyspace', ... 
    'examples', 'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c')};
proj.Configuration.TargetCompiler.Compiler = 'gnu4.9';
proj.Configuration.ResultsDir = fullfile(pwd,'results');

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

% Read results
resObj = proj.Results;
bfSummary = getSummary(resObj, 'defects');

Run a Polyspace Bug Finder™ analysis on the demo file numerical.c.

Copy the file numerical.c into a temporary location.

proj = polyspace.Project;

% Configure analysis
proj.Configuration.Sources = {fullfile(polyspaceroot, 'polyspace', ... 
    'examples', 'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c')};

Specify GCC 4.9 as the compiler and save results in the subfolder results.

proj.Configuration.TargetCompiler.Compiler = 'gnu4.9';
proj.Configuration.ResultsDir = fullfile(pwd,'results');

Optionally, Disable Bug Finder defects.

proj.Configuration.BugFinderAnalysis.EnableCheckers = 0;

Enable MISRA C™:2023 and CERT® C coding standards.

% Configure coding standards
proj.Configuration.CodingRulesCodeMetrics.EnableMisraC2023 = true;
proj.Configuration.CodingRulesCodeMetrics.MisraC2023 = 'all';
proj.Configuration.CodingRulesCodeMetrics.EnableCertC = true;
proj.Configuration.CodingRulesCodeMetrics.CertC = 'all';

Run the analysis read results.

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

% Read results
resObj = proj.Results;

Summarize coding standard violations.

bfSummary = getSummary(resObj, 'codingStandard');

The object bfSummary is two-element cell array. One of the elements is a table containing the MISRA C:2023 violations, and the other is a table containing CERT C violations.

This example shows how to read Code Prover analysis results from MATLAB.

Copy a demo result set to a temporary folder.

resPath = fullfile(polyspaceroot,'polyspace','examples','cxx','Code_Prover_Example', ...
'Module_1','CP_Result');
userResPath = tempname;
copyfile(resPath,userResPath);

Create the results object.

resObj = polyspace.CodeProverResults(userResPath);

Read results to MATLAB tables using the object.

resSummary = getSummary(resObj, 'runtime');
resTable = getResults(resObj);

Run a Polyspace Code Prover™ analysis on the demo file single_file_analysis.c. Configure these options:

  • Specify GCC 4.9 as your compiler.

  • Save the results in a results subfolder of the current working folder.

  • Specify that a main function must be generated, if it does not exist in the source code.

proj = polyspace.Project

% Configure analysis
proj.Configuration.Sources = {fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Code_Prover_Example', 'sources', 'single_file_analysis.c')};
proj.Configuration.TargetCompiler.Compiler = 'gnu4.9';
proj.Configuration.ResultsDir = fullfile(pwd,'results');
proj.Configuration.CodeProverVerification.MainGenerator = true;


% Run analysis
cpStatus = run(proj, 'codeProver');

% Read results
resObj = proj.Results;
cpSummary = getResults(resObj, 'readable');

Input Arguments

collapse all

Bug Finder or Code Prover results set, specified as a polyspace.BugFinderResults or polyspace.CodeProverResults (Polyspace Code Prover) object respectively.

Type of result, specified as a character vector. The default for a Bug Finder results set is 'defects' and the default for a Code Prover results set is 'runtime'.

EntryMeaning
'defects'Bug Finder defects
'runtime'Code Prover checks for run-time errors
'metrics'Code complexity metrics
'codingStandards'All coding standards. For a list of supported coding standards, see Coding Standards.
'misraC'MISRA C:2004 rules
'misraCAGC'MISRA C:2004 rules for generated code
'misraCPP'MISRA™ C++ rules
'misraC2012'MISRA C:2012 rules
'jsf'JSF® C++ rules
'certC'CERT C rules
'certCpp'CERT C++ rules
'iso17961'ISO®/IEC TS 17961 rules
'autosarCPP14'AUTOSAR C++ 14 rules
'metrics'Code complexity metrics
'customRules'Custom rules enforcing naming conventions for identifiers
'guidelines'Polyspace Guidelines checkers

Output Arguments

collapse all

Distribution of results, specified as a table. For instance:

  • If you choose to see a summary of Bug Finder defects, an extract of the table looks like this:

    CategoryDefectImpactTotal
    ConcurrencyData raceHigh2
    ConcurrencyDeadlockHigh 1
    Data flowNon-initialized variableHigh 2

    The table above shows that the result set contains two data races, one deadlock and two non-initialized variables.

  • If you choose to see a summary of Code Prover run-time checks, an extract of the table looks like this:

    FileProvenGreenRedGrayOrange
    file1.c92.0%87328
    file2.c97.7%41011

    The table above shows that file1.c has:

    • 3 red, 2 gray and 8 orange checks.

    • 92% of operations proven.

      In other words, of every 100 operations that the verification checked, 92 operations were proven green, red or gray. See Code Prover Result and Source Code Colors (Polyspace Code Prover).

  • If you choose to see a summary of coding standard violations, resSummary is an array of table, where each table represents the results of one coding standard. Each table in the array shows the number and description of a violated rule.

For more information on MATLAB tables, see Tables.

Version History

Introduced in R2017a

expand all