A hybrid execution test optimization method and device based on constraint partitioning

By segmenting the constraints into parts suitable for random generation and SMT solution in hybrid execution tests, and using graph segmentation and timeout prediction techniques, the problem of low constraint solution efficiency in the existing technology is solved, and more efficient test case generation and Improved efficiency of hybrid execution tests.

CN114706761BActive Publication Date: 2024-12-10NAT UNIV OF DEFENSE TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210259506.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-16
Publication Date
2024-12-10
Estimated Expiration
2042-03-16

AI Technical Summary

Technical Problem

Existing hybrid execution testing techniques have problems with inefficiency in constraint solution, especially when dealing with complex data structures and operations, resulting in complex path constraint generation and slow constraint resolution.

Method used

Using a method based on constraint segmentation, the constraints to be solved are divided into parts suitable for solving using random generation technology and parts suitable for solving using SMT solution technology, and the most suitable method is used for solving them, and the variable relationship diagram is constructed and the graph is performed. Segmentation, using timeout prediction to identify subconstraints that may cause timeouts, combined with depth-first search strategy and cluster graph segmentation algorithm to optimize constraint solution.

Benefits of technology

A more fine-grained combination of random testing and symbol execution methods is realized, which improves the efficiency of test case generation, makes full use of the advantages of the two methods, improves the efficiency of hybrid execution tests, and avoids performance degradation during constraint solution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114706761B_ABST
    Figure CN114706761B_ABST
Patent Text Reader

Abstract

The present invention discloses a hybrid execution test optimization method and device based on constraint partitioning, the steps include: constructing an initial input or randomly generating an initial input according to the solution provided by the constraint solver to perform specific execution on the tested program; performing symbolic execution along the specific path of program input execution, collecting path constraints, using a search strategy to generate new constraints to be solved and constructing a variable relationship graph, partitioning the variable relationship graph to obtain a subgraph set; generating a sub-constraint set based on the subgraph set, making a timeout prediction for each sub-constraint, generating a sub-constraint set predicted to be non-timeout and a sub-constraint set predicted to be timeout; using an SMT solution method to solve the sub-constraint set that does not timeout, using a random generation method to solve the sub-constraint set that timeouts, obtaining a solution to the original constraint, and generating a new program input according to the solution result. The present invention combines random testing and symbolic execution methods in a more fine-grained manner, and can improve the efficiency of hybrid execution testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of hybrid execution testing in program testing, and in particular to a hybrid execution testing optimization method and device based on constraint partitioning. Background Art

[0002] Program testing is an act of discovering vulnerabilities in a program by constructing and executing test cases, with the aim of improving the quality and reliability of the program. As a key link in the traditional program development process, a considerable portion of the program development cost is spent on program testing, and the industry needs to invest a lot of money and manpower in the testing link every year. The biggest challenge in program testing is how to efficiently generate high-quality test cases, that is, test cases that can achieve high coverage. At present, test cases are generally generated manually, which has the problems of high labor costs, low generation efficiency and low test case quality. To solve this problem, an effective way is program automatic testing, which realizes the automatic generation of test cases through program means. At present, there are some effective program automatic testing technologies, such as random testing, symbolic execution and hybrid execution testing.

[0003] Random testing generates program inputs in a random way and is the most direct automated testing method. The cost of generating test cases in random testing is very low, and a large number of test cases can be generated in a short time. However, these test cases often have the disadvantage of high similarity and are difficult to cover different areas of the program. Symbolic execution is an automated testing method that is opposite to random testing. It simulates the execution of the program after symbolizing the program input, collects path constraints during the execution process, and obtains the specific input of the program after solving the constraints. Symbolic execution can effectively cover different areas of the program, but is limited by the high cost of constraint solving. Generally speaking, in the symbolic execution process, an SMT solver is needed to solve the path constraints to generate the next input, that is, the constraint solving problems in symbolic execution are all SMT solving problems, and the current SMT solvers have serious performance problems when solving SMT formulas of array, floating point and other theories, which seriously restricts the performance of symbolic execution. Random testing and symbolic execution are two complementary testing technologies. If the two methods of random testing and symbolic execution can be fully combined, the advantages of both can be combined while making up for their respective shortcomings to form a new hybrid testing method.

