51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2377|回复: 5
打印 上一主题 下一主题

[求助] 关于loadrunner函数编写位置问题和lr_output_message问题

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2013-9-9 15:59:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 hbacc2047003 于 2013-9-9 16:02 编辑
  1.         char *randstring(int slen)
  2. {
  3.     int i,randid;
  4.     char temp[100]="";
  5.     char character_set[52]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','a','b','c',
  6.         'd','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'};

  7.     for(i=1;i<=slen;i++)
  8.     {
  9.         randid = rand()%52;
  10.         sprintf(temp,"%s%c",temp,character_set[randid]);        
  11.     }

  12.     return(temp);

  13. }

  14. Action()

  15. {


  16.         web_url("phpwind85",
  17.                 "URL=http://127.0.0.1:8080/phpwind85",
  18.                 "TargetFrame=",
  19.                 "Resource=0",
  20.                 "RecContentType=text/html",
  21.                 "Referer=",
  22.                 "Snapshot=t3.inf",
  23.                 "Mode=HTML",
  24.                 EXTRARES,
  25.                 "Url=/phpwind85/js/lang/zh_cn.js", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  26.                 "Url=/phpwind85/images/wind85/topbar.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  27.                 "Url=/phpwind85/images/wind85/bg.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  28.                 "Url=/phpwind85/images/button.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  29.                 "Url=/phpwind85/images/wind85/navA.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  30.                 "Url=/phpwind85/images/wind85/hB.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  31.                 "Url=/phpwind85/images/wind85/searchA.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  32.                 "Url=/phpwind85/images/wind85/down.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  33.                 "Url=/phpwind85/images/wind85/colon.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  34.                 "Url=/phpwind85/images/select_arrow.gif", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  35.                 "Url=/phpwind85/images/wind85/h.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  36.                 "Url=/phpwind85/images/wind85/new.gif", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  37.                 "Url=/phpwind85/images/del.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  38.                 "Url=/phpwind85/images/wind85/search_btn.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  39.                 "Url=/phpwind85/images/wind/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  40.                 "Url=/phpwind85/images/wind8gray/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  41.                 "Url=/phpwind85/images/wind8black/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  42.                 "Url=/phpwind85/images/wind8green/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  43.                 "Url=/phpwind85/images/wind8purple/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  44.                 "Url=/phpwind85/images/wind85/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  45.                 "Url=/phpwind85/images/register/regright.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  46.                 "Url=/favicon.ico", "Referer=", ENDITEM,
  47.                 "Url=/phpwind85/images/pwicon/top.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
  48.                 LAST);

  49.         lr_think_time(25);

  50.         web_submit_data("login.php",
  51.                 "Action=http://127.0.0.1:8080/phpwind85/login.php",
  52.                 "Method=POST",
  53.                 "TargetFrame=",
  54.                 "RecContentType=text/html",
  55.                 "Referer=http://127.0.0.1:8080/phpwind85/",
  56.                 "Snapshot=t4.inf",
  57.                 "Mode=HTML",
  58.                 ITEMDATA,
  59.                 "Name=jumpurl", "Value=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  60.                 "Name=step", "Value=2", ENDITEM,
  61.                 "Name=pwuser", "Value={usernameid}", ENDITEM,
  62.                 "Name=pwpwd", "Value=1234567", ENDITEM,
  63.                 "Name=head_login", "Value=", ENDITEM,
  64.                 "Name=lgt", "Value=0", ENDITEM,
  65.                 EXTRARES,
  66.                 "Url=images/register/regright2.png", ENDITEM,
  67.                 "Url=js/lang/zh_cn.js", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  68.                 "Url=images/wind85/bg.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  69.                 "Url=images/wind85/topbar.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  70.                 "Url=images/g/facebg_a.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  71.                 "Url=images/down.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  72.                 "Url=images/wind85/navA.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  73.                 "Url=images/wind85/searchA.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  74.                 "Url=images/wind85/search_btn.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  75.                 "Url=images/wind85/down.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  76.                 "Url=images/wind85/colon.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  77.                 "Url=images/wind85/hB.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  78.                 "Url=images/wind85/h.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  79.                 "Url=images/wind85/new.gif", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  80.                 "Url=images/wind/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  81.                 "Url=images/wind8gray/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  82.                 "Url=images/wind8black/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  83.                 "Url=images/wind8green/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  84.                 "Url=images/wind8purple/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  85.                 "Url=images/wind85/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  86.                 "Url=images/register/regright.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  87.                 "Url=images/pwicon/top.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
  88.                 LAST);


  89.     lr_save_string(randstring(5),"searchstring");

  90. //lr_output_message("zheshi %s",temp[100]);

  91.         lr_think_time(10);

  92.         lr_start_transaction("search");

  93.         web_submit_data("searcher.php",
  94.                 "Action=http://127.0.0.1:8080/phpwind85/searcher.php",
  95.                 "Method=POST",
  96.                 "TargetFrame=",
  97.                 "RecContentType=text/html",
  98.                 "Referer=http://127.0.0.1:8080/phpwind85/index.php",
  99.                 "Snapshot=t5.inf",
  100.                 "Mode=HTML",
  101.                 ITEMDATA,
  102.                 "Name=verify", "Value=b2496deb", ENDITEM,
  103.                 "Name=step", "Value=2", ENDITEM,
  104.                 "Name=type", "Value=thread", ENDITEM,
  105.                 "Name=keyword", "Value={searchstring}", ENDITEM,
  106.                 EXTRARES,
  107.                 "Url=images/search/search_del.png", ENDITEM,
  108.                 "Url=images/search/search_btn.png", ENDITEM,
  109.                 "Url=images/search/pImg.png", ENDITEM,
  110.                 "Url=u/images/pre.cur", ENDITEM,
  111.                 "Url=u/images/next.cur", ENDITEM,
  112.                 "Url=images/search/pImg_close.png", ENDITEM,
  113.                 LAST);


  114.         lr_end_transaction("search", LR_AUTO);


  115.         return 0;
  116. }
