Main Content

padv.builtin.task.RunCodeInspection Class

Namespace: padv.builtin.task
Superclasses: padv.Task

Task for inspecting generated model code using Simulink Code Inspector

Description

This class requires CI/CD Automation for Simulink Check.

The padv.builtin.task.RunCodeInspection class provides a task that can detect unintended functionality in your models by establishing model-to-code and code-to-model traceability using Simulink® Code Inspector™. The results of this task can help you to satisfy code-review objectives in DO-178 and other high-integrity standards.

You can add the task to your process model by using the method addTask. After you add the task to your process model, you can run the task from the Process Advisor app or by using the function runprocess.

To view the source code for this built-in task, in the MATLAB® Command Window, enter:

open padv.builtin.task.RunCodeInspection

The padv.builtin.task.RunCodeInspection class is a handle class.

Note

This task is not supported on macOS.

Creation

Description

task = padv.builtin.task.RunCodeInspection() creates a task for detecting unintended functionality in models using Simulink Code Inspector.

example

task = padv.builtin.task.RunCodeInspection(Name=Value) sets certain properties using one or more name-value arguments. For example, task = padv.builtin.task.RunCodeInspection(Name = "MyCodeInspectionTask") creates a task with the specified name.

You can use this syntax to set property values for IsTopModel, ReportFolder, Name, Title, IterationQuery, InputDependencyQuery, InputQueries, LaunchToolAction, and LaunchToolText.

The padv.builtin.task.RunCodeInspection class also has other properties, but you cannot set those properties during task creation.

Properties

expand all

The RunCodeInspection class inherits properties from padv.Task. The properties listed in Specialized Inherited Properties are padv.Task properties that the RunCodeInspection task overrides.

The task also has properties for specifying Code Inspection Options for creating a code inspection object slci.Configuration (Simulink Code Inspector).

Specialized Inherited Properties

Unique identifier for task in process, specified as a string.

Example: "MyCodeInspectionTask"

Data Types: string

Human-readable name that appears in Process Advisor app, specified as a string.

Example: "My Code Inspection Task"

Data Types: string

Task description, specified as a string.

When you point to a task in Process Advisor and click the information icon, the tooltip shows the task description.

Example: "This task uses Simulink Code Inspector to detect unintended functionality in your models by establishing model-to-code and code-to-model traceability."

Data Types: string

Path to task documentation, specified as a string.

When you point to a task in Process Advisor, click the ellipsis (...), and click Help, Process Advisor opens the task documentation.

Example: fullfile(pwd,"taskHelpFiles","myTaskDocumentation.pdf")

Data Types: string

Type of artifact, specified as one or more of the values listed in this table. To specify multiple values, use an array.

CategoryArtifact TypeDescription

MATLAB

"m_class"MATLAB class
"m_file"MATLAB file
"m_func"MATLAB function
"m_method"MATLAB class method
"m_property"MATLAB class property

Model Advisor

"ma_config_file"Model Advisor configuration file
"ma_justification_file"Model Advisor justification file

Other

"coder_code_files"Code files
"other_file"Other file

Process Advisor

"padv_dep_artifacts"

Related artifacts that current artifact depends on

"padv_output_file"

Process Advisor output file

Project

"project"Current project file

Requirements

"mwreq_item"Requirement (since R2024b)

"sl_req"

Requirement (for R2024a and earlier)
"sl_req_file"Requirement file
"sl_req_table"Requirements Table

Stateflow®

"sf_chart"Stateflow chart
"sf_graphical_fcn"Stateflow graphical function
"sf_group"Stateflow group
"sf_state"Stateflow state
"sf_state_transition_chart"Stateflow state transition chart
"sf_truth_table"Stateflow truth table

Simulink

"sl_block_diagram"Block diagram
"sl_data_dictionary_file"Data dictionary file
"sl_embedded_matlab_fcn"MATLAB function
"sl_block_diagram"Block diagram
"sl_library_file"Library file
"sl_model_file"Simulink model file
"sl_protected_model_file"Protected Simulink model file
"sl_subsystem"Subsystem
"sl_subsystem_file"Subsystem file
"sl_subsystem"Subsystem

System Composer™

