1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 ******************************************************************************/
10 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
12 type component mymtctype {
17 type component mycomptype1 {
23 type component mycomptype2 {
31 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
33 type port duplex message {
35 } with { extension "internal" }
37 type port simplex_in message {
39 } with { extension "internal" }
41 type port simplex_out message {
43 } with { extension "internal" }
45 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
47 type enumerated commtype { echo, relay }
49 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
51 const charstring str_hello := "Hello!";
52 const charstring str1 := "Hello!";
53 const charstring str2 := "!olleH";
54 const float TOUT := 5.0;
56 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
58 altstep tout_fail(timer t) {
59 [] any port.receive { setverdict(fail) }
60 [] t.timeout { setverdict(inconc) }
63 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
65 function createconfig() runs on mymtctype {
66 A := mycomptype1.create;
67 B := mycomptype2.create;
68 C := mycomptype2.create;
76 function donestop() runs on mymtctype {
77 A.done; B.done; C.done
80 function neg(in verdicttype v) return verdicttype {
81 if(v == fail) { return pass }
85 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
87 function send_receive(in charstring istr, in charstring ostr, in commtype ct)
90 var verdicttype v := pass;
92 mydef := activate(tout_fail(t));
93 if(ct == echo) { v := fail }
97 [] io.receive(istr) { setverdict(v) }
98 [] oi.receive(istr) { setverdict(neg(v)) }
103 function send_receive2x(in charstring msg1, in charstring msg2)
104 runs on mycomptype1 {
111 [] io.receive(charstring:?) -> value str
113 if(str == msg1) { setverdict(pass) }
114 else { setverdict(fail) }
116 [] oi.receive(charstring:?) -> value str
118 if(str == msg2) { setverdict(pass) }
119 else { setverdict(fail) }
121 [] t.timeout { setverdict(inconc) }
125 function relay_cross(in charstring msg1, in charstring msg2, in boolean single)
126 runs on mycomptype2 {
134 [] io.receive(charstring:?) -> value str
136 if(str == msg1) { o.send(msg1); setverdict(pass) }
137 else { setverdict(fail) }
139 [] i.receive(charstring:?) -> value str
141 if(str == msg2) { io.send(msg2); setverdict(pass) }
142 else { setverdict(fail) }
144 [] t.timeout { setverdict(inconc) }
146 if(getverdict == pass and not single) { goto here }
150 function relay_x(in charstring id, in charstring term, in boolean last2io)
151 runs on mycomptype2 {
152 var charstring str := "";
154 mydef := activate(tout_fail(t))
158 [] io.receive(charstring:?) -> value str
162 if(str == term) { setverdict(pass) }
165 [] i.receive(charstring:?) -> value str
169 if(last2io) { io.send(str); setverdict(pass) }
170 else { o.send(str); setverdict(pass) }
172 else { o.send(str); repeat }
179 // This function is erronous as it tries to send a charstring on its
180 // port that has direction 'in'.
181 // That is why testcase 7 is supposed to give compilation error!
183 function relay_i() runs on mycomptype2 {
187 mydef := activate(tout_fail(t));
191 [] io.receive(charstring:?) -> value str { i.send(str); setverdict(pass) }
196 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
199 // A:oi ---str_hello--> B:io (pass)
200 // B:o ---str_hello--> C:i (pass)
201 // C:o ---str_hello--> A:io (pass)
203 testcase comptest_1() runs on mymtctype {
205 B.start(relay_x("", str_hello, false));
206 C.start(relay_x("", str_hello, true));
207 A.start(send_receive(str_hello, str_hello, relay));
212 // A:oi -----A---> B:io (pass)
213 // B:o ----AB---> C:i (pass)
214 // C:o ----ABC--> B:i (pass)
215 // B:o ---ABCB--> A:oi (pass)
217 testcase comptest_2() runs on mymtctype {
219 B.start(relay_x("B", "ABCB", true));
220 C.start(relay_x("C", "ABC", false));
221 A.start(send_receive("ABCB", "A", echo));
227 // A:oi ---str_1--> B:io (pass) A:io ---str_2--> C:i (pass)
228 // B:o ---str_1--> C:i (pass) C:o ---str_2--> B:i (pass)
229 // C:o ---str_1--> A:io (pass) B:io ---str_2--> A:oi (pass)
231 testcase comptest_3() runs on mymtctype {
233 B.start(relay_cross(str1, str2, true));
234 C.start(relay_cross(str2, str1, true));
235 A.start(send_receive2x(str1, str2));
241 // A:oi ------A-----> B:i (pass)
242 // B:o -----AB-----> C:i (pass)
243 // C:o -----ABC----> B:i (pass)
244 // B:o ----ABCB----> C:i (pass)
245 // C:o ----ABCBC---> B:i (pass)
246 // B:o ---ABCBCB---> C:i (pass)
247 // C:o ---ABCBCBC--> A:io (pass)
249 testcase comptest_4() runs on mymtctype {
251 B.start(relay_x("B", "ABCBCB", false));
252 C.start(relay_x("C", "ABCBCBC", true));
253 A.start(send_receive("ABCBCBC", "A", relay));
258 // A:oi ---str_1--> B:io (pass)
260 // B:o ---str_1--> C:i (error)
262 testcase comptest_5(in boolean disc) runs on mymtctype {
263 action("<<< This testcase shall terminate with error verdict >>>");
266 disconnect(B:o, C:i);
267 disconnect(C:o, B:i);
268 disconnect(C:io, A:io);
271 B.start(relay_x("B", "ABC", true));
272 A.start(send_receive("ABC", "A", echo));
277 // A:oi ---str_1--> B:io (pass)
280 // connect(B:o, B:i) (pass)
281 // B:o ---str_1--> B:i (pass)
282 // B:o ---str_1--> A:io (pass)
284 testcase comptest_6() runs on mymtctype {
286 disconnect(B:o, C:i);
287 disconnect(C:o, B:i);
288 disconnect(C:io, A:io);
292 B.start(relay_x("B", "ABB", true));
293 A.start(send_receive("ABB", "A", echo));
298 // This is an invalid testcase! Uncomment it together with function relay_i()
299 // and you should get a compile-time error!
301 // A:oi ---str_1--> B:i (pass)
302 // B:i ---str_1--> C:o (compile type error)
304 testcase comptest_7() runs on mymtctype {
307 C.start(relay_x("", str_hello, true));
308 A.start(send_receive(str_hello, str_hello, relay));
313 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
316 execute(comptest_1());
317 execute(comptest_2());
318 // execute(comptest_3());
319 execute(comptest_4());
320 execute(comptest_5(false));
321 execute(comptest_5(true));
322 execute(comptest_6());
323 // execute(comptest_7()); // results in compile type semantic error