Friday 11 April 2014

Sample date conversion program using vugen scripting in Load runner

//Main Function
Action()
{
char *ConvDate;

//Call date conversion function
dateConv("10/JUL/2009", ConvDate);
lr_output_message("date is %s",ConvDate);
return 0;
}

//Date conversion function
dateConv(char *MyDate, char *ReqDate)
{
lr_save_var(MyDate,2,0,"Date");
lr_save_var(MyDate+3,3,0,"pMonth");

lr_output_message("Month is %s",lr_eval_string("{pMonth}"));

if(strcmp(lr_eval_string("{pMonth}"),"JAN")==0)
lr_save_string("01","Month");

/*  Similar rest of the code goes here....*/

else if(strcmp(lr_eval_string("{pMonth}"),"DEC")==0)
lr_save_string("12","Month");

lr_save_var(MyDate+7,4,0,"Year");

ReqDate = lr_eval_string("{Month}/{Date}/{Year}");
lr_output_message("date is %s",ReqDate);

return 0;
}

Invoke Vugen from a .net app

Steps for running Vugen from a .NET application:

1. Add System as a Reference to the project
2. Here is actual code to run the script -
Shell("[Vugen Installation Folder]\bin\mmdrv.exe -usr [Full path of the script] -vugen_win 0", AppWinStyle.NormalFocus)

Example :

Shell("C:\Program Files\HP\Virtual User Generator\bin\mmdrv.exe -usr C:\FlightsTool\FlightCal.usr -vugen_win 0", AppWinStyle.NormalFocus)
Note: Neither Vugen now the Run Time window will be visible as the script runs in the background, however the results, log files, etc will be still be saved in the usual location.

lr_param_sprintf security issue when run over a firewall(Error: CCI security error: You are running under secure mode and the function lr_param_sprintf is not allowed in this mode. )

The function lr_param_sprintf sometimes causes a security issue in the script when run from Performance Center.

Error Message
Error: CCI security error: You are running under secure mode and the function lr_param_sprintf is not allowed in this mode.

This function causes an issue in Performance Center due to the way the function works and the way the Load Generators have been setup in the environment as this function does not work over a firewall.
Solution:This is an example of how function could be to generate a timestamp value –

lr_param_sprintf( "timeStamp" , "%ld", time(&t) );
An easier and workable way of which is

char strTime[10]; //timestamp variable
/*
-- -- -- -- -- -- -- --
Other code goes here
-- -- -- -- -- -- -- --
*/
lr_save_string( (char*)itoa( time(&t), strTime, 10 ), "timeStamp" );

Run Vugen from command prompt in load runner

Run Vugen from command prompt

Here is the command to run vugen from the command prompt

1. Go to where the Vugen is installed and navigate to the 'bin' folder
C:\Program Files\HP\Virtual User Generator\bin

2. Run the following command there
mmdrv.exe -usr [Full path of the script name.usr]