lrs_save_param
| Correlating Statements Functions |
Saves data from a static or received buffer to a parameter.
int lrs_save_param( char *s_desc,char *buf_desc, char *param_name, int offset, int param_len );
| s_desc | A descriptor identifying a connected socket. |
| buf_desc | A descriptor identifying a buffer. |
| param_name | The name of a parameter to hold the buffer value. |
| offset | The offset of the data in the buffer to be saved to the parameter. |
| param_len | The length of the data to be saved to the parameter (in bytes). |
The lrs_save_param function saves data from a buffer to a parameter. This function is used for correlating or linking statements within a script.
The first two parameters specify which buffer to use:
| Use a specific buffer from the data file: | Use the last received buffer: |
| The buffer descriptor has the form: "bufxx" | The socket descriptor is not NULL and the buffer descriptor is NULLLRS_LAST_RECEIVED is specified as the buf_desc parameter |
After specifying an active socket and buffer, you specify a parameter name to store the data. Specify an offset to indicate the offset of the data in the buffer, and length of the data.
Once you save the parameter, you can use it in both the script and data file. Substitute all of the appropriate constant values with the parameter. Whenever you reference the parameter, enclose it in angle brackets (or other delimiters defined within VuGen options).
Note: To save encoded data from a user buffer to a parameter, use the lrs_save_param_ex function.
Return Values
Parameterization
You cannot use standard parameterization for any arguments in this function.
Example
In the following example, a user performed a Telnet session. The user used a ps command to determine a process ID (PID), and killed the application based on its PID. Repeating the exact steps during replay will not work—during replay the PID will be different (Linux assigns a new PID). Killing the PID that was recorded in the script will be ineffective. To overcome this problem, lr_save_param saves the value of the PID to a parameter during replay. This parameter is referenced in the Send buffer which contains the kill command.
The following code was recorded. The script would not perform the kill command during replay. To correct this, the following steps were performed:
The recorded value of the PID, 28597 was located along with the socket and buffer descriptors. The offset and length of the data was determined. The buffer shown below, buf47, was received after the ps command. The offset of the PID within the buffer data is 67, and its length is 5.
An lrs_save_param function was placed in the Actions section, before the lrs_send statement, in this instance buffer "buf48". NULL was specified in place of a buffer descriptor, indicating that VuGen should use the last received buffer, "buf47". During each subsequent replay, the PID is saved to a parameter called param1. The parameter was evaluated and printed in the output window or log file using lr_output_message.
The parameter was referenced in the Send buffer in place of the original PID constant. In this example angle brackets were used, but you can define the delimiters from VuGen's Option menu.
recv buf47 188 "\r" "\x0" "\r\n""PID TT STAT TIME COMMAND\r\n" "28469 q2 S 0:01 -tcsh (tcsh)\r\n" "28597 q2 T 0:00 vi log1.txt\r\n" "28602 q2 R 0:00 ps\r\n" "tears:/tmp_mnt/u/jay>"
The PID also appeared in the Send buffer, buf48, when the user performed a kill operation to the process.
send buf48 "kill -9 28597"
lrs_receive("socket2", "buf47", LrsLastArg);
lrs_save_param("socket2", NULL, "param1", 67, 5);
lr_output_message ("param1: %s", lr_eval_string("<param1>"));
lr_think_time(10);
lrs_send("socket2", "buf48", LrsLastArg);
send buf48 "kill -9 <param1>"

