Difference between revisions of "Branch Coverage Cheat Sheet"

From OC Systems Wiki!
Jump to: navigation, search
m (Switch Statements)
m (Markers/Colors)
 
(18 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
=== Markers/Colors ===
 
=== Markers/Colors ===
  
A source line with no line count (no color / no marker) is either a line with no object code and can be ignored of it is part of a subprogram for which coverage was not requested.
+
A source line with no line count (no color / no marker) is either a line with no object code and can be ignored or it is part of a subprogram for which coverage was not requested.
  
[[file:BCCS_1.jpeg|1500px]]
+
[[file:BCCS_1.jpeg|1200px]]
  
 
A source line with a positive line count (no marker / green color) is OK (has been executed).
 
A source line with a positive line count (no marker / green color) is OK (has been executed).
  
[[file:BCCS_2.jpeg|1500px]]
+
[[file:BCCS_2.jpeg|1200px]]
  
 
A source line with a zero line count (+ marker / yellow color) needs attention (has not been executed).
 
A source line with a zero line count (+ marker / yellow color) needs attention (has not been executed).
  
[[file:BCCS_3.jpeg|1500px]]
+
[[file:BCCS_3.jpeg|1200px]]
  
 
A source line with a zero line count (* marker / red color) needs attention (has not been instrumented).
 
A source line with a zero line count (* marker / red color) needs attention (has not been instrumented).
  
[[file:BCCS_4.jpeg|1500px]]
+
[[file:BCCS_4.jpeg|1200px]]
  
 
A branch with positive count (green color) is OK (has been executed).
 
A branch with positive count (green color) is OK (has been executed).
  
[[file:BCCS_5.jpeg|1500px]]
+
[[file:BCCS_5.jpeg|1200px]]
  
 
A branch with a zero count (+ marker / yellow color) need attention (has not been executed).
 
A branch with a zero count (+ marker / yellow color) need attention (has not been executed).
  
[[file:BCCS_6.jpeg|1500px]]
+
[[file:BCCS_6.jpeg|1200px]]
  
 
A branch with a zero count (+ marker / red color) need attention (has not been instrumented).
 
A branch with a zero count (+ marker / red color) need attention (has not been instrumented).
  
[[file:BCCS_7.jpeg|1500px]]
+
[[file:BCCS_7.jpeg|1200px]]
  
 
=== Multiple Branches Per Line ===
 
=== Multiple Branches Per Line ===
Line 41: Line 41:
 
Lines with multiple branches may be easier to work with if the source code is modified to put one decision per line.
 
Lines with multiple branches may be easier to work with if the source code is modified to put one decision per line.
  
[[file:BCCS_8.jpeg|1500px]]
+
[[file:BCCS_8.jpeg|1200px]]
  
 
versus
 
versus
  
[[file:BCCS_9.jpeg|1500px]]
+
[[file:BCCS_9.jpeg|1200px]]
  
 
== C/x86 ==
 
== C/x86 ==
Line 59: Line 59:
 
In a for loop, the index bounds test is completed at the top of the loop. If the branch associated with the for loop in not taken, then the body of the loop will not have been executed (line counts should be 0).
 
In a for loop, the index bounds test is completed at the top of the loop. If the branch associated with the for loop in not taken, then the body of the loop will not have been executed (line counts should be 0).
  
[[file:BCCS_10.jpeg|1500px]]
+
[[file:BCCS_10.jpeg|1200px]]
  
 
In a for loop, the index bounds test is completed at the top of the loop. The line count of the for loop should be greater than the branch count of the for loop because the final bounds check will fail and not branch back to the loop body.
 
In a for loop, the index bounds test is completed at the top of the loop. The line count of the for loop should be greater than the branch count of the for loop because the final bounds check will fail and not branch back to the loop body.
  
[[file:BCCS_11.jpeg|1500px]]
+
[[file:BCCS_11.jpeg|1200px]]
  
 
In a while loop, the while test is completed at the top of the loop. If the branch associated with the while loop in not taken, then the body of the loop will not have been executed (line counts should be 0).
 
In a while loop, the while test is completed at the top of the loop. If the branch associated with the while loop in not taken, then the body of the loop will not have been executed (line counts should be 0).
  
[[file:BCCS_12.jpeg|1500px]]
+
[[file:BCCS_12.jpeg|1200px]]
  
 
In a while loop, the while test is completed at the bottom of the loop. The line count of the while loop should be greater than the branch count of the for loop because the final while test will fail and not branch back to the loop body.
 
In a while loop, the while test is completed at the bottom of the loop. The line count of the while loop should be greater than the branch count of the for loop because the final while test will fail and not branch back to the loop body.
  
[[file:BCCS_13.jpeg|1500px]]
+
[[file:BCCS_13.jpeg|1200px]]
  
 
In a do-while loop, the while test is completed at the bottom of the loop. The line count of the do-while loop should be greater than the branch count of the for loop because the final while test will fail and not branch back to the loop body.
 
In a do-while loop, the while test is completed at the bottom of the loop. The line count of the do-while loop should be greater than the branch count of the for loop because the final while test will fail and not branch back to the loop body.
  
[[file:BCCS_14.jpeg|1500px]]
+
[[file:BCCS_14.jpeg|1200px]]
  
 
=== Conditional Operator (?) ===
 
=== Conditional Operator (?) ===
Line 83: Line 83:
 
Conditional operators on a single line will include a branch to the same line which is for the FALSE condition. If the branch is not taken then the TRUE conditional has not been executed. If the branch is executed fewer times than the line count then both conditions have been executed.
 
Conditional operators on a single line will include a branch to the same line which is for the FALSE condition. If the branch is not taken then the TRUE conditional has not been executed. If the branch is executed fewer times than the line count then both conditions have been executed.
  
[[file:BCCS_15.jpeg|1500px]]
+
[[file:BCCS_15.jpeg|1200px]]
  
 
Conditional operator expressions spanning multiple source lines allow for easier (not easy) determination of decisions tested.
 
Conditional operator expressions spanning multiple source lines allow for easier (not easy) determination of decisions tested.
  
[[file:BCCS_16.jpeg|1500px]]
+
[[file:BCCS_16.jpeg|1200px]]
  
 
versus
 
versus
  
[[file:BCCS_17.jpeg|1500px]]
+
[[file:BCCS_17.jpeg|1200px]]
  
 
=== Switch Statements ===
 
=== Switch Statements ===
Line 97: Line 97:
 
Switch statements with a default case will have a single branch to the default case and use a jump table for the rest. Line counts will indicate which cases have been executed.
 
Switch statements with a default case will have a single branch to the default case and use a jump table for the rest. Line counts will indicate which cases have been executed.
  
[[file:BCCS_18.jpeg|1500px]]
+
[[file:BCCS_18.jpeg|1200px]]
  
 
Switch statements without a default will have branches for each case. Line counts will indicate which cases have been executed. There will also be a branch to the same line as the switch expression (which represents the default case) which is executed when no explicit cases are executed.
 
Switch statements without a default will have branches for each case. Line counts will indicate which cases have been executed. There will also be a branch to the same line as the switch expression (which represents the default case) which is executed when no explicit cases are executed.
  
[[file:BCCS_19.jpeg|1500px]]
+
[[file:BCCS_19.jpeg|1200px]]
  
 
Switch statements with null or no statements will have branches to the next statement following the switch statement. If the switch statement is at the end of a loop, the next statement may be the loop condition test, whose source line number may/will be at the top of the loop.
 
Switch statements with null or no statements will have branches to the next statement following the switch statement. If the switch statement is at the end of a loop, the next statement may be the loop condition test, whose source line number may/will be at the top of the loop.
  
[[file:BCCS_20.jpeg|1500px]]
+
[[file:BCCS_20.jpeg|1200px]]
  
 
=== If Statements ===
 
=== If Statements ===
  
: 110: 100 -> 173
+
If statements will include (at least) one branch for the condition of each leg. If the branch count is not the same as the line count then both paths of the decision have been tested.
for(j=0;j<10;j++)
 
switch (i)
 
break;
 
case 4: case 5:
 
    171: ::{ <snip>
 
218 : : : /* switch with null alternatives */
 
: 100 40 -> 170
 
: 20
 
: :
 
:
 
:
 
: :
 
    220: ::{
 
221 : : : case 0: 222: : : ; 223 : : : case 1:
 
225 : : : case 2: 226 : : : case 3:
 
227 : : 20 : k = k + 3; 228 : : 20 : break;
 
  230 : : 10 : k = k + 4; 231 : : 10 : break;
 
  233 : : 10 : k = k + 5; 234 : : 10 : break;
 
235 : : : default: 236: : : ; 237: ::}
 
238: ::}
 
 
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is not the same as the line count then both paths of the decision have been tested.
 
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_21.jpeg|1200px]]
248 : : : /* never taken */
 
