Exemple #1
0
Action()
{
    GetSourceDataRegister();
    
    if( strcmp( lr_eval_string("{first_name}"), "") != 0)
	{
    // {first_name} is not null
     lr_output_message("%s %s Registered as a new customer", 
                      lr_eval_string("{first_name}"),
                      lr_eval_string("{last_name}"));
    
    lr_think_time(5);
    
    OutputUsedDataRegister();
    lr_output_message("New Customer %s %s is now awaiting approval", 
                      lr_eval_string("{first_name}"),
                      lr_eval_string("{last_name}"));
    
    lr_think_time(5);
	}
    
else
	{
    // {first_name} is null, wait for more data
    lr_output_message("No data for user login...waiting for 50 seconds.");
    lr_think_time(50);
    	
    lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_PASS);
	}   


    
    return 0;
}
Exemple #2
0
int set_gen_QR_attribute(){

	   LPCSTR_SaveImageYN = lr_get_attrib_string("SaveImageYN"); // from run-time settings or command line.
 	if(LPCSTR_SaveImageYN==NULL){
	   LPCSTR_SaveImageYN=SaveImageYN_default; // ="N"; as N=No default.
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"SaveImageYN\" not specified. QR image files NOT generated from short URLs by default. [in vuser_init]"
					,LPCSTR_SaveImageYN 
					);
			wi_stopPrinting();
	}else{
		if( stricmp("Y",LPCSTR_SaveImageYN ) == FOUND ){ // Run-time Attribute "SaveImageYN" or command line option "-SaveImageYN"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"SaveImageYN\"=%s. QR image files generated from short URLs. [in vuser_init]"
					,LPCSTR_SaveImageYN 
					);
			wi_stopPrinting();
		}else{
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"SaveImageYN\"=%s. QR image files NOT generated from short URLs. [in vuser_init]"
					,LPCSTR_SaveImageYN 
					);
			wi_stopPrinting();
		}
	}
	
	return LR_PASS;
} // set_gen_QR_attribute()
	int WriteToFile(char *cDOSPath, char * cDOS)
	{
    //Save Epoch time to an array
	web_save_timestamp_param("sEpochMilliseconds", LAST);
    strcpy(cEpochTime, lr_eval_string("{sEpochMilliseconds}"));

	//Save the unique filename in the format C:\temp\x_yyyyyyyyyyyyy.txt where x is vUserID and yyyyyyyyyyyyy is Current EpochTime
    lr_save_string("C:\\temp\\", "FilePath");
	lr_save_string(".txt", "FileType");
	strcpy(file_path, lr_eval_string("{FilePath}"));
	strcat(file_path, lr_eval_string("{pVuser}"));
	strcat(file_path, "_");
	strcat(file_path, cEpochTime);
	strcat(file_path, lr_eval_string("{FileType}"));

//	Uncomment the following line for debugging - output current filepath
//	lr_output_message("File Path - %s", file_path);

	//This is the command thich will write data to the external file.
	//It starts by writing the DOS command into a string called "command"
	sprintf(cCommand, "%s%s > %s", cDOSPath, cDOS ,file_path); 

	lr_output_message("cCommand - %s", cCommand);
	lr_output_message("cDOS - %s", cDOS);
	lr_output_message("file_path - %s", file_path);


//	Uncomment the following line for debugging - output current command
	lr_output_message("command - %s", cCommand);

	//Execute the DOS command "command"
    system(cCommand); 
	}
