1 /******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8 // This code is a small snippet from TitanSim. Thanks to EJNOSVN for the
9 // project and the scripts.
12 import from CommonStuff all;
14 modulepar integer tsp_NumberOfComponents := 2;
15 modulepar float tsp_PerfTestDuration := 20.0;
16 modulepar integer tsp_messagesToSend := 100;
45 type port SyncPort message{
50 } with { extension "internal"}
53 type component TitanTest_CT extends EPTF_Base_CT {
54 timer T_testDuration := tsp_PerfTestDuration;
55 var integer v_counter := 0;
56 var integer v_sendCounter := 0;
57 var boolean v_loop := true;
59 var charstring v_chdata1 := "+-=!@#$%^&*abcdefghijklmnopqrstuvwxyz01234567890~~";
60 var charstring v_chdata2 := "-+=!@#$%^&*01234567890abcdefghijklmnopqrstuvwxyz~~";
61 var charstring v_chData := "+-=!@#$%^&*abcdefghijklmnopqrstuvwxyz01234567890~~";
62 port SyncPort sync_PCO;
63 var integer v_lastPartner := 0;
64 var integer v_lastDataType := 0;
67 var TitanTest_CTList vl_components;
70 type record of TitanTest_CT TitanTest_CTList;
74 function f_EPTF_TitanTest_sendResponse(in integer pl_senderNum) runs on TitanTest_CT
76 log("Send happens - comp"&int2str(pl_senderNum));
78 if(v_lastPartner == pl_senderNum){
79 v_lastPartner := v_lastPartner + 1;
80 if(v_lastPartner >= tsp_NumberOfComponents){v_lastPartner := 0}
81 if (v_lastDataType == 0){
82 v_chData := v_chdata2;
85 v_chData := v_chdata1;
90 if (v_lastDataType == 0){
91 var Data1 data1 := {pl_senderNum, v_lastPartner, v_chData}
92 sync_PCO.send( data1 );
94 var Data2 data2 := {pl_senderNum, v_lastPartner, v_chData, int2float(v_sendCounter + v_sendCounter/10)}
95 sync_PCO.send( data2);
98 v_lastPartner := v_lastPartner + 1;
99 if(v_lastPartner >= tsp_NumberOfComponents){v_lastPartner := 0}
100 v_sendCounter := v_sendCounter + 1;
103 private altstep as_EPTF_TitanTest_receive1(in integer pl_senderNum) runs on TitanTest_CT {
104 []sync_PCO.receive(Data1:? ) -> value v_Msg1{
105 log("Receive happens1 - comp"&int2str(pl_senderNum));
106 if (match(v_Msg1.chdata, v_chdata1)){
109 timer T_send := 0.01 * int2float(pl_senderNum + 1);
112 f_EPTF_TitanTest_sendResponse(pl_senderNum);
115 []sync_PCO.receive(StartOk:? ) {
116 log("Receive happens1 - StartOK - comp"&int2str(pl_senderNum));
117 timer T_send := 0.01 * int2float(pl_senderNum + 1);
120 f_EPTF_TitanTest_sendResponse(pl_senderNum);
123 []sync_PCO.receive(StopOk:? ) {
124 log("StopOk happens1 - comp"&int2str(pl_senderNum));
125 timer T_send := 0.01 * int2float(pl_senderNum + 1);
134 private altstep as_EPTF_TitanTest_receive2(in integer pl_senderNum) runs on TitanTest_CT {
135 []sync_PCO.receive(Data2:? ) -> value v_Msg2{
136 log("Receive happens2 - comp"&int2str(pl_senderNum));
138 if (match(v_Msg2.chdata, v_chdata2)){
142 timer T_send := 0.01 * int2float(pl_senderNum + 1);
145 f_EPTF_TitanTest_sendResponse(pl_senderNum);
148 []sync_PCO.receive(StartOk:? ) {
149 log("Receive happens2 - StartOK - comp"&int2str(pl_senderNum));
150 timer T_send := 0.01 * int2float(pl_senderNum + 1);
153 f_EPTF_TitanTest_sendResponse(pl_senderNum);
156 []sync_PCO.receive(StopOk:? ) {
157 log("StopOk happens2 - comp"&int2str(pl_senderNum));
158 timer T_send := 0.01 * int2float(pl_senderNum + 1);
165 function f_EPTF_TitanTest_behavior(in integer pl_senderNum) runs on TitanTest_CT
167 log("Start behaviour - comp"&int2str(pl_senderNum));
168 var StartOk sok:= {pl_senderNum};
169 sync_PCO.send( sok );
170 T_testDuration.start;
171 log("before Alt in comp"&int2str(pl_senderNum));
173 [] T_testDuration.timeout { }
174 [] as_EPTF_TitanTest_receive1(pl_senderNum);
175 [] as_EPTF_TitanTest_receive2(pl_senderNum);
177 log("Finished behaviour - comp"&int2str(pl_senderNum));
180 private altstep as_EPTF_TitanTest_forward1() runs on TitanTest_CT {
181 []sync_PCO.receive(Data1:? ) -> value v_Msg1{
182 var integer vl_sendTo := 0; var integer vl_sender := 0;
183 vl_sendTo := v_Msg1.receiverNum; vl_sender := v_Msg1.senderNum;
184 log(" Forward send happens1 - comp"&int2str(vl_sendTo));
185 action(" Forward send from comp" & int2str(vl_sender) &" to comp"&int2str(vl_sendTo));
186 if (v_counter >= tsp_messagesToSend){
191 var StopOk sok:= {0};
192 for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i := vl_i + 1){
194 sync_PCO.send(sok) to vl_components[vl_i];
197 sync_PCO.send(v_Msg1) to vl_components[vl_sendTo];
198 v_counter := v_counter + 1;
204 private altstep as_EPTF_TitanTest_forward2() runs on TitanTest_CT {
205 []sync_PCO.receive(Data2:? ) -> value v_Msg2{
206 var integer vl_sendTo := 0; var integer vl_sender := 0;
207 vl_sendTo := v_Msg2.receiverNum; vl_sender := v_Msg2.senderNum;
208 log(" Forward send happens2 - comp"&int2str(vl_sendTo));
209 action(" Forward send from comp" & int2str(vl_sender) &" to comp"&int2str(vl_sendTo));
210 if (v_counter >= tsp_messagesToSend){
214 var StopOk sok:= {0};
215 for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i := vl_i + 1){
217 sync_PCO.send(sok) to vl_components[vl_i];
220 sync_PCO.send(v_Msg2) to vl_components[vl_sendTo];
221 v_counter := v_counter + 1;
227 testcase Titan_Logging_BasicTest() runs on TitanTest_CT
229 log("TestCase has been started ");
230 f_EPTF_Base_init_CT("mtc");
232 for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i:= vl_i+ 1){
233 vl_components[vl_i] := TitanTest_CT.create("Comp" & int2str(vl_i) /* ??? TODO : on different hosts ???? */);
234 connect(self : sync_PCO, vl_components[vl_i] : sync_PCO);
235 vl_components[vl_i].start(f_EPTF_TitanTest_behavior(vl_i));
241 if (i < tsp_NumberOfComponents) { repeat;
245 T_testDuration.start;
246 // start the first one
247 var StartOk sok:= {0};
248 sync_PCO.send(sok) to vl_components[0];
250 var sendData vl_value;
252 []T_testDuration.timeout { }
253 [] as_EPTF_TitanTest_forward1();
254 [] as_EPTF_TitanTest_forward2();
256 action("TestCase has been ended - Counter: " & log2str(v_counter));
257 log("TestCase has been ended ");