249: B
 
+ 251:
 
255: + B
 
: 10: 10 -> 255
 
: 0:
 
: 10: 0 -> 261
 
if(ident(j)<0) j = j + 1;
 
if (ident(j) < 1000)
 
    250: ::{
 
252: ::}
 
253: : :
 
254 : : : /* always taken */
 
    256: ::{
 
257 :
 
258: ::}
 
  
 
If statements with null/empty legs...TBD
 
If statements with null/empty legs...TBD
  
j = j + 1;
+
[[file:BCCS_21a.jpeg|1200px]]
262: ::{ 263: ::; 264: ::}
 
: 10 :
 
  261 : : 10 : if (ident(j) < 1000)
 
  
 
If statement conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
 
If statement conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
  
368: : 10: if((ident(j)>=0)& + B 0 -> 377
+
[[file:BCCS_22.jpeg|1200px]]
372: ::{
 
373 : : 10 : j = j + 1; 374: ::}
 
  
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
  
  Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_23.jpeg|1200px]]
367 : : : /* all true */
 
    369 : 370 : 371 :
 
: 10 : : 10 : : 10 :
 
(ident(k) == 0) & (0 == ident(k)) & (0 <= ident(j)))
 
    Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
442 : : : /* third true */
 
  + +
 
+
 
443: : B 0->448
 
444: : B 0->448
 
445: : B 10 -> 448
 
10 : 10 : 10 :
 
if ((ident(j) >= 1111110) || (1111110 == ident(k)) || (ident(k) == 0) || (111110 <= ident(j)))
 
j = j + 1;
 
          446: :
 
447: ::{ 448 : : 10 : 449: ::}
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
0 :
 
  
 
== GNAT Ada/x86 ==
 
== GNAT Ada/x86 ==
Line 192: Line 131:
 
Straight-line code will often include exception checks for ranges and bounds. If straight-line code contains branches to the same line then these are exception checks. If the branch counts are the same as the line counts then the exception checks passed and an exception was not raised.
 
