This example shows how to select a metric and add a rule that uses that metric. In this example, you create a rule to justify an unsatisfied decision for a Saturation block.
Open the Model and Enable Coverage Analysis
Load the model into memory.
Use a Simulink.SimulationInput object to configure coverage for the model.
Simulate the model using the SimulationInput object as the input.
View the coverage results before applying a filter. You can access the coverage using decisioninfo, or you can view the HTML report using cvhtml.
Both decisioninfo and cvhtml show the same result of 50% decision coverage. If you don't intend your current tests to exercise this outcome, you can justify the outcome so it is no longer reported as missing coverage.
In this example, we justify the false decision outcome of the input > lower limit decision objective in the Saturation block.
Justify the Missing Condition Objective
MetricSelector objects accept the block path or the block handle as the second input. Get the block handle of the Saturation block by using getSimulinkBlockHandle.
Because the objective being justified is a decision outcome, the first input to the metric selector constructor is slcoverage.MetricSelectorType.DecisionOutcome. The second input is the block handle. The last two are the index of the objective to justify and the index of the outcome of that objective, respectively.
Because the input > lower limit decision objective is the first objective for the Saturation block, its objective index is 1. Because the false outcome of this objective is the first outcome, its outcome index is also 1. Therefore, the last two inputs are 1,1.
Create a filter and rule. In this case, we use the default filter mode of justify. Then add the rule to the filter using the addRule method.
Save the filter to a filter file using the save method. Then apply the filter file to the cvdata object by assigning the filter property to the new filter file.
Re-generate the coverage results for the Saturation block using the new filtered cvdata object.
In the HTML report, the missing decision outcome is highlighted to indicate that it is justified. Decision coverage for the Saturation block is now 75%.