Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / acceptance_test / comptest / comptest.ttcn
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 ******************************************************************************/
8 module comptest {
9
10 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
11
12 type component mymtctype {
13 var mycomptype1 A;
14 var mycomptype2 B, C;
15 }
16
17 type component mycomptype1 {
18 port duplex io, oi;
19 var default mydef;
20 timer t := TOUT;
21 }
22
23 type component mycomptype2 {
24 port simplex_in i;
25 port simplex_out o;
26 port duplex io;
27 var default mydef;
28 timer t := TOUT;
29 }
30
31 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
32
33 type port duplex message {
34 inout charstring
35 } with { extension "internal" }
36
37 type port simplex_in message {
38 in charstring
39 } with { extension "internal" }
40
41 type port simplex_out message {
42 out charstring
43 } with { extension "internal" }
44
45 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
46
47 type enumerated commtype { echo, relay }
48
49 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
50
51 const charstring str_hello := "Hello!";
52 const charstring str1 := "Hello!";
53 const charstring str2 := "!olleH";
54 const float TOUT := 5.0;
55
56 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
57
58 altstep tout_fail(timer t) {
59 [] any port.receive { setverdict(fail) }
60 [] t.timeout { setverdict(inconc) }
61 }
62
63 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
64
65 function createconfig() runs on mymtctype {
66 A := mycomptype1.create;
67 B := mycomptype2.create;
68 C := mycomptype2.create;
69
70 connect(A:oi, B:io);
71 connect(B:o, C:i);
72 connect(C:o, B:i);
73 connect(C:io, A:io);
74 }
75
76 function donestop() runs on mymtctype {
77 A.done; B.done; C.done
78 }
79
80 function neg(in verdicttype v) return verdicttype {
81 if(v == fail) { return pass }
82 else { return fail }
83 }
84
85 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
86
87 function send_receive(in charstring istr, in charstring ostr, in commtype ct)
88 runs on mycomptype1 {
89
90 var verdicttype v := pass;
91
92 mydef := activate(tout_fail(t));
93 if(ct == echo) { v := fail }
94 t.start;
95 oi.send(ostr);
96 alt {
97 [] io.receive(istr) { setverdict(v) }
98 [] oi.receive(istr) { setverdict(neg(v)) }
99 }
100 }
101
102 /*
103 function send_receive2x(in charstring msg1, in charstring msg2)
104 runs on mycomptype1 {
105 var charstring str;
106 timer t := TOUT;
107 t.start;
108 io.send(msg2);
109 oi.send(msg1);
110 interleave {
111 [] io.receive(charstring:?) -> value str
112 {
113 if(str == msg1) { setverdict(pass) }
114 else { setverdict(fail) }
115 }
116 [] oi.receive(charstring:?) -> value str
117 {
118 if(str == msg2) { setverdict(pass) }
119 else { setverdict(fail) }
120 }
121 [] t.timeout { setverdict(inconc) }
122 }
123 }
124
125 function relay_cross(in charstring msg1, in charstring msg2, in boolean single)
126 runs on mycomptype2 {
127 var charstring str;
128 timer t := TOUT;
129
130 t.start;
131
132 label here;
133 interleave {
134 [] io.receive(charstring:?) -> value str
135 {
136 if(str == msg1) { o.send(msg1); setverdict(pass) }
137 else { setverdict(fail) }
138 }
139 [] i.receive(charstring:?) -> value str
140 {
141 if(str == msg2) { io.send(msg2); setverdict(pass) }
142 else { setverdict(fail) }
143 }
144 [] t.timeout { setverdict(inconc) }
145 }
146 if(getverdict == pass and not single) { goto here }
147 }
148 */
149
150 function relay_x(in charstring id, in charstring term, in boolean last2io)
151 runs on mycomptype2 {
152 var charstring str := "";
153
154 mydef := activate(tout_fail(t))
155 t.start;
156
157 alt {
158 [] io.receive(charstring:?) -> value str
159 {
160 str := str & id;
161 o.send(str);
162 if(str == term) { setverdict(pass) }
163 else { repeat }
164 }
165 [] i.receive(charstring:?) -> value str
166 {
167 str := str & id;
168 if(str == term) {
169 if(last2io) { io.send(str); setverdict(pass) }
170 else { o.send(str); setverdict(pass) }
171 }
172 else { o.send(str); repeat }
173 }
174 }
175 }
176
177 /*
178 //
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!
182 //
183 function relay_i() runs on mycomptype2 {
184 var charstring str;
185 timer t := TOUT;
186
187 mydef := activate(tout_fail(t));
188 t.start;
189
190 alt {
191 [] io.receive(charstring:?) -> value str { i.send(str); setverdict(pass) }
192 }
193 }
194 */
195
196 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
197
198 //
199 // A:oi ---str_hello--> B:io (pass)
200 // B:o ---str_hello--> C:i (pass)
201 // C:o ---str_hello--> A:io (pass)
202 //
203 testcase comptest_1() runs on mymtctype {
204 createconfig();
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));
208 donestop();
209 }
210
211 //
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)
216 //
217 testcase comptest_2() runs on mymtctype {
218 createconfig();
219 B.start(relay_x("B", "ABCB", true));
220 C.start(relay_x("C", "ABC", false));
221 A.start(send_receive("ABCB", "A", echo));
222 donestop();
223 }
224
225 /*
226 //
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)
230 //
231 testcase comptest_3() runs on mymtctype {
232 createconfig();
233 B.start(relay_cross(str1, str2, true));
234 C.start(relay_cross(str2, str1, true));
235 A.start(send_receive2x(str1, str2));
236 donestop();
237 }
238 */
239
240 //
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)
248 //
249 testcase comptest_4() runs on mymtctype {
250 createconfig();
251 B.start(relay_x("B", "ABCBCB", false));
252 C.start(relay_x("C", "ABCBCBC", true));
253 A.start(send_receive("ABCBCBC", "A", relay));
254 donestop();
255 }
256
257 //
258 // A:oi ---str_1--> B:io (pass)
259 // C.stop
260 // B:o ---str_1--> C:i (error)
261 //
262 testcase comptest_5(in boolean disc) runs on mymtctype {
263 action("<<< This testcase shall terminate with error verdict >>>");
264 createconfig();
265 if(disc) {
266 disconnect(B:o, C:i);
267 disconnect(C:o, B:i);
268 disconnect(C:io, A:io);
269 }
270 C.stop;
271 B.start(relay_x("B", "ABC", true));
272 A.start(send_receive("ABC", "A", echo));
273 donestop();
274 }
275
276 //
277 // A:oi ---str_1--> B:io (pass)
278 // disconnect
279 // C.stop
280 // connect(B:o, B:i) (pass)
281 // B:o ---str_1--> B:i (pass)
282 // B:o ---str_1--> A:io (pass)
283 //
284 testcase comptest_6() runs on mymtctype {
285 createconfig();
286 disconnect(B:o, C:i);
287 disconnect(C:o, B:i);
288 disconnect(C:io, A:io);
289 C.stop;
290
291 connect(B:o, B:i);
292 B.start(relay_x("B", "ABB", true));
293 A.start(send_receive("ABB", "A", echo));
294 donestop();
295 }
296
297 /*
298 // This is an invalid testcase! Uncomment it together with function relay_i()
299 // and you should get a compile-time error!
300 //
301 // A:oi ---str_1--> B:i (pass)
302 // B:i ---str_1--> C:o (compile type error)
303 //
304 testcase comptest_7() runs on mymtctype {
305 createconfig();
306 B.start(relay_i());
307 C.start(relay_x("", str_hello, true));
308 A.start(send_receive(str_hello, str_hello, relay));
309 donestop();
310 }
311 */
312
313 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
314
315 control {
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
324 }
325
326 }
This page took 0.037742 seconds and 6 git commands to generate.