CN103207833B - The disposal route of loop code and system in software test - Google Patents
The disposal route of loop code and system in software test Download PDFInfo
- Publication number
- CN103207833B CN103207833B CN201310113328.XA CN201310113328A CN103207833B CN 103207833 B CN103207833 B CN 103207833B CN 201310113328 A CN201310113328 A CN 201310113328A CN 103207833 B CN103207833 B CN 103207833B
- Authority
- CN
- China
- Prior art keywords
- path
- sub
- loop body
- paths
- loop
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
- 238000012360 testing method Methods 0.000 claims abstract description 132
- 238000000034 method Methods 0.000 claims abstract description 26
- 125000004122 cyclic group Chemical group 0.000 claims description 14
- 238000013522 software testing Methods 0.000 claims description 14
- 238000004880 explosion Methods 0.000 abstract description 3
- 238000010586 diagram Methods 0.000 description 5
- 230000004931 aggregating effect Effects 0.000 description 4
- 238000003672 processing method Methods 0.000 description 2
- 101100062121 Neurospora crassa (strain ATCC 24698 / 74-OR23-1A / CBS 708.71 / DSM 1257 / FGSC 987) cyc-1 gene Proteins 0.000 description 1
- 230000002776 aggregation Effects 0.000 description 1
- 238000004220 aggregation Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The invention discloses the disposal route of loop code in a kind of software test, first according to program control flowchart, search the loop body of tested code, determine subpath before the loop body of previous cycle body, determine all single sub path of previous cycle body again, combine described single sub path for combination subpath, when before described loop body, the collection routes of subpath and described combination subpath is for reaching, determine that described combination subpath is previous cycle body stator path really, when before determining described loop body, subpath and the described collection routes determining subpath are for reaching, generating test use case, and according to described test case, perform tested code, catch the actual execution route of described previous cycle body, repeat above-mentioned steps, until process all loop bodies of tested code.The invention also discloses the disposal system of loop code in a kind of software test simultaneously.Dirigibility of the present invention is high, can save human cost, avoid path explosion.
Description
Technical Field
The invention relates to a software testing technology, in particular to a method and a system for processing a loop code in software testing.
Background
Software testing is the process of analyzing or executing a source program (code under test) in a controlled environment, and the primary purpose of the software testing is to find and correct potential faults and defects in the software in as little time and labor as possible, thereby improving the quality of the software. The accuracy of the software test is closely related to the comprehensiveness of the test path generation.
In the prior art, a test path is generated by traversing nodes in a program control flow graph, and a source program is executed by using a test case along the test path. When the nodes in the program control flow graph are all sequential nodes, namely the source programs are all sequential statements, a definite test path can be generated; however, when a branch node appears in the program control flow graph, that is, a loop statement appears in the source program, the existing conventional processing method, such as a 0-1 strategy or a 0-K strategy, treats the loop statement as a judgment statement, so that the generation of part of test paths is virtually omitted, and the accuracy of software testing is reduced because the test paths are not generated completely. In addition, the loop statements can be processed by manual methods such as manual designation of test paths, which increases labor cost; moreover, manual methods are relatively flexible and difficult to adapt to the requirements of different engineering projects.
Disclosure of Invention
In view of the above, the main objective of the present invention is to provide a method and a system for processing a cyclic code in a software test, which can ensure the comprehensiveness and high flexibility of the test path generation, and can save the labor cost.
In order to achieve the purpose, the technical scheme of the invention is realized as follows:
the invention provides a method for processing loop codes in software testing, which comprises the following steps:
searching a loop body of the tested code according to the program control flow graph;
determining a circulation body front sub-path of a current circulation body;
determining all single sub-paths of the current cycle body, combining the single sub-paths into a combined sub-path, and determining the combined sub-path as the determined sub-path of the current cycle body when the set path of the sub-path before the cycle body and the combined sub-path is reachable;
when the set paths of the sub paths before the cycle body and the determined sub paths are determined to be reachable, generating a test case;
and executing the tested code according to the test case, and capturing the actual execution path of the current loop body.
In the above scheme, the method further comprises:
and after the actual execution paths of all the loop bodies of the tested code are captured, generating a complete test path of the tested code, generating a complete test case, and executing the coverage test of the complete test case on the tested code by using a preset coverage test criterion.
In the foregoing solution, the determining the loop body front sub-path of the current loop body includes:
determining that a current loop body is a first loop body of a tested code and a path from an inlet node of a program control flow graph of the tested code to a current loop body starting point is reachable, and determining that a path from the inlet node of the program control flow graph to the current loop body starting point is a loop body front sub-path;
when the current loop body is determined to be the first loop body of the tested code and the path from the entry node of the program control flow graph of the tested code to the starting point of the current loop body is unreachable, the unreachable path is changed into a reachable path, and the reachable path is determined to be a loop body front sub-path;
determining that a current loop body is a non-first loop body of a tested code, and a loop body front sub-path of a last loop body of the tested code, a captured actual execution path of the last loop body, and a path from the last loop body of the tested code to the current loop body are new loop body front sub-paths, and when the new loop body front sub-paths are reachable, determining that the new loop body front sub-paths are loop body front sub-paths;
determining that the current loop body is a non-first loop body of the tested code, and collecting a loop body front sub-path of a last loop body of the tested code, a captured actual execution path of the last loop body, and a path from the last loop body of the tested code to the current loop body as a new loop body front sub-path, when the new loop body front sub-path is unreachable, changing the new loop body front sub-path into a reachable path, and determining that the new loop body front sub-path is a loop body front sub-path.
In the above scheme, the determining all the single sub-paths of the current loop body includes:
and traversing nodes on the control flow graph of the tested code program in sequence, wherein the set of the traversed paths from the start node of the loop body to the end node of the loop body is all single sub-paths of the loop body.
In the foregoing solution, the combining the single sub-path to be a combined sub-path, and determining that the combined sub-path is the determined sub-path of the current loop body includes:
and sequentially selecting one single sub-path from all the single sub-paths as a target sub-path, taking other single sub-paths as reference sub-paths, and collecting at least one reference sub-path and the target sub-path as the combined sub-path or collecting the target sub-path as the combined sub-path, and generating a definite sub-path of the target sub-path by using a cyclic path generation strategy.
In the above scheme, when the determining that the sub-path before the loop body and the set path of the determining sub-path are reachable, generating a test case includes:
and sequentially selecting a determining sub-path, collecting the cyclic body front sub-path and the determining sub-path as half sub-paths, and generating the test cases of the half sub-paths when the half sub-paths are determined to be reachable.
In the above scheme, the generating a complete test path of the tested code, generating a complete test case, and performing a coverage test of the complete test case on the tested code by using a preset coverage test criterion includes:
and collecting the sub paths in front of the loop body, determining the paths between the sub paths and the last loop body of the tested code to the exit node of the program control flow graph as a complete test path, generating a complete test case, and executing the coverage test of the complete test case on the tested code by using a preset coverage test criterion.
The invention also provides a system for processing the loop code in the software test, which comprises the following components: the device comprises a searching unit, a first determining unit, a second determining unit, a generating unit and a capturing unit; wherein,
the searching unit is used for searching a loop body of the tested code according to the program control flow graph;
the first determining unit is used for determining a circulation body front sub-path of the current circulation body;
the second determining unit is configured to determine all single sub-paths of the current loop body, combine the single sub-paths into a combined sub-path, and determine that the combined sub-path is the determined sub-path of the current loop body when a set path of the sub-path before the loop body and the combined sub-path is reachable;
the generating unit is used for generating a test case when the set paths of the front sub-path of the cycle body and the determined sub-path are determined to be reachable;
and the capturing unit is used for executing the tested code according to the test case and capturing the actual execution path of the current loop body.
In the above scheme, the system further comprises a test unit;
the test unit is used for generating a complete test path of the tested code after the actual execution paths of all the loop bodies of the tested code are captured, generating a complete test case, and executing the coverage test of the complete test case on the tested code by using a preset coverage test rule.
In the above scheme, the second determining unit is further configured to sequentially traverse nodes on the control flow graph of the code program to be tested, a set of traversed paths from the start node of the loop body to the end node of the loop body is all single sub-paths of the loop body, one single sub-path of the single sub-paths is sequentially selected as a target sub-path, other single sub-paths are reference sub-paths, and at least one reference sub-path and the target sub-path are collected as the combined sub-path or the target sub-path is collected as the combined sub-path, and a cyclic path generation strategy is used to generate the determined sub-path of the target sub-path.
The invention provides a processing method and a system of a loop code in a software test, which firstly search a loop body of a tested code according to a program control flow graph, determine a front sub-path of the loop body of the current loop body, then determine all single sub-paths of the current loop body, combine the single sub-paths into a combined sub-path, determine the combined sub-path as the determined sub-path of the current loop body when the set paths of the front sub-path of the loop body and the combined sub-path are reachable, then determine the front sub-path of the loop body and the set paths of the determined sub-paths as reachable, generate a test case, execute the tested code according to the test case, capture the actual execution path of the current loop body, repeat the steps until all loop bodies of the tested code are processed, and capture the actual execution paths of all loop bodies of the tested code, and generating a complete test path to carry out coverage test on the code to be tested. The invention can realize the comprehensiveness of generating the test path, has higher flexibility and does not need to manually appoint the test path; meanwhile, the reachability judgment is used for eliminating non-reachable paths and reserving reachable paths, so that processing resources can be saved, and the problem of path explosion in software testing is avoided.
Drawings
FIG. 1 is a schematic flow chart of an implementation of a method for processing loop codes in software testing according to the present invention;
FIG. 2 is a schematic diagram of a program control flow diagram in accordance with an embodiment of the present invention;
FIGS. 3(a) -3 (b) are schematic diagrams of embodiments of the present invention;
FIG. 4 is a schematic diagram of the structure of the loop code processing system in the software test according to the present invention.
Detailed Description
The invention provides a method for processing loop codes in software testing, which comprises the following steps of:
step 1: searching a loop body of the tested code according to the program control flow graph;
step 2: determining a circulation body front sub-path of a current circulation body;
and step 3: determining all single sub-paths of the current cycle body, combining the single sub-paths into a combined sub-path, and determining the combined sub-path as the determined sub-path of the current cycle body when the set path of the sub-path before the cycle body and the combined sub-path is reachable;
and 4, step 4: when the set paths of the sub paths before the cycle body and the determined sub paths are determined to be reachable, generating a test case;
and 5: and executing the tested code according to the test case, and capturing the actual execution path of the current loop body.
Further, after capturing the actual execution paths of all loop bodies of the code under test, the method further includes:
step 6: and generating a complete test path of the tested code, generating a complete test case, and executing a coverage test of the complete test case on the tested code by using a preset coverage test criterion.
Here, the coverage test criteria include: branch override, statement override, conditional override, etc.
In the above technical solution, the step 2 is a situation where the loop body of the code to be tested can be found, and when the loop body of the code to be tested cannot be found, the step 6 is continuously executed.
Further, the step 2 is as follows:
determining that a current loop body is a first loop body of a tested code and a path from an inlet node of a program control flow graph of the tested code to a current loop body starting point is reachable, and determining that a path from the inlet node of the program control flow graph to the current loop body starting point is a loop body front sub-path;
when the current loop body is determined to be the first loop body of the tested code and the path from the entry node of the program control flow graph of the tested code to the starting point of the current loop body is unreachable, the unreachable path is changed into a reachable path, and the reachable path is determined to be a loop body front sub-path;
determining that a current loop body is a non-first loop body of a tested code, and a loop body front sub-path of a last loop body of the tested code, a captured actual execution path of the last loop body, and a path from the last loop body of the tested code to the current loop body are new loop body front sub-paths, and when the new loop body front sub-paths are reachable, determining that the new loop body front sub-paths are loop body front sub-paths;
determining that the current loop body is a non-first loop body of the tested code, and collecting a loop body front sub-path of a last loop body of the tested code, a captured actual execution path of the last loop body, and a path from the last loop body of the tested code to the current loop body as a new loop body front sub-path, when the new loop body front sub-path is unreachable, changing the new loop body front sub-path into a reachable path, and determining that the new loop body front sub-path is a loop body front sub-path.
Here, the modifying the unreachable path into a reachable path and the modifying the new cycle body front sub-path into a reachable path mainly adopt a branch replacement mode.
Further, the step 3 is:
determining all single sub-paths of the current loop body as follows:
and traversing nodes on the control flow graph of the tested code program in sequence, wherein the set of the traversed paths from the start node of the loop body to the end node of the loop body is all single sub-paths of the loop body.
Here, the loop body start node is simply referred to as a loop body start point, and the loop body end node is simply referred to as a loop body end point.
The single sub-path is combined into a combined sub-path, and the sub-path determined that the combined sub-path is the current cycle body is determined as follows:
and sequentially selecting one single sub-path from all the single sub-paths as a target sub-path, taking other single sub-paths as reference sub-paths, and collecting at least one reference sub-path and the target sub-path as the combined sub-path or collecting the target sub-path as the combined sub-path, and generating the determined sub-path of the target sub-path by using a cyclic path generation strategy.
Further, the step 4 is:
and sequentially selecting a determining sub-path, collecting the cyclic body front sub-path and the determining sub-path as half sub-paths, and generating the test cases of the half sub-paths when the half sub-paths are determined to be reachable.
In step 5, the actual execution path of the current loop body is captured by identifying the code of the current loop body which is actually run.
Further, the step 6 is:
and collecting the sub-paths before the cycle body, determining the sub-paths and the sub-paths after the cycle body as complete test paths, generating a complete test case, and executing the coverage test of the complete test case on the code to be tested by using a preset coverage test criterion.
Here, the post-loop body sub-path is defined as a path from the last loop body of the code under test to an exit node of the program control flow graph.
Specifically, the step 2 is as follows:
here, the loop body front sub-path of the current loop body is represented by a prepath;
step 21: when the loop body of the tested code is found, further determining whether the current loop body is the first loop body of the tested code;
when the current loop body is determined to be the first loop body of the tested code, continuing to execute the step 22;
when the current loop body is determined not to be the first loop body of the tested code, continuing to execute the step 24;
step 22: determining whether a path from an inlet node of a program control flow graph of the tested code to a current loop body starting point is reachable;
when the determination is that the access is available, continuing to execute step 23;
when the determination result is that the user is not reachable, continuing to execute the step 27;
here, the reachability determination criterion is: all the variable values in the path are not null, and the path is considered to be reachable; if the value of at least one variable in the path is null, the path is considered to be unreachable; in the explanation of the technical solution, all the related reachable and unreachable decision meanings are the same as those in the above description, and are not described again.
Step 23: determining that a path from the inlet node to the starting point of the current cycle body is a pre path of the cycle body of the current cycle body, and ending the flow in the step 2;
step 24: the loop body front sub-path of the last loop body of the tested code, the actual execution path of the last loop body captured in the step 5 and the path from the last loop body of the tested code to the current loop body are integrated into a new loop body front sub-path, and the step 25 is continuously executed;
step 25: determining whether the new cycle body front sub-path is reachable;
when it is determined to be reachable, step 26 is performed;
when it is determined that the access is not available, step 27 is executed;
step 26: determining that the new cycle body front sub-path is a cycle body front sub-path prepath of the current cycle body (not the first cycle body), and ending the flow in the step 2;
step 27: reconstructing the unreachable path into a reachable path, determining that the reachable path is a loop body front sub-path prepath of the current loop body, and ending the flow in the step 2;
wherein, mainly adopt the branch replacement mode to reform the unreachable route into reachable route: and performing reverse-order traversal of the nodes from the position of the unreachable node on the program control flow graph, and performing branch replacement on other branch nodes in the path.
Specifically, the step 3 is as follows:
the determined sub-path determining that the combined sub-path is the current loop body is:
here, selecting a first single sub-path in the current cycle body as a current sub-path;
step 31: taking the current single sub-path as a target sub-path pathk, and taking other single sub-paths as reference sub-paths path1.. pathk-1;
here, the value of the iteration depth k is set to be equal to or less than the iteration depth threshold.
Step 32: and determining the generation of the sub-path of the target sub-path by utilizing a cyclic path generation strategy, selecting the next single sub-path in the current cyclic body as the current sub-path, and returning to the step 31 until all the single sub-paths of the current cyclic body are taken as the primary target sub-paths.
Here, the cyclic path generation strategy utilizes a depth-first principle:
step 321: initializing an iteration depth k, collecting a loop body front sub-path of a current loop body and the target sub-path as a collection path, and determining whether the collection path is reachable;
when the target sub-path is determined to be reachable, determining the target sub-path as a determined sub-path;
here, for convenience of description, a single target sub-path that does not involve other reference sub-paths may also be a combined sub-path;
if not, go to step 322;
step 322: the iteration depth k is added by 1, and in the current iteration depth, a single sub-path (reference sub-path) path1 of the first execution loop body is collected, the single sub-path (reference sub-path) pathk-1 of the k-1 th execution loop body and a target sub-path (sub-path pathk of the k-th execution loop body) are combined sub-paths; a set path of the front sub-path of the combined cycle body is a set path, and whether the set path is reachable or not is determined;
when the combined sub-path is reachable, determining the combined sub-path as a determined sub-path;
if not, continue to step 322 until the iteration depth k is the iteration depth threshold (maximum).
Here, the iteration depth threshold is established according to the needs of the engineering project.
Specifically, the step 4 is as follows:
here, selecting the current determined sub-path as a first determined sub-path;
step 41: collecting the front sub-path of the loop body of the current loop body and the current determination sub-path as half sub-paths, and determining whether the half sub-paths are reachable;
when the test case is determined to be reachable, generating the test case of the half sub-path;
if it is determined to be unreachable, go to step 42;
step 42: and selecting the next determined sub-path as the current determined sub-path, and returning to the step 41 until all the determined sub-paths of the current cycle body are processed.
The following describes the technical solution of the present invention in detail by taking a cycle body as the first cycle body Cyc1 of the code Program to be tested, an initial value of the iteration depth k is 1, an iteration depth threshold is 3, and the first cycle body Cyc1 has two branch nodes C and C'.
Setting a loop body starting node as a loop body starting point LoopHead and a loop body ending node as a loop body ending point LoopOut; the left child node of the branch node C is A, and the right child node of the branch node C is B; the left child node of the branch node C 'is A', and the right child node of the branch node C 'is B'; on the Program control flow graph of the code Program under test, the branch node C' is located before the branch node C.
The step 1 may specifically be: defining a queue for storing a loop body starting point LoopHead in a tested code Program; traversing nodes of a Program control flow graph of a tested code Program, pressing a loop body starting point into a queue when the loop body starting point is found, performing out-of-queue operation on elements (nodes which are already pressed into the queue) in the queue when a loop body end point Loopout corresponding to the loop body starting point LoopHead is found, and determining that the queue is empty at the moment, considering the elements which are just out of the queue as a loop body; here, the description of the nodes in the program control flow graph occurs in pairs, such as a loop body starting point LoopHead being for _ head and a corresponding loop body ending point LoopOut being for _ out; the loop body starting point LoopHead is while _ head and the corresponding loop body ending point LoopOut is while _ out.
The step 2 may specifically be: when the starting point of the first cycle body Cyc1 of the tested code Program is found, the Program control flow graph is traversed in a reverse order, namely, the entry node of the Program control flow graph is found from the starting point of the first cycle body Cyc1 to the direction of the entry node of the Program control flow graph, the entry node is found, and when the path from the entry node to the starting point of the first cycle body Cyc1 is determined to be reachable, the pre-cycle sub-path prepath of the first cycle body Cyc1 is determined to be the path from the entry node of the Program control flow graph of the tested code Program to the starting point of the first cycle body Cyc 1.
The step 3 may specifically be: in the above description, at least one path exists between the loop body start node LoopHead and the loop body end node LoopOut, so that at least one path exists that can traverse from the current loop body start node LoopHead to the current loop body end node LoopOut, which takes into account the existence of branch nodes on the program control flow graph. For the branch node, the following processing is performed in this embodiment:
defining a stack for storing all the single sub-paths of said first Cyc1 cycle body; when the nodes of the program control flow graph are not pushed into the stack, the nodes are marked as 'unaccessed';
fig. 2 is a schematic diagram of a program control flow graph according to a specific embodiment of the present invention, where each o represents a node, and when nodes of the program control flow graph are traversed and traversed nodes such as a branch node C ', a left child node a ' of the branch node C ', the branch node C, and a left child node a of the branch node C (referred to as C ' a ' CA) are sequentially pushed into a stack in combination with fig. 2, the nodes are identified as "visited"; the C 'A' CA is a first single sub-path;
when a second single sub-path of the first cycle body Cyc1 is searched for due to the characteristic of the stack that the stack is in first and then out, all nodes on the first single sub-path are subjected to out-of-stack operation, and the out-of-stack sequence is from the top element to the bottom element; therefore, the left child node a of the branch node C on the first single path is popped up, the left child node a is still marked as "visited", and when traversing to the branch node C, it is determined whether there are other child node marks as "not visited" in the branch node C, here, the right child node B of the branch node C is found as "not visited", the right child node B of the branch node C is pushed into the stack to form a second single sub-path C 'a' CB, the nodes on the second single sub-path are the same as the nodes on the first single sub-path except the child nodes of the branch node C;
when a third single sub-path is searched, all nodes on the second single sub-path are subjected to pop operation, and the right sub-node B of the branch node C is popped first and still marked as accessed; when traversing to the branch node C, determining whether the branch node C has other child nodes marked as 'not visited', wherein the branch node C only has two child nodes A and B, both the two child nodes A and B are already popped, the left child node A and the right child node B which are already popped are re-marked as 'not visited', and the branch node C is popped and marked as 'not visited'. Next, the left child node a ' of the branch node C ' is popped, and no reset operation is performed on the left child node a ' of the branch node C ', that is, no change is performed on the left child node a ' of the branch node C ' that has been popped, and the left child node a ' is still identified as "visited"; when traversing to the branch node C ', finding that a right child node B' identifier of the branch node C 'is' unaccessed ', pressing the right child node B' of the branch node C 'into a stack, and identifying as' accessed ', wherein the branch node C and a left child node A thereof which are positioned below the branch node C' are 'unaccessed', pressing the branch node C and the left child node A thereof into the stack, and identifying as 'accessed', so as to form a third single sub-path C 'B' CA;
when a fourth single sub-path is searched, performing pop operation on the nodes of the third single sub-path, performing pop operation on the left sub-node A of the branch node C, still marking the left sub-node A as visited, and when the left sub-node A of the branch node C is searched to be traversed to the branch node C, marking the right sub-node B of the branch node C as not visited, pressing the right sub-node B of the branch node C into the stack to form a fourth single sub-path C 'B' CB;
by analogy, all the single sub-paths of the first cycle body Cyc1 can be found.
Fig. 3(a) -3 (b) illustrate a specific embodiment of the implementation method of the present invention, and in this embodiment, the process and step 4 of determining the stator path of the first cycle volume Cyc1 may specifically be:
as shown in fig. 3(a), all the single sub-paths found in the first cycle volume Cyc1 are: a single sub-path p1, a single sub-path p2, a single sub-path p3, and a single sub-path p 4.
As shown in fig. 3(b), the single sub-path p1 is used as the target sub-path, and the other single sub-paths p2, p3, and p4 are used as the reference sub-paths, so that the determination sub-paths are generated.
Step 3211: setting the iteration depth k to 1, and determining whether a set path of a cycle body pre sub-path prepath of the first cycle body Cyc1 and the target sub-path p1 is reachable;
when the target sub-path p1 is determined to be reachable, the step 411 is continued;
when the determination is not reachable, step 3221 is executed;
step 3221: tracing back to a reference sub-path p2(path1), adding 1 to the iteration depth, that is, k is 2, aggregating the reference sub-path p2(path1) and the target sub-path p1 (path) into a p2p1 combined sub-path, and determining whether an aggregate path of the loop body pre-sub-path and the p2p1 combined sub-path is reachable;
when the combined subpath is determined to be reachable, determining the p2p1 combined subpath as a determined subpath, and continuing to execute the step 411;
when the determination is not reachable, continue to execute step 3222;
step 3222: adding 1 to the iteration depth, namely k is 3, aggregating the reference sub-path p2(path1), the reference sub-path p2(path2) and the target sub-path p1 (path) into a p2p2p1 sub-path, and determining whether an aggregation path of a sub-path combined by the loop body pre-sub-path and the p2p2p1 is reachable;
when the combined sub-path is determined to be reachable, determining the p2p2p1 combined sub-path as a determined sub-path, and continuing to execute step 411;
when the determination is that the user is not reachable, the step 3223 is continuously executed;
step 3223: the iteration depth k is 3, the reference sub-path p2(path1), the reference sub-path p3(path2) and the target sub-path p1 (path) are aggregated to be a p2p3p1 combined sub-path, and whether the aggregated path of the loop body pre-sub-path and the p2p3p1 combined sub-path is reachable or not is determined;
when the determination is reachable, determining the combined p2p3p1 sub-path as a determined sub-path, and continuing to execute step 411;
when the determination is that the user is not reachable, the step 3224 is continuously executed;
step 3224: the iteration depth k is 3, the reference sub-path p2(path1), the reference sub-path p4(path2) and the target sub-path p1 (path) are aggregated to be a p2p4p1 combined sub-path, and whether the aggregated path of the loop body pre-sub-path and the p2p4p1 combined sub-path is reachable or not is determined;
when the combined sub-path is determined to be reachable, determining the p2p4p1 combined sub-path as a determined sub-path, and continuing to execute step 411;
when it is determined that the sub path is not reachable, all combined sub paths in the current iteration depth (which is an iteration depth threshold) with the reference sub path p2, the reference sub path pn (n ═ 3 or 4), and the target sub path p1 as a set have been processed, and then step 3225 is executed;
step 3225: tracing back to a reference sub-path p3(path1), subtracting 1 from the iteration depth, namely k equals 2, and aggregating the reference sub-path p3(path1) and a target sub-path p1 (path) into a p3p1 combined sub-path to determine whether the p3p1 combined sub-path is reachable;
when the combined sub-path is determined to be reachable, determining the p3p1 combined sub-path as a determined sub-path, and continuing to execute step 411;
when the determination is not reachable, go to step 3226;
step 3226: adding 1 to the iteration depth, namely k is 3, aggregating the reference sub-path p3(path1), the reference sub-path p2(path2) and the target sub-path p1 (path) into a p3p2p1 combined sub-path, and determining whether an aggregate path of the loop body pre-sub-path and the p3p2p1 combined sub-path is reachable;
when the combined sub-path is determined to be reachable, determining the p3p2p1 combined sub-path as a determined sub-path, and continuing to execute step 411;
and so on until all the determination sub-paths in the first cycle body Cyc1 are determined;
step 411: collecting the pre-path of the cycle body of the first cycle body Cyc1 and the determining sub-path as half sub-paths, generating a test case of the half sub-paths when the half sub-paths are determined to be reachable, executing tested codes according to the test case, and capturing the actual execution path of the first cycle body Cyc1 by identifying actually-operated codes.
In this embodiment, as described above, when other loop bodies (a second loop body.. mth loop body, and M is a positive integer greater than 1) exist in the code Program to be tested, the process of determining all sub-paths of the other loop bodies and determining the sub-paths is similar to that of the first loop body, except that the value of the sub-path prepath before the loop body of the other loop body is slightly different from that of the sub-path before the loop body of the first loop body, which is specifically referred to steps 21 to 27 in the above technical solution.
After all the loop bodies of the code Program to be tested are processed according to the technical scheme, gathering the front sub-path of the loop body of the code Program to be tested, determining the sub-path and the back sub-path of the loop body to be complete test paths, generating a complete test case, and executing the coverage test of the complete test case on the code to be tested by utilizing a coverage test criterion, such as branch coverage, statement coverage and the like.
Here, the post-loop body sub-path is a path from the last loop body of the code Program under test to an exit node of the Program control flow graph.
In the invention, the loop bodies are all outermost loops of the tested code.
For the above method for processing loop code in software test, the present invention also describes a system for processing loop code in software test, as shown in fig. 4, the system includes: a search unit 400, a first determination unit 401, a second determination unit 402, a generation unit 403, and a capture unit 404; wherein,
the searching unit 400 is configured to search a loop body of the detected code according to the program control flow graph;
the first determining unit 401 is configured to determine a loop body front sub-path of a current loop body;
the second determining unit 402 is configured to determine all single sub-paths of the current loop body, combine the single sub-paths to form a combined sub-path, and determine that the combined sub-path is the determined sub-path of the current loop body when the set path of the sub-path before the loop body and the combined sub-path is reachable;
the generating unit 403 is configured to generate a test case when the set path of the loop body front sub-path and the determined sub-path is reachable;
the capturing unit 404 is configured to execute the tested code according to the test case, and capture an actual execution path of the current loop body.
Wherein the system further comprises a test unit 405;
the capturing unit 404 captures the actual execution paths of all loop bodies of the code to be tested, and then the testing unit 405 is configured to generate a complete test path of the code to be tested, generate a complete test case, and execute a coverage test of the complete test case on the code to be tested by using a preset coverage test criterion.
Here, the coverage test criteria include branch coverage, statement coverage, condition coverage, and the like.
Further, the searching unit 400 searches for a loop body of the code to be tested according to the program control flow graph of the code to be tested, and when the loop body of the code to be tested is found, the first determining unit 401 is notified, and the first determining unit 401 determines whether the current loop body is the first loop body of the code to be tested.
When the first determining unit 401 determines that the current loop body is the first loop body of the tested code and determines that a path from an entry node of a program control flow graph of the tested code to a current loop body starting point is reachable, it determines that a path from the entry node of the program control flow graph to the current loop body starting point is a loop body front sub-path of the current loop body;
when the first determining unit 401 determines that the current loop body is the first loop body of the tested code and a path from an entry node of a program control flow graph of the tested code to a current loop body starting point is unreachable, the first determining unit adopts a branch replacement mode to change the unreachable path into a reachable path, and determines that the reachable path is a loop body front sub-path;
the first determining unit 401 determines that the current loop body is a non-first loop body of the code to be tested, the loop body front sub-path of the last loop body of the code to be tested is collected, the actual execution path of the last loop body captured by the capturing unit 404, and the path from the last loop body of the code to be tested to the current loop body are new loop body front sub-paths, and when the new loop body front sub-path is reachable, the new loop body front sub-path is determined to be a loop body front sub-path;
the first determining unit 401 determines that the current loop body is a non-first loop body of the code to be tested, the loop body front sub-path of the last loop body of the code to be tested is collected, the actual execution path of the last loop body captured by the capturing unit 404, and the path from the last loop body of the code to be tested to the current loop body are new loop body front sub-paths, when the new loop body front sub-path is unreachable, the new loop body front sub-path is changed into a reachable path, and the new loop body front sub-path is determined to be a loop body front sub-path;
here, the unreachable path is transformed into a reachable path by adopting a branch replacement mode: performing reverse-order traversal of the nodes from the position of the unreachable node on the program control flow graph, and performing branch replacement on other branch nodes in the path; the reachability determination criterion is: all the variable values in the path are not null, and the path is considered to be reachable; if the value of at least one variable in the path is null, the path is considered to be unreachable; in the present invention, all the meanings related to reachable and unreachable judgments are the same as those in the present invention, and are not described again.
The second determining unit 402 traverses nodes on the control flow graph of the tested code program in sequence, a set of at least one traversed path between a starting node of the loop body and an ending node of the loop body is all single sub-paths in the loop body, one single sub-path in the single sub-paths is sequentially selected as a target sub-path, other single sub-paths are sequentially selected as reference sub-paths, at least one reference sub-path and the target sub-path are combined as the combined sub-path, and a cyclic path generating strategy is used for generating the determined sub-path of the target sub-path.
Here, the loop body start node is simply referred to as a loop body start point, and the loop body end node is simply referred to as a loop body end point.
The generating unit 403 sequentially selects a determined sub-path, collects the cyclic body front sub-path and the determined sub-path as half sub-paths, and generates a test case of the half sub-paths when the half sub-paths are determined to be reachable.
The capturing unit 404 captures an actual execution path of the current loop body by identifying a code of the current loop body that is actually run, and sends the captured actual execution path of the current loop body to the first determining unit 401, so as to assign a value to a loop body front sub-path of a next loop body of the current loop body.
After the first determining unit 401, the second determining unit 402, the generating unit 403, and the capturing unit 404 capture the actual execution paths of all loop bodies of the code under test, the testing unit 405 is notified, the testing unit 405 collects the sub paths before the loop bodies, the determining sub paths, and the sub paths after the loop bodies as complete testing paths, generates a complete testing case, and performs a coverage test of the complete testing case on the code under test by using a coverage testing criterion.
Here, the loop body back sub-path is a path from the last loop body of the code under test to an exit node of the program control flow graph.
The invention provides a method and a system for processing a loop code in a software test, which mainly perform the following processing on a loop body in a tested code: firstly, searching a loop body of a tested code according to a program control flow graph, determining a front sub-path of the loop body, then determining all single sub-paths of the current loop body, combining the single sub-paths to form a combined sub-path, and determining the combined sub-path to be the determined sub-path of the current loop body when a set path of the front sub-path of the loop body and the combined sub-path is reachable; and then, collecting paths of the sub-paths in front of the loop body and the determined sub-paths as half sub-paths, generating test cases of the half sub-paths when the half sub-paths are determined to be reachable, executing the tested codes according to the test cases, capturing the actual execution paths of the loop body, generating complete test paths and complete test cases after all loop bodies of the tested codes are processed according to the method, and executing the coverage test of the complete test cases on the complete test paths. Different from the 0-1 strategy and the 0-K strategy in the prior art, the method can generate all possible paths of the loop body, carry out accessibility judgment on all the generated possible paths, and can eliminate non-accessible paths and reserve accessible paths, so that on one hand, a test path can be generated more comprehensively, and on the other hand, waste of tested code processing resources and path explosion are avoided; meanwhile, compared with the existing method for manually specifying the test path, the method saves labor and obviously improves the flexibility.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention.
Claims (8)
1. A method for processing loop codes in software testing, which is characterized by comprising the following steps:
searching a loop body of the tested code according to the program control flow graph;
determining a circulation body front sub-path of a current circulation body;
the circulation body front sub-path comprises any one of the following parts:
when the current loop body is the first loop body of the tested code and the path from the inlet node of the program control flow graph of the tested code to the starting point of the current loop body is reachable, the path from the inlet node of the program control flow graph to the starting point of the current loop body is a sub-path before the loop body;
when the current loop body is the first loop body of the tested code and the path from the entry node of the program control flow graph of the tested code to the starting point of the current loop body is unreachable, changing the unreachable path into a reachable path, wherein the reachable path is a front sub-path of the loop body;
when the new loop body front sub-path is reachable, the new loop body front sub-path is a loop body front sub-path;
when the new cycle body front sub-path is unreachable, the new cycle body front sub-path is changed into a reachable path, and the new cycle body front sub-path changed into the reachable path is the cycle body front sub-path;
determining all single sub-paths of a current cycle body, combining the single sub-paths to form a combined sub-path, determining the combined sub-path to be the determined sub-path of the current cycle body when the set paths of the sub-paths before the cycle body and the combined sub-path are reachable, wherein all the single sub-paths of the cycle body are sets of paths from a cycle body starting node to a cycle body ending node, which are traversed by nodes on a control flow graph of a tested code program in sequence;
when the set paths of the sub paths before the cycle body and the determined sub paths are determined to be reachable, generating a test case;
and executing the tested code according to the test case, and capturing the actual execution path of the current loop body.
2. The method for processing loop code in software test according to claim 1, further comprising:
and after the actual execution paths of all the loop bodies of the tested code are captured, generating a complete test path of the tested code, generating a complete test case, and executing the coverage test of the complete test case on the tested code by using a preset coverage test criterion.
3. The method for processing loop code in software testing according to claim 1, wherein said combining the single sub-path into a combined sub-path, and determining that the combined sub-path is a determined sub-path of the current loop body comprises:
and sequentially selecting one single sub-path from all the single sub-paths as a target sub-path, taking other single sub-paths as reference sub-paths, and collecting at least one reference sub-path and the target sub-path as the combined sub-path or collecting the target sub-path as the combined sub-path, and generating a definite sub-path of the target sub-path by using a cyclic path generation strategy.
4. The method for processing loop code in software testing according to claim 1, wherein when the loop pre-body sub-path and the set path of the determined sub-path are determined to be reachable, generating a test case comprises:
and sequentially selecting a determining sub-path, collecting the cyclic body front sub-path and the determining sub-path as half sub-paths, and generating the test cases of the half sub-paths when the half sub-paths are determined to be reachable.
5. The method for processing the loop code in the software test according to any one of claims 2 to 4, wherein the generating a complete test path of the code to be tested, generating a complete test case, and performing the coverage test of the complete test case on the code to be tested by using a preset coverage test criterion includes:
and collecting the sub paths in front of the loop body, determining the paths between the sub paths and the last loop body of the tested code to the exit node of the program control flow graph as a complete test path, generating a complete test case, and executing the coverage test of the complete test case on the tested code by using a preset coverage test criterion.
6. A system for processing loop code in software testing, the system comprising: the device comprises a searching unit, a first determining unit, a second determining unit, a generating unit and a capturing unit; wherein,
the searching unit is used for searching a loop body of the tested code according to the program control flow graph;
the first determining unit is configured to determine a loop body front sub-path of a current loop body, where the loop body front sub-path includes any one of:
when the current loop body is the first loop body of the tested code and the path from the inlet node of the program control flow graph of the tested code to the starting point of the current loop body is reachable, the path from the inlet node of the program control flow graph to the starting point of the current loop body is a sub-path before the loop body;
when the current loop body is the first loop body of the tested code and the path from the entry node of the program control flow graph of the tested code to the starting point of the current loop body is unreachable, changing the unreachable path into a reachable path, wherein the reachable path is a front sub-path of the loop body;
when the new loop body front sub-path is reachable, the new loop body front sub-path is a loop body front sub-path;
when the new cycle body front sub-path is unreachable, the new cycle body front sub-path is changed into a reachable path, and the new cycle body front sub-path changed into the reachable path is the cycle body front sub-path;
the second determining unit is configured to determine all single sub-paths of the current loop body, combine the single sub-paths to form a combined sub-path, determine that the combined sub-path is the determined sub-path of the current loop body when a set path of the sub-path before the loop body and the combined sub-path is reachable, where all the single sub-paths of the loop body are sets of paths from a start node to an end node of the loop body, where the nodes on the control flow graph of the tested code program are sequentially traversed, and the traversed start node of the loop body is a node on the control flow graph of the tested code program;
the generating unit is used for generating a test case when the set paths of the front sub-path of the cycle body and the determined sub-path are determined to be reachable;
and the capturing unit is used for executing the tested code according to the test case and capturing the actual execution path of the current loop body.
7. The system for processing loop code in software testing according to claim 6, wherein said system further comprises a test unit;
the test unit is used for generating a complete test path of the tested code after the actual execution paths of all the loop bodies of the tested code are captured, generating a complete test case, and executing the coverage test of the complete test case on the tested code by using a preset coverage test rule.
8. The system according to claim 6 or 7, wherein the second determining unit is further configured to sequentially traverse nodes on the control flow graph of the code program under test, a set of traversed paths from a start node of a loop body to an end node of the loop body is all single sub-paths of the loop body, one of the single sub-paths is sequentially selected as a target sub-path, other single sub-paths are reference sub-paths, at least one of the reference sub-paths and the target sub-path are set as the combined sub-path, or the target sub-path is set as the combined sub-path, and the determined sub-path of the target sub-path is generated by using a loop path generation policy.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310113328.XA CN103207833B (en) | 2013-04-02 | 2013-04-02 | The disposal route of loop code and system in software test |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310113328.XA CN103207833B (en) | 2013-04-02 | 2013-04-02 | The disposal route of loop code and system in software test |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103207833A CN103207833A (en) | 2013-07-17 |
CN103207833B true CN103207833B (en) | 2016-04-06 |
Family
ID=48755062
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310113328.XA Expired - Fee Related CN103207833B (en) | 2013-04-02 | 2013-04-02 | The disposal route of loop code and system in software test |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103207833B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116302994B (en) * | 2023-02-28 | 2023-10-10 | 浙江大学 | Hierarchical matching method, device and equipment for program paths and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6694456B1 (en) * | 1997-12-09 | 2004-02-17 | Siemens Aktiengesellschaft | Method for checking path coverage in software tests |
CN102073587A (en) * | 2010-12-27 | 2011-05-25 | 北京邮电大学 | Static detection method for inaccessible route in program |
-
2013
- 2013-04-02 CN CN201310113328.XA patent/CN103207833B/en not_active Expired - Fee Related
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6694456B1 (en) * | 1997-12-09 | 2004-02-17 | Siemens Aktiengesellschaft | Method for checking path coverage in software tests |
CN102073587A (en) * | 2010-12-27 | 2011-05-25 | 北京邮电大学 | Static detection method for inaccessible route in program |
Non-Patent Citations (3)
Title |
---|
BPEL4WS Unit Testing:Test case generation using a concurrent path analysis Approach;Jun Yan等;《17th International Symposium on Software Reliablity Engineering(ISSRE"06)》;20061130;第75-84页 * |
单元覆盖测试中基于区间运算的路径选择;王思岚等;《清华大学学报(自然科学版) 》;20111031;第51卷(第S1期);第1402-1413页 * |
基于Z路径覆盖的测试用例自动生成技术研究;夏辉等;《软件技术》;20060331(第3期);第92-94页 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116302994B (en) * | 2023-02-28 | 2023-10-10 | 浙江大学 | Hierarchical matching method, device and equipment for program paths and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN103207833A (en) | 2013-07-17 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107193899B (en) | A kind of strongly connected graph division methods that nomography is friendly | |
US9426177B2 (en) | Method and apparatus for detecting security vulnerability for animation source file | |
KR101981028B1 (en) | System for detecting security vulnerability based on binary, method and program thereof | |
CN102253889B (en) | Method for dividing priorities of test cases in regression test based on distribution | |
Forejt et al. | Incremental runtime verification of probabilistic systems | |
WO2015007166A1 (en) | Method and apparatus for detecting security vulnerability for animation source file | |
JP2012099111A (en) | Node computation initialization technique for efficient parallelization of software analysis in distributed computing environment | |
RU2011131824A (en) | SEARCH INTRA MODE FOR VIDEO INFORMATION ENCODING | |
JP5845810B2 (en) | Efficient partial computation for parallel analysis of software in distributed computing environments | |
CN103207833B (en) | The disposal route of loop code and system in software test | |
Slaby et al. | Compact symbolic execution | |
US10474442B2 (en) | Methods and apparatus to perform region formation for a dynamic binary translation processor | |
US10009151B2 (en) | Packet storage method, information processing apparatus, and non-transitory computer-readable storage medium | |
US9880923B2 (en) | Model checking device for distributed environment model, model checking method for distributed environment model, and medium | |
CN103678121A (en) | Testing case priority ordering method for embedded binary system software | |
Doungsa-Ard et al. | GA-based automatic test data generation for UML state diagrams with parallel paths | |
Rungta et al. | Generating counter-examples through randomized guided search | |
CN113900662A (en) | LLVM compiling option selection method | |
Wu et al. | A path-oriented approach to generating executable test sequences for extended finite state machines | |
US20200050438A1 (en) | Object graph traversal and processing | |
CN110457046B (en) | Disassembles method, disassembles device, storage medium and disassembles terminal for hybrid instruction set programs | |
CN111026713B (en) | Search system, data search method and operation time determination method | |
CN105159835A (en) | Pile inserting position obtaining method based on global superblock domination graph | |
CN104317572A (en) | Circulation boundary inward direction analysis method of real-time system | |
Chen et al. | The role of operation granularity in search-based learning of latent tree models |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20160406 |