IBM
Contents Index Previous Next



Getting Started


Unfortunately, a test sequence description expressed in TTCN cannot easily be executed as it is. This, because the test notation is not executable and only few test environments interpret pure TTCN. A different approach to create an executable test suite (ETS), is to translate the formal test description into a language which can be compiled into an executable format.

The TTCN to C compiler translates TTCN into ANSI-C which can be compiled by an ANSI-C compiler. Figure 231 depicts the first step in the process of creating an ETS using the TTCN to C compiler.

The generated code, called the TTCN runtime behavior, is only one of the two major modules of an ETS.

The second module which is needed includes test support functions which are dependent on the protocol used, the host machine, test equipment, etc. For this reason, it is up to the user to write this second module and in such way adapt the TTCN runtime behavior to the system he/she wants to test.

Figure 231 : Translating TTCN to ANSI-C

The adaption process is described in "Adaptation of Generated Code" on page 1491 in chapter 36, Adaptation of Generated Code. Figure 232 displays the anatomy of the final result.

Figure 232 : The anatomy of an ETS

Running the TTCN to C Compiler

To generate C code for the currently selected test document:

  • Select Generate Code from the Build menu.
    • The shortcut is <F8>.
      This will open a dialog where you may change settings for code generation (see Figure 233).
      You can also open this dialog by the menu choice Build > Options or by the shortcut <Alt+F8>.

Note:

Observe that the TTCN to C compiler is unable to function correctly if the test suite is not fully verified correct. This verification is accomplished by running the Analyzer tool on all the parts of the test suite.

Note:

If you generate code for large test suites containing many types that form long reference chains (T references T1, T1 references T2 and so on), code generation process may fail. This may happen if reference depth exceeds the default limit = 200. You can solve this by setting the environment variable ITEX_REFERENCE_DEPTH to a higher value, for example 300.

Note:

(Windows only) On Windows, code generation may fail to do anything for big test suites containing large number of type declarations. And no crash information will pop up. This may happen because of stack overflow during code generation.

Code generator is invoked from 2 different executables - ttcn2c.exe starts code generation from command line, iedit2.exe invokes code generation from GUI. The problem with stack overflow can be solved by increasing the stack size for one of these executables or for both if you use both of them. This can be done with Microsoft Visual Studio utility "editbin.exe". The default stack size set during compilation is 10000000, so if this is not enough, try setting stack size to a higher value, for example:

editbin /STACK:20000000 <installation>\bin\wini386\iedit2.exe

editbin /STACK:20000000 <installation>\bin\wini386\ttcn2c.exe

Note that every active TTCN document has its own code generation settings, so in practice, two or more TTCN documents can be edited and/or viewed at the same time in the TTCN Suite, and yet have individual settings. (Multiple views on the same TTCN document does of course share the same settings.)

The TTCN to C compiler runs in background. The Progress Bar at the bottom of the TTCN Suite window shows the TTCN to C compiler completion. During the code generation it is possible browse the already opened TTCN documents. It is not allowed to edit, save, close or open any of the TTCN documents during analysis. The analysis may be canceled by pressing the break button on the toolbar or by the menu choice Build > Break.

Options

Figure 233 : TTCN to C Compiler Options tab

Encoders/Decoders

Kernel

MSC Trace

For more information, see "TTCN Test Logs in MSC Format" on page 1333.

Output Directory

The final thing you have to do is to set the output directory.

OK

When you have set the options, click OK to start the generation of code. When the generation phase is started, information about the code generation will be displayed in the Log Manager. You will receive information about what parts that were generated and also some statistics about the amount of tables traversed during the generation phase.

If code is being generated for a large test suite, the status bar will show the progress.

Save

If you would like to store the option settings for future usage, press the Save button. The options settings is then saved in a file with the same name as the current test suite's filename (with extension) and with an additional '.ini' extension. For example will the options for 'foo.itex' be saved in a file named 'foo.itex.ini', for a test suite named 'foo.mp' the options will be in the file 'foo.mp.ini'. The options file is placed in the same folder as the test suite file.

The options file is automatically searched and the options settings are loaded when a TTCN Suite browser window is opened (on Windows), or when the TTCN Suite Make dialog is opened (on UNIX).