复制代码
有这么几个问题,希望达人解答下
1.如果上述代码所述,函数randstring写在action外面是能完全走完脚本的,但是为什么写在action里面就各种报错了呢?错误信息不截图了,太多了
2.如102行代码所示,我想输出一个值,查看随机出的字符串。但是只要加上这行代码,会提示我以下信息
Action.c (14): warning: pointer to local `temp' is an illegal return value
Action.c (102): undeclared identifier `temp'
Action.c (102): type error: pointer expected
e:\\phpwind\301\252\317\265\275\305\261\276\\\277\264\314\373\\\\combined_\277\264\314\373.c (5): 2 errors, not writing pre_cci.ci
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2013-9-9 18:08:40 | 只看该作者
这个问题我貌似在blog上写过,在我当初写这个例子的LR版本上从函数返回的数据可以走入action中并被转化为参数,但是后面有人问到这个问题,我也出现了该问题,于是就修改了代码,你在函数中直接转化为参数来做就不会有错了,具体问题为什么,确实一下不知道原因。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2013-9-9 18:09:59 | 只看该作者
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2013-9-10 08:55:10 | 只看该作者
回复 3# 云层


  谢谢,参考下
回复 支持 反对

使用道具 举报

该用户从未签到

5#
 楼主| 发表于 2013-9-10 12:28:04 | 只看该作者
回复 3# 云层


   自己查找了下,P349上面的randstring函数本身写的好像有些问题?
   我的理解是:
   randstring因为返回的是一个指针,当这个函数执行完毕后,内存空间清空了,所以在action里面怎么也取不到值
   我试下来正确的写法是(只写有变动的地方)
  int randstring(char* temp,int slen)
{
  //char temp[100] = "";
  return 0 ;
}

action
{
  char *p;
p=(char*)malloc(100);
randstring(p,5);
lr_save_string(p,“search”);
}
通过主函数里面定义的P指针,在主函数中开辟一个内存空间,让temp指针指向P指针的内容,这样内存清空后,P还是能拿到值
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2013-9-10 13:27:37 | 只看该作者
回复  云层


   自己查找了下,P349上面的randstring函数本身写的好像有些问题?
   我的理解是:
  ...
hbacc2047003 发表于 2013-9-10 12:28



    多谢指导
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-21 09:16 , Processed in 0.077418 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表