Load Runner测试脚本(tuxedo服务)的编写指南
1.熟悉loadrunner與c++中調(diào)用tuxedo服務(wù)的對應(yīng)API:
c++:
對比表
| C++中 | loadrunner | |
| 分配內(nèi)存 | tpalloc() | lrt_tpalloc() |
| 釋放內(nèi)存 | tpfree() | lrt_tpfree() |
| 定義發(fā)送接收緩沖區(qū) | FBFR32* | FBFR32* |
| 緩沖區(qū)初始化 | Finit32() | lrt_Finitialize32() |
| 向緩沖區(qū)中加入變量 | Fadd32() | lrt_Fadd32_fld() |
| 獲取緩沖區(qū)中變量 | Fget32() | lrt_save32_fld_val() |
| call tuxedo服務(wù) | tpcall() | lrt_tpcall() |
主要用到就是以上幾個(gè)函數(shù),此外,為了統(tǒng)計(jì)與tuxedo交互期間的性能,應(yīng)將事務(wù)統(tǒng)計(jì)插入到tacall前后:
lr_start_transaction()
lrt_tpcall()
lr_end_transaction()
2.注意事項(xiàng)
需要注意的是,lr中相關(guān)的函數(shù)參數(shù)與c++中并不相同,不能想當(dāng)然,一定要遵循其語法規(guī)則:
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);
對于標(biāo)識的傳入,需加上"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("返回值:o%d",resind);
對比,可看出,在LR中,是以字符串形式傳入?yún)?shù)的名字,其內(nèi)部根據(jù)參數(shù)名來查找并匹配類型,再相應(yīng)的填充數(shù)據(jù);
熟悉以上幾點(diǎn)后,編寫tuxedo的LR測試腳本基本上就沒什么問題了。
附上一段LR腳本,供參考:
//replay.vdf-----------------------------------------
#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-------------------------------------------------
#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("結(jié)果狀態(tài):%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; }注:在代碼編寫過程中,需要將內(nèi)存的申請和釋放放在vuser_init和vuser_end中,否則對測試結(jié)果影響非常大!
vuser_init---------------
#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---------------------------------
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
轉(zhuǎn)載于:https://www.cnblogs.com/me115/archive/2011/04/01/2001911.html
總結(jié)
以上是生活随笔為你收集整理的Load Runner测试脚本(tuxedo服务)的编写指南的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WCF 报错
- 下一篇: Direct2D (25) : 将画笔线