[0004] Some practitioners have proposed to combine random testing and symbolic execution in the hope of forming a hybrid testing method that combines the advantages of both. However, this type of hybrid testing that combines machine testing and symbolic execution is usually only a coarse-grained combination, in which random testing and symbolic execution are executed separately and independently, and cannot fully utilize the information generated during their respective execution processes to improve their respective execution efficiency. For example, the general testing process that combines random testing and symbolic execution in the prior art is: randomly generate the initial input of the program under test, based on this input, the program under test can be specifically executed, and at the same time, symbolic execution is performed along the specific execution path, and path constraints are collected; after the current path constraints are collected, the path constraints are reversed according to a certain search strategy to generate new constraints, and new program inputs can be obtained after solving; if the new constraints are unsatisfiable, or when path divergence occurs, the next input is still generated by random testing, that is, the specific values ​​in each program input are either completely randomly generated by the random testing method, or completely generated by the constraint solution in symbolic execution, and random testing and symbolic execution are executed independently. However, the coarse-grained combination of independent execution of random testing and symbolic execution testing still cannot completely solve the serious performance problems of SMT solvers when solving SMT formulas of array, floating point and other theories, so there is still the problem of low efficiency in constraint solving.

[0005] In summary, the testing methods in the prior art, even the hybrid execution methods combining random testing and symbolic execution, still rely heavily on the efficiency of constraint solving and have the problem of low solving efficiency. As for real programs, complex data structures and operations are often widely used in the programs. Using traditional testing methods to analyze such programs with complex structures and operations will generate complex path constraints, which will still lead to very slow constraint solving and serious efficiency problems. Summary of the invention

[0006] The technical problem to be solved by the present invention is: in response to the technical problems existing in the prior art, the present invention provides a hybrid execution test optimization method and device based on constraint partitioning, which can fully combine random testing and symbolic execution methods at a finer granularity, improve the efficiency of generating high-quality test cases, and thus improve the efficiency of hybrid execution testing.

[0007] In order to solve the above technical problems, the technical solution proposed by the present invention is:

[0008] A hybrid execution test optimization method based on constraint partitioning, comprising:

[0009] Step S1. Program input: construct an initial program input according to the solution provided by the constraint solver, or randomly generate an initial program input, and input it into the program under test to perform specific execution on the program under test;

[0010] Step S2. Constraint collection: perform symbolic execution along the specific path of program input execution, collect path constraints and use the preset search strategy to generate new constraints to be solved;

[0011] Step S3. Constraint segmentation: construct a variable relationship graph for the new constraint to be solved, and segment the variable relationship graph to obtain a subgraph set of the variable relationship graph; generate a corresponding sub-constraint set based on the subgraph set, make a timeout prediction for each sub-constraint, and generate a sub-constraint set predicted to not time out and a sub-constraint set predicted to time out;

[0012] Step S4. Constraint solving: Use the SMT solving method to solve the sub-constraint set that does not time out, and use the random generation method to solve the sub-constraint set that times out, to obtain the solution of the original constraint, and generate a new program input based on the solution results.

[0013] Furthermore, the preset search strategy is a depth-first search strategy (DFS).

[0014] Furthermore, the step of constructing a variable relationship graph for the new constraint to be solved is: scanning all atomic constraints in the new constraint, setting the nodes of the variable relationship graph according to the variables that have appeared in all atomic constraints, setting the edges of the variable relationship graph according to the association relationship between variables, and setting the weights on the edges in the variable relationship graph according to the number of times two variables appear in the atomic constraints at the same time, wherein if the two variables do not appear in any atomic constraint at the same time, the weight is configured to 0.

[0015] Furthermore, in step S3, a clustering-based graph segmentation algorithm is used to segment the variable relationship graph.

[0016] Furthermore, the step of making a timeout prediction for each sub-constraint in step S3 includes:

[0017] Step S31. Offline training: Collect the benchmark set of SMT formula in advance, train the benchmark set, determine whether it is timed out and mark it after each feature vector is extracted during training, and obtain a bag-of-words model through training;

[0018] Step S32. Online prediction: for each of the sub-constraints, extract the feature vector of the sub-constraint and pass it to the bag-of-words model, and the bag-of-words model gives a prediction of whether it is timed out or not.

