|
update:原来的代码因为转码的原因去掉了方括号,更新为
LR脚本如下:
----------------------------------------------------------
Action()
{
int i;
char j[10][20];
int count=10;
//循环1:i最大为10
for (i=1;i<=10;i++) {
sprintf(j[i],"abc",i);
lr_output_message("√ j%d=%s\n",i,lr_eval_string(j[i]));
}
//循环2:i最大为11
for (i=1;i<=count;i++) {
sprintf(j[i],"abc",i);
lr_output_message("× j%d=%s\n",i,lr_eval_string(j[i]));
}
return 0;
}
----------------------------------------------------------
这是简化后的脚本 ,[color=#ff0000]问题是:为什么加了变量的循环会越界[/color]
脚本说明:
通过循环对数组赋值,循环用常量赋值则一切正常,如用自定义变量则会越界,比如上例中count=10,结果存在i=11的情况,这时lr会报错
[font=mceinline]——难道是C语言编译器的问题?这样的结果岂不是不能用变量做for边界?
以上脚本可以贴到action中直接运行,有兴趣的可以试试,欢迎高手解惑:)
-----------------------------------------Ps:我的运行结果--------------------------------
Virtual User Script started
Starting action vuser_init.
Web Turbo Replay of LoadRunner 8.1.0 for WIN2003; Web build 4788 [MsgId: MMSG-27143]
Run-Time Settings file: "C:\Documents and Settings\robin\Local Settings\Temp\noname4\\default.cfg" [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(8): √ j1=abc
Action.c(8): √ j2=abc
Action.c(8): √ j3=abc
Action.c(8): √ j4=abc
Action.c(8): √ j5=abc
Action.c(8): √ j6=abc
Action.c(8): √ j7=abc
Action.c(8): √ j8=abc
Action.c(8): √ j9=abc
Action.c(8): √ j10=abc
Action.c(14): × j1=abc
Action.c(14): × j2=abc
Action.c(14): × j3=abc
Action.c(14): × j4=abc
Action.c(14): × j5=abc
Action.c(14): × j6=abc
Action.c(14): × j7=abc
Action.c(14): × j8=abc
Action.c(14): × j9=abc
Action.c(14): × j10=abc
Action.c(14): Error: C interpreter run time error: Action.c (14): Error -- memory violation : Exception ACCESS_VIOLATION received.
Action.c(14): Error: An exception was raised while calling invocation function in interpreter extension cciext.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION.
Ending Vuser...
Starting action vuser_end.
Action.c(14): Notify: CCI trace: Action.c(14): vuser_end()
.
Action.c(14): Notify: CCI trace: pop[1] -> 0
.
Ending action vuser_end.
Vuser Terminated.
[[i] 本帖最后由 hanyuan72 于 2010-6-3 16:25 编辑 [/i]] |
|