主要内容

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

通过重用模型表示来扩展现有测试用例

此示例说明如何在重新分析模型时避免构建不必要的模型表示。考虑您执行测试生成并且分析超出最大分析时间的情况。在指定的分析时间内,Simulink Design Verifier 分析一些目标并将生成的测试用例保存在 MAT 文件中。

要重新分析模型,您需要更新最大分析时间并选择扩展现有测试用例选项。为了加快分析速度,将重建模型表示选项设置为 If change is detected。Simulink Design Verifier 通过重复使用模型表示来重新分析模型。有关详细信息,请参阅重用模型表示进行分析

步骤 1:打开模型并指定分析选项

通过指定 sldvdemo_cruise_control 来生成 sldvoptions 模型的测试用例。

model = 'sldvdemo_cruise_control';
open_system(model);
opts = sldvoptions;
opts.Mode = "TestGeneration";
opts.MaxProcessTime = 10;
opts.RebuildModelRepresentation = "IfChangeIsDetected";

使用此命令分析模型。

[ status, files ] = sldvrun('sldvdemo_cruise_control', opts, true);

诊断查看器窗口显示测试生成分析错误。

Simulink Design Verifier has exceeded the maximum processing time. You can extend the time limit by modifying the "Maximum analysis time" edit field on the Design Verifier pane of the configuration dialog or by modifying the "MaxProcessTime" attribute of the options object.

分析完成后,“结果摘要”窗口将显示结果。该软件报告 22/24 目标已满足,而 2/24 目标尚未确定。

步骤 2:通过修改 sldvoptions 重新分析模型

要重新分析模型,请选择扩展现有测试用例选项并更新最大分析时间。重建模型表示选项设置为 If change is detected。该软件验证缓存模型表示,检测到无变化,并重用模型表示进行分析。

opts.MaxProcessTime =500;
opts.ExtendExistingTests='on';
opts.IgnoreExistTestSatisfied = 'on';
opts.ExistingTestFile=files.DataFile;
sldvrun('sldvdemo_cruise_control', opts, true);

结果表明 24/24 目标得到满足,并且没有生成额外的测试用例。

关闭模型。

close_system('sldvdemo_cruise_control', 0);

相关主题