[0019] Furthermore, the specific steps of extracting the feature vector in step S31 are:

[0020] Step S311. Determine the vocabulary set: take all possible node types in the AST tree of the SMT formula as the vocabulary set;

[0021] Step S312. Bag-of-words initialization: construct a vector with a dimension equal to the size of the vocabulary set as the bag-of-words. Each element in the vector represents the number of occurrences of each node type. In the initial state, the number of occurrences of all node types is 0.

[0022] Step S313. Vocabulary statistics: traverse the AST (Abstract Syntax Tree) tree of the SMT formula, calculate the number of times each node type appears in the tree and update the vector, and finally obtain the feature vector.

[0023] Furthermore, the specific steps of step S4 are:

[0024] Step S41. Use SMT to solve the first conjunction PC of the sub-constraint set that does not time out c , when the solution result is unsatisfiable or unknown, the solution result of the original constraint is also unsatisfiable or unknown; otherwise, when the solution result is satisfiable, the first solution S is obtained. c ;

[0025] Solve the second conjunctive PC of the timed-out sub-constraint set using a random generation method r , when solving, first determine the second conjunction PC r Combined with the first PC c Is there a common variable between them? If so, then the first solution S c The value of the common variable in is assigned to the second conjunction PC r If no solution is found using the random generation method within the given time limit, the solution result of the original constraint is determined to be unknown; otherwise, the second solution S is obtained. r ;

[0026] Step S42. Solve the first solution S c And the second solution S r The merging is performed to obtain the final solution of the original constraints.

[0027] The present invention also provides a hybrid execution test optimization device based on constraint partitioning, comprising a hybrid executor, wherein the hybrid executor comprises:

[0028] An input construction module is used to construct an initial program input according to the solution provided by the constraint solver, or randomly generate an initial program input, and input it into the tested program to perform specific execution on the tested program;

[0029] The constraint collection module is used to perform symbolic execution along the specific path of program input execution, collect path constraints and use preset search strategies to generate new constraints to be solved;

[0030] A constraint segmentation module is used to construct a variable relationship graph for the new constraint to be solved, and segment the variable relationship graph to obtain a subgraph set of the variable relationship graph; generate a corresponding sub-constraint set based on the subgraph set, make a timeout prediction for each sub-constraint, and generate a sub-constraint set predicted to not time out and a sub-constraint set predicted to time out;

[0031] The constraint solving module is used to solve the sub-constraint set that does not time out using the SMT solving method, and to solve the sub-constraint set that times out using the random generation method, to obtain the solution of the original constraint, and to generate a new program input according to the solution result.

[0032] The present invention also provides a hybrid execution test optimization device based on constraint partitioning, comprising a processor and a memory, wherein the memory is used to store a computer program, the processor is used to execute the computer program, and the processor is used to execute the computer program to execute the hybrid execution test optimization method based on constraint partitioning as described above.

[0033] The present invention also provides a computer-readable storage medium, in which a computer program is stored for being executed by a computer device to implement the above-mentioned hybrid execution test optimization method based on constraint partitioning.

[0034] Compared with the prior art, the advantages of the present invention are:

[0035] 1. The present invention divides the constraints to be solved in the hybrid execution test into a part suitable for solving by random generation technology and a part suitable for solving by SMT solving technology, and then solves them respectively by the most appropriate method, and then combines the solutions to obtain the solutions to the constraints to be solved. This method combines random testing and symbolic execution methods in a finer-grained manner. This fine-grained combination can give full play to the advantages of the two methods and realize the improvement of the efficiency of hybrid execution testing.

[0036] 2. The present invention divides the variable relationship graph through a segmentation algorithm based on graph clustering, which can effectively divide similar constraints together, and then by combining timeout prediction, it can effectively identify the sub-constraints in the constraints to be solved that will cause timeouts, thereby better segmenting the constraints, making it possible to fully utilize the two solution methods of SMT solution and random solution to hybridly execute tests, further improving the test effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 It is a flowchart of the hybrid execution test optimization method based on constraint partitioning in this embodiment.

[0038] Figure 2 It is a schematic diagram of initial program input in a specific application embodiment of the present invention.

[0039] Figure 3 It is a schematic diagram of the generation principle of the variable relationship diagram in the specific application embodiment of the present invention. DETAILED DESCRIPTION

