Contenuto principale

polyspace.test.BoundaryTestOptions Class

R2026b

Namespace: polyspace.test

(Python) Configure automatic boundary-value test generation

Since R2026b

Description

This Python® class configures automatic generation of boundary-value test cases (for example, minimum, maximum, and zero values) when you generate tests for C/C++ code in a Polyspace® Platform project. Use this object to choose the boundary strategy (minimal or exhaustive), include near-boundary neighbors, include zero where valid, and set a bound on the number of generated tests.

Creation

Description

opts = polyspace.test.BoundaryTestOptions() creates a boundary test-generation options object opts with default property values.

example

Properties

expand all

How boundary values are combined across inputs, specified as an enumeration member of the polyspace.test.BoundaryTestingMode class.

ValueDescription
BoundaryTestingMode.MINIMAL

Generate the fewest tests that still exercise boundary values (such as minimum, maximum or zero) for each parameter.

BoundaryTestingMode.EXHAUSTIVE

Generate combinations that exercise all boundary values across multiple inputs to expose boundary interactions.

To set this property, use either of these syntaxes:

opts.Mode = polyspace.test.BoundaryTestingMode.MINIMAL
opts.Mode = "minimal"

When True, include values adjacent to integer boundaries (for example, min+1 and max-1) in addition to exact minimum and maximum values. This inclusion is useful for catching off‑by‑one or boundary shift defects.

When True, include 0 for parameters whose valid domain includes zero (for example, signed integers and floating‑point types). The zero is considered to be a boundary value, in addition to the minimum and maximum values, where applicable.

When True, include very small non‑zero floating‑point values near zero (implementation‑dependent) to exercise underflow or denormal behavior in algorithms that are sensitive to magnitude.

Set a hard cap on the number of tests the generator can produce for the requested function or script. Use this property to avoid combinatorial growth, especially with the EXHAUSTIVE mode. If the test generator determines that the number of tests that would be generated exceeds MaxNumberOfTests, it produces an error.

Examples

collapse all

Create boundary settings and generate a small suite that exercises boundaries with minimal combinations. Include both zero parameter values and off-by-one values in the generated tests.

Create the project, add your source files, and parse the code. Then create options and generate tests for the saturate_value function.

## Import modules
import polyspace.project
import polyspace.test
import os

## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace", 
                            "examples", "doc_pstest", "getting_started_test_manager")

proj = polyspace.project.Project("myProject.psprjx")

## Add source files and include path
proj.Code.Files.add(os.path.join(examples_path, "algo.c"))
proj.Code.Files.add(os.path.join(examples_path, "saturate.c"))
proj.IncludePaths.add(os.path.join(examples_path))

## Parse code - returned object contains list of functions and other source code data
codeInfo = polyspace.project.parseCode(proj)

## Get function
func = codeInfo.getFunctionBySignature("int saturate_value(int)")

## Set global test generation options
bOpts = polyspace.test.BoundaryTestOptions()
bOpts.Mode = polyspace.test.BoundaryTestingMode.MINIMAL
bOpts.IncludeOffByOneValues = True
bOpts.IncludeZeroParameterValues = True

## Set function-specific test generation options
cfg = polyspace.test.FunctionTestGenerationConfiguration(func)

## Generate tests
testGenResults = polyspace.test.generateTests(proj, cfg, bOpts)

Version History

Introduced in R2026b