主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

在 RLS 生成代码中实现缺失覆盖

此示例向您展示如何使用 Simulink® Design Verifier™ 生成实现全覆盖率的测试用例。如果您在软件在环 (SIL) 仿真模式下仿真可重用库子系统 (RLS) 的框架,则会报告 RLS 生成代码的覆盖率。使用 Simulink® 测试管理器™,您可以通过以下步骤轻松实现全面覆盖率:

在 RLS 的框架上调用仿真之前生成顶层模型代码。在生成代码之前,需要设置代码生成目标环境。有关如何设置代码生成环境的更多信息,请参阅为可重用库子系统生成测试用例。代码生成后,打开测试文件。

打开该测试文件。

 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;
### 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_2135085/tpdd452aec/sldv-ex86252898/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 4.29s).
### Saving binary information cache.
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc25a_2864802_2135085/tpdd452aec/sldv-ex86252898/IntelWin64/_shared/rtwshared.mk' ...
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc25a_2864802_2135085/tpdd452aec/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/Bdoc25a_2864802_2135085/tpdd452aec/sldv-ex86252898/IntelWin64/mRLS/R2025a:

    Controller_O359HnDW.c
    Controller_O359HnDW.h
    shared_file.dmr

Files copied from IntelWin64/_shared to /tmp/Bdoc25a_2864802_2135085/tpdd452aec/sldv-ex86252898/IntelWin64/mRLS/R2025a.

2.仿真测试文件,观察覆盖率值。

3.点击“添加缺失覆盖率测试”,因为 RLS 生成的代码的覆盖率不是 100%。

此工作流程调用 Simulink® Design Verifier™ 来生成其他测试用例。

新的测试用例被添加到测试文件中。

4.仿真整体测试文件并检查您现在是否对 RLS 生成的代码进行了全面覆盖率。