Home > User Support > CoverageMaster winAMS FAQ

CoverageMaster winAMS FAQ

Object File, OMF Conversion

102_08: How to test an inline function or a macro defined function?

Question:

How do I test an inline function specified by a #pragma or inline keyword or a macro defined function?

Answer:

In order to test a function using CoverageMaster, it is necessary to generate code as a function object with debug information symbols. In order to test directly by the function name (same for creating a stub function), it is necessary to remove the inline expansion or macro definition format and compile as an ordinary function object. However, in doing so the object code structure will be modified.

<About the test method>

For inline functions and macro defined sub functions, code is embedded into the test function as one function object. Therefore, not testing the inline function or the macro-defined sub function as another function and testing it as is, will be the most faithful test to the actual code.

The method for testing an inline function or a macro-defined sub function is described further in detail below.

Macro defined functions:
A sub function defined by macro is handled as one process (1 executable statement line) in the function to be tested, and its internal coverage cannot be measured. If you want to measure the coverage of a function written by macro and test it by directly giving test data from the CSV, the macro definition must be removed and compiled as a normal function.
As one method, we recommend first testing the function in embedded state, then as a supplementary test, remove the macro definition to convert it into a function object, and perform unit testing and coverage measurement of only the macro defined function.

testfunc()    // test function
{
  subfunc();    // macro defined function, cannot measure coverage within subfunc()
}

subfunc()
{
    :
}

It is necessary to remove the macro definition in order to test alone or measure coverage.

If it is necessary to confirm that there is no change in the function of the test function as a result of removing the macro definition format, we recommend comparing the test results (output values) of the test function with and without the macro definition format.

testfunc()    // test function
{
  subfunc();    // macro defined function
}

testfunc()    // test function
{
  subfunc();    // macro definition removed function
}

By confirming that the test results are the same for the above 2 testfunc() implementations, it can be confirmed that there is no impact on testfunc() by removing the macro definition.

Inline functions:
Sub functions that are inline expanded by compiler optimizations or inline specifications called by the test function are only measured for code coverage when C0 coverage measurement hook code has been inserted.

However, since a function object has not been created in this case, it is not possible to stub it, or test it by giving data directly from the CSV file.

When hook code has not been inserted, coverage cannot be measured like the case with macro defined functions.

In order to perform these, it must be compiled as a normal function without inline expansion.

testfunc()    // test function
{
  subfunc();    // inline function, can measure coverage within subfunc()
}

subfunc()
{
    :
}

However, it is necessary to remove the inline expansion in order to test alone.

If it is necessary to confirm that there is no change in the function of the test function as a result of removing the inline expansion, we recommend comparing the test results (output values) of the test function with and without the inline expansion.

testfunc()    // test function
{
  subfunc();    // inline function
}

testfunc()    // test function
{
  subfunc();    // inline expansion removed function
}

By confirming that the test results are the same for the above 2 testfunc() implementations, it can be confirmed that there is no impact on testfunc() by removing the inline expansion.



Related Technical Tips Search

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

Search key word link: Inline Function
Technical Tips Google Search


Information Links