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 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 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

model

Name of the Simulink® model to execute

dataFile

Name of the data file or a structure that contains the input data. Data can be generated either by:

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

  • Using the slvnvlogsignals function.

runOpts

A structure whose fields 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

Specifies to create and configure the model if you have not configured it for executing test cases with the CGV API.

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

cgvObject

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 on the model

Examples

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));

More About

expand all

Tips

To run slvnvruncgvtest, you must have a Embedded Coder® license.

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.

Was this topic helpful?