1.首先在进行性能测试的时候,我们要了解软件的通信协议是什么,我们使用什么协议,如何去模拟。SOCKET协议主要应用于在C/S模式的系统。
作者本人已当初做过的C/S架构的系统做的脚本录制,在上面做脚本的参数化以及优化工作。脚本如下:
#include "lrs.h"
#include <sub1.h>
#include <sub2.h>//包含了2个自定义的C函数。LR不支持C++的函数库。C++函数需要做修改
Action()
{
unsigned char cLine[2048]={0};
unsigned char cOut[2048]={0};
unsigned char cOut2[2048]={0};
unsigned char retu1[2048]={0};
int len = 0;
int len1 = 0;
int rc,i,re;
lr_start_transaction("Conn_socket");
rc = lrs_create_socket("socket0", "TCP", "RemoteHost=127.0.0.1:22222", LrsLastArg);//创建SOCKET连接
//lr_output_message("rc=%d",rc);
//连接成功返回判断
if (rc != 0 ) {
lr_end_transaction("Conn_socket", LR_FAIL);
return 0;
}
lr_end_transaction("Conn_socket", LR_PASS);
lr_start_transaction("sender");
strcpy(cLine,lr_eval_string("<shuju>" ));//LR参数传递入C环境
len = strlen((char*)cLine);//或者字符串的长度
//字符串转ASCII码
AsciiToHex(cLine,cOut,len);
//字节数组cOut的长度:
len1 = strlen((char*)cLine)/2;
lrs_save_param_ex("socket0", "user", (char *)cOut, 0, len1,"ascii", "sender0");
lrs_send("socket0","buf0", LrsLastArg);
lrs_receive("socket0","buf1",LrsLastArg);
lrs_save_param( "socket0", LRS_LAST_RECEIVED, "Parame1", 0, -1 );
strcpy(retu1,lr_eval_string("<Parame1>"));
re = lrs_get_last_received_buffer_size("socket0");
//ASCII码转字符串
HexToAscii( retu1,cOut2,re);
lr_output_message("return is %d",re);
if( cOut2 == cLine )//对返回值做判断
lr_end_transaction("sender", LR_PASS);
else
lr_end_transaction ("sender", LR_FAIL);
lrs_close_socket("socket0");
return 0;
}