When you record coverage for models containing supported C/C++ S-Functions, MATLAB Function blocks that call external C/C++ code, C Caller blocks with C/C++ code , or Stateflow® charts that integrate custom C/C++ code for simulation, coverage is recorded for the C/C++ code within the C/C++ S-Functions, MATLAB Function blocks, or Stateflow charts. The coverage results the custom code can be viewed in the same report as the rest of the model. For each S-Function block, MATLAB Function block, or Stateflow chart, the report links to a detailed coverage report for the C/C++ code in the block.
To enable code coverage for custom C/C++ code in your Simulink® model:
On the Simulation Target pane of the Configuration Parameters, select Import custom code.
On the Simulation Target pane of the Configuration Parameters, select Enable custom code analysis.
Simulink Coverage™ records code coverage for custom C/C++ code in MATLAB Function blocks, C Caller blocks, and Stateflow charts.
For more information on the three approaches, see Implement C/C++ S-Functions (Simulink).
Initialize a MATLAB® structure with fields that represent Legacy Code Tool properties.
def = legacy_code('initialize')
To enable model coverage, turn on the option
def.Options.supportCoverageAndDesignVerifier = true;
Use the structure
the usual way to generate an S-function. For an
example, see Coverage for S-Functions.
S-Function Using S-Function Builder
Copy an instance of the S-Function Builder block from the User-Defined Functions library in the Library Browser into the your model.
Double-click the block to open the S-Function Builder dialog box.
On the Build Info tab, select Enable support for coverage.
Function. If you use the
function to compile and link your source files,
compiles your source code and also makes it
compatible with coverage.
This function has the same syntax and takes
the same options as the
function. In addition, you can provide some
options relevant for model coverage. For more
Select Analysis > Coverage > Settings.
On the Coverage pane of the Configuration Parameters dialog box, select C/C++ S-functions.
When you run a simulation, the coverage report contains coverage metrics for C/C++ S-Function blocks in your model. For each S-Function block, the report links to a detailed coverage report for the C/C++ code in the block.