[0040] The present invention is further described below in conjunction with the accompanying drawings and specific preferred embodiments, but the protection scope of the present invention is not limited thereby.

[0041] Random testing has low cost in generating test cases and can generate a large number of test cases in a short time. However, test cases often have the disadvantage of high similarity and are difficult to cover different areas in the program. Symbolic execution can effectively cover different areas in the program, but symbolic execution requires an SMT solver when solving constraints. SMT solvers have serious performance issues when solving SMT formulas of array, floating point and other theories, resulting in solution timeouts. That is, SMT solvers will cause solution timeouts for constraints such as SMT formulas of array, floating point and other theories. If the constraints can be divided in advance according to whether the solution has timed out, the SMT solution method can be used to solve the sub-constraint set that does not time out, and the random generation method can be used to solve other sub-constraint sets that have timed out, the advantages of the two testing methods can be fully utilized, that is, they can cover different areas in the program as much as possible and avoid the performance degradation problem when solving constraints.

[0042] like Figure 1 As shown, the steps of the hybrid execution test optimization method based on constraint partitioning in this embodiment include:

[0043] Step S1. Program input: construct an initial program input according to the solution provided by the constraint solver, or randomly generate an initial program input, and input it into the program under test to perform specific execution on the program under test;

[0044] Step S2. Constraint collection: perform symbolic execution along the specific path of program input execution, collect path constraints and use the preset search strategy to generate new constraints to be solved;

[0045] Step S3. Constraint segmentation: construct a variable relationship graph for the new constraint to be solved, and segment the variable relationship graph to obtain a subgraph set of the variable relationship graph; generate a corresponding sub-constraint set based on the subgraph set, make a timeout prediction for each sub-constraint, and generate a sub-constraint set predicted to not time out and a sub-constraint set predicted to time out;

[0046] Step S4. Constraint solving: Use the SMT solving method to solve the sub-constraint set that does not time out, and use the random generation method to solve the sub-constraint set that times out, obtain the solution of the original constraint, and generate a new program input based on the solution results.

[0047] This embodiment divides the constraints to be solved in the hybrid execution test into a part suitable for solving with a random generation technology and a part suitable for solving with an SMT solving technology, and then solves them respectively with the most appropriate method, and then combines the solutions to obtain the solutions to the constraints to be solved. It can combine random testing and symbolic execution methods in a finer-grained manner. The fine-grained combination can give full play to the advantages of the two methods and improve the efficiency of hybrid execution testing.

[0048] In this embodiment, the preset search strategy can specifically adopt a depth-first search strategy (DFS), starting from a certain node v, and performing depth-first traversal through the unvisited adjacent nodes of the node v in sequence until all nodes with paths connected to the node v are visited. If there are still unvisited nodes, start from an unvisited node and re-perform the above-mentioned depth-first traversal until all nodes have been visited. By using the depth-first search strategy, all new constraints can be quickly generated.

[0049] In this embodiment, the steps of constructing a variable relationship graph for the new constraint to be solved are: scanning all atomic constraints in the new constraint, setting the nodes of the variable relationship graph according to the variables that appear in all atomic constraints, setting the edges of the variable relationship graph according to the association between the variables, and setting the weights on the edges in the variable relationship graph according to the number of times two variables appear in the atomic constraints at the same time, where if the two variables do not appear in any atomic constraint at the same time, the weight is configured to 0.

[0050] In this embodiment, the variable relationship graph is segmented by a clustering-based graph segmentation algorithm in step S3. The clustering-based graph segmentation algorithm is an algorithm widely used in deep learning sample classification tasks. By dividing the variable relationship graph based on the graph clustering segmentation algorithm, similar constraints can be effectively divided together. Then, by combining the timeout prediction, the sub-constraints that will cause timeouts in the constraints to be solved can be effectively identified, thereby better segmenting the constraints, making it possible to make full use of the two solution methods of SMT solution and random solution to perform mixed tests, further improving the test effect.

[0051] The nodes in the variable relationship graph are the variables that appear in the atomic constraints. The weighted edges in the graph are the number of times two variables (nodes) appear in all atomic constraints at the same time. If two variables do not have a common atomic constraint, the weight of the weighted edge between them is 0. Assuming that all nodes need to be divided into N categories, the specific steps of segmenting the variable relationship graph based on the clustering graph segmentation algorithm in this embodiment are as follows:

