Main Content

Achieve Missing Coverage in Generated Code of RLS

This example shows you how to use Simulink® Design Verifier™ to generate test cases that achieve full coverage. If you simulate a harness of a reusable library susbsystem (RLS) in the software-in-the-loop (SIL) simulation mode, then coverage of the generated code of the RLS is reported. Using Simulink® Test Manager™, you can easily achieve full coverage by using the following steps:

Generate the top-model code before invoking simulation on the harness of the RLS. Before generating the code, you need to set up the code generation target environment. For more information on how to set up the code generation environment, see Generate Test Cases for a Reusable Library Subsystem. After code generation, open the test file.

Open the test file.

 orig = Simulink.fileGenControl('get','CodeGenFolderStructure');
 Simulink.fileGenControl('set','CodeGenFolderStructure', Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder) ;
 load_system('mRLS');
 slbuild('mRLS');

 testFile = 'dTest_TopOffCoverage_Controller.mldatx';
 sltest.testmanager.load(testFile);
 sltest.testmanager.view;
### Starting build procedure for: Controller_CodeSpecification1
### Generating code and artifacts to 'Target environment subfolder' folder structure
### Generating code into build folder: /tmp/Bdoc24a_2528353_1741016/tp0f7301d6/sldv-ex86252898/IntelWin64/Controller_CodeSpecification1
### Invoking Target Language Compiler on Controller_CodeSpecification1.rtw
### Using System Target File: /mathworks/devel/bat/filer/batfs1904-0/Bdoc24a.2528353/build/matlab/rtw/c/ert/ert.tlc
### Loading TLC function libraries
.......
### Initial pass through model to cache user defined code
.
### Caching model source code
.........................................
### Writing header file Controller_tTndzGf8.c
### Writing header file Controller_CodeSpecification1_types.h
### Writing header file Controller_CodeSpecification1.h
.
### Writing header file rtwtypes.h
### Writing header file Controller_tTndzGf8.h
### Writing source file Controller_CodeSpecification1.c
### Writing header file Controller_CodeSpecification1_private.h
### Writing source file ert_main.c
.
### TLC code generation complete (took 6.121s).
### Saving binary information cache.
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc24a_2528353_1741016/tp0f7301d6/sldv-ex86252898/IntelWin64/_shared/rtwshared.mk' ...
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc24a_2528353_1741016/tp0f7301d6/sldv-ex86252898/IntelWin64/Controller_CodeSpecification1/Controller_CodeSpecification1.mk' ...
### Successful completion of code generation for: Controller_CodeSpecification1

The following files will be copied from IntelWin64/_shared to /tmp/Bdoc24a_2528353_1741016/tp0f7301d6/sldv-ex86252898/IntelWin64/mRLS/R2024a:

    Controller_tTndzGf8.c
    Controller_tTndzGf8.h
    shared_file.dmr

Files copied from IntelWin64/_shared to /tmp/Bdoc24a_2528353_1741016/tp0f7301d6/sldv-ex86252898/IntelWin64/mRLS/R2024a.

2. Simulate the test file and observe the coverage value.

3. Click Add Tests for Missing Coverages as coverage of the generated code for the RLS is not 100%.

This workflow invokes Simulink® Design Verifier™ to generate additional testcases.

New test cases are added to the test file.

4. Simulate the overall test file and check if you now have full coverage for the generated code for the RLS.