Contenido principal

polyspace.project.Function Class

R2026b

Namespace: polyspace.project

(Python) Store information about a function in parsed source code

Since R2025a

Description

This Python® class contains information about a function in your source code. A polyspace.project.Function object stores the function name, signature, and support information for stubbing, mocking, testing, and test generation.

You obtain polyspace.project.Function objects from the Functions property of a polyspace.project.CodeInfo object, or by using the getFunctionBySignature method.

Creation

Description

funcList = codeInfo.Functions returns a list of polyspace.project.Function objects for all the functions in the parsed source code. Here, codeInfo is a polyspace.project.CodeInfo object.

example

func = codeInfo.getFunctionBySignature(signature) returns the polyspace.project.Function object for the function with the specified signature. You can specify the signature either with or without the argument names. All names and types that you use in this signature must be qualified with namespaces.

Input Arguments

expand all

Signature of the function, specified as a string. You can specify the signature either with or without the argument names.

Examples:

  • "int saturate_value(int)"

  • "int saturate_value(int value)"

Properties

expand all

Name of the function, returned as a string.

Example: "saturate_value"

Signature of the function, returned as a string.

Example: "int saturate_value(int)"

Whether the function has a stub in an external stub file, returned as True or False.

This property is set to True only if a function stub is sourced from an external C/C++ file. It is set to False if the function is stubbed with a project-specific polyspace.project.FunctionStub object.

Whether the function is undefined and requires a stub, returned as a polyspace.project.SymbolSupport object. The object consists of these properties.

PropertyDescription
SupportedBoolean value that evaluates to True if the function requires a stub, and False otherwise
DiagnosticList of strings with reasons why a function might not require or not be supported for stubbing. If there is more than one string, the later strings act as further elaborations of the former strings.

If the object itself is used in a boolean context, its value translates to the value of the Supported property.

Whether the function is supported for mocking, returned as a polyspace.project.SymbolSupport object. The object consists of these properties.

PropertyDescription
SupportedBoolean value that evaluates to True if the function is supported for mocking, and False otherwise
DiagnosticList of strings with reasons why a function might not be supported for mocking. If there is more than one string, the later strings act as further elaborations of the former strings.

If the object itself is used in a boolean context, its value translates to the value of the Supported property.

Whether the function is supported for graphical test authoring, returned as a polyspace.project.SymbolSupport object. The object consists of these properties.

PropertyDescription
SupportedBoolean value that evaluates to True if the function is supported for graphical test authoring, and False otherwise
DiagnosticList of strings with reasons why a function might not be supported for graphical test authoring. If there is more than one string, the later strings act as further elaborations of the former strings.

If the object itself is used in a boolean context, its value translates to the value of the Supported property.

If a function is not supported for graphical test authoring, you can test the function using a scripted test step. For more information, see polyspace.project.ScriptedTestStep.

Whether the function is supported for automatic test generation, returned as a polyspace.project.SymbolSupport object. The object consists of these properties.

PropertyDescription
SupportedBoolean value that evaluates to True if the function is supported for automatic test generation, and False otherwise
DiagnosticList of strings with reasons why a function might not be supported for automatic test generation. If there is more than one string, the later strings act as further elaborations of the former strings.

If the object itself is used in a boolean context, its value translates to the value of the Supported property.

Examples

collapse all

Print names of functions not supported for graphical test authoring along with the reason.

Import the required modules, create a project, and add the source files.

## Import modules
import polyspace.project
import os

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

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

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

Parse the code to get information about the source code in the project.

codeInfo = polyspace.project.parseCode(proj)

Iterate over the functions in the parsed source code. For each function that is not supported for graphical test authoring, print the function name and the diagnostic reasons.

for f in codeInfo.Functions:
    if not f.TestingSupport:
        print(f"Unsupported Function: {f.Name}")
        for i, reason in enumerate(f.TestingSupport.Diagnostic):
            if i == 0:
                print(f"  Reason: {reason}")
            else:
                print(f"  └─ {reason}")

You see the following output:

Unsupported Function: Watchdog_Process
  Reason: Function parameter 1 (wd) contains an unsupported type.
  └─ WatchdogCtrl_t: Type definition is not accessible.

Version History

Introduced in R2025a

expand all