• <menu id="w2i4a"></menu>
  • logo LoadRunner 系列教程
    文檔首頁(yè)>>LoadRunner 系列教程>>LoadRunner添加C語(yǔ)言代碼的幾種方式

    LoadRunner添加C語(yǔ)言代碼的幾種方式


    今天給大家?guī)?lái)如何直接把自己的C語(yǔ)言代碼讓LoadRunner調(diào)用,一般有三種方法,廢話不多,直接干貨。

    1.直接引用
      1)寫一個(gè)c代碼,直接保存為c文件,代碼如下。文件為sum.c
      int sum(int num1,int num2)
      {
      retun num1+num2;
      }
      2)打開Loadrunner 新建一個(gè)空白http協(xié)議腳本,保存為L(zhǎng)r_Call_cCode
      3)打開該腳本的文件夾,找到“globals.h”文件,在全局變量中添加以下內(nèi)容,保存。
    #ifndef _GLOBALS_H
    #define _GLOBALS_H
    //--------------------------------------------------------------------
    // Include Files
    #include "lrun.h"
    #include "web_api.h"
    #include "lrw_custom_body.h"
    #include "sum.c"  //此行為添加內(nèi)容
    //--------------------------------------------------------------------
    // Global Variables
    #endif // _GLOBALS_H
      4)將文件"sum.c"拷貝到腳本“Lr_Call_cCode”根目錄中
      5)編輯action腳本如下:
      Action()
      {
      int *i, *j;
      int a=50, b=50;
      i = &a;
      j = &b;
      lr_message("i+j=%d",sum(i,j));
      return 0;
      }
      6)保存,調(diào)試腳本,通過(guò)。
    Virtual User Script started at : 2016-03-28 09:13:52
    Starting action vuser_init.
    Web Turbo Replay of LoadRunner 11.0.0 for Windows 2008 R2; build 9238 (Feb  1 2011 02:48:36)      [MsgId: MMSG-27143]
    Run Mode: HTML      [MsgId: MMSG-26000]
    Run-Time Settings file: "C: eststudyLr_Call_cCode\default.cfg"      [MsgId: MMSG-27141]
    Ending action vuser_init.
    Running Vuser...
    Starting iteration 1.
    Starting action Action.
    i+j=100
    Ending action Action.
    Ending iteration 1.
    Ending Vuser...
    Starting action vuser_end.
    Ending action vuser_end.
    Vuser Terminated.
      
    2.第二種方法,更直接
      直接在action中寫代碼
    Action()
    {
    int *i, *j;
    int a=50, b=50;
    i = &a;
    j = &b;
    lr_message("i+j=%d",sum(i,j));
    return 0;
    }
    /*直接在action函數(shù)外部寫c代碼*/
    int sum(int num1,int num2)
    {
    retun num1+num2;
    }
      保存腳本,回放,結(jié)果同1.
      3.通過(guò)VC++使用標(biāo)準(zhǔn)C語(yǔ)言編寫sum.dll庫(kù)
      通過(guò)Loadrunner調(diào)用,官方文檔說(shuō)明:
    int lr_load_dll( const char *library_name );
    note:library_name  The name of a DLL (Windows) or shared object (UNIX).
    The lr_load_dll function loads a DLL (Windows) or shared object (UNIX) allowing you to call an external function when replaying using the
    C interpreter. Once you load the DLL, you can call any function defined in the DLL, without having to declare it.
    You can specify a full path for the DLL.
    On Windows platforms, if you do not specify a path, lr_load_library searches for the DLL using the standard sequence used by the C++ function, LoadLibrary .
    On UNIX platforms, you can set the LD_LIBRARY_PATH environment variable (or the platform equivalent). The lr_load_dll function uses the same search
    rules as dlopen. For more information, see the man pages for dlopen or its equivalent.
      dll動(dòng)態(tài)庫(kù)編寫使用標(biāo)準(zhǔn)c++函數(shù),加載標(biāo)準(zhǔn)的WindowsLoadLibrary.Linux平臺(tái)類似,不過(guò)大部分人用估計(jì)都是在windows平臺(tái)吧。

    本文轉(zhuǎn)自(spasvo.com

    點(diǎn)擊下載最新版LoadRunner試用

    >>>年終促銷第一波強(qiáng)勢(shì)來(lái)襲,全場(chǎng)6折起,趕緊搶!<<<

    活動(dòng)截止日:10月31日

    loadrunner

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();