Home > User Support > CoverageMaster winAMS FAQ

CoverageMaster winAMS FAQ

Test Data Settings

301_03: I am using complex linked structures with pointers (lists, etc.). Is there an efficient way to setup test data for these complex structures?

Question:

I am using complex linked structures with pointers (lists, etc.). To create test data for these variables, setting up pointers 1 by 1 is possible, but laborious. Is there a more efficient way to setup meaningful test data?

Answer:

When using complex linked structures, individually setting up pointers in CoverageMaster for each member of the structure can be laborious. Here we present a way to efficiently use dummy variables to easily generate the desired test data.

Sample program: main.h

struct ST_PARAM
{
    int data;
    int ret_code;
} gb_result;

typedef struct st_Leaf {
      int No;
      void *pstCmd;
} T_Leaf;

typedef struct st_Second {
      int No;
      T_Leaf *pstLeaf;
} T_Second;


typedef struct st_Top {
      int No;
      T_Second *pstSecond;
} T_Top;

typedef struct TEST
{
      int enable;
      int mode;
      int input;
} T_test1;

 Sample program: main.c

void func1(T_Top * param)
{
        int enable,mode,input;
        enable = ( (T_test1 *)(param->pstSecond->pstLeaf->pstCmd) ) -> enable;
        mode   = ( (T_test1 *)(param->pstSecond->pstLeaf->pstCmd) ) -> mode;
        input  = ( (T_test1 *)(param->pstSecond->pstLeaf->pstCmd) ) -> input;

        if( enable )
        {
                switch( mode )
                {
                case 0:
                        gb_result.data = input;
                        break;
                case 1:
                        gb_result.data = input * 10;
                        break;
                case 2:
                        gb_result.data = input * 100;
                        break;
                case 3:
                        if( input>100 ) 
                                gb_result.data = 10000;
                        else
                                gb_result.data = input*100;
                        break;
                default:
                        gb_result.data = -1;
                }
                // return code
                gb_result.ret_code = TRUE;
        }
        else
        {
                gb_result.data = 0;
                gb_result.ret_code = FALSE;
        }
}

Step 1:
Create the dummy symbols to assign test data to. (They can be declared in any arbitrary source file, as long as it is compiled and linked in the final object file).

Sample program: dummy.c

T_test1 DBG_test1;?// Actually contains the test data
T_Leaf DBG_Leaf = { 0, (void *)&DBG_test1};
T_Second DBG_Second = { 0, &DBG_Leaf};
T_Top DBG_param = { 0, &DBG_Second };  // Parameter for the tested function

Step 2:

In the Unit Test CSV Settings, select the function parameter func1@param as an input variable. Select "Address" in Pointer Settings.


Click to enlarge

Step 3:
Add the debug symbols DBG_test1.enable, DBG_test1.mode, DBG_test1.input as input variables.


Click to enlarge

Step 4:
In CSV files, addresses can be input using symbol names instead of numerical values.
In ATDEditor or Excel, edit the input CSV file to give to the parameter @param the value DBG_param (to give it the address of the dummy variable DBG_param). Give the desired values to the other dummy member variables DBG_test1.enable, DBG_test1.mode and DBG_test1.input.


Click to enlarge

This way, without setting up the complex linked structure, the desired values of the relevant member variables can be easily assigned.

 

Related Technical Tips Search

Other technical tips in GAIO's web site can be searched for using the links below.

Search key word link: linked structure
Technical Tips Google Search


Information Links