Home > User Support > CoverageMaster winAMS FAQ
Question:
A library function is called from the test target function. Is it possible to generate a stub function of this library function and use it for testing by using the stub function generation feature of CoverageMaster?
Answer:
It is possible by making the library function a skeleton (empty function).
In order to create a stub function with the CoverageMaster stub creation feature, the original function must be in C and debug information must be output. Normally, debug information is not output to library functions, so stubs cannot be created based on library functions.
For example, even if you build/OMF convert the sample code below in which the library function "__mulu()" is called, "__mulu" does not appear in the "Stub Settings" screen of WinAMS so it cannot be replaced with a stub function.
unsigned int test(unsigned char a, unsigned char b)
{
unsigned int retVal = __mulu(a, b);
return retVal;
}
This can be avoided by not linking library functions, and instead creating a dummy function (empty function) that has an API as a C language function, compiling and linking, and recreating the object file. In this way the symbol name of the library (sub) function will be displayed in the Stub Settings screen, so a stub function can be created for it.
[Reference]
An empty function can be created manually, or a dummy function can be created using CasePlayer2's "Create Skeleton for Undefined Func/Var" feature.
When creating a skeleton for a function that does not have a definition, the "Create data for func/var skeletons" setting in the "Analysis Settings" must first be enabled (see image below as a reference). As a result, CasePlayer2 analyzes the source files registered in the project and collects information of functions/variables without definitions when creating documents.
Open the dialog by selecting "Project" -> "Create Skeleton for Undefined Func/Var".
Select the library (sub) function ("__mulu" in the above example) to create a skeleton for in the "<<Do not create skeleton for function>>" list and click the "Add >>" button. This will add the selected function to the "<<Create skeleton for function>>" list on the right.
This will automatically generate "CasePlayer2StubSrcFile.c" with the skeleton function implemented as below.
/* CP2_STUB_FUNC[__mulu] */
unsigned int __mulu(unsigned char arg11,unsigned char arg15)
{
static unsigned char volatile CP2_AMOUT_arg11;
static unsigned char volatile CP2_AMOUT_arg15;
static unsigned int volatile CP2_AMIN_return;
CP2_AMOUT_arg11 = arg11;
CP2_AMOUT_arg15 = arg15;
return CP2_AMIN_return;
}
Add this source file to the compiler build environment and Build -> OMF convert.
Other technical tips in GAIO's web site can be searched for using the links below.
Search key word link: Library function stub
Related Technical Tips Search