Commit | Line | Data |
---|---|---|
970ed795 EL |
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. | |
10 | module TitanLogTest { | |
11 | ||
12 | import from CommonStuff all; | |
13 | ||
14 | modulepar integer tsp_NumberOfComponents := 2; | |
15 | modulepar float tsp_PerfTestDuration := 20.0; | |
16 | modulepar integer tsp_messagesToSend := 100; | |
17 | ||
18 | type record StartOk{ | |
19 | integer senderNum | |
20 | } | |
21 | ||
22 | type record StopOk{ | |
23 | integer senderNum | |
24 | } | |
25 | ||
26 | type record Data1{ | |
27 | integer senderNum, | |
28 | integer receiverNum, | |
29 | charstring chdata | |
30 | } | |
31 | ||
32 | type record Data2{ | |
33 | integer senderNum, | |
34 | integer receiverNum, | |
35 | charstring chdata, | |
36 | float fldata | |
37 | } | |
38 | ||
39 | type union sendData { | |
40 | StartOk startOk, | |
41 | Data1 data1, | |
42 | Data2 data2 | |
43 | } | |
44 | ||
45 | type port SyncPort message{ | |
46 | inout StartOk | |
47 | inout StopOk | |
48 | inout Data1 | |
49 | inout Data2 | |
50 | } with { extension "internal"} | |
51 | ||
52 | ||
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; | |
58 | ||
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; | |
65 | var Data1 v_Msg1; | |
66 | var Data2 v_Msg2; | |
67 | var TitanTest_CTList vl_components; | |
68 | } | |
69 | ||
70 | type record of TitanTest_CT TitanTest_CTList; | |
71 | ||
72 | group Titan_Logging { | |
73 | ||
74 | function f_EPTF_TitanTest_sendResponse(in integer pl_senderNum) runs on TitanTest_CT | |
75 | { | |
76 | log("Send happens - comp"&int2str(pl_senderNum)); | |
77 | ||
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; | |
83 | v_lastDataType := 1; | |
84 | } else { | |
85 | v_chData := v_chdata1; | |
86 | v_lastDataType := 0; | |
87 | } | |
88 | } | |
89 | ||
90 | if (v_lastDataType == 0){ | |
91 | var Data1 data1 := {pl_senderNum, v_lastPartner, v_chData} | |
92 | sync_PCO.send( data1 ); | |
93 | } else { | |
94 | var Data2 data2 := {pl_senderNum, v_lastPartner, v_chData, int2float(v_sendCounter + v_sendCounter/10)} | |
95 | sync_PCO.send( data2); | |
96 | } | |
97 | ||
98 | v_lastPartner := v_lastPartner + 1; | |
99 | if(v_lastPartner >= tsp_NumberOfComponents){v_lastPartner := 0} | |
100 | v_sendCounter := v_sendCounter + 1; | |
101 | } | |
102 | ||
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)){ | |
107 | log(" xxxxxxxxxx "); | |
108 | } | |
109 | timer T_send := 0.01 * int2float(pl_senderNum + 1); | |
110 | T_send.start; | |
111 | T_send.timeout; | |
112 | f_EPTF_TitanTest_sendResponse(pl_senderNum); | |
113 | repeat; | |
114 | } | |
115 | []sync_PCO.receive(StartOk:? ) { | |
116 | log("Receive happens1 - StartOK - comp"&int2str(pl_senderNum)); | |
117 | timer T_send := 0.01 * int2float(pl_senderNum + 1); | |
118 | T_send.start; | |
119 | T_send.timeout; | |
120 | f_EPTF_TitanTest_sendResponse(pl_senderNum); | |
121 | repeat; | |
122 | } | |
123 | []sync_PCO.receive(StopOk:? ) { | |
124 | log("StopOk happens1 - comp"&int2str(pl_senderNum)); | |
125 | timer T_send := 0.01 * int2float(pl_senderNum + 1); | |
126 | T_send.start; | |
127 | T_send.timeout; | |
128 | ||
129 | } | |
130 | ||
131 | ||
132 | } | |
133 | ||
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)); | |
137 | ||
138 | if (match(v_Msg2.chdata, v_chdata2)){ | |
139 | log(" yyyyyyyyyy "); | |
140 | } | |
141 | ||
142 | timer T_send := 0.01 * int2float(pl_senderNum + 1); | |
143 | T_send.start; | |
144 | T_send.timeout; | |
145 | f_EPTF_TitanTest_sendResponse(pl_senderNum); | |
146 | repeat; | |
147 | } | |
148 | []sync_PCO.receive(StartOk:? ) { | |
149 | log("Receive happens2 - StartOK - comp"&int2str(pl_senderNum)); | |
150 | timer T_send := 0.01 * int2float(pl_senderNum + 1); | |
151 | T_send.start; | |
152 | T_send.timeout; | |
153 | f_EPTF_TitanTest_sendResponse(pl_senderNum); | |
154 | repeat; | |
155 | } | |
156 | []sync_PCO.receive(StopOk:? ) { | |
157 | log("StopOk happens2 - comp"&int2str(pl_senderNum)); | |
158 | timer T_send := 0.01 * int2float(pl_senderNum + 1); | |
159 | T_send.start; | |
160 | T_send.timeout; | |
161 | ||
162 | } | |
163 | } | |
164 | ||
165 | function f_EPTF_TitanTest_behavior(in integer pl_senderNum) runs on TitanTest_CT | |
166 | { | |
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)); | |
172 | alt { | |
173 | [] T_testDuration.timeout { } | |
174 | [] as_EPTF_TitanTest_receive1(pl_senderNum); | |
175 | [] as_EPTF_TitanTest_receive2(pl_senderNum); | |
176 | } | |
177 | log("Finished behaviour - comp"&int2str(pl_senderNum)); | |
178 | } | |
179 | ||
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){ | |
187 | timer T_send := 0.5; | |
188 | T_send.start; | |
189 | T_send.timeout; | |
190 | ||
191 | var StopOk sok:= {0}; | |
192 | for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i := vl_i + 1){ | |
193 | sok:= {vl_i}; | |
194 | sync_PCO.send(sok) to vl_components[vl_i]; | |
195 | } | |
196 | } else { | |
197 | sync_PCO.send(v_Msg1) to vl_components[vl_sendTo]; | |
198 | v_counter := v_counter + 1; | |
199 | repeat; | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
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){ | |
211 | timer T_send := 0.5; | |
212 | T_send.start; | |
213 | T_send.timeout; | |
214 | var StopOk sok:= {0}; | |
215 | for(var integer vl_i := 0; vl_i < tsp_NumberOfComponents; vl_i := vl_i + 1){ | |
216 | sok:= {vl_i}; | |
217 | sync_PCO.send(sok) to vl_components[vl_i]; | |
218 | } | |
219 | } else { | |
220 | sync_PCO.send(v_Msg2) to vl_components[vl_sendTo]; | |
221 | v_counter := v_counter + 1; | |
222 | repeat; | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | testcase Titan_Logging_BasicTest() runs on TitanTest_CT | |
228 | { | |
229 | log("TestCase has been started "); | |
230 | f_EPTF_Base_init_CT("mtc"); | |
231 | var integer i; | |
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)); | |
236 | } | |
237 | i := 0; | |
238 | alt{ | |
239 | []sync_PCO.receive { | |
240 | i := i + 1; | |
241 | if (i < tsp_NumberOfComponents) { repeat; | |
242 | } | |
243 | } | |
244 | } | |
245 | T_testDuration.start; | |
246 | // start the first one | |
247 | var StartOk sok:= {0}; | |
248 | sync_PCO.send(sok) to vl_components[0]; | |
249 | ||
250 | var sendData vl_value; | |
251 | alt { | |
252 | []T_testDuration.timeout { } | |
253 | [] as_EPTF_TitanTest_forward1(); | |
254 | [] as_EPTF_TitanTest_forward2(); | |
255 | } | |
256 | action("TestCase has been ended - Counter: " & log2str(v_counter)); | |
257 | log("TestCase has been ended "); | |
258 | timer T_send := 0.5; | |
259 | T_send.start; | |
260 | T_send.timeout; | |
261 | ||
262 | setverdict(pass); | |
263 | } | |
264 | } | |
265 | ||
266 | } |