Condition Coverage

Code Coverage for Ada

Basic Conditions

Basic conditions are operands of logical operators (standard or derived, but not overloaded) or, xor, and, not, or else, or and then, wherever they appear in ADA units.  They are also the conditions of if, while, exit when, when of entry body, and when of select statement, even if these conditions do not contain logical operators.  For each of these basic conditions, two branches are defined: the sub-condition is true and the sub-condition is false.

A basic condition is also defined for each when of a case statement, even each sub-expression of a compound when, that is when A | B: two branches.

-- power_of_10 function                                                     -- -cond

Function power_of_10( value, max : in integer )

is

   result : integer ;

Begin

     if value = 0 then

        return 0;

     end if ;

     result := value ;

     for i in 0..9 loop

       if ( max > 0 ) and then (( max / value ) < result ) then

          result := result * value;

       else

          result := max ;

       end if ;

     end loop;

     return result ;

end ; -- there are 3 basic conditions (and 6 branches).

-- Near_Color function

Function Near_Color ( color : in ColorType ) return ColorType

is

Begin

     case color is

       when WHITE | LIGHT_GRAY => return WHITE ;

       when RED | LIGHT_RED .. PURPLE => return RED ;

     end case ;

End ; -- there are 4 basics conditions (and 4 branches).

Two branches are enumerated for each boolean basic condition, and one per case basic condition.

Forced Conditions

A forced condition is a multiple condition in which any occurrence of the or else operator is replaced with the or operator, and the and then operator is replaced with the and operator.  This modification forces the evaluation of the second member of these operators.  You can use this coverage type after modified conditions have been reached to ensure that all the contained basic conditions have been evaluated.  With this coverage type, you can be sure that only the considered basic condition value changes between both condition vectors.

-- Original source :                                        -- -cond=forceevaluation

  if ( a and then b ) or else c then

-- Modified source :

  if ( a and      b ) or      c then

Note   This replacement modifies the code semantics. You need to verify that using this coverage type does not modify the behavior of the software.

Example

procedure P ( A : in tAccess ) is

begin

  if A /= NULL and then A.value > 0     -- the evaluation of A.value will raise an

                                        -- exception when using forced conditions

                                        -- if the A pointer is nul

  then

    A.value := A.value - 1;

  end if;

end P;

 

Modified Conditions

A modified condition is defined for each basic condition enclosed in a composition of logical operators (standard or derived, but not overloaded).  It aims to prove that this condition affects the result of the enclosing composition.  To do that, find a subset of values affected by the other conditions, for example, if the value of this condition changes, the result of the entire expression changes.

Because compound conditions list all possible cases, you must find the two cases that can result in changes to the entire expression. The modified condition is covered only if the two compound conditions are covered.

-- State_Control state                                             -- -cond=modified

Function State_Condtol return integer

is

Begin

     if  ( ( flag_running and then ( process_count > 10 ) )

           or else flag_stopped )

     then

         return VALID_STATE ;

     else

         return INVALID_STATE ;

     end if ;

End ;

-- There are 3 basic conditions, 5 compound conditions

--     and 3 modified conditions :

--      flag_running : TTX=T and FXF=F

--      process_count > 10 : TTX=T and TFF=F

--      flag_stopped : TFT=T and TFF=F, or FXT=T and FXF=F

--     4 test cases are enough to cover all the modified conditions :

--      TTX=T

--      FXF=F

--      TFF=F

--      FTF=F or FXT=T

 

Note   You can associate a modified condition with more than one case, as shown in this example for flag_stopped.  In this example, the modified condition is covered if the two compound conditions of at least one of these cases are covered.

Code Coverage calculates cases for each modified condition.

The same number of modified conditions as boolean basic conditions appear in a composition of logical operators (standard or derived, but not overloaded).

Multiple Conditions

A multiple condition is one of all the available cases of logical operators (standard or derived, but not overloaded) wherever it appears in an ADA unit.  Multiple conditions are defined by the concurrent values of the enclosed basic boolean conditions.

A multiple condition is noted with a set of T, F, or X letters, which means that the corresponding basic condition evaluates to true or false, or it was not evaluated, respectively. Such a set of letters is called a condition vector. The right operand of or else or and then logical operators is not evaluated if the evaluation of the left operand determines the result of the entire expression.

-- State_Control Function                                          -- -cond=compound

Function State_Control return integer

is

Begin

     if  ( ( flag_running and then ( process_count > 10 ) )

           or else flag_stopped

     then

         return VALID_STATE ;

     else

         return INVALIDE_STATE ;

     end if ;

End ;

-- There are 3 basic conditions

--    and 5 compound conditions :

--      TTX=T <=> ((T and then T) or else X ) = T

--      TFT=T

--      TFF=F

--      FXT=T

--      FXF=F

Code Coverage calculates the computation of every available case for each composition.

The number of enumerated branches is the number of distinct available cases for each composition of logical operators (standard or derived, but not overloaded).

Related Topics

Selecting coverage typesCode Coverage settings