Lesson15 Coverage and MCDCtesting
Lesson15 Coverage and MCDCtesting
Marco Di Natale
Scuola Superiore S. Anna- Pisa, Italy
Taken from
A Practical Tutorial on Modified Condition/Decision Coverage by Kelly
J. Hayhurst, Dan S. Veerhusen, John J. Chilenski, Leanna K. Rierson,
NASA/TM-2001-210876, May 2001
Model-based testing
More on MCC
Testing
"No product of human intellect comes out right the first time. We rewrite
sentences, rip out knitting stitches, replant gardens, remodel houses,
and repair bridges. Why should software be any different?"
Wiener, Ruth: Digital Woes, Why We Should Not Depend
on Software.
Model-based testing
DO-178B
Coverage
"Our goal, then, should be to provide enough testing to ensure that the
probability of failure due to hibernating bugs is low enough to accept.
'Enough' implies judgement.
Coverage
Coverage refers to the extent to which a given verification activity has
satisfied its objectives: in essence, providing anexit criteria for when to
stop. That is, what is enough is defined in terms of coverage
Coverage is a measure, not a method or a test. As a measure,
coverage is usually expressed as the percentage of an activity that is
accomplished.
Coverage
Two specific measures of test coverage are
Requirements coverage analysis: how well the
requirements based testing verified the implementation
of the software requirements
Requires traceability between the software requirements and the
test cases.
Coverage
Provide evidence that the code structure was verified to the degree
required for the applicable software level;
Provide a means to support demonstration of absence of unintended
functions;
Establish the thoroughness of requirements-based testing.
and
Reveal code structure that was not exercised during testing.
Note 1: In the above text, the term exercised during requirementsbased testing does not only mean that the specific code was
exercised. It also means that the behavior of the code has been
compared with the requirements to which it traces.
Model-based testing
weakest
strongest
Statement coverage
To achieve statement coverage, every executable statement in the
program is invoked at least once during software testing.
shows that all code statements are reachable (reachable based on test
cases developed from the requirements).
Statement coverage
According to Myers (ref. 10), statement-coverage criterion is so weak that it is
With respect to control flow, structural testing does not provide any
information as to whether the right decisions are being made for the
right reasons.
Structural testing fails to assure that there are no unintended
functions.
In the best case, structural testing confirms that the object code and
processor properly implement the source code
More on MCC
According to legend, there were once folks who advocated requiring
100% multiple condition coverage (that is, exhaustive testing) for
level A software.
The motivation is simple: testing all possible combinations of inputs for each
decision ensures that the correct decision outcome is reached in all cases.
The problem with such testing, however, is that for a decision with n
inputs, 2n tests are required.
The table shows the number of Boolean expressions with n
conditions for all of the logic expressions taken from the airborne
software of five different Line Replaceable Units (LRUs) from level A
systems. (from two airplane models in 1995). As the table shows,
actual code has been written with more than 36 conditions.
More on MCC
MC/DC attempts to provide a practical alternative. The modified
condition/decision coverage criterion was developed to achieve many
of the benefits of multiple-condition testing while retaining the linear
growth in required test cases of condition/decision testing.
MC/DC is intended to assure, with a high degree of confidence, that
the verification process has shown that each condition in each
decision in the source code has the proper effect.
Q1: Consider an expression with 36 inputs. How much time would it take to
execute all of the test cases required for multiple condition coverage of this
expression if you could run 100 test cases per second?
A1:
Q2: If your test artifacts include a single line for the test results of each test
case, how tall would the report be for test results for achieving multiple
condition coverage for an expression with 36 inputs? (Assume 64 lines per
sheet of paper, and 250 sheets of paper per inch height.)
A2:
More on MCC
The requirement to show the independent effect of each condition
within a decision makes MC/DC unique among coverage criteria.
Determining whether a condition has independent effect might seem
rather simple: a condition has independent effect when that condition
alone determines the outcome of the decision.
ConditionA Boolean expression containing no Boolean operators.
DecisionA Boolean expression composed of conditions and zero or
more Boolean operators. A decision without a Boolean operator is a
condition. If a condition appears more than once in a decision, each
occurrence is a distinct condition.
Modified Condition/Decision CoverageEvery point of entry and exit
in the program has been invoked at least once, every condition in a
decision in the program has taken all possible outcomes at least
once, every decision in the program has taken all possible outcomes
at least once, and each condition in a decision has been shown to
independently affect that decisions outcome. A condition is shown to
independently affect a decisions outcome by varying just that
condition while holding fixed all other possible conditions.
More on MCC
These definitions raise a number of confounding issues when
determining whether a set of test cases provides MC/DC.
The first issue involves the meaning of condition. Without the last
sentence in the definition of decision, most people would probably
say that the decision (A and B) or (A and C), where A, B, and C are
conditions set by the software, contains three conditionsA, B, and
C. According to the last sentence of the definition, however, this
decision contains four conditions: the first A, B, C, and the second
A. The first occurrence of A is said to be coupled with the second
occurrence of A because a change to one condition affects the
other.
According to the definition of MC/DC above, showing independent
effect in this example requires, among other things, showing what
happens when the value of the first A is held constant, while the
value of the second A is toggled between false and true. This
typically cannot be accomplished in any meaningful way.
More on MCC
The next issue involves the scope of within a decision. For example,
consider the following code statements:
A:= B or C; (statement 1)
E:= A and D; (statement 2)
These two statements are logically equivalent to:
E:= (B or C) and D; (statement 3)
Statements 1, 2, and 3 all contain decisions, even though none of the
statements are branch points such as an if statement. That is, a
decision is not synonymous with a branch point. MC/DC applies to all
decisionsnot just those within a branch point.
More on MCC
A:= B or C; (statement 1)
E:= A and D; (statement 2)
E:= (B or C) and D; (statement 3)
Further, a test set that provides MC/DC for statements 1 and 2
individually will not necessarily provide MC/DC for statement 3. That
is, if a complex decision statement is decomposed into a set of less
complex (but logically equivalent) decision statements, providing
MC/DC for the parts is not always equivalent to providing MC/DC for
the whole.
For the example above, tests (TFT), (FTF), and (FFT) for (B,C,D)
provide MC/DC for statements 1 and 2 individually, but do not
provide MC/DC for statement 3.
More on MCC
The final issue involves the concept of independent effect. Showing that a
condition independently affects a decisions outcome by varying just that
condition while holding all others fixed is commonly referred to as the uniquecause approach to MC/DC. This approach ensures that the effect of each
condition is tested relative to the other conditions without requiring analysis
of the logic of each decision (that is, if changing the value of a single
condition causes the value of the decision outcome to change, then the
single condition is assumed to be the cause for the changeno further
analysis is needed).
Historically, the unique-cause approach has often been the only acceptable
means of showing the independent effect of a condition. The unique-cause
approach cannot be applied, however, to decisions where there are repeated
or strongly coupled conditions; e.g., (A and B) or (A and C).
More on MCC
More on MCC
every decision in the program has taken all possible outcomes at least once
every condition in a decision in the program has taken all possible outcomes at least once
every condition in a decision has been shown to independently affect that decisions outcome
The MC/DC approach for the tutorial was selected because it requires an
explicit mapping of the requirements-based tests to the source code
structure. This approach applies to any source code written regardless of
whether it is in a high-level language such as Ada or in assembly language.
Mapping requirements-based test cases to source code structure reinforces
the notion that structural coverage analysis is a check on the adequacy of
requirements-based tests for a given source code implementation.
The approach also capitalizes on several concepts familiar to engineers,
including a schematic representation of the source code (which allows you to
see everything needed for assessing MC/DC on one page), and the
hardware testing concepts of controllability and observability.
Minimum testing to achieve MC/DC for an and gate requires the following:
(1) All inputs are set true with the output observed to be true. This requires one test
case for each n-input and gate.
(2) Each and every input is set exclusively false with the output observed to be false.
This requires n test cases for each n-input and gate.
The requirements make sense when considering how an and gate works. Changing
a single condition starting from a state where all inputs are true will change the
outcome; that is, an and gate is sensitive to any false input. Hence, a specific set of
n+1 test cases is needed for an n-input and gate. These specific n+1 test cases meet
the intent of MC/DC by demonstrating that the and gate is correctly implemented.
An example of the minimum testing required for a three-input and gate (shown in
Figure 3) is given in Table 5. In this example, test case 1 in Table 5 provides the
coverage for (1) above, and test cases 2-4 provide coverage for (2).
A comparator evaluates two numerical inputs and returns a Boolean based on the
comparison criteria. A comparator is a condition and also a simple decision. The
following comparison criteria are considered in this tutorial:
less than
greater than
less than or equal to
greater than or equal to
equal to
not equal to
In general, the comparison point can be a constant or another variable (see Figure 7).
In either case, two test cases will confirm MC/DC for a comparatorone test
case with a true outcome, and one test case with a false outcome. Hence,
minimum testing for a comparator requires the following:
(1) Input x set at a value above the comparison point (or y)
(2) Input x set at a value below the comparison point (or y)
However, the numerical aspects of a comparator must also be considered in
determining reasonable tests. For example, given a software requirement to
test (x 5000), one test case with a true outcome (e.g., x = 30000), and one
test case with a false outcome (e.g., x = 30000) provide MC/DC. However,
these cases do not confirm that the design is accurately implemented in the
source code. Specifically in this example, the test cases do not confirm that
5000 is the correct comparison point or less-than-or-equalto is the
appropriate relational operator. The source code could have been
implemented as x < -5000 or as x 500 and still pass the test cases.
Selecting two test cases closer to the comparison point is better, but does
not cover certain coding errors. For example, test cases with x = 5000 and x
= 5001 are better, but they will not detect a coding error of x = 5000.
In general, three test cases are needed to assure that simple coding errors have not
been made; that is, that the correct relational operator and comparison point are used
in the code. So, while MC/DC only requires two tests, minimum good requirementsbased testing for a comparator requires:
Test cases 1 and 2 give the desired MC/DC output. However, those test cases do not
confirm that the toggle occurred at 2500, and not elsewhere. Even adding test case 3 does
not improve the test suite much.
The design could have been implemented with a comparison point anywhere between
2501 and 32000, and give the same result for test cases 1, 2, and 3. Test cases 3, 4, and
5 are a better set, because this set confirms that the transition occurs at 2500.
The if-then-else statement is a switch that controls the execution of the software.
Consider the following example where x, y, and z are integers and C is a Boolean:
if C then z := x else z := y;
A minimal test set for the statement if Z then a := x else a := y is shown in Table 9.
Bibliography
Taken from
A Practical Tutorial on Modified Condition/Decision
Coverage by Kelly J. Hayhurst, Dan S. Veerhusen, John J.
Chilenski, Leanna K. Rierson, NASA/TM-2001-210876, May
2001