Unit coverage

Code Coverage for Ada

Unit Entries

Unit entries determine which units are executed and/or evaluated.

-- Function factorial                                                       

-- -proc

function factorial ( a : in integer ) return integer is

begin

      if ( a > 0 ) then

        return a * factorial ( a - 1 );

      else

        return 1;

      end if;

end factorial ;

One branch is defined for each defined and instrumented unit.  In the case of a package, the unit entry only exists if the package body contains the begin/end instruction block.

For Protected units, no unit entry is defined because this kind of unit does not have any statements blocks.

Unit Exits and Returns

These are the standard exit (if it is coverable), each return instruction (from a procedure or function), and each exception-processing block in the unit.

-- Function factorial                                                   

-- -proc=ret

function factorial ( a : in integer ) return integer is

begin

  if ( a > 0 ) then

      return a * factorial ( a - 1 );

  else

      return 1;

  end if ;

end factorial ; -- the standard exit is not coverable

-- Procedure divide

procedure divide ( a,b : in integer; c : out integer ) is

begin

     if ( b == 0 ) then

       text_io.put_line("Division by zero" );

       raise CONSTRAINT_ERROR;

     end if ;

     if ( b == 1 ) then

       c := a;

       return;

     end if ;

     c := a / b;

exception

  when PROGRAM_ERROR => null ;

end divide ;

 

For Protected units, no exit is defined because this kind of unit does not have any statements blocks.

In general, at least two branches per unit are defined; however, in some cases the coding may be such that:

The entry is always numbered if it exists.  The exit is also numbered if it is coverable.  If it is not coverable, it is preceded by a terminal instruction containing return or raise instructions; otherwise, it is preceded by an infinite loop.

A raise is considered to be terminal for a unit if no processing block for this exception was found in the unit.

Related Topics

Selecting coverage typesCode Coverage settings