Loadrunner的Tuxedo脚本分析,基本流程和基本函数介绍

#include "lrt.h"
#include "replay.vdf"

vuser_init()
{


 //=================================================================================================================
 // 第一个交易
 
    // 1.设置变量组: Sets a list of environment variables.
 lrt_set_env_list(env_allow_array);

    // 2.从配置文件读取环境变量:  Adds variables to the environment from a file.
 lrt_tuxreadenv("C:\\Program Files\\test\\test8\\etc\\tuxedoenv.ini", "TUXCOMM");

    //事务开始
 lr_start_transaction("01_login");

    // 3. Modifies an existing environment value or adds a value to the environment.
 lrt_tuxputenv("ULOGPFX=c:\\log\\330100-300302");

 lr_think_time(25);

    // 4.分配空间: Allocates a new buffer.
 // The lrt_tpalloc function allocates a new buffer and returns a pointer to a buffer of specified type. Since some buffer types
 // require initialization before they can be used, lrt_tpalloc initializes a buffer after it is allocated, before it is returned.
 data_0 = lrt_tpalloc("FML32", "", 65000);

 // 5.进行初始化: Initializes an existing FML buffer.
   //  注意:  data_0 在replay.vdf 中已经被定义,同时在此处被初始化,初始化后,就可以向里面添加field-value对了.
 lrt_Finitialize32((FBFR32*)data_0);

 // 6.向data_0中加field-value对,就是传给后台tuxedo服务的数据:
 lrt_Fadd32_fld((FBFR32*)data_0, "id=167772364", "value=330100", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=167772373", "value=10.253.1.138", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=167772374", "value=000000000000", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=167772375", "value=1", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=167772422", "value=300302", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=167772423", "value=000000", LRT_END_OF_PARMS);

   // 7. 分配空间给data_1: Allocates a new buffer.
 data_1 = lrt_tpalloc("FML32", "", 65000);


 // 8. 使用lrt_tpcall 调用服务,发送的数据是data_0,服务器的返回信息保存在data_1中.
 // lrt_tpcall Sends a service request and awaits its reply.
    // int lrt_tpcall ( char *svc, char *idata, long ilen, char **odata, long *olen, long flags );

 // svc  Requested service (can be parameterized). 
 // idata  Data portion of the request. 
 // ilen  Length of request data to send. 
 // odata  Reply data. 
 // olen  Length of reply data. 
 // flags  Valid flags: TPNOTRAN- SVC will not be performed on behalf of caller's transaction,
 //    TPNOCHANGE - buffer type of reply data is not allowed to change, TPNOBLOCK - request not sent if blocking condition exists,
 //    TPNOTIME - caller immune to blocking timeouts, TPSIGRSTRT - any interrupted system calls are re-issued after lrt_tpcall. 

 tpresult_int = lrt_tpcall("new_css_Login",
  data_0,
  0,
  &data_1,
  &olen,
  0);
 /* Returned FML32 buffer 1 */


 // 9.使用lrt_save32_fld_val 从服务器返回信息中获取需要的数据:
 // The lrt_save32_fld_val function saves the current value of an FML32 buffer to a parameter specified by paramName.
 // lrt_save32_fld_val(fbfr, "id=xxxx", 0, "parameter");
 // lrt_save32_fld_val(fbfr, "name=xxxx", 0, "parameter");
 lrt_save32_fld_val((FBFR32*)data_1,"id=167772363",0,"returnValue") ;
    // print
 lr_output_message("返回值:%s",lr_eval_string("{returnValue}") ) ;

    // 10.如果出错,则停止事务Aborts the current transaction if the previous Tuxedo function resulted in an error.
 lrt_abort_on_error();


 //11.释放之前的空间和连接:
 // The lrt_tpfree function frees a buffer that was previously obtained by either lrt_tpalloc or lrt_tprealloc.
 lrt_tpfree(data_0);
 lrt_tpfree(data_1);
 // The lrt_tpterm function removes a client from a System/T application.
 // If the client is in transaction mode, then the transaction is rolled back.
 lrt_tpterm();


    // 第一个交易已经完成.
    //=================================================================================================================

 // 进行第二个交易:
 
    // 其他的操作和第一轮操作类似:
    //分配新的空间
 data_0 = lrt_tpalloc("FML32", "", 65535);
 // 重新初始化:
 lrt_Finitialize32((FBFR32*)data_0);
 //设置数据
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554633", "value=5084013", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554637", "value=9901", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554640", "value=1", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554642", "value=920041", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=42755520", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=67109070", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=67109071", "value=1", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=67109076", "value=Q", LRT_END_OF_PARMS);
    // 为返回值分配空间:
 data_1 = lrt_tpalloc("FML32", "", 65535);
 // 调用服务:
 tpresult_int = lrt_tpcall("csi_01",
  data_0,
  0,
  &data_1,
  &olen,
  0);
 /* Returned FML32 buffer 2 */
 lrt_abort_on_error();

// 释放
 lrt_tpfree(data_0);
 lrt_tpfree(data_1);
 lrt_tpterm();


   // 第二个交易完成
   //=================================================================================================================

 lr_end_transaction("01_login", LR_AUTO);


 lr_start_transaction("05_select");

   
 // 第三个及以后的所有交易,都与之前的交易类似:
 //=================================================================================================================

 lr_think_time(55);
 data_0 = lrt_tpalloc("FML32", "", 65535);
 lrt_Finitialize32((FBFR32*)data_0);
 
 lrt_Fadd32_fld((FBFR32*)data_0, "id=1101360", "value=1", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=1101360", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=1101360", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=1101360", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554633", "value=5084013", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554637", "value=9901", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554640", "value=1", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=33554642", "value=110001", LRT_END_OF_PARMS);

 data_1 = lrt_tpalloc("FML32", "", 65535);
 tpresult_int = lrt_tpcall("csi_01",
  data_0,
  0,
  &data_1,
  &olen,
  0);
 /* Returned FML32 buffer 3 */
 lrt_abort_on_error();

 lrt_tpfree(data_0);
 lrt_tpfree(data_1);
 lrt_tpterm();


//=================================================================================================================

 data_0 = lrt_tpalloc("FML32", "", 65535);
 lrt_Finitialize32((FBFR32*)data_0);
 
 lrt_Fadd32_fld((FBFR32*)data_0, "id=1101225", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=1101307", "value=0", LRT_END_OF_PARMS);
 lrt_Fadd32_fld((FBFR32*)data_0, "id=168873390", "value=", LRT_END_OF_PARMS);

 data_1 = lrt_tpalloc("FML32", "", 65535);
 tpresult_int = lrt_tpcall("csi_01",
  data_0,
  0,
  &data_1,
  &olen,
  0);
 /* Returned FML32 buffer 11 */
 lrt_abort_on_error();
 
 lrt_tpfree(data_0);
 lrt_tpfree(data_1);
 lrt_tpterm();
 lr_end_transaction("05_select", LR_AUTO);

//=================================================================================================================

 return 0;
}

Action()
{
 return 0;
}

vuser_end()
{
 return 0;
}

replay.vdf

#ifndef TUXVDF_H
#define TUXVDF_H
char* data_0;
char* data_1;

/* Returned FML32 buffer 1
field: "id=33554633", "occurrence=0", "value=5084013"
field: "id=33554637", "occurrence=0", "value=9901"
Reply buffer */

#endif /* TUXVDF_H */

loadrunner wdiff对比返回结果,分析异同,进行关联
也可以监测服务器收到的和返回的信息,分析

posted @ 2011-03-31 14:30  大CC  阅读(1556)  评论(0编辑  收藏  举报
木书架 大CC的博客