| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // 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 |
| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // File: EPTF_Applib_HTTP_Test_Functions.ttcn |
| // Rev: <RnXnn> |
| // Prodnr: CNL 113 618 |
| // Updated: 2009-01-08 |
| // Contact: http://ttcn.ericsson.se |
| /////////////////////////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| // Module: EPTF_Applib_HTTP_Test_Functions |
| // |
| // Purpose: |
| // Functions of EPTF HTTP Application Library test cases |
| // |
| // Module Parameters: |
| // - |
| // |
| // Module depends on: |
| // <EPTF_CLL_HashMapInt2Int_Functions> |
| // |
| // <EPTF_CLL_FBQ_Functions> |
| // |
| // <IPL4asp_Types> |
| // |
| // <HTTPmsg_Types> |
| // |
| // <EPTF_CLL_Base_Functions> |
| // |
| // <EPTF_HTTP_Transport_Definitions> |
| // |
| // <EPTF_HTTP_Transport_Functionss> |
| // |
| // <EPTF_Applib_HTTP_Test_Responder> |
| // |
| // <EPTF_Applib_HTTP_Test_Application1_Definitions> |
| // |
| // <EPTF_Applib_HTTP_Test_Application1_Functions> |
| // |
| // <TCCMaths_GenericTypes> |
| // |
| // Current Owner: |
| // EAKOPER |
| // |
| // Last Review Date: |
| // 2009-01-09 |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| module EPTF_Applib_HTTP_Test_Functions { |
| |
| //========================================================================= |
| // Import Part |
| //========================================================================= |
| import from EPTF_CLL_HashMapInt2Int_Functions all; |
| import from EPTF_CLL_FBQ_Functions all; |
| import from HTTPmsg_Types all; |
| import from EPTF_CLL_Base_Functions all; |
| |
| import from EPTF_HTTP_Transport_Definitions all; |
| import from EPTF_HTTP_Transport_Functions all; |
| |
| import from EPTF_Applib_HTTP_Test_Definitions all; |
| import from EPTF_Applib_HTTP_Test_Responder all; |
| import from EPTF_Applib_HTTP_Test_Application1_Definitions all; |
| import from EPTF_Applib_HTTP_Test_Application1_Functions all; |
| |
| import from TCCMaths_GenericTypes all; |
| |
| //========================================================================= |
| // Functions |
| //========================================================================= |
| /* |
| function f_myRandom() runs on EPTF_HTTP_Test_CT return float |
| { |
| var float vl_randVal := 1.0 / int2float(tsp_rangeHi) + 0.5 * rnd() / int2float(tsp_rangeHi); |
| v_randState := v_randState + vl_randVal; |
| |
| if (v_randState >= 1.0) { v_randState := v_randState - 1.0; }; |
| |
| return v_randState; |
| } |
| */ |
| |
| function f_EPTF_HTTP_Test_checkConfig() |
| runs on EPTF_HTTP_Test_CT return boolean |
| { |
| if (not isvalue(v_numberOfLGens1)) { |
| log("Parameter v_numberOfLGens1 not value!"); |
| return false; |
| } |
| |
| if (not isvalue(v_numberOfLGens2)) { |
| log("Parameter v_numberOfLGens2 not value!"); |
| return false; |
| } |
| |
| if (v_numberOfLGens1 < 0) { |
| log("Parameter tsp_numberOfLGens1 must be at least zero (now: ", v_numberOfLGens1, ")"); |
| return false; |
| } |
| |
| if (v_numberOfLGens2 < 0) { |
| log("Parameter tsp_numberOfLGens2 must be at least zero (now: ", v_numberOfLGens2, ")"); |
| return false; |
| } |
| |
| return true; |
| } |
| |
| function f_EPTF_HTTP_Test_createResponder( |
| in integer pl_tcId, |
| in float pl_runningTime) |
| runs on EPTF_HTTP_Test_CT |
| { |
| log("--- Creating responder ... "); |
| |
| v_HTTP_Responder_comp := EPTF_HTTP_Test_Responder_CT.create("HTTP_Responder"); |
| connect(v_HTTP_Responder_comp:v_CM_PCO, self:v_CM_PCO); |
| v_HTTP_Responder_comp.start(f_EPTF_HTTP_Test_Responder_behavior(pl_tcId, pl_runningTime)); |
| |
| timer tl_guard; |
| tl_guard.start(5.0); |
| alt { |
| [] v_CM_PCO.receive {tl_guard.stop} |
| [] tl_guard.timeout {f_EPTF_Base_stopAll()} |
| } |
| } |
| |
| function f_EPTF_HTTP_Test_createApplConfig1( |
| in integer pl_tcIdx, |
| in integer pl_numEntities, |
| in float pl_runningTime, |
| in float pl_responderRunningTime, |
| in boolean pl_portMode, |
| in boolean pl_globalMode, |
| in integer pl_numOfPorts, |
| in boolean pl_iConnOpen, |
| in boolean pl_iConnClose) |
| runs on EPTF_HTTP_Test_CT |
| { |
| log("--- Creating Application 1 configuration ... "); |
| |
| if (v_numberOfLGens1 == 0) { |
| log("WARNING! Application 1 disabled!"); |
| return; |
| } |
| |
| var integer i; |
| var charstring vl_name; |
| |
| v_isRemote_appl1 := v_numberOfLGens1 > 1; |
| log(" Remote transport: ", v_isRemote_appl1); |
| |
| if (v_isRemote_appl1) |
| { |
| vl_name := "APPL1_MAPPER"; |
| log(" Creating mapper: ", vl_name); |
| |
| v_HTTP_Mapper1_comp := EPTF_HTTP_Test_Application1_MapperCT.create(vl_name); |
| } |
| |
| for (i := 0; i < v_numberOfLGens1; i := i + 1) |
| { |
| vl_name := "APPL1_LGEN_" & int2str(i); |
| |
| if (v_isRemote_appl1) |
| { |
| |
| log(" Creating REMOTE lgen: ", vl_name); |
| v_HTTP_Remote1_comps[i] := EPTF_HTTP_Test_Application1_RemoteCT.create(vl_name); |
| |
| connect(v_HTTP_Remote1_comps[i]:v_EPTF_HTTP_RemoteTransport_commPort, |
| v_HTTP_Mapper1_comp:v_EPTF_HTTP_Mapper_commPort); |
| |
| v_HTTP_Remote1_comps[i].start(f_EPTF_HTTP_Test_Application1_RemoteBehavior( |
| i, pl_numEntities, |
| pl_globalMode, pl_runningTime, pl_responderRunningTime)); |
| } |
| else |
| { |
| log(" Creating LOCAL lgen: ", vl_name); |
| v_HTTP_Local1_comps[i] := EPTF_HTTP_Test_Application1_LocalCT.create(vl_name); |
| v_HTTP_Local1_comps[i].start(f_EPTF_HTTP_Test_Application1_LocalBehavior(pl_tcIdx, |
| i, pl_numEntities, |
| pl_portMode, pl_globalMode, pl_numOfPorts, pl_iConnOpen, pl_iConnClose, |
| pl_runningTime, pl_responderRunningTime)); |
| } |
| } |
| |
| if (v_isRemote_appl1) |
| { |
| v_HTTP_Mapper1_comp.start(f_EPTF_HTTP_Test_Application1_Mapper_Behavior( |
| v_HTTP_Remote1_comps, pl_tcIdx, pl_numEntities, pl_portMode, |
| pl_globalMode, pl_numOfPorts, pl_iConnOpen, pl_iConnClose, |
| 2.0*pl_runningTime)); |
| } |
| } |
| |
| // checks state of a port in a group (pl_group, pl_port) |
| // pl_state - port state |
| // pl_connId - connection id |
| // pl_c2g - should be in connection id 2 group id HashMap |
| // pl_c2p - should be in connection id 2 port id HashMap |
| // pl_busyState - should be busy in portStateQueue (meaning free/busy for sending) |
| // return true if state is valid, false otherwise |
| function f_EPTF_HTTP_Test_checkPortState( |
| in integer pl_group, |
| in integer pl_port, |
| in EPTF_HTTP_Transport_ConnectionState pl_state, |
| in integer pl_connId, |
| in boolean pl_c2g, |
| in boolean pl_c2p, |
| in boolean pl_busyState) |
| runs on EPTF_HTTP_Test_LocalAPI_CT return boolean |
| { |
| var boolean vl_found; |
| var integer vl_result, vl_connId; |
| var EPTF_HTTP_Transport_ConnectionState vl_state; |
| |
| if (pl_group == -1 or pl_group >= sizeof(v_EPTF_HTTP_Transport_portDB)) { |
| log("Port database (GROUP) is wrong!"); |
| setverdict(fail); |
| return false; |
| } |
| |
| if (pl_port == -1 or pl_port >= sizeof(v_EPTF_HTTP_Transport_portDB[pl_group].portDatabase)) { |
| log("Port database (PORT) is wrong!"); |
| setverdict(fail); |
| return false; |
| } |
| |
| vl_state := v_EPTF_HTTP_Transport_portDB[pl_group].portDatabase[pl_port].state; |
| if (vl_state != pl_state) |
| { |
| log("Inconsistent port state: ", vl_state, " instead of: ", pl_state); |
| setverdict(fail); |
| return false; |
| } |
| |
| vl_connId := v_EPTF_HTTP_Transport_portDB[pl_group].portDatabase[pl_port].connectionId; |
| if (vl_connId != pl_connId) |
| { |
| log("Inconsistent connnection id: ", vl_connId, "instead of: ", pl_connId); |
| setverdict(fail); |
| return false; |
| } |
| |
| vl_found := f_EPTF_int2int_HashMap_Find(v_EPTF_HTTP_Transport_connId2GroupId_HM, |
| vl_connId, vl_result); |
| |
| if (vl_found != pl_c2g) { |
| if (pl_c2g) { |
| log("Group id not found in Conn2Grp HM for connection (", |
| vl_connId, "), but it should be there!"); |
| } else { |
| log("Group id found in Conn2Grp HM for connection (", |
| vl_connId, "), but it shouldn't be there!"); |
| } |
| |
| setverdict(fail); |
| return false; |
| } |
| |
| vl_found := f_EPTF_int2int_HashMap_Find(v_EPTF_HTTP_Transport_connId2PortId_HM, |
| vl_connId, vl_result); |
| |
| if (vl_found != pl_c2p) { |
| if (pl_c2p) { |
| log("Port id not found in Conn2Grp HM for connection (", |
| vl_connId, "), but it should be there!"); |
| } else { |
| log("Port id found in Conn2Grp HM for connection (", |
| vl_connId, "), but it shouldn't be there!"); |
| } |
| |
| setverdict(fail); |
| return false; |
| } |
| |
| vl_found := f_EPTF_FBQ_itemIsBusy(pl_port, v_EPTF_HTTP_Transport_portDB[pl_group].portStateQueue); |
| if (pl_busyState != vl_found) { |
| if (vl_found) { |
| log("Port is busy for sending!"); |
| } |
| else { |
| log("Port is free for sending!"); |
| } |
| |
| return false; |
| } |
| |
| return true; |
| } |
| |
| function f_EPTF_HTTP_Test_DummyHTTPRequest( |
| in charstring pl_body) |
| return octetstring |
| { |
| var HTTPMessage vl_outgoingMessage := { |
| request := { |
| client_id:= omit, |
| method:= "GET", |
| uri:= "http://responder.com", |
| version_major := 1, |
| version_minor := 1, |
| header:= {{"Content-Length", int2str(lengthof(pl_body)) }}, |
| body:= pl_body |
| } |
| } |
| |
| log("HTTP message: ", vl_outgoingMessage); |
| |
| return enc_HTTPMessage(vl_outgoingMessage); |
| } |
| |
| function f_EPTF_HTTP_Test_bufferTest(in integer pl_size, in integer pl_offset) |
| runs on EPTF_HTTP_Test_LocalAPI_CT |
| { |
| var EPTF_HTTP_RingBuffer vl_buffer; |
| var integer vl_int := 0; |
| var boolean vl_busy := false; |
| var IntegerList vl_list := {}; |
| var IntegerList vl_listExpected := {}; |
| var integer vl_headIdx := -1; |
| |
| f_EPTF_HTTP_RingBuffer_init(vl_buffer, pl_size, 0); |
| |
| vl_buffer.nextSeqNum := pl_offset; |
| vl_buffer.waitForSeqNum := pl_offset; |
| |
| |
| for(var integer i := 0; i < pl_size; i := i + 1) |
| { |
| vl_listExpected[sizeof(vl_listExpected)] := (i + pl_offset) mod pl_size; |
| } |
| |
| vl_listExpected[sizeof(vl_listExpected)] := -1; |
| |
| for(var integer i := 0; i < pl_size + 1; i := i + 1) |
| { |
| vl_list[sizeof(vl_list)] := f_EPTF_HTTP_RingBuffer_getNext(vl_buffer) |
| } |
| |
| if (vl_list != vl_listExpected) |
| { |
| setverdict(fail); |
| log("Error: getting sequence number. Expected: ", vl_listExpected, " got: ", vl_list); |
| log(vl_buffer); |
| } |
| |
| for(var integer i := pl_size - 1; i > 0; i := i - 1) |
| { |
| f_EPTF_HTTP_RingBuffer_setElementBusy(vl_buffer, (i + pl_offset) mod pl_size); |
| vl_busy := f_EPTF_HTTP_RingBuffer_isHeadBusy(vl_buffer) or vl_busy; |
| } |
| |
| if (vl_busy) |
| { |
| log("Error: header should be free"); |
| log(vl_buffer); |
| setverdict(fail); |
| } |
| |
| f_EPTF_HTTP_RingBuffer_setElementBusy(vl_buffer, pl_offset); |
| |
| while (f_EPTF_HTTP_RingBuffer_isHeadBusy(vl_buffer)) |
| { |
| vl_list[sizeof(vl_list)] := f_EPTF_HTTP_RingBuffer_getHeadIdx(vl_buffer); |
| f_EPTF_HTTP_RingBuffer_freeHead(vl_buffer); |
| } |
| |
| for (var integer i := 0; i < pl_size; i := i + 1) |
| { |
| vl_listExpected[sizeof(vl_listExpected)] := (i + pl_offset) mod pl_size; |
| } |
| |
| if (vl_list != vl_listExpected) |
| { |
| setverdict(fail); |
| log("Error: reading out buffer. Expected: ", vl_listExpected, " got: ", vl_list); |
| log(vl_buffer); |
| } |
| |
| vl_headIdx := f_EPTF_HTTP_RingBuffer_getHeadIdx(vl_buffer); |
| |
| if (vl_headIdx != pl_offset) |
| { |
| log("Error: head index: ", vl_headIdx, " expected: ", pl_offset); |
| log(vl_buffer); |
| setverdict(fail); |
| } |
| |
| vl_int := f_EPTF_HTTP_RingBuffer_getNext(vl_buffer); |
| |
| if (pl_offset != vl_int) |
| { |
| log("Error: next sequence number: ", vl_int, " expected: ", pl_offset); |
| log(vl_buffer); |
| setverdict(fail); |
| } |
| |
| if (f_EPTF_int2int_HashMap_Size(vl_buffer.isSlotBusyHM) != 0) |
| { |
| log("Error: size of busy slot hash map should be 0."); |
| f_EPTF_int2int_HashMap_DumpByID(vl_buffer.isSlotBusyHM); |
| setverdict(fail); |
| } |
| |
| f_EPTF_HTTP_RingBuffer_erase(vl_buffer, 0) |
| } |
| } |