Straight-line code will often include exception checks for ranges and bounds. If straight-line code contains branches to the same line then these are exception checks. If the branch counts are the same as the line counts then the exception checks passed and an exception was not raised.
  
19 : : 11 : result := result + i; B 11 -> 19
+
[[file:BCCS_24.jpeg|1200px]]
B 11 -> 19
 
  
 
=== Loops ===
 
=== Loops ===
Line 199: Line 137:
 
All for loops will include a branch for the loop range check at the top. The normal loop range check should have a line count greater than the line count of the body statements to indicate the loop reached completion and the branch count should be non-zero to indicate the exit was taken. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
 
All for loops will include a branch for the loop range check at the top. The normal loop range check should have a line count greater than the line count of the body statements to indicate the loop reached completion and the branch count should be non-zero to indicate the exit was taken. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
  
34 : : 121 : for l in integer range 0..9 loop B 11 -> 39
+
[[file:BCCS_25.jpeg|1200px]]
  
 
For loops with dynamic bounds will test for a null loop range at the top of the loop and contain a branch to the next statement which is taken when the loop range is null.
 
For loops with dynamic bounds will test for a null loop range at the top of the loop and contain a branch to the next statement which is taken when the loop range is null.
  
Line Edge/Branch Line Cnt Source
+
[[file:BCCS_26.jpeg|1200px]]
      Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
    35 : : 110 : k := k + i; 36: : 110: endloop;
 
 
 
------ ----------- --------- ------- - -
 
28 : : : -- no iterations
 
29 : : 11 : for l in integer range Ident(1)..Ident(0) loop B 11 -> 34
 
B 0 -> 34
 
  
 
While loops will test loop exit condition at the top of the loop and contain a branch to the next statement which is taken when the loop exit is taken. The loop exit condition should have a line count greater than the line count of the body statements to indicate the loop reached completion. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
 
While loops will test loop exit condition at the top of the loop and contain a branch to the next statement which is taken when the loop exit is taken. The loop exit condition should have a line count greater than the line count of the body statements to indicate the loop reached completion. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
  
    +
+
[[file:BCCS_27.jpeg|1200px]]
  + 30 : : 0 : k := k + i; + 31 : : 0 : end loop;
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
58 : : 11 : j := 0;
 
59: : 121: while(j<10)loop
 
B 11 -> 65 60 : : B 110 -> 60 61 : : B 110 -> 61 62: :
 
  
 
=== Exit Statements ===
 
=== Exit Statements ===
  
110: k:=k +2; 110: j:=j +1; 110: endloop;
 
         
 
 
Loop exit statements will include a branch which is taken when the exit is taken. The branch count should be less than the line count to indicate that both paths of the decision are taken. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage.
 
Loop exit statements will include a branch which is taken when the exit is taken. The branch count should be less than the line count to indicate that both paths of the decision are taken. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage.
  
81 : : 11 : j := 0; 82: ::loop
+
[[file:BCCS_28.jpeg|1200px]]
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
  83 : : B 11 -> 83 84: : B 11 -> 84 85: : B 11 -> 89
 
  
 
=== Case Statements ===
 
=== Case Statements ===
  
11 : k :=
 
11:j :=
 
11 : exit when (j < 10);
 
+ 86 : : 0 : k := k + 2; + 87 : : 0 : end loop;
 
k + 2; j+1;
 
           
 
 
Case statements will have a single branch at the top to handle the others case. Coverage of the when alternatives can be confirmed by line counts.
 
Case statements will have a single branch at the top to handle the others case. Coverage of the when alternatives can be confirmed by line counts.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_29.jpeg|1200px]]
96 : : B 5->110
 
98 : :
 
99 : : 100 : :
 
B 1->100
 
102 : : B 1->102
 
104 : : B 1->104
 
106 : : B 1->106
 
108 : : B 1->108
 
110 : : B 5->110
 
111 : :
 
  
 
=== If Statements ===
 
=== If Statements ===
  
11 : case (i) is
 
1 : k:=k + 1; : when 1 =>
 
1 : k:=k + 1;
 
1 : k:=k + 2;
 
1 : k:=k + 3;
 
1 : k:=k + 4;
 
1 : k:=k + 5;
 
5 : k:=k + 6; 11 : end case;
 
    97 : : : when 0 =>
 
      101 : : : when 2 =>
 
    103 : : : when 3 =>
 
    105 : : : when 4 =>
 
    107 : : : when 5 =>
 
    109 : : : when others =>
 
   
 
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is greater than zero but less than the line count then both paths of the decision have been tested.
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is greater than zero but less than the line count then both paths of the decision have been tested.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_30.jpeg|1200px]]
180: : 11: B 11 -> 184
 
+181::0:
 
184: : 11: + B 0 -> 188
 
if (ident(j) < 0) then j:=j+1;
 
if (ident(j) < 1000) then
 
    182 : : : end if; 183: : :
 
   
 
185 : : 11 : j := j + 1; B 11 -> 185
 
  
 
If statements conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
 
If statements conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
  
240 : : 11 : if ((ident(j) >= 0) and (ident(k) = 0)) then + B 0 -> 245
+
[[file:BCCS_31.jpeg|1200px]]
241 : : 11 : j := j + 1; B 11 -> 241
 
  
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
  
    186 : : : end if;
+
[[file:BCCS_32.jpeg|1200px]]
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
        242 : : : end if;
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
353 : : : -- second true
 
+
 
354: : B 0->359
 
