Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / commProcedure / ProcPort.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 ProcPort {
9
10 type record MyRecord { }
11
12 signature MyProc(in integer Par1,inout charstring Par2,out float Par3)
13 return boolean
14 exception(integer);
15 signature MyProc2();
16 type MyProc2 MyProc2Alias; // testing type alias
17 signature MyProc3(in integer I) return float exception(integer);
18 signature MyProc4(in float F) noblock;
19 signature MyProc5(in integer A, in integer B)
20 return float exception(charstring, MyRecord);
21 signature s_StopPTC();
22 signature MyProc6(inout integer I);
23
24 template s_StopPTC StopPTC := { }
25
26 template MyProc5 MyProc5Template_any := {
27 A:=?,
28 B:=?
29 }
30
31 template MyProc5 MyProc5TemplateP(integer pA,integer pB) := {
32 A:=pA,
33 B:=pB
34 }
35
36 template MyProc3 MyProc3Template:={
37 I:=2003
38 }
39
40 template MyProc3 MyProc3Template_any:={I:=?}
41
42 template MyProc3 MyProc3TemplateP (integer P) := {
43 I:=P
44 }
45
46 template MyProc MyProcTemplateP (integer i,charstring c,float f) := {
47 Par1:=i,
48 Par2:=c,
49 Par3:=f
50 }
51
52 template MyProc MyProcTemplate:= {
53 Par1:=44,
54 Par2:="Q",
55 Par3:=324.664
56 }
57
58 template MyProc MyProcTemplate2:= {
59 Par1:=4200,
60 Par2:="T",
61 Par3:=170.01
62 }
63
64 template MyProc MyProcTemplate_any:= {
65 Par1:=?,
66 Par2:=?,
67 Par3:=?
68 }
69
70 template MyProc2 MyProc2Template := { }
71
72 type record address {
73 integer a1,
74 integer a2
75 }
76
77 template address MyAddress(integer p1,integer p2) := {
78 a1:=p1,
79 a2:=p2
80 }
81
82 type port PortAddress procedure {
83 inout MyProc,s_StopPTC;
84 in MyProc2;
85 } with { extension "address" }
86
87 type port ProcPort1 procedure
88 {
89 inout MyProc,s_StopPTC;
90 in MyProc2;
91 out MyProc3;
92 } with {extension "internal"}
93
94 type port ProcPort2 procedure
95 {
96 inout MyProc,s_StopPTC;
97 out MyProc2;
98 in MyProc3;
99 } with {extension "internal"}
100
101 type port ExtProcPort procedure
102 {
103 inout MyProc5;
104 }
105
106 type port CompileOnlyPort procedure
107 {
108 in MyProc;
109 inout MyProc2;
110 out MyProc3;
111 in MyProc4;
112 inout MyProc5;
113 }
114
115 type port CompileOnlyPortAddress procedure {
116 out MyProc;
117 in MyProc2;
118 inout MyProc3;
119 out MyProc4;
120 in MyProc5;
121 } with { extension "address" }
122
123 type port ProcPort3 procedure {
124 inout MyProc6;
125 } with { extension "internal" }
126
127 type component ProcComponent
128 {
129 port ProcPort1 Port0;
130 }
131
132 type component ProcComponent2
133 {
134 port ProcPort2 Port1;
135 }
136
137 type component ProcComponentMultiPort
138 {
139 port ProcPort1 Port0;
140 port ProcPort2 Port1[4];
141 port ExtProcPort Port2;
142 port CompileOnlyPort Port3;
143 port PortAddress Port4;
144 }
145
146 type component eComponent
147 {
148 port ExtProcPort ePort;
149 }
150
151 type component addressComponent
152 {
153 port PortAddress P;
154 }
155
156 type component ProcComponent3 {
157 port ProcPort3 pt;
158 }
159
160 function GetCall_behav1() runs on ProcComponent2 {
161 while(true) {
162 alt {
163 []Port1.getcall(MyProcTemplate_any) {
164 Port1.reply(MyProcTemplate2 value true);
165 }
166 []Port1.getcall(MyProc3Template_any) {
167 Port1.reply(MyProc3Template value 3.1415);
168 }
169 []Port1.getcall(StopPTC) {
170 Port1.reply(StopPTC);
171 stop;
172 }
173 }
174 }
175 }
176
177 function GetCall_behav2() runs on ProcComponent {
178 while(true) {
179 alt {
180 []Port0.getcall(MyProcTemplate2) {
181 Port0.raise(MyProc,integer:555);
182 }
183 []Port0.getcall(MyProcTemplate_any) {
184 Port0.reply(MyProcTemplate value false);
185 }
186 []Port0.getcall(MyProc2Template) {
187 Port0.reply(MyProc2Template);
188 }
189 []Port0.getcall(StopPTC) {
190 Port0.reply(StopPTC);
191 stop;
192 }
193 }
194 }
195 }
196
197 function GetCall_behav3() runs on ProcComponent2 {
198 while(true) {
199 alt {
200 []Port1.getcall(MyProcTemplate2) {
201 Port1.raise(MyProc,integer:272869);
202 }
203 []Port1.getcall(MyProcTemplate_any) {
204 Port1.reply(MyProcTemplateP(22,"G",199.99) value false);
205 }
206 []Port1.getcall(MyProc3Template_any) {
207 Port1.reply(MyProc3Template value 2.78);
208 }
209 []Port1.getcall(StopPTC) {
210 Port1.reply(StopPTC);
211 stop;
212 }
213 }
214 }
215 }
216
217 function Check_getcall_behav() runs on ProcComponent2 {
218 while(true) {
219 alt {
220 []Port1.check(getcall(MyProcTemplate2)) {
221 Port1.getcall;
222 Port1.reply(MyProcTemplate value true);
223 }
224 []Port1.getcall(StopPTC) {
225 Port1.reply(StopPTC);
226 stop;
227 }
228 []Port1.check(getcall) {
229 Port1.getcall;
230 Port1.reply(MyProcTemplate2 value false);
231 }
232 }
233 }
234 }
235
236 // parameters values
237 const integer c_CallParam := 10;
238 const integer c_ReplyParam := 19;
239
240 // error codes
241 template integer t_getCall_invalidValue := -1;
242 template integer t_getCall_timeout := -2;
243
244 function GetCallParameters_behav() runs on ProcComponent3 {
245 var integer x := 0;
246 timer t := 1.0;
247 t.start;
248 alt {
249 [] pt.getcall(MyProc6:{?}) -> param (x) {
250 if (c_CallParam == x) { pt.reply(MyProc6:{c_ReplyParam}); }
251 else { pt.reply(MyProc6:{t_getCall_invalidValue}); }
252 }
253 [] t.timeout { pt.reply(MyProc6:{t_getCall_timeout}); }
254 }
255 }
256
257 testcase Call_tc1() runs on ProcComponent {
258 /* Non-blocking calls */
259 var ProcComponent2 PC2;
260 var integer i:=0;
261 var boolean b:=false;
262 var float f:=0.0;
263 timer T:=1.0;
264 PC2:=ProcComponent2.create;
265 PC2.start(GetCall_behav1());
266 connect(self:Port0,PC2:Port1);
267 T.start;
268 Port0.call(MyProcTemplate,nowait);
269 Port0.call(MyProc3Template,nowait);
270 while(i<2) {
271 alt {
272 []Port0.getreply(MyProcTemplate2) -> value b {
273 if(i==0) {
274 if(b==true) {i:=1;}
275 else {setverdict(fail);stop;}
276 } else {
277 setverdict(inconc);stop;
278 }
279 }
280 []Port0.getreply(MyProc3Template) -> value f {
281 if((i==1)and(f==3.1415)) {i:=2;}
282 else {log(f);setverdict(inconc);stop;}
283 }
284 []T.timeout {
285 setverdict(fail);
286 stop;
287 }
288 }
289 }
290 if(i==2) {setverdict(pass);}
291 Port0.call(StopPTC,0.5) {
292 []Port0.getreply(StopPTC) { }
293 []Port0.catch(timeout) { }
294 }
295 disconnect(self:Port0,PC2:Port1);
296 }
297
298 testcase Call_tc2() runs on ProcComponent2 {
299 /* Blocking calls */
300 var ProcComponent PC;
301 var boolean b:=true;
302 PC:=ProcComponent.create;
303 PC.start(GetCall_behav2());
304 connect(self:Port1,PC:Port0);
305 Port1.call(MyProcTemplate,1.0) {
306 []Port1.getreply(MyProcTemplate value ?) -> value b{
307 Port1.call(MyProc2Template,0.7) {
308 []Port1.getreply(MyProc2Template) {
309 Port1.call(MyProcTemplate2,0.4) {
310 []Port1.catch(MyProc,integer:555) {
311 if(b==false) {setverdict(pass);}
312 else {setverdict(inconc);}
313 }
314 []Port1.catch(timeout) {
315 setverdict(fail);
316 stop;
317 }
318 }
319 }
320 []Port1.catch(timeout) {
321 setverdict(fail);
322 stop;
323 }
324 }
325 }
326 []Port1.catch(timeout) {
327 setverdict(fail);
328 stop;
329 }
330 }
331 Port1.call(StopPTC,0.5) {
332 []Port1.getreply(StopPTC) { }
333 []Port1.catch(timeout) { }
334 }
335 }
336
337 testcase extCall_tc1() runs on eComponent system eComponent {
338 map(self:ePort,system:ePort);
339 ePort.call(MyProc5TemplateP(128,32),0.5) {
340 []ePort.getreply(MyProc5Template_any value 4.0) {
341 setverdict(pass);
342 }
343 []ePort.catch(timeout) {
344 setverdict(fail);stop;
345 }
346 }
347 unmap(self:ePort,system:ePort);
348 }
349
350 testcase extCall_tc2() runs on eComponent system eComponent {
351 map(self:ePort,system:ePort);
352 ePort.call(MyProc5TemplateP(32,128),0.5) {
353 []ePort.getreply(MyProc5Template_any value 0.25) {
354 setverdict(pass);
355 }
356 []ePort.catch(timeout) {
357 setverdict(fail);stop;
358 }
359 }
360 unmap(self:ePort,system:ePort);
361 }
362
363 testcase extCall_tc3() runs on eComponent system eComponent {
364 map(self:ePort,system:ePort);
365 ePort.call(MyProc5TemplateP(128,0),0.5) {
366 []ePort.catch(MyProc5,charstring:"Divide by 0.") {
367 setverdict(pass);
368 }
369 []ePort.catch(timeout) {
370 setverdict(fail);stop;
371 }
372 }
373 unmap(self:ePort,system:ePort);
374 }
375
376 testcase Call_MultiPTC_tc() runs on ProcComponent {
377 /* procedure based communication with multiple PTCs */
378 var ProcComponent2 PC1,PC2;
379 var integer i:=0;
380 timer T:=1.0;
381 PC1:=ProcComponent2.create;
382 PC1.start(GetCall_behav1());
383 connect(self:Port0,PC1:Port1);
384 PC2:=ProcComponent2.create;
385 PC2.start(GetCall_behav3());
386 connect(self:Port0,PC2:Port1);
387 T.start;
388 Port0.call(MyProcTemplate,nowait) to PC1;
389 Port0.call(MyProc3Template,nowait) to PC2;
390 while(i<2) {
391 alt {
392 []Port0.getreply(MyProcTemplate2 value true) from PC1 {
393 i:=i+1;
394 }
395 []Port0.getreply(MyProc3Template value 2.78) from PC2 {
396 i:=i+1;
397 }
398 []T.timeout {
399 setverdict(fail);stop;
400 }
401 }
402 }
403 setverdict(pass);
404 Port0.call(StopPTC,0.5) to PC1 {
405 []Port0.getreply(StopPTC) from PC1 { }
406 []Port0.catch(timeout) { setverdict(fail);stop; }
407 }
408 Port0.call(StopPTC,0.5) to PC2 {
409 []Port0.getreply(StopPTC) from PC2 { }
410 []Port0.catch(timeout) { setverdict(fail);stop; }
411 }
412 disconnect(self:Port0,PC1:Port1);
413 disconnect(self:Port0,PC2:Port1);
414 }
415
416 testcase Call_MultiPTC_anyport_tc() runs on ProcComponentMultiPort {
417 /* testing any-port operations with multiple PTCs */
418 var ProcComponent2 PC1,PC2;
419 var ProcComponent2 sndr;
420 var integer i:=0;
421 var boolean chk1:=true,chk2:=true;
422 timer T:=1.5;
423 PC1:=ProcComponent2.create;
424 PC1.start(GetCall_behav1());
425 connect(self:Port0,PC1:Port1);
426 PC2:=ProcComponent2.create;
427 PC2.start(GetCall_behav3());
428 connect(self:Port0,PC2:Port1);
429 T.start;
430 Port0.call(MyProcTemplate,nowait) to PC1;
431 Port0.call(MyProc3Template,nowait) to PC2;
432 while(i<4) {
433 alt {
434 [chk1]any port.check {
435 i:=i+1;
436 chk1:=false;
437 log("any port.check OK");
438 }
439 [chk2]any port.check(getreply -> sender sndr) {
440 i:=i+1;
441 chk2:=false;
442 log("any port.check(getreply) OK, sender: ",sndr);
443 }
444 []any port.check(catch) {
445 log("any port.check(catch) matched --> fail");
446 setverdict(fail);stop;
447 }
448 []any port.getcall {
449 log("any port.getcall matched --> fail");
450 setverdict(fail);stop;
451 }
452 []any port.getreply from PC1 {
453 log("any port.getreply from PC1 OK");
454 i:=i+1;
455 }
456 []any port.getreply from PC2 {
457 log("any port.getreply from PC2 OK");
458 i:=i+1;
459 }
460 []T.timeout {
461 setverdict(fail);stop;
462 }
463 }
464 }
465 setverdict(pass);
466 Port0.call(StopPTC,0.5) to PC1 {
467 []Port0.getreply(StopPTC) from PC1 { }
468 []Port0.catch(timeout) { setverdict(fail);stop; }
469 }
470 Port0.call(StopPTC,0.5) to PC2 {
471 []Port0.getreply(StopPTC) from PC2 { }
472 []Port0.catch(timeout) { setverdict(fail);stop; }
473 }
474 disconnect(self:Port0,PC1:Port1);
475 disconnect(self:Port0,PC2:Port1);
476 }
477
478 testcase Check_tc1() runs on ProcComponent {
479 var ProcComponent2 PC2;
480 timer T:=1.5;
481 PC2:=ProcComponent2.create;
482 PC2.start(GetCall_behav3());
483 connect(self:Port0,PC2:Port1);
484 Port0.call(MyProcTemplate2,nowait);
485 T.start;
486 alt {
487 []Port0.check(catch) { }
488 []T.timeout {
489 setverdict(fail);
490 stop;
491 }
492 }
493 alt {
494 []any port.check(catch) {
495 log("any port.check(catch) OK");
496 }
497 []T.timeout {
498 setverdict(fail);
499 stop;
500 }
501 }
502 alt {
503 []Port0.check(catch(MyProc,integer:272869)) {
504 Port0.catch;
505 }
506 []T.timeout {
507 setverdict(fail);
508 stop;
509 }
510 }
511 Port0.call(MyProcTemplate,nowait);
512 alt {
513 []Port0.check(getreply) { }
514 []T.timeout {
515 setverdict(fail);
516 stop;
517 }
518 }
519 alt {
520 []Port0.check(getreply(MyProcTemplateP(22,"G",199.99) value false)){
521 Port0.getreply;
522 setverdict(pass);
523 }
524 []T.timeout {
525 setverdict(fail);
526 stop;
527 }
528 }
529 Port0.call(StopPTC,0.5) {
530 []Port0.getreply(StopPTC) { }
531 []Port0.catch(timeout) { }
532 }
533 }
534
535 testcase Check_tc2() runs on ProcComponent {
536 var ProcComponent2 PC2;
537 PC2:=ProcComponent2.create;
538 PC2.start(Check_getcall_behav());
539 connect(self:Port0,PC2:Port1);
540 Port0.call(MyProcTemplate2,1.0) {
541 []Port0.getreply(MyProcTemplate value true) { }
542 []Port0.catch(timeout) {
543 setverdict(fail);
544 stop;
545 }
546 }
547 Port0.call(MyProcTemplate,1.0) {
548 []Port0.getreply(MyProcTemplate2 value false) {
549 setverdict(pass);
550 }
551 []Port0.catch(timeout) {
552 setverdict(fail);
553 stop;
554 }
555 }
556 Port0.call(StopPTC,0.5) {
557 []Port0.getreply(StopPTC) { }
558 []Port0.catch(timeout) { }
559 }
560 }
561
562 testcase PortAddress_internal_usage() runs on ProcComponentMultiPort {
563 /* procedure based internal communication with address-supporting port */
564 var ProcComponent2 PC2;
565 var integer i:=0;
566 PC2:=ProcComponent2.create;
567 PC2.start(GetCall_behav3());
568 connect(self:Port4,PC2:Port1);
569 Port4.call(MyProcTemplateP(11,"T",99.012),1.0) {
570 []Port4.getreply(MyProcTemplateP(22,"G",199.99) value false) {
571 i:=i+1;
572 }
573 []Port4.catch(timeout) {
574 setverdict(fail);stop;
575 }
576 }
577 Port4.call(MyProcTemplate2,1.0) {
578 []Port4.catch(MyProc,integer:272869) {
579 i:=i+1;
580 }
581 []Port4.catch(timeout) {
582 setverdict(fail);stop;
583 }
584 }
585 if(i==2){setverdict(pass);}
586 Port4.call(StopPTC,1.0) {
587 []Port4.getreply(StopPTC) { }
588 []Port4.catch(timeout) {
589 setverdict(fail);
590 }
591 }
592 }
593
594 testcase PortAddress_external_usage1() runs on addressComponent
595 system addressComponent {
596 map(self:P,system:P);
597 P.call(MyProcTemplate,1.0) to valueof(MyAddress(321,67)) {
598 []P.getreply(MyProcTemplate_any value true) from MyAddress(67,321) {
599 setverdict(pass);
600 }
601 []P.catch(timeout) {
602 setverdict(fail);
603 }
604 }
605 unmap(self:P,system:P);
606 }
607
608 testcase PortAddress_external_usage2() runs on addressComponent
609 system addressComponent {
610 map(self:P,system:P);
611 P.call(MyProcTemplate,1.0) to valueof(MyAddress(321,68)) {
612 []P.catch(MyProc,integer:389) from MyAddress(68,321) {
613 setverdict(pass);
614 }
615 []P.catch(timeout) {
616 setverdict(fail);
617 }
618 }
619 unmap(self:P,system:P);
620 }
621
622 function signatureEncode(template MyProc par1, template MyProc par2) runs on addressComponent
623 {
624 log(par1, par2);
625 }
626
627 // tests the 'param' directive in functions 'getcall' and 'getreply',
628 // specificly with signatures containing 'inout' parameters (HT93096)
629 testcase GetReplyParameters_tc() runs on ProcComponent3 {
630 var ProcComponent3 c := ProcComponent3.create;
631 connect(c:pt, self:pt);
632 c.start(GetCallParameters_behav());
633
634 var integer x := 0;
635 pt.call(MyProc6:{c_CallParam}, 1.0) {
636 [] pt.getreply(MyProc6:{t_getCall_invalidValue}) { setverdict(fail, "invalid getcall parameter"); }
637 [] pt.getreply(MyProc6:{t_getCall_timeout}) { setverdict(fail, "getcall timed out"); }
638 [] pt.getreply(MyProc6:{?}) -> param (x) {
639 if (c_ReplyParam == x) { setverdict(pass); }
640 else { setverdict(fail, "invalid getreply parameter"); }
641 }
642 [] pt.catch(timeout) { setverdict(fail, "getreply timed out"); }
643 }
644
645 c.done;
646 }
647
648 control {
649 execute(Call_tc1());
650 execute(Call_tc2());
651 execute(extCall_tc1());
652 execute(extCall_tc2());
653 execute(extCall_tc3());
654 execute(Call_MultiPTC_tc());
655 execute(Call_MultiPTC_anyport_tc());
656 execute(Check_tc1());
657 execute(Check_tc2());
658 execute(PortAddress_internal_usage());
659 execute(PortAddress_external_usage1());
660 execute(PortAddress_external_usage2());
661 execute(GetReplyParameters_tc());
662 }
663 }
This page took 0.079866 seconds and 6 git commands to generate.