Home > User Support > CoverageMaster winAMS FAQ

CoverageMaster winAMS FAQ

Test Data Settings

111_01: How can I specify a void type pointer variable as an input/output variable in a CSV file?

Question:

I'm trying to test a function that has a void pointer as an argument. The passed pointer variable of type void is cast to another type in the function. How can I specify such a void type pointer variable as an input/output variable in a CSV file?

Answer:

A pointer variable of void type cannot be directly specified as an input/output variable in a CSV file (the pointer variable itself can be made a test variable by address specification, but the value to which the pointer points can't be given from the test CSV). Instead a dummy function (driver function) can be used as described below.

Sample code:

(test.h)
typedef struct _TEST_ST {
    signed char a;
    signed int  b;
} TEST_ST;

(test.c)
#include "test.h"

int test(void *pv)
{
    TEST_ST *pst = (TEST_ST *)pv;

    if (pst->a < 0) {
        return -1;
    } else {
        return pst->b;
    }
}

To use the members "a" and "b" of the structure "TEST_ST" as test variables in the above example, execute a test using a dummy function. See also the following FAQ for a test using a dummy function.

014_04: The input data cannot be entered from the CSV file to the target function's arguments. Is there a workaround?

Specifically, first create a new dummy function as shown below. Add the dummy function to the build environment, rebuild the object file and re-execute the OMF conversion. Create a global variable of the same type as is being casted by void pointer in the function being tested (see "*" below).

Dummy function (driver function):

(dummy.c)
#include "test.h"

extern int test(void*);
TEST_ST test_st; // *

int dummy_for_test(void)
{
    return test((void *)&test_st);
}

Next, create a unit test CSV using "dummy_for_test()" as the test target function. As shown in the image below, check the "Using test driver" checkbox and set the original test target function "test()" as the "Measure coverage for function".

Now "test_st.a" and "test_st.b" can be used as test variables.
For example, the following test data can be created for testing the function.



Related Technical Tips Search

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

Search key word link: void Pointer
Technical Tips Google Search


Information Links