polyspace.test.ScriptedTestGenerationConfiguration Class
R2026bNamespace: polyspace.test
Description
Use this Python® class to configure automatic test generation for scripts that call one or more
C/C++ functions in a Polyspace® Platform project. Provide optional preamble, setup, and teardown code; supply a
test script body; and manage test generation inputs using the Inputs
property.
Creation
Description
scriptConfig = polyspace.test.ScriptedTestGenerationConfiguration()
creates a configuration object for script-based test generation with default
settings.
Properties
Collection of inputs used during test generation, specified as a
polyspace.test.ScriptedTestGenerationInputList object. Each
individual input contained in this list is an instance of the
polyspace.test.TestGenerationInput class that contains these properties:
Name— Name of the input, specified as a string. This property is read-only.Scope— Scope of the input, specified as a string. This property is read-only.Type— Type of the input, specified as a string. This property is read-only.Value— Fixed value of the input in generated tests, specified as a string. By default, the input values are initialized to"".Min— Minimum value of the input in generated tests, specified as a string. By default, the minimum values are initialized to"".Max— Maximum value of the input in generated tests, specified as a string. By default, the maximum values are initialized to"".
Note
You can only assign strings to the Value,
Max, or Min property of an input object.
Therefore, put quotes around the values you assign. For example:
To specify the integer
42, assign the string"42"to theValueproperty.To specify the double
3.14, assign the string"3.14"to theValueproperty.To specify the string
"My String", assign the string'"My String"'to theValueproperty.
When generating code for your tests, Polyspace Test™ uses the content of the string to reconstruct the constraints on the function input.
This table summarizes the various ways you can modify a script input list object
scriptConfig.Inputs, where scriptConfig is a
polyspace.test.ScriptedTestGenerationConfiguration object.
| Action | Command |
|---|---|
| Access individual inputs |
|
| Add constraints | To apply constraints on the value of an input in the generated tests,
set the |
| Add new input for a primitive type | Suppose that |
| Delete an input |
|
| Delete all inputs | To delete all inputs, use the |
Optional C/C++ code compiled into the generated test harness prior to executing tests, specified as a string.
For example, you can use this property to specify include statements or helper declarations:
scriptConfig.Preamble = '#include "decls.h"'Optional C/C++ code executed before each generated test. For example, you can use this property to specify code that performs initialization of a global state.
Optional C/C++ code executed after each generated test. For example, you can use this property to specify code that performs cleanup actions after each test is executed.
C/C++ code that forms the body of the scripted test. For example, use this property to specify code that exercises functions that you want to test.
Examples
Generate script-based tests to achieve a coverage objective while constraining the values of the function inputs.
Create the project, add your source files, and parse the code. Then, specify
coverage objectives for test generation. Next, specify test script body that exercises
the checkAgainstSpeedLimit function. Next, specify preamble, script
inputs, and constraints. Finally, generate tests that achieve the coverage
objectives.
## Import modules
import polyspace.project
import polyspace.test
import os
## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace",
"examples", "doc_pstest", "coverage_tests")
proj = polyspace.project.Project("myProject.psprjx")
## Add source file and include path
proj.Code.Files.add(os.path.join(examples_path, "src","helpers.c"))
proj.IncludePaths.add(os.path.join(examples_path, "src"))
## Parse code - returned object contains list of functions and other source code data
codeInfo = polyspace.project.parseCode(proj)
## Get function
func = codeInfo.getFunctionBySignature("bool checkAgainstSpeedLimit(uint32_t, uint32_t)")
## Set coverage objective to DECISION for test generation
cOpts = polyspace.test.CoverageTestOptions()
cOpts.Level = polyspace.project.CoverageMetricLevel.DECISION
## Specify preamble and test script
## Add inputs and set constraints
cfg = polyspace.test.ScriptedTestGenerationConfiguration()
cfg.Preamble = '#include "decls.h"'
cfg.TestScriptBody = 'bool res = checkAgainstSpeedLimit(speed, limit);'
cfg.Inputs.create("speed",codeInfo.getType("unsigned int"))
cfg.Inputs["speed"].Min = "20u"
cfg.Inputs["speed"].Max = "250u"
cfg.Inputs.create("limit",codeInfo.getType("unsigned int"))
cfg.Inputs["limit"].Value = "70u"
# Generate tests
testGenResults = polyspace.test.generateTests(proj, cfg, cOpts)Version History
Introduced in R2026b
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)