博主的系统环境
1、Windows7
2、MS Visual C++ 2008,(对应IDE需要用到Visual的一个批处理文件)
3、IDE:IBM Rational System Tester 3.3
1,2两点就不说啦,IBM这个工具是个商用软件,分Windows版和Linux版的,相关主页在此:http://www-01.ibm.com/software/awdtools/ttester/
3.3版本的还可以使用本地License文件,后续新版本的需要搭建一个局域网的License服务器,稍稍复杂一点。
使用Tester开发,基本上是 TTCN-3完成测试脚步+C完成下层模块 的架构,Tester能对TTCN-3进行语法检查,再将TTCN-3脚步转成C语言代码,再对整个项目进行编译生成可执行文件。
(lz支持采用正版软件,虽然我觉得IBM这个工具做得挺不好用的)
上面是IDE成功安装后进入看到的界面。比较有帮助的是右下角的Project Samples,里面有大概10个例子,值得看看,依葫芦画瓢。
我们目前从新建项目开始。
依次选择File->New->Project->TTCN project,项目名称HelloWorld,一路Next,选择默认的项目配置即可
完成后项目的结构图如下,分为两个文件夹,分别是ttcn与c文件
右键HelloWorld.ttw,选择Settings配置,注意在Build中要添上vsvars32.bat的正确路径(如果C++环境是Visual studio 2008 路径要修改成 “%VS90COMNTOOLS%”)
接下来在HelloWorld.ttcn文件中加入如下代码
- module HelloWorld {
- function Hello(){
- log("Hello world !!");
- }
- control{
- //直接打印hello world
- log("Hello world !");
- //通过函数调用打印hello world
- Hello();
- }
- }
module HelloWorld {
function Hello(){
log("Hello world !!");
}
control{
//直接打印hello world
log("Hello world !");
//通过函数调用打印hello world
Hello();
}
}
接下来打开t3tri_template.c文件,搜索triSAReset()与 triPAReset()函数, 令函数返回TRI_OK
然后点击菜单栏上的分析(小勾),编译(圆圈里面一个c),Build(两个下箭头),执行(感叹号)
系统默认执行是执行Module Define部分,控制部分,需要手动执行,如下图
右击Hello_word,点击start control part.
打印出如下结果
- Running executable...
- "Target\HelloWorld.exe" -t3rt "+log -v 2 -lrtconf" -t3rt "-confbool t3rt.logging.builtin.pretty_print true"
- Establishing connection with Test Management...
- Connected to Test Management.
- Telelogic Tester test suite started.
- Waiting for commands ...
- HelloWorld.ttcn (6): [CPC] scope_entered: control
- HelloWorld.ttcn (8): [CPC] ttcn3_message: LOG Hello world !
- HelloWorld.ttcn (11): [CPC] function_call: Hello() return <undefined>
- HelloWorld.ttcn (2): [CPC] scope_entered: Hello() return <undefined>
- HelloWorld.ttcn (3): [CPC] ttcn3_message: LOG Hello world !!
- HelloWorld.ttcn (3): [CPC] scope_left: Hello() return <undefined>
- HelloWorld.ttcn (11): [CPC] scope_left: control
- [final] MESSAGE Test case summary:
- [final] MESSAGE
- [final] MESSAGE none 0 (0%)
- [final] MESSAGE pass 0 (0%)
- [final] MESSAGE inconc 0 (0%)
- [final] MESSAGE fail 0 (0%)
- [final] MESSAGE error 0 (0%)
- [final] MESSAGE
- [final] MESSAGE total 0
Running executable...
"Target\HelloWorld.exe" -t3rt "+log -v 2 -lrtconf" -t3rt "-confbool t3rt.logging.builtin.pretty_print true"
Establishing connection with Test Management...
Connected to Test Management.
Telelogic Tester test suite started.
Waiting for commands ...
HelloWorld.ttcn (6): [CPC] scope_entered: control
HelloWorld.ttcn (8): [CPC] ttcn3_message: LOG Hello world !
HelloWorld.ttcn (11): [CPC] function_call: Hello() return <undefined>
HelloWorld.ttcn (2): [CPC] scope_entered: Hello() return <undefined>
HelloWorld.ttcn (3): [CPC] ttcn3_message: LOG Hello world !!
HelloWorld.ttcn (3): [CPC] scope_left: Hello() return <undefined>
HelloWorld.ttcn (11): [CPC] scope_left: control
[final] MESSAGE Test case summary:
[final] MESSAGE
[final] MESSAGE none 0 (0%)
[final] MESSAGE pass 0 (0%)
[final] MESSAGE inconc 0 (0%)
[final] MESSAGE fail 0 (0%)
[final] MESSAGE error 0 (0%)
[final] MESSAGE
[final] MESSAGE total 0
HelloWorld程序分析:
上面就是在IBM工具中完成首个TTCN-3项目的流程,这个HelloWorld与其它语言比较起来还是略复杂的,但是从这个例子里面我们可以看出下面几点:
1、TTCN的语言特性,module,模块是TTCN3中范围最大的单元(其他的都需要包含在Module中).
一个Module包含两个部分:Module定义和Module控制,这两个部分都是可选的,也就是说一个Module中可以是空的,没有任何东西
2、适配文件,例如本例子里面的两个c文件,光有TTCN-3代码是跑不起来的,需要将TTCN-3与下层代码联和编译才能执行
3、结果打印:终端把一步一步的执行结果都打印出来了,最后还有测试的总结,TTCN系统是为测试而准备的。