[0052] Step 1. Randomly select N cluster center nodes;

[0053] Step 2. Based on the current N central nodes, all nodes are divided into N categories using the number of intervals from the central node and the edge weight as a metric;

[0054] Step 3. Calculate the mean of the relevant edge weights of each type of sample point, and use the node closest to the mean feature in the classification as the cluster center of the next iteration;

[0055] Step 4. Calculate the mean feature difference between the cluster center of the next iteration and the current cluster center;

[0056] Step 5. If the feature gap is less than the given iteration threshold, the iteration ends, otherwise return to step S3.2 to continue the next round of iteration.

[0057] In this embodiment, the step of making a timeout prediction for each sub-constraint in step S3 includes:

[0058] Step S31. Offline training: Collect the benchmark set of SMT formula in advance, train the benchmark set, determine whether it has timed out and mark it after each feature vector is extracted during training, and obtain a bag-of-words model through training;

[0059] Step S32. Online prediction: For each sub-constraint, extract the feature vector of the sub-constraint and pass it to the bag-of-words model, which will predict whether it will time out.

[0060] The SMT solver will have serious performance problems when solving theoretical SMT formulas such as arrays and floating points. This embodiment collects SMT formulas for training in advance and generates a bag-of-words model. The bag-of-words model can characterize the characteristics of various SMT formulas. Therefore, after generating sub-constraints, the sub-constraints are matched with the trained bag-of-words model to determine whether they are SMT formulas. If they match, the prediction will time out, otherwise the prediction will not time out. The sub-constraints can be divided into two categories: timeout and non-timeout, so that matching solution methods can be used based on the characteristics of the two types of sub-constraints: sub-constraints that time out are solved using a random solution method, and sub-constraints that do not time out are solved using an SMT solution method, giving full play to the advantages of the two methods and greatly improving the efficiency of hybrid execution testing.

[0061] In this embodiment, the specific steps of extracting the feature vector in step S31 are:

[0062] Step S311. Determine the vocabulary set: take all possible node types in the AST tree of the SMT formula as the vocabulary set;

[0063] Step S312. Bag-of-words initialization: construct a vector with a dimension equal to the size of the vocabulary set as the bag-of-words. Each element in the vector represents the number of occurrences of each node type. In the initial state, the number of occurrences of all node types is 0.

[0064] Step S313. Vocabulary statistics: traverse the AST tree of the SMT formula, calculate the number of times each node type appears in the tree and update the vector, and finally obtain the feature vector.

[0065] In this embodiment, the specific steps of step S4 are:

[0066] Step S41. Use SMT to solve the first conjunction PC of the sub-constraint set that does not time out c , when the solution result is unsatisfiable or unknown, the solution result of the original constraint is also unsatisfiable or unknown; otherwise, when the solution result is satisfiable, the first solution S is obtained c ;

[0067] Solve the second conjunctive PC of the sub-constraint set that is out of time using a random generation method r , when solving, first determine the second conjunction PC r Combine with the first PC c Is there a common variable between them? If so, put the first solution S c The value of the common variable in the second conjunction PC is assigned to r If no solution is found using the random generation method within the given time limit, the solution of the original constraint is determined to be unknown; otherwise, the second solution S is obtained. r ;

[0068] Step S42. For the first solution S c and the second solution S r Merge to obtain the final solution of the original constraints.

[0069] This embodiment uses Figure 2 The present invention is further described by taking the program shown as an example. The program takes integer variables x and y as inputs, and the detailed steps are:

[0070] Step S1: randomly generate an initial input (x=1, y=0), and execute the tested program based on the initial input;

[0071] Step S2: Perform symbolic execution along the specific execution path to obtain the path constraints (x 7 >=0)∧(y=0), and generate new constraints to be solved (x 7 >=0)∧(y!=0).

[0072] Step S3: construct a variable relationship graph for the new constraint, and use a clustering-based graph segmentation algorithm to segment the variable relationship graph to obtain a subgraph set of the variable relationship graph. The variable relationship graph and the subgraph set are as follows: Figure 3 As shown;

