Load Runner测试脚本(tuxedo服务)的编写指南
1.熟悉loadrunner与c++中调用tuxedo服务的对应API:
c++:
对比表
C++中 | loadrunner | |
分配内存 | tpalloc() | lrt_tpalloc() |
释放内存 | tpfree() | lrt_tpfree() |
定义发送接收缓冲区 | FBFR32* | FBFR32* |
缓冲区初始化 | Finit32() | lrt_Finitialize32() |
向缓冲区中加入变量 | Fadd32() | lrt_Fadd32_fld() |
获取缓冲区中变量 | Fget32() | lrt_save32_fld_val() |
call tuxedo服务 | tpcall() | lrt_tpcall() |
主要用到就是以上几个函数,此外,为了统计与tuxedo交互期间的性能,应将事务统计插入到tacall前后:
lr_start_transaction()
lrt_tpcall()
lr_end_transaction()
2.注意事项
需要注意的是,lr中相关的函数参数与c++中并不相同,不能想当然,一定要遵循其语法规则:
a.变量申明
lr中的变量申明都放在replay.vdf中;
b.传参
C++中:
#define FCCKEY ((FLDID32)167776166)
Fadd32(sndBuf,FCCKEY,(char*)key,(FLDLEN32)0)
LR中:
lrt_Fadd32_fld(sndBuf,"id=167776166",(char*)key,LRT_END_OF_PARMS);
对于标识的传入,需加上"id=";
同样,key的传入,也需加入value:
char key[30];
strcpy(key,"value=HELLOCOLIN^");
c.取参
c++中:
int resind;
Fget32((FBFR32*)rcvBuf, F_RESULT_IND, oc, (char*)&resind, &maxlen);
cout << resind;
LR中:
int resind:
lrt_save32_fld_val((FBFR32*)rcvBuf,"id=5032",0,"resind");
lr_output_message("返回值:º%d",resind);
对比,可看出,在LR中,是以字符串形式传入参数的名字,其内部根据参数名来查找并匹配类型,再相应的填充数据;
熟悉以上几点后,编写tuxedo的LR测试脚本基本上就没什么问题了。
附上一段LR脚本,供参考:
//replay.vdf-----------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #ifndef TUXVDF_H #define TUXVDF_H #define FCCKEY ((FLDID32)167776166) FBFR32* sndBuf; //char* sndBuf; FBFR32* rcvBuf; char * data_2; char * data_3; char key[61]; char dataResult[513]; int len; int resind; FLDOCC oc; |
//Action.c-------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include "lrt.h" #include "replay.vdf" Action() { lrt_abort_on_error(); //sndBuf = lrt_tpalloc("STRING", "", 512); len = 65000; strcpy (key, "value=HelloColin^" ); lrt_Finitialize32(sndBuf); lrt_Fadd32_fld(sndBuf, "id=167776166" ,( char *)key,LRT_END_OF_PARMS); /* Request STRING buffer 1 */ //lrt_strcpy(sndBuf, sbuf_1); //rcvBuf = lrt_tpalloc("STRING", "", 10000000); lr_start_transaction( "ColinLau" ); tpresult_int = lrt_tpcall( "CC_Q_1" , ( char *)sndBuf, 0, ( char **)&rcvBuf, &olen, 0); /* Reply STRING buffer 1 */ if (tpresult_int == -1){ lr_end_transaction( "ColinLau" , LR_FAIL); lr_output_message( "TpQuery:tpcall error" ); return 0; } lr_end_transaction( "ClassCache" , LR_PASS); lrt_save32_fld_val((FBFR32*)rcvBuf, "id=5032" ,0, "resind" ); lr_output_message( "结果状态:%d" ,resind); lrt_save32_fld_val((FBFR32*)rcvBuf, "id=167776167" ,0, "dataResult" ) ; lr_output_message( "返回值:" ,lr_eval_string( "{dataResult}" ) ) ; //("{dataResult}") lrt_abort_on_error(); return 0; } |
注:在代码编写过程中,需要将内存的申请和释放放在vuser_init和vuser_end中,否则对测试结果影响非常大!
vuser_init---------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include "lrt.h" #include "replay.vdf" vuser_init() { lrt_set_env_list(env_allow_array); lrt_tuxputenv( "WSNADDR=//10.6.36.103:10115" ); /* old format: lrt_tuxputenv("WSNADDR=0x000223600a062444"); */ lr_think_time(5); tpresult_int = lrt_tpinitialize(LRT_END_OF_PARMS); if ((sndBuf = (FBFR32*)lrt_tpalloc(( char *) "FML32" , NULL, len)) == NULL){ lr_output_message( "TpQuery:tpalloc error" ); return 0; } if ((rcvBuf = (FBFR32*)lrt_tpalloc(( char *) "FML32" , NULL, len)) == NULL){ lr_output_message( "TpQuery:tpalloc error" ); return 0; } return 0; } |
VUser_end---------------------------------
1 2 3 4 5 6 7 | vuser_end() { lrt_tpfree(( char *)sndBuf); lrt_tpfree(( char *)rcvBuf); lrt_tpterm(); return 0; } |
Over.!
More: http://blog.donews.com/me1105/archive/2011/04/01/140.aspx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述