OpenTTCN/Training/TTCN-3 Basics/Exercises/3.1
From OpenTTCN
Exercise 3.1: Defining alternatives and avoiding deadlock
Goal: In this exercise we are learning how to specify alternate outcomes and how to avoid deadlock situation.
Step 1: Defining alternatives and avoiding deadlock
Writing code where send statement is followed by a single receivce statement sounds more like we are writing code of an implmentation, not writing a test script. When we are writing test scripts it is inherently natural that there exists multiple alternative outcomes after our own actions which are deterministic. At least there are two types of outcomes: valid input is received, or invalid input is received.
Step 2: Current TC_receive test case
The current status of our "TC_receive" test case should be as follows:
testcase TC_receive() runs on MTC_DNSclient system TSI_DNSclient
{
map(mtc:port_A, system_PCO_A);
port_A.send(T_DNS_query);
port_A.receive(T_DNS_query);
unmap(mtc:port_A, system_PCO_A);
}
Step 3: Adding an alt statement
By adding a single alt statement around a receive statement, the resulting semantics are the same.
testcase TC_receive() runs on MTC_DNSclient system TSI_DNSclient
{
map(mtc:port_A, system_PCO_A);
port_A.send(T_DNS_query);
alt
{
port_A.receive(T_DNS_query)
{
}
}
unmap(mtc:port_A, system_PCO_A);
}
Step 4: Adding a second alternative
Instructions:
- Add a so called "receive any" statement to the "TC_receive" test case. Do you add this statement before or after the receive(T_DNS_query) line?
Adding the receive any statement makes our test case deadlock-free. The "receive any" is used to handle only unexpected input. At this moment anything else than "T_DNS_query" input is unexpected because we are sending this same message just a few lines earlier and we are using a loopback.
In TTCN-2 the "receive any" statement was called "OTHERWISE" statement.
Summary
Congratulations! You have just completed the first exercise of today. During this exercise you learned how to specify alternatives in your test case. Now you are ready to proceed to learn more details about TTCN-3 test cases.
