Declaring global variables for testing

Component Testing for Ada

The Target Deployment Ports for Ada do not provide any variables that can be used freely by the tester.

To avoid having to modify the code under test, it is easier to add an extra C package, which is actually just the spec part of the package, to provide a set of globally accessible variables. You can do this directly in the .ptu test script.

Declaring Global Variables

Any code inserted between the HEADER and BEGIN keywords is copied into the generated code as is. For example:

Header Code_Under_Test, 1.0, 1.0

    #With Code_Under_Test; -- only if Code_Under_Test is used within My_Globals

    -- this context clause goes into the package My_Globals

    #package My_Globals is

    #     Global_Var_Integer : Integer := 0;

    #end My_Globals;

    #with Code_Under_Test;

    #with My_Globals;

    -- these two context clauses go into the generated test harness


-- etc..


Note   Any Ada instruction between HEADER and the BEGIN instruction must be encapsulated into a procedure or a package. Context clauses are possible.

Accessing Global Variables

The extra global variable package is visible from within all units of the test driver.

Variables can be accessed like this:

#My_Globals.Global_Var_Integer := 1;


Variables can be accessed from a DEFINE STUB block for example:

Define Stub Another_Package

#with My_Globals;

#procedure some_proc (param : in out some_type) is


#     My_Globals.Global_Var_Integer := 2;

#end some_proc;

-- however, no "return" statement is possible within this block

End Define


Variables can be accessed in the ELEMENT blocks, just like any other variable:

VAR My_Globals.Global_Var_Integer, init = 0, EV = 1


OneTest Embedded processes the .ptu test script in such a way that global variable package automatically becomes a separate compilable unit.

Related Topics

Testing variablesTesting intervalsTesting expressionsHandling global variables with stubs