Trouble executing with stubs
I've made a couple of stubs using the "Lesson 15: Configuring Stub Behavior in Source Code" chapter in "C++test Host-Based Unit Testing" guide.
After running "Collect Stub Information" I created User Stubs for the functions I needed to stub. Trying to execute my test case give the error:function "CPPTEST_STUB_CALLBACK_PARAMS" declared implicitly
C/C++ Test created the stub function:
EXTERN_C_LINKAGE E_TIMER_STATUS TimerSvc_Start (E_TIMER_ID timId, uint32_t time) ;
EXTERN_C_LINKAGE E_TIMER_STATUS CppTest_Stub_TimerSvc_Start (E_TIMER_ID timId, uint32_t time)
{
CPPTEST_STUB_CALLED("TimerSvc_Start");
E_TIMER_STATUS __return = TIMER_ERROR;
/**
* This section enables Dynamic Stub Configuration with Stub Callbacks.
*
* IMPORTANT: THIS COMMENT BLOCK SHOULD NOT BE DELETED OR MODIFIED
*
* 1. Define stub callback function in test suite file - use the following signature:
* void CppTest_StubCallback_SomeName(CppTest_StubCallInfo* stubCallInfo, E_TIMER_STATUS* __return, E_TIMER_ID timId, uint32_t time)
*
* 2. Register stub callback in test case function - use the following code:
* CPPTEST_REGISTER_STUB_CALLBACK("TimerSvc_Start", &CppTest_StubCallback_SomeName);
*
* 3. Fill out the body of the stub callback function according to intent.
* The following line may be used to call original function inside stub callback:
* *__return = TimerSvc_Start(timId, time);
*/
if (CPPTEST_STUB_HAS_CALLBACK()) {
CPPTEST_STUB_CALLBACK_PARAMS(E_TIMER_STATUS* __return, E_TIMER_ID timId, uint32_t time);
CPPTEST_STUB_INVOKE_CALLBACK(&__return, timId, time);
} else {
/* You can put additional stub logic here. */
}
return __return;
}
Using the guide I changed the function to:
EXTERN_C_LINKAGE E_TIMER_STATUS CppTest_Stub_TimerSvc_Start (E_TIMER_ID timId, uint32_t time)
{
E_TIMER_STATUS __return = TIMER_ERROR;
CPPTEST_CALL_STUB_CALLBACK("TimerSvc_Start", &__return, timId, time);
return __return;
}
And registered the stub in my test case.
void CppTest_StubCallback_TimerSvc_Start(CppTest_StubCallInfo* stubCallInfo, E_TIMER_STATUS* __return, E_TIMER_ID timId, uint32_t time)
{
printf("CppTest_StubCallback_TimerSvc_Start\r\n");
//*__return = TimerSvc_Start(timId, time);
}
/* CPPTEST_TEST_CASE_BEGIN test_SensorMgr_On_01 */
/* CPPTEST_TEST_CASE_CONTEXT E_SENSOR_MGR_STATE SensorMgr_On(void) */
void SensorMgr_unit_test_test_SensorMgr_On_01()
{
/* Pre-condition initialization */
CPPTEST_REGISTER_STUB_CALLBACK("TimerSvc_Start", &CppTest_StubCallback_TimerSvc_Start);
/* Initializing global variable sensorMgrState */
{
sensorMgrState = SENSOR_OFF;
}
{
/* Tested function call */
E_SENSOR_MGR_STATE _return = SensorMgr_On();
/* Post-condition check */
CPPTEST_POST_CONDITION_ENUM(E_SENSOR_MGR_STATE, "E_SENSOR_MGR_STATE _return", ( _return ));
CPPTEST_POST_CONDITION_ENUM(E_SENSOR_MGR_STATE, "E_SENSOR_MGR_STATE sensorMgrState", ( sensorMgrState ));
}
}
But when I execute (not in FileScope) I get the "Quality Task":Message: Invalid stub configuration - cannot use Stub Callbacks for "TimerSvc_Start" (hint: re-create stub with "Dynamic stubs configuration> Enable Stub Callbacks" option enabled)
If I execute in FileScope mode I get a linker error:
IAR ELF Linker V8.22.2.15995/W32 for ARM Copyright 2007-2018 IAR Systems AB. Error[Li005]: no definition for "TimerSvc_Start" [referenced from C:\Users\swtest\parasoft\workspace\.cpptest\ADC_AnalogWatchdog_test\file-data\SensorMgr.c922fb77f\tested\harness_SensorMgr.o]
My Test Configurations are based on "Run IAR ARM Tests" and work fine without stubs.
Any help?
BR, Thomas Damgaard