Block coverage

Code Coverage for Ada

When analyzing Ada source code, Code Coverage can provide the following block coverage types:

Statement blocks (or simple blocks)

Simple blocks are the main blocks within units as well as blocks introduced by decisions, such as:

A simple block constitutes one branch. Each unit contains at least one simple block corresponding to its body, except packages that do not contain an initialization block.

Decision coverage (implicit blocks)

An if statement without an else statement introduces an implicit block.

-- Function power_10                         

-- -block=decision or -block=implicit

function power_10 ( value, max : in integer) return integer is

   ret, i : integer ;


     if ( value == 0 ) then

        return 0;

     -- implicit else block

     end if ;

     for i in 0..9


     if ( (max /10) <  ret ) then

           ret := ret *10 ;


           ret := max ;

         end if ;

     end loop ;

    return ret;

end ;


An implicit block constitutes one branch.

Implicit blocks refer to simple blocks to describe possible decisions. The Code Coverage report presents the sum of these decisions as an absolute value and a ratio.

Loop coverage (logical blocks)

A for or while loop constitutes three branches:

A loop...end loop block requires only two branches because the exit condition, if it exists, is tested within the loop:

In the following example, you need to execute the function try_five_times() several times for 100 % coverage of the three logical blocks induced by this while loop.

-- Function try_five_times                                        

function try_five_times return integer is

   result, i : integer := 0 ;


  -- try is any function

  while ( i < 5 ) and then ( result <= 0 ) loop

      result := try ;

      i := integer'succ(i);

  end loop ;

  return result;

end ; -- 3 logical blocks


Logical blocks are attached to the loop introduction keyword.

Asynchronous transfer of control (ATC) blocks

This coverage type is specific to the Ada 95 asynchronous transfer of control (ATC) block statement (see your Ada documentation).

The ATC block contains tree branches:

In the following example, you need to execute the compute_done function several times to obtain full coverage of the three ATC blocks induced by the select statement:

function compute_done return boolean is                               

   result : boolean := true ;


  -- if computing is not done before 10s ...


    delay 10.0;

    result := false ;

  then abort


  end select;

  return result;

end ; -- 3 logical blocks


Code Coverage blocks are attached to the Select keyword of the ATC statement.

Related Topics

Selecting coverage typesCode Coverage settings