Main Content

sldvruncgvtest

Invoke Code Generation Verification (CGV) API and execute model

Description

cgvObject = sldvruncgvtest(model, dataFile) invokes the Code Generation Verification (CGV) API methods and executes the model by using all the test cases in dataFile. cgvObject is a cgv.CGV object that sldvruncgvtest creates during the execution of the model. sldvruncgvtest sets the execution mode for cgvObject to'sim' by default.

cgvObject = sldvruncgvtest(model, dataFile, runOpts) invokes CGV API methods and executes the model by using the test cases in dataFile. runOpts defines the options for executing the test cases. The settings in runOpts determine the configuration of cgvObject.

example

Examples

collapse all

Create the default configuration object for sldvruncgvtest and execute the specified test cases on the generated code for the model.

Open the example model sldemo_mdlref_basic. Log the input signals to the Counter A Model block.

openExample('sldemo_mdlref_basic');
open_system('sldemo_mdlref_basic');
load_system('sldemo_mdlref_counter');
loggedData = sldvlogsignals('sldemo_mdlref_basic/CounterA');

Create the default configuration object for sldvruncgvtest and allow the model to be configured to execute test cases with the CGV API.

runOpts = sldvruntestopts('cgv');
runOpts.allowCopyModel = true;

To invoke the CGV API and execute the specified test cases on the generated code for the model, use the logged signals, execute sldvruncgvtest—first in the simulation mode, and then in software-in-the-loop (SIL) mode.

cgvObjectSim = sldvruncgvtest('sldemo_mdlref_counter', loggedData, runOpts);
runOpts.cgvConn = 'sil';
cgvObjectSil = sldvruncgvtest('sldemo_mdlref_counter', loggedData, runOpts);

Use the CGV API to compare the results of the first test case.

simout = cgvObjectSim.getOutputData(1);
silout = cgvObjectSil.getOutputData(1);
[matchNames, ~, mismatchNames, ~ ] = cgv.CGV.compare(simout, silout);
fprintf('\nTest Case:  %d Signals match, %d Signals mismatch', ...
        length(matchNames), length(mismatchNames));

Input Arguments

collapse all

Name or handle of the Simulink® model to execute.

Name of the data file or a structure that contains the input data. You can generate the data by either of these methods:

  • Analyzing the model by using the Simulink Design Verifier™ software.

  • Using the sldvlogsignals function.

A structure whose fields specify the configuration of sldvruncgvtest.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Description','My new description.'

Test case index array to execute from dataFile. If testIdx is [], sldvruncgvtest executes all test cases in dataFile.

Default: []

If you have not configured the model, specifies to create and configure the model to execute test cases with the CGV API.

If true and you have not configured model to execute test cases with the CGV API, sldvruncgvtest copies the model, fixes the configuration, and executes the test cases on the copied model.

If false (the default), an error occurs if the tests cannot execute with the CGV API.

Note

If you have not configured the top-level model or any referenced models to execute test cases, sldvruncgvtest does not copy the model, even if allowCopyModel is true. An error occurs.

Defines the software-in-the-loop (SIL) or processor-in-the-loop (PIL) approach for CGV:

  • 'topmodel' (default)

  • 'modelblock'

Specifies mode of execution for CGV:

  • 'sim' (default)

  • 'sil'

  • 'pil'

Note

runOpts = sldvruntestopts('cgv') returns a runOpts structure with the default values for each field.

Output Arguments

collapse all

cgv.CGV (Embedded Coder) object that sldvruncgvtest creates during the execution of model.

sldvruncgvtest saves the following data for each test case executed in an array of Simulink.SimulationOutput objects inside cgvObject.

Field

Description

tout_sldvruncgvtest

Simulation time

xout_sldvruncgvtest

State data

yout_sldvruncgvtest

Output signal data

logsout_sldvruncgvtest

Signal logging data for:

  • Signals connected to outports

  • Signals that are configured for logging on the model

Tips

To run sldvruncgvtest, you must have Embedded Coder®.

If your model has parameters that are not configured for executing test cases with the CGV API, sldvruncgvtest reports warnings about the invalid parameters. If you see these warnings, do one of the following:

  • Modify the invalid parameters and rerun sldvruncgvtest.

  • Set allowCopyModel in runOpts to be true and rerun sldvruncgvtest. sldvruncgvtest makes a copy of your model with the same configuration and invokes the CGV API.

Version History

Introduced in R2010b