[0073] Based on the subgraph set of the above variable relationship graph, the corresponding sub-constraint set {x 7 >=0,y!=0}, and make a timeout prediction for each sub-constraint, and obtain the sub-constraint set {y!=0} predicted as not timed out and the sub-constraint set {x 7 >=0};

[0074] Step S41: Use SMT solving technology to solve the conjunction PC of the sub-constraint set that does not time out c :y! = 0, the solution is satisfactory, and its solution is S c =(y=1);

[0075] Solving the Conjunctive PC of Timed Subconstraint Sets Using Random Generation Techniques r :x 7 >=0; due to PC r With PC c There are no common variables between them, so directly r In this embodiment, PC r The solution space is large, and the random generation technology can easily find a solution without exceeding the given time limit. The solution is S r =(x=1);

[0076] Step S42: Solve S c Settlement S r Merge and obtain the solution of the original constraint (x=1, y=1).

[0077] This embodiment also provides a hybrid execution test optimization device based on constraint partitioning, including a hybrid executor, the hybrid executor including:

[0078] An input construction module is used to construct an initial program input according to the solution provided by the constraint solver, or randomly generate an initial program input, and input it into the tested program to perform specific execution on the tested program;

[0079] The constraint collection module is used to perform symbolic execution along the specific path of program input execution, collect path constraints and use preset search strategies to generate new constraints to be solved;

[0080] The constraint segmentation module is used to construct a variable relationship graph for the new constraint to be solved, and segment the variable relationship graph to obtain a subgraph set of the variable relationship graph; generate a corresponding sub-constraint set based on the subgraph set, make a timeout prediction for each sub-constraint, and generate a sub-constraint set predicted to not time out and a sub-constraint set predicted to time out;

[0081] The constraint solving module is used to solve the sub-constraint set that does not time out using the SMT solving method, and to solve the sub-constraint set that times out using the random generation method, to obtain the solution of the original constraint, and to generate a new program input according to the solution result.

[0082] The hybrid execution test optimization device based on constraint partitioning in this embodiment corresponds one to one with the hybrid execution test optimization method based on constraint partitioning described above, and will not be described one by one here.

[0083] This embodiment also provides a hybrid execution test optimization device based on constraint partitioning, including a processor and a memory, the memory is used to store computer programs, the processor is used to execute the computer program, and the processor is used to execute the computer program to perform the above method.

[0084] This embodiment also provides a computer-readable storage medium, which stores a computer program for being executed by a computer device to implement the above-mentioned hybrid execution test optimization method based on constraint partitioning.

[0085] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, may be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the functions in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0086] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.

Claims

1. A hybrid execution test optimization method based on constraint partitioning, characterized in that: include: Step S1, program input: construct an initial program input according to the solution provided by the constraint solver, or randomly generate an initial program input, and input it to the tested program to perform specific execution on the tested program; Step S2, constraint collection: perform symbolic execution along the specific path of program input execution, collect path constraints and use preset search strategies to generate new constraints to be solved; Step S3, constraint segmentation: construct a variable relationship graph for the new constraint to be solved, and segment the variable relationship graph to obtain a subgraph set of the variable relationship graph; generate a corresponding sub-constraint set based on the subgraph set, make a timeout prediction for each sub-constraint, and generate a sub-constraint set predicted to not time out and a sub-constraint set predicted to time out; Step S4, constraint solving: using the SMT solving method to solve the sub-constraint set that does not time out, and using the random generation method to solve the sub-constraint set that times out, to obtain the solution of the original constraint, so as to generate a new program input according to the solution result; The step of making a timeout prediction for each sub-constraint in step S3 includes: Step S31, offline training: pre-collect a benchmark set of SMT formulas, train the benchmark set, determine whether it has timed out and mark it after extracting feature vectors each time during training, and obtain a bag-of-words model through training; Step S32, online prediction: for each of the sub-constraints, extract the feature vector of the sub-constraint and pass it to the bag-of-words model, and the bag-of-words model gives a prediction of whether it is timed out; The specific steps of extracting the feature vector in step S31 are: Step S311, determine the vocabulary set: take all possible node types in the AST tree of the SMT formula as the vocabulary set; Step S312, word bag initialization: construct a vector with a dimension equal to the size of the vocabulary set as a word bag, where each element in the vector represents the number of occurrences of each node type. In the initial state, the number of occurrences of all node types is 0; Step S313. Vocabulary statistics: traverse the AST tree of the SMT formula, calculate the number of times each node type appears in the tree and update the vector, and finally obtain the feature vector.

