lr_exit Function in Loadrunner With Examples

lr_exit Function in loadrunner with examples

This is very important function which is used in LoadRunner. The main purpose of this function is to stop executing the script and exit from the script. But there are various ways to do which we need to see.

To understand this function, we should know that there are three ways from which LoadRunner can exit the execution of script. It can be either exit from the script, action, or iteration. Let us see the syntax given below.

void lr_exit (int continuation_option, int exit_status);

We can clearly see that this function doesn’t return any value because return type is void.

Let us see the arguments of this function

continuation_option: The Script Continuation Options specifies how the script continues after the call to lr_exit Because we know that there are different ways to exit from the script execution

exit_status: The Script Exit Status of the scenario group

One thing to be noted here is that lr_exit(LR_EXIT_VUSER, LR_ABORT); is equal to lr_abort because purpose of both the function is to abort the execution of the script

Let us see the following example where we are using the function to instruct Vuser to stop the current iteration and start the next iteration.

lr_exit(LR_EXIT_MAIN_ITERATION_AND_CONTINUE, LR_AUTO);

Let us see the list of other script continuation options:

Let us see various types of exit Is supported by LoadRunner which can be given below and help us understand LoadRunner exit process.

LR_EXIT_VUSER – It immediately stop the execution of action script and go directly to vuser_end action Which comes after action part of the script.

LR_EXIT_ACTION_AND_CONTINUE – It is used for stopping current action and go to the next action.

LR_EXIT_ITERATION_AND_CONTINUE – It is used for stopping current iteration execution and go to the next iteration.

LR_EXIT_VUSER_AFTER_ITERATION – It is used to stop the execution of a script after the current iteration run is completed.

LR_EXIT_VUSER_AFTER_ACTION – It is used to stop the execution of a script after the current action run is completed.

In the example given below we can see clearly that virtual user script execution is stopped by this function when the variable status contains the value LR_FAIL

Action()

{

//Assigning a variable status to the value – LR_FAIL

     int status = LR_FAIL;

     if (status == LR_FAIL) {

//Printing message in the output log window of loadrunner

//We can give any message for output log window of LoadRunner. Here we have given following message.

//  failed

          lr_error_message (“failed”);

          lr_exit(LR_EXIT_VUSER, LR_FAIL);

     }

     return(0);

}

lr_exit Example 1

Starting action Action.

Action.c(8): Error: failed

Abort was called from an action.

Ending Vuser…

Starting action vuser_end.

Ending action vuser_end.

Vuser Terminated.

Now in this condition, when the status is LR_FAIL, it will directly exit the virtual user which means that current virtual user will stop executing the script and it will stop then and there itself and now the script will run for other virtual user, if there is any.

We can see the output log window of LoadRunner as given below in the form of screenshot.

lr_exit Example 2

Overall , we can say that it is very useful function which is used in LoadRunner which shows different ways how LoadRunner stop the execution of the script and we know that there are different exit techniques to stop the execution and Load Runner does so according to script which is executed by it. In short, we can say that lr_exit function allows you to exit from the script run during execution.