Documentation

slvnvruncgvtest

Invoke Code Generation Verification (CGV) API and execute model

Syntax

cgvObject = slvnvruncgvtest(model, dataFile)
cgvObject = slvnvruncgvtest(model, dataFile, runOpts)

Description

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

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

Input Arguments

collapse all

Name of the Simulink® model that you execute.

Name of the data file or a structure that contains the input data. Generate data by either:

  • Using the Simulink Design Verifier™ software to analyze the model.

  • Using the slvnvlogsignals function.

The fields of runOpts specify the configuration of slvnvruncgvtest .

Field NameDescription
testIdx

Test case index array to simulate from dataFile.

If testIdx = [] (the default), slvnvruncgvtest simulates all test cases.

allowCopyModel

If you have not configured your model to execute test cases with the CGV API, this field specifies creating and configuring the model.

If true and you have not configured your model to execute test cases with the CGV API, slvnvruncgvtest 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, slvnvruncgvtest does not copy the model, even if allowCopyModel is true. An error occurs.

cgvCompType

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

  • 'topmodel' (default)

  • 'modelblock'

cgvConn

Specifies mode of execution for CGV:

  • 'sim' (default)

  • 'sil'

  • 'pil'

Note

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

Output Arguments

collapse all

cgv.CGV object that slvnvruncgvtest creates during the execution of model.

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

Field

Description

tout_slvnvruncgvtest

Simulation time

xout_slvnvruncgvtest

State data

yout_slvnvruncgvtest

Output signal data

logsout_slvnvruncgvtest

Signal logging data for:

  • Signals connected to outports

  • Signals that are configured for logging data on the model

Examples

Log Signals, Run Tests, and Compare Results by Using the CGV API

% Open the sldemo_mdlref_basic example model and log the input signals to the CounterA Model block:
open_system('sldemo_mdlref_basic');
load_system('sldemo_mdlref_counter');
loggedData = slvnvlogsignals('sldemo_mdlref_basic/CounterA');

% Create the default configuration object for slvnvruncgvtest,and allow the model to be configured to
% execute test cases with the CGV API:
runOpts = slvnvruntestopts('cgv');
runOpts.allowCopyModel = true;

% Using the logged signals, execute slvnvruncgvtest — first in simulation mode, and then in 
% Software-in-the-Loop (SIL) mode — to invoke the CGV API and execute the specified test 
% cases on the generated code for the model:
cgvObjectSim = slvnvruncgvtest('sldemo_mdlref_counter', loggedData, runOpts);
runOpts.cgvConn = 'sil';
cgvObjectSil = slvnvruncgvtest('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));

Tips

To run slvnvruncgvtest, you must have the Embedded Coder® software.

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

  • Modify the invalid parameters and rerun slvnvruncgvtest.

  • Set allowCopyModel in runOpts to be true and rerun slvnvruncgvtest. slvnvruncgvtest makes a copy of your model configured for executing test cases, and invokes the CGV API.

Introduced in R2010b

Was this topic helpful?