Testing Ada Tasks

Component Testing for Ada

As a general matter, OneTest Embedded Component Testing for Ada was designed for synchronous programming. However, it is possible to achieve component testing even in an asynchronous environment.

The important detail is that any task which might be producing Runtime Analysis information (especially by calling stubbed procedures or functions) must be terminated when control reaches the END ELEMENT instruction in the .ptu test script.

If the code under test does not provide select statements or entry points in order to request the termination of the task, an abort call to the task might be necessary. For tasks who terminate after a certain time (not entering a infinite loop), the tester might check the task’s state and sleep until termination of the task. In the .ptu test script, this might read as follows:

#while not TaskX’Terminated loop

#   delay 1;

#end loop;


This instruction block is placed just before the END ELEMENT statement of the Test Script.


The source files and complete .ptu script for following example are provided in the examples/Ada_Task directory.

In this example, the task calls a stubbed procedure. Therefore the task must be terminated from within the Test Script. Two different techniques of starting and stopping the task are shown here in Test 1 and Test 2.

HEADER Prg_Under_Tst, 0.3, 0.0

#with Pck_Stub;

BEGIN Prg_Under_Tst


#with Text_IO;

#procedure Proc_Stubbed is


# Text_IO.Put_Line("Stub called.");





    #Param_1 : duration;

    #task1 : Prioritaire;

    TEST 1

    FAMILY nominal


       VAR   Param_1, init = duration(0), ev = init

   STUB  Pck_Stub.Proc_Stubbed 1..1 => ()


    #delay duration(5);



    END TEST -- TEST 1

    TEST 2

    FAMILY nominal


       VAR   Param_1, init = duration(2), ev = init

   STUB  Pck_Stub.Proc_Stubbed 1..1 => ()


          #   Task2 : T_Prio := new Prioritaire;


    #  Task2.Do_Something_Useful(Param_1);

    #  Task2.Unit_Testing_Exit_Loop;

    #  Task2.Unit_Testing_Wait_Termination;



    END TEST -- TEST 2



In the BEGIN line of the script, it is not necessary to add the name of the separate procedure Attol_Test, as this is the default name;

The user code within the STUB contains a context clause and some custom native Ada instructions.

In both Test 1 and Test 2 it is necessary not only to stop the main loop of the task before reaching the END ELEMENT instruction, but also the task itself in order to have the tester return.

Task1 and Task2 could run in parallel, however, the test Report would be unable to distinguish between the STUB calls coming in from either task, and would show the calls in a cumulative manner.

The entry points Unit_Testing_Exit_Loop and Unit_Testing_Wait_Termination can be considered as implementations for testing purposes only. They might not be used in the deployment phase.

The second test is False in the Report, the loop runs twice. This allows to check that the dump goes through smoothly.