355: : B 11 -> 359
 
358: : 359: :
 
B 11 -> 359
 
11 : if ((ident(j) >= 100000) or else
 
  11 :
 
(ident(k) = 0) or else
 
    + 356 : : 0 : (0 = ident(k)) or else + 357 : : 0 : (0 <= ident(j)))
 
360 : : : end if;
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
32 : : : /* 10 iterations */
 
: then
 
11 : j:=j+1;
 
 
 
  
 
== XLC/PPC ==
 
== XLC/PPC ==
Line 322: Line 185:
 
In a for loop, an index bounds test is completed at the top and bottom of the loop. The branches generated for those tests are associated with the first line of
 
In a for loop, an index bounds test is completed at the top and bottom of the loop. The branches generated for those tests are associated with the first line of
 
the loop, and the first is from the top of the loop and the second is from the bottom of the loop. test, the loop body was not executed (the difference of the counts).
 
the loop, and the first is from the top of the loop and the second is from the bottom of the loop. test, the loop body was not executed (the difference of the counts).
If the first branch count is less than the line count of the loop
+
If the first branch count is less than the line count of the loop test, the loop body was not executed (the difference of the counts).
  
 
+
[[file:BCCS_33.jpeg|1200px]]
33 : + B
 
: 100: for(j=0;j<10;j++) 0x -> 39
 
    B 90x -> 35
 
  34: ::{
 
35 :
 
36:
 
: 100: k=k+i;
 
::}
 
 
    
 
    
 
In a while loop, an loop exit test is completed at the top and bottom of the loop. The branches generated for those tests are associated with the first line of
 
In a while loop, an loop exit test is completed at the top and bottom of the loop. The branches generated for those tests are associated with the first line of
 
the loop, and the first is from the top of the loop and the second is from the bottom of the loop. test, the loop body was not executed (the difference of the counts).
 
the loop, and the first is from the top of the loop and the second is from the bottom of the loop. test, the loop body was not executed (the difference of the counts).
  
+
+
[[file:BCCS_34.jpeg|1200px]]
  
If the first branch count is less than the line count of the loop
 
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
55 : : : /* 10 iterations */
 
56: : 10: j=0;
 
57: : 100: while(j<10)
 
58: ::{
 
59 : 60 : 61 :
 
: 100 : : 100 : : 100 :
 
k = k + 2; j = j + 1; if (j < 5)
 
B
 
B 90x -> 59
 
0x -> 68
 
    B 60x -> 64
 
  62 : 63: 64: 65:
 
: 40 : continue; ::else :60: k++; ::}
 
   
 
 
In a do-while loop, an loop exit test is completed at the bottom of the loop. The branch generated for that test is associated with the last line of the loop. The loop body will have been executed one more time then the branch count, as confirmed by loop body line counts.
 
In a do-while loop, an loop exit test is completed at the bottom of the loop. The branch generated for that test is associated with the last line of the loop. The loop body will have been executed one more time then the branch count, as confirmed by loop body line counts.
  
76 : : : /* 10 iterations */
+
[[file:BCCS_35.jpeg|1200px]]
77: : 10: j=0;
 
  78: ::do 79: ::{
 
 
80 : : 100 : k = k + 2; 81 : : 100 : j = j + 1;
 
82: ::}
 
83: : 100: while(j<10);
 
B 90x -> 80
 
  
 
=== Conditional Operator (?) ===
 
=== Conditional Operator (?) ===
Line 371: Line 202:
 
Conditional operator expressions will generate one branch for each conditional operator (?). Conditional operators on a single line will include a branch to the same line which is for the FALSE condition. If the branch is not taken then the TRUE conditional has not been executed. If the branch is executed fewer times than the line count then both conditions have been executed.
 
Conditional operator expressions will generate one branch for each conditional operator (?). Conditional operators on a single line will include a branch to the same line which is for the FALSE condition. If the branch is not taken then the TRUE conditional has not been executed. If the branch is executed fewer times than the line count then both conditions have been executed.
  
103: : 10: k=(i>2?5:1); B 3 -> 103
+
[[file:BCCS_36.jpeg|1200px]]
  
 
Conditional operator expressions spanning multiple source lines allow for easier (not easy) determination of decisions tested.
 
Conditional operator expressions spanning multiple source lines allow for easier (not easy) determination of decisions tested.
  
    Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_37.jpeg|1200px]]
    Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
105 : B
 
B
 
108 : B
 
109 : +B
 
  
--- Switch Statements ===
+
=== Switch Statements ===
  
:10: 6->105
+
Switch statements with a default case will have a single branch to the default case which shows up as a branch to the top of the switch statement. (This is a conditional branch to an unconditional branch to the default case.) Line counts will indicate which cases have been executed.
0->105
 
:10: 6x -> 109
 
:4: 0x -> 109
 
k=(i>5?(i<10?5:1):7);
 
k=(i>5?
 
(i<10? 5:1):7);
 
    +
 
  
versus
+
[[file:BCCS_38.jpeg|1200px]]
 
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
 
 
          Switch statements with a default case will have a single branch to the default case which shows up as a branch to the top of the switch statement. (This is a conditional branch to an unconditional branch to the default case.) Line counts will indicate which cases have been executed.
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
120 :
 
B 4x -> 120
 
switch (i)
 
case 1:
 
case 2:
 
k = k + 2;
 
