Sie sind auf Seite 1von 48

Performance Testing VU Scripting using Rational Tools

raj.kamal13@gmail.com www.itest.co.nr

Courseware Information
This introductory course is designed to familiarize testing professionals with the basics of Rational Test Manager The focus will be on applying Rational Test Manager to define, configure and design test cases, define project iterations, configurations and computers and establish traceability links between test inputs and test cases.

Course Objective & Outline


After completing this course, you will be able to:

Build a Test Plan Create Test Cases Configure test Cases Design test Cases Create Planning Reports

Virtual User Scripting


The VU language is the Rational Software corporation language for building virtual tester scripts. The VU language is based on the C programming language. In addition to supporting many C language features, VU includes commands and environment variables specifically designed for use in Rational Suite TestStudio scripts. When you record client/server conversations, Rational Robot automatically generates a script for you in the VU language. You can either play back the script as it was generated, or you can make modifications in Robot.

Automated Script Generation


During virtual tester recording, Robot "listens in" on the client/server conversation. Robot translates the raw conversation into a series of VU commands and stores them in the script.

Modifying Scripts
Although Robot generates complete, executable scripts, sometimes you may want to edit a recorded script for example, to:

Add for, while, and do-while loops to simplify repetitive actions.


Add conditional branching. Modify think time variables. Respond to runtime errors.

Source & Runtime files


The VU language supports the following kinds of files:
File type Extension Location

Script files

.s

The script directory (TMS_Scripts) of your project.


The session directory (TMS_Session) of your project. VU.h file shipped with TestManager is located in \rational\rational test\include by default.

Watch files (also called session files) Header files

.wch

.h

VU addition to C Language
The VU language contains a number of commands in addition to standard C programming language commands. Environment control commands Enable you to control a virtual testers environment by changing the VU environment variables. For example, the number of times to try a connection.

VU addition to C Language Contd..


Datapool functions Retrieve data from a datapool. This enables a script that is executed more than once to use different values in each execution. VU toolkit functions These functions, which come with TestManager, enable you to parse data returned by sqlnrecv into rows and columns.

Environment Control commands


eval: Returns the value and data type at the top of a VU environment variables stack.

Syntax: type eval env_var;


Example: set [Timeout_val = 2000, Log_level = "ALL"]; t = eval Timeout_val; e=(eval Log_level=="ALL");

Environment Control commands


pop: Removes the value of a VU environment variable from the top of the stack.

Syntax: pop [env_var_list];


env_var_list

A list of one or more environment variables, separated by commas and optionally by white space. If env_var_list contains one item, the brackets are optional. If env_var_list contains more than one item, pop operates on the items from left-to-right. ENV_VARS. This specifies all the environment variables.

Environment Control commands


push: Pushes the value of a VU environment variable to the top of the stack. Syntax: push [env_assign_list]; env_assign_list: A list of one or more environment variable assignments, of the form env_var = expr Example: /* Set values for Timeout_val and Log_level. */ set [Timeout_val = 120000, Log_level = TIMEOUT]; push Timeout_val = 30000; pop Log_level;

Environment Control commands


reset: Changes the current value of a VU environment variable to its default value, and discards all other values in the stack. Syntax: reset [env_var_list]; restore: Makes the saved value of a VU environment variable the current value. Syntax: restore [env_var_list]; Example: set Timeout_val = 60000; save Timeout_val; set Timeout_val = 30000; restore Timeout_val; show Timeout_val;

Environment Control commands


Save: Saves the value of a VU environment variable. Syntax: save [env_var_list];

Set: Sets a VU environment variable to the specified expression.


Syntax: set [env_assign_list]; show: Writes the current values of the specified variables to standard output. Syntax: show [env_var_list];

Flow Control Commands


break: Stops execution of for, while, and do-while statements. continue: Skips remaining statements in a loop and continues with the next iteration of the loop. do-while :Repeatedly executes a VU statement while a condition is true. for: Repeatedly executes a VU statement. if-else: Conditionally executes a VU statement. while: Repeatedly executes a VU statement.

Library Routines
I/O Routines : open, close, fseek, feof, fgetc, fputc, fprintf, fscanf etc. Conversion Routines : atoi, ctos, stoc etc. String Routines: sindex, strlen, strstr, substr, subfield etc. Random Number Routines: negexp, rand, uniform etc.

Timing Routines: delay, time, tod.


Miscellaneous Routines: abs, display, getenv, user_exit, usergroup_size Synchronization Functions: wait

