开发环境及TTCN-3的Hello World

博主的系统环境

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文件中加入如下代码

  1. module HelloWorld {  
  2.     function Hello(){  
  3.         log("Hello world !!");    
  4.     }  
  5.       
  6.     control{  
  7.         //直接打印hello world   
  8.         log("Hello world !");     
  9.   
  10.         //通过函数调用打印hello world   
  11.         Hello();  
  12.     }  
  13. }  
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.

打印出如下结果

  1. Running executable...  
  2. "Target\HelloWorld.exe"   -t3rt "+log -v 2 -lrtconf" -t3rt "-confbool t3rt.logging.builtin.pretty_print true"  
  3. Establishing connection with Test Management...   
  4. Connected to Test Management.   
  5. Telelogic Tester test suite started.   
  6. Waiting for commands ...   
  7.   
  8. HelloWorld.ttcn (6): [CPC] scope_entered: control  
  9. HelloWorld.ttcn (8): [CPC] ttcn3_message: LOG Hello world !  
  10. HelloWorld.ttcn (11): [CPC] function_call: Hello() return <undefined>  
  11. HelloWorld.ttcn (2): [CPC] scope_entered: Hello() return <undefined>  
  12. HelloWorld.ttcn (3): [CPC] ttcn3_message: LOG Hello world !!  
  13. HelloWorld.ttcn (3): [CPC] scope_left: Hello() return <undefined>  
  14. HelloWorld.ttcn (11): [CPC] scope_left: control  
  15. [final] MESSAGE   Test case summary:  
  16. [final] MESSAGE   
  17. [final] MESSAGE   none          0 (0%)  
  18. [final] MESSAGE   pass          0 (0%)  
  19. [final] MESSAGE   inconc        0 (0%)  
  20. [final] MESSAGE   fail          0 (0%)  
  21. [final] MESSAGE   error         0 (0%)  
  22. [final] MESSAGE   
  23. [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系统是为测试而准备的。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值