Test Script Services |
Use the synchronization functions to synchronize virtual testers during script playback. You can insert synchronization points and wait periods, and you can manage variables shared among virtual testers.
The following table lists the synchronization functions.
TSSSharedVarAssign()
Performs a shared variable assignment operation.
TSSSharedVarEval()
Gets the value of a shared variable and operates on the value as specified.
TSSSharedVarWait()
Waits for the value of a shared variable to match a specified range.
TSSSyncPoint()
Puts a synchronization point in a script.
Performs a shared variable assignment operation.
s32TSSSharedVarAssign
(char *name
, s32value
, ShVarOpop
, s32 *returnVal
)
On success, this function retrieves the value of the specified shared variable before and after it has been operated on. The function exits with one of the following results:
TSS_OK.
Success.
TSS_NOSERVER
. No previous successful call to TSSConnect()
.
TSS_INVALID
. The entered name
is not a shared variable.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
The data type ShVarOp
is defined as follows:
typedef enum ShVarOp ShVarOp; enum ShVarOp { SHVOP_assign, SHVOP_add, SHVOP_subtract, SHVOP_multiply, SHVOP_divide SHVOP_modulo, SHVOP_and, SHVOP_or, SHVOP_xor, SHVOP_shiftleft SHVOP_shiftright SHVOP_END }
TSSSharedVarAssign("myVar",5,SHVOP_add,NULL)
is equivalent to myVar += 5.
This example adds 5 to the value of the shared variable lineCounter
and puts the new value of lineCounter
in returnval
.
s32 returnval = 5;
s32 retVal = TSSSharedVarAssign
("lineCounter", val, SHVOP_add,
returnVal);
TSSSharedVarEval()
, TSSSharedVarWait()
Gets the value of a shared variable and operates on the value as specified.
s32TSSSharedVarEval
(char *name
, s32 *value
,ShVarAdj op
)
On success, this function returns the new value of the specified shared variable as described above. The function exits with one of the following results:
TSS_OK.
Success.
TSS_NOSERVER
. No previous successful call to TSSConnect()
.
TSS_INVALID
. The entered name
is not a shared variable.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
The data type ShVarAdj
is defined as follows:
typedef enum ShVarAdj ShVarAdj; enum ShVarAdj { SHVADJ_none, SHVADJ_pre_inc, SHVADJ_post_inc, SHVADJ_pre_dec, SHVADJ_post_dec }
This example post-decrements the value of shared variable lineCounter
and stores the result in val
.
s32 val;
s32 retVal = TSSSharedVarEval
("lineCounter",val,SHVADJ_post_inc);
TSSSharedVarAssign()
, TSSSharedVarWait()
Waits for the value of a shared variable to match a specified range.
s32TSSSharedVarWait
(char *name
, s32min
, s32max
, s32adjust
, s32timeout
, s32 *returnVal
)
On success, this function returns 1
(condition was met before time-out) or 0
(time-out expired before the condition was met). The function exits with one of the following results:
TSSConnect()
.
TSS_INVALID
. The entered name
is not a shared variable.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
This call provides a method of blocking a virtual tester until a user-defined global event occurs.
If virtual testers are blocked on an event using the same shared variable, TestManager guarantees that the virtual testers are unblocked in the same order in which they were blocked.
Although this alone does not ensure an exact multiuser timing order in which statements following a wait are executed, the additional proper use of the arguments min
, max
, and adjust
allows control over the order in which multiuser operations occur. (UNIX or Windows NT determines the order of the scheduling algorithms. For example, if two virtual testers are unblocked from a wait in a given order, the tester that was unblocked last might be released before the tester that was unblocked first.)
If a shared variable's value is modified, any subsequent attempt to modify this value -- other than through TSSSharedVarWait() -- blocks execution until all virtual testers already blocked have had an opportunity to unblock. This ensures that events cannot appear and then quickly disappear before a blocked virtual tester is unblocked. For example, if two virtual testers were blocked waiting for name
to equal or exceed N
, and if another virtual tester assigned the value N
to name
, then TestManager guarantees both virtual testers the opportunity to unblock before any other virtual tester is allowed to modify name
.
Offering the opportunity for all virtual testers to unblock does not guarantee that all virtual testers actually unblock, because if TSSSharedVarWait() is called with a nonzero value of adjust
by one or more of the blocked virtual testers, the shared variable value changes during the unblocking script. In the previous example, if the first user to unblock had called TSSSharedVarWait() with a negative adjust
value, the event waited on by the second user would no longer be true after the first user unblocked. With proper choice of adjust
values, you can control the order of events.
This example returns 1
if the shared variable inProgress
reaches a value between 10 and 20 within 60000 milliseconds of the time of the call. Otherwise, it returns 0
. svVal
contains the value of inProgress
at the time of the return, before it is adjusted. (In this case, the adjustment value is 0 so the value of the shared variable is not adjusted.)
s32 svVal = 0;
s32 retVal = TSSSharedVarWait
("inProgress",10,20,0,60000,svVal);
TSSSharedVarAssign()
, TSSSharedVarEval()
Puts a synchronization point in a script.
s32TSSSyncPoint
(char *label
)
label
The name of the synchronization point.
This function exits with one of the following results:
TSS_OK.
Success.
TSS_NOOP
. The TSS server is running proxy.
TSS_NOSERVER
. No previous successful call to TSSConnect()
.
TSS_INVALID
. The synchronization point label
is invalid.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
A script pauses at a synchronization point until the release criteria specified by the suite have been met. If the criteria are met, the script delays a random time specified in the suite and then resumes execution.
Typically, it is better to insert a synchronization point into a suite from TestManager rather than use the TSSSyncPoint() call inside a script.
If you insert a synchronization point into a suite, synchronization occurs at the beginning of the script. If you insert a synchronization point into a script with TSSSyncPoint(), synchronization occurs at the point of insertion. You can insert the command anywhere in the script.
This example creates a sync point named BlockUntilSaveComplete
.
s32 retVal = TSSSyncPoint
("BlockUntilSaveComplete");
Rational TestManager Extensibility Reference | Rational Software Corporation |
Copyright (c) 2003, Rational Software Corporation | http://www.rational.com support@rational.com info@rational.com |