/****************************************************************************** * Copyright (c) 2000-2015 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 ******************************************************************************/ // This code is a small snippet from TitanSim. Thanks to EJNOSVN for the // project and the scripts. module TitanLogTest { import from CommonStuff all; modulepar integer tsp_NumberOfComponents := 2; modulepar float tsp_PerfTestDuration := 20.0; modulepar integer tsp_messagesToSend := 100; type record StartOk{ integer senderNum } type record StopOk{ integer senderNum } type record Data1{ integer senderNum, integer receiverNum, charstring chdata } type record Data2{ integer senderNum, integer receiverNum, charstring chdata, float fldata } type union sendData { StartOk startOk, Data1 data1, Data2 data2 } type port SyncPort message{ inout StartOk inout StopOk inout Data1 inout Data2 } with { extension "internal"} type component TitanTest_CT extends EPTF_Base_CT { timer T_testDuration := tsp_PerfTestDuration; var integer v_counter := 0; var integer v_sendCounter := 0; var boolean v_loop := true; var charstring v_chdata1 := "+-=!@#$%^&*abcdefghijklmnopqrstuvwxyz01234567890~~"; var charstring v_chdata2 := "-+=!@#$%^&*01234567890abcdefghijklmnopqrstuvwxyz~~"; var charstring v_chData := "+-=!@#$%^&*abcdefghijklmnopqrstuvwxyz01234567890~~"; port SyncPort sync_PCO; var integer v_lastPartner := 0; var integer v_lastDataType := 0; var Data1 v_Msg1; var Data2 v_Msg2; var TitanTest_CTList vl_components; } type record of TitanTest_CT TitanTest_CTList; group Titan_Logging { function f_EPTF_TitanTest_sendResponse(in integer pl_senderNum) runs on TitanTest_CT { log("Send happens - comp"&int2str(pl_senderNum)); if(v_lastPartner == pl_senderNum){ v_lastPartner := v_lastPartner + 1; if(v_lastPartner >= tsp_NumberOfComponents){v_lastPartner := 0} if (v_lastDataType == 0){ v_chData := v_chdata2; v_lastDataType := 1; } else { v_chData := v_chdata1; v_lastDataType := 0; } } if (v_lastDataType == 0){ var Data1 data1 := {pl_senderNum, v_lastPartner, v_chData} sync_PCO.send( data1 ); } else { var Data2 data2 := {pl_senderNum, v_lastPartner, v_chData, int2float(v_sendCounter + v_sendCounter/10)} sync_PCO.send( data2); } v_lastPartner := v_lastPartner + 1; if(v_lastPartner >= tsp_NumberOfComponents){v_lastPartner := 0} v_sendCounter := v_sendCounter + 1; } private altstep as_EPTF_TitanTest_receive1(in integer pl_senderNum) runs on TitanTest_CT { []sync_PCO.receive(Data1:? ) -> value v_Msg1{ log("Receive happens1 - comp"&int2str(pl_senderNum)); if (match(v_Msg1.chdata, v_chdata1)){ log(" xxxxxxxxxx "); } timer T_send := 0.01 * int2float(pl_senderNum + 1); T_send.start; T_send.timeout; f_EPTF_TitanTest_sendResponse(pl_senderNum); repeat; } []sync_PCO.receive(StartOk:? ) { log("Receive happens1 - StartOK - comp"&int2str(pl_senderNum)); timer T_send := 0.01 * int2float(pl_senderNum + 1); T_send.start; T_send.timeout; f_EPTF_TitanTest_sendResponse(pl_senderNum); repeat; } []sync_PCO.receive(StopOk:? ) { log("StopOk happens1 - comp"&int2str(pl_senderNum)); timer T_send := 0.01 * int2float(pl_senderNum + 1); T_send.start; T_send.timeout; } } private altstep as_EPTF_TitanTest_receive2(in integer pl_senderNum) runs on TitanTest_CT { []sync_PCO.receive(Data2:? ) -> value v_Msg2{ log("Receive happens2 - comp"&int2str(pl_senderNum)); if (match(v_Msg2.chdata, v_chdata2)){ log(" yyyyyyyyyy "); } timer T_send := 0.01 * int2float(pl_senderNum + 1); T_send.start; T_send.timeout; f_EPTF_TitanTest_sendResponse(pl_senderNum); repeat; } []sync_PCO.receive(StartOk:? ) { log("Receive happens2 - StartOK - comp"&int2str(pl_senderNum)); timer T_send := 0.01 * int2float(pl_senderNum + 1); T_send.start; T_send.timeout; f_EPTF_TitanTest_sendResponse(pl_senderNum); repeat; } []sync_PCO.receive(StopOk:? ) { log("StopOk happens2 - comp"&int2str(pl_senderNum)); timer T_send := 0.01 * int2float(pl_senderNum + 1); T_send.start; T_send.timeout; } } function f_EPTF_TitanTest_behavior(in integer pl_senderNum) runs on TitanTest_CT { log("Start behaviour - comp"&int2str(pl_senderNum)); var StartOk sok:= {pl_senderNum}; sync_PCO.send( sok ); T_testDuration.start; log("before Alt in comp"&int2str(pl_senderNum)); alt { [] T_testDuration.timeout { } [] as_EPTF_TitanTest_receive1(pl_senderNum); [] as_EPTF_TitanTest_receive2(pl_senderNum); } log("Finished behaviour - comp"&int2str(pl_senderNum)); } private altstep as_EPTF_TitanTest_forward1() runs on TitanTest_CT { []sync_PCO.receive(Data1:? ) -> value v_Msg1{ var integer vl_sendTo := 0; var integer vl_sender := 0; vl_sendTo := v_Msg1.receiverNum; vl_sender := v_Msg1.senderNum; log(" Forward send happens1 - comp"&int2str(vl_sendTo)); action(" Forward send from comp" & int2str(vl_sender) &" to comp"&int2str(vl_sendTo)); if (v_counter >= tsp_messagesToSend){ timer T_send := 0.5; T_send.start; T_send.timeout; var StopOk sok:= {0}; for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i := vl_i + 1){ sok:= {vl_i}; sync_PCO.send(sok) to vl_components[vl_i]; } } else { sync_PCO.send(v_Msg1) to vl_components[vl_sendTo]; v_counter := v_counter + 1; repeat; } } } private altstep as_EPTF_TitanTest_forward2() runs on TitanTest_CT { []sync_PCO.receive(Data2:? ) -> value v_Msg2{ var integer vl_sendTo := 0; var integer vl_sender := 0; vl_sendTo := v_Msg2.receiverNum; vl_sender := v_Msg2.senderNum; log(" Forward send happens2 - comp"&int2str(vl_sendTo)); action(" Forward send from comp" & int2str(vl_sender) &" to comp"&int2str(vl_sendTo)); if (v_counter >= tsp_messagesToSend){ timer T_send := 0.5; T_send.start; T_send.timeout; var StopOk sok:= {0}; for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i := vl_i + 1){ sok:= {vl_i}; sync_PCO.send(sok) to vl_components[vl_i]; } } else { sync_PCO.send(v_Msg2) to vl_components[vl_sendTo]; v_counter := v_counter + 1; repeat; } } } testcase Titan_Logging_BasicTest() runs on TitanTest_CT { log("TestCase has been started "); f_EPTF_Base_init_CT("mtc"); var integer i; for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i:= vl_i+ 1){ vl_components[vl_i] := TitanTest_CT.create("Comp" & int2str(vl_i) /* ??? TODO : on different hosts ???? */); connect(self : sync_PCO, vl_components[vl_i] : sync_PCO); vl_components[vl_i].start(f_EPTF_TitanTest_behavior(vl_i)); } i := 0; alt{ []sync_PCO.receive { i := i + 1; if (i < tsp_NumberOfComponents) { repeat; } } } T_testDuration.start; // start the first one var StartOk sok:= {0}; sync_PCO.send(sok) to vl_components[0]; var sendData vl_value; alt { []T_testDuration.timeout { } [] as_EPTF_TitanTest_forward1(); [] as_EPTF_TitanTest_forward2(); } action("TestCase has been ended - Counter: " & log2str(v_counter)); log("TestCase has been ended "); timer T_send := 0.5; T_send.start; T_send.timeout; setverdict(pass); } } }