51Testing软件测试网'^0L f#f#T
Uvoid lr_whoami (int *vuser_id, char **sgroup, int *scid);
O&e6_"}d)^v0VS.n:wFc0返回值:返回当前运行的vuser ID、运行脚本的组名称以及场景ID
L_g.ogu!g051Testing软件测试网
h"T$k.c-`SFk中文解释:lr_whoami函数获取关于vuser的信息
0^z~2]!B8Pn,J3~051Testing软件测试网xa3p~^(V&o?_参数说明:
3T]~ob4N~K9ST0【int *vuser_id】需先注册,保存正在运行的vuser的ID,在虚拟用户生成器(Virtual User Generator)中回放返回-151Testing软件测试网4_7V7\lt T
aFpY
【char **sgroup】需先注册,保存正在运行的vuser的组名(脚本名),在虚拟用户生成器(Virtual User Generator)中回放返回None51Testing软件测试网&n8t["kq)fu;r+`
【int *scid】需先注册,保存正在运行的Scenario的ID,在虚拟用户生成器(Virtual User Generator)中回放返回0
{
}8jCY
LcV08f$c0W y
|b6o0函数使用技巧:
"P;F$]6I3o(Dn'A01、函数的所有参数都为必须,其中vuser_id、scid两个整形的变量,如果不需要返回则直接用NULL替换即可
K1W
_B%RV!rns1d0例:lr_whoami (&myid,&mygroup,NULL); //就用NULL把scid的变量替换掉了,也就不保存scid了51Testing软件测试网)hRT:u7g8t{(oQc/h
F!d N`5fp4vW02、使用lr_whoami函数判断虚拟用户信息,增强脚本
7q6NpY;GqM&D0Action()51Testing软件测试网'O6b!~)Z/gQ7O
{51Testing软件测试网S4Ai4DwZ7cg
int id,scid;//定义保存vuser信息的2个整形变量
VP0A!yS:I]0 char *group;//定义保存groupname51Testing软件测试网1W7|]iu$V9OW
char *filename = "c:\\work\\log\\whoami.log";
oU"X gL^/~0 long file_stream;
e
H~ s7mMW0:Xcu%V9TK3FNe,`0 if ((file_stream = fopen(filename,"a+")) == NULL) //打开文件51Testing软件测试网qUe*@4?2W
{51Testing软件测试网K.F8Q5i Z1I
lr_error_message("Cannot open %s", filename);51Testing软件测试网X']%l],a(x?
return -1;
*f Q7q.qJ0 }
}9P4g4Rk5~o(?
`051Testing软件测试网/V4F
z;L-eP)DP(nF lr_whoami (&id,&group,&scid);//获取变量51Testing软件测试网0x c9od*S
if (id > 10)51Testing软件测试网|"Y;K[4aPj
{
u,oeWnn1p*v0 fprintf(file_stream,"vuser用户的信息:id=%d,group=%s,scid=%d\n",id,group,scid);51Testing软件测试网V.wZ#D7|\b
}
)P,DZ,W*JEI w0 else51Testing软件测试网r5tWC+ayI!C4x
fprintf(file_stream,"id=%d,group=%s,scid=%d\n",id,group,scid);
|)YF`r$uX8V|2n051Testing软件测试网H,ej{![+J/x fclose(file_stream);51Testing软件测试网0UT2D*`$a2l2Q7F,O1Pr~
return 0;
|G%~-dd7n|B0}51Testing软件测试网xM;T4nY,U2\
场景:运行15个用户跑这个脚本,log文件内容如下51Testing软件测试网c!`)Nur&~b
id=3,group=lr_whoami,scid=0
(u/S uOo
`B3MH)@0id=1,group=lr_whoami,scid=0
\
P4s8\S-E \r1{2C0id=2,group=lr_whoami,scid=0
{k |,`w0gI
hU#Nu0id=4,group=lr_whoami,scid=0
Jn+P#m(l/G0id=6,group=lr_whoami,scid=051Testing软件测试网Dli
H)rkMh9c C
id=5,group=lr_whoami,scid=0
!yB2|'`2o3Ya:P$V0id=7,group=lr_whoami,scid=051Testing软件测试网/PWmt9z doT
id=8,group=lr_whoami,scid=0
.?#S'Ub_0id=9,group=lr_whoami,scid=051Testing软件测试网6R[;G| [&L
id=10,group=lr_whoami,scid=0
4r3_3Dzvcn3]0vuser用户的信息:id=11,group=lr_whoami,scid=051Testing软件测试网2p2Nz.N ^"F
vuser用户的信息:id=13,group=lr_whoami,scid=0
8Qv B!f
R-@"s0vuser用户的信息:id=12,group=lr_whoami,scid=0
4{
V/k&~lO0vuser用户的信息:id=14,group=lr_whoami,scid=0
IArNW ft;A0vuser用户的信息:id=15,group=lr_whoami,scid=0
p:M7E;EZ.{!j0