:10 :
 
    121: ::{
 
122 : : : case 0:
 
123 : : 1 : k = k + 1; 124 : : 1 : break;
 
125 :
 
128 : 129 : 130 :
 
133 : 136 :
 
139 : 140 : 141:
 
: :
 
: :
 
: 1 :
 
:
 
:
 
126 : : 1 : k = k + 1; 127 : : 1 : break;
 
  131 : : 2 : k = k + 3; 132 : : 2 : break;
 
:
 
: case 3:
 
  134 : : 1 : k = k + 4; 135 : : 1 : break;
 
: case 4:
 
: case 5:
 
: default:
 
k = k + 6;
 
  137 : : 1 : k = k + 5; 138 : : 1 : break;
 
:
 
: 4: ::}
 
 
    
 
    
 
Switch statements without a default will have branches for each case. Line counts will indicate which cases have been executed.
 
Switch statements without a default will have branches for each case. Line counts will indicate which cases have been executed.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_39.jpeg|1200px]]
143 : : : /* switch with no default */
 
144 :
 
B 1x -> 147
 
B 1x -> 150 B 1x -> 153 B 1x -> 155
 
switch (i)
 
case 1:
 
case 2:
 
k = k + 2;
 
: 10 :
 
      145: ::{
 
146 : : : case 0:
 
147 : : 1 : k = k + 1; 148 : : 1 : break;
 
    149 :
 
152 : 153 : 154 :
 
157:
 
: :
 
: : :1 : : :
 
150 : : 1 : k = k + 1; 151 : : 1 : break;
 
  case 3: ::}
 
155 : : 2 : k = k + 3; 156 : : 2 : break;
 
 
    
 
    
 
Switch statements with null or no statements will not have branches to those cases. For multiple cases with the same statements, each case will have a branch to the same source line.
 
Switch statements with null or no statements will not have branches to those cases. For multiple cases with the same statements, each case will have a branch to the same source line.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_40.jpeg|1200px]]
216 : : : /* switch with null alternatives */
 
217 :
 
B 60x -> 217
 
B 20x -> 222 B 10x -> 225 B 10x -> 225 B 10x -> 228 B 10x -> 231
 
switch (i)
 
: break;
 
: case 4:
 
: case 5:
 
: 100 :
 
      218: ::{
 
219 : : : case 0: 220: : : ; 221 : : : case 1:
 
        222 :
 
227 : 230 :
 
  
If Statements:
+
=== If Statements ===
 
 
: 20
 
: :
 
223 : : : case 2: 224 : : : case 3:
 
225 : : 20 : k = k + 3; 226 : : 20 : break;
 
  228 : : 10 : k = k + 4; 229 : : 10 : break;
 
  231 : : 10 : k = k + 5; 232 : : 10 : break;
 
233 : : : default: 234: : : ; 235: ::}
 
236: ::}
 
  
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is not the same as the line count then both paths of the decision have been tested.
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is not the same as the line count then both paths of the decision have been tested.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_41.jpeg|1200px]]
248 : : : /* never taken */
 
249: B
 
+ 251:
 
255: + B
 
: 10: 10 -> 255
 
: 0:
 
: 10: 0 -> 261
 
if(ident(j)<0) j = j + 1;
 
if (ident(j) < 1000)
 
    250: ::{
 
252: ::}
 
253: : :
 
254 : : : /* always taken */
 
    256: ::{
 
257 :
 
258: ::}
 
  
 
If statements with null/empty legs...TBD
 
If statements with null/empty legs...TBD
  
j = j + 1;
+
[[file:BCCS_42.jpeg|1200px]]
: 10 :
 
  261 : : 10 : if (ident(j) < 1000)
 
  
 
If statement conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
 
If statement conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
  
368: : 10: if((ident(j)>=0)& + B 0 -> 377
+
[[file:BCCS_43.jpeg|1200px]]
372: ::{
 
373 : : 10 : j = j + 1; 374: ::}
 
  
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
  
262: ::{ 263: ::; 264: ::}
+
[[file:BCCS_44.jpeg|1200px]]
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
367 : : : /* all true */
 
    369 : 370 : 371 :
 
: 10 : : 10 : : 10 :
 
(ident(k) == 0) & (0 == ident(k)) & (0 <= ident(j)))
 
    Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
440 : : : /* third true */
 
441 : + B
 
: 10 : if ((ident(j) >= 1111110) || 0x -> 442
 
    442 :
 
B 10x -> 443
 
: 10 : (1111110 == ident(k)) ||
 
   
 
+ +
 
443 :
 
B 0x->
 
444 : 445: 446 : 447:
 
: 10 : (ident(k) == 0) || 444
 
: 0 : (111110 <= ident(j))) ::{
 
: 10: j=j+1; ::}
 
  
 
== PowerAda/PPC ==
 
== PowerAda/PPC ==
Line 547: Line 248:
 
Straight-line code will often include exception checks for ranges and bounds. If straight-line code contains branches to the end of a subprogram then these are exception checks. Branch counts will indicate how many time the exception was raised.
 
Straight-line code will often include exception checks for ranges and bounds. If straight-line code contains branches to the end of a subprogram then these are exception checks. Branch counts will indicate how many time the exception was raised.
  
15 : : 11 : result := result + i; + B 0x -> 21
+
[[file:BCCS_45.jpeg|1200px]]
  
 
=== Loops ===
 
=== Loops ===
Line 553: Line 254:
 
All for loops will include a branch for the loop range check at the bottom. The normal loop range check should have a branch count less than the line count of the body statements to indicate the loop reached completion. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
 
