Difference between revisions of "Custom LoadRunner Library Code"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (New page: =Source= C utilities for local customization of LoadRunner scripts. <pre> // // $Id:$ // //----------------------------------------------------------------------------------------------...) |
PeterHarding (talk | contribs) m (LR Lib Utils.c moved to Custom LoadRunner Library Code) |
(No difference)
|
Revision as of 16:24, 26 June 2008
Source
C utilities for local customization of LoadRunner scripts.
// // $Id:$ // //------------------------------------------------------------------------------------------------- #include "web_api.h" #include "lrw_custom_body.h" #include "lib.h" //------------------------------------------------------------------------------------------------- typedef long time_t; //------------------------------------------------------------------------------------------------- static time_t save; //------------------------------------------------------------------------------------------------- char msgbuf[4096000]; char tmpbuf[102400]; long lfp = NULL; char *logfile = "_run.log"; //------------------------------------------------------------------------------------------------- long refTime(int flg) { long t; time(&t); if (flg) { save = t; t = 0; } else { t = t - save; } return t; } // refTime //------------------------------------------------------------------------------------------------- double theTime(void) { double t; t = refTime(0) * 1.0; return t; } // theTime //------------------------------------------------------------------------------------------------- void initLog(char *project, char *script, char* sgroup, int vuser_id) { char logfile[128]; time_t t; double now; refTime(1); time(&t); if (vuser_id != -1) { sprintf(logfile, "C:\\lr\\%s\\log\\%s__%03d__%s.log", project, sgroup, vuser_id, script); } else { sprintf(logfile, "_run.log", vuser_id); } if ((lfp = fopen(logfile, "a")) == NULL ) { lr_error_message("Cannot open %s", logfile); lr_abort(); exit(1); } sprintf(msgbuf, "Timestamp (%d) - %s", t, ctime(&t) ); fprintf(lfp, "------ %s------ =================================================\n", msgbuf); fprintf(lfp, "------ Script: %s Scenario Group: %s\n", script, sgroup); fflush(lfp); lr_output_message("=====> %s", msgbuf); } // initLog //------------------------------------------------------------------------------------------------- void closeLog(void) { time_t t; time(&t); sprintf(msgbuf, "Timestamp (%d) - %s", t, ctime(&t) ); fprintf(lfp, "------ Close() @ %s------ =================================================\n", msgbuf); fflush(lfp); close(lfp); lr_output_message("=====> %s", msgbuf); } // initLog //------------------------------------------------------------------------------------------------- void userLog(char *msg) { double now; now = theTime(); if (lfp != 0) { fprintf(lfp, "%06.1f %s\n", now, msg); fflush(lfp); } lr_output_message("=====> %s", msg); } // userLog //------------------------------------------------------------------------------------------------- char * upper(char* s) { int i; static char buf[128]; int l = strlen(s); if (l >= 127) { userLog("upper() overflow!"); lr_abort(); } for (i = 0; i < l; i++) { buf[i] = toupper(s[i]); } buf[l] = '\0'; return buf; } // upper //------------------------------------------------------------------------------------------------- int day_of_week(char *day) { char *uc_day = upper(day); int l = strlen(day); int rc = 0; if (!strncmp(day, "SUNDAY", l)) { rc = 1; } else if (!strncmp(uc_day, "MONDAY", 3)) { rc = 2; } else if (!strncmp(uc_day, "TUESDAY", 3)) { rc = 3; } else if (!strncmp(uc_day, "WEDNESDAY", 3)) { rc = 4; } else if (!strncmp(uc_day, "THURSDAY", 3)) { rc = 5; } else if (!strncmp(uc_day, "FRIDAY", 3)) { rc = 6; } else if (!strncmp(uc_day, "SATURDAY", 3)) { rc = 7; } return rc; } // day_of_week //------------------------------------------------------------------------------------------------- int randidx(int array_count) { int n; srand(time(NULL)); n = rand() % array_count; return n + 1; // matched arra } // randint //-------------------------------------------------------------------------------------------------