为可重用库子系统生成测试用例
可重用库子系统 (RLS) 是您定义并包含在库中并配置为可跨模型重用的子系统。有关如何配置 RLS 进行分析的更多信息,请参阅 Generate Reusable Code for Subsystems Shared Across Models (Embedded Coder)。您必须通过从库中创建框架而不是从设计模型中的实例来测试已配置的 RLS。
此示例使用 sldvdemo_cruise_control 模型,其中 PI controller 是 RLS 模块。您可以从此 RLS 模块的实例创建一个框架,如图所示。可以在从库而不是从其实例创建的框架 RLS 模块上调用 RLS 的测试生成。
![]()
当您从所示的库中创建测试框架时,设计模型支持从该框架生成 RLS 代码的测试。
![]()
此示例展示了如何在软件在环模式下分析 RLS 代码。
在软件在环模式下生成 RLS 测试用例
此示例展示如何在软件在环(SIL) 模式下为 RLS 生成测试用例。
1.打开示例模型:'mRLS'
model = 'mRLS';
open_system(model);2.解锁库模型。在配置参数窗口中,点击代码生成,并将系统目标文件设置为 ert.tlc。或者,输入以下命令:
set_param(model,'Lock','off'); set_param(model,'SystemTargetFile','ert.tlc');
3.点击硬件实现,然后将设备供应商和设备类型设置为您的 SIL 系统的供应商和类型。例如,对于 64 位 Linux 计算机,请将设备供应商设置为 Intel,并将设备类型设置为 x-86-64 (Linux)。或者,输入以下代码:
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.使用设备设置来设置函数接口。有关如何从库内设置函数接口的更多信息,请参阅从库内配置函数接口。
5.在为 RLS 生成测试之前,先生成顶层模型代码。在生成代码之前,请设置代码生成目标环境。有关设置目标环境的更多信息,请参阅 SIL 测试可重用库子系统。
orig = Simulink.fileGenControl('get','CodeGenFolderStructure'); Simulink.fileGenControl('set','CodeGenFolderStructure',... Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder); slbuild('mRLS');
### Unable to find Simulink cache file "mRLS.slxc".
### Searching for referenced models in model 'Controller_CodeSpecification1'.
### Total of 1 models to build.
### Starting build procedure for: Controller_CodeSpecification1
### Generating code and artifacts to 'Target environment subfolder' folder structure
### Generating code into build folder: /tmp/Bdoc25a_2864802_2151310/tp2e836fb6/sldv-ex41550386/IntelWin64/Controller_CodeSpecification1
### Invoking Target Language Compiler on Controller_CodeSpecification1.rtw
### Using System Target File: /mathworks/devel/bat/filer/batfs2566-0/Bdoc25a.2864802/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_O359HnDW.c
### Writing header file Controller_CodeSpecification1_types.h
### Writing header file Controller_CodeSpecification1.h
### Writing header file rtwtypes.h
.
### Writing header file Controller_O359HnDW.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 2.346s).
### Saving binary information cache.
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc25a_2864802_2151310/tp2e836fb6/sldv-ex41550386/IntelWin64/_shared/rtwshared.mk' ...
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc25a_2864802_2151310/tp2e836fb6/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/Bdoc25a_2864802_2151310/tp2e836fb6/sldv-ex41550386/IntelWin64/mRLS/R2025a:
Controller_O359HnDW.c
Controller_O359HnDW.h
shared_file.dmr
Files copied from IntelWin64/_shared to /tmp/Bdoc25a_2864802_2151310/tp2e836fb6/sldv-ex41550386/IntelWin64/mRLS/R2025a.
6.如果库模型被锁定,请解锁库模型来为子系统模块创建 Simulink 测试框架。
为特定函数接口的子系统模块创建框架。在此示例中,为函数接口 Double 创建框架。
7.打开框架模型并选择适当的目标,然后开始测试生成。
注意:对于 RLS,您可以从库中生成子系统代码,该代码会被编译成静态库并可供组件重用。从库创建的框架上的测试生成,如果将目标设置为作为模型参考生成的代码,您将收到一条错误消息,因为这不受支持。
RLS 的覆盖率过滤工作流程特定于操作系统。在 Windows 操作系统上创建的过滤器可在 Windows 平台上使用。其他操作系统平台也是如此。
另请参阅
主题
- Generate Reusable Code for Subsystems Shared Across Models (Embedded Coder)
- 测试库模块 (Simulink Test)