Example: lrs_save_param

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:

  1. 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.

  2. 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"

  3. 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.

  4. lrs_receive("socket2", "buf47", LrsLastArg);
    lrs_save_param("socket2", NULL, "param1", 67, 5);
    lr_output_message ("param1: %s", lr_eval_string("<param1>"));
    lrs_send("socket2", "buf48", LrsLastArg);

  5. 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.

  6. send buf48 "kill -9 <param1>"