Y-lib
Loadrunner libraries
|
Macros | |
#define | RAND_MAX 32767 |
RAND_MAX constant for use with rand() - 15 bits integer. More... | |
#define | Y_RAND_MAX 1073741823 |
Alternate RAND_MAX constant for use with y_rand. More... | |
#define | vuser_init() vuser_init() { y_setup(); return y_vuser_init(); } y_vuser_init() |
Hook to ensure that y_setup() is called at start-up. This allows many performance improvements in the library. More... | |
#define | y_is_vugen_run() y_is_vugen_run_bool |
Test if this script is running in vugen (debug mode) More... | |
Functions | |
void | y_setup () |
Ylib setup - determines and stores the identity of the virtual user. More... | |
long | y_rand (void) |
Generate a random (integer) number between 0 and Y_RAND_MAX (30 bit maxint). More... | |
double | y_drand (void) |
Generate a random number between 0 <= y_drand() < 1. This supersedes y_rand(). Equal to Math.random in Java and JavaScript, Random.NextDouble in C#, etc. Better distribution of the random numbers over the range than by using y_rand() with modulo (%) – thus no skewed results. More... | |
char * | y_mem_alloc (size_t size) |
Ylib wrapper for malloc() More... | |
char * | y_array_alloc (size_t length, size_t size) |
Allocates a character array and initializes all elements to zero As y_mem_alloc(), but using the 'calloc' function, rather than 'malloc()'. More... | |
char * | y_strdup (char *source) |
Copy a string into a malloc'd piece of memory using strdup(), and lr_abort() if the allocation fails. See the strdup() C documentation for what it does. This is just a simple wrapper around it that catches the strdup return value and handles any errors by aborting the script. More... | |
char * | y_get_parameter_eval_string (const char *param_name) |
Obtain the string required to fetch the contents of a parameter through lr_eval_string(). More... | |
int | y_is_empty_parameter (const char *param_name) |
Test if the given parameter is empty or not yet set. (These are two different things..) It would be nice if loadrunner had a builtin for this. More... | |
char * | y_get_parameter (const char *param_name) |
Get the content of a parameter and return it as a char *. More... | |
char * | y_get_parameter_or_null (const char *param_name) |
Get the content of a parameter and return it as a char *, or return NULL if it wasn't set. More... | |
char * | y_get_parameter_with_malloc_or_null (const char *src_param) |
Get the content of a parameter and return it as a char * (malloc version) More... | |
char * | y_get_parameter_ext (const char *source_param) |
Get the content of a parameter and return it as a char * (lr_eval_string_ext() version) More... | |
Variables | |
int | y_virtual_user_id = 0 |
The virtual user id, as reported by lr_whoami(). More... | |
char * | y_virtual_user_group = NULL |
The virtual user group, as reported by lr_whoami(). More... | |
int | y_scid |
The virtual user scid, as reported by lr_whoami(). More... | |
int | y_is_vugen_run_bool = 0 |
Boolean, true when running in Vugen. Not able to do this in pre-compile phase. More... | |
#define RAND_MAX 32767 |
RAND_MAX constant for use with rand() - 15 bits integer.
Loadrunner does not give you full C headers, so the 'RAND_MAX' #define from <stdlib.h> is missing. We define it here mostly for documentation, as we do not have access to the header files themselves and therefore cannot change this.
#define vuser_init | ( | ) | vuser_init() { y_setup(); return y_vuser_init(); } y_vuser_init() |
#define y_is_vugen_run | ( | ) | y_is_vugen_run_bool |
Test if this script is running in vugen (debug mode)
Recommended practice: Use this to create script debugging code that will hit all of the functional code inside the script when run in Vugen, but the full (semi-randomized) realistic scenario when it runs as part of a load test.
Example:
#define Y_RAND_MAX 1073741823 |
char* y_array_alloc | ( | size_t | length, |
size_t | size | ||
) |
Allocates a character array and initializes all elements to zero As y_mem_alloc(), but using the 'calloc' function, rather than 'malloc()'.
[in] | length | Expected number of characters. |
[in] | size | How much space a single character requires. Usually this should contain "sizeof char". |
double y_drand | ( | void | ) |
Generate a random number between 0 <= y_drand() < 1. This supersedes y_rand().
Equal to Math.random in Java and JavaScript, Random.NextDouble in C#, etc. Better distribution of the random numbers over the range than by using y_rand() with modulo (%) – thus no skewed results.
Examples:
char* y_get_parameter | ( | const char * | param_name | ) |
Get the content of a parameter and return it as a char *.
This is useful mostly for code that wants to manipulate parameter contents but not care about the name of the parameter itself. (Something which applies to most of ylib ..)
[in] | param_name | The name of the parameter to fetch. |
Example:
char* y_get_parameter_eval_string | ( | const char * | param_name | ) |
Obtain the string required to fetch the contents of a parameter through lr_eval_string().
[in] | param_name | The parameter name to construct the eval text for. |
char* y_get_parameter_ext | ( | const char * | source_param | ) |
Get the content of a parameter and return it as a char * (lr_eval_string_ext() version)
Like y_get_parameter, but the result will use lr_eval_string_ext() to acquire it's memory, rather than getting it from lr_eval_string. This can be useful when you want your data to remain in memory instead of getting freed at the end of each iteration. An example is the browser emulation code in y_emulate_browser.c, which sets up a linked list that has to stay allocated throughout the duration of the test. (And therefore never needs to be freed. But I digress.)
[in] | source_param | The name of the parameter to fetch. |
Example:
char* y_get_parameter_or_null | ( | const char * | param_name | ) |
Get the content of a parameter and return it as a char *, or return NULL if it wasn't set.
This will return null in the most typical case: A parameter saved with web_reg_save_param(), but never filled. The actual check employed here is a test that looks if the parameter content matches the parameter name surrounded by brackets.
If the parameter was never filled, lr_eval_string() will return that. However, in many more elaborate cases we really need to know if it was never filled to begin with. This function mimics the behaviour we really want to see in LR, but don't have. (At least, not in LR 11.05, the version I'm working with.)
It would be really nice if there was a loadrunner built-in that did this.
[in] | param_name | The name of the parameter to fetch. |
Example:
char* y_get_parameter_with_malloc_or_null | ( | const char * | src_param | ) |
Get the content of a parameter and return it as a char * (malloc version)
This is like y_get_parameter(), but the result will use memory allocated with y_mem_alloc(), instead of acquired from lr_eval_string().
[in] | src_param | The name of the parameter to fetch. |
Example:
int y_is_empty_parameter | ( | const char * | param_name | ) |
Test if the given parameter is empty or not yet set. (These are two different things..) It would be nice if loadrunner had a builtin for this.
[in] | param_name | The name of the parameter to |
char* y_mem_alloc | ( | size_t | size | ) |
Ylib wrapper for malloc()
Allocates a block of memory, but aborts the Vuser if that fails.
[in] | size | Number of bytes required. |
Example:
long y_rand | ( | void | ) |
Generate a random (integer) number between 0 and Y_RAND_MAX (30 bit maxint).
Example:
void y_setup | ( | ) |
Ylib setup - determines and stores the identity of the virtual user.
This runs lr_whoami and sets y_virtual_user_id and y_virtual_user_group as global variables. Called y_rand() (for it's seed), y_is_vugen_run() and others dynamically.
char* y_strdup | ( | char * | source | ) |
Copy a string into a malloc'd piece of memory using strdup(), and lr_abort() if the allocation fails. See the strdup() C documentation for what it does. This is just a simple wrapper around it that catches the strdup return value and handles any errors by aborting the script.
[in] | source | The string to copy. |
int y_is_vugen_run_bool = 0 |
int y_scid |
char* y_virtual_user_group = NULL |