Main Content

Generate Test Cases for a Reusable Library Subsystem

A reusable library subsystem (RLS) is a subsystem that you define and include in a library and configure for reuse across models. For more information on how to configure an RLS for analysis, see Generate Reusable Code for Subsystems Shared Across Models (Embedded Coder). You must test the configured RLS by creating a harness from the library and not from an instance in a design model.

This example uses sldvdemo_cruise_control model, where PI controller is the RLS block. You can create a harness from the instance of this RLS block as shown. Test generation of RLS can be invoked on a harness RLS block created from the library and not from its instance.

When you create the test harness from the library as shown, the test generation for the RLS code from this harness is supported by the design model.

This example shows how to analyse RLS code in the Software-in-the-Loop mode.

Generate Test Cases for RLS in Software-in-the-Loop Mode

This example shows how to generate test cases for RLS in the software-in-the-loop (SIL) mode.

1. Open the example model: 'mRLS'

model = 'mRLS';
open_system(model);

2. Unlock the library model. In the Configuration Parameters window, click Code Generation and set System Target File to ert.tlc. Alternatively, enter the following command:

set_param(model,'Lock','off');
set_param(model,'SystemTargetFile','ert.tlc');

3. Click Hardware Implementation, then set Device vendor and Device type to the vendor and type of your SIL system. For example, for a 64-bit Linux machine, set Device vendor to Intel and Device type to x-86-64 (Linux). Alternatively, enter the following code:

if ismac
    lProdHWDeviceType = 'Intel->x86-64 (Mac OS X)';
 elseif isunix
    lProdHWDeviceType = 'Intel->x86-64 (Linux 64)';
 else
     lProdHWDeviceType = 'Intel->x86-64 (Windows64)';
 end
set_param(model, 'ProdHWDeviceType', lProdHWDeviceType);

4. Use the device settings to set up the function interface. For more information on how to set the function interface from within a library, see Configure Function Interfaces from Within a Library.

5. Generate the top-model code before generating tests for the RLS. Before you generate the code, set up the code generation target environment. For more information on setting up the target environment, see SIL Testing a Reusable Library Subsystem.

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

slbuild('mRLS');
### Starting build procedure for: Controller_CodeSpecification1
### Generating code and artifacts to 'Target environment subfolder' folder structure
### Generating code into build folder: /tmp/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex41550386/IntelWin64/Controller_CodeSpecification1
### Invoking Target Language Compiler on Controller_CodeSpecification1.rtw
### Using System Target File: /mathworks/devel/bat/filer/batfs2566-0/Bdoc24b.2725827/build/runnable/matlab/rtw/c/ert/ert.tlc
### Loading TLC function libraries
.......
### Initial pass through model to cache user defined code
.
### Caching model source code
.........................................
### Writing source file Controller_aWDHngMf.c
### Writing header file Controller_CodeSpecification1_types.h
### Writing header file Controller_CodeSpecification1.h
### Writing header file rtwtypes.h
### Writing header file Controller_aWDHngMf.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 4.188s).
### Saving binary information cache.
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex41550386/IntelWin64/_shared/rtwshared.mk' ...
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex41550386/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/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex41550386/IntelWin64/mRLS/R2024b:

    Controller_aWDHngMf.c
    Controller_aWDHngMf.h
    shared_file.dmr

Files copied from IntelWin64/_shared to /tmp/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex41550386/IntelWin64/mRLS/R2024b.

6. If the library model is locked, unlock the library model to create a Simulink test harness for the subsystem block.

Create the harness for the subsystem block for a particular function interface. In this example, create the harness for the function interface Double.

7. Open the harness model and select the appropriate target and then start test generation.

Note: For RLS you can generate subsystem code from the library that gets compiled into a static library and can be reused by components. Test generation on the harness, created from the library and if you set the target as Code Generated as Model Reference you will receive an error message as this is not supported.

The coverage filtering workflow for RLS is specific to the operating system. The filters created on the Windows operating system, are used on the Windows platform. The same applies to other operating system platforms.

Related Topics