Build Options

Makefile Type

Choose one of the known make types, corresponding to your compiler, for the generated makefile.

Figure 234 : Build Options tab

Custom adaptor objects

This text field allows you to specify additional object files to be linked to ETS.

Make command

The Run Make check box controls if the make command is to be invoked directly after the code generation (provided it has completed successfully). The text field allows a manual change of the invoked make command if this is desired.

Log Options

There are two options in the Build Options tab for log management. These options are also related to a compilation flag, SHOWSIGNALPARAMETERS, which is generated in the makefile.

Verbose Log

The Verbose Log switches the logging between the default mode, which prints the result of the Make process as it goes along, and the Verbose mode, where all possible information is presented. The Verbose log is primarily intended for debugging.

The Verbose log contains the following information in addition to the default log:

Show Executable Path

When Show Executable Path is selected, the lines in the ETS log will be prefixed by the path for the executing Test Case and Test Steps, like the following example:

Test Case:[line number]  Step_no:[line number] ... Test Step_n 

Compilation flag /DSHOWSIGNALPARAMETERS

The flag SHOWSIGNALPARAMETERS is generated in the Makefile even when the log is not Verbose. With this compilation flag the default log will also contain the complete contents of all signals, just like when log is set to Verbose. When this is not desired, this flag can easily be removed from the Makefile.

Additional Compiler Options and Additional Linker Options

Here it is possible to specify any compiler and linker options that will be added into the generated Makefile.

Running the TTCN to C Compiler from the Command Line

You can start the TTCN to C compiler by executing ttcn2c with command line switches. The usage is ttcn2c [switches] filename.

Example 219

To generate C code for example.itex in the current directory, with hard values and in silent mode, use the command:

ttcn2c -ms example.itex

C Code Generator Parameters

Switch Explanation
-a <objs>

Link with objs as adaptor

-A <ASN1files>

File containing filenames of ASN.1 module files.

-b <dir>

Search in <dir> for static files

-B

Generate BER encoding/decoding interface

-C <options>

Set the additional compiler options

-d

Debug information in C code

-D

Step through ETS execution

-e <file>

Use file to be included in the make file

-f

Forced mode - always overwrite files

-F

Definitions of encountered ASN.1 references should be retrieved. See "Retrieve ASN.1 Definitions" on page 1197 in chapter 26, Analyzing TTCN Documents (on UNIX)

-g

Ignore bodies of test suite operations

See also "Options" on page 1323.

-h

Help

-i <defined flag>

Set the flag defined for the preprocessor

-I <flags file>

Set the file with the flags defined for the preprocessor.

-j <file>

User file name for types

-k <file>

Use file name for constraints

-l <file>

Specify log file

-L <options>

Set the additional linker options

-M file

Enable MSC/PR file tracing

-M msce

Enable MSC Editor tracing

-o <dir>

Specify output directory

-p <file>

Use file name for behavior

-P

Generate PER encoding/decoding interface

-r <file>

Use file name to generate a makefile

-R

Disable makefile generation

-s

Silent mode - do not display messages

-t

Generate simulator

See also "Kernel" on page 1324.

-T

Generate targe/stand-alone kernel

-u vc

Generate code for Microsoft Visual compiler

-w

No warning mode

-z <lines>

Aim at splitting generated file at <lines> number of lines

Generating C Code for Modular Test Suites

Generating C code for modular test suites from the command line, may be a bit tricky. Please see the example below for an explanation of how to proceed.

Example 220

You want to generate C code for the modular test suite mts.itex, which depends on module1.itex, module2.itex, module3.itex and module4.itex. To do this enter:

ttcn2c """mts.itex""""""module1.itex""""""module2.itex""""""module3.itex"
"""""module4.itex"""

Note that there are six quotation marks between the file names.

This will generate code for the entire modular test suite.

It is also possible to use MP documents in the same manner.

For a description of file naming, see "Files in the TTCN Suite" on page 24 in chapter 2, Introduction to the TTCN Suite (in Windows), in the Getting Started.


http://www.ibm.com/rational
Contents Index Previous Next