polyspace.test.SanitizerProfilingResults Class
Namespace: polyspace.test
Description
This Python® class contains code sanitizer profiling results obtained from executing C/C++ tests.
Creation
Description
sanitizerResults = profilingResults.Sanitizer loads code sanitizer results:
From a
polyspace.test.ProfilingResultsobjectprofilingResults.To a
polyspace.test.sanitizerProfilingResultsobjectsanitizerResults.
Properties
Number of instrumented expressions that caused errors during test runs. Each expression is instrumented for certain types of errors that can result during execution (for instance, an array access is instrumented for potential out of bounds access). If one of the expected errors happens during the execution of a test, it is counted within FailedCount.
If an expression is instrumented for multiple errors, each instrumentation is counted separately.
Number of instrumented expressions that did not cause errors during test runs. Each expression is instrumented for certain types of errors that can result during execution (for instance, an array access is instrumented for potential out of bounds access). If none of the expected errors happen during the execution of a test, it is counted within PassedCount.
If an expression is instrumented for multiple errors, each instrumentation is counted separately.
Total number of expressions instrumented for possible errors during test execution. If an expression is instrumented for multiple errors, each instrumentation is counted separately.
File-by-file breakdown of code sanitizer results, returned as a list of polyspace.test.SanitizerFile objects with the following properties.
| Property | Description |
|---|---|
FullPath | Full path to a file, returned as a string. |
Path | Filename, returned as a string. |
PassedCount | Number of instrumented expressions in the file that did not cause errors during test execution. |
FailedCount | Number of instrumented expressions in the file that caused errors during test execution. |
TotalCount | Number of instrumented expressions in the file |
Functions | Function-by-function breakdown of code sanitizer results in the file, returned as a list of polyspace.test.SanitizerFunction objects. |
Each polyspace.test.SanitizerFunction object represents the code sanitizer results for a single function and consists of these properties:
| Property | Description |
|---|---|
File | Full path to file containing the function, returned as a string. |
Function | Function signature, returned as a string. |
PassedCount | Number of instrumented expressions in the function that did not cause errors during test execution. |
FailedCount | Number of instrumented expressions in the function that caused errors during test execution. |
TotalCount | Number of instrumented expressions in the function |
Expressions | Expression-by-expression breakdown of code sanitizer results in the function, returned as a list of polyspace.test.SanitizerExpressionDetail objects. |
Each polyspace.test.SanitizerExpressionDetail object represents the code sanitizer results for a single instrumented expression and consists of the following properties. If an expression is instrumented for multiple errors, each instrumentation is counted separately.
| Property | Description |
|---|---|
File | Full path to file containing the expression, returned as a string. |
Function | Signature of function containing the expression, returned as a string. |
IsPassed | Whether the expression was free of the error during test runs (True or False). |
IsFailed | Whether the expressed caused an error during test runs (True or False).. |
Kind | Type of error, returned as a string. |
Predicates | More details of the error, specified as a list of polyspace.test.SanitizerPredicate objects with properties Details (full error message), FailedCount, PassedCount, and TotalCount. |
SourceLocation | Location of the expression in the source code returned as a polyspace.test.SourceLocation object with properties Startline, Endline, StartColumn, and EndColumn |
Text | Text of the expression, returned as a string. |
Methods
Get expressions that were instrumented for sanitizer profiling.
Here, res is a polyspace.test.SanitizerProfilingResults object.
getExpressions | Get expressions instrumented for sanitizer profiling. The returned object contains four properties:
Example:
|
Examples
This example shows how to print the list of expressions that led an to an error when running C/C++ tests.
In general, you generate and manage execution profiling results by using classes from the polyspace.project and polyspace.test modules. Before starting, make sure you can import these modules on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.
Import the required modules:
import polyspace.project import polyspace.test import osAdd source files and xUnit test files to a project, and parse the source code in the project. This example uses some example source and test files available with a Polyspace® Test™ installation.
examples_path = os.path.join(polyspace.__install_path__, "polyspace", "examples", "doc_pstest", "sanitizer_profiling") polyspaceProject = polyspace.project.Project("testProject") polyspaceProject.Code.Folders.add(os.path.join(examples_path, "src")) polyspaceProject.refreshSources() polyspaceProject.ActiveBuildConfiguration.Language="CPP" codeInfo = polyspace.project.parseCode(polyspaceProject)Write three tests for the function
int32_t compute_results(int32_t input). Each test invokes the function with an input that is designed to trigger a specific error.functionComputeResults = codeInfo.getFunctionBySignature( "int32_t compute_results(int32_t input)" ) suiteComputeResults = polyspaceProject.TestSuites.create( "suite_compute_results" ) testPow = suiteComputeResults.TestCases.create("test_pow") testPowStep = testPow.TestSteps.createTabular( "test_pow_step", functionComputeResults ) testPowStep.Inputs["input"].Value = "2" testArrayAccess = suiteComputeResults.TestCases.create("test_array_access") testArrayAccessStep = testArrayAccess.TestSteps.createTabular( "test_array_access_step", functionComputeResults ) testArrayAccessStep.Inputs["input"].Value = "3" testShift = suiteComputeResults.TestCases.create("test_shift") testShiftStep = testShift.TestSteps.createTabular( "test_shift", functionComputeResults ) testShiftStep.Inputs["input"].Value = "4"Run the tests added to the project with code sanitizer profiling enabled.
res = polyspace.test.run( polyspaceProject, ProfilingSelection=polyspace.test.ProfilingSelection.SANITIZER )Read the code sanitizer profiling results from the test results.
profilingResults = res.Profiling sanitizerResults = profilingResults.SanitizerLoop through the details of the sanitizer profiling results and print the expressions that led to an error.
You should see an output such as the following:for f in sanitizerResults.Files: for func in f.Functions: for expr in func.Expressions: if expr.IsFailed: # expression caused an error line = expr.SourceLocation.StartLine kind = expr.Kind expr_text = expr.Text.strip() # Print each failing predicate's full message for pred in expr.Predicates: if pred.FailedCount > 0: print( f"{f.FullPath}:{line} " f"[{kind}] {pred.Details} :: Expression with issue: '{expr_text}'" )example.cpp:7 [UINT_CONV_OVFL] Conversion from unsigned int to unsigned int must not overflow :: Expression with issue: '<' example.cpp:12 [OUT_BOUND_ARRAY] Array index i must be within bounds (Array size: 33) :: Expression with issue: 'gsX3.a[i][0]' example.cpp:21 [FLOAT_STD_LIB] Function must not return Not-a-Number and not cause floating exception :: Expression with issue: '(*funcPtr)(x, y)' example.cpp:21 [FLOAT_STD_LIB] Function must not return Infinity :: Expression with issue: '(*funcPtr)(x, y)'
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)