|
|
# About TTCN
|
|
|
|
|
|
The _Testing and Test Control Notation Version 3_ (TTCN-3) is a standardized testing language developed and maintained by the European Telecommunication Standards Institute (ETSI) and specifically designed for testing and certification. You can find all (detailed) information at <a href="http://www.ttcn-3.org" target="new">ETSI's official TTCN3 page</a>.
|
|
|
|
|
|
# How can I test something?
|
|
|
|
|
|
TTCN3 using a very basic (black box) assumption to test the given device/implementation which has the following components:
|
|
|
* _System Under Test_ (SUT) - Vendor's product (hardware)
|
|
|
* _Implementation Under Test_ (IUT), Vendor's software implementation running on this device
|
|
|
* _TTCN Test Component_ executing Test Cases - TTCN test environment which modelling the User's test environment
|
|
|
|
|
|
Black box testing means that we do not care the implementation details of the given product, only controlling/analysing the communication messages between the Test and the SUT devices.
|
|
|
|
|
|
<p align="center"><img src="https://github.com/ekrigul/ttcn3-doc/blob/master/img/ttcn3_testcase.png" width="500px" alt="TTCN3 Testcase"></p>
|
|
|
|
|
|
<br>So a TestCase (TC) performs the next processing flow:
|
|
|
* sends out a test message to the device
|
|
|
* catch the received message (if any) and evaluate it.
|
|
|
|
|
|
Possible results are:
|
|
|
* _pass_ - test has been successfully performed, the response message is correct
|
|
|
* _fail_ - test has been failed</li>
|
|
|
* inconclusive - _none_, _error_
|
|
|
|
|
|
# TITAN: Executable test suite
|
|
|
|
|
|
In order to execute TestCases, you need an environment to build and run your TTCN3 code. You can find these environments at <a href="http://www.ttcn-3.org/index.php/tools" target="new">ETSI's page</a>. In this tutorial, <a href="https://projects.eclipse.org/projects/tools.titan/downloads" target="new">Ericsson's TITAN</a> compilation and execution environment will be used/described.
|
|
|
|
|
|
TITAN environment provides the following tools:
|
|
|
* TTCN3 compiler, which compile ttcn files to c++ code
|
|
|
* Huge amount of <a href="https://projects.eclipse.org/projects/tools.titan/developer" target="new">components</a> (ttcn and c++ code) for various test purposes
|
|
|
* A makefile generator, which generates a makefile skeleton based on all input sources (<code>*.ttcn, *.hh and *.cc</code>)
|
|
|
|
|
|
<p align="center"><img src="https://github.com/ekrigul/ttcn3-doc/blob/master/img/ttcn3_flow.png" width="500px" alt="TTCN3 Testcase"></p>
|
|
|
|
|
|
All compiled source files (your test files and TITAN's component) can compiled into an executable binary. You can also add a configuration file as an input parameters to modify the followings:
|
|
|
* Different logging parameters, log file parameters
|
|
|
* Console output parameters
|
|
|
* TTCN module parameters
|
|
|
|
|
|
You can find all related tools at TITAN's <a href="https://projects.eclipse.org/projects/tools.titan/downloads" target="new">download page</a>
|
|
|
|
|
|
# Elements of a TTCN3 code
|
|
|
|
|
|
The most simple TTCN3 tests has a module file (<code>*.ttcn</code>) and a configuration file (<code>*.cfg</code>). The TTCN 3 file (module) is generally modelling the whole test environment (System/MTC) and it has the following main parts:
|
|
|
* _Module_: Main part of the TTCN3 file
|
|
|
* _Component(s)_: High level configuration entity(es), defining/modelling the test environment of the TestCases (for example: port connection(s))
|
|
|
* _Test cases_ (TCs): Defining and evaluating output/input messages. Test cases are running on components.
|
|
|
* _Control_: List of test cases will be executed
|
|
|
|
|
|
<p align="center"><img src="https://github.com/ekrigul/ttcn3-doc/blob/master/img/ttcn3_code_frame.png" width="400px" alt="TTCN3 Testcase"><p>
|
|
|
|
|
|
During the execution process these code parts above will be used in the following way:
|
|
|
* The given test configuration file (if any) is evaluated to the set different environment parameters
|
|
|
* The corresponding component (of the TestCase) is loaded to the Main Test Component (MTC)
|
|
|
* MTC's port(s) must be mapped (connected) to the SYSTEM's port(s) - connecting our TestCase to the outside world
|
|
|
* Test case is executed (send and receive messages via port(s)) - actual testing process
|
|
|
* Test case is evaluated: pass/fail/inconc/error
|
|
|
* Unmap resources (automatic) - disconnect the outside world
|
|
|
|
|
|
## Module
|
|
|
|
|
|
Module is the main part of the ttcn3 file: one file => one module.
|
|
|
|
|
|
```
|
|
|
module MyFirstTest // define a module: MyFirstTest
|
|
|
{
|
|
|
import from OtherModule all; // Import other module's definition
|
|
|
}
|
|
|
```
|
|
|
Your file should be named as: <code>MyFirstTest.ttcn3</code>
|
|
|
|
|
|
## Component
|
|
|
|
|
|
Components are high level configuration entities: definition of the implemented test case's environment.
|
|
|
|
|
|
```
|
|
|
type component testComponent // define a new type of component: testComponent
|
|
|
{
|
|
|
port SpecialPort testPort; // define a port for this component, port type: SpecialPort
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## Testcase
|
|
|
|
|
|
Test case executes and evaluates the test itself.
|
|
|
|
|
|
```
|
|
|
testcase TC1() // definition of a test case: TC1
|
|
|
runs on testComponent // TC1 uses testComponent setups
|
|
|
{
|
|
|
map(mtc:testPort, system:testPort); // mapping MTC's port to System's port
|
|
|
|
|
|
/*
|
|
|
definition of the input and output messages should be here: msg_in, msg_out
|
|
|
*/
|
|
|
|
|
|
testPort.send(msg_out); // send out msg_out message
|
|
|
alt // possible test outputs, alternatives
|
|
|
{
|
|
|
[] testPort.receive -> value msg_in // capture incoming message and store it in msg_in
|
|
|
{
|
|
|
// evaluate the incoming message (will be discussed later)
|
|
|
// set the verdict of test case
|
|
|
setverdict(pass);
|
|
|
}
|
|
|
/*
|
|
|
...
|
|
|
[] Other alternatives
|
|
|
{
|
|
|
|
|
|
}
|
|
|
...
|
|
|
*/
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## Control
|
|
|
|
|
|
In control part you can list your test cases.
|
|
|
|
|
|
```ttcn
|
|
|
control {
|
|
|
execute (TC1()); // executes TC1 testcase
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## Configuration file
|
|
|
|
|
|
Configuration file is a simple textfile (<code>*.cfg</code>) with various test parameters. Is should be added as a parameter of the compiled test binary.
|
|
|
|
|
|
```
|
|
|
[MODULE_PARAMETERS]
|
|
|
...
|
|
|
|
|
|
[LOGGING] // Various parameters of logging
|
|
|
LogFile := "logs/%e.%h-%r.%s"
|
|
|
FileMask := LOG_ALL | DEBUG | MATCHING
|
|
|
ConsoleMask := LOG_ALL | ERROR | WARNING | TESTCASE | STATISTICS | PORTEVENT
|
|
|
LogSourceInfo := No
|
|
|
AppendFile := No
|
|
|
TimeStampFormat := DateTime
|
|
|
...
|
|
|
``` |