All for loops will include a branch for the loop range check at the bottom. The normal loop range check should have a branch count less than the line count of the body statements to indicate the loop reached completion. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
  
B 99x -> 35
+
[[file:BCCS_46.jpeg|1200px]]
  
 
For loops with dynamic bounds will test for a null loop range at the top of the loop and contain a branch to the next statement which is taken when the loop range is null.
 
For loops with dynamic bounds will test for a null loop range at the top of the loop and contain a branch to the next statement which is taken when the loop range is null.
  
29 : : 11 : for l in integer range Ident(1)..Ident(0) loop B 11 -> 34
+
[[file:BCCS_47.jpeg|1200px]]
B 0 -> 34
 
  
 
While loops will test the loop exit condition at the top of the loop and contain a branch to the next statement which is taken when the loop exit is taken. While loops will test the loop exit condition at the bottom of the loop too and contain a branch to the top of the loop which is taken when the loop continues. The loop exit condition should have a line count greater than the line count of the body statements to indicate the loop reached completion. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
 
While loops will test the loop exit condition at the top of the loop and contain a branch to the next statement which is taken when the loop exit is taken. While loops will test the loop exit condition at the bottom of the loop too and contain a branch to the top of the loop which is taken when the loop continues. The loop exit condition should have a line count greater than the line count of the body statements to indicate the loop reached completion. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_48.jpeg|1200px]]
      Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
33 : : : -- 10 iterations
 
34 : 35 : 36:
 
: 11 : for l in integer range 0..9 loop : 110 : k := k + i;
 
: 110: endloop;
 
    Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
28 : : : -- no iterations
 
    +
 
  + 30 : : 0 : k := k + i; + 31 : : 0 : end loop;
 
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
 
67 : : : -- 10 iterations
 
68 : : 11 : j := 0;
 
69 : : 11 : while (j < 10) loop
 
+B 70 :
 
+B 71 :
 
+B B
 
  
 
=== Exit Statements ===
 
=== Exit Statements ===
  
0x -> 75
 
: 110: k:=k+2;
 
0x -> 100
 
: 110: j:=j+1;
 
0x -> 100 99x -> 70
 
           
 
 
Loop exit statements will include a branch which is taken when the exit is taken. The branch count should be less than the line count to indicate that both paths of the decision are taken. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage.
 
Loop exit statements will include a branch which is taken when the exit is taken. The branch count should be less than the line count to indicate that both paths of the decision are taken. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_49.jpeg|1200px]]
83 : : : -- 10 iterations
 
84: 85: 86:
 
+ B 87:
 
+ B 88:
 
B 89:
 
+ B
 
: 11: j:= 0; ::loop :110:k :=
 
0x -> 93
 
:110: j :=
 
0x -> 93
 
:110: exit
 
11x -> 92
 
:99: k:=
 
0x -> 93
 
k+2;
 
j+1;
 
when (j >= 10); k+2;
 
                  90 : : : end loop;
 
  
 
=== Case Statements ===
 
=== Case Statements ===
Line 614: Line 274:
 
Case statements will have a branch for each alternative listed. The others alternative will have branches associated with values not handled by the specified alternatives, including values below the range, above the range, and values in between. Coverage of the when alternatives can be confirmed by line counts. Coverage of out of bound values can be confirmed by the branch counts.
 
Case statements will have a branch for each alternative listed. The others alternative will have branches associated with values not handled by the specified alternatives, including values below the range, above the range, and values in between. Coverage of the when alternatives can be confirmed by line counts. Coverage of out of bound values can be confirmed by the branch counts.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_50.jpeg|1200px]]
99 : + B
 
: 11: 0x -> 113
 
case (i) is
 
k:=k+ 1; k:=k+ 1; k:=k+ 2; k:=k+ 3; k:=k+ 4; k:=k+ 5; k:=k+ 6;
 
    B 1x -> 101 B 1x -> 103 B 1x -> 105 B 1x -> 107 B 1x -> 109 B 1x -> 111
 
100 : : : when 0 =>
 
          101 : + B
 
103 : + B
 
105 : + B
 
107 : + B
 
109 : + B
 
111 : + B
 
113 : + B
 
  
 
=== If Statements ===
 
=== If Statements ===
 
: 1: 0x -> 135
 
: 1: 0x -> 135
 
: 1: 0x -> 135
 
: 1: 0x -> 135
 
: 1: 0x -> 135
 
: 1: 0x -> 135
 
: 5: 0x -> 135
 
    102 : : : when 1 =>
 
    104 : : : when 2 =>
 
    106 : : : when 3 =>
 
    108 : : : when 4 =>
 
    110 : : : when 5 =>
 
    112 : : : when others =>
 
    114 : : : end case;
 
  
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is greater than zero but less than the line count then both paths of the decision have been tested.
 
If statements will include (at least) one branch for the condition of each leg. If the branch count is greater than zero but less than the line count then both paths of the decision have been tested.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_51.jpeg|1200px]]
182 : : : -- never taken
 
183 :
 
B 11x -> 187
 
if (ident(j) < 0) then j := j + 1;
 
if (ident(j) < 1000) then j := j + 1;
 
    +
 
+ +
 
: 11:
 
: 0:
 
184 :
 
187 :
 
B 0x-> 191
 
185 : : : end if; 186: : :
 
: 11:
 
    188 :
 
B 0x-> 432
 
11:
 
:
 
    189 : : : end if;
 
  
 
If statements conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
 
