blob: ccdbcd9b0ca2b74d5d6a0e79e1c8a48dda2e04cf [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_FreeBusyQueue_demo
//
// Purpose:
// This module contains function definitions for testing EPTF FreeBusyQueue
//
// Module Parameters:
// -
//
// Module depends on:
// <EPTF_CLL_FBQ_Functions>
// <EPTF_CLL_FBQ_PrivateFunctions>
// <EPTF_CLL_FBQ_Definitions>
//
// Current Owner:
// Gabor Tatarka (egbotat)
//
// Last Review Date:
// -
//
// Detailed Comments:
// -
///////////////////////////////////////////////////////////
module EPTF_FreeBusyQueue_demo {
import from EPTF_CLL_FBQ_Functions all;
import from EPTF_CLL_FBQ_Definitions all;
//=========================================================================
//Component Types
//=========================================================================
type component EPTF_FreeBusyQueue_demo_CT extends EPTF_FBQ_CT
{
var EPTF_FreeBusyQueue v_queue;
var integer v_idx;
var boolean v_success;
}
////////////////////////////////////////////////////////////
testcase tc_fbq_demo() runs on EPTF_FreeBusyQueue_demo_CT system EPTF_FreeBusyQueue_demo_CT {
var EPTF_IndexList vl_data := {2};
var integer vl_setNofFreeSlots := 7;
var integer vl_idxTail;
// Init
f_EPTF_FBQ_init_CT("FreeBusyQueue_demo");
// init empty queue
f_EPTF_FBQ_initFreeBusyQueue(v_queue);
// Creating a slot
// ---------------
log("creating a slot...");
f_EPTF_FBQ_createFreeSlots(vl_setNofFreeSlots, v_queue);
// log a chain
f_EPTF_FBQ_logChain(free_chain, v_queue);
// get the head index of the free_chain slot
v_success := f_EPTF_FBQ_getFreeHeadIdx(v_idx, v_queue);
log("get the head index of the free_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// check whether the item is within the free_chain, or not
v_success := f_EPTF_FBQ_itemIsFree(v_idx, v_queue);
log("within the free_chain - v_idx = ", v_idx,"[",v_success,"]");
// set the data indices of the first queue item
f_EPTF_FBQ_setQueueDidx( 0, vl_data, v_queue);
log("set the data indices of the first queue item - v_queue:=", v_queue);
// get user data indices associated with a given slot
f_EPTF_FBQ_getQueueDidx(v_idx, v_queue, vl_data);
log("get user data indices associated with a given slot - v_idx = ", v_idx);
// set queue data
f_EPTF_FBQ_setQueueData(0,v_queue,0,4);
f_EPTF_FBQ_setQueueData(0,v_queue,1,5);
log("set queue data - v_queue:=", v_queue);
// get queue data
log("data[0]:=", f_EPTF_FBQ_getQueueData(0,v_queue,0)," data[1]:=",f_EPTF_FBQ_getQueueData(0,v_queue,1));
// Moves
// ----------------------
// Free => Busy
log("moves ...");
// move the slot at the head of free_chain to somewhere into busy_chain = > busy[1], free[6]
f_EPTF_FBQ_moveFromFreeHeadToBusy(v_idx, empty, 0, 0, v_queue);
log("move the slot at the head of free_chain to somewhere into busy_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
if (f_EPTF_FBQ_itemIsBusy(v_idx, v_queue))
{
log("OK: ", v_idx," item isbusy");
}
else
{
log("Error: ", v_idx," item is not busy");
}
// simply moves the head of the free_chain to the tail of the busy_chain => busy[2], free[5]
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_queue);
log("moves the head of the free_chain to the tail of the busy_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// get the tail index of the free_chain slot
v_success := f_EPTF_FBQ_getFreeTailIdx(v_idx,v_queue);
log("get the tail index of the free_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// move a slot from the free_chain to the tail of busy_chain => busy[3], free[4]
f_EPTF_FBQ_moveFromFreeToBusyTail(v_idx,v_queue);
log("move a slot from the free_chain to the tail of busy_chain - [",v_idx,"] v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// get the head index of the free_chain slot
v_success := f_EPTF_FBQ_getFreeHeadIdx(v_idx,v_queue);
log("get the head index of the free_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// get the head index of the busy_chain slot
v_success := f_EPTF_FBQ_getBusyHeadIdx(v_idx,v_queue);
log("get the head index of the busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// Busy => Invalid
// move a slot from busy_chain to invalid_chain => invalid[1]=> busy[2], free[4], invalid[1]
f_EPTF_FBQ_moveFromBusyToInvalid(v_idx, v_queue);
log("move a slot from busy_chain to invalid_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// check whether a given slot is within the invalid_chain, or not
v_success := f_EPTF_FBQ_itemIsInvalid(v_idx, v_queue);
log("within the invalid_chain - v_idx = ", v_idx,"[",v_success,"]");
// Invalid => Free
// move a slot from invalid to free_chain head => busy[2], free[5], invalid[0]
f_EPTF_FBQ_moveFromInvalidToFreeHead(v_idx, v_queue);
log("move a slot from invalid to free_chain head - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// check whether a given slot is within the invalid_chain, or not
v_success := f_EPTF_FBQ_itemIsFree(v_idx, v_queue);
log("within the free_chain - v_idx = ", v_idx,"[",v_success,"]");
// Busy => Invalid
// get the tail index of the busy_chain slot
v_success := f_EPTF_FBQ_getBusyTailIdx(v_idx,v_queue);
log("get the tail index of the busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// move a slot from busy_chain to invalid_chain => busy[1], free[5], invalid[1]
f_EPTF_FBQ_moveFromBusyToInvalid(v_idx, v_queue);
log("move a slot from busy_chain to invalid_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// Invalid => Free
// move a slot from invalid to free_chain tail => busy[1], free[6], invalid[0]
f_EPTF_FBQ_moveFromInvalidToFreeTail(v_idx,v_queue);
log("move a slot from invalid to free_chain tail - [",v_idx,"] v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// Busy => Free
// get the head index of the busy_chain slot
v_success := f_EPTF_FBQ_getBusyHeadIdx(v_idx,v_queue);
log("get the head index of the busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// move an item from the busy_chain to the head of the free_chain => busy[0], free[7], invalid[0]
f_EPTF_FBQ_moveFromBusyToFreeHead(v_idx,v_queue);
log("move an item from the busy_chain to the head of the free_chain - [",v_idx,"] v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// get the tail index of the busy_chain slot
v_success := f_EPTF_FBQ_getBusyTailIdx(v_idx,v_queue);
log("get the tail index of the busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// move a slot from the busy_chain to the tail of free_chain => busy[0], free[7], invalid[0]
f_EPTF_FBQ_moveFromBusyToFreeTail(v_idx,v_queue);
log("move a slot from the busy_chain to the tail of free_chain - [",v_idx,"] v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// Free => Busy
// simply moves the head of the free_chain to the tail of the busy_chain => busy[1], free[6]
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_queue);
log("moves the head of the free_chain to the tail of the busy_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// simply moves the head of the free_chain to the tail of the busy_chain => busy[2], free[5]
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_queue);
log("moves the head of the free_chain to the tail of the busy_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// Busy => Invalid
// get the tail index of the busy_chain slot
v_success := f_EPTF_FBQ_getBusyTailIdx(v_idx,v_queue);
log("get the tail index of the busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// move a slot from busy_chain to invalid_chain => busy[1], free[5], invalid[1]
f_EPTF_FBQ_moveFromBusyToInvalid(v_idx, v_queue);
log("move a slot from busy_chain to invalid_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// get the tail index of the busy_chain slot
v_success := f_EPTF_FBQ_getBusyTailIdx(vl_idxTail,v_queue);
log("get the tail index of the busy_chain slot - vl_idxTail = ", vl_idxTail,"[",v_success,"]");
// move a slot from busy_chain to invalid_chain => busy[0], free[5], invalid[2]
f_EPTF_FBQ_moveFromBusyToInvalid(vl_idxTail, v_queue);
log("move a slot from busy_chain to invalid_chain - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// Invalid => Busy
// move a slot from invalid to busy_chain head => busy[1], free[5], invalid[1]
f_EPTF_FBQ_moveFromInvalidToBusyHead(vl_idxTail,v_queue);
log("move a slot from invalid to busy_chain head - [",vl_idxTail,"] v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// move a slot from invalid to busy_chain tail => busy[2], free[5], invalid[0]
f_EPTF_FBQ_moveFromInvalidToBusyTail(v_idx,v_queue);
log("move a slot from invalid to busy_chain tail - [",v_idx,"] v_queue:=",
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// Creating a free slot
// ----------------------
log("creating a free slot...");
v_idx := f_EPTF_FBQ_getOrCreateFreeSlot(v_queue);
log("creating a free slot - v_idx = ", v_idx," - v_queue:=", v_queue);
//set the data indices of the second v_queue item
f_EPTF_FBQ_setQueueDidx( 1, {3}, v_queue);
log("set the data indices of the second v_queue item - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
f_EPTF_FBQ_getQueueDidx(v_idx, v_queue, vl_data);
log("get user data indices associated with a given slot - v_idx = ", v_idx);
// make the item 'free' (put to free chain) after using it, the most recently used free_chain slot will be reused first (LIFO policy)
f_EPTF_FBQ_moveFromInvalidToFreeHead(v_idx, v_queue);
log("make the item 'free' - v_queue:=", v_queue,
" - length:", f_EPTF_FBQ_getLengthOfQueue(v_queue)," [busy:", f_EPTF_FBQ_getLengthOfBusyChain(v_queue)," | free:",f_EPTF_FBQ_getLengthOfFreeChain(v_queue),"]");
// get the head of the free_chain
v_idx := f_EPTF_FBQ_getFreeSlot(v_queue);
log("get the head of the free_chain - v_idx = ", v_idx);
// get the index of the next forward busy_chain slot
v_success := f_EPTF_FBQ_getFwdBusyItemIdx(v_idx,v_queue);
log("get the index of the next forward busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// get the index of the next backward busy_chain slot
v_success := f_EPTF_FBQ_getBwdBusyItemIdx(v_idx,v_queue);
log("get the index of the next backward busy_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// get the index of the next forward free_chain slot
v_success := f_EPTF_FBQ_getFwdFreeItemIdx(v_idx,v_queue);
log("get the index of the next forward free_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// get the index of the next backward free_chain slot
v_success := f_EPTF_FBQ_getBwdFreeItemIdx(v_idx,v_queue);
log("get the index of the next backward free_chain slot - v_idx = ", v_idx,"[",v_success,"]");
// log a chain
log("FREE CHAIN:");
f_EPTF_FBQ_logChain(free_chain, v_queue);
log("BUSY CHAIN:");
f_EPTF_FBQ_logChain(busy_chain, v_queue);
setverdict(pass);
}
control{
execute(tc_fbq_demo());
}
} //module