Why do two functions with identical logic but different structure result in different MC/DC coverage results in Simulink Verification and Validation?

2 views (last 30 days)
I have created two functions that have identical logic. I would like to know why these two functions result in different Modified condition/decision coverage (MC/DC) coverage results as reported by the Coverage Tool.
An example of this is two Stateflow functions created as follows. In Funtion1 I have created an OR condition via 2 parallel branches, and in Function2, I use the OR operator on a single branch. If you now generate the coverage report, you will see the MC/DC coverage for the 2 functions is not the same.
It may be noted that Real Time Workshop generates the exact same code for both of these functions. I would expect the Model Coverage Tool to also interpret these identically.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is not a bug. The model coverage tool interprets structural coverage for a model based design. As the name implies, structural information about the design is used to determine when each coverage metric is satisfied.
The fundamental definition of MCDC, as defined in DO-178B is that each condition that makes up a decision will independently change the outcome of the decision while the other conditions are held constant. In Stateflow each conditional transition is treated as a separate decision.
In your case, you are looking at the equivalent of the following two code fragments:
if (in1 == 1 && in2 == 1) {
do_something();
} else if (in1 == 0 && in2 == 0) {
do_something();
}
and its functional equivalent with a different structure:
if ((in1 == 1 && in2 == 1) || (in1 == 0 && in2 == 0)) {
do_something();
}
Given the same inputs to the code fragments above you should see the same MCDC coverage results from a code coverage tool.
However, the coverage tool considers each condition in a transition to be independent so it will not be able to recognize that setting in1==1 to True will make it impossible to set in1==0 to True. The tool simply interprets the expression above to be in the form:
if ( (A && B) || (C && D))
While the relationship between conditions is straightforward in this example in the general case of arbitrary expression and side-effect functions it is very difficult to determine the inter-relationships of conditions.
This could be interpreted as a short coming of the metric itself, but depending on the application, it may also be a feature. Thus, the results that you are receiving are to be expected.
If you wish for a slightly different interpretation of the coverage that would only require each condition to be tested as true and false, then you can obtain this by only enabling decision and condition coverage from the coverage settings dialog.

More Answers (0)

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Verification, Validation, and Test in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!