Travel through the method for testing software that combines based on control flow graph traversal and slice forward
Technical field
What the present invention relates to is a kind of method for testing software.Be particularly related to a kind of selectivity regression test method of regression test technical field based on control flow graph traversal and the combination of slice forward ergodic algorithm.
Background technology
The generation that software test is accompanied by software produces, and in the early stage software development process, the implication of test is narrow, test is equal to " debugging ".Up to nineteen fifty-seven, software test just begins to come with the debugging difference, becomes a kind of activity of finding software defect.The research focus of software test both at home and abroad exists at present: software test procedure model, unit testing adequacy standard, regression test, embedded software test, object-oriented software test, software quality and complexity metric, the generation of automatic test data etc.Wherein, regression test is a research direction in the software test field.
In regression test; Often face the unit testing use-case and the very high member function of complexity of enormous amount; How to concentrate the selection test case or to design new test case from already present test case; Thereby both guaranteed the regression tested quality, and improved regression test efficient again, be the subject matter that regression test faces always.
At present, had several kinds of selectivity regression test methods, in this field, the quality of method of testing is mainly weighed through security and degree of accuracy, and the definition of security and degree of accuracy is following:
1. security
Suppose that M is a selectivity regression test method, security is to weigh M from test use cases T, to select to revise the scope that discloses test case.We define security and are program P ' and test use cases T according to a specific program P, modification, and are specific as follows:
Definition: suppose that T has comprised n test case and revised to disclose for program P and P ', suppose to select m in these test cases that then M is following about the security of P, P ' and T:
If M has selected all modifications to disclose test case definitely, we say that the M technology is safe so.If the superset that M has selected a known modification to disclose, then M also is safe.For example, if M has selected the test case of all modification traversals for controlled regression test, M is a safety so.
If M is safe, then M has selected in T each wrong test case that discloses, and if M is unsafe, then it possibly ignored some and exposes wrong test case, in addition, we suppose M
1And M
2Be two selectivity regression test methods, if M
1Compare M
2Bigger security is arranged, then M
1Relative M
2The ability that bigger uncover mistakes is arranged.
2. degree of accuracy
Suppose that M is a selectivity regression test method, degree of accuracy is weighed M and is ignored the degree that non-modification discloses test case, and the definition degree of accuracy is according to a specific program P, the program P ' that is modified and test use cases T, and is specific as follows:
Definition: supposing to have comprised among the test use cases T n test case is that non-modification discloses, and supposes that M has ignored the test case of m wherein, and then M is following about the degree of accuracy of P, P ' and T:
Similar with security, for M, P, P ' and T arbitrarily, go back the neither one algorithm and can determine the degree of accuracy of M, but about degree of accuracy, we still can access some useful conclusions about P, P ' and T.At first, we can come comparison selectivity regression test method M according to degree of accuracy
1And M
2Quality; Secondly, we can prove whether accurate M is, if the test case that M selects a non-modification to disclose, then M is coarse.
Degree of accuracy is of great practical value, because it has weighed the ability that a selectivity regression test method M avoids selecting some test cases, and these test cases can not produce different output results on P and P '.In general, compare selectivity regression test method, can discern which method and carry out test unnecessary still less according to degree of accuracy.
The document relevant with the present invention comprises:
[1]R.Gupta,M.J.Harrold,M.L.Soffa.An?Approach?to?Regression?Testing?UsingSlicing;
[2]H.Agrawal,J.Horgan,E.Krauser,S.London.Incremental?Regression?Testing;
[3]Gregg?Rothermel,Mary?Jean?Harrold.A?Safe,Efficient?Regression?Test?SelectionTechnique。
Next analyze three typical selectivity regression test methods; Use above-mentioned framework to assess and analyze them,, describe with Fig. 1 here in order more clearly to set forth security and degree of accuracy; All test cases in oval all are to revise traversal; Remaining test case then is not, in Fig. 1, and T '
Modification-revealingDash area is to revise the test use cases that discloses, and be to revise to disclose because revise the concentrated a part of test case of the test case of traversal, and another part is not to revise to disclose.
Document [1] has proposed the selectivity regression test method based on data stream.
Security:
Only considered to use the modification relevant to (define-use) with variable-definition, so it possibly ignore some and revise the test case that discloses, for example the deletion of the function call code definition that do not relate to variable is used, and this method can not be selected any test case; Similarly; If a test case is carried out an output statement new or that revise, but does not comprise the use of variable in this statement, this method just can not be selected corresponding test case; Even this statement is revised to disclose for P and P ', so data flow technique is incomplete.
Degree of accuracy:
1) only selects to carry out those variable-definitions that increase newly, that be modified or that deleted and use right test case, so the test case of non-modification traversal has been ignored on data stream selectivity regression test technological model ground;
2) the data stream measuring technology selects definition that traversal increases newly, that revise or deletion to use right test case; Data flow technique just possibly ignored some test cases; This test case has reached a variable-definition that is modified; But but do not reach the use of this variable, these test cases are to revise traversal, but are that non-modification discloses.
3) data flow technique possibly neglect and revise the test case that discloses, for example, and when the deletion of code does not relate to the variable-definition use.
Document [2] has defined the employing program slicing technique and has realized selectivity regression tested method.Comprise and carry out section, Dynamic Slicing, relevant section and approximate four kinds of slice types of relevant section.
Security:
1) when having comprised the assertion statement of revising among the program P, the Dynamic Slicing technology possibly ignored some and revise the test case that discloses, so this technology is unsafe; When the modification of code does not have the control flow graph of reprogramming P or increases new variable-definition, other microtomy is safe.
2) increase assertion statement or assignment statement will have a negative impact to the security of microtomy in program P; For example in P, increase a new assignment statement s; Because the section that program slicing technique obtains appears at the statement among the program P before only being included in modification of program, the section of any test case can not comprise statement s.But in test procedure P ' time, any test case that can implement the s statement all is to revise to disclose in T, but microtomy is not selected these test cases, so microtomy is unsafe.
Degree of accuracy:
It is non-structured revising when code, and does not have the increase of fresh code, and microtomy only selects to revise the test case of traversal.Through restrictively selecting to influence the test case of program output, the Dynamic Slicing technology is to revise traversal rather than revise the test case that discloses with relevant microtomy having got rid of some in varying degrees.But in program P ', comprise structurized change, this technology just possibly selected the test case of non-modification traversal.
Document [3] has proposed one based on control flow graph traversal Technology Selection property regression test method.
Security:
The control flow graph traversal choice of technology test case of all modification traversal, for controlled regression test, this technology is safe.
Degree of accuracy:
Control flow graph traversal technology be not 100% accurate.The control flow graph has a node of repeatedly being visited (multiply-visited-node) characteristic, and when not containing this characteristic among program P and the P ', this technology has accurately selected to revise the test case of traversal simultaneously; When containing this characteristic among program P and the P ', this technology possibly selected the test case of some non-modification traversals.
Summary of the invention
The object of the present invention is to provide a kind of guarantee security that regression test case is selected and degree of accuracy simultaneously travel through the method for testing software that combines based on control flow graph traversal and slice forward.
The objective of the invention is to realize through following steps:
A. create original program and amended programmed control flow graph G and G ' respectively,, set up the corresponding relation of itself and execution route each test case among the test use cases T before the regression test;
B. G and G ' are carried out the depth-first search traversal synchronously, compare the statement node that each traversal can arrive; For the change of variable-definition in the code, use the forward direction ergodic algorithm only to discern all variable-definitions that directly or indirectly are affected and use v
Define~v
Use, in T, select to traverse variable-definition and use right test case; For other node N and the inconsistent situation of statement morphology of N ' in the comparison procedure, in T, select all can reach the test case of this node;
C. list all suitable test cases of revising the back program of from T, selecting.
In the technique scheme, said step B further comprises:
B1. the variable that the definition that obtains according to traversal among the step B changes, its variable-definition of initialization is used pair set, and writes down the node location at this statement place;
B2. continue traversal forward:
1), puts it into definition and use in the pair set if find in a statement, to use the value of the variable that traverses among the step B;
2) depend on the value of the variable that traverses among the step B if find the Variable Control of in a statement, using, put it into definition and use in the pair set;
3) if find in a statement, the variable that step B traversal obtains has a new definition, stops at the traversal on this path;
B3. the node location that returns step B1 record continues execution in step B.
The present invention is on the basis based on the selectivity regression test method of controlling flow graph traversal; In conjunction with the slice forward ergodic algorithm; A kind of improved selectivity regression test method has been proposed; Make it in the advantage while that keeps based on the overall safety of the selectivity regression test method of controlling flow graph traversal, further change and improve the degree of accuracy that regression test case is selected.
The notable feature that method of the present invention is different from existing method is: for the change of the variable-definition that exists in the code, only need all variable-definitions that directly or indirectly are affected of identification to use v
Define~v
UseGet final product, and need not select all to pass through the test case of this variate-value definition.The variable-definition that directly is affected is used being meant the direct change mainly due to the variable-definition value; For example definition statement x=2 is directly changed into x=3; It is right that new definition use is not introduced in the code change, but it is right to test all definition uses that rely on variable x values again; The variable-definition use that is affected indirectly uses right variable-definition value to depend on reformed variate-value to being meant certain variable-definition, or certain variable-definition use depends on reformed variable to control.Select these variable-definitions of traversal to use right test case, promptly selected the test case of all modification traversals, thereby also guaranteed its security.
The beneficial effect of method of the present invention is mainly reflected in: among the present invention; Traversal strategy to based on the selectivity regression test method of controlling flow graph traversal improves; Change for variable-definition in the code; Quote the slice forward ergodic algorithm, discern all variable-definitions that directly or indirectly are affected and use v
Define~v
Use, and only select to traverse these variable-definitions and use right test case, avoided selecting all test durations of causing through the test case of certain node and the consumption of effectiveness.Owing to improve the modification that just is directed against variable-definition, do not consider the deletion of code etc., so method disclosed by the invention can not produce adverse influence to security, and improved the degree of accuracy that test case is selected within the specific limits.
Description of drawings
Fig. 1 is the test use cases graph of a relation;
Fig. 2 is the practical implementation process flow diagram of selectivity regression test method disclosed by the invention;
Fig. 3 is the regression test case collection figure that selectivity regression test method disclosed by the invention is selected.
Embodiment
For example the present invention is done description in more detail below in conjunction with accompanying drawing:
In conjunction with Fig. 2, mainly comprise following step:
Step 1: create original program and amended programmed control flow graph G and G ' respectively,, set up the corresponding relation of itself and execution route to each test case among the test use cases T before the regression test.
Step 2: G and G ' depth-first search are synchronously traveled through, compare the statement node that each traversal can arrive.Node for changing variable-definition skips to step 3; For the inconsistent situation of statement morphology of node N and N ' in the comparison procedure, in T, select all can reach the test case of this node.
Step 3: at first variable and the process variable to the use among the forward direction ergodic algorithm ForwardWalk (Pairs) describes:
Algorithm ForwardWalk (Pairs)
Input Pairs: (s
i, v
i) set of affected variable-definition, wherein s
iBe variable v
iThe statement of definition, v
iBe variable.
Output ValueUseTriples:{ (s, u, v) }
Statement In [i], Out [i], kill, NewIn: the set of variable
Worklist, Cd [i], OldCd, Affected Preds: the set of statement
S: statement collection
V: original variable collection
U: reformed variables set
K, n: statement
I, x: node
DefsOfV [i]: (s, the v) set of definition
Pred (i), Succ (i): the forerunner of node i, descendant node in the programmed control flow graph
Def (i): the variable of statement i definition
Specific as follows:
For the node that changes variable-definition, pair set ValueUseTriples:{ is used in the initializing variable definition, and (s, u v) }, make
Obtain among the set Pairs of affected variable-definition each (s, v) in depth-first search Work List Worklist=n of immediate successor node of s
Depth-first+ Worklist.With all node n in Pairs not in the control flow graph
iIn [n
i] and Out [n
i] be initialized as
The In [s] of node s in Pairs is initialized as
Out [s] be initialized as (s, v) }.For each statement node n ∈ G, In and Out set have comprised the variable that definition value is modified or influences, and adopt a bi-values with (d; P) expression; D is the position of variable, and p is the variable that is changed or influences, and the use of these variablees will come to light in follow-up ergodic process; Set In [n] is illustrated in the node n use of variable before and comes to light, and Out [n] is illustrated in the node n use of variable afterwards and will comes to light.
Step 4: each node among the circular treatment Worklist; If
then algorithm stop; Otherwise from Worklist, take out first statement node n; Definition
is if NewIn ≠ In [n], then In [n]=NewIn,
1) if
then the statement of all k ∈ (OldCd-Cd (n)) ∩ Affected Preds; Set up formula (1), (2), (3), as follows:
In[n]=In[n]-{(k,v
i)} (1)
AffectedPreds=AffectedPreds-{k} (2)
ValueUseTriples=ValueUseTriples-{(k,u,v)} (3)
For all (d, v) the definition of ∈ DefsOfV [k] is right, formula (4) is set up, as follows:
ValueUseTriples=ValueUseTriples∪{(d,u,v)}?(4)
2) if statement n calculate and to have used (formula (5) is set up for d, the v) variable v of ∈ In [n], as follows:
ValueUseTriples=ValueUseTriples∪{(d,n,v)}?(5)
If on this path, found the redetermination of variable v, then stop (d, the v) search on this path, and definition kill={ (x, Def (n)): (x, Def (n)) ∈ In [n] }, formula (6) is set up, as follows:
Out[n]=(In[n]-kill)∪{n,Def(n)} (6)
3) if statement n assert and used (formula (7) is set up for d, the v) variable v of ∈ In [n], as follows:
ValueUseTriples=ValueUseTriples∪{(d,n,v)}?(7)
Calculate and reach the but definition set in In [n] not of this assertion statement, set up formula (8), (9), (10), (11), as follows:
DefsOfV[n]=BackwardWalk(n,{v})-In[n] (8)
In[n]=In[n]∪{(n,v
i):(d,v
i)∈DefOfV[n]} (9)
Out[n]=In[n] (10)
Affected?Preds=Affected?Preds∪{n} (11)
4) if statement n has defined a variable p; And
be Out [n]=Out [n] ∪ { (n, Def (n)) } then;
5) otherwise Out [n]=In [n];
6) if
The depth-first search of all descendant node x ∈ Succ (n) of n is added Work List Worklist=x
Depth-first+ Worklist;
7) if
then algorithm stop; Return ValueUseTriples, otherwise get back to 1).
Step 5: in T, select the right test case of all variable-definitions uses in the traversal ValueUseTriples set;
Step 6: be back to the node location that variable-definition changes in the step 2, continue depth-first search traversal based on the control flow graph;
Step 7: traversal finishes, and lists all suitable test cases of revising the back program of from T, selecting.
Below come comparative studies method disclosed by the invention and degree of accuracy and security through experiment with document [3] method, proved that method disclosed by the invention is guaranteeing that test case selects to have improved degree of accuracy under the situation of security, comparative result sees table 1 for details.
Table 1 document [3] method and method test case disclosed by the invention are selected the table of comparisons
Interpretation is summed up:
1) complexity when function to be tested is big more---and cyclomatic complexity and node number, like functions such as calcup, draw_ft, draw_feature and draw_sounding, their complexity is all very high.When only when function entrance changes variate-value, the raising that method disclosed by the invention can be by a relatively large margin is based on the degree of accuracy of control flow graph traversal technology.
2) when the complexity of function to be tested hour; The nested statement of function inside is less; Perhaps be modified to such an extent that definition value exists when asserting use; Like functions such as getdeg, kp_sub, putspace and get_text_cmds, method disclosed by the invention and the technological degree of accuracy basically identical of control flow graph traversal.
3) the global variable value in function to be tested is modified; And in function, do not exist when quoting; Like getcmds and get_chinese_cmds function, method disclosed by the invention can not selected any test case, and can select all test cases based on control flow graph traversal algorithm.
In sum; Method disclosed by the invention can improve the degree of accuracy based on the algorithm of control flow graph traversal within the specific limits; As shown in Figure 3; Because method disclosed by the invention just to the modification of variable-definition, is not considered the deletion of code etc., so can not produce adverse influence to security.