| Stateflow User's Guide | ![]() |
Understanding Embedded MATLAB Function Model Coverage
Model coverage reports are generated during simulation if you specify them (see Making Model Coverage Reports). When simulation is finished, the model coverage report appears in a browser window. After the summary for the model, the Details section reports on each of the parts of the model. Model coverage for the parts of the example model in Creating a Model with Embedded MATLAB Function Decisions appears in the following order:
The reports for the Embedded MATLAB functions rect_intersect and run_intersect_test appear in alphabetical order as part of the report on their parent, the Stateflow block Chart. The reports on individual decisions for each function appear in numerical line order. Line numbers are indicated by the # character.
The following subtopics examine the model coverage report for the example model in reverse order of the report. Reversing the order helps you make sense of the summary information that appears at the top of each section.
Model Coverage for Embedded MATLAB Function run_intersect_test
Model coverage for the Embedded MATLAB function run_intersect_test, which sends test rectangles to the function rect_intersect, appears in the model coverage report as shown.
The report on run_intersect_test begins with the function name run_intersect_test, which links to an Embedded MATLAB Editor for the function. Following the name is a link to the model coverage report for the parent of run_intersect_test, the Stateflow chart Chart. Coverage continues with a summary of the coverage metrics for the function followed by a code listing. The line number for the first line of the listing is highlighted in bold red, which is actually a link to an analysis for that decision below.
The first line of every function receives coverage analysis indicative of the decision to run the function. Its coverage here indicates that the function run_intersect_test executed 8 out of 8 times for the samples taken at 0 through 7 seconds. Because this is the only decision in the function run_intersect_test, coverage for it in the metrics table above indicates the occurrence of 1 out of 1 possible outcomes. In this case, the only possible outcome is function execution. In other words, the function was executed during simulation.
Coverage for Embedded MATLAB Function rect_intersect
Model coverage for the Embedded MATLAB function rect_intersect, which tests rectangles for intersection, appears first in the model coverage report as shown.
The coverage metrics for rect_intersect include Decision, Condition, and MCDC coverage. These are best understood after you examine the coverage for the decisions in rect_intersect highlighted in the listing below.
The listing for rect_intersect includes three highlighted line numbers. The first line is highlighted as the decision on whether or not to execute the function. Highlighted line numbers 14 and 17 indicate decisions in a nested if-else statement. Notice that the condition right1 < left2 in line 17 is highlighted in red. This means that this condition did not test both the true and false possible outcomes for this decision during simulation. Exactly which of the outcomes was not tested is answered by the metrics for the decision in line 17. The metrics for line 17 and the remaining decisions appear below listed in numerical line order, and are easily accessed through the line number links in the listing.
Coverage for Line 1. Coverage metrics for line 1 appear directly below the listing for rect_intersect as shown.
The first line of every function receives coverage analysis indicative of the decision to run the function in response to a call. The preceding table indicates that rect_intersect executed. Coverage for this decision, which is equivalent to decision D1 in the metrics table for rect_intersect, is therefore 100%.
Coverage for Line 14. Coverage metrics for line 14 appear directly below the coverage metrics for line 1 as shown.
The Decisions analyzed table indicates that there are two possible outcomes for the decision in line 14: false and true. 5 of 8 times the decision evaluated false, and the remaining times (3) it evaluated true. Because both the true and false outcome occurred during simulation, Decision Coverage is 100%.
The following Conditions analyzed table sheds some light on the decision in line 14. Because this decision consists of two conditions linked by a logical or (||) operation, only one condition must evaluate true for the decision to be true. Also, if the first condition evaluates to true, there is no need to evaluate the second condition. The first condition, top1 < bottom2, was evaluated 8 times, and was true twice. This means that it was necessary to evaluate the second condition only 6 times. In only one case was it true, which brings the total of the true occurrence for the decision to 3 as reported in the Decisions analyzed table.
MCDC coverage looks for decision reversals that occur because one condition outcome changes from T to F or from F to T. The table identifies all possible combinations of outcomes for the conditions that lead to a reversal in the decision. The character x is used to indicate a condition outcome that is irrelevant to the decision reversal. Reversing condition outcomes that are not achieved during simulation are marked with a set of parentheses. There are no parentheses, so all decision reversing outcomes occurred, and MCDC Coverage is complete for this decision.
Coverage for rect_intersect Line 17. Coverage metrics for line 17 appear directly below the coverage metrics for line 14, as shown.
The line 17 decision if (right1 < left2 || right2 < left1) is nested in the if statement of the line 14 decision and is evaluated only if the line 14 decision is false. Because the line 14 decision evaluated false 5 times, line 17 is evaluated 5 times, 3 of which were false. Because both the true and false outcomes were achieved, Decision Coverage for line 17 is 100%.
Because line 17, like line 14, has two conditions related by a logical OR operator (||), condition 2 is tested only if condition 1 is false. Because condition 1 tests false 5 times, condition 2 is tested 5 times. Of these, condition 2 tests true 2 times and false 3 times, which accounts for the two occurrences of the true outcome for this decision.
Because the first condition of the line 17 decision does not test true, both outcomes did not occur for that condition, and the Condition Coverage for the first condition is highlighted with a rose color. Because the first condition of the line 17 decision does not test true, MCDC coverage is also highlighted in the same way for a decision reversal based on the true outcome for that condition.
Coverage for All rect_intersect Lines. Reviewing the coverage report for each line of rect_intersect in the previous topics makes sense of the coverage metrics reported at the beginning of the model coverage report for rect_intersect, which is as shown.
Reflecting on the model coverage reports for each line of rect_intersect, you can draw the following conclusions:
rect_intersect in the line reports: one for line 1 (execute), two for line 14 (true and false), and two for line 17 (true and false). The decision coverage for each line shows 100% coverage. This means that decision coverage for rect_intersect is 5 of 5 or 100%.
rect_intersect in the line reports. Lines 14 and 17 each have two conditions, and each condition has two condition outcomes (true and false), for a total of eight condition outcomes in rect_intersect. All conditions tested for both the true and false outcome, except for the first condition of line 17 (right1 < left2). This means that condition coverage for rect_intersect is 7 of 8 or 88%.
| Creating a Model with Embedded MATLAB Function Decisions | Building Targets | ![]() |
© 1994-2005 The MathWorks, Inc.