Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

TEST SELECTION USING EXECUTION TRACE

TEST SELECTION PROCEDURE: STEPS


 Step 1: Given P and test set T, find the execution trace of P for each test in T.

 Step 2: Extract test vectors from the execution traces for each node in the
CFG of P

 Step 3: Construct syntax trees for each node in the CFGs of P and P’.

 Step 4: Traverse the CFGs and determine the subset of T appropriate for
regression testing of P’.
STEP 1: EXECUTION TRACE
 Let G=(N, E) denote the CFG of program P.

 N is a finite set of nodes and E a finite set of edges connecting the nodes.

 For each function f in P, we generate a separate CFG denoted by Gf.

 Suppose that nodes in N are numbered 1, 2, and so on and that Start and End are two
special nodes.

 Let Tno be the set of all valid tests for P’.

 It is obtained by discarding all tests that have become obsolete for some reason.
STEP 1: EXECUTION TRACE (CONTD…)
 An execution trace of program P for some test t in Tno is the sequence of
nodes in G traversed when P is executed against t.

 As an example, consider the following program.


STEP 1: EXECUTION TRACE (CONTD…)
 Here is a CFG for our example program.
STEP 1: EXECUTION TRACE (CONTD…)
 Now consider the following set of three tests and the corresponding trace.
STEP 2: TEST VECTORS
 A test vector for node n, denoted by test(n), is the set of tests that traverse
node n in the CFG.

 For program P we obtain the following test vectors.


STEP 3: SYNTAX TREES
 A syntax tree is constructed for each node of CFG(P) and CFG(P’).
STEP 4: COMPARE CFGS AND TEST SELECTION
 Given the execution traces and the CFGs for P and P’, the following three
steps are executed to obtain a subset T’ of T for regression testing of P’.
STEP 4: COMPARE CFGS AND TEST SELECTION
(CONTD…)
 The basic idea underlying the SelectTests procedure is to traverse the two
CFGs from their respective START nodes using a recursive descent
procedure.

 The descent proceeds in parallel and the corresponding nodes are compared.

 If two nodes N in CFG(P) and N’ in CFG( P’) are found to be syntactically


different, all tests in test (N) are added to T’.
STEP 4: COMPARE CFGS AND TEST SELECTION
(EXAMPLE)
 Suppose that function g1 in P is modified as follows.

 Try the SelectTests algorithm and check if you get T’={t1, t3}.
HANDLING CHANGES IN DECLARATIONS
 The SelectTests algorithm selects modification-traversing tests for regression
testing.

 Suppose that a simple change is made to variable declaration and that this
declaration occurs in the main function.

 SelectTests will be unable to account for the change made simply because we
have not included declarations in the CFG.
HANDLING CHANGES IN DECLARATIONS (CONTD…)
 One method to account for changes in declarations is to add a node
corresponding to the declarations in the CFG of a function.

 This is done for the CFG of each function in P.

 The addition of a node representing declarations will force SelectTests to


compare the corresponding declaration nodes in the CFGs for P and P’.

 Tests that traverse the declaration node will be included in T’ if the nodes are
found not equivalent.
HANDLING CHANGES IN DECLARATIONS (CONTD…)
 The problem now is that any change in the declaration will force the
inclusion of all tests from T in T’.

 This is obviously due to the fact that all tests traverse the node following the
Start node in the CFG for main.
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH
 Let declChangef be the set of all variables in function f whose declarations
have changed in f’.

 Variables removed or added are not included in declChangef

 Similarly, we denote by gdeclChange the set of all global variables in P


whose declarations have changed.
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH (CONTD…)
 Let usef(n) be the set of variable names used at node n in the CFG of function f.

 This set can be computed by traversing the CFG of each function and analyzing the
syntax tree associated with each node.

 Any variable used - not assigned to - in an expression at node n in the CFG of function f
is added to usef(n) .

 Note that declChangef is empty when there has been no change in declarations of
variables in f.

 Similarly, usef(n) is empty when node n in CFG(f) does not use any variable, for example
in statement x = 0
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH (CONTD…)
 Procedure SelectTestsMainDecl is a modified version of procedure
SelectTestsMain.

 It accounts for the possibility of changes in declarations and carefully selects


only those tests that need to be run again for regression testing.
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH (CONTD…)
 Declarations involving explicit variable initializations are treated in two
parts: a pure declaration part followed by an initialization part.

 Initializations are included in a separate node placed immediately following


the Start node.

 Thus, any change in the initialization part of a variable declaration, such as


“int x=0;” changed to “int x=1;” is processed by SelectTests.
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH (EXAMPLE)
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH (EXAMPLE)
 It is easy to see that gdeclChange = ∅ and declChangemain = { z }.

 Suppose the following test set is used for testing P

 We can easily trace CFG( P ) for each test case to find the test vectors.
HANDLING CHANGES IN DECLARATIONS: ANOTHER
APPROACH (EXAMPLE)
 Step 1 in procedure SelectTestsDecl proceeds as follows:

 node 1: use(1) ∩ declChangemain = ∅. Hence, T does not change.


 node 2: use(2) ∩ declChangemain = {z}. Hence, T = T ∪ tests(2) = {t1, t3}.
 node 3: use (3) ∩ declChangemain = ∅. Hence, T does not change.

 Procedure SelectTestsDecl terminates at this point. Procedure SelectTests


does not change T, as all the corresponding nodes in CFG( P ) and CFG( P )
are equivalent.

 Hence, we obtain the regression test T = {t1, t3}.


THANK YOU

You might also like