"zc_block_diagram"System Composer architecture
"zc_component"System Composer architecture component
"zc_file"System Composer architecture file
Tests"harness_info_file"Harness info file
"sl_harness_block_diagram"Harness block diagram
"sl_harness_file"Test harness file
"sl_test_case"Simulink Test™ case
"sl_test_case_result"Simulink Test case result
"sl_test_file"Simulink Test file
"sl_test_iteration"Simulink Test iteration
"sl_test_iteration_result"Simulink Test iteration result
"sl_test_report_file"Simulink Test result report
"sl_test_result_file"Simulink Test result file
"sl_test_resultset"Simulink Test result set
"sl_test_seq"Test Sequence
"sl_test_suite"Simulink Test suite
"sl_test_suite_result"Simulink Test suite result

Example: "sl_model_file"

Example: ["sl_model_file "zc_file"]

Query that finds the artifacts that the task iterates over, specified as a padv.Query object or the name of a padv.Query object. When you specify IterationQuery, the task runs one time for each artifact returned by the query. In the Process Advisor app, the artifacts returned by IterationQuery appear under task title.

For more information about task iterations, see Overview of Process Model.

Example: padv.builtin.query.FindProjectFile

Query that finds artifact dependencies for task inputs, specified as a padv.Query object or the name of a padv.Query object.

The build system runs the query specified by InputDependencyQuery to find the dependencies for the task inputs, since those dependencies can impact if task results are up-to-date.

For more information about task inputs, see Overview of Process Model.

Example: padv.builtin.query.GetDependentArtifacts

List of licenses that the task requires, specified as a string.

Data Types: string

Function that launches a tool, specified as the function handle.

When you point to a task in the Process Advisor app, you can click the ellipsis (...) to see more options. For built-in tasks, you have the option to launch a tool associated with the task.

For the task RunCodeInspection, you can launch the Code Inspector app.

Data Types: function_handle

Description of the action that the LaunchToolAction property performs, specified as a string.

Data Types: string

Inputs to the task, specified as:

  • a padv.Query object

  • the name of padv.Query object

  • an array of padv.Query objects

  • an array of names of padv.Query objects

By default, the task RunCodeInspection gets the model and generated code inputs by using the built-in queries:

  • padv.builtin.query.GetIterationArtifact

  • padv.builtin.query.GetOutputsOfDependentTask on the task padv.builtin.task.GenerateCode

Location for standard task outputs, specified as a string.

The built-in tasks use tokens, like $DEFAULTOUTPUTDIR$, as placeholders for dynamic path resolution during run-time. For more information, see Dynamically Resolve Paths with Tokens.

Data Types: string

Code Inspection Options

Setting for specifying if current model is top model, specified as an empty logical array [] or as a numeric or logical 0 (false) or 1 (true).

By default, the task automatically identifies whether a model is a top model or a reference model. But you can specify IsTopModel as true or false if you want to override that behavior and only generate top model code or reference model code.

Example: true

Data Types: logical

Path to generated report, specified as a string.

The task uses this property to specify the report folder for code inspection.

The built-in tasks use tokens, like $DEFAULTOUTPUTDIR$, as placeholders for dynamic path resolution during run-time. For more information, see Dynamically Resolve Paths with Tokens.

Data Types: string

Methods

expand all

Examples

collapse all

Add a task that can detect unintended functionality in your models by establishing model-to-code and code-to-model traceability using Simulink Code Inspector.

Open the process model for your project. If you do not have a process model, open the Process Advisor app to automatically create a process model.

In the process model file, add the RunCodeInspection task to your process model by using the addTask method. By default, the RunCodeInspection task automatically identifies whether a model is a top model or a reference model.

slciTask = pm.addTask(padv.builtin.task.RunCodeInspection);

You can reconfigure the task behavior by using the task properties. For example, to specify a different location for the code inspection report:

slciTask.ReportFolder = fullfile("reports","code_inspection");

The RunCodeInspection task requires outputs from the GenerateCode task. Specify this dependency in your process model by using the dependsOn method.

To make sure that you run your tasks using the built-in task GenerateCode before you add the task, you can use conditional logic in your process model. For example:

includeGenerateCodeTask = true;
includeCodeInspection = true;

%% Generate Code
% Tools required: Embedded Coder
% By default, generating code for each model in the project
if includeGenerateCodeTask
    codegenTask = pm.addTask(padv.builtin.task.GenerateCode);
    % ... Optionally specify task property values
end

%% Inspect Code
% Tools required: Simulink Code Inspector
if includeGenerateCodeTask && includeCodeInspection
    slciTask = pm.addTask(padv.builtin.task.RunCodeInspection(IterationQuery=findModels));
    % ... Optionally specify task property values
end

%% Set Task Dependencies
if includeGenerateCodeTask && includeCodeInspection
    slciTask.dependsOn(codegenTask);
end