Web (HTTP/HTML) scripts in LoadRunner are implemented using C programming language. And like always with C, you should remember about some basics. One of them is that few string handling functions can return NULL value instead of correct pointer which will definitely lead to exception like the one below:
-
Action. c ( 7 ): Error: C interpreter run time error: Action. c ( 7 ): Error — memory violation : Exception ACCESS_VIOLATION received.
Basically if you see message like this, it is not any internal LoadRunner error. It means that you made a mistake in your script and you need to fix it. But let’s start from the beginning with some example:
-
Action ( )
-
{
-
char * x_p;
-
-
lr_save_string ( "hello_world!", "MESSAGE" );
-
x_p = ( char * )strchr (lr_eval_string ( "{MESSAGE}" ), ‘ ‘ );
-
lr_save_string (x_p, "MESSAGE_FROM_SP" );
-
lr_output_message (lr_eval_string ( "{MESSAGE_FROM_SP}" ) );
-
-
return 0;
-
}
This small piece of code takes parameter MESSAGE with value “hello_world”, then search for the first space character and display the string starting from that place up to the end. Function strchr() is responsible for searches for the space character. If it’s found then strchr() will return a valid pointer (something like 0xb36ac56e). But if the space is not there (which is our case since there is no space in the hello message), strchr() will return NULL which refers to 0×0 memory address location.
Such memory address is a very special address. Basically any read attempt from there is treated as incorrect operation and results in memory access violation (not only in LoadRunner).
Now, howto deal with it? If you see ACCESS_VIOLATION, in most cases it means that your LR script is working on incorrect/incomplete values. You are responsible for error handling in your scripts and you should always:
- validate parameters values
- check results of C functions to handle any errors, unexpected conditions
- remember that you can’t always expect correct values and you need to handle it as well
Here is our example with fix showing howto deal with ACCESS_VIOLATION. We are calling strchr() function and checking if value returned is not NULL.
-
Action ( )
-
{
-
char * x_p;
-
-
lr_save_string ( "hello_world!", "MESSAGE" );
-
x_p = ( char * )strchr (lr_eval_string ( "{MESSAGE}" ), ‘ ‘ );
-
-
if (x_p ) // if the pointer is not NULL display correct message
-
{
-
lr_save_string (x_p, "MESSAGE_FROM_SP" );
-
lr_output_message (lr_eval_string ( "{MESSAGE_FROM_SP}" ) );
-
}
-
else //if pointer is NULL display error message
-
{
-
lr_error_message ( "Space not found in MESSAGE parameter" );
-
}
-
return 0;
-
}
More details about NULL pointer herehttp://en.wikipedia.org/wiki/Pointer_(computer_programming)#Null_pointer