Altsteps re-calculate guard conditions and local variable initial values
In altsteps in Titan, the boolean expressions in alt-guards and the initial values of local variables are re-calculated every time the altstep is called. An altsteps can be called multiple times from the same alt statement, every time it takes a new snapshot.
According to the TTCN-3 standard, the guard expressions and the variable initial values are supposed to be calculated only once in each alt statement, from the data in the first snapshot (discussed with Denis Filatov from ETSI).
For example:
type component CT {
var integer counter := 0;
timer t1 := 1.0;
}
function f() runs on CT return integer {
counter := counter + 1;
return counter;
}
altstep as() runs on CT {
var integer local := f();
[t1.running] t1.timeout { log(local); }
}
testcase TC1() runs on CT {
t1.start;
alt {
[] as() {}
}
}
Currently function 'f()' is called twice, increasing the counter to 2, because the altstep is executed twice in the alt statement (once at the start, and once when timer 't1' has timed out. Similarly, the guard expression, 't1.running', is evaluated twice. In the first snapshot it is true (since the timer has not timed out yet), and in the second snapshot it is false (so 't1.timeout' is not checked).
According to the standard, 'f()' should only be called once, and 't1.running' should only be evaluated once.
If the alt branch from the altstep was moved into the alt statement directly, then it would work as intended (i.e. the guard expression would only be evaluated once, from the first snapshot).
/cc @aknappqwt @mmagyari