Download GCT User Manual
Transcript
User’s Manual
16
Loop Coverage
7. Loop Coverage
These are the looping statements:
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
c Operator c Point of instrumentation c
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
c
c
c
for
for
i
c iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
c
c
ciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
while
c while
c
c
c
c
do-while c do
ciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
c
Loops constructed with gotos are not measured.
The greport message for a while or for loop might look like this:
"example1.c", line 9: loop zero times: 1, one time: 2, many times: 3.
The output refers to the number of times the body of the loop was entered. The "zero" entry is the number
of times the loop test failed on the first try; the "one" entry is the number of times it succeeded exactly
once; the "many" entry is the number of times it succeeded at least twice.
The body of a do-while loop is always entered at least once, since the test is at the bottom of the loop.
Therefore, the greport message looks like this:
"example1.c", line 9: loop one time: 10, many times: 2.
The loop test failed on the first try ten times; it failed on a later try twice.
Loop coverage is measured at the loop test. Suppose a while loop is "started" with a goto into the body,
and then the test at the top of the loop immediately fails. This counts as a "loop zero times"; it is no different than if the test failed as soon as the loop was entered normally.
A break or goto out of a loop does not affect the count. In a loop like
do
{
code
if if-test break;
code
} while (loop-test);
the count is the same whether the loop exits because the if-test succeeds or because the loop-test fails.
Once the body of the loop has been entered, it doesn’t matter how it’s exited.
The only case in which non-local exits make a difference is if a loop is exited with a goto or break and
then entered with another goto. In this case, GCT cannot tell that the loop was ever left.