Action()
{
	//Example of a loop using a FOR loop
	for (i=1;i<=10;i++)
		{
		lr_output_message( "FOR Loop number %d", i);
		} 


	//Equivalent example but using a WHILE loop
	//This can be made more complicated by including other conditions e.g. && 
	i=1;
	while ((i <= 10) && (whileloop ==1)) 
		{
		lr_output_message( "WHILE Loop number %d", i);
		i++;
		}


	//Equivalent example but using a WHILE loop
	//This can also be made more complicated by including other conditions e.g. && 
	i=1;
	do {
        lr_output_message( "DO WHILE Loop number %d", i);
		i++;
		} 
	while (i <= 10) ;


return 0; 
}
SplitStringCalculations()
{
	int iValue;
	char cBuffer[1024]="";
	char cConcatenatedOutput[1024]="";
	
	web_save_timestamp_param("sLoadRunnerTimeStamp", LAST);
	lr_output_message( "Current UNIX time in milliseconds is #%s", lr_eval_string( "{sLoadRunnerTimeStamp}" ) ); 

	//Splits the saved string {sLoadRunnerTimeStamp} into two parts, first 7 and remainder
	//fSplitString function is declared in  vuser_init
	fSplitString(lr_eval_string("{sLoadRunnerTimeStamp}"),7);
	
   	//Convert {sRightString} to integer iValue to perform calculation
   	//In this case subtract 1000 milliseconds to get timestamp from one second ago
	iValue = atoi(lr_eval_string("{sRightString}"));
	iValue = iValue-1000;
	sprintf(cBuffer, "%d", iValue);
	
	//Save Right part of the string
	lr_save_string(cBuffer, "sCalculatedRightString");
	
	//Copy {sLeftString} into cConcatenatedOutput, then concatenate (append) {sCalculatedRightString} 
	strcpy(cConcatenatedOutput, lr_eval_string("{sLeftString}"));
	strcat(cConcatenatedOutput, lr_eval_string("{sCalculatedRightString}"));
	
	lr_output_message("Epoch time minus 1000 milliseconds is:[%s]",cConcatenatedOutput);
	
	return 0;
}
Exemple #6
0
void fCaptureScreen (char* sTitleLeftBound, char* sTitleRightBound){
	char * sLB;
	char * sRB;

	if((sLB = (char *)malloc((strlen(sTitleLeftBound) + strlen("LB/IC=") + 2)* sizeof(char))) == NULL){
		lr_error_message("Out of memory error");
		lr_exit(LR_EXIT_VUSER,LR_FAIL);
	}else{
		sprintf(sLB,"LB/IC=%s", sTitleLeftBound);
		lr_output_message("TIVMsg: LB:%s", sLB);

	}

	if((sRB = (char *)malloc((strlen(sTitleRightBound) + strlen("RB/IC=") + 2)* sizeof(char))) == NULL){
		lr_error_message("Out of memory error");
		lr_exit(LR_EXIT_VUSER,LR_FAIL);
	}else{
		sprintf(sRB,"RB/IC=%s", sTitleRightBound);
		lr_output_message("TIVMsg: RB:%s", sRB);
	}

	web_reg_save_param("cPageTitle",
		sLB,
		sRB,
		"Notfound=warning",
	LAST);

	free (sLB);
	free (sRB);
}
//**************************************************
// created by Mark Sibley
// modified by Richard Bishop
// Saves left and right parts of a string into two separate strings
// Similar to Excel LEFT() and RIGHT() functions
//--------------------------------------------------
int SplitString(char * StringToSplit, int iLeftSplit)
{
   int iSLenA, iSLenB, iLoopLen;
   int iLooper = 0;
   char sStringB[200], sFullString[200], sParam[2000], n, sCharacter[200];

   //--------------------------------------------------
   // This saves the left hand x characters of the account number string
    strncpy(sStringB, StringToSplit, iLeftSplit);
   lr_save_string(lr_eval_string(sStringB),"sLeftString");
   //--------------------------------------------------
   // this calculates the string lengths
   iSLenA = strlen(lr_eval_string(StringToSplit));
   iSLenB = strlen(lr_eval_string("{sLeftString}"));
   iLoopLen = iSLenA - iSLenB;
   //--------------------------------------------------
   // this saves the right hand characters of the account string
   sprintf(sParam,"%s",lr_eval_string(StringToSplit));
   for (iLooper = iSLenB; iLooper < iSLenA; iLooper++)
   {
      sscanf(sParam+iLooper, "%c", &n);
      sprintf(sCharacter,"%c",n);
      strcat(sFullString, sCharacter);
   }
   lr_save_string(lr_eval_string(sFullString),"sRightString");
   //--------------------------------------------------
   // used when debugging this function
   
   lr_output_message("Original string:[%s]",lr_eval_string(StringToSplit));
   lr_output_message("Left hand split:[%s]",lr_eval_string("{sLeftString}"));
   lr_output_message("Right hand split:[%s]",lr_eval_string("{sRightString}"));
      
   //--------------------------------------------------
}
Exemple #8
0
get_google_access_token(){
		int rc=LR_PASS;
	char sOut[256]; // used by wi_EncodePlainToURL()

	rc=get_pJWTAssertion(); // into parameter pJWTAssertion used by this function.
	if( rc != LR_PASS ){ return rc; } // No input data to process.

		if( stricmp("Token",LPCSTR_RunType ) == FOUND ){ // "Token" or "TOKEN" specified in Run-time Attribute "RunType" or command line option "-RunType".
			wi_startPrintingTrace();
		    lr_output_message(">> RunType=\"%s\". JWT=%s."
					,LPCSTR_RunType 
					,lr_eval_string("{pJWTAssertion}")
					);
			wi_stopPrinting();
			return LR_PASS;
		}

	    web_add_header("Content-Type","application/x-www-form-urlencoded");
	    web_add_header("X-Frame-Options","deny"); // to protect against drag'n drop clickjacking attacks in older browsers.
	    web_reg_save_param_ex("ParamName=pAccessToken","LB=\"access_token\" : \"","RB=\"",SEARCH_FILTERS,"Scope=body",LAST);

	    // Example: "Body=grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion={pJWTAssertion}",
	    wi_EncodePlainToOAuth("grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=",sOut );
	    lr_save_string(sOut,"pJWTAssertion_request");
			wi_startPrintingTrace();
		    lr_output_message(">> sOut=\"%s\"."
					,lr_eval_string("{pJWTAssertion_request}")
					);
			wi_stopPrinting();
				
		// TODO: 15. If you want to, change the transaction name suffix for access authorization requests.
		sprintf( 	   tempString1, "%s_1access", lr_eval_string("{pTransSequence}") );
		lr_save_string(tempString1,"pTransName");
	    wi_start_transaction();
	    // web_rest("Token",
	    web_custom_request("Token",
                       "URL=https://accounts.google.com/o/oauth2/token",
                       "Method=POST",
                       //"ResType=JSON",
                       "Body={pJWTAssertion_request}{pJWTAssertion}",
                       LAST);
                       // The %3A are urlencoded from colons. (but %2D for the dash causes an "Invalid request" response):
                       // "Body=grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion={pJWTAssertion}",
                       // 		Common name for "jwt-bearer" is JWT Bearer Token Grant Type Profile for OAuth 2.0
                       // 		Defined at http://tools.ietf.org/html/draft-ietf-oauth-jwt-bearer-04
	    rc = wi_end_transaction();
	    // "Error -27796: Could not resolve address of hot accounts.google.com" is issued if there in no internet connection.
	    // Google API does not issue "error_description" such as "Audience validation failed".

		/* The response should look something like:
		{
  			"access_token" : "1/_5pUwJZs9a545HSeXXXXXuNGITp1XtHhZXXxxyyaacqkbc",
			"token_type" : "Bearer",
			"expires_in" : 3600
		}
		*/
		
    return rc;
} // get_google_access_token()
Exemple #9
0
int vi_set_VTS3(){

	int rc=LR_PASS;
	
	// Using VTS3 (Virtual Table Service version 3) available since LR 11.52+:
	// See blog by its developer at http://h30499.www3.hp.com/t5/HP-LoadRunner-and-Performance/The-New-Virtual-Table-Server-VTS-in-LoadRunner-11-52/ba-p/6069435#.Ukt79rHnb4Y
	// HP Support article at http://support.openview.hp.com/selfsolve/document/KM305130

       LPCSTR_VTS_Host = lr_get_attrib_string("VTS_Host"); // from Run-time settings Attributes or command line.
 	if(LPCSTR_VTS_Host==NULL){                 // Not specified in Run-Time Settings Attributes or command line.
 	          VTS_Host_string="localhost"; // VTS_Host_default; // such as "localhost"; 

			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"VTS_Host\" not specified in command-line or run-time settings. Default to \"%s\"."
					,VTS_Host_string
					);
			wi_stopPrinting();
    }else{
		sprintf( VTS_Host_string ,"%s",LPCSTR_VTS_Host);
	} // if(LPCSTR_VTS_Host==NULL)
       

       LPCSTR_VTS_Port = lr_get_attrib_string("VTS_Port"); // from Run-time settings Attributes or command line.
 	if(LPCSTR_VTS_Port==NULL){             // Not specified in Run-Time Settings Attributes or command line.
 	             nPort=8787; // nVTS_Port_default; // such as 8787 or 8888;
		    wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"VTS_Port\" not specified in command-line or run-time settings. Default to \"%d\"."
					,nPort 
					);
			wi_stopPrinting();
    }else{
     	nPort = atoi(LPCSTR_VTS_Port); 
	} // if(LPCSTR_VTS_Port==NULL)

    /// Connect using LoadRunner native functions:
 		pvci = vtc_connect( VTS_Host_string , nPort , VTOPT_KEEP_ALIVE ); // VTS_Host_string
	if( pvci <= 0){
	    wi_startPrintingDebug();
		lr_error_message(">> VTS pvci=%d (non-zero).", pvci);
		wi_stopPrinting();
	}else{
		rc = vtc_get_last_error(pvci);
		if( rc != LR_PASS ) {
		    wi_startPrintingDebug();
			lr_error_message(">> rc from vtc_get_last_error(pvci)=%d for VTC connection to %s port .", rc, VTS_Host_string,nPort);
			wi_stopPrinting();
			return LR_FAIL; // FAIL
		}

		// Count rows in VTS table:
		vtc_column_size(pvci, "web", &nVTS_row_count);
		wi_startPrintingInfo();
		lr_output_message(">> nVTS_row_count=%d.", nVTS_row_count);
		wi_stopPrinting();
	}

	return rc;
} // vi_set_VTS3()
Exemple #10
0
void OnMessageCB0 (const char* connectionID,
				  int isbinary,
				  const char * data,
				  int length)
{

int isupdate;

	
//		if (isbinary) {
//			lr_output_message("WebSocket ID = %s. [%d] bytes binary message received.", connectionID, length);
//		}
//		else {
//			lr_output_message("WebSocket ID = %s. [%d] bytes text message received.", connectionID, length);
//			lr_output_message("\r\n===\r\n%s\r\n===", data);
//		}

	OnMessageCB0_entries = OnMessageCB0_entries + 1;

// The first response after connect downloads JavaScript:  function setPhase,  c,d,z,n,r,p, error(cod, ph, tbl, msg), start, end, loop, retry, bw, convert.

   isupdate = strncmp(data,"d(",2); // as in data=d(1,8,1,'5.57','00:45:50','4.89','19500','5.57','5.58','25000',4);
if(isupdate != 0) {
   		// Display what is NOT handled as a message:
		lr_output_message(">> Among %d entries, OnMessageCB0_updates=%d with data=%s [at OnMessageCB0]"
		                  , OnMessageCB0_entries, OnMessageCB0_updates, data);
   }else{
	// message= z(1,10,'ELE Manufacturing','7.37','00:45:47','-3.15','49500','7.37','7.38','18000','5.97','9.11','7.61','7.7');
	//		    z(1,2,'Ations Europe','14.91','00:45:47','-7.33','47500','14.91','14.93','35000','12.62','19.43','16.09','16.2');
	
	    OnMessageCB0_updates = OnMessageCB0_updates + 1;
	if( OnMessageCB0_updates == 1 ){
		lr_set_transaction("T04_first_CB0_update", dTime_elapsed, LR_PASS); // Create successful transaction with a duration of seconds.
		lr_output_message(">> Among %d entries, OnMessageCB0_updates=%d with data=%s [at OnMessageCB0]"
		                  , OnMessageCB0_entries, OnMessageCB0_updates, data);
	}

	lr_save_param_regexp (
        			data,
        			length,
					myvalue_regexp,	
					"Ordinal=All",					
        			"ResultParam=myValue",
        			LAST );	
			
	if (atoi(lr_eval_string("{myValue_count}"))>0) {
		lr_message(">> [%s]: '%s'= [%s]$"
	    	           ,lr_eval_string("{ts}")
	    	           ,lr_eval_string("{COMPANY}")
	    	           ,lr_eval_string("{myValue_1}")
	    	          );
		lr_user_data_point(lr_eval_string("{COMPANY} stock value")
	    	           ,atof(lr_eval_string("{myValue_1}"))
	    	           );
	}
}
	
}
Exemple #11
0
vuser_init()
{
    lrs_startup(257);	
    lrs_create_socket("socket0","UDP","RemoteHost=ad3.norouter.cn:1500",LrsLastArg);



	lr_whoami(&id, &vuser_group, &scid);
	
	srand(id+time(NULL)); 
	rand_mac(randmac);
	rand_ip(randip);
	lr_output_message("randip=%s",randip);
	lr_output_message("rand_mac=%s",randmac);
	lr_save_string(randmac,"mac");
	lr_save_string(randip,"ip");
  
    lrs_send("socket0", "buf0", LrsLastArg);
    lrs_receive("socket0", "buf1", LrsLastArg);
    ids = lrs_get_received_buffer("socket0",18,18,NULL);
	buffer_convert_to_hex_string(ids,18,buf);
	lr_output_message("ids=%s",buf);
    lrs_get_buffer_by_name("buf2",&data,&size);
	memcpy(dev_id,ids,8);
	memcpy(id_rand,ids+8,10);
	memcpy(data+18,dev_id,8);
	buffer_convert_to_hex_string(data,36,buf);
	//lr_output_message("buf=%s",buf);
    lrs_set_receive_option(Mismatch,MISMATCH_CONTENT);
    lrs_set_send_buffer("socket0",buf,strlen(buf));
	lrs_send("socket0", "buf2", LrsLastArg);
    lrs_receive("socket0","buf3",LrsLastArg);
	lrs_set_receive_option(Mismatch,MISMATCH_SIZE);
	lrs_get_buffer_by_name("buf4",&data,&size);
	memcpy(data+18,dev_id,8);
	buffer_convert_to_hex_string(data,44,buf);
	lrs_set_send_buffer("socket0",buf,strlen(buf));
	lrs_send("socket0", "buf4", LrsLastArg);
	lrs_receive("socket0","buf5",LrsLastArg);
	p = lrs_get_received_buffer("socket0",18,16,NULL);
	memcpy(ran,p,16);
    oemMD5Init(&context);
    oemMD5Update(&context,(unsigned char*)id_rand,10);
    oemMD5Update(&context,(unsigned char*)ran,16);
    oemMD5Final((unsigned char*)digest,&context);
	lrs_get_buffer_by_name("buf6",&data,&size);
	memcpy(data+18,dev_id,8);
	memcpy(data+30,digest,16);
	buffer_convert_to_hex_string(data,131,buf);
	lrs_set_receive_option(Mismatch,MISMATCH_CONTENT);
	lrs_set_send_buffer("socket0",buf,strlen(buf));
	lrs_send("socket0", "buf6", LrsLastArg);
	lrs_receive("socket0","buf7",LrsLastArg);
	lrs_set_receive_option(Mismatch,MISMATCH_SIZE);
    return 0;
}
Exemple #12
0
Action()
{


	lr_output_message("Hola");

	lr_output_message("2 Hola");
	
	return 0;
}
Exemple #13
0
/*! \brief Detect excessive disk usage by the test and turn all further logging off if more than a specific limit number of mebibytes has been used.

When called, this function will check the amount of space used on the generator's "output" device / directory since the first call to this function.
If the amount of used space exceeds the treshold it will generate an error transaction "---DISK SPACE LOW IN LOG FOLDER FOR {y_hostname_generator}---" and turn all further logging off until the end of the test, using y_log_turn_off_permanently().

\note Scripts that call lr_debug_message() or the various y_lib() toggle functions to turn the loglevel back up may ignore this restriction.

Loadrunner does not protect the generators' disks from overflowing, even if the test is writing out a lot of information to the logs really quickly.
If a disk fills up on the generator or the disk the controller uses for results collation overflows there is no graceful recovery. Collation will fail and test results may be hard or impossible to recover.
This kind of situation can occur when temporary service disruptions happen (triggering a flood of 'log on error' messages), but also if runtime settings are incorrect and the test was configured to log *everything*.

\note Because of the way this measurement is done, it may also trigger if some other process on the same machine starts writing large amounts of data to the same device.

In order to prevent this from happening scripts should regularly call to both y_disk_space_guard() and y_disk_space_usage_guard() with some reasonable limits.

\note The contents of the generator's output folder will be transferred to the controller during collation. If the sum of the output directories for the generators exceed the size of that filesystem collation will fail, even if there is enough space on the generators. Therefore, set this low enough to make sure that if all generators output folders get filled to the limit the controller will still have enough space for it's collation process.

\param [in] limit_mebibytes_used The amount of mebibytes the test is allowed to used on the generator's target directory. 

\author Floris Kraak
*/
void y_disk_space_usage_guard(double limit_mebibytes_used)
{
    char* hostname;
    char* log_folder = lr_get_attrib_string("out");
    double free_mebibytes;
    static double max_free_mebibytes = -1;
    double mebibytes_used;
    static int disk_space_warning_given = 0;

    // check already fired once before.
    if( disk_space_warning_given )
    {
        // guard against accidental re-enablement of the logs by turning them off explicitly.
        y_log_turn_off_permanently();
        return;
    }

    free_mebibytes = y_get_free_disk_space_in_mebibytes(log_folder);
    lr_log_message("y_disk_space_usage_guard: current free: %f MB, max free: %f MB, limit: %f MB used in folder: %s",
                   free_mebibytes, max_free_mebibytes, limit_mebibytes_used, log_folder);

    if(max_free_mebibytes < 0)
    {
        lr_log_message("Storing free space as detected maximum");
        max_free_mebibytes = free_mebibytes;
        return;
    }
    else if(max_free_mebibytes < free_mebibytes)
    {
        lr_output_message("Warning: Free disk space increased from %f to %f, test disk space usage measurements may have become unreliable.", max_free_mebibytes, free_mebibytes);
        max_free_mebibytes = free_mebibytes;
        return;
    }

    // Ok, so we used *something*. Now let's see if it exceeds our limit.
    mebibytes_used = max_free_mebibytes - free_mebibytes;

    // data points
    hostname = lr_get_host_name();
    lr_save_string(hostname, "y_hostname_generator");
    lr_user_data_point( lr_eval_string("disk_space_{y_hostname_generator}_free_mebibytes"), free_mebibytes);
    lr_user_data_point( lr_eval_string("disk_space_{y_hostname_generator}_used_mebibytes"), mebibytes_used);

    if( mebibytes_used >= limit_mebibytes_used ) 
    {
        y_setup();
        lr_set_transaction(lr_eval_string("---DISKSPACE USAGE TOO HIGH IN LOG FOLDER FOR {y_hostname_generator}---"), 0, LR_FAIL);
        lr_output_message("Disk space used on host %s in folder %s was %f mebibytes, reaching the limit of %f. Logging turned off for user id %d for the remainder of the test!",
                           hostname, log_folder, mebibytes_used, limit_mebibytes_used, y_virtual_user_id);
        disk_space_warning_given = 1; // turn off further warnings.
        y_log_turn_off_permanently();
    }
}
//*******************************************************
Action()
{
 lr_save_string("ABC123456","Param");
 Reverse(lr_eval_string("{Param}"),"NewParam");
 lr_output_message(lr_eval_string("Changed [{Param}] to [{NewParam}]"));

 lr_save_string("Peter Piper","Param");
 Reverse(lr_eval_string("{Param}"),"NewParam");
 lr_output_message(lr_eval_string("Changed [{Param}] to [{NewParam}]"));

 lr_save_string("Fiddlesticks","Param");
 Reverse(lr_eval_string("{Param}"),"NewParam");
 lr_output_message(lr_eval_string("Changed [{Param}] to [{NewParam}]"));
 return 0;
}
GenerateSSNs()
{
	SSNGenerator("EmployeeSpouseSSN");
	
		lr_output_message(lr_eval_string("{EmployeeSpouseSSN}"));
	
	SSNGenerator("EmployeeChildOneSSN");
	
		lr_output_message(lr_eval_string("{EmployeeChildOneSSN}"));
		
	SSNGenerator("EmployeeChildTwoSSN");
	
		lr_output_message(lr_eval_string("{EmployeeChildTwoSSN}"));	
	return 0;
}
Exemple #16
0
update_shorturl_in_VTS(){
	// Store the shorturl generated into the VTS table so the same value is not generated again.
	
	int rc=LR_PASS;
	
	if( iUpdate_shorturl_in_VTS == 1 ){
		// Operating on the current VTS index:
		rc = vtc_send_if_unique(pvci, "shorturl", lr_eval_string("{pShortURL}"), &status);

		wi_startPrintingTrace();
	    lr_output_message(">> update_shorturl_in_VTS rc=%d pShortURL=%s, rc=%d, status=%d (1=Pass, 0=Fail)."
		        ,nURLtoShorten_done 
				,lr_eval_string("{pShortURL}")
				,rc
				,status
				);
		wi_stopPrinting();
		if( status == 1 ){
			rc=LR_PASS;
		}else{
			rc=LR_FAIL;
		}
	}

    return rc;
} // update_shorturl_in_VTS()
GenerateSSNs()
{
    SSNGenerator("Assisted_SSN");

    lr_output_message(lr_eval_string("{Assisted_SSN}"));
    return 0;
}
Exemple #18
0
int wi_set_unique_id(){
	int rc=LR_PASS;
	char*			my_controller_name;
	char*			my_host; // host_name of load generator (injector):
	int 			iScenarioID;
	char* 			vuser_group;
	int 			iVuserID; // -1 if run in VuGen.
	char* 			sVuserID[32]; // from lr_get_vuser_ip()
//	char 			my_unique_id[64]=""; // defined as global variable.
	int              vuser_pid=0; // Windows Process ID
	
	my_controller_name = lr_get_master_host_name(); 
	my_host = lr_get_host_name();
	vuser_pid = wi_get_vuser_pid();

	lr_whoami(&iVuserID, &vuser_group, &iScenarioID); // lr_whoami returns void by design (no rc).

	// NOTE: When run in VuGen: Controller=None, host=%MACHINENAME%, ScenarioID=0, vuser_group=None, iVuserID=-1.
  	wi_startPrintingInfo();
	lr_output_message(">> Controller=%s, Host=%s, ScenarioID=%d, Group=%s, Vuser=%d, PID=%d." 
  	                  ,my_controller_name ,my_host ,iScenarioID, vuser_group ,iVuserID, vuser_pid );
	wi_stopPrinting();
	
	sprintf( global_unique_id,"C%s.H%d.S%s.G%s.U%d.P%d"
			,my_controller_name
			,my_host
			,iScenarioID
			,vuser_group
			,iVuserID
			,vuser_pid
			);

	return rc;
} // wi_set_unique_id
Exemple #19
0
lr_popen()
{
    long fp; // file/stream pointer
    int count; // number of characters that have been read from the stream.
    char buffer[BUFFER_SIZE]; // allocate memory for the output of the command.
 
    // "VER" outputs the version of Windows that is running.
    if (!(fp = popen("VER", "r"))) {
        lr_error_message("Error opening stream.");
        return -1;
    }
 
    count = fread(buffer, sizeof(char), BUFFER_SIZE, fp); // read up to 10KB
    if (feof(fp) == 0) {
        lr_error_message("Did not reach the end of the input stream when reading. Try increasing BUFFER_SIZE.");
        return -1;
    }
    if (ferror(fp)) {
        lr_error_message ("I/O error during read."); 
        return -1;
    } 
    buffer[count] = NULL;
 
    lr_output_message("The Windows version is: %s", buffer);
    pclose(fp);
    return 0;
}
Exemple #20
0
Action()
{
	int iDebug;
	
	web_cleanup_cookies( );
		
	lr_start_transaction("_TIVApp_001_My_Test");
	
	lr_save_string("TIVApp_001_001_Homepage", "pTransactionName");
	
	web_reg_find("Fail=NotFound",
		"Search=Body",
		"Text=Test site.",
		LAST);

	web_reg_save_param("cServerName",
	    "LB=Set-Cookie: ROUTEID=.",
	    "RB=;",
	    "Notfound=warning",
	    LAST);
	
	web_reg_save_param("cVersion",
	    "LB=version\">",
	    "RB=<",
	    "Notfound=warning",
	    LAST);
	
	lr_start_transaction(lr_eval_string("{pTransactionName}"));
	
	web_url("Homepage", 
		"URL=http://{pURL}/", 
		"Resource=0", 
		"RecContentType=text/html", 
		"Referer=", 
		"Snapshot=t1.inf", 
		"Mode=HTML", 
		LAST);
	// Log Levels:
	// LR_MSG_CLASS_DISABLE_LOG
	// LR_MSG_CLASS_BRIEF_LOG
	// LR_MSG_CLASS_EXTENDED_LOG
	// LR_MSG_CLASS_RESULT_DATA
	// LR_MSG_CLASS_PARAMETERS
	// LR_MSG_CLASS_FULL_TRACE
	iDebug = lr_get_debug_message();

	lr_output_message("TIVMsg: Msg Level was: %d", iDebug);
	
	lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG, LR_SWITCH_ON);
	
	lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_RESULT_DATA,"TIVMsg: %s loaded via server: %s", lr_eval_string("{pTransactionName}"), lr_eval_string("{cServerName}"));
	
	lr_set_debug_message(iDebug, LR_SWITCH_ON);
	
	lr_end_transaction(lr_eval_string("{pTransactionName}"), LR_AUTO);
	
	lr_end_transaction("_TIVApp_001_My_Test", LR_AUTO);
	
	return 0;
}
Action()
{
	lr_save_datetime("%y%j", DATE_NOW, "JulianDate"); 
	lr_output_message("Today's Julian Date is %s",lr_eval_string("{JulianDate}"));
	
	return 0;
}
Exemple #22
0
hex_dump(char* buf,int len)
{
	int i;
	for(i=0;i<len;i++)
	{
		lr_output_message("\\x%02X",(unsigned char)buf[i]);
	}
}
Exemple #23
0
int vi_set_Verbosity_attribute(){

	   LPCSTR_Verbosity = lr_get_attrib_string("Verbosity"); // from Run-time settings Attributes or command line.
	if(LPCSTR_Verbosity==NULL){                 // Not specified in Run-Time Settings Attributes or command line.
            iVerbosity=iVerbosity_default; // =default.
		    wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"Verbosity\" not specified in command-line or run-time settings. Default to \"%d\"."
					,iVerbosity
					);
			wi_stopPrinting();
		// NOTE: Don't return LR_FAIL; // fail here because default can be used.
	}else{
		iVerbosity=atoi(LPCSTR_Verbosity);
	} // if(LPCSTR_Verbosity==NULL)

	// TODO: 23. Set each web_set_max_html_param_len based on the largest individual server response detrermined from initial runs.	   
	if( iVerbosity == 1 ){
	    web_set_max_html_param_len("10240"); 
	}else
	if( iVerbosity == 2 ){
	    web_set_max_html_param_len("10240");
	}else
	if( iVerbosity == 3 ){
	    web_set_max_html_param_len("10240");
	}else
	if( iVerbosity == 4 ){
	    web_set_max_html_param_len("10240");
	}else
	if( iVerbosity == 5 ){
	    web_set_max_html_param_len("20240");
	}else{
	   	iVerbosity=iVerbosity_default; // =default.
		    wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"Verbosity\" not specified in command-line or run-time settings. Default to \"%d\"."
					,iVerbosity
					);
			wi_stopPrinting();

			wi_startPrintingError();
		    lr_output_message(">> Attribute \"Verbosity\" not recognized as valid value."
					,iVerbosity
					);
			wi_stopPrinting();
	}
	return LR_PASS;
} // vi_set_Verbosity_attribute()
Exemple #24
0
void OnCloseCB0 (const char* connectionID,
				  int isClosedByClient,
				  int code,
				  const char* reason,
				  int length)
{
	
		lr_output_message(">> WebSocket ID=%s closed. CloseCode= %d, CloseReason=%s  [at OnCloseCB0]"
	                  , connectionID, code, reason);
}
Exemple #25
0
Action()
{

	lr_start_transaction("kp");


	web_service_call( "StepName=electronInvoice_102",
		"SOAPMethod=ElectronInvoiceSer|ElectronInvoiceSerHttpPort|electronInvoice",
		"ResponseParam=response",
		"Service=ElectronInvoiceSer",
		"ExpectedResponse=SoapResult",
		"Snapshot=t1457769024.inf",
		"BEGIN_ARGUMENTS",
		"xml=<ElectronInvoiceInput><UNI_BSS_HEAD><ORIG_DOMAIN>PTIS</ORIG_DOMAIN><SERVICE_NAME>ElectronInvoiceSer</SERVICE_NAME><OPERATE_NAME>electronInvoice</OPERATE_NAME><ACTION_CODE>0</ACTION_CODE><ACTION_RELATION>0</ACTION_RELATION><ROUTING><ROUTE_TYPE>36</ROUTE_TYPE><ROUTE_VALUE>18674453342</ROUTE_VALUE></ROUTING><PROC_ID>seq00001</PROC_ID><TRANS_IDO>seq00001</TRANS_IDO><TRANS_IDH></TRANS_IDH><PROCESS_TIME>201603111704001</PROCESS_TIME><RESPONSE><RSP_TYPE></RSP_TYPE><RSP_CODE></RSP_CODE><RSP_DESC></RSP_DESC></RESPONSE><COM_BUS_INFO><OPER_ID>yanff</OPER_ID><PROVINCE_CODE>0002</PROVINCE_CODE><EPARCHY_CODE>地市代码表</EPARCHY_CODE><CITY_CODE>区县编码</CITY_CODE><CHANNEL_ID>渠道编码</CHANNEL_ID><ACCESS_TYPE>1</ACCESS_TYPE><ORDER_TYPE>1</ORDER_TYPE></COM_BUS_INFO><SP_RESERVE><TRANS_IDC>ECIP0002seq00001</TRANS_IDC><CUTOFFDAY>20080608</CUTOFFDAY><OSNDUNS>0002</OSNDUNS><HSNDUNS>1100</HSNDUNS><CONV_ID>ECIP0002seq00001200806081200111</CONV_ID></SP_RESERVE><TEST_FLAG>0</TEST_FLAG><MSG_SENDER>1100</MSG_SENDER><MSG_RECEIVER>1101</MSG_RECEIVER></UNI_BSS_HEAD><UNI_BSS_BODY><ELECTRON_INVOICE_REQ><INVOICE_REQ_ID>lyl{lsh}</INVOICE_REQ_ID><MAKE_INVOICE_TYPE>0</MAKE_INVOICE_TYPE><SELLER_TAXPAYER_ID>440300568519737</SELLER_TAXPAYER_ID><SELLER_NAME>电子发票测试</SELLER_NAME><SELLER_ADD>深圳市南山区南海大道1057号科技大厦二期A栋601房</SELLER_ADD><SELLER_PHONE>0755-26027907</SELLER_PHONE><SELLER_BANK_ACCOUNT>31001669701052502638</SELLER_BANK_ACCOUNT><BUYER_TAXPAYER_ID></BUYER_TAXPAYER_ID><BUYER_NAME>张三</BUYER_NAME><BUYER_ADD>深圳市南山区深南大道1057号科技大厦二期A栋6888房</BUYER_ADD><BUYER_BANK_ACCOUNT>98888888701052502638</BUYER_BANK_ACCOUNT><BUYER_PHONE>18888888888</BUYER_PHONE><BUYER_EMAIL>[email protected]</BUYER_EMAIL><WRITE_MANAGER>admin</WRITE_MANAGER><RECE_FEE_MANAGER>admin</RECE_FEE_MANAGER><CHECK_MANAGER>admin</CHECK_MANAGER><ORG_INVOICE_CODE></ORG_INVOICE_CODE><ORG_INVOICE_NUM></ORG_INVOICE_NUM><TOTAL_PRICE_TAX>117</TOTAL_PRICE_TAX><TOTAL_FEE>100</TOTAL_FEE><TOTAL_TAX_PAY>17</TOTAL_TAX_PAY><PROJECT_INFO><INVOICE_COMPANY_NATURE>0</INVOICE_COMPANY_NATURE><PROJECT_NAME>洗衣粉</PROJECT_NAME><UNIT>袋</UNIT><MODEL>500克</MODEL><PROJECT_COUNT>1</PROJECT_COUNT><PROJECT_UNIT_PRICE>100</PROJECT_UNIT_PRICE><PROJECT_FEE>100</PROJECT_FEE><TAX_RATE>0.17</TAX_RATE><TAX_PAY>17</TAX_PAY></PROJECT_INFO><PARA><PARA_ID>保留字段ID</PARA_ID><PARA_VALUE>保留字段值</PARA_VALUE></PARA></ELECTRON_INVOICE_REQ></UNI_BSS_BODY><UNI_BSS_ATTACHED><MEDIA_INFO></MEDIA_INFO></UNI_BSS_ATTACHED></ElectronInvoiceInput>",
		"END_ARGUMENTS",
		"BEGIN_RESULT",
		"out=Param_out",
		"END_RESULT",
		"LAST");

lr_save_string( lr_eval_string("{Param_out}"),"a" );
	lr_replace("a","&lt;","<" );
	lr_replace( "a","&gt;",">" );
	lr_output_message("result:%s", lr_eval_string("{a}"));
   	lr_xml_get_values("XML={a}","FastQuery=/ElectronInvoiceOutput/UNI_BSS_BODY/ELECTRON_INVOICE_RSP/RESP_CODE", "ValueParam=strXml","LAST");
    lr_output_message("result:%s", lr_eval_string("{strXml}"));

	if(atoi(lr_eval_string("{strXml}"))==0){
      lr_output_message("result:%s", "交易成功");
      
	lr_end_transaction("kp", 2);

	}
	else{
      lr_error_message("result:%s", "交易失败");
      
	lr_end_transaction("kp", 2);

	}
   
return 0;
}
Exemple #26
0
void fTestMe(char* sVar){
	char * sBuf;

	if((sBuf = (char *)malloc((strlen(sVar) + strlen(" was a bar fighter") + 2)* sizeof(char))) == NULL){
		lr_error_message("Out of memory error");
	}else{
		sprintf(sBuf,"%s was a bar fighter", sVar);
		lr_output_message(sBuf);
		
	}
	
	free(sBuf);
}
Action()
{
	//Sample code taken from Kim at - http://ptfrontline.wordpress.com/2010/01/27/lr_save_float-function-for-loadrunner/
	//Kim's comments....
	//LoadRunner has lr_save_int() and lr_save_string() but the float saving function is missing so I just quickly
	//whipped up the following code. It’s by no means perfect when it comes to checking for errors, but it will 
	//work >90% of the times (as long as the scripter knows what he/she is doing).. Enjoy
	
	lr_save_float(123.456, "myVar", 2);
	lr_output_message("%s",lr_eval_string("{myVar}"));  //Rounds floating point number to two decimal places
	
	return 0;
}
	int ReadFromFile()
	{
    //The rest of the script is responsible for reading in data from the external file created above and then deleting that file.
	//This IF statement checks that the file_path is valid and that the file can be opened.
	if ((file_stream = fopen(file_path, "r")) == NULL ) 
		{ 
        lr_error_message("Cannot open %s", file_path); 
        return -1; 
        } 

		//This IF statement returns the string which has been read into LoadRunner and saves it as "line"
		//Unless the End Of File is reached or if a reading error occurred. 
		if (fgets(cLine, 100, file_stream) == NULL) 
    		lr_output_message("fgets error"); 
	
		else 
		//Uncomment the following line for debugging - output contents of "cLine" array including trailing \n
        //lr_output_message( "Data from the external file is [%s]", cLine); 

		//This function writes the data from the external file without the trailing \n into a new array called cExtData 
		strncat ( cExtData, cLine, (strlen(cLine)-1) );
        lr_output_message( "Data from the external file is [%s]", cExtData); 

		//This IF statement returns an error if LoadRunner cannot close the external file.
		if (fclose(file_stream)) 
        lr_error_message("Error closing file %s", file_path); 

	//This is the command thich will delete the external temporary file
	//It starts by writing the DOS command into a string called "command"
	sprintf(cCommand, "del %s", file_path); 

//	Uncomment the following line for debugging - output current command
//	lr_output_message("command - %s", cCommand);

	//Execute the DOS command "cCommand"
	system(cCommand); 

	}