Datapool commands
datapool_close datapool_fetch datapool_open datapool_rewind datapool_value Closes an open datapool. Moves the datapool cursor to the next record. Opens a datapool. Resets the cursor for the datapool. Retrieves the value of a specified column.

VU Toolkit function
Data commands: AppendData: Adds the data returned by sqlnrecv to the specified data set. FreeAllData: Frees all data sets saved with SaveData and AppendData. FreeData: Frees specified data sets saved with SaveData and AppendData. GetData:Retrieves a specific value created with SaveData or AppendData. SaveData: Stores the data returned by the most recent sqlnrecv command.

VU Toolkit function
File I/O commands: NextField :Parses the line read by the ReadLine function.

NextSubField: Parses the field returned by the most recent call to NextField or IndexedField.
ReadLine:Reads a line from the open file designated by file_descriptor. SHARED_READ: Allows multiple virtual testers to share a file. IndexedField :Parses the line read by the ReadLine function and returns the field designated by index.

Emulation commands
SQL Emulation commands & Functions SQL Send Emulation Commands

SQL Receive Emulation Commands


SQL Emulation Functions

SQL Send Emulation Commands


sqlclose_cursor : Closes the indicated cursor. sqldelete_cursor :Deletes the current row using the indicated cursor.

sqlexec: Executes SQL statements.


sqlopen_cursor: Opens the specified cursor. sqlposition_cursor: Positions a cursor within a result set. sqlrefresh_cursor: Refreshes the result set of a cursor. sqlupdate_cursor: Updates the current row of the indicated cursor.

SQL Receive Emulation Commands


sqlfetch_cursor : Fetches the requested rows from the cursor indicated. Sqllongrecv: Retrieves longbinary and longchar results. sqlnrecv: Retrieves row results after sqlexec is executed.

SQL Emulation Functions


Sqlcommit: Commits the current transaction.
Sqlconnect: Logs on to a SQL database server. Sqldisconnect: Closes the specified connection.

HTTP Emulation Commands and Functions

HTTP Send Emulation Commands http_request: Sends an HTTP request to a Web server.

Syntax: int http_request [cmd_id] primary_addr [, secondary_addr] [, flags], text

HTTP Emulation Commands and Functions

HTTP Emulation Functions:


http_disconnect: Closes the connection to a Web server.

http_find_values: Searches for the specified values on the current connection.

Socket Emulation Commands and Functions


Socket Send Emulation Commands sock_send: Sends data to the server.

Socket Receive Emulation Commands sock_nrecv: Receives n bytes from the server. sock_recv : Receives data until the specified delimiter string is found.
Socket Emulation Functions sock_connect, sock_create, sock_disconnect, sock_open etc

Emulation Commands Used with Any Protocol


emulate : Provides generic emulation command services to support a proprietary protocol.

Note: VU supports the SAP protocol by using external C functions and the emulate command.
start_time: Enables you to define start and stop times. stop_time: Enables you to define start and stop times. testcase: Checks a response for specific results and reports and logs them

Scripts, Subroutines, and C Libraries


Program structure Header Files Preprocessor features

Defining your own subroutines

Program Structure
VU programming structure is similar to the structure of the C programming language. #include <VU.h> #include <VU_tux.h> proc proc_name() { /* body of procedure */ } func function_name() { /* body of function */ } /* main body of script follows: */ { string declarations; shared declarations; /* VU code goes here*/ }

Header Files
VU header files contain a collection of definitions and macros. VU.h is automatically included in scripts generated from recording HTTP, SQL, and socket sessions. VU_tux.h is automatically included in scripts generated from recording a TUXEDO session.

If you are manually writing a script, include the following preprocessor statement:
#include <VU.h>

If you are manually writing a script that accesses a TUXEDO application, include both VU_tux.h and VU.h as preprocessor statements:
#include <VU.h> #include <VU_tux.h>

VU.h Header File


The VU.h file includes definitions for:

The EOF value returned by various VU functions. The file descriptors for the standard files.

ENV_VARS, which lets you operate on the environment variables as a unit.


HOURS(A), MINUTES(A) and SECONDS(A) returns the time in milliseconds.

sme/data.h file & sme/file.h


The sme/data.h file includes definitions for functions that come with TestStudio. These functions let you parse data returned by sqlnrecv into rows and columns. Typically, this is useful in dynamic data correlation for SQL, where you extract data from queries and use that data in subsequent statements.

Preprocessor Features
Replace tokens : Token replacement and macro substitution can be specified with the #define preprocessor command. To indicate simple replacement throughout the entire script, use a command of the form: #define orig_ident new_token Include more than one source file in a script: The #include preprocessor command lets you include another source file in your script at compile time. This command has two forms: #include <filename> #include "filename" Compile parts of a script: Conditional compilation commands allow you to conditionally compile parts of a script. There are three ways to specify conditional compilation: #if-#else-#endif #ifdef-#else-#endif #ifndef-#else-#endif

