blob: 843025dcab5b63632c0c2401b39bd9ea1eeb619e [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2018 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
///////////////////////////////////////////////////////////////////////////////
//
// File: EPTF_MBT_LGen_Functions.ttcn
// Rev: <RnXnn>
// Prodnr: CNL 113 659
// Updated: 2010-10-01
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
module EPTF_MBT_LGen_Functions
{
import from EPTF_MBT_LGen_Definitions all;
import from EPTF_CLL_Logging_Definitions all;
import from EPTF_CLL_Logging_Functions all;
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_Variable_Functions all;
import from EPTF_CLL_Scheduler_Definitions all;
import from EPTF_CLL_Base_Definitions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_LGenBase_ConfigDefinitions all;
import from EPTF_CLL_LGenBase_ConfigFunctions all;
import from EPTF_CLL_LGenBase_Functions all;
import from EPTF_CLL_LGenBase_Definitions all;
import from EPTF_CLL_LGenBase_EventHandlingFunctions all;
import from EPTF_CLL_LGenBase_StepFunctions all;
import from EPTF_CLL_RBTScheduler_Functions all;
import from EPTF_CLL_Semaphore_Functions all;
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_init
//
// Purpose:
// Function to initialize MBT behaviour
//
// Parameters:
// pl_selfName - *in* *charstring* - the components self name
// pl_selfId - *in* *integer* - component self id
// pl_entityNamePrefix - *in* *charstring* - entity name prefix
// pl_numEntities - *in* *integer* - number of entities
// pl_bind - *in* <EPTF_LGenBase_BehaviorContextBinder_FT> - behaviour
// context bind callback function
// pl_reset - *in* <EPTF_LGenBase_BehaviorContextHandler_FT> - behaviour
// context reset callback function
// pl_unbind - *in* <EPTF_LGenBase_BehaviorContextHandler_FT> - behaviour
// context unbind callback function
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_init
(
in charstring pl_selfName,
in integer pl_selfId,
in charstring pl_entityNamePrefix,
in integer pl_numEntities := 0,
in EPTF_LGenBase_BehaviorContextBinder_FT pl_bind := refers(f_EPTF_MBT_bindEntity),
in EPTF_LGenBase_BehaviorContextHandler_FT pl_reset := refers(f_EPTF_MBT_resetEntity),
in EPTF_LGenBase_BehaviorContextHandler_FT pl_unbind := refers(f_EPTF_MBT_unbindEntity)
)
runs on EPTF_MBT_LGen_CT
{
if(v_EPTF_MBT_initialized)
{
f_EPTF_Logging_warning(true,%definitionId&": The FTD applib on this component is already initialized!");
return;
}
f_EPTF_LGenBase_init(pl_selfName);
f_EPTF_Logging_init_CT(pl_selfName);
f_EPTF_Semaphore_init_CT(pl_selfName);
f_EPTF_Base_registerCleanup(refers(f_EPTF_MBT_cleanup_CT));
v_EPTF_MBT_myBIdx :=
f_EPTF_LGenBase_declareBehaviorType
(c_EPTF_MBT_myBName,
-1,
pl_reset,
pl_bind,
pl_unbind
);
f_EPTF_MBT_declareEvents();
f_EPTF_MBT_declareTestSteps();
v_EPTF_MBT_LoggingMaskId := f_EPTF_Logging_registerComponentMasks("FTD_Logging", {"ERROR", "WARNING", "DEBUG"}, EPTF_Logging_CLL);
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, %definitionId & ": myBIdx is " & int2str(v_EPTF_MBT_myBIdx));
activate(as_EPTF_MBT_PCO_Handler());
map(self:EPTF_MBT_PCO, system:EPTF_MBT_PCO);
v_EPTF_MBT_initialized := true;
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_cleanup_CT
//
// Purpose:
// Cleanup function of the MBT Applib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// Unmaps the TestPorts from teh System
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_cleanup_CT()
runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, "### " & %definitionId);
if (v_EPTF_MBT_initialized)
{
unmap(self:EPTF_MBT_PCO, system:EPTF_MBT_PCO);
v_EPTF_MBT_initialized := false;
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_declareEvents
//
// Purpose:
// Register the EVents used by the MBT AppLib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_declareEvents()
runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, "### " & %definitionId);
var integer vl_temp := -1;
vl_temp := f_EPTF_LGenBase_declareFsmEvent(c_EPTF_MBT_myBName,c_EPTF_MBT_inputName_incomingUserRequest);
f_EPTF_Base_assert(%definitionId&": Error during registration of "&c_EPTF_MBT_inputName_incomingUserRequest, vl_temp == c_EPTF_MBT_inputIdx_incomingUserRequest);
vl_temp := f_EPTF_LGenBase_declareFsmEvent(c_EPTF_MBT_myBName,c_EPTF_MBT_inputName_incomingTestStepRequest);
f_EPTF_Base_assert(%definitionId&": Error during registration of "&c_EPTF_MBT_inputName_incomingTestStepRequest, vl_temp == c_EPTF_MBT_inputIdx_incomingTestStepRequest);
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_declareTestSteps
//
// Purpose:
// Register the TestSteps used by the MBT AppLib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_declareTestSteps()
runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, "### " & %definitionId);
f_EPTF_LGenBase_declareStep(
pl_bName:=c_EPTF_MBT_myBName,
pl_step:={name:=c_EPTF_MBT_stepName_invokeTestStep,
step:=refers(f_EPTF_MBT_TestStep_invokeTestStep)});
f_EPTF_LGenBase_declareStep(
pl_bName:=c_EPTF_MBT_myBName,
pl_step:={name:=c_EPTF_MBT_stepName_invokeUserFunction,
step:=refers(f_EPTF_MBT_TestStep_invokeUserFunction)});
f_EPTF_LGenBase_declareStep(
pl_bName:=c_EPTF_MBT_myBName,
pl_step:={name:=c_EPTF_MBT_stepName_sendUserResponse,
step:=refers(f_EPTF_MBT_TestStep_sendUserResponse)});
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_bindEntity
//
// Purpose:
// Bind function of the MBT AppLib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_bindEntity(in integer pl_eIdx)
runs on EPTF_MBT_LGen_CT
return EPTF_IntegerList
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, "### " & %definitionId & "() with eIdx: " & int2str(pl_eIdx));
//var integer v_EPTF_MBT_index := sizeof(v_EPTF_MBT_Contexts);
//v_EPTF_MBT_Contexts[v_EPTF_MBT_index] := c_MBT_DefaultCtx;
//v_EPTF_MBT_Contexts[v_EPTF_MBT_index].eIdx := pl_eIdx;
//return {v_EPTF_MBT_index};
return {-1};
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_unbindEntity
//
// Purpose:
// Unbind function of the MBT AppLib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_unbindEntity(in integer pl_eIdx)
runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, "### " & %definitionId & "() with eIdx: " & int2str(pl_eIdx));
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_resetEntity
//
// Purpose:
// Reset function of the MBT AppLib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
//////////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_resetEntity(
in integer pl_eIdx)
runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, "### " & %definitionId & "() with eIdx: " & int2str(pl_eIdx));
}
//*****************************************************************************
// TestSteps of the MBT AppLib
//*****************************************************************************
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_TestStep_invokeTestStep
//
// Purpose:
// General Purpose wrapper TestStep to select the Proper TestStep based on its
// actual parameters and invokes it. Otherwise generates a log&console statement
//
// Parameters:
// in EPTF_LGenBase_TestStepArgs pl_ptr
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_TestStep_invokeTestStep(in EPTF_LGenBase_TestStepArgs pl_ptr) runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "() "));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() pl_ptr: ", pl_ptr));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() v_EPTF_MBT_TestStepRequest: ", v_EPTF_MBT_TestStepRequest));
//var integer vl_fnIdx := f_EPTF_LGenBase_functionNameIndex(v_EPTF_MBT_TestStepRequest.stepName);
//var EPTF_LGenBase_TestStepFunction_FT vl_fn:=null;
var EPTF_LGenBase_RegisteredFunctions vl_fn;
if (f_EPTF_LGenBase_functionReferenceByName(v_EPTF_MBT_TestStepRequest.stepName, vl_fn))
{
pl_ptr.refContext.fRefArgs := v_EPTF_MBT_TestStepRequest.stepArgs;
if (ispresent(v_EPTF_MBT_TestStepRequest.addr))
{
pl_ptr.eIdx := v_EPTF_MBT_TestStepRequest.addr.eIdx;
pl_ptr.refContext.fCtxIdx := v_EPTF_MBT_TestStepRequest.addr.fIdx;
}
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() executing ", v_EPTF_MBT_TestStepRequest.stepName));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() with pl_ptr: ", pl_ptr));
//f_EPTF_LGenBase_getTesStepFunctionRef(v_EPTF_MBT_TestStepRequest.stepName, vl_fn);
f_EPTF_LGenBase_functionReferenceByName(v_EPTF_MBT_TestStepRequest.stepName, vl_fn);
if (ischosen(vl_fn.testStepFunction))
{
vl_fn.testStepFunction.apply(pl_ptr);
if(ispresent(v_EPTF_MBT_TestStepRequest.lock) and v_EPTF_MBT_TestStepRequest.lock > -1)
{
f_EPTF_Semaphore_unlock(v_EPTF_MBT_TestStepRequest.lock);
}
}
else
{
f_EPTF_Logging_warning(true, log2str(%definitionId & "(): Function was found, but not a test step: " & v_EPTF_MBT_TestStepRequest.stepName));
}
}
else
{
f_EPTF_Logging_warning(true, log2str(%definitionId & "(): Step was not found: " & v_EPTF_MBT_TestStepRequest.stepName));
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_TestStep_sendUserResponse
//
// Purpose:
// TestStep function to generate the User response,. It shall be invoked in case
// of the unhandled events (FSM description) based on the generated event it
// sends back a response towards the Tester component
//
// Parameters:
// in EPTF_LGenBase_TestStepArgs pl_ptr
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_TestStep_sendUserResponse(in EPTF_LGenBase_TestStepArgs pl_ptr) runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "() "));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() pl_ptr: ", pl_ptr));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() vf_EPTF_MBT_createUserResponse: ", vf_EPTF_MBT_createUserResponse));
var boolean vl_autoResp := true;
if(vf_EPTF_MBT_createUserResponse!=null)
{
vl_autoResp := not vf_EPTF_MBT_createUserResponse.apply(pl_ptr);
}
if (vl_autoResp)
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() v_LGenBase_reportedEvent: ",pl_ptr.reportedEvent));
var integer vl_grpIdx := f_EPTF_LGenBase_getEGrpOfEntity(pl_ptr.eIdx);
var integer vl_eIdx := pl_ptr.eIdx - f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx);
var EPTF_MBT_TestStepResponse vl_resp :=
{
bName := f_EPTF_LGenBase_bIdx2Str(pl_ptr.reportedEvent.event.bIdx),
iName := f_EPTF_LGenBase_iIdx2Str(pl_ptr.reportedEvent.event.bIdx,pl_ptr.reportedEvent.event.iIdx), //TODO later one of the TestStep args will decsribe the events that has been dispatcehd
addr :=
{
entityGroupName := f_EPTF_LGenBase_entityGroupName(vl_grpIdx),
eIdx := pl_ptr.eIdx,
fIdx := pl_ptr.refContext.fCtxIdx
}
}
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() user response: ", vl_resp));
var EPTF_IntegerList vl_ctx := f_EPTF_LGenBase_getBehaviorCtx(pl_ptr.eIdx, v_EPTF_MBT_myBIdx);
EPTF_MBT_PCO.send(vl_resp) to f_EPTF_Base_downcast(vl_ctx[0]);
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_TestStep_invokeUserFunction
//
// Purpose:
// TestStep function to invoke user specific function
//
// Parameters:
// in EPTF_LGenBase_TestStepArgs pl_ptr
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// It seraches for the user declared function basedon its name
// (stored in a component variable) and invokes it.)
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_TestStep_invokeUserFunction(in EPTF_LGenBase_TestStepArgs pl_ptr) runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "() "));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() pl_ptr: ", pl_ptr));
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() v_EPTF_MBT_UserRequest: ", v_EPTF_MBT_UserRequest));
var integer vl_fnIdx := f_EPTF_LGenBase_functionNameIndex(v_EPTF_MBT_UserRequest.functionName);
var EPTF_LGenBase_RegisteredFunctions vl_fn;
if (vl_fnIdx > 0)
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() v_EPTF_MBT_UserRequest: ",v_EPTF_MBT_UserRequest));
//vl_fn.apply(pl_ptr);
//f_EPTF_LGenBase_getTesStepFunctionRef(v_EPTF_MBT_TestStepRequest.stepName, vl_fn);
if (f_EPTF_LGenBase_functionReferenceByName(v_EPTF_MBT_TestStepRequest.stepName, vl_fn))
{
if (ischosen(vl_fn.testStepFunction))
{
vl_fn.testStepFunction.apply(pl_ptr);
}
else
{
f_EPTF_Logging_warning(true, log2str(%definitionId & "(): Function was found, but not a test step: " & v_EPTF_MBT_TestStepRequest.stepName));
}
}
else
{
f_EPTF_Logging_warning(true, log2str(%definitionId & "(): Step was not found: " & v_EPTF_MBT_TestStepRequest.stepName));
}
}
else
{
f_EPTF_Logging_warning(true, log2str(%definitionId & "(): Step was not found: " & v_EPTF_MBT_UserRequest.functionName));
}
var integer vl_grpIdx := f_EPTF_LGenBase_getEGrpOfEntity(pl_ptr.eIdx);
var integer vl_eIdx := pl_ptr.eIdx - f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx);
var EPTF_MBT_TestStepResponse vl_resp :=
{
bName := c_EPTF_MBT_myBName,
iName :=f_EPTF_LGenBase_iIdx2Str(v_EPTF_MBT_myBIdx,pl_ptr.reportedEvent.event.iIdx), //TODO later one of the TestStep args will decsribe the events that has been dispatcehd
addr :=
{
entityGroupName := f_EPTF_LGenBase_entityGroupName(vl_grpIdx),
eIdx := pl_ptr.eIdx,
fIdx := pl_ptr.refContext.fCtxIdx
}
}
var EPTF_IntegerList vl_ctx := f_EPTF_LGenBase_getBehaviorCtx(pl_ptr.eIdx, v_EPTF_MBT_myBIdx);
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() user response: ", vl_resp));
EPTF_MBT_PCO.send(vl_resp) to f_EPTF_Base_downcast(vl_ctx[0]);
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_Listener_catchEntityEvents
//
// Purpose:
// This is a listener to catch all entity level events. Because unhandled
// events in the FSM descriptor can catch only FSM level events.
//
// Parameters:
// in EPTF_LGenBase_ReportedEventDescriptor pl_event
// in EPTF_IntegerList pl_listenerArgs
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_Listener_catchEntityEvents(
EPTF_LGenBase_ReportedEventDescriptor pl_event,
EPTF_IntegerList pl_listenerArgs
) runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "() "));
if (ispresent(pl_event.event.target) and not ispresent(pl_event.event.target.fsmCtxIdx))
{
// Only for entity level events
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() entity level event caught, calling sendUserResponse"));
var EPTF_LGenBase_TestStepArgs vl_args :=
{
eIdx := pl_event.event.target.eIdx,
refContext :=
{
fCtxIdx := -1, //related FSM context of the entity, if invoked via FSM
fRefArgs := {} //args supplied in the context from which the step is referenced
}, //FSM cell & context if invoked from FSM
stepArgs:= {},
reportedEvent:=pl_event
}
f_EPTF_MBT_TestStep_sendUserResponse(vl_args);
}
else
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() dropping"));
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_Listener_catchGenericEvents
//
// Purpose:
// This is a listener to catch all generic level events. Because unhandled
// events in the FSM descriptor can catch only FSM level events.
//
// Parameters:
// in EPTF_LGenBase_ReportedEventDescriptor pl_event
// in EPTF_IntegerList pl_listenerArgs
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_Listener_catchGenericEvents(
EPTF_LGenBase_ReportedEventDescriptor pl_event,
EPTF_IntegerList pl_listenerArgs
) runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "() "));
if (true /*ispresent(pl_event.event.target) and not ispresent(pl_event.event.target.fsmCtxIdx)*/)
{
// Only for entity level events
/*
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() generic level event caught, calling sendUserResponse"));
var EPTF_LGenBase_TestStepArgs vl_args :=
{
eIdx := pl_event.event.target.eIdx,
refContext :=
{
fCtxIdx := -1, //related FSM context of the entity, if invoked via FSM
fRefArgs := {} //args supplied in the context from which the step is referenced
}, //FSM cell & context if invoked from FSM
stepArgs:= {},
reportedEvent:=pl_event
}
f_EPTF_MBT_TestStep_sendUserResponse(vl_args);
*/
action("Generic caught: ", pl_event);
}
else
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "() dropping"));
}
}
//////////////////////////////////////////////////////////////////
//
//
// Event Handler
//
//
////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Function: as_EPTF_MBT_PCO_Handler
//
// Purpose:
// EventHandler of the MBT AppLib
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// Handles the following cases
// In case of an incomming TestStep Request dispatches the
// c_EPTF_MBT_inputIdx_incomingTestStepRequest event
// incomming Config Request configure the LoadGens creates the
// entity goups activate the fsms...etc
// incomming Command Request executes the requested command
// -
// incomming User Request dispatches the
// c_EPTF_MBT_inputIdx_incomingUserRequest event
///////////////////////////////////////////////////////////////////////////////
altstep as_EPTF_MBT_PCO_Handler() runs on EPTF_MBT_LGen_CT
{
var EPTF_MBT_Tester_CT vc_from;
[] EPTF_MBT_PCO.receive(EPTF_MBT_TestStepRequest:?) -> value v_EPTF_MBT_TestStepRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_FTD_TestStepRequest: ",v_EPTF_MBT_TestStepRequest));
var integer vl_eIdx := 0;
var integer vl_fIdx := 0;
if (ispresent(v_EPTF_MBT_TestStepRequest.addr))
{
var integer vl_grpIdx := f_EPTF_LGenBase_entityGrpNameIndex(v_EPTF_MBT_TestStepRequest.addr.entityGroupName);
vl_eIdx := f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx);
if (ispresent(v_EPTF_MBT_TestStepRequest.addr.eIdx)) { vl_eIdx := vl_eIdx + v_EPTF_MBT_TestStepRequest.addr.eIdx }
if (ispresent(v_EPTF_MBT_TestStepRequest.addr.fIdx)) { vl_fIdx := v_EPTF_MBT_TestStepRequest.addr.fIdx }
}
f_EPTF_LGenBase_dispatchEvent({{v_EPTF_MBT_myBIdx, c_EPTF_MBT_inputIdx_incomingTestStepRequest,{vl_eIdx, vl_fIdx}, omit},{}});
repeat;
}
[] EPTF_MBT_PCO.receive(EPTF_MBT_EventDispatchRequest:?) -> value v_EPTF_MBT_EventDispatchRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_MBT_EventDispatchRequest: ",v_EPTF_MBT_EventDispatchRequest));
var integer vl_eIdx := 0;
var integer vl_fIdx := 0;
var integer vl_grpIdx := f_EPTF_LGenBase_entityGrpNameIndex(v_EPTF_MBT_EventDispatchRequest.addr.entityGroupName);
vl_eIdx := f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx);
if (ispresent(v_EPTF_MBT_EventDispatchRequest.addr.eIdx)) { vl_eIdx := vl_eIdx + v_EPTF_MBT_EventDispatchRequest.addr.eIdx }
if (ispresent(v_EPTF_MBT_EventDispatchRequest.addr.fIdx)) { vl_fIdx := v_EPTF_MBT_EventDispatchRequest.addr.fIdx }
var integer vl_bIdx := f_EPTF_LGenBase_behaviorTypeNameIndex(v_EPTF_MBT_EventDispatchRequest.bName);
var integer vl_iIdx := v_EPTF_MBT_EventDispatchRequest.iName
f_EPTF_LGenBase_dispatchEvent({{vl_bIdx, vl_iIdx,{vl_eIdx, vl_fIdx}, omit},{}});
repeat;
}
[] EPTF_MBT_PCO.receive(EPTF_MBT_ConfigRequest:?) -> value v_EPTF_MBT_ConfigRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_MBT_ConfigRequest: ", v_EPTF_MBT_ConfigRequest));
var integer vl_senderInt := f_EPTF_Base_upcast(vc_from);
f_EPTF_LGenBase_declareEntityType
(
v_EPTF_MBT_ConfigRequest.entityGroupName & "_Type",
v_EPTF_MBT_ConfigRequest.behaviors
);
f_EPTF_LGenBase_createEntityGroup
(
{
v_EPTF_MBT_ConfigRequest.entityGroupName,
v_EPTF_MBT_ConfigRequest.entityGroupName & "_Type",
v_EPTF_MBT_ConfigRequest.noEntities
}
);
if (vf_EPTF_MBT_entityGroupCreated != null)
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "(): calling ", vf_EPTF_MBT_entityGroupCreated));
vf_EPTF_MBT_entityGroupCreated.apply(v_EPTF_MBT_ConfigRequest);
}
var integer vl_grpIdx := f_EPTF_LGenBase_entityGrpNameIndex(v_EPTF_MBT_ConfigRequest.entityGroupName);
var integer vl_entityIdx := f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx);
var integer vl_fsmTableIdx := f_EPTF_LGenBase_fsmNameIndex(v_EPTF_MBT_ConfigRequest.fsmName);
for (var integer i:=0; i<v_EPTF_MBT_ConfigRequest.noEntities; i:=i+1)
{
f_EPTF_LGenBase_activateFsm(i + vl_entityIdx, vl_fsmTableIdx, 0, -1);
f_EPTF_LGenBase_setBehaviorCtx(i + vl_entityIdx, v_EPTF_MBT_myBIdx, {vl_senderInt});
f_EPTF_LGenBase_addEntityIdxListener(i + vl_entityIdx, refers(f_EPTF_MBT_Listener_catchEntityEvents), {})
}
EPTF_MBT_PCO.send(EPTF_MBT_ConfigResponse:{}) to vc_from;
repeat;
}
[] EPTF_MBT_PCO.receive(EPTF_MBT_CreateFSMRequest:?) -> value v_EPTF_MBT_CreateFSMRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_MBT_CreateFSMRequest: ", v_EPTF_MBT_CreateFSMRequest));
var integer vl_senderInt := f_EPTF_Base_upcast(vc_from);
var integer vl_grpIdx := f_EPTF_LGenBase_entityGrpNameIndex(v_EPTF_MBT_CreateFSMRequest.entityGroupName);
var integer vl_entityIdx := f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx) + v_EPTF_MBT_CreateFSMRequest.eIdx;
var integer vl_fsmTableIdx := f_EPTF_LGenBase_fsmNameIndex(v_EPTF_MBT_CreateFSMRequest.fsmName);
var integer vl_fIdx := f_EPTF_LGenBase_activateFsm(vl_entityIdx, vl_fsmTableIdx, 0, -1);
f_EPTF_LGenBase_setBehaviorCtx(vl_entityIdx, v_EPTF_MBT_myBIdx, {vl_senderInt});
f_EPTF_LGenBase_addEntityIdxListener(vl_entityIdx, refers(f_EPTF_MBT_Listener_catchEntityEvents), {})
var EPTF_MBT_CreateFSMResponse vl_resp :=
{
result := 0,
addr :=
{
entityGroupName := v_EPTF_MBT_CreateFSMRequest.entityGroupName,
eIdx := v_EPTF_MBT_CreateFSMRequest.eIdx,
fIdx := vl_fIdx
}
}
EPTF_MBT_PCO.send(vl_resp) to vc_from;
repeat;
}
[] EPTF_MBT_PCO.receive(EPTF_MBT_RemoveFSMRequest:?) -> value v_EPTF_MBT_RemoveFSMRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_MBT_RemoveFSMRequest: ", v_EPTF_MBT_RemoveFSMRequest));
var integer vl_senderInt := f_EPTF_Base_upcast(vc_from);
var integer vl_grpIdx := f_EPTF_LGenBase_entityGrpNameIndex(v_EPTF_MBT_RemoveFSMRequest.addr.entityGroupName);
var integer vl_entityIdx := f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx) + v_EPTF_MBT_RemoveFSMRequest.addr.eIdx;
var integer vl_fsmIdx := v_EPTF_MBT_RemoveFSMRequest.addr.fIdx;
f_EPTF_LGenBase_deactivateFsm(vl_entityIdx, vl_fsmIdx);
var EPTF_MBT_RemoveFSMResponse vl_resp :=
{
result := 0
}
EPTF_MBT_PCO.send(vl_resp) to vc_from;
repeat;
}
[] EPTF_MBT_PCO.receive(EPTF_MBT_CommandRequest:?) -> value v_EPTF_MBT_CommandRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_MBT_CommandRequest: ",v_EPTF_MBT_CommandRequest));
if (ischosen(v_EPTF_MBT_CommandRequest.quit))
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str(%definitionId & "(): calling Base_stopAll"));
f_EPTF_Base_stopAll(pass, true); // FIXME noCleanup should be false.
}
else
{
f_EPTF_Logging_warning(true, log2str(%definitionId & "(): unhandled command: ", v_EPTF_MBT_CommandRequest));
repeat;
}
EPTF_MBT_PCO.send(EPTF_MBT_CommandResponse:{ quitAck := {} }) to vc_from;
}
[] EPTF_MBT_PCO.receive(EPTF_MBT_UserRequest:?) -> value v_EPTF_MBT_UserRequest sender vc_from
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "(): incoming v_EPTF_MBT_UserRequest: ",v_EPTF_MBT_UserRequest));
var integer vl_eIdx := 0;
var integer vl_fIdx := 0;
if (ispresent(v_EPTF_MBT_UserRequest.addr))
{
var integer vl_grpIdx := f_EPTF_LGenBase_entityGrpNameIndex(v_EPTF_MBT_UserRequest.addr.entityGroupName);
vl_eIdx := f_EPTF_LGenBase_getEGrpBaseOffset(vl_grpIdx);
if (ispresent(v_EPTF_MBT_UserRequest.addr.eIdx)) { vl_eIdx := vl_eIdx + v_EPTF_MBT_UserRequest.addr.eIdx }
if (ispresent(v_EPTF_MBT_UserRequest.addr.fIdx)) { vl_fIdx := v_EPTF_MBT_UserRequest.addr.fIdx }
}
f_EPTF_LGenBase_dispatchEvent({{v_EPTF_MBT_myBIdx, c_EPTF_MBT_inputIdx_incomingUserRequest,{vl_eIdx, vl_fIdx}, omit},{}});
}
[] EPTF_MBT_PCO.receive
{
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_EPTF_Logging_warning(true, "### " & %definitionId & "(): dropping message");
repeat;
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_initLGenFsm
//
// Purpose:
// This function inits the MBT FSM
//
// Parameters:
// in fcb_EPTF_MBT_customUserFunction p_userFunc - sets the callback that shall create the UserResponses
// in fcb_EPTF_MBT_entityGroupCreated p_entityGroupCreateFunc - sets the callback to handle entity group created
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_initLGenFsm
(
in fcb_EPTF_MBT_customUserFunction p_userFunc,
in fcb_EPTF_MBT_entityGroupCreated p_entityGroupCreateFunc
)
runs on EPTF_MBT_LGen_CT
{
f_EPTF_Logging_debug(tsp_EPTF_MBT_LGen_debug, log2str("### " & %definitionId & "() "));
vf_EPTF_MBT_createUserResponse := p_userFunc;
vf_EPTF_MBT_entityGroupCreated := p_entityGroupCreateFunc;
var integer v_dummyInt := f_EPTF_LGenBase_declareFSMTable(
{
//DOT: digraph FSM_MBT {
name := "FSM_MBT",
fsmParams :=
{
{
stateList := { "main" }
}
},
table :=
{
extendedTable := {
{events2Listen :={
events:= {
{singleEvent:={
bName:=c_EPTF_LGenBase_behavior,
iName:=c_EPTF_LGenBase_inputName_testMgmt_startTC,
eventType:=fsm}
}}},
cellRow := {
classicCellRow := {
{//state[0]==main
//DOT: main -> main [label="i:startTC\n"]
actionList:=omit,
nextStateCalculation:=omit,
nextState:="main"
}
} // classicCellRow
} // cellRow
},
{events2Listen := {
events:= {
{singleEvent:={
bName:=c_EPTF_MBT_myBName,
iName:=c_EPTF_MBT_inputName_incomingTestStepRequest,
eventType:=fsm}
}}},
cellRow := {
classicCellRow := {
{//state[0]==main
//DOT: main -> main [label="i:incomingTestStepRequest\n a:step_invokeTestStep"]
actionList:={{stepOrFunctionName:=c_EPTF_MBT_stepName_invokeTestStep,contextArgs:=omit}},
nextStateCalculation:=omit,
nextState:="main"
}
} // classicCellRow
} // cellRow
},
{events2Listen := {
events:= {
{ singleEvent:={
bName:=c_EPTF_MBT_myBName,
iName:=c_EPTF_MBT_inputName_incomingUserRequest,
eventType:=fsm}
}}},
cellRow := {
classicCellRow := {
{//state[0]==main
//DOT: main -> main [label="i:incomingUserRequest\n a:step_invokeUserFunction"]
actionList:={{stepOrFunctionName:=c_EPTF_MBT_stepName_invokeUserFunction,contextArgs:=omit}},
nextStateCalculation:=omit,
nextState:="main"
}
} // classicCellRow
} // cellRow
},
{events2Listen := {
unhandled:={}
//catchAll:={}
},
cellRow := {
classicCellRow := {
{//state[0]==main
//DOT: main -> main [label="i:unhandled\n a:step_sendUserResponse"]
actionList:={{stepOrFunctionName:=c_EPTF_MBT_stepName_sendUserResponse,contextArgs:=omit}},
nextStateCalculation:=omit,
nextState:="main"
}
} // classicCellRow
} // cellRow
}
} // extendedTable
} // table
}
);
}
///////// Tester part
///////////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_MBT_Tester_init
//
// Purpose:
// This function inits the EPTF_MBT_Tester_CT
//
// Parameters:
// - *in* *charstring* pl_selfName - local internal name for the MBT Tester component
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_EPTF_MBT_Tester_init
(
in charstring pl_selfName
)
runs on EPTF_MBT_Tester_CT
{
f_EPTF_Base_init_CT(pl_selfName);
f_EPTF_Semaphore_init_CT(pl_selfName);
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_MBT_execute
//
// Purpose:
// This function executes a test step on specifid FSM (which must run the FSM_MBT)
// FSM. It is possible to make the function blocking until the test stepis executed
// by setting the p_lock parameter to true, but it will only work in case
// the component extends the EPTF_MBT_Tester_CT and EPTF_MBT_LGen_CT as well!
//
// Parameters:
// - *in* *charstring* p_name - name of the test step
// - *in* <FsmAddr> p_addr - address of the FSM
// - *in* <EPTF_IntegerList> - p_params - parameters for the test step
// - *in* *boolean* - p_lock - Enables/disables waiting for the test step to finish executing.
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_MBT_execute(in charstring p_name, in EPTF_MBT_LGen_Definitions.FsmAddr p_addr, in EPTF_IntegerList p_params := {}, in boolean p_lock := true)
runs on EPTF_MBT_Tester_CT
{
action(%definitionId, "TestStep: ", p_name)
if (p_lock)
{
var integer v_lock := f_EPTF_Semaphore_new();
EPTF_MBT_TESTER_PCO.send(EPTF_MBT_TestStepRequest: {p_name, p_params, p_addr, v_lock});
f_EPTF_Semaphore_waitForUnlock(v_lock, tsp_EPTG_MBT_execute_lockTimeout);
}
else
{
EPTF_MBT_TESTER_PCO.send(EPTF_MBT_TestStepRequest: {p_name, p_params, p_addr, omit});
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_MBT_waitFor
//
// Purpose:
// This function waits for specified EPTF event to arrive. Please note, that
// until the waiting time runs out all the other incoming events are dropped.
//
// Parameters:
// - *in* *charstring* p_behavior - behavior name of the expected event
// - *in* *charstring* p_name - name of the expected event
// - *in* <FsmAddr> - p_addr - the event must arrive from this FSM.
// - *in* *float* - p_timeout - Maximum waiting time for the expected event
//
// Return Value:
// - *boolean* - True if the expected emssage was caught.
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_MBT_waitFor(
in charstring p_behavior, in charstring p_name,
in EPTF_MBT_LGen_Definitions.FsmAddr p_addr, in float p_timeout := 3.0)
runs on EPTF_MBT_Tester_CT
return boolean
{
timer t_wait;
t_wait.start(p_timeout);
alt
{
[] EPTF_MBT_TESTER_PCO.receive(EPTF_MBT_TestStepResponse:{ bName := p_behavior, iName := p_name, addr := p_addr})
{
t_wait.stop;
action(%definitionId, "Received: ", p_name)
return true;
}
[] EPTF_MBT_TESTER_PCO.receive
{
action(%definitionId, "Dropping unexpected message!")
repeat;
}
[] t_wait.timeout
{
action(%definitionId, "Timeout!")
return false;
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_MBT_dispatch
//
// Purpose:
// This function sends an EPTF event to an FSM.
//
// Parameters:
// - *in* *charstring* p_bName - behavior name of the event
// - *in* *integer* p_iIndex - index of the event
// - *in* <FsmAddr> - p_addr - the event will be sent to this FSM.
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_MBT_dispatch(in charstring p_bName, in integer p_iIndex, in EPTF_MBT_LGen_Definitions.FsmAddr p_addr)
runs on EPTF_MBT_Tester_CT
{
action(%definitionId, "Dispatching: ", p_bName, ":",p_iIndex, " to ",p_addr)
EPTF_MBT_TESTER_PCO.send(EPTF_MBT_EventDispatchRequest: {p_bName, p_iIndex, p_addr});
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_MBT_activateFsm
//
// Purpose:
// This function activates an FSM on an entity.
//
// Parameters:
// - *in* *charstring* p_entityGroupName - entity group name of the entity
// - *in* *integer* p_eIdx - index of the entity
// - *in* *charstring* - p_fsmName - the event will be sent to this FSM.
// - *out* *FsmAddr* - p_fsmAddr - The address of the activated FSM if succesful
//
// Return Value:
// - *integer* - the result of the FSM activation (-1 if unsuccesful)
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_MBT_activateFsm(in charstring p_entityGroupName, in integer p_eIdx, in charstring p_fsmName, out FsmAddr p_fsmAddr)
runs on EPTF_MBT_Tester_CT
return integer
{
EPTF_MBT_TESTER_PCO.send(EPTF_MBT_CreateFSMRequest:
{
entityGroupName := p_entityGroupName,
eIdx := 0,
fsmName := p_fsmName
}
)
var EPTF_MBT_CreateFSMResponse vl_resp;
EPTF_MBT_TESTER_PCO.receive(EPTF_MBT_CreateFSMResponse:?) -> value vl_resp;
p_fsmAddr := vl_resp.addr;
return vl_resp.result;
}
///////////////////////////////////////////////////////////////////////////////
// Function: f_convert_FsmAddr2TestStepArgs
//
// Purpose:
// Utility function to convert an FsmAddr address to a TestStepArgs value.
//
// Parameters:
// - *in* *FsmAddr* - p_fsmAddr - An FSM address
//
// Return Value:
// - <EPTF_LGenBase_TestStepArgs> - the corresponding TestStapArgs value
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////////////////////
function f_convert_FsmAddr2TestStepArgs(in EPTF_MBT_LGen_Definitions.FsmAddr p_addr)
return EPTF_LGenBase_TestStepArgs
{
// FIXME: entity group check!
var EPTF_LGenBase_TestStepArgs vl_ret :=
{
eIdx := p_addr.eIdx,
refContext :=
{
fCtxIdx := p_addr.fIdx,
fRefArgs := {}
},
stepArgs := {},
reportedEvent := c_EPTF_LGenBase_emptyReportedEventDescriptor
}
return vl_ret;
}
}