Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Incomplete Behavior Types Support?
Incomplete Behavior Types Support? [message #1780789] Sat, 27 January 2018 10:37 Go to next message
Harald Welte is currently offline Harald WelteFriend
Messages: 140
Registered: July 2017
Location: Berlin, Germany
Senior Member

The TITAN reference / programmers guide states in section 3.9 "TITAN supports the behaviour type package of the TTCN-3 standard, but with a different syntax". So my assumption is that its functionally equivalent to the spec, just with different syntax.

I have successfully used the refers/derefers syntax when starting new components. So my code looks exactly like Table 2 + Table 3 in 3.9 of the manual, and that works.

However, I seem to be unable to simply call a function without starting a new component. My reading of ES 202 785: "A function can also be invoked by the apply operation by referring to an expression of a behaviour type of kind function and to a parameter list. " seems to indicate that one can simply invoke a function from a behavior type.

The TTCN-3 manual now states that instead of apply, one uses derefers.

However, it fails. Something like this will simply not compile (on 6.3.0):
module x {
  type function ft();
  function f() { }
  type component ct { }
  testcase tc() runs on ct
  {
    var ft vf := refers(f);
    derefers(vf)();
  }
}


In fact, the above example is taken from the titan.core semantic analyzer script and it is named "Function reference - derefers used where it is not supposed to be used ". But why is it not supposed to be used? Isn't it exactly used like indicated in the spec on behaviour types?

What am I missing? Is this not actually supported and the corresponding statement in the manual a bit too bold?
Re: Incomplete Behavior Types Support? [message #1780790 is a reply to message #1780789] Sat, 27 January 2018 11:13 Go to previous messageGo to next message
Harald Welte is currently offline Harald WelteFriend
Messages: 140
Registered: July 2017
Location: Berlin, Germany
Senior Member

actually, it seems that the "Behaviour Types" are referenced twice in the programmers guide (2/198 17-CRL 113 200/6 Uen): as both [5] and [20]
Re: Incomplete Behavior Types Support? [message #1780859 is a reply to message #1780790] Mon, 29 January 2018 10:32 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Harald,

OK, lets go step by step:

-in the standard, the refers is implicit:
type function MyFunc3 ( in integer p1 ) return charstring;
function f(integer p) return charstring { return int2char(p)  };
:
var MyFunc3 myVar1 := f;


but in Titan has been made explicit, by the usage of refers keyword:

type function MyFunc3 ( in integer p1 ) return charstring;
function f(integer p) return charstring { return int2char(p)  };
:
var MyFunc3 myVar1 := refers(f);



-in the standard, apply is being used in direct function invokation and
also when using the function as a parameter of start, activate , execute

In Titan this is split in direct function invokation where apply is being used and the other usage where derefers is being used.

direct invokation:

in the standard:

type function MyFunc3 ( in integer p1 ) return charstring;
function f(integer p) return charstring { return int2char(p)  };
:
var MyFunc3 f_var1 := f;  //refers 
apply(f_var1(MyVar1))    //apply



in Titan:


type function MyFunc3 ( in integer p1 ) return charstring;
function f(integer p) return charstring { return int2char(p)  };
:
var MyFunc3 f_var1 := refers(f);
f_var1.apply(MyVar1)


using the function as an operation parameter:

in the standard:

type function t_functionstartTests();
var t_functionstartTests vl_function;

vl_comp.start(apply(vl_function2)());



in Titan:


type function t_functionstartTests();
var t_functionstartTests vl_function;

vl_comp.start(derefers(vl_function2)());




The reason for the changes is that it makes the compilers job easier in interpreting different situations.



This means that in your example the derefers indeed should not be used in that place; in its stead , apply is to be be used:

module x {
  type function ft(in integer p) return integer;

  function f(integer p) return integer { return p+11; }
  type component ct { }
  testcase tc() runs on ct
  {

    var integer MyVar := 2;
    var ft vf := refers(f);
 
    log(vf)
    log(vf.apply(MyVar))
     vf.apply(MyVar);
   //derefers(vf)();
  }

control {

execute(tc())

}

}


When executed, this results in:


11:26:31.437757 TTCN-3 Main Test Component started on esekilxxen1844. Version: CRL 113 200/6 R3B.
11:26:31.437896 TTCN Logger v2.2 options: TimeStampFormat:=Time; LogEntityName:=No; LogEventTypes:=No; SourceInfoFormat:=None; *.FileMask:=LOG_ALL; *.ConsoleMask:=ACTION | ERROR | TESTCASE | STATISTICS_VERDICT | STATISTICS_UNQUALIFIED | WARNING; LogFileSize:=0; LogFileNumber:=1; DiskFullAction:=Error
11:26:31.437986 Connected to MC.
11:26:31.446534 Executing control part of module x.
11:26:31.446631 Execution of control part in module x started.
11:26:31.446752 Test case tc started.
11:26:31.446815 Initializing variables, timers and ports of component type x.ct inside testcase tc.
11:26:31.446854 Component type x.ct was initialized.
11:26:31.446871 refers(x.f)
11:26:31.446910 13
11:26:31.446930 Terminating component type x.ct.
11:26:31.446942 Component type x.ct was shut down inside testcase tc.
11:26:31.446955 Waiting for PTCs to finish.
11:26:31.447013 Setting final verdict of the test case.
11:26:31.447043 Local verdict of MTC: none
11:26:31.447068 No PTCs were created.
11:26:31.447082 Test case tc finished. Verdict: none
11:26:31.447124 Execution of control part in module x finished.
11:26:31.454533 Verdict statistics: 1 none (100.00 %), 0 pass (0.00 %), 0 inconc (0.00 %), 0 fail (0.00 %), 0 error (0.00 %).
11:26:31.454659 Test execution summary: 1 test case was executed. Overall verdict: none
11:26:31.454702 Exit was requested from MC. Terminating MTC.




I hope this makes it somewhat clearer.

Sorry for the documentation errors, we'll fix the double reference.

Best regards
Elemer






[Updated on: Mon, 29 January 2018 19:09]

Report message to a moderator

Re: Incomplete Behavior Types Support? [message #1780870 is a reply to message #1780859] Mon, 29 January 2018 12:14 Go to previous messageGo to next message
Jeno Attila Balasko is currently offline Jeno Attila BalaskoFriend
Messages: 80
Registered: September 2013
Location: Budapest, Hungary
Member

Hi Harald,

I also wrote some simple testcases to illustrate the usage of behavior types.
They are in an attached file and it is also copied here.
Hopefully it helps.

Best regards
Jeno

module FuncRefExample {

modulepar integer tsp_i := 0;

type component CT {
  const charstring vc_message := "Hello from CT";
}

type function FT_1();

type function FT_2() runs on CT;

function f_1() {
  log("Hello");
}

function f_2() {
  log("Hi")
}

function f_3_CT() runs on CT {
  log(vc_message);
}

testcase tc_1() runs on CT {
  var FT_1 vl_f:= refers(f_1);
  vl_f.apply();
}

testcase tc_2() runs on CT {
  var FT_1 vl_f:= refers(f_2);
  vl_f.apply();
}

//late binding
testcase tc_3() runs on CT {
  var FT_1 vl_f:= null;
  if ( tsp_i == 0) {
    vl_f := refers(f_1);
  } else {
    vl_f := refers(f_2);
  }
  vl_f.apply();
  
}

testcase tc_4() runs on CT {
  var CT vlc_myComponent := CT.create;
  var FT_2 vl_f := refers(f_3_CT);
  vlc_myComponent.start(derefers(vl_f)());
}


control{
  execute(tc_1());
  execute(tc_2());
  execute(tc_3());
  execute(tc_4());
}
}

Re: Incomplete Behavior Types Support? [message #1781021 is a reply to message #1780859] Wed, 31 January 2018 15:59 Go to previous message
Harald Welte is currently offline Harald WelteFriend
Messages: 140
Registered: July 2017
Location: Berlin, Germany
Senior Member

Thanks a lot for your explanation. From reading the programmers reference manual I was under the impression that apply doesn't exist at all in TITAN, and that derefers is always used instead of apply(). Guess I must have been misreading it.

Now with f_var.apply() my use case is solved. Thanks.
Previous Topic:Avoiding all initialization at every test case
Next Topic:avoiding warnings about unused function arguments
Goto Forum:
  


Current Time: Fri Apr 19 14:03:08 GMT 2024

Powered by FUDForum. Page generated in 0.02086 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top