OpenTTCN/Training/TTCN-3 Basics/Exercises/2.4

From OpenTTCN

Jump to: navigation, search

Exercise 2.4: Defining test configuration

Goal: In this exercise we are learning how to define a basic test configuration. The simplest test configuration consists of a Main Test Component and a Test System Interface and a mapping between these two.

Step 1: Defining test configuration

A simple test configuration consists of of a Main Test Component (MTC) and a Test System Interface (TSI) and a mapping between these two.

The Main Test Component (MTC) can be thought as a "process" that runs a test case. The MTC defines ports that it uses to communicate with outside world i.e. more importantly to communicate with the System Under Test (SUT). Besides defining ports, a MTC can define timers, variables, and constants to be used by a test case.

The Test System Interface (TSI) defines the interface of the "outside world" as implemented by a set of TTCN-3 SUT Adapters. The TSI is defined as a set of one or more ports that can be used to communicate with the System Under Test (SUT).

The third part of test configuration is a mapping between a port of a MTC and a port of a TSI. When this mapping exists, a test case running in a MTC can send and receive messages through TSI.

Step 2: Define a DNS port type

TTCN-3 port types are user-defined types that define the characteristics of instances of ports of that type. A port type can be message-based (identified by message keyword), procedure-based (identified by procedure keyword), or both (identified by mixed keyword). A port type also specifies which messages can go "in" and "out" directions through the port.

Instructions: In this exercise the DNS protocol is modeled naturally using message-based communication. Define a port type called "PORT_TYPE_DNSPort". Define that the DNS message type that we defined previously can go both "in" and "out" directions through the port.

Internet protocols regularly use the same packet formats for sent and received messages and because of that the same message type is allowed for both "in" and "out" directions. Telecom protocols in the other hand more commonly specify used messages (protocol data units, PDUs) asymmetrically and this causes need to have different "in" and "out" lists.

Step 3: Define a Main Test Component

Instructions: Define a user-defined component type called "MTC_DNSclient" to have a port instance of "port_A" of type the DNS port we defined during Step 2. This user-define component is used as a Main Test Component (MTC) in our DNS server test configuration. This simple component definition is enough for us at this moment. Later we enhance this definition by defining a timer in this component.

Step 4: Define a Test System Interface

Instructions: Define a user-defined component type called "TSI_DNSclient" to have a port instance of "PCO_A" of type the DNS port we defined during Step 2. This user-define component is used as a Test System Interface (TSI) in our DNS server test configuration.

Step 5: Telling which MTC and TSI a test case is using

Each test case individually tells in which test component they are running on using runs on clause. In the same way each test case individually tells which Test System Interface (TSI) it is using (or in other words what TSI it requires).

testcase MyTest() runs on MyMTC system MyTSI
{
...
}

Instructions: Define an empty TC_send() test case with "runs on" clause specifying the MTC type and "system" clause specifying the TSI type that we just defined.

Step 6: Mapping test component to Test System Interface

Mapping between a port of a test component (maybe MTC) and a port of a Test System Interface (TSI) is created using a map statement. Normally this mapping can be done in the beginning of a test case.

An existing mapping is destroyed using an unmap statement. Normally the mapping can be destroyed in the end of a test case.

Instructions: Add map and unmap statements to "TC_send" test case to create a mapping between port_A and PCO_A in the beginning of a test case, and destroy that mapping in the end of a test case.

Summary

Well done! You have just completed your fourth TTCN-3 exercise. During this exercise you learned how to define a message port type, a Main Test Component, and a Test System Interface for DNS testing. You also learned to create a mapping between a port of MTC and a port of TSI. You are now ready to proceed to the next exercise to learn how to send and receive DNS messages.

<< Previous   Next >>

Views
Personal tools