If statements conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_52.jpeg|1200px]]
227 : + B
 
228 : + B
 
: 11: if((k<0)or(ident(j)>=0))then 0x -> 231
 
: 11: j:=j+1; 0x -> 432
 
        229 : : : end if;
 
  
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
 
If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.
  
Line Edge/Branch Line Cnt Source ------ ----------- --------- ------- - -
+
[[file:BCCS_53.jpeg|1200px]]
356 : : : -- second true
 
+
 
+
 
357 : : B 0x-> 362
 
11 :
 
if ((ident(j) >= 100000) or else (ident(k) = 0) or else
 
then
 
j := j + 1;
 
  358 :
 
B 11x -> 362
 
: 11 :
 
    + 359 : : 0 : (0 = ident(k)) or else + 360 : : 0 : (0 <= ident(j)))
 
361 : 362 :
 
: :
 
: 11 : B 0x-> 432
 
    363 : : : end if;
 

Latest revision as of 22:22, 16 July 2018

Branch Coverage Cheat Sheet

This document provides information about interpreting the Branch Coverage Reports produced from data collected by the predefined probes coverage,ual (and brcov.ual) and the tool abrmerge. There are sections providing general guidance and sections for target-specific and compiler-specific guidance.

General Guidance

This section provides guidance applicable to all target ins compilers.

Markers/Colors

A source line with no line count (no color / no marker) is either a line with no object code and can be ignored or it is part of a subprogram for which coverage was not requested.

BCCS 1.jpeg

A source line with a positive line count (no marker / green color) is OK (has been executed).

BCCS 2.jpeg

A source line with a zero line count (+ marker / yellow color) needs attention (has not been executed).

BCCS 3.jpeg

A source line with a zero line count (* marker / red color) needs attention (has not been instrumented).

BCCS 4.jpeg

A branch with positive count (green color) is OK (has been executed).

BCCS 5.jpeg

A branch with a zero count (+ marker / yellow color) need attention (has not been executed).

BCCS 6.jpeg

A branch with a zero count (+ marker / red color) need attention (has not been instrumented).

BCCS 7.jpeg

Multiple Branches Per Line

Lines with multiple branches may be easier to work with if the source code is modified to put one decision per line.

BCCS 8.jpeg

versus

BCCS 9.jpeg

C/x86

This section provides guidance for GNU C compiler (gcc) on x86.

Functions

At the end of a function the closing brace may have a line count of 0 due to a patching problem. This is fixed in ap.4.4.63/7. Otherwise, the 0 line count can be ignored.

Loops

In a for loop, the index bounds test is completed at the top of the loop. If the branch associated with the for loop in not taken, then the body of the loop will not have been executed (line counts should be 0).

BCCS 10.jpeg

In a for loop, the index bounds test is completed at the top of the loop. The line count of the for loop should be greater than the branch count of the for loop because the final bounds check will fail and not branch back to the loop body.

BCCS 11.jpeg

In a while loop, the while test is completed at the top of the loop. If the branch associated with the while loop in not taken, then the body of the loop will not have been executed (line counts should be 0).

BCCS 12.jpeg

In a while loop, the while test is completed at the bottom of the loop. The line count of the while loop should be greater than the branch count of the for loop because the final while test will fail and not branch back to the loop body.

BCCS 13.jpeg

In a do-while loop, the while test is completed at the bottom of the loop. The line count of the do-while loop should be greater than the branch count of the for loop because the final while test will fail and not branch back to the loop body.

BCCS 14.jpeg

Conditional Operator (?)

Conditional operator expressions will generate one branch for each conditional operator (?).

Conditional operators on a single line will include a branch to the same line which is for the FALSE condition. If the branch is not taken then the TRUE conditional has not been executed. If the branch is executed fewer times than the line count then both conditions have been executed.

BCCS 15.jpeg

Conditional operator expressions spanning multiple source lines allow for easier (not easy) determination of decisions tested.

BCCS 16.jpeg

versus

BCCS 17.jpeg

Switch Statements

Switch statements with a default case will have a single branch to the default case and use a jump table for the rest. Line counts will indicate which cases have been executed.

BCCS 18.jpeg

Switch statements without a default will have branches for each case. Line counts will indicate which cases have been executed. There will also be a branch to the same line as the switch expression (which represents the default case) which is executed when no explicit cases are executed.

BCCS 19.jpeg

Switch statements with null or no statements will have branches to the next statement following the switch statement. If the switch statement is at the end of a loop, the next statement may be the loop condition test, whose source line number may/will be at the top of the loop.

BCCS 20.jpeg

If Statements

If statements will include (at least) one branch for the condition of each leg. If the branch count is not the same as the line count then both paths of the decision have been tested.

BCCS 21.jpeg

If statements with null/empty legs...TBD

BCCS 21a.jpeg

If statement conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)

BCCS 22.jpeg

If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.

BCCS 23.jpeg

GNAT Ada/x86

Exception Checks

Straight-line code will often include exception checks for ranges and bounds. If straight-line code contains branches to the same line then these are exception checks. If the branch counts are the same as the line counts then the exception checks passed and an exception was not raised.

BCCS 24.jpeg

Loops

All for loops will include a branch for the loop range check at the top. The normal loop range check should have a line count greater than the line count of the body statements to indicate the loop reached completion and the branch count should be non-zero to indicate the exit was taken. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.

BCCS 25.jpeg

For loops with dynamic bounds will test for a null loop range at the top of the loop and contain a branch to the next statement which is taken when the loop range is null.