2. The hybrid execution test optimization method based on constraint partitioning according to claim 1 is characterized in that: The preset search strategy is the depth-first search strategy DFS.

3. The hybrid execution test optimization method based on constraint partitioning according to claim 1 is characterized in that: The step of constructing a variable relationship graph for the new constraint to be solved in step S3 is: scanning all atomic constraints in the new constraint, setting the nodes of the variable relationship graph according to the variables that have appeared in all atomic constraints, setting the edges of the variable relationship graph according to the association relationship between variables, and setting the weights of the edges in the variable relationship graph according to the number of times two variables appear in the atomic constraints at the same time, wherein if the two variables do not appear in any atomic constraint at the same time, the weight is configured to 0.

4. The hybrid execution test optimization method based on constraint partitioning according to claim 1 is characterized in that: In step S3, the variable relationship graph is segmented using a clustering-based graph segmentation algorithm.

5. The hybrid execution test optimization method based on constraint partitioning according to any one of claims 1 to 4, characterized in that: The specific steps of step S4 are: Step S41: Use SMT to solve the first conjunction PC of the sub-constraint set that does not time out c , when the solution result is unsatisfiable or unknown, the solution result of the original constraint is also unsatisfiable or unknown; otherwise, when the solution result is satisfiable, the first solution S is obtained. c ; Solve the second conjunctive PC of the timed-out sub-constraint set using a random generation method r , when solving, first determine the second conjunction PC r Combined with the first PC c Is there a common variable between them? If so, then the first solution S c The value of the common variable in is assigned to the second conjunction PC r If no solution is found using the random generation method within the given time limit, the solution result of the original constraint is determined to be unknown; otherwise, the second solution S is obtained. r ; Step S42: c And the second solution S r The merging is performed to obtain the final solution of the original constraints.

6. A hybrid execution test optimization device based on constraint partitioning, characterized in that: A hybrid actuator is included, wherein the hybrid actuator comprises: An input construction module is used to construct an initial program input according to the solution provided by the constraint solver, or randomly generate an initial program input, and input it into the tested program to perform specific execution on the tested program; The constraint collection module is used to perform symbolic execution along the specific path of program input execution, collect path constraints and use preset search strategies to generate new constraints to be solved; A constraint segmentation module is used to construct a variable relationship graph for the new constraint to be solved, and segment the variable relationship graph to obtain a subgraph set of the variable relationship graph; generate a corresponding sub-constraint set based on the subgraph set, make a timeout prediction for each sub-constraint, and generate a sub-constraint set predicted to not time out and a sub-constraint set predicted to time out; A constraint solving module, used to solve the sub-constraint set that does not time out using an SMT solving method, and to solve the sub-constraint set that times out using a random generation method, to obtain a solution to the original constraint, so as to generate a new program input according to the solution result; The constraint segmentation module comprises: An offline training unit is used to collect a benchmark set of SMT formulas in advance, train the benchmark set, determine whether a timeout occurs and mark it each time a feature vector is extracted during training, and obtain a bag-of-words model through training; An online prediction unit, for extracting a feature vector of each sub-constraint and transmitting the feature vector to the bag-of-words model, so that the bag-of-words model predicts whether a timeout has occurred; The offline training unit comprises: Determine a vocabulary set subunit, which is used to use all possible node types in the AST tree of the SMT formula as a vocabulary set; The bag-of-words initialization subunit is used to construct a vector with a dimension equal to the size of the vocabulary set as the bag-of-words. Each element in the vector represents the number of occurrences of each node type. In the initial state, the number of occurrences of all node types is 0. The vocabulary statistics subunit is used to traverse the AST tree of the SMT formula, calculate the number of times each node type appears in the tree and update the vector, and finally obtain the feature vector.

7. A hybrid execution test optimization device based on constraint partitioning, comprising a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to execute the computer program, characterized in that: The processor is used to execute the computer program to perform the hybrid execution test optimization method based on constraint partitioning as claimed in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for being executed by a computer device to implement the hybrid execution test optimization method based on constraint partitioning as described in any one of claims 1 to 5.