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