BCCS 26.jpeg

While loops will test loop exit condition at the top of the loop and contain a branch to the next statement which is taken when the loop exit is taken. The loop exit condition should have a line count greater than the line count of the body statements to indicate the loop reached completion. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.

BCCS 27.jpeg

Exit Statements

Loop exit statements will include a branch which is taken when the exit is taken. The branch count should be less than the line count to indicate that both paths of the decision are taken. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage.

BCCS 28.jpeg

Case Statements

Case statements will have a single branch at the top to handle the others case. Coverage of the when alternatives can be confirmed by line counts.

BCCS 29.jpeg

If Statements

If statements will include (at least) one branch for the condition of each leg. If the branch count is greater than zero but less than the line count then both paths of the decision have been tested.

BCCS 30.jpeg

If statements conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)

BCCS 31.jpeg

If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.

BCCS 32.jpeg

XLC/PPC

This section covers the IBM XLC compiler on AIX PPC targets.

Functions

At the end of a function the closing brace may have a line count of 0. This can be safely ignored.

Loops

In a for loop, an index bounds test is completed at the top and bottom of the loop. The branches generated for those tests are associated with the first line of the loop, and the first is from the top of the loop and the second is from the bottom of the loop. test, the loop body was not executed (the difference of the counts). If the first branch count is less than the line count of the loop test, the loop body was not executed (the difference of the counts).

BCCS 33.jpeg

In a while loop, an loop exit test is completed at the top and bottom of the loop. The branches generated for those tests are associated with the first line of the loop, and the first is from the top of the loop and the second is from the bottom of the loop. test, the loop body was not executed (the difference of the counts).

BCCS 34.jpeg

In a do-while loop, an loop exit test is completed at the bottom of the loop. The branch generated for that test is associated with the last line of the loop. The loop body will have been executed one more time then the branch count, as confirmed by loop body line counts.

BCCS 35.jpeg

Conditional Operator (?)

Conditional operator expressions will generate one branch for each conditional operator (?). Conditional operators on a single line will include a branch to the same line which is for the FALSE condition. If the branch is not taken then the TRUE conditional has not been executed. If the branch is executed fewer times than the line count then both conditions have been executed.

BCCS 36.jpeg

Conditional operator expressions spanning multiple source lines allow for easier (not easy) determination of decisions tested.

BCCS 37.jpeg

Switch Statements

Switch statements with a default case will have a single branch to the default case which shows up as a branch to the top of the switch statement. (This is a conditional branch to an unconditional branch to the default case.) Line counts will indicate which cases have been executed.

BCCS 38.jpeg

Switch statements without a default will have branches for each case. Line counts will indicate which cases have been executed.

BCCS 39.jpeg

Switch statements with null or no statements will not have branches to those cases. For multiple cases with the same statements, each case will have a branch to the same source line.

BCCS 40.jpeg

If Statements

If statements will include (at least) one branch for the condition of each leg. If the branch count is not the same as the line count then both paths of the decision have been tested.

BCCS 41.jpeg

If statements with null/empty legs...TBD

BCCS 42.jpeg

If statement conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)

BCCS 43.jpeg

If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.

BCCS 44.jpeg

PowerAda/PPC

This section covers the OCS PowerAda compiler for the PPC target.

Exception Checks

Straight-line code will often include exception checks for ranges and bounds. If straight-line code contains branches to the end of a subprogram then these are exception checks. Branch counts will indicate how many time the exception was raised.

BCCS 45.jpeg

Loops

All for loops will include a branch for the loop range check at the bottom. The normal loop range check should have a branch count less than the line count of the body statements to indicate the loop reached completion. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.

BCCS 46.jpeg

For loops with dynamic bounds will test for a null loop range at the top of the loop and contain a branch to the next statement which is taken when the loop range is null.

BCCS 47.jpeg

While loops will test the loop exit condition at the top of the loop and contain a branch to the next statement which is taken when the loop exit is taken. While loops will test the loop exit condition at the bottom of the loop too and contain a branch to the top of the loop which is taken when the loop continues. The loop exit condition should have a line count greater than the line count of the body statements to indicate the loop reached completion. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage. Testing for 0, 1, and multiple loop executions should be achieved with separate test runs.

BCCS 48.jpeg

Exit Statements

Loop exit statements will include a branch which is taken when the exit is taken. The branch count should be less than the line count to indicate that both paths of the decision are taken. Using short circuits operators in the loop exit condition will increase the number of branches, and each should be executed for complete coverage.

BCCS 49.jpeg

Case Statements

Case statements will have a branch for each alternative listed. The others alternative will have branches associated with values not handled by the specified alternatives, including values below the range, above the range, and values in between. Coverage of the when alternatives can be confirmed by line counts. Coverage of out of bound values can be confirmed by the branch counts.

BCCS 50.jpeg

If Statements

If statements will include (at least) one branch for the condition of each leg. If the branch count is greater than zero but less than the line count then both paths of the decision have been tested.

BCCS 51.jpeg

If statements conditions with multiple boolean operators will have one branch associated with the whole condition. If the boolean operands are spread on separate source lines they will all have the same line count. (See short circuit operators.)

BCCS 52.jpeg

If statement conditions with short circuit operators will have one branch for each operand of the short circuit operator. If a branch has a count of 0 then that path has not been executed. If the boolean operands are spread on separate source lines they will have separate line counts which will indicate if each operand was executed.

BCCS 53.jpeg