Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
import "logging.eol";
import "common.eol";
import "helper.eol";
import "debug.eol";
import "reusable.eol";
operation TDL!Interaction executeSource() : TTCN!FunctionStatementList {
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.communication = new TTCN!CommunicationStatements();
sfs.communication.send = new TTCN!SendStatement();
//sfs.communication.send.port = self.sourceGate.gate.equivalent();
sfs.communication.send.port = self.sourceGate.equivalent().port;
sfs.communication.send.send = new TTCN!PortSendOp();
sfs.communication.send.send.template = new TTCN!InLineTemplate();
sfs.communication.send.send.template.template = self.argument.getTemplateBody();
ssl.statements.add(sfs);
ssl.sc.add(";");
return ssl;
}
operation TDL!Interaction executeTarget(t : TDL!Target) : TTCN!FunctionStatementList {
var tsl = new TTCN!FunctionStatementList();
var tfs = new TTCN!FunctionStatement();
tfs.communication = new TTCN!CommunicationStatements();
tfs.communication.receive = new TTCN!ReceiveStatement();
tfs.communication.receive.any = new TTCN!PortOrAny();
//tfs.communication.receive.any.ref = t.targetGate.gate.equivalent();
tfs.communication.receive.any.ref = t.targetGate.equivalent().port;
tfs.communication.receive.receive = new TTCN!PortReceiveOp();
tfs.communication.receive.receive.template = new TTCN!InLineTemplate();
tfs.communication.receive.receive.template.template = self.argument.getTemplateBody();
if (not t.valueAssignment.isEmpty()) {
var pr = new TTCN!PortRedirect();
tfs.communication.receive.receive.redirect = pr;
pr.value = new TTCN!ValueSpec();
pr.value.variable = new TTCN!VariableRef();
pr.value.variable.ref = new TTCN!ReferencedValue();
pr.value.variable.ref.head = new TTCN!Head();
pr.value.variable.ref.head.target = t.valueAssignment.get(0).variable.equivalent();
}
tsl.statements.add(tfs);
tsl.sc.add(";");
return tsl;
}
operation TDL!Interaction execute() {
//TODO: needs adapting to context
// add a statement block stack for each component during transformation?
//TODO: simplify
//source behaviour
if ((simulateSUT or self.sourceGate.component.role = TDL!ComponentInstanceRole#Tester)
and (currentScope.isUndefined() or currentScope = self.sourceGate.component)
) {
var sc = self.getMainContext(self.sourceGate.component);
var sb = stack.get(sc).last();
var ssl = self.executeSource();
sb.stat.add(ssl);
}
//TODO: handle multicast?
//target behaviour
if ((simulateSUT or self.target.first().targetGate.component.role = TDL!ComponentInstanceRole#Tester)
and (currentScope.isUndefined() or currentScope = self.target.first().targetGate.component)
) {
var tc = self.getMainContext(self.target.first().targetGate.component);
var tb = stack.get(tc).last();
var t = self.target.first();
var tsl = self.executeTarget(t);
tb.stat.add(tsl);
}
//inlined above
//self.execute(sb, tb);
}
//TODO: remove? (inlined above)
operation TDL!Interaction execute(sourceContext : TTCN!StatementBlock, targetContext : TTCN!StatementBlock) {
//source behaviour
var ssl = self.executeSource();
sourceContext.stat.add(ssl);
//TODO: handle multicast?
//target behaviour
var t = self.target.first();
var tsl = self.executeTarget(t);
targetContext.stat.add(tsl);
}
operation TDL!AlternativeBehaviour execute() {
if (not transformAlt) return;
var td = self.getTestDescription();
//TODO: naive simplified assumption
var fb = self.block.first().behaviour.first();
if (fb.isKindOf(TDL!Interaction)) {
if (simulateSUT or fb.sourceGate.component.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(fb.sourceGate.component);
var sb = stack.get(sc).last();
self.executeSource(sb);
}
if (simulateSUT or fb.target.first().targetGate.component.role = TDL!ComponentInstanceRole#Tester) {
var tc = self.getMainContext(fb.target.first().targetGate.component);
var tb = stack.get(tc).last();
self.executeTarget(tb);
}
}
}
operation TDL!AlternativeBehaviour executeTarget(targetContext : TTCN!StatementBlock) {
var tsl = self.executeTarget();
targetContext.stat.add(tsl);
}
operation TDL!AlternativeBehaviour executeSource(sourceContext : TTCN!StatementBlock) {
//TODO: simple assumption - trigger first
//TODO: needs to follow path, right now triggers first interactions in other branches as well
var fb = self.block.first().behaviour.first();
if (fb.isKindOf(TDL!Interaction)) {
var ssl = fb.executeSource();
sourceContext.stat.add(ssl);
}
}
operation TDL!AlternativeBehaviour checkPath() : Boolean {
var first = true;
if (self.eContainer.isDefined()) {
if (self.eContainer.isKindOf(TDL!Block)) {
if (self.eContainer.eContainer.isKindOf(TDL!AlternativeBehaviour)) {
if (self.eContainer.eContainer.block.indexOf(self.eContainer) <> 0) {
first = false;
} else {
first = self.eContainer.eContainer.checkPath();
}
}
}
}
return first;
}
operation TDL!AlternativeBehaviour executeTarget() : TTCN!FunctionStatementList {
if (not transformAlt) return;
//TODO
//target only so far..
//where should this be placed? in the receiving side?
//how about source
//TODO: add explicit scoping
var tsl = new TTCN!FunctionStatementList();
var fs = new TTCN!FunctionStatement();
fs.behavior = new TTCN!BehaviourStatements();
fs.behavior.alt = new TTCN!AltConstruct();
fs.behavior.alt.agList = new TTCN!AltGuardList();
for (block in self.block) {
var gs = block.executeAltBlock();
fs.behavior.alt.agList.guardList.add(gs);
}
tsl.statements.add(fs);
//tsl.sc.add(";");
return tsl;
}
operation TDL!Block executeAltBlock() : TTCN!GuardStatement {
var gs = new TTCN!GuardStatement();
gs.`guard` = new TTCN!AltGuardChar();
//TODO: expression
gs.block = new TTCN!StatementBlock();
//naive assumption
if (self.behaviour.first().isKindOf(TDL!Interaction)) {
var cf = self.behaviour.first().getMainContext(self.behaviour.first().target.first().targetGate.component);
stack.get(cf).add(gs.block);
var i = 0;
for (b in self.behaviour) {
if (i==0) {
//this should be redundant now
if (b.isKindOf(TDL!Interaction)) {
gs.op = b.getGuardOp();
} else {
//TODO: handle other behaviours?
}
} else {
b.execute();
}
i = i+1;
}
stack.get(cf).remove(gs.block);
} else if (self.behaviour.first().isKindOf(TDL!TimeOut)) {
var cf = self.behaviour.first().getMainContext(self.behaviour.first().componentInstance);
stack.get(cf).add(gs.block);
var i = 0;
for (b in self.behaviour) {
if (i==0) {
//this should be redundant now
if (b.isKindOf(TDL!TimeOut)) {
gs.op = b.getGuardOp();
} else {
//TODO: handle other behaviours?
}
} else {
b.execute();
}
i = i+1;
}
stack.get(cf).remove(gs.block);
} else {
//TODO
}
//TODO: statement block
return gs;
}
operation TDL!BoundedLoopBehaviour execute() {
//TODO: no component?
for (le in self.numIteration) {
currentScope = le.scope;
var sc = self.getMainContext(le.scope);
var sb = stack.get(sc).last();
var tsl = new TTCN!FunctionStatementList();
sb.stat.add(tsl);
var fs = new TTCN!FunctionStatement();
fs.basic = new TTCN!BasicStatements();
fs.basic.loop = new TTCN!LoopConstruct();
fs.basic.loop.forStm = new TTCN!ForStatement();
tsl.statements.add(fs);
var init = new TTCN!Initial();
fs.basic.loop.forStm.init = init;
var cv = new TTCN!SingleVarInstance();
var exp = new TTCN!RelExpression();
fs.basic.loop.forStm.expression = exp;
//init
if (le.expression.isKindOf(TDL!DataInstanceUse)) {
cv.name = "cv";
cv.ac = ":=";
cv.expr = new TTCN!Value();
cv.expr.predef = new TTCN!PredefinedValue();
cv.expr.predef.integer = "0";
init.variable = new TTCN!VarInstance();
//TODO: add more comprehensive resolution
init.variable.listType = le.expression.dataInstance.dataType.getTTCNType();
init.variable.list = new TTCN!VarList();
init.variable.list.variables.add(cv);
//TODO: the TTCN3 grammar needs to save the operators
//control
exp.left = new TTCN!Value();
exp.left.ref = new TTCN!ReferencedValue();
exp.left.ref.head = new TTCN!Head();
exp.left.ref.head.target = cv;
exp.right = new TTCN!Value();
exp.right.ref = new TTCN!ReferencedValue();
exp.right.ref.head = new TTCN!Head();
if (le.expression.dataInstance.isValue()) {
exp.right.ref.head.target = le.expression.dataInstance.equivalent().defs.list.first();
} else {
//can it even be template?
exp.right.ref.head.target = le.expression.dataInstance.equivalent().base;
}
} else {
//TODO:
}
//increment
var assign = new TTCN!Assignment();
assign.ref = new TTCN!VariableRef();
assign.ref.ref = new TTCN!ReferencedValue();
assign.ref.ref.head = new TTCN!Head();
assign.ref.ref.head.target = cv;
assign.expression = new TTCN!AddExpression();
assign.expression.left = new TTCN!Value();
assign.expression.left.ref = new TTCN!ReferencedValue();
assign.expression.left.ref.head = new TTCN!Head();
assign.expression.left.ref.head.target = cv;
assign.expression.right = new TTCN!Value();
assign.expression.right.predef = new TTCN!PredefinedValue();
assign.expression.right.predef.integer = "1";
fs.basic.loop.forStm.assign = assign;
var block = new TTCN!StatementBlock();
fs.basic.loop.forStm.statement = block;
var cf = self.getMainContext(le.scope);
stack.get(cf).add(block);
for (b in self.block.behaviour) {
b.execute();
}
stack.get(cf).remove(block);
currentScope = null;
}
}
operation TDL!UnboundedLoopBehaviour execute() {
//TODO
for (b in self.block.behaviour) {
b.execute();
}
}
operation TDL!ConditionalBehaviour execute() {
var guards = self.block.get(0).`guard`;
for (le in guards) {
currentScope = le.scope;
var sc = self.getMainContext(le.scope);
var sb = stack.get(sc).last();
var tsl = new TTCN!FunctionStatementList();
sb.stat.add(tsl);
var sfs = new TTCN!FunctionStatement();
sfs.basic = new TTCN!BasicStatements();
sfs.basic.conditional = new TTCN!ConditionalConstruct();
//condition
sfs.basic.conditional.expression = le.expression.getDataUseValue();
tsl.statements.add(sfs);
//main block
var block = new TTCN!StatementBlock();
sfs.basic.conditional.statement = block;
var cf = self.getMainContext(le.scope);
stack.get(cf).add(block);
for (b in self.block.get(0).behaviour) {
b.execute();
}
stack.get(cf).remove(block);
//TODO: else ifs
//else block
if (self.block.size() > 1) {
sfs.basic.conditional.`else` = new TTCN!ElseClause();
var eBlock = new TTCN!StatementBlock();
sfs.basic.conditional.`else`.statement = eBlock;
stack.get(cf).add(eBlock);
for (b in self.block.last().behaviour) {
b.execute();
}
stack.get(cf).remove(eBlock);
}
currentScope = null;
}
}
operation TDL!tdl::Assignment execute() {
var ci = self.variable.componentInstance;
if (simulateSUT or ci.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.basic = new TTCN!BasicStatements();
sfs.basic.assign = new TTCN!Assignment();
sfs.basic.assign.ref = new TTCN!VariableRef();
sfs.basic.assign.ref.ref = new TTCN!ReferencedValue();
sfs.basic.assign.ref.ref.head = new TTCN!Head();
sfs.basic.assign.ref.ref.head.target = self.variable.variable.equivalent();
sfs.basic.assign.expression = self.expression.getDataUseValue();
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!Assertion execute() {
var ci = self.componentInstance;
if (simulateSUT or ci.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.basic = new TTCN!BasicStatements();
sfs.basic.conditional = new TTCN!ConditionalConstruct();
//condition
sfs.basic.conditional.expression = self.condition.getDataUseValue();
//statements - pass
sfs.basic.conditional.statement = new TTCN!StatementBlock();
var psl = new TTCN!FunctionStatementList();
psl.statements.add("pass".getVerdictStatement());
sfs.basic.conditional.statement.stat.add(psl);
//else - otherwise verdict
sfs.basic.conditional.`else` = new TTCN!ElseClause();
sfs.basic.conditional.`else`.statement = new TTCN!StatementBlock();
var osl = new TTCN!FunctionStatementList();
if (self.otherwise.isDefined()) {
osl.statements.add(self.otherwise.getVerdictStatement());
} else {
osl.statements.add("fail".getVerdictStatement());
}
sfs.basic.conditional.`else`.statement.stat.add(osl);
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!ActionReference execute() {
var ci = self.componentInstance;
if (simulateSUT or ci.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.behavior = new TTCN!BehaviourStatements();
sfs.behavior.`function` = new TTCN!FunctionInstance();
sfs.behavior.`function`.ref = self.action.equivalent();
if (not self.actualParameter.isEmpty()) {
var pl = new TTCN!FunctionActualParList();
sfs.behavior.`function`.params = pl;
for (ap in self.actualParameter) {
var p = new TTCN!FunctionActualPar();
p.template = new TTCN!InLineTemplate();
p.template.template = new TTCN!TemplateBody();
p.template.template.simple = new TTCN!SimpleSpec();
p.template.template.simple.expr = ap.dataUse.getDataUseValue();
pl.params.add(p);
}
}
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!TestDescriptionReference execute() {
//TODO: support parameters (also in initialisation in TD2FD)
//TODO: support bindings
for (ci in self.getTestDescription().testConfiguration.componentInstance.select(c|simulateSUT or c.role = TDL!ComponentInstanceRole#Tester)) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var tc = self.testDescription.getMainContext(ci);
var cf = TTCN!FunctionDef.all().select(f|f.name = tc).first();
if (cf.isDefined()) {
var ssl = new TTCN!FunctionStatementList();
var s = new TTCN!FunctionStatement();
s.behavior = new TTCN!BehaviourStatements();
s.behavior.`function` = new TTCN!FunctionInstance();
s.behavior.`function`.ref = cf;
ssl.statements.add(s);
ssl.sc.add(";");
sb.stat.add(ssl);
} else {
(" Could not resolve "+tc).log(1);
//TODO
}
}
}
operation TDL!VerdictAssignment execute() {
for (ci in self.getTestDescription().testConfiguration.componentInstance.select(c|simulateSUT or c.role = TDL!ComponentInstanceRole#Tester)) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = self.verdict.getVerdictStatement();
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!CompoundBehaviour execute() {
//TODO
for (b in self.block.behaviour) {
b.execute();
}
}
operation TDL!TimerStart execute() {
var ci = self.componentInstance;
if (simulateSUT or ci.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.timer = new TTCN!TimerStatements();
sfs.timer.start = new TTCN!StartTimerStatement();
sfs.timer.start.ref = self.timer.equivalent();
sfs.timer.start.expr = self.period.getDataUseValue();
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!TimerStop execute() {
var ci = self.componentInstance;
if (simulateSUT or ci.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.timer = new TTCN!TimerStatements();
sfs.timer.stop = new TTCN!StopTimerStatement();
sfs.timer.stop.ref = new TTCN!TimerRefOrAll();
sfs.timer.stop.ref.ref = self.timer.equivalent();
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!TimeOut execute() {
//TODO: handle in an alt statement?
var ci = self.componentInstance;
if (simulateSUT or ci.role = TDL!ComponentInstanceRole#Tester) {
var sc = self.getMainContext(ci);
var sb = stack.get(sc).last();
var ssl = new TTCN!FunctionStatementList();
var sfs = new TTCN!FunctionStatement();
sfs.timer = new TTCN!TimerStatements();
sfs.timer.timeout = new TTCN!TimeoutStatement();
sfs.timer.timeout.ref = new TTCN!TimerRefOrAny();
sfs.timer.timeout.ref.ref = self.timer.equivalent();
ssl.statements.add(sfs);
ssl.sc.add(";");
sb.stat.add(ssl);
}
}
operation TDL!Behaviour execute() {
(" Skipping " +self.type.name+" (not yet supported)").println();
if (self.type.name = "ParallelBehaviour" and false) {
(indent+"group Parallel").printlno();
var i = 0;
for (block in self.block) {
for (b in block.behaviour) {
b.execute(indent+" ");
}
if (i <= block.size()) {
(indent+"else").printlno();
}
i = i+1;
}
(indent+"end").printlno();
}
}