当前位置:首页 > Loadrunner学习 - 脚本编写系列(1)
对于COM/DCOM协议:略 C脚本语言的格式:
LoadRunner使用的没有进行微软扩展的ANSI C语法。任意最小的action代码块如下:
#include as_web.h // from LoadRunner's include folder. Action1() {
/* comment block */
// comment line
return 0; }
C脚本编译/类库
当VuGen编译脚本时,产生一个\文件,这个文件包含了所有action的代码和包含文件。这就是为什么会有语法错误“not writing pre_cci.ci”的原因。 控制器编译这些.ci文件为机器目标码。
VuGen在每一个脚本文件中自动创建一个lib文件夹,这个文件夹中包含了combined_lib.c文件。该文件包含了所有引用文件。
#include \来定义 UNIX或者Windows的函数。 #include \的模版文件夹的其中一个。 #include \ #include \ #include \
警告:当你使用类库中的函数却没有正确包含该类库的时候,你会收到一条错误信息: Error -- Unresolved symbol C类库
LoadRunner 使用1994 GNU C Pre-Processoroptions 和1995 LCC-win32 Retargetable
C Compiler/Linkerfrom the Free Software Foundation via Chris Fraser of AT&T and Dave Hanson of Princeton. 附加的函数定义在
ANSI C library中。
外部的没有返回整型数的C函数需要在脚本的开头进行显式声明。例如,string函数中的 string tokenizer:extern char*strtok(char *token, const char *delimiter); Java语法:略
OK,先到这里,休息一下,下期接着翻译LR脚本相关知识.
loadrunner学习系列---脚本编写(2)
今天接着翻译http://www.wilsonmar.com/1lrscrīpt.htm上面关于LR脚本编写部分. VUser_Init部分
这里是Vuser_init部分的一些例子: 操作系统的User ID
下面显示了使用advapi32.dll的GetUserNameA函数获得的操作系统的用户ID char
sUserID[1024]; // Maximum possible UserID length. long int
lUserIDSize = sizeof(sUserID)-1; rc;
rc=lr_load_dll(\if( rc != 0 ){
lr_error_message(\
for rc=%d\
}else{
GetUserNameA(sUserID, &lUserIDSize); lr_message(\lr_abort();
}
所有的变量声明需要一块放到最上方。在vuser_init 部分创建的本地C变量(如 int或char)对其他部分的脚本是不可见的。所以使用lr_save_string函数来创建对所有脚本可用的全局参数。例子:
char *itoa ( int value, char *str, int radix ); vuser_init(){
int x = 10; char buffer[10];
lr_save_string(itoa( x, buffer, 10) , \
lr_message ( \
return 0; }
运行时设置的附加属性(Additional Attribute)
8.0版本引进了一个非常有价值的特性:在运行时设置中指定属性,这个属性可以对不同的虚拟用户组设置不同的值。
下面的代码是从运行时设置的附加属性中读取名为“usertype”的参数。然后使用参数值来对应的设置全局的\变量。
int thinktime1=0; vuser_init() {
LPCSTR strUsertype; // Define *str.
strUsertype =lr_get_attrib_string(\if (strUsertype==NULL){
lr_output_message(\specified. Cannot continue.\lr_abort(); }else{
lr_message(\strUsertype );
if( strcmp( strUsertype,\Else
if( strcmp( strUsertype,\else
if( strcmp( strUsertype,\else{
lr_error_message(\lr_abort(); } }
return 0; }
Time Structure Fix(不知道怎么翻译,呵呵,“时间结构的解决“?)
根据知识库34195的文章,默认当前时间戳的毫秒部分不被更新,除非ftime使用的时间结构被重新定义: typedef long time_t;
共分享92篇相关文档