Post on 20-Jan-2016
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 1
An Introductory OverviewAnthony Wiles
ETSI PTCC/ETSI STF 156
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 2
Presentation Outline1. Basic Concepts2. Structure and Contents of a TTCN-3 Test Suite3. TTCN-3 Data Types4. Defining Test Data5. Specifying elements of Test System Architecture 6. Specifying Test System Behaviour7. TTCN-3 Program Statements and Operations 8. Creating, Building and Controlling Test Configurations9. Communication Between Test Components10. TTCN-3 Behaviour Trees11. Timers, Verdicts and SUT Operations 12. Executing and Controlling Test Cases
13.Specifying Additional Attributes
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 3
Basic Concepts
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 4
History of TTCN
• TTCN: Tree and Tabular Combined Notation
• Versions 1 and 2 developed by ISO SC21 WG3 (1984 - 1997) as part of the widely-used ISO/IEC 9646 conformance testing standard
– ISO/IEC 9646-3 and ITU-T X.292
– Updates/maintenance by ETSI in TR 101 666 (TTCN-2++)
• Version 3 developed by ETSI TC MTS (1998 - 2000)
– Specialist Task Forces STF 133 & STF 156
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 5
TTCN-3 Standard Documents
• Three-part ETSI Standard (ES)
– DES/MTS-00063-1 : Core Language
– DES/MTS-00063-2 : Tabular Presentation Format
– DES/MTS-00063-3 : MSC Presentation Format
• ITU-T equivalents Z.140, Z.141, Z.142
• Additional Documents
– DTR/MTS-00069 : TTCN-2 to TTCN-3 Mapping
– DTS/MTS-00070 : Library of Predefined Functions
TTCN-3
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 6
Motivation for Producing TTCN-3
Modernization – technology has changed since TTCN was first developed
Wider scope of application– should be applicable to many kinds of test applications
not just conformance (development, system, integration, iop …)
Harmonization– should be the first choice for test specifiers, implementors
and users both for standardized test suites ...
… and as a generic solution in industrial product development
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 7
Main Capabilities of TTCN-3• Dynamic concurrent testing configurations
• Various communication mechanisms (synch and asynch)
• Data and signature templates with powerful matching mechanisms
• Specification of encoding information
• Display and user-defined attributes
• Test suite parameterization
• Test case control and selection mechanisms
• Assignment and handling of test verdicts
• Harmonized with ASN.1
• Different presentation formats
• Well-defined syntax, static semantics and operational semantics
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 8
The Core Language
PresentationFormat3
PresentationFormatn
TTCN-3 Core Language
Text format
MSC Format
Tabular Format
• Core format is a text based language
• Core can be viewed as text or in various presentation formats
• Tabular format for conformance testing
• Message Sequence Chart (MSC)format
• Other standardized formats in the future
• Proprietary formats
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 9
Example Core (Text) Formatfunction PO49901(integer FL) runs on MyMTC {
L0.send(A_RL3(FL,CREF1,16));TAC.start;alt {
[] L0.receive(A_RC1((FL+1) mod 2)) { TAC.cancel;
verdict.set(pass)
}
[] TAC.timeout { verdict.set(inconc)
}
[] any.receive { verdict.set(fail) }
}END_PTC1() // postamble as function call
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 10
Example Tabular FormatTest Case Definition
Name : MyTestcase
Group :
Purpose : Example Testcase
System I/f :
MTC Type : MyComponentType
Comments :
Name Type Initial Value Comments
MyVar INTEGER 0
Behaviour Definition Commentsalt{ [ ] MyPort.receive(Msg);
[ ] … :
}
DetailedComments:
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 11
Example MSC Format
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 12
Use With Other Languages
TTCN-3 Core Language
Other types & Values2
Other types & Valuesn
ASN.1 Types & Values • TTCN can be integrated
with other 'type and value' systems
• Fully harmonized with ASN.1 (1997)
• Harmonization possible with other type and value systems (possibly from proprietary languages)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 13
Major Elements of TTCN-3
Test Behaviour
Test System Architecture
• Built-in and user-defined generic data types (e.g., to define messages, service primitives, information elements, PDUs)
• Actual test data transmitted/received during testing
• Definition of the components and communication ports that are used to build various testing configurations
• Specification of the dynamic test system behaviour
TTCN-3 Core
Test Data
Data Types
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 14
Structure and Contents of a TTCN-3 Test Suite
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 15
• Modules are the building blocks of all TTCN-3 specifications
• A test suite is a module
• A module has a definitions part and a control part
• Modules can be parameterised
• Modules can import definitions from other modules
• Modules can have attributes
TTCN-3 Modules
Attributes
Module (…)
Module Control
Module Definitions
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 16
Example of Module Structure
module MyModule (integer MyTSPar1)
{
: // Definitions part
control
{
: // Control part
}
}
with display “ETSI format”;
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 17
Module Definitions
• Definitions are global to the entire module
• Data Type definitions are based on the TTCN-3 predefined types
• Templates and Signatures define the test data
• Ports and Components are used in Test Configurations
• Functions, Named Alts and Test Cases define behaviourTest Cases
Named Alternatives
Functions
Test Components
Communication Ports
Signature Templates
Data Templates
RP Signatures
Constants
Data Types
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 18
Importing Definitions
// Importing single definitions
import template MyTemplate from MyModule;
// Importing definitions of the same kind
import all template from MyModule;
// Importing all definitions
import all from MyModule;
// inhibiting recursive import
import template MyTemplate from MyModule nonrecursive;
/* To avoid name clashes the imported definition is prefixed with the identifier of the source module */
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 19
External Definitions
// External constants may be defined
external const integer MyExternalConst;
// External functions may be defined
external function MyFunction4() return integer;
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 20
Groups of Definitions// A nested group of function definitions
group MyTestStepLibrary
{ group MyGroup1
{ function MyTestStep11 { … }
:
function MyTestStep1n { … }
}
group MyGroup2
{ function MyTestStep21 { … }
:
function MyTestStep2n { … }
}
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 21
TTCN-3 Data Types
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 22
TTCN-3 Base TypesClass of type Keywords Sub-type
integer range, listBasic typesfloatbooleanobjectidentifierverdicttype
Basic string types bitstringhexstringoctetstring
list, length
Basic characterstringtypes
charstringuniversal charstring
list, length
User-definedstructured types
record, record ofset, set ofenumeratedunion
Special configurationtypes
addressportcomponent
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 23
Example of Integer Type
/* integer sub-type RANGE definition */
type integer MyIntegerRange (1 .. 100)
type integer MyIntegerRange (0 .. infinity)
/* integer sub-type LIST definition */
type integer MyIntegerList (1 , 2, 3, 4)
/* integer sub-type as a mixed LIST and RANGE */
type integer MyIntegerListAndRange (1 ..5, 7, 9)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 24
Example of a Structured Type
// record type definition
type record MyMessageType
{ integer field1 optional,
boolean field2
}
// record value notation
var MyMessageType MyMessage
{ field1 1,
field2 true
}
// Individual field assignment
MyMessage.field2 := false
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 25
Arrays
/* Arrays are not considered to be types in TTCN-3. Instead, they are specified at the point of variable declaration */
// integer array of 5 elements
var integer MyArray[5];
// indexing starts at zero
MyArray[0]:= 1;
// An initialiser may be used to set array values
MyArray := {1,2,3,4,5};
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 26
ASN.1 Type Compatibility• The following ASN.1 types are considered to be
equivalent to their TTCN-3 counterparts
• TTCN-3 value notation, operators etc. may be used on values of these types a TTCN module
integerbooleanobjectidentifierbitstringoctetstringsequencesequence ofsetset ofenumeratedunion
ASN.1 types
INTEGERBOOLEANOBJECT IDENTIFIERBIT STRINGOCTET STRINGSEQUENCESEQUENCE OFSETSET OFENUMERATEDCHOICE
TTCN types
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 27
Defining Test Data
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 28
Different Uses of Data in TTCN-3 Test Specifications
• Data in TTCN-3 is used
– internally to the test component
– as information passed between test components within the test system
– as test data transmitted to and received from the System Under Test (SUT)
• The grouping mechanism can be used to collect data definitions of a similar ‘kind’ e.g.,
– Service Primitives (ASP)
– Protocol Data Units (PDU)
– internal coordination messages
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 29
Constants (and Variables)
/* Constants are defined in the definitions part of a module (and inside functions and test components) */
constant integer MyConstant := 1;
/* Variables can only be declared in the module control part (and inside functions and test components) TTCN-3 does not support global variables */
var hexstring MyHexString;
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 30
Example Message Definition// Complex messages can be defined by records
Type record MyMessageType MyMessage :=
{
field1 integer optional,
field2 integer,
field3 integer,
field4 integer,
field5 boolean optional,
field6 hexstring optional,
field7 AnotherMessageType,
field8 bitstring,
field9 charstring (1 .. 20)
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 31
Data Templates
• Templates are special data values that have the following characteristics
– matching mechanisms
– they can be parameterised
– they can be modified to provide a simple form of inheritance
• Templates can be applied to simple types as well as complex types
• Are most often used to define the possible received values of messages and responses to remote procedure calls
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 32
Matching Mechanisms
Notation Descriptiom( … ) Match a value in a list of values
not ( … ) Match a value not in a list of values
( lower .. upper) Match an integer range
? Wildcard for any value
* Wildcard for any value or no value
..<?>.. Wildcard for any single element in a stringor array
..<*>.. Wildcard for any number (including zero) ofconsecutive elements in a string or array
length Match on a restricted length (string type)
ifpresent Match if an optional element is present
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 33
Examples of Simple Templates
/* Template for a simple integer type */
template integer MyData1 := *;
template integer MyData2 := (1, 2, 3);
/* This line in a test behaviour description will match any incoming integer value */
P1.receive(MyData1);
/* This line will match on one of the incoming integer values 1, 2 or 3 */
P1.receive(MyData2);
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 34
Example Message Template
template MyMessageType MyMessage :=
{
field1 1 ifpresent,
field2 (1, 2, 3),
field3 (0 .. 255),
field4 not (1, 2, 3),
field5 omit,
field6 * ifpresent,
field7 ?,
field8 ‘1011?110*1’B,
field9 “abc” <*> “xyz” length (20)
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 35
Parameterised Templates (1)
// Value parameterisation
template MyMessageType MyMessage (integer MyPar) :=
{
field1 MyPar,
field2 true
field3 ‘110011’B
}
// Example use of this template
P1.send(MyMessage(1));
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 36
Parameterised Templates (2)
// Type parameterisation
type record MyRecordType(MyMetaType)
{
boolean field1,
MyMetaType field2 // field2 type not defined
}
var MyRecordType(integer) MyRecordValue :=
{
field1 := true,
field2 := 123 // field2 now of type integer
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 37
Modified Templates// Writing
template MyMessageType MyMessage1
{ field1 123,
field2 true
} // and
template MyMessageType MyMessage2 modifies MyMessage1
{ field2 false
}
// Is the same as writing
template MyMessageType MyMessage3
{ field1 123,
field2 false
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 38
Local Function Definitions
/* Functions can declare local constants, variables and timers */
function MyFunction
{
const hexstring MyConst := ‘FF00’H;
var integer MyVar :=1;
timer MyTimer;
:
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 39
Procedure Signatures
/* Procedure signatures are needed for synchronous communication over procedure-based ports (remote procedure calls) */
signature MyRemoteProc( in integer Par1,
out float Par2,inout integer Par3
)return integerexception (ExceptType1, ExceptType2);
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 40
Signature Templatessignature MyRemoteProc
( in integer Par1,out float Par2,inout integer Par3
)return integerexception (ExceptType1, ExceptType2);
/* templates may be used to define the actual parameters to a remote procedure call */
template MyRemoteProc Mytemplate := {
Par1 := 7,Par2 := *,Par3 := MyConst
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 41
Specifying Elements of Test System Architecture
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 42
• Test components are the entities on which test behaviour is executed (in parallel)
• Declarations may be made locally in the component
• A list of the ports used by the component must also be given
• Actual configurations are built dynamically in the test behaviour using operations such as create, connect etc.
Test Components
Ports Used
Local Declarations
Test Component
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 43
Kinds of Test Components• There are three ‘kinds’ of component
– MTC (Main Test Component)
– PTC (Parallel Test Component)
– a PTC that defines the Abstract Test System Interface
Real test system connected to an SUT
MTC1
Abstract Test System Interface
PTCnPTC1 PTC2
Abstract Test System
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 44
Communication Ports• Test components communicate via communication ports
• A test port is modeled as an infinite FIFO queue
• Ports have direction (in, out, inout)
• There are three types of port
– message-based, procedure-based or mixed
PTC1 PTC2
P1.send(Msg) P1.receive(Msg)
P1 (in)P1 (out)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 45
Example Port Definition// Definition of a message-based port
type port MyMessagePortType message
{
in MsgType1, MsgType2;
out MsgType3;
inout integer
}
// Definition of a procedure-based port
type port MyProcedurePortType procedure
{
out ProcedureSignature1, ProcedureSignature2
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 46
Example Component Definition
// Definition of test component type
type component MyComponentType
{ // Local declarations
var integer MyVar;
timer MyTimer;
// Ports used by the component
MyMessagePortType P1, P2;
MyProcedurePortType P3
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 47
Test System Interface
/* A user-defined component that defines the port interface to the underlying real test system */
type component MyTestSystemIntefaceType
{
MyLowerPCOType LT;
MyUpperPCOType UT
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 48
Specifying Test System Behaviour
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 49
TTCN-3 Functions
Function ( . . . )
Program Part
Local Declarations
• Functions are the building-blocks of test system behaviour
• Functions have local declarations and a program part
• Can be a 'pure' function doing some internal test system task or specify test behaviour using communication operations such as send and receive
• External functions are allowed• There are some pre-defined
functions (type conversion etc.)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 50
Pre-defined FunctionsFunction Name
Conversion functionsConvert bitstring value to integer value bit2intConvert hexstring value to integer value hex2intConvert octetstring value to Integer value oct2intConvert string value to integer value str2intConvert integer value to bitstring value int2bitConvert integer value to hexstring value int2hexConvert integer value to octetstring value int2octConvert integer value to string value int2strlength/size functionsReturn the length of a value of any string type lengthofReturn no. of elements in record, recordof, template, set, setof , array sizeofPresence/choice functionsDetermines if an optional field in a record, template etc. is present ispresentDetermine which choice has been made in a union type ischosen
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 51
Function Definitions(1)
// Functions can be parameterised// in, out, inout paramters. Default is infunction MyFunction (in integer MyPar){
:}// Functions can return values// Default is voidfunction MyFunction return integer{
:}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 52
Function Definitions(2)
/* This function performs a generic task. It does not use any communication operations */
function MyFunction{
:}/* This function uses communication operations
consistent with the ports offered by MyPTC */function MyFunction runs on MyPTC{
:}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 53
Test Case Definitions• Test cases are a special kind
of function executed in the control part of a module
• The interface part (runs on) references the MTC on which the test case will run
• The system part (system) references the test system interface component. Can be omitted if the test case only consists of an MTC
• The Behaviour part defines test case behaviour
Test Case ( . . . )
Behaviour Part
System Part
Interface Part
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 54
Example Test Case Definitions
// Parallel configuration testcase MyTestCase()runs on MyMTCTypesystem MyTestSystemType{
: // behaviour defined here}
// Configuration consists only of an MTCtestcase MyTestCase()runs on MyMTCType{
: // behaviour defined here}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 55
TTCN-3 Program Statements and Operations
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 56
Kinds of Statements and Operations
Kind of Statement orOperation
Used in ModuleControl
Used inFunctions and
Test CasesBasic program statements Yes Yes (except execute)
Dynamic test behaviour Yes (limited) YesConfiguration operations YesCommunication operations YesTimer operations Yes YesVerdict operations YesSUT operations Yes
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 57
Basic Program Statements
Statement Keyword or symbolExpressions (…)Assignments :=Logging logIf-else statement if (…) {…} else {…}For loop for (…) {…}While loop while (…) {…}Do while loop do {…} while (…)Label Definition labelJump to label gotoStop execution of function/control stopExecute test case execute
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 58
Example Program Statement
function MyFunction{
var integer x, j;
for (j:=1; j<=10; j:=j+1){ if (MyGlobalFlag == true)
{ x:=j*2;log int2str(x);
}else x := j*3
}}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 59
OperatorsCategory Operation Keyword
addition +subtraction -multiplication *division /
Arithmetic operators
modulo modString operators concatenation &
equal ==less than <greater than >not equal !=greater than or equal >=
Relational operators
less than or equal <=logical not notlogical and andlogical or or
Logical operators
logical xor xorbitwise not not4bbitwise and and4bbitwise or or4b
Bitwise operators
bitwise xor xor4bshift left <<Shift operatorsshift right >>rotate left <@Rotate operatorsrotate right @>
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 60
Creating, Building and Controlling Test Configurations
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 61
Configuration Operations
Operation KeywordCreate a (new) parallel test component createConnect two components connectConnect component to test system interface mapGet MTC address mtcGet test system interface address systemGet own address selfStart execution of test component startStop execution of test component stopCheck termination of a test component done
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 62
Creating Components
• The MTC is the only component that is automatically created when the test case is executed
– all PTCs must be created explicitly using the create operation
• The create operation returns the unique component reference for the newly created component
• Components can be created at any point in a behaviour description
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 63
Example of Create
// Define a variable of type component
type component MyComponentType
{
:
}
// Define a variable of type component
var MyComponentType MyComponent;
// create the component
MyComponent := MycomponentType.create
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 64
Connecting and Mapping Components
Test System
MyPTC
Abstract Test System Interface
SUT
Real Test System Interface
MyMTC
IN OUT
OUT IN
Connected Ports
P1P1
INOUTMapped Ports
INOUT
P2
PCO
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 65
Example of Connect and Map
/* The connect operation is used to connect components within the test system */
connect(MyPTC:P1, mtc:P1)
/* The map operation is used to ‘connect’ components to the abstract test system interface */
map(MyPTC:P2, system:PCO)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 66
Communication Between Test Components
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 67
Asynchronous Communication
non-blocking
blocking
MTC
send receive
PTC
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 68
Asynchronous Communication Operations
Operation KeywordSend a message sendReceive a message receiveTrigger on a given message triggerCheck in queue of port for message checkClear port clearClear and give access to port startStop access to port stop
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 69
Examples of Asynchronous Communication Operations
MyPort.send(integer:5);
MyPort.receive(MyTemplate(5, MyVar));
MyPort.receive(A<B) from MyPartner;
MyPort.receive(MyType:*) -> value MyVar;
MyPort.receive(integer:5) -> sender MyPeer;
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 70
Synchronous Communication
call getcall
blocking blocking
getreply orcatch exception
reply orraise exception
MTC PTC
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 71
Synchronous Communication Operations
Operation KeywordInvoke (remote) procedure call callReply to (remote) procedure call replyRaise an exception raiseAccept (remote) procedure call getcallHandle response from a previous call getreplyCatch exception (from called entity) catchCheck reply or exception checkClear port clearClear and give access to port startStop access to port stop
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 72
Examples of Synchronous Communication Operations
// Calling a remote procedure
MyPort.call (MyProc, 30ms) to MyPeer
{
[] MyPort.getreply(MyProc) -> value MyResult;
[] MyPort.catch (MyProc, Exception1)
}
// Replying to a remote procedure
MyPort.reply (MyProc)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 73
TTCN-3 Behaviour Trees
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 74
Behaviour Statements
Statement Keyword orsymbol
Sequential behaviour … ; … ; … ;Alternative behaviour alt {…}Interleaved behaviour interleave {…}Activate a default activateDeactivate a default deactivateReturning control return
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 75
Behaviour Statements
// Sequential statements are denoted by a semi-colon
function MyFunction1
{
MyFunction2;
x:=x+1;MyPort.receive(myMessage); // Blocks execution until message received
MyPort.send(MyMessage)
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 76
Alternative Behaviour
S1; alt {[ ] S3; S6; [ ] S2; alt { [ ] S4; S7; [ ] S5; S8; alt { [ ] S9; [ ] S10; } } }
S1
S3
S6
S2
S4
S7
S5
S8
S9 S10
• Alternative behaviour is defined using the alt statement
• alt statements may only be the receiving communication operations and timer events
– receive, trigger, getcall, getreply, catch, check, timeout
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 77
Schematic View of Alternatives
• Each alternative consists of
– a guard (possibly empty)
– an event, and
– an (optional) sequence of actions (including further alts)
• The TTCN-2 concept of snapshot semantics still applies
guard1 event1 actions1
guard2 event2 actions2
guardn eventn actionsn
alt
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 78
Example Alt Statement
alt
{
[] MyPort.receive(MyMessage1)
{MyPort.send(MyMessage4)alt{ // Next level}
}
[x>1] MyPort.receive(MyMessage2);
[x<1] MyPort.receive(MyMessage3)
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 79
Named Alternatives
• Named alternatives (named alt) are descriptions of partial alternatives
– defined in the module definitions
– are named and may be parameterised
• Named alternatives are macro-expansions
– they are not functions
• Can be referenced from anywhere that it is legal to write a normal alt statement
• The expand statement allows a named alt to be explicitly expanded inside another set of alternatives
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 80
Example of Named Alt (1)// Definition in module definitions
named alt MyNamedAlt
{ [] L1.receive(MyMessage1)
[] L1.receive(MyMessage2)
}// Use of the named alttestcase TC101()
{ MyNamedAlt() // In-line reference in test case
alt
{ [] L1.receive(MyMessage3);
[expand] MyNamedAlt(); // Macro expansion here
}
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 81
// Is the same astestcase TC101()
{ alt
{ [] L1.receive(MyMessage1)
[] L1.receive(MyMessage2)
}
alt
{ [] L1.receive(MyMessage3)
[] L1.receive(MyMessage1)
[] L1.receive(MyMessage2)
}
}
Example of Named Alt (2)
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 82
Default Behaviour• Default behaviour is defined using named alternatives
• Defaults must be explicitly activated and deactivated
• The expansion of defaults is applied to the end of the top-level set of alternatives in an alt statement …
• … and to all single receiving operations and timeouts
// Note that the single statement
L1.receive(MyMessage1);
// is equivalent to
alt { [] L1.receive(MyMessage1)}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 83
Activate and Deactivatenamed alt MyDefault
{ [] L1.any.receive
}
// Use of the named alttestcase TC101()
{ :
activate (MyDefault)
: // Default applies from here
deactivate (MyDefault)
: // Default does not apply from here
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 84
Interleaved Behaviour
/* The interleave statement specifies all possible combinations of executing a given set of alternative statements */
interleave {
[] PCO1.receive(MyMessageOne);
[] PCO1.receive(MyMessageTwo);
[] PCO1.receive(MyMessageThree);
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 85
Timers, Verdicts and SUT Operations
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 86
Additional OperationsStatement Keyword or
symbolModulecontrol
part
Functionsand testcases
Timer operationsStart timer start Yes YesStop timer stop Yes YesRead elapsed time read Yes YesCheck timeout event timeout Yes YesCheck timer status running Yes YesVerdict operationsSet local verdict verdict.set YesGet local verdict verdict.get YesSUT operationsCause SUT action sut.action Yes
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 87
Verdicts• Verdicts: pass, fail, inconc, none, error
• each test components has its own local verdict
– can be written (set) and read (get)
• Global verdict returned by Test Case (read-only)
MTC PTC1 PTC2 V
verdict.set(inconc)
Verdict returned by the test case when it terminates
V
verdict.set(fail)
V V
verdict.set(pass)
VV
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 88
Timer Operations
// Starting, stopping and reading a timer
MyTimer.start(20E-3)// Default unit is secs
MyTimer.stop
MyVar := MyTimer.read
// Check if a timer is running
if (MyTimer.running) { … }
// timeout in an alternative
:
[] MyTimer.timeout
:
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 89
Executing and Controlling Test Cases
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 90
Module Control
• Module control is the ‘dynamic’ part of a TTCN-3 specification where test cases are executed (execute)
• Local declarations, such as variables and timers may be made in the control part
• Basic programming statements may be used to select and control the execution of the test cases
Test Case Execution
Local Control Declarations
Control
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 91
Local Control Declarations
:
control
{
const hexstring MyConst := ‘FF00’H;
var integer MyVar :=1;
timer MyTimer;
:
}
:
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 92
Executing Test Cases
Module MyModule
{ // Test cases are defined in the module definitions
testcase MyTestCase() runs on MyMTC system MyTestSystem{
// behaviour defined here}
control
{ // and executed in the control part
execute (MyTestCase())
}
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 93
Controlling Test Cases
// Test Cases return verdictsexecute(MyTestCase()) -> value MyVerdict;
// Timeouts may be placed on Test Casesexecute(MyTestCase(),0.5) -> value MyVerdict;
// Test Cases can be used with program statementswhile (x<10) { x:=x+1;
execute(MyTestCase())}
// Selection of Test Casesif (MySelectionExpression) execute(MyTestCase())
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 94
Specifying Additional Attributes
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 95
Defining Attributes• Special attributes can be associated
with most TTCN-3 language elements using the with statement
• encoding information (encode)
– standardized: ASN.1
– application specific, proprietary
• display information (display)
– standardized: tabular and MSC formats
– or proprietary
• user-defined (extension)
– proprietary
Attributes
Language Element
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 96
Example Attributes
type record MyPDU
{
integer field1,
ia5string field2,
boolean field3
}
with
{
display “ETSI Tabular := PDU”; // Tabular PDU
encode “BER”; // Encoding directive
extension “MyRule” // User specific
}
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 97
An Introductory Overview
The End
TTCN-3 An Introductory Overview, Copyright ETSI 2000 Slide 98
… or just the beginning?