I am writing a script to test the web server.Basically this utility is written to test the login-logout feature of the web server. Below is the complete code of the utility.Please look into that.
use WWW::Mechanize; use Config::IniFiles; use threads; use threads::shared; use Time::HiRes qw(gettimeofday); $options = new Config::IniFiles ( -file => "loginOptions.ini"); $options1 = new Config::IniFiles ( -file => "loginUserNamePassword.in +i"); our (%login_hashArray); our $simul_loginenable:shared; our $simul_logoutenable:shared; our $simul_loginenable = 0; our $simul_logoutenable = 0; our $DEBUG; our $incremental_load; our $URL; ########################## sub initVarsFromOptionsFile() { #### $DEBUG=$options->val('DEBUG','DEBUG'); $incremental_load=$options->val('OTHERS','INCREMENTAL_LOAD'); #### $URL=$options->val('DUT_INFO','DUT_URL'); #### my @userName; my @password; my $no_of_users=$options->val('LOGIN_INFO','NO_OF_USERS'); my $simultaneousLogin=$options->val('LOGIN_INFO','SIMULTANEOUS_LOGIN') +; my $simultaneousLogout=$options->val('LOGIN_INFO','SIMULTANEOUS_LOGOUT +'); my $no_of_login=$options->val('LOGIN_INFO','NO_OF_LOGIN'); #### if($no_of_users == 1) { $userName=$options->val('LOGIN_INFO','UNAME'); $password=$options->val('LOGIN_INFO','UPASS'); @userName=$userName; @password=$password; } else { my @userName_password=$options1->val('LOGIN_INFO','UNAMEPASS') +; $i=0; foreach $userName_password(@userName_password) { $userName_password=~/(.*?)=(.*)/; $userName[$i]=$1; $password[$i]=$2; $i++; } my $tmp_no_of_users=@userName; if($no_of_users > $tmp_no_of_users ) { print "LoginPassword info is not found for $no_of_user +s users in loginUserNamePassword.ini.Please provide correct info in l +oginOption.ini file......\n"; exit -1; } } #### $login_hashArray{0}=\@userName; $login_hashArray{1}=\@password; $login_hashArray{2}=$no_of_users; $login_hashArray{3}=$simultaneousLogin; $login_hashArray{4}=$simultaneousLogout; $login_hashArray{5}=$no_of_login; } sub start() { @threads; #### $hash{user}=$login_hashArray{0}; $hash{password}=$login_hashArray{1}; $hash{no_of_users}=$login_hashArray{2}; $hash{simultaneous_login}=$login_hashArray{3}; $hash{simultaneous_logout}=$login_hashArray{4}; $hash{no_of_login}=$login_hashArray{5}; my $no_of_users=$hash{no_of_users}; print "Number of user are:$no_of_users \n"; ##### for($u=0;$u<$no_of_users;$u++) { print "####################################\n"; print "#Thread:$u #\n"; print "####################################\n"; $threads[$u] = threads->create(start_login); print "Incremental_load=$incremental_load\n"; sleep $incremental_load; if($hash{simultaneous_login} eq "OFF" && $hash{simultaneous_lo +gout} eq "OFF") { close(LOG); $result = $threads[$u]->join(); } } $simul_loginenable = 1; $simul_logoutenable = 1; if(($hash{simultaneous_login} eq "ON" && $hash{simultaneous_logout +} eq "ON") || ($hash{simultaneous_login} eq "OFF" && $hash{simultaneo +us_logout} eq "ON") || ($hash{simultaneous_login} eq "ON" && $hash{si +multaneous_logout} eq "OFF")) { foreach my $threads (@threads) { close(LOG); $result = $threads->join(); } } } sub start_login() { my @userName=@{$hash{user}}; my @password=@{$hash{password}}; my $no_of_users=$hash{no_of_users}; my $simultaneous_login=$hash{simultaneous_login}; my $simultaneous_logout=$hash{simultaneous_logout}; my $no_of_login=$hash{no_of_login}; my $logFile="LogFile"."-".$userName[$u]."."."txt"; open(LOG,">$logFile"); =catch print "this is debug statement userName:@userName\n"; print "this is debug statement password:@password\n"; print "this is debug statement no_of_users:$no_of_users\n"; print "this is debug statement simultaneous_login:$simultaneous_login\ +n"; print "this is debug statement simultaneous_logout:$simultaneous_logou +t\n"; print "this is debug statement no_of_login:$no_of_login\n"; =cut for($l=0;$l<$no_of_login;$l++) { $agent = WWW::Mechanize->new(); ###########################Logging IN if($simultaneous_login eq "OFF") { #print "Logging IN Simultaneous OFF:UserName:$userName[$u],Pas +sword:$password[$u]\n"; login($userName[$u],$password[$u]); } elsif($simultaneous_login eq "ON") { while($simul_loginenable != 1) { print "Inside while Loop Sleep\n"; sleep(1); } login($userName[$u],$password[$u]); } ###########################Downloading if($simultaneous_logout eq "OFF") { #print "Logging OUT Simultaneous OFF:UserName:$userName[$u],Pa +ssword:$password[$u]\n"; logout($userName[$u],$password[$u]); } elsif($simultaneous_logout eq "ON") { while($simul_logoutenable != 1) { print "Inside logout while Loop Sleep\n"; sleep(1); } logout($userName[$u],$password[$u]); } undef $agent; } } ##########Login Function sub login($$) { my $username=shift; my $password=shift; my ($content,$time0,$status,$temp,$time1,$login_time); ############## $time0=gettimeofday; $agent->get($URL); $status = $agent->status(); unless ($status==200) { print "Fail:Could not get the response properly for $username. +Please Check serer IP or Network Connectivity\n"; print LOG "Fail:Could not get the response properly for $usern +ame.Please Check serer IP or Network Connectivity\n"; return (-1); } ############## $agent->form_name('login'); $agent->field('upass',$password ); $agent->field('uname',$username ); $agent->click(); $content=$agent->response()->content(); $content=~/parent.location.href='..\/(.*?)'/; $temp=$URL.$1; #print "|$temp|\n"; $agent->get($temp); $time1=gettimeofday; sleep 2; $status=$agent->status(); $content=$agent->response()->content(); $login_time=$time1-$time0; if($DEBUG eq "Enable") { open(FH,">$username.login.html"); print FH $content; close(FH); } unless ($status==200) { print "Login Status:ERROR$status,UserName:$username,LoginNo:$l +,Reason:Could not get the response properly.Please Check userName Pas +sword.\n"; print LOG "Login Status:ERROR$status,UserName:$username,LoginN +o:$l,Reason:Could not get the response properly.Please Check userName + Password.\n"; return (-1); } unless ($content =~ />Logout/) { print "Login Status:ERROR,UserName:$username,LoginNo:$l,Reason +:Login page is not as expected.Please Check userName Password.\n"; print LOG "Login Status:ERROR,UserName:$username,LoginNo:$l,Re +ason:Login page is not as expected.Please Check userName Password.\n" +; return (-1); } print "Login Status:PASS,UserName:$username,LoginNo:$l,Login Time: +$login_time Sec\n"; print LOG "Login Status:PASS,UserName:$username,LoginNo:$l,Login T +ime:$login_time Sec\n"; } ##########Logout Function sub logout($$) { my $username=shift; my $password=shift; my ($content,$time0,$status,$buf,$time1,$logout_time); $time0=gettimeofday; $agent->get($URL); $status = $agent->status(); unless ($status==200) { print "Fail:Could not get the response properly for $username. +Please Check serer IP or Network Connectivity\n"; print LOG "Fail:Could not get the response properly for $usern +ame.Please Check serer IP or Network Connectivity\n"; return (-1); } $buf=$agent->response()->content(); $agent->get($URL."common/validate.php?uid=1&uname=$username&ut=2&l +vl=9c79ed3e43662d611fd46cc4bd7bea2c&entry=2&typ=logout"); $agent->get($URL."index.php?uname=$username&lvl=9c79ed3e43662d611f +d46cc4bd7bea2c&typ=logout"); $time1=gettimeofday; sleep 2; $logout_time=$time1-$time0; $status=$agent->status(); $content=$agent->response()->content(); if($DEBUG eq "Enable") { open(FH,">$username.logout.html"); print FH $content; close(FH); } unless ($status==200) { print "LogoutStatus:ERROR$status,UserName:$username,LoginNo:$l +,Reason:Could not get the response properly.Please Check userName Pas +sword.\n"; print LOG "LogoutStatus:ERROR$status,UserName:$username,LoginN +o:$l,Reason:Could not get the response properly.Please Check userName + Password.\n"; return (-1); } unless ($content =~ /to enjoy an/ && $buf=~/>Logout/) { print "LogoutStatus:ERROR,UserName:$username,LoginNo:$l,Reason +:Logout page is not as expected.Please Check userName Password.\n"; print LOG "LogoutStatus:ERROR,UserName:$username,LoginNo:$l,Re +ason:Logout page is not as expected.Please Check userName Password.\n +"; return (-1); } print "LogoutStatus:PASS,UserName:$username,LoginNo:$l,LogoutTime: +$logout_time Sec\n"; print LOG "LogoutStatus:PASS,UserName:$username,LoginNo:$l,LogoutT +ime:$logout_time Sec\n"; } ##################### sub logfile() { my $no_of_users=$login_hashArray{2}; my @userName=@{$login_hashArray{0}}; open(FH,">>AllUserLOG.txt") or die "could not open the All +UserLOG.txt file\n"; for (my $i=0;$i<$no_of_users;$i++) { my $t_log="LogFile"."-".$userName[$i].".".txt; open(FP,"$t_log") or print "could not open |$t_log| file\n +"; my @tp=<FP>; close(FP); my $tp=join('',@tp); print FH $tp; } close(FH); } ##################### sub main { initVarsFromOptionsFile; start(); logfile(); } &main;
20060713 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
edit (broquaint): Added <readmore> tags per consideration. In reply to Re^2: Getting the Error message "*** glibc detected *** corrupted double-linked list:"
by chiragforever
in thread Getting the Error message "*** glibc detected *** corrupted double-linked list:"
by chiragforever
For:
Use:
& & < < > > [ [ ] ]