set_oauthhelper_dll(){ // Called by get_pJWTAssertion() interations: int retVal = 0; // used for return from oauth_load_privatekey(). // *** No need to change the rest of this file: lr_param_sprintf("pTimeExpire","%d",time(0)); // create initial seed where (now 10-digit) 1379510581 is for Sep. 18, 2013 at 7:24AM MT. lr_load_dll("oauthhelper.dll"); // Written by [email protected]. // TODO: 20. In Run-time Settings > Miscellaneous, set to run as "Process" rather than "Thread". // TODO: 21. Specify in vugen.dat file in "C:\Program Files (x86)\HP\LoadRunner\dat" to load DLL globally for use by all Vuser scripts. // file mdrv.dat // [HTTP] section // WINNT_DLLS=kernel32.dll,vtclient.dll,user32.dll // TODO: 22. If loading from the script’s directory, specify the DLL is listed in the Controller’s Design View -> Details -> More -> Files. // If errors are only from Controller, copy the DLL to the same directory on all Load Generator machines. // Using values obtained from Google APIs Console for Project X Client ID associated with {GoogleAPIServiceEmail}: retVal = oauth_load_privatekey(lr_eval_string("{pServicePrivateKeyFile}"),"notasecret"); // Done only once. if( retVal != 0 ){ if( retVal == -1 ){ lr_error_message(">> oauth_load_privatekey Failed to open p12 file, file not found, path incorrect."); }else if( retVal == -2 ){ lr_error_message(">> oauth_load_privatekey Error reading the PKCS#12 file, file permissions."); }else if( retVal == -3 ){ lr_error_message(">> oauth_load_privatekey Error parsing the PKCS#12 file, invalid certificate or invalid password."); }else if( retVal == -4 ){ lr_error_message(">> oauth_load_privatekey Key not set."); }else{ lr_error_message(">> oauth_load_privatekey retVal=%d.",retVal); } } return retVal; } // set_oauthhelper_dll()
/** * Gets the process ID of the mmdrv.exe process that is running the VuGen script that called * this function. * * @return This function returns the process ID of the calling process. * * Example code: * // Print the vuser's process ID * int vuser_pid; vuser_pid = wi_get_vuser_pid(); * lr_output_message("vuser_pid: %d", vuser_pid); * * Note: This function only works on Windows. * From lr-libc. */ int wi_get_vuser_pid() { int rc=LR_PASS; // return code int pid=0; // the process id (usually 4 digits) static int is_msvcrt_dll_loaded = FALSE; // A static variable inside a function keeps its value between // invocations. The FALSE value is assigned only on the first // invocation. char* dll_name = "MSVCRT.DLL"; // This DLL contains the _getpid() function. It is a standard // Windows DLL, usually found in C:\WINDOWS\system32. // Note: on Windows platforms, if you do not specify a path, // lr_load_dll searches for the DLL using the standard sequence // used by the C++ function, LoadLibrary. // Only load the DLL the first time this function is called: if (is_msvcrt_dll_loaded == FALSE) { rc = lr_load_dll(dll_name); if (rc != 0) { lr_error_message("Error loading %s.", dll_name); lr_abort(); } is_msvcrt_dll_loaded = TRUE; } pid = _getpid(); return pid; } // wi_get_vuser_pid
wi_load_kernel32_dll(){ int rc=LR_PASS; static int is_kernel32_dll_loaded = FALSE; // A static C variable inside a function retains its value between invocations. // The FALSE value is assigned only on the first invocation. #ifdef USING_WINDOWS char* dll_name = "KERNEL32.DLL"; // In C:/Windows/System32 that comes with Windows. // Its File Description: "Windows NT BASE API Client DLL". if (is_kernel32_dll_loaded == FALSE) { rc = lr_load_dll(dll_name); if (rc == 0) { is_kernel32_dll_loaded = TRUE; }else{ is_kernel32_dll_loaded = FALSE; lr_error_message(">> Error loading %s.", dll_name); // lr_abort(); } } #endif // USING_WINDOWS return rc; }
/** * Gets the process ID of the mmdrv.exe process running the VuGen script calling this function. * * @return This function returns the process ID of the calling process. * * Example code: * // Print the vuser's process ID * int vuser_pid; vuser_pid = wi_get_vuser_pid(); * lr_output_message("vuser_pid: %d", vuser_pid); * * Note: This function only works on Windows. * From lr-libc. */ int wi_get_vuser_pid() { int rc=LR_PASS; // return code int pid=0; // the process id (usually 4 digits) static int is_msvcrt_dll_loaded = FALSE; // A static variable inside a function keeps its value between // invocations. The FALSE value is assigned only on the first // invocation. char* dll_name = "MSVCRT.DLL"; // This DLL contains the _getpid() function. It is a standard // Windows DLL, usually found in C:\WINDOWS\system32. // On Windows platforms, if a path is not specified, // lr_load_dll searches for the DLL using the standard sequence. #ifdef USING_WINDOWS // Only load the DLL the first time this function is called: if (is_msvcrt_dll_loaded == FALSE) { rc = lr_load_dll(dll_name); if (rc == 0) { is_msvcrt_dll_loaded = TRUE; pid = _getpid(); }else{ is_msvcrt_dll_loaded = FALSE; lr_error_message(">> Error loading %s to get WIN32 pid in wi_get_vuser_pid.", dll_name); // lr_abort(); } } #endif // USING_WINDOWS return pid; } // wi_get_vuser_pid
Action() { char chQuery[128]; MYSQL *Mconn; lr_load_dll("libmysql.dll"); Mconn = lr_mysql_connect(MYSQLSERVER, MYSQLUSERNAME, MYSQLPASSWORD, MYSQLDB, atoi(MYSQLPORT)); lr_save_string(lr_eval_string("{pTransactionName}"),"sTransactionName"); lr_save_string(lr_eval_string("{pResult}"),"sResult"); lr_save_string(lr_eval_string("{pRandom}"),"sResponseTime"); lr_save_datetime("%H:%M:%S", TIME_NOW, "sTime"); sprintf(chQuery, "insert into test.sample_writes (sqTransactionName, sqResult, sqResponseTime, sqTime) values ('%s','%s','%s','%s');", lr_eval_string("{sTransactionName}"), lr_eval_string("{sResult}"), lr_eval_string("{sResponseTime}"), lr_eval_string("{sTime}")); lr_mysql_query(Mconn, chQuery); lr_mysql_disconnect(Mconn); return 0; }
MySQLTemplate() { int rc = 0; MYSQL *db_connection; MYSQL_RES *query_result; MYSQL_ROW result_row; char *server = "localhost"; char *user = "******"; char *password = "******"; char *database = "LRDB"; int port = 3306; // default MySQL port //static char *server_options[] = { "mysql_test", "--defaults-file=my.cnf" }; //int num_elements = sizeof(server_options)/ sizeof(char *); lr_whoami(&vuser_id, &vuser_group, &scid); lr_message( "Group: %s, vuser id: %d, scenario id %d", vuser_group, vuser_id, scid); if (vuser_id == -1) { vuser_id = 1; } rc = lr_load_dll("C:\\Program Files\\MySQL\\MySQL Server 5.0\\lib\\opt\\libmysql.dll"); // You should be able to find the MySQL DLL somewhere in your MySQL install directory. if (rc != 0) { lr_error_message("Could not load libmysql.dll"); lr_abort(); } // Allocate and initialise a new MySQL object db_connection = mysql_init(NULL); if (db_connection == NULL) { lr_error_message("Insufficient memory"); return -1; } // Connect to the database if (mysql_real_connect(db_connection, server, user, password, database, port, NULL, 0) == NULL) { lr_error_message("error on connect: %s\n", mysql_error(db_connection)); return -1; } if (mysql_query(db_connection, "SELECT * FROM LATLogin;")!= 0) { lr_error_message("error on query: %s\n", mysql_error(db_connection)); return -1; } if ((query_result = mysql_store_result(db_connection)) == NULL) { lr_error_message("error on store: %s\n", mysql_error(db_connection)); return -1; } while (result_row = mysql_fetch_row(query_result)) { lr_output_message("%s - %s", result_row[0]); } mysql_free_result(query_result); // Free the MySQL object created by mysql_init mysql_close(db_connection); mysql_server_end(); return 0; }