主要内容

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

在包含 C Caller 模块的模型上生成测试

R2026b

此示例说明如何在包含 C Caller 模块和自定义 C 代码的模型上使用测试生成

打开包含 C Caller 模块和自定义代码的模型

open_system('sldvexCCallerBlock');

生成测试以确保模型的覆盖率

使用 sldvrun 函数运行 Simulink® Design Verifier™ 分析。

opts = sldvoptions;
opts.Mode = 'TestGeneration';
opts.ModelCoverageObjectives = 'ConditionDecision';
opts.SaveHarnessModel = 'off';
opts.SaveReport = 'off';

[status, fileNames] = sldvrun('sldvexCCallerBlock', opts);
07-Aug-2026 02:56:29
Checking compatibility for test generation: model 'sldvexCCallerBlock'
Compiling model...done
Building model representation...done

07-Aug-2026 02:56:50

'sldvexCCallerBlock' is compatible for test generation with Simulink Design Verifier.
Generating tests...

..........
07-Aug-2026 02:57:00

Completed normally.

Generating output files:

07-Aug-2026 02:57:02
Results generation completed.

    Data file:
    /tmp/Bdoc26b_3351752_1703115/tpb5085f00/sldv-ex07804984/sldv_output/sldvexCCallerBlock/sldvexCCallerBlock_sldvdata.mat

验证覆盖率

使用 sldvruntest 函数验证测试套件是否实现了完整模型覆盖率。

[~, finalCov] = sldvruntest('sldvexCCallerBlock', fileNames.DataFile, [], true);
cvhtml('Final Coverage', finalCov);

清理

要完成示例,请关闭所有模型。

close_system('sldvexCCallerBlock', 0);