Exemple #29
0
int wi_set_Think_Time(){
	char strTemp[48]; double doubleTemp;
	LPCSTR			  LPCSTR_ThinkTimeSecs;
	float			   floatThinkTimeSecs_default = 10.5;
 	// For use by wi_start_transaction():
	static float	floatThinkTimeSecs; // numeric.
					
  		 LPCSTR_ThinkTimeSecs = lr_get_attrib_string("ThinkTimeSecs");
	if(  LPCSTR_ThinkTimeSecs==NULL){ // Not specified.
	  	   floatThinkTimeSecs=floatThinkTimeSecs_default; // Default unless changed for subsequent transactions.

  	    wi_startPrintingDebug();
		lr_output_message(">> floatThinkTimeSecs=%8.2f from coded default.", floatThinkTimeSecs);
		wi_stopPrinting();
	}else{ // use value from command attribute: // floats have 24 significant bits, double 52.
		// Not using strtof() per http://pubs.opengroup.org/onlinepubs/009695399/functions/strtod.html
	    floatThinkTimeSecs= atof(LPCSTR_ThinkTimeSecs); // atof() requires definition at top of file.

	    wi_startPrintingDebug();
		lr_output_message(">> Attribute floatThinkTimeSecs=%8.3f.", floatThinkTimeSecs );
		wi_stopPrinting();
	 } // For ftoa see http://www.performancecompetence.com/wordpress/?p=318
	return LR_PASS;
} // wi_set_Think_Time()
Exemple #30
0
vi_set_RunType_attribute(){

	LPCSTR_RunType = lr_get_attrib_string("RunType"); // from run-time settings Attributes or command line.
 	if(LPCSTR_RunType==NULL){ // Not specified in Run-Time Settings Attributes or command line.
	   LPCSTR_RunType="All"; // =default.
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"RunType\" not specified in command-line or run-time settings. Default to \"%s\"."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
	}else{ // Ensure only acceptable values were input:
		if( stricmp("All",LPCSTR_RunType ) == FOUND ){ // Run-time Attribute "RunType" or command line option "-RunType"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"RunType\"=%s."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
       	}else
		if( stricmp("NoOp",LPCSTR_RunType ) == FOUND ){ // Run-time Attribute "RunType" or command line option "-RunType"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"RunType\"=%s for no operation."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
		}else{
			wi_startPrintingError();
		    lr_output_message(">> Attribute \"RunType\"=%s not valid. lr_exit() stopping script execution."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
			lr_exit(LR_EXIT_VUSER,LR_FAIL);
		}
	} // if(LPCSTR_RunType==NULL)

	return LR_PASS;
} // vi_set_RunType_attribute()