blob: 6044fa27fe3a4c5351617ccd1e28693afeb51924 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 Ericsson Telecom AB //
// //
// All rights reserved. This program and the accompanying materials //
// are made available under the terms of the Eclipse Public License v2.0 //
// which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
///////////////////////////////////////////////////////////////////////////////
module EPTF_Scheduler_test {
import from EPTF_CLL_Scheduler_Definitions all;
import from EPTF_CLL_RBTScheduler_Definitions all;
import from EPTF_CLL_RBTScheduler_Functions all;
// to use Red-black tree scheduler, comment the FBQ lines and uncomment these lines:
//import from EPTF_CLL_RBTScheduler_Definitions all;
//import from EPTF_CLL_RBTScheduler_Functions all;
type record Event0Data {
float period,
integer eventIdx,
integer maxExecutionNum,
integer eventCounter
}
type Event0Data Event1Data;
type component Scheduler_test_CT extends EPTF_Scheduler_CT {
var Event0Data v_event0Data := {
period := 0.0,
eventIdx := -1,
maxExecutionNum := 0,
eventCounter := 0
}
var Event1Data v_event1Data := {
period := 0.0,
eventIdx := -1,
maxExecutionNum := 0,
eventCounter := 0
}
var EPTF_Scheduler_ActionHandler v_myEventHandler;
}
// eventid: [0] : type (0,1)
// if eventId[0] == 0 (event 0): eventId[1]: number of execution times
// if eventId[0] == 1 (event 1): eventId[1]: number of execution times
// Event0: logs periodically how many times it is executed from start.
// event1: if event0 is executing stops it, if not starts it.
// handles my scheduler events
function f_myEventHandler(in EPTF_ScheduledAction pl_action, in integer pl_eventIndex) runs on Scheduler_test_CT return boolean {
if (pl_action.actionId[0] == 0) {
f_handleEvent0(pl_action.when,pl_action.actionId[1]);
return true;
}
if (pl_action.actionId[0] == 1) {
f_handleEvent1(pl_action.when,pl_action.actionId[1]);
return true;
}
return false;
}
//initialises my component
function f_init_Scheduler_test_CT() runs on Scheduler_test_CT {
f_EPTF_Scheduler_init_CT("SchedulerTest");
v_myEventHandler := refers(f_myEventHandler);
}
//////////////////////////
// Event 0 functions
//////////////////////////
// activates event0
function f_startEvent0(in float pl_period, in integer pl_maxExecutionNum) runs on Scheduler_test_CT {
v_event0Data.period := pl_period;
v_event0Data.maxExecutionNum := pl_maxExecutionNum;
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_handleEvent0(f_EPTF_SchedulerComp_snapshotTime(),0);
}
function f_scheduleEvent0(in float when, in integer pl_action) runs on Scheduler_test_CT {
f_EPTF_SchedulerComp_scheduleAction(
when + v_event0Data.period,v_myEventHandler,{0,pl_action},
v_event0Data.eventIdx
);
}
function f_handleEvent0(in float when, in integer pl_action) runs on Scheduler_test_CT {
log("Event 0 executed ", pl_action, " times.");
v_event0Data.eventCounter := v_event0Data.eventCounter+1;
log("Event 0 executed ", v_event0Data.eventCounter, " times since start.");
if (pl_action==v_event0Data.maxExecutionNum) {
v_event0Data.eventIdx := -1;
return; // do not schedule more
}
f_scheduleEvent0(when,pl_action+1);
}
function f_stopEvent0() runs on Scheduler_test_CT {
if (v_event0Data.eventIdx==-1) {
return; // already stopped
}
f_EPTF_SchedulerComp_CancelEvent(v_event0Data.eventIdx);
v_event0Data.eventIdx := -1;
log("Event 0 stopped.");
}
//////////////////////////
// Event 1 functions
//////////////////////////
// activates event1
function f_startEvent1(in float delay, in float pl_period, in integer pl_maxExecutionNum) runs on Scheduler_test_CT {
v_event1Data.period := pl_period;
v_event1Data.maxExecutionNum := pl_maxExecutionNum;
f_EPTF_SchedulerComp_refreshSnapshotTime();
f_scheduleEvent1(f_EPTF_SchedulerComp_snapshotTime()+delay,0);
}
function f_scheduleEvent1(in float when, in integer pl_action) runs on Scheduler_test_CT {
f_EPTF_SchedulerComp_scheduleAction(
when + v_event1Data.period,v_myEventHandler,{1,pl_action},
v_event1Data.eventIdx
);
}
function f_handleEvent1(in float when, in integer pl_action) runs on Scheduler_test_CT {
log("Event 1 executed ", pl_action, " times.");
v_event1Data.eventCounter := v_event1Data.eventCounter+1;
log("Event 1 executed ", v_event1Data.eventCounter, " times since start.");
if (pl_action==v_event1Data.maxExecutionNum) {
v_event1Data.eventIdx := -1;
return; // do not schedule more
}
// if event running: stop, else start:
if (v_event0Data.eventIdx != -1 ) {
f_stopEvent0();
} else {
f_startEvent0(v_event0Data.period, v_event0Data.maxExecutionNum);
// increase Event 1 period:
v_event1Data.period := v_event1Data.period * 2.0;
}
f_scheduleEvent1(when,pl_action+1);
}
function f_stopEvent1() runs on Scheduler_test_CT {
if (v_event1Data.eventIdx==-1) {
return; // already stopped
}
f_EPTF_SchedulerComp_CancelEvent(v_event1Data.eventIdx);
v_event1Data.eventIdx := -1;
log("Event 1 stopped.");
}
// test case:
testcase tc_scheduler_test() runs on Scheduler_test_CT {
action("Please wait 30 seconds until test case finishes...");
f_init_Scheduler_test_CT();
f_startEvent0(1.0,10);
f_startEvent1(1.0,3.0,10);
timer t_wait := 30.0;
t_wait.start;
alt {
[] t_wait.timeout {
}
}
// test if the event were executed correct number of times:
if (v_event0Data.eventCounter != 21 or v_event1Data.eventCounter !=4) {
setverdict(fail, log2str("v_event0Data.eventCounter should be 21 or v_event1Data.eventCounter should be 4. v_event0Data.eventCounter = ",
v_event0Data.eventCounter, " v_event1Data.eventCounter = ", v_event1Data.eventCounter));
}
setverdict(pass);
}
} // end of module