Functions
Functions Subroutines that return a value through a return statement. You define functions with the func keyword. [type] func fname [array_spec] (arg_list) arg_declar; { stmnt1; stmnt2;

Procedures
Procedures Subroutines that do not return a value. You define procedures with the proc keyword. proc pname (arg_list) arg_declar; { stmnt1; stmnt2;

Accessing External C Data and Functions


The VU language supports access to external C data and functions. A VU script can call functions written in C and pass values as arguments to the C functions.
C functions can return values to VU scripts.

External C Variables
C Variable Type VU Variable Type

int char * char *


int * char **

int string /* read only */ string:maxsize /* writable */


int [ ], int[ ][ ], int[ ][ ][ ] string [ ], string [ ][ ], string [ ][ ][ ]

External C Variables
In a script an external C string is read-only unless its VU declaration includes its maximum size. The C code must allocate space for the string greater than or equal to maxsize bytes. The maximum size must include room for the C null-terminator character '\0'; it is specified with a colon and an integer constant, as in: external_C string:81 extc_line;

External C data cannot be declared persistent or shared. Values of external C variables persist for the duration of the run.

Declaring External C Subroutines


An external C subroutine is declared the same way as a VU function or procedure, with an empty statement block for the body. The following VU declarations: external_C func foo(i, s) string s; {} external_C int func[10][20] afunc() {} are used for the C functions whose prototypes are:

int foo(int, char *); int *afunc(void);

Accessing Values Returned from C Functions


C Variable Type void int char * int * char ** VU Variable Type proc int func string func int func[ ], int func[ ][ ], int func[ ] [ ][ ] string func[ ], string func[ ] ], string func[ ] [ ] [ ]

Specifying External C Libraries


In TestManager, select Tools -> Options, and then click the Compilation tab. Under External C Libraries, click Add and enter the name of the library. To make a library available to a particular script, modify the script properties for that script. You can modify script properties using TestManager, Robot, or LoadTest. In LoadTest

Creating a Dynamic-Link Library


To access C code and data from a VU script, compile the C code into a dynamic-link library (DLL). There are three steps involved in creating a DLL:

1. Write and compile the C source code to be called from your VU script.
2. Examine the VU script, and note which functions and variables the script needs to access. 3. Create the DLL, and export the necessary symbols.

Creating a Dynamic-Link Library


1. Write c_prog.c, which contains code that you want to call from your script, script.s. Invoke the compiler to compile c_prog.c and produce c_prog.obj 2. Examine your VU script script.s. The script uses external C notation to indicate that the symbols s_func, afunc, and addr_message are defined in a C module. 3. Issue the link command to create a DLL and export the external C symbols. The following command produces c_prog.lib, c_prog.exp and c_prog.dll, and exports s_func, afunc and addr_message: link c_prog.obj /dll /export:s_func /export:afunc /export:addr_message 4. Once you have created the DLL, copy it to each project that needs to access it. The directory location is project_nameTestDatastore\DefaultTestScriptDatastore\TMS_Scripts\externC

Supplying a Script with Meaningful Data


When you play back a script, the script uses the exact values that you recorded. Assume, for example, that you record a script that adds a record with a primary key of John Doe to a database. When you play back the script, to emulate thousands of users, you will get errors after the first John Doe is added.

Dynamic Data Correlation


Dynamic data correlation is a technique to supply variable data values to a script when the transactions in a script depend on values supplied from the server. For example, when you record an http script, the Web server may send back a unique string, or session ID, to your browser. The next time your browser makes a request, it must send back the same session ID to authenticate itself with the server.

Types of Performance Test


Benchmark tests Compares the performance of a new or unknown server to a known reference standard, such as existing software or measurements. Configuration tests Verifies the acceptability of the server's performance behavior using varying configurations while the operational conditions remain constant. Load tests Verifies the acceptability of the server's performance behavior using varying workloads while the operational conditions remain constant.

Stress tests Verifies the acceptability of the server's performance behavior when abnormal or extreme conditions are encountered, such as diminished resources or an extremely high number of users.
Contention tests Verifies that the server can handle multiple user demands on the same resource (that is, data records or memory).

LoadTest
Load testing is designed to test client or server response times under varying loads.

Load tests also are used to compute the maximum number of transactions a server can handle over a given time period.

Questions

Das könnte Ihnen auch gefallen