Test case generation method and device and electronic equipment

By calculating distance differences in branch nodes within a control flow graph, the method improves the accuracy and convergence of test case generation using genetic algorithms, addressing the complexity and inaccuracy issues in existing methods.

CN120315992APending Publication Date: 2025-07-15SUZHOU DONGCHAYUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410020783.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-05
Publication Date
2025-07-15

AI Technical Summary

Technical Problem

In the prior art, the program for generating test cases by genetic algorithms is complex and difficult to converge, resulting in inaccurate test cases.

Method used

By obtaining the coverage of branch nodes in the control flowchart of the objective function, the distance difference value of branch nodes is calculated, and the chromosomal fitness of the genetic algorithm is determined based on the distance difference value, and the input parameters are updated to generate a test case.

Benefits of technology

Improve the accuracy of genetic algorithms, accelerate algorithm convergence, and obtain higher test case coverage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120315992A_ABST
    Figure CN120315992A_ABST
Patent Text Reader

Abstract

The invention discloses a test case generation method and device and electronic equipment. The method comprises the following steps: operating an objective function by taking an input parameter of the objective function as a chromosome of a genetic algorithm, and obtaining a coverage condition of nodes in a first control flow chart (CFG) corresponding to the objective function; the nodes comprise branch nodes; the branch nodes correspond to selection statements or loop statements of the target function; determining a distance difference value according to at least one of an absolute value of a numerical difference between two sides of a judgment condition operator corresponding to the branch node, a coverage condition of the branch node and a coverage condition of a child node of the branch node; determining the fitness of the branch node according to the distance difference value; determining the updated parameter value of the input parameter according to the fitness of the branch node; and generating a test case of the target function according to the updated parameter value of the input parameter.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of testing, and in particular, to a test case generation method, apparatus, and electronic device. Background Art

[0002] A test case includes test inputs, execution conditions, and expected results prepared for a specific target (for example, testing a certain function of a service). The test case can be used to verify whether the service under test in the service system meets the service requirements. The test input is the data input to the code under test. The expected output is determined based on the input data and the program function. That is, for a certain program, once the input data is determined, the expected output can be determined.

[0003] A good test case set covers as many targets as possible with a smaller number of test cases, and ensures the balance of the test data distribution, so that the test cases are highly effective.

[0004] In the related art, a genetic algorithm is used to generate test cases. However, it is found that: in the related art, the program for generating test cases by the genetic algorithm is complex, the convergence is difficult, and even it cannot converge, resulting in inaccurate generated test cases. Summary of the Invention

[0005] In view of this, embodiments of this application provide a test case generation method, apparatus, and electronic device, aiming to reduce the generation complexity, calculation amount, or improve the quality of the generated test cases.

[0006] The technical solution of the embodiments of this application is implemented as follows:

[0007] In a first aspect, a test case generation method is provided, and the method includes:

[0008] Running the objective function with the input parameters of the objective function as the chromosomes of the genetic algorithm, and obtaining the coverage of the nodes in the first control flow graph (CFG) corresponding to the objective function; the nodes include branch nodes; the branch nodes correspond to the selection statements or loop statements of the objective function;

[0009] Determining a distance difference according to at least one of the absolute value of the difference between the numerical values on both sides of the judgment condition operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node;

[0010] Determining the fitness of the branch node according to the distance difference;

[0011] Determining the updated parameter value of the input parameter according to the fitness of the branch node;

[0012] Generate test cases for the objective function based on the parameter values updated according to the input parameters.

[0013] A second aspect provides a test case generation device, which includes:

[0014] An acquisition module, configured to run the objective function with the input parameters of the objective function as the chromosomes of the genetic algorithm, and acquire the coverage of the nodes in the first control flow graph CFG corresponding to the objective function; the nodes include branch nodes; the branch nodes correspond to the selection statements or loop statements of the objective function;

[0015] A first determination module, configured to determine a distance difference according to at least one of the absolute value of the difference between the values on both sides of the conditional operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node;

[0016] A second determination module, configured to determine the fitness of the branch node according to the distance difference;

[0017] An update module, configured to determine the parameter values after updating the input parameters according to the fitness of the branch node;

[0018] A generation module, configured to generate test cases for the objective function based on the parameter values after updating the input parameters.

[0019] A third aspect provides an electronic device, including: a processor and a memory for storing a computer program that can run on the processor, where

[0020] When the processor is used to run the computer program, it executes the steps of the test case generation method described in any of the first aspects.

[0021] A fourth aspect provides a computer-readable storage medium, where the computer storage medium stores one or more programs, and the one or more programs can be executed by one or more processors, so that the one or more processors execute the test case generation method provided in any technical solution of the first aspect.

[0022] The technical solution provided in the embodiments of the present application, when using the genetic algorithm to generate test cases, determines the distance difference according to the coverage of the branch node and its child nodes, and determines the fitness of the chromosomes of the genetic algorithm according to the distance difference. Practice has proved that this method can improve the accuracy of the algorithm, accelerate the convergence of the algorithm, and obtain test cases with higher coverage. Description of the Drawings

[0023] Figure 1A It is a schematic flowchart of the test case generation method provided in an embodiment of the present application;

[0024] Figure 1B CFG partial schematic diagram of the conditional statement provided by an embodiment of the present application;

[0025] Figure 1C is Figure 1B Schematic diagram in which all branch nodes and their child nodes of the conditional statement shown are covered.

[0026] Figure 1D is Figure 1B Coverage schematic diagram of the true branch of the conditional statement shown;

[0027] Figure 1E is Figure 1B Coverage schematic diagram of the false branch of the conditional statement shown;

[0028] Figure 2 Schematic diagram of an objective function provided by an embodiment of the present application;

[0029] Figure 3 provided by an embodiment of the present application and Figure 2 Schematic diagram of the first CFG corresponding to the objective function shown;

[0030] Figure 4 Schematic diagram of the process for generating updated input parameters provided by an embodiment of the present application;

[0031] Figure 5 provided by an embodiment of the present application Figure 2 Schematic diagram of the second CFG corresponding to the objective function shown;

[0032] Figure 6 Schematic diagram of the abstract syntax tree provided by an embodiment of the present application;

[0033] Figure 7 provided by an embodiment of the present application Figure 6 Schematic diagram after traversing the abstract syntax tree of;

[0034] Figure 8 provided by an embodiment of the present application Figure 6 CFG partial schematic diagram corresponding to the selection statement of the second CFG shown;

[0035] Figure 9 provided by an embodiment of the present application Figure 8 Schematic diagram of the sub-CFG of the CFG partial schematic diagram shown;

[0036] Figure 10 Effect schematic diagram of position marking on the CFG provided by an embodiment of the present application;

[0037] Figure 11CFG schematic diagram of the branch node corresponding to the selection statement provided by an embodiment of the present application;

[0038] Figure 12 CFG schematic diagram of the branch node corresponding to the loop statement provided by an embodiment of the present application;

[0039] Figure 13 Effect schematic diagram of position marking and depth level recording for CFG provided by an embodiment of the present application;

[0040] Figure 14 Schematic diagram of obtaining the reachable set provided by an embodiment of the present application;

[0041] Figure 15 Schematic diagram of obtaining the full path provided by an embodiment of the present application;

[0042] Figure 16 Schematic diagram of the first parameter information in the input parameter dictionary provided by an embodiment of the present application;

[0043] Figure 17 Flow schematic diagram of the test case generation method provided by an embodiment of the present application;

[0044] Figure 18 Iterative process schematic diagram of a genetic algorithm provided by an embodiment of the present application;

[0045] Figure 19 Iterative process schematic diagram of a genetic algorithm provided by an embodiment of the present application;

[0046] Figure 20 Iterative process schematic diagram of a genetic algorithm provided by an embodiment of the present application;

[0047] Figure 21 Schematic diagram of a CFG provided by an embodiment of the present application;

[0048] Figure 22 Schematic diagram of the source code provided by an embodiment of the present application;

[0049] Figure 23 Provided by an embodiment of the present application Figure 22 CFG coverage schematic diagram of the shown source code;

[0050] Figure 24 Provided by an embodiment of the present application Figure 22 Schematic diagram of the test case of the shown source code;

[0051] Figure 25 Schematic diagram of the source code provided by an embodiment of the present application;

[0052] Figure 26A 、 Figure 26Band Figure 26C For different parts of the coverage schematic diagram of the CFG of the source code provided by an embodiment of the present application Figure 22 as shown;

[0053] Figure 27A 、 Figure 27B and Figure 27C For different parts of the schematic diagram of the test case of the source code provided by an embodiment of the present application Figure 22 as shown;

[0054] Figure 28 The structural schematic diagram of the program test device provided by the embodiment of the present application

[0055] Figure 29 The structural schematic diagram of the electronic device provided by the embodiment of the present application Detailed implementation manners

[0056] The present application will be further described in detail below with reference to the drawings and embodiments

[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which this application belongs. The terms used in the specification of this application herein are only for the purpose of describing specific embodiments, and are not intended to limit this application

[0058] The test case generation method provided by the embodiment of the present application

[0059] The embodiment of the present application provides a test case generation method, as Figure 1A shown, the method includes the following steps

[0060] S1110: Use the input parameters of the objective function as the chromosomes of the genetic algorithm to run the objective function, and obtain the coverage of the nodes in the first control flow graph CFG corresponding to the objective function; the nodes include branch nodes; the branch nodes correspond to the selection statements or loop statements of the objective function

[0061] S1120: Determine the distance difference according to at least one of the absolute value of the difference between the values on both sides of the conditional operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node

[0062] S1130: Determine the fitness of the branch node according to the distance difference

[0063] S1140: Determine the parameter value after updating the input parameters according to the fitness of the branch node

[0064] S1150: Generate a test case for the objective function according to the parameter value after updating the input parameters

[0065] The objective function is also the program.

[0066] The first CFG is a CFG constructed for the objective function. A CFG is an abstract representation of a procedure or program, representing all the paths that will be traversed during the execution of a program. A CFG represents, in the form of a graph, the possible flow directions of all basic blocks within a procedure, and can also reflect the real-time execution process of a procedure. Each node in the graph represents a basic block.

[0067] A CFG has nodes and edges. The edges connect two nodes.

[0068] In some embodiments, the nodes in the first CFG have node information; the node information of the nth node in the first CFG includes at least one of the following:

[0069] The identifier of the basic block corresponding to the nth node;

[0070] The identifier of the previous basic block corresponding to the basic block corresponding to the nth node;

[0071] The identifier of the next basic block corresponding to the basic block corresponding to the nth node;

[0072] The statements of the basic block corresponding to the nth node;

[0073] The dynamic execution state of the basic block corresponding to the nth node.

[0074] Here, n can be a natural number or a positive integer.

[0075] In some embodiments, a basic block refers to a sequence of statements that are executed sequentially in a program.

[0076] In some embodiments, a basic block has only one entry and one exit. The entry is the first statement among them, and the exit is the last statement among them. For a basic block, during execution, it only enters from its entry and exits from its exit.

[0077] Specifically: A basic block has only one entry, indicating that there is no other place in the program that can enter this basic block through a jump instruction.

[0078] A basic block has only one exit, indicating that only the last instruction in the objective function can cause entry into other basic blocks for execution.

[0079] So a typical characteristic of a basic block is that as long as the first instruction in the basic block is executed, then all the executions within the basic block will be executed only once in sequence.

[0080] In some embodiments, a basic block can be represented by source code, assembly, instructions, etc.

[0081] In some embodiments, the previous basic block may include a basic block whose exit corresponds to the entry of the current basic block. For example, after the last instruction of the previous basic block is executed, it can directly access the first statement of the current basic block, or enter the current basic block through one or more intermediate operations.

[0082] In some embodiments, the next basic block may include a basic block whose entry corresponds to the exit of the current basic block.

[0083] Different basic blocks have different identifiers. In some embodiments, the identifier of a basic block may be referred to as a block identifier.

[0084] The execution status of the target function may include: a dynamic execution status and a static execution status.

[0085] The dynamic execution status may refer to: the status of determining the execution order according to dynamic information during runtime. The static execution status may refer to: the status of executing sequentially according to the execution order determined during compilation.

[0086] In some embodiments, the edges in the first CFG have edge information.

[0087] The edge information of the m-th edge in the first CFG includes at least one of the following:

[0088] The identifier of the m-th edge;

[0089] The identifier of the previous basic block associated with the m-th edge;

[0090] The identifier of the next basic block associated with the m-th edge.

[0091] In some embodiments, m is a natural number or a positive integer.

[0092] The identifier of the m-th edge can be referred to as an edge identifier.

[0093] Of course, the above is only an illustrative example of node information and / or edge information.

[0094] Such as Figure 2 The first CFG corresponding to the target function (target_func()) as shown may be as Figure 3 shown. This first CFG includes an entry node (node 43) and a leaf node (node 55). The entry node can be the root node of the first CFG of the target program. Node 44 corresponds to the switch statement in the target function.

[0095] A CFG can display the mutual relationships, dynamic execution status, and statement tables corresponding to each basic block within a procedure.

[0096] CFG is usually constructed based on the information of all basic blocks of a program obtained through static code analysis.

[0097] In the embodiments of the present disclosure, among the nodes included in the first CFG, there are branch nodes. The branch nodes correspond to conditional statements and / or loop statements in the target function. Typical conditional statements may include: conditional statements led by if and / or conditional statements led by switch. Typical loop statements may include: for statement, while statement, do while statement, etc.

[0098] In some embodiments, the nodes of the first CFG may further include non-branch nodes, which are different from branch nodes. The non-branch nodes may correspond to other program statements other than conditional statements and loop statements.

[0099] In the embodiments of the present disclosure, the input parameters of the target function are used as the chromosomes of the genetic algorithm, that is, the parameter values of the input parameters of the target function are used as the input parameters for the iteration of the genetic algorithm. Substitute the input parameters corresponding to a certain chromosome into the target function to run, and determine that the corresponding nodes of the first CFG are covered according to the statements used in the running of the target function. According to the coverage of each node in the first CFG. After substituting the parameter value of a certain input parameter, some nodes may be covered and some nodes may not be covered.

[0100] In some embodiments, at least obtain the coverage of branch nodes and branch nodes in the first CFG of the target function.

[0101] The judgment conditions may include judgment conditions of conditional statements and / or loop statements.

[0102] For example, the judgment condition of the if statement is a>0. For example, assume that the parameter a = -1, then the absolute values on both sides of the operator > are 1, and in combination with at least one of the branch node and the coverage of the branch node, the distance difference can be determined.

[0103] In some embodiments, the distance difference characterizes the coverage of branch nodes and their child nodes. The larger the distance difference, the smaller the fitness. The smaller the distance difference, the larger the fitness value. When the branch node and its child nodes are both covered, the distance difference is equal to 0. Therefore, introducing the distance difference to calculate the fitness can improve the accuracy of the algorithm, accelerate the convergence of the algorithm, and obtain test cases with higher coverage.

[0104] The distance difference can be simply converted into the fitness of the branch node, and the fitness of the branch node can be used in the genetic algorithm to determine whether to continue iteration and the mutation of chromosomes, etc. In this way, the proposal of the distance difference enables the genetic algorithm to converge quickly, thereby improving the updated parameters for finding test cases with good generation effects.

[0105] In some embodiments, a distance difference is determined based on at least one of the absolute value of the difference between the values on both sides of the judgment conditional operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node, including at least one of the following:

[0106] If the branch node is covered for the first time, the distance difference is determined based on the absolute value of the difference between the values on both sides of the judgment conditional operator corresponding to the branch node when it is covered for the first time;

[0107] If the branch node is not covered for the first time, the distance difference is determined according to whether the child nodes of the branch node are completely covered and the absolute value of the difference between the values on both sides of the judgment conditional operator corresponding to the chromosome used when the branch node is covered this time;

[0108] If the branch node is not covered, it is determined that the distance difference has a first value.

[0109] For example, when the above-mentioned if statement is covered for the first time and the judgment condition is a > 0, and the chromosome is a = 1, the distance difference at the first coverage is the normalized value of the absolute value of the difference between the values on both sides of the judgment conditional operator.

[0110] If a branch node is not covered for the first time, it is necessary to analyze the coverage of the branch node and its child nodes during the current iterative update to further determine the distance difference.

[0111] If the branch node is not covered during the current traversal, the distance difference is directly taken as the first value. Exemplarily, this first value can be a maximum value. Further, after normalization, the first value can be 1.

[0112] Further, if the branch node is not covered for the first time and there are uncovered child nodes of the branch node, the distance difference is determined according to the state of the judgment condition corresponding to the chromosome used when the branch node is covered this time;

[0113] If the branch node is not covered for the first time and all its child nodes are covered, it is determined that the distance difference has a second value.

[0114] In some embodiments, if the branch node is not covered for the first time, there are uncovered child nodes of the branch node, and the judgment condition corresponding to the chromosome used when the branch node is covered this time is in a critical state, it is determined that the distance difference has a third value; the critical state means that the difference between the values on both sides of the operator of the judgment condition of the branch node is a specified value and the judgment result of the judgment condition is false.

[0115] In some embodiments, if the branch node is not covered for the first time, there are uncovered child nodes of the branch node, and the judgment condition corresponding to the chromosome used to cover the branch node this time is not in a critical state, the normalized value of the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the chromosome used to cover the branch node this time is determined as the distance difference.

[0116] Further, if the branch node is not covered for the first time and there are uncovered child nodes of the branch node, determining the distance difference according to the state of the judgment condition corresponding to the chromosome used to cover the branch node this time includes:

[0117] If the branch node is not covered for the first time, there are uncovered child nodes of the branch node, and the judgment condition corresponding to the chromosome used to cover the branch node this time is in a critical state, it is determined that the distance difference has a third value; the critical state means that the difference between the values on both sides of the operator of the judgment condition of the branch node is a specified value and the judgment result of the judgment condition is false;

[0118] If the branch node is not covered for the first time, there are uncovered child nodes of the branch node, and the judgment condition corresponding to the chromosome used to cover the branch node this time is not in a critical state, the normalized value of the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the chromosome used to cover the branch node this time is determined as the distance difference.

[0119] The second value here can be a minimum value. Exemplarily, this minimum value can be 0. The third value can be a maximum value close to 1.

[0120] The above gives the implementation method of how to calculate the distance difference specifically, and the specific implementation is not limited to the above examples.

[0121] As Figure 1B shown, the absolute value of the difference between the values on both sides of the operator at the branch node is a normalized value. According to the normalized value result, the maximum distance difference is 1 and the minimum is 0.

[0122] First, determine the distance difference of the branch node in the calculation process.

[0123] For example, an ellipse represents a node, node 0 is a branch node, node 1 is a child node on the true branch, and node 2 is a child node on the false branch. If the ellipse is filled with gray, it indicates that the node is covered.

[0124] If the branch node and all its child nodes are covered, it indicates that the input parameter meets the coverage condition. At this time, there is the maximum fitness value, and the distance difference is 0. At this time, the coverage situation can be as Figure 1C shown.

[0125] If there are at least two chromosomes in the population, and a = 1 in one chromosome, then nodes 0 and 1 are covered; if a = -1 in another chromosome, then nodes 0 and 2 are covered. At this time, nodes 0, 1, and 2 are covered, and the distance difference is 0.

[0126] If a branch node is covered and there are uncovered child nodes of this branch node, there are two cases as shown in Figure 1C and Figure 1D shown. Figure 1C Shown is that the true branch is covered and the false branch is not covered. Figure 1D Shown is that the false branch is covered and the true branch is not covered.

[0127] For Figure 1C the case where the true branch is covered: If there is at least one chromosome in the population, and a = 0 in this chromosome, so that nodes 0 and 1 are covered for the first time, and the initial distance difference is 0.

[0128] Since the optimization goal is to cover all of nodes 0, 1, and 2, therefore, when nodes 0 and 1 are covered, it is necessary to adjust the parameter value to cover node 2, that is, to make the conditional judgment of node 0 false. So when node 0 is not covered for the first time, it is necessary to execute that the conditional judgment a ≥ 0 is false, that is, a < 0 is true. If there is another chromosome, and a = 0 in this chromosome, then this is the critical state at this time. At this time, the distance difference takes a minimum value, which also means that the relevant parameter values are already very close to the target value. Note that although a = 0 in the chromosome, due to the change in the coverage state of the child nodes of the branch node, the value of the distance difference also changes.

[0129] The critical state means that the difference between the values on both sides of the operator of the branch judgment of the branch node is 0, but the branch execution corresponding to the target covered child node of the branch node is false.

[0130] The branch execution here may be the same as the original branch judgment, or the original branch judgment has been conditionally reversed, and it is judged according to the target child node to be covered.

[0131] For Figure 1D the case where the false branch is covered: If there is at least one chromosome in the initial population, and a = -2 in this chromosome, so that nodes 0 and 2 are covered for the first time, and the initial distance difference is the normalized value according to the absolute value of a.

[0132] Since the optimization goal is to cover all of Node 0, Node 1, and Node 2, when Node 0 and Node 2 are covered, the parameter values need to be adjusted to cover Node 1, that is, to make the conditional judgment of Node 0 true. Therefore, when Node 0 is covered not for the first time, the conditional judgment a≧0 needs to be executed as true. If there is another chromosome where a = -2 in this chromosome, then Node 0 and Node 2 are covered. At this time, the distance difference is still the initial distance difference. If there is another chromosome where a = 0 in this chromosome, then Node 0, Node 1, and Node 2 are all covered. At this time, the distance difference is 0.

[0133] If the branch node is not covered, then the child nodes of this branch node are not covered either, and the distance difference is infinite. After data normalization, the maximum value 1 of the distance difference is taken.

[0134] It can be seen that the calculation of the distance difference is closely related to the coverage of the branch node and the child nodes of the branch node. The following gives the determination method for determining the coverage of the branch node and the child nodes of the branch node:

[0135] Run the objective function with the input parameters of the objective function as the chromosome of the genetic algorithm, and obtain the coverage of the nodes in the first control flow graph CFG corresponding to the objective function, including:

[0136] Run the objective function with the input parameters of the objective function as the chromosome of the genetic algorithm, and determine the coverage of the child nodes of the branch node according to the reachable set of the branch node in the first CFG; the reachable set is used to represent the set of position marks of all nodes experienced when the branch node traverses to the end node corresponding to the branch node; the end node refers to the exit node of the branch with the branch node as the root node.

[0137] When the branch node is the branch node corresponding to the selection statement, compare the nodes covered in this traversal with the reachable set of the branch node. If there is a node in the nodes covered in this traversal that corresponds to a certain branch in the reachable set of the conditional branch node, it is determined that the branch corresponding to the branch node is covered; if the branch is covered, the child nodes on the branch are covered;

[0138] When the branch node is the branch node corresponding to the loop statement, compare the nodes covered in this traversal with the reachable set of the branch node. If the nodes covered in this traversal contain all the nodes in the reachable set of the branch node, it is determined that the loop body of the branch node is covered, and continue to traverse the end node corresponding to the branch node; if the loop body of the branch node is covered, the child nodes of the branch node contained in the loop body are covered.

[0139] It can be seen that in the embodiments of the present disclosure, determining being covered is related to the reachable set of the branch nodes. The following provides a way to determine the reachable set:

[0140] Traverse the first CFG in the traversal order to obtain the position markers of the traversed nodes;

[0141] Determine the depth level of the corresponding node according to the number of nodes between the traversed node and the root node;

[0142] Determine the reachable set of each branch node in the first CFG according to the position marker and depth level of a node.

[0143] The branch nodes include the branch nodes corresponding to loop statements and conditional statements. The reachable sets of the branch nodes corresponding to different statements are introduced below.

[0144] Traverse the first CFG downward from the root node with a depth level of 0, and increment the depth level by 1 for each traversed node;

[0145] When traversing to the branch node of a selection statement, determine the depth level of the branch node of the selection statement by incrementing the depth level of the previous traversed node by 1;

[0146] Determine the depth level of the child node of the branch node according to the distance between the child node of the branch node and the branch node;

[0147] When the number of nodes included in different branches under the branch node of the same selection statement is different, use the depth level of the end node of the branch with the depth level determined first in the traversal order as the depth level of the end nodes of all branches of the branch node;

[0148] When traversing to the branch node of a loop statement, determine the alternative depth level of the branch node of the loop statement by incrementing the depth level of the previous traversed node by 1;

[0149] When there are multiple alternative depth levels, use the minimum value among the multiple alternative depth levels as the depth level of the branch node of the loop statement;

[0150] Determine the depth level of the child node of the branch node of the loop statement according to the number of nodes between the child node of the branch node of the loop statement and the branch node of the loop statement.

[0151] Further, traverse to the child node of the branch node in the traversal order, and record the position markers of all nodes from the branch node containing each child node to the corresponding end node of the branch node into the reachable set;

[0152] If there are sibling nodes with the same depth level among the child nodes of the branch node, then the nodes that have been recorded among all the nodes traversing the branch node containing the sibling nodes to the end node corresponding to the branch node are removed from the reachable set until all the child nodes of the branch node are included in the reachable set; the reachable set of the branch node does not include the branch node; if the branch node is the branch node of a loop statement, the reachable set does not include the end node corresponding to the branch node.

[0153] As Figure 4 shown, S1140 may include:

[0154] S1141: Determine the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm. Different evaluation methods correspond to different optimized individuals;

[0155] S1142: Determine the fitness of the optimized individual corresponding to the branch node according to the fitness of the branch node;

[0156] S1143: Determine the fitness of the chromosome corresponding to the optimized individual according to the fitness of the optimized individual;

[0157] S1144: Update the parameter values of the input parameters according to the fitness of the chromosome.

[0158] In one embodiment, the determining the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm includes:

[0159] Taking all the edges of the first CFG as the optimization objective, determine the edges covered by the first CFG corresponding to each chromosome as the edges covered by the first CFG;

[0160] Merge the edges covered by the corresponding chromosome to obtain the set of edges covered by the corresponding chromosome;

[0161] Taking the edges with the parent node as the branch node in the edge set as the optimized individual.

[0162] In one embodiment, the determining the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm includes:

[0163] Taking all the paths of the first CFG as the optimization objective, obtain the paths covered in the first CFG by each chromosome through environmental interaction feedback;

[0164] Taking the paths covered in the first CFG as the optimized individual.

[0165] In one embodiment, the method for determining the fitness evaluation method of the chromosome according to the optimization objective corresponding to the genetic algorithm includes:

[0166] Taking all the edges of the first CFG as the optimization objective, determining the edges covered by the first CFG corresponding to each chromosome as the edges covered by the first CFG;

[0167] Merging the covered edges corresponding to the chromosome to obtain the set of edges covered by the chromosome;

[0168] Taking one edge in the edge set as the base edge and extending in two directions from the base edge to the root node and the child node of the base edge to obtain an extended path; wherein, when encountering multiple nodes or multiple child nodes during the extension process, select one node to continue the extension until the root node and / or the terminal node;

[0169] Taking the extended path as the optimization individual.

[0170] The above provides three examples of genetic algorithms, and the specific implementation is not limited to the above examples.

[0171] The above three algorithms determine the fitness of the branch nodes based on the distance difference, so that the convergence speed of the genetic algorithm is fast. Especially in the way of taking the extended path as the optimization individual, the convergence speed is significantly improved.

[0172] In some embodiments, S1140 may include: performing update iteration of the genetic algorithm according to the fitness of the chromosome until the optimization objective of the genetic algorithm is reached or the number of update iterations reaches the set maximum number of iterations; obtaining the updated parameter values of the input parameters according to the population corresponding to the genetic algorithm when the iteration stops.

[0173] In the embodiments of the present disclosure, during the update iteration process based on the genetic algorithm, an input parameter dictionary will be constructed according to the input parameters of the objective function, and the input parameter dictionary may include the parameter information of the input parameters of the objective function.

[0174] In some embodiments, the parameter information may include: the parameter values of the input parameters.

[0175] Before the update of the iteration based on the genetic algorithm, the parameter values may include: the initial parameters initialized based on the initialization strategy.

[0176] The initialization strategy may include but is not limited to: random initialization, all-zero initialization, middle-value initialization, etc.

[0177] The parameter information may specifically include but is not limited to at least one of the following:

[0178] The name of the parameter;

[0179] The bit width of the parameter; this bit width can be understood as the number of binary bits.

[0180] The sign status of the parameter; for example, the sign of a positive number is a plus sign; the sign of a negative number is a minus sign.

[0181] The type of the parameter, for example, integer type or floating-point type.

[0182] In some embodiments, through iterative update, an updated parameter value can be obtained.

[0183] The updated parameter value is used to construct a test case, and the test case constructed in this way can well test the code structure of the target function.

[0184] In some embodiments, determining the fitness of the branch node according to the distance difference includes: according to the functional relationship Determine the fitness; where dist is the distance difference and fit is the fitness.

[0185] It can be seen that it is simple and convenient to convert from the distance difference to the fitness of the branch node.

[0186] In some embodiments, obtaining the CFG of the target function may include:

[0187] Generate a second CFG according to the target function; one node in the second CFG corresponds to one statement of the target function;

[0188] When the second CFG contains branch nodes, expand the multiple conditions involved in the branch nodes into multiple single conditions; the branch nodes correspond to the selection statements and / or loop statements of the target function;

[0189] Construct a sub-CFG according to the multiple single conditions; wherein, one node in the sub-CFG corresponds to one single condition;

[0190] Replace the corresponding branch node in the second CFG with the sub-CFG to obtain the first CFG.

[0191] Expand the branch node into a sub-CFG and replace the sub-CFG into the second CFG to obtain the first CFG. In this way, when traversing the paths of the first CFG, the execution paths of each statement of the first CFG can be traversed. Therefore, the test cases constructed by updating and iterating the second parameter information in this way are beneficial to achieving higher code structure coverage of the target function.

[0192] Figure 5 As shown Figure 2 The second CFG of the target function shown. In the second CFG, there are branch nodes corresponding to the selection statement (switch) and branch nodes corresponding to the loop statement (for).

[0193] In some embodiments, the method further includes: performing a preorder traversal on the abstract syntax tree (AST) of the target function to obtain a list of node information of the branch nodes. Figure 6 Yes Figure 2 The AST of the target program shown.

[0194] In specific implementation, traverse the AST according to the search algorithm to find the branch nodes, and construct a list of node information based on the information of the branch nodes.

[0195] For example, in some embodiments, use preorder traversal (DLR) to search the AST, then search from the root node to the leaf nodes, starting from the left and moving to the right.

[0196] That is, in some embodiments, perform a preorder traversal on the abstract syntax tree AST of the target function to obtain a list of node information of the branch nodes; the list of node information includes: the node identifier of the branch node; the node type; the node type includes: non-conditional type, single-conditional type, and / or multi-conditional type; the judgment condition.

[0197] Figure 7 A schematic diagram obtained by using preorder traversal to search the AST, in Figure 7 In the shown nodes [a, b], a represents the traversal order of the node, and b represents the node identifier.

[0198] In some embodiments, the list of node information includes: the node identifier of the branch node, the node type, and / or the judgment condition.

[0199] In some embodiments, the node type includes: non-conditional type, single-conditional type, and / or multi-conditional type.

[0200] If the node type is non-conditional type, the condition list corresponding to the node is empty;

[0201] If the node type is single-conditional type, the length of the condition list corresponding to the node is 1, and the condition list contains the text information of the condition;

[0202] If the node type is multi-conditional type, the length of the condition list corresponding to the node is greater than 1, and the condition list contains the text information of all single conditions of the multi-conditions, as well as the logical operators between the single conditions.

[0203] In some embodiments, when the second CFG includes a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions includes: when the second CFG includes a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions based on the logical operators in the judgment conditions of the branch node of the multiple-condition type.

[0204] Figure 5 The node 44 corresponding to the switch statement in the shown second CFG is a single-condition selection statement itself. The node 55 corresponding to the for statement in the second CFG is a loop statement corresponding to multiple conditions.

[0205] When the second CFG uses node 55 as the root node, the local control flow graph can be as Figure 8 shown. Figure 9 It is a schematic diagram of the sub-CFG expanded from node 55.

[0206] In some embodiments, when the second CFG includes a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions includes:

[0207] When the second CFG includes a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions based on the logical operators in the judgment conditions of the branch node of the multiple-condition type.

[0208] For example, a>0&&b>0 is a multiple condition. This multiple condition can be expanded into two single conditions, which are respectively: a>0 and b>0. Among them, && is one type of logical operator. It can be seen that only node 55 in the second CFG is a branch node with multiple conditions. Therefore, expand node 55 into a sub-CFG and replace node 55 in the second CFG to obtain the first CFG.

[0209] In some embodiments, the method further includes:

[0210] Traversing the first CFG to obtain the depth level of each node and the reachable set of the branch nodes;

[0211] Based on the depth level and the reachable set, perform path search on the first CFG to obtain the path of the first CFG;

[0212] The path of the first CFG is one of the attributes of the first CFG.

[0213] In some embodiments, the depth level can be simply referred to as depth.

[0214] Exemplarily, the depth amplitude of the root node is 0. When traversing from the root node to the leaf node, for each node passed through, the depth is incremented by 1. Figure 3The depth of the middle node 43 is 0, the depth of node 44 is 1, the depth of node 49 is 4, and so on.

[0215] Figure 18 Shown is the process of iterative optimization with the goal of covering all edges in the first CFG, and in Figure 18 the first CFG is represented by the abbreviation "CFG".

[0216] As Figure 18 shown, it includes:

[0217] Initialize the target edge set SE with the edge set of the CFG;

[0218] Initialize the population S, chromosome list (LC), global covered edge set RE, and global covered path set RP. The input parameters in the input parameter dictionary can correspond to the chromosomes recorded in the chromosome list of the genetic algorithm;

[0219] Environmental interaction to obtain the feedback covered node set SCN;

[0220] Restore SCN to path P and edge set SE0, merge SE0 into RE, and save P into RP.

[0221] Update SE;

[0222] Judge whether SE is empty.

[0223] If SE is not empty, judge whether the population iteration upper limit is reached;

[0224] If SE is empty, the iteration ends.

[0225] If the population iteration upper limit is not reached, calculate the distance and fitness according to SE and SEO;

[0226] Optimize chromosomes based on the distance and fitness;

[0227] Perform chromosome crossover and mutation, and return to the step of environmental interaction to obtain the feedback covered node set SCN.

[0228] Figure 19 Shown is the process of iterative optimization with the goal of covering all paths in the first CFG, and in Figure 19 the first CFG is represented by the abbreviation "CFG".

[0229] Initialize the target path set SP with the path set of the CFG, and initialize the global covered path set RP;

[0230] Judge whether SP is empty;

[0231] If it is, the iteration ends;

[0232] If not, obtain the target path P0;

[0233] Initialize the population S and the chromosome list LC;

[0234] Perform environmental interaction to obtain the feedback-covered node set SCN;

[0235] Restore SCN to the path P and the edge set SE0;

[0236] Save the non-expected paths to PR and update SP;

[0237] Calculate the distance and fitness according to the feedback path P and the target path P0;

[0238] Judge whether the distance is 0;

[0239] If so, update P to RP;

[0240] If not, judge whether the population iteration upper limit is reached;

[0241] If so, return to the step of judging whether SP is empty;

[0242] If not, perform chromosome optimization;

[0243] Perform chromosome crossover and mutation, and return to the step of performing environmental interaction to obtain the feedback-covered node set SCN.

[0244] Figure 20 The following shows the iterative optimization process with the optimization goal of covering all edges in the first CFG and combining the extension of all edges towards the root node and the leaf node, and in Figure 20 the first CFG is represented by the abbreviation "CFG".

[0245] Initialize the target edge set SE with the path set of the CFG, initialize the global covered edge set RE and initialize the global covered path set RP. The specific operations can be seen in Figure 20 as shown.

[0246] Judge whether SE is empty;

[0247] If so, the iteration ends;

[0248] If not, randomly select E0 from SE;

[0249] Extend the start node and the end node of E0 up and down to form the target path P0;

[0250] Initialize the population S and the chromosome list LC;

[0251] Perform environmental interaction to obtain the feedback-covered node set SCN;

[0252] Restore the SCN to the path P and the edge set SE0;

[0253] Merge SE0 into RE and save P to RP;

[0254] Update SE;

[0255] Calculate the distance and fitness according to P0 and P;

[0256] Determine whether the distance is 0,

[0257] If not, determine whether the population iteration upper limit is reached;

[0258] If so, return to the step of determining whether SE is empty.

[0259] If not, calculate the distance and fitness according to P0 and P;

[0260] Chromosome optimization;

[0261] Chromosome crossover and mutation, and return to the step of environmental interaction to obtain the covered nodes combined with the SCN for feedback.

[0262] The test method provided by the embodiments of the present disclosure may include preprocessing, genetic algorithm processing, test result collection, and statistics.

[0263] The first step: The preprocessing may include the following steps:

[0264] 1.1: Construct a CFG corresponding to the objective function, and obtain the node information and edge information of the CFG.

[0265] The nodes of the CFG represent a basic block, and the edges of the CFG represent the logical jumps between basic blocks.

[0266] A basic block is a sequence composed of consecutive statements or expressions. A basic block has a unique entry and a unique exit. If a certain statement in the basic block is executed, all statements can be executed.

[0267] The node information of the CFG includes: the unique identifier of the basic block, the identifiers of all possible previous basic blocks, the identifiers of all possible next basic blocks, the corresponding statement list, and the dynamic execution status.

[0268] The edge information of the CFG includes: the unique identifier of the edge, and the identifiers of the previous basic block and the next basic block associated with the edge.

[0269] 1.2: Obtain the abstract syntax tree AST corresponding to the objective function, perform a pre-order traversal according to the depth-first search algorithm, and obtain the list of branch node information.

[0270] A branch node refers to a node that contains a conditional branch or a loop statement.

[0271] The branch node information list includes a node identifier, a node type, and a condition list.

[0272] The condition list includes at least one of the following three cases:

[0273] If the node type is a non - conditional type, the condition list is empty;

[0274] If the node type is a single - condition type, the length of the condition list is 1, and the condition list contains the text information of the condition;

[0275] If the node type is a multi - condition type, the length of the condition list is greater than 1, and the condition list contains the text information of all single conditions of the multi - conditions, as well as the logical operators between the single conditions.

[0276] 1.3: Expand the nodes of the CFG based on the branch node information list to generate an expanded control flow graph CFG', and save the node information and edge information of CFG'.

[0277] Expanding the nodes of the CFG based on the branch node information list may include, but is not limited to, the following examples:

[0278] Traverse the CFG, determine the nodes in the CFG that need to be conditionally expanded according to the node identifiers of the multi - condition nodes in the branch node information list, expand the multi - conditions into sub - conditions according to the information of the multi - condition nodes, each sub - condition is a single condition, one sub - condition corresponds to a node in the expanded CFG, and replace the CFG of the sub - condition with the position of the multi - condition node in the CFG to obtain CFG'.

[0279] 1.4: Traverse CFG', mark the positions of the traversed nodes in the order of traversal, and determine the depth level of the nodes according to the number of nodes between the traversed nodes and the root node.

[0280] Marking the positions of the traversed nodes means marking the positions of the nodes of CFG' traversed in the order of traversal with unique identifiers;

[0281] Determine the depth level of the nodes according to the number of nodes between the traversed nodes and the root node:

[0282] Assign the depth level of the root node as 0; traverse downward from the root node, and increment the depth level of the current node by 1 for each traversed node;

[0283] When a branch is traversed, handle it according to the following rules:

[0284] For a selection branch, the depth level of the branch node of the selection branch is the depth level determined by the previously traversed node plus 1. The depth level of the child node of the branch node is determined according to the distance between the child node of the branch node and the branch node.

[0285] If the number of nodes included in different branches under the same selection branch node is different, then according to the traversal order, the depth level of the branch end node that determines the depth level first is used as the depth level of other branch end nodes, so that the depth levels of the branch end nodes of different branches under the same selection branch node are the same.

[0286] For a loop branch, in each traversal process, the depth level determined by the previously traversed node of the branch node of the loop branch plus 1 is used as the depth level of the branch node of the loop branch to be determined. The minimum value among the depth levels of the branch nodes of the loop branch to be determined is used as the depth level of the branch node of the loop branch. The depth level of the child node of the branch node is determined according to the distance between the child node of the branch node and the branch node.

[0287] 1.5: According to the position markers and depth levels of the nodes in CFG', obtain the reachable set of each branch node of CFG'. The reachable set is used to represent the set of position markers of all nodes that can be experienced when traversing from the branch node to the corresponding end node of the branch node. The end node refers to the exit node of the branch with the branch node as the root node.

[0288] Obtaining the reachable set of each branch node of CFG' according to the position markers and depth levels of the nodes in CFG' can be as follows:

[0289] Traverse to the first child node of the branch node in the traversal order, and record all the nodes from the branch node containing the child node to the corresponding end node of the branch node into the reachable set;

[0290] If there are sibling nodes with the same depth level among the child nodes of the branch node, then remove the nodes that have been recorded among all the nodes from the branch node containing the sibling nodes to the corresponding end node of the branch node, and only record the different nodes into the reachable set until all the child nodes of the branch node are included in the reachable set;

[0291] The reachable set does not include the branch node; if the branch node is a loop branch node, the reachable set does not include the corresponding end node of the branch node.

[0292] 1.6: Through the CFG' full-path generation algorithm based on inheritance-based depth-first search, obtain all the path information corresponding to CFG'. The path information refers to an ordered list from the root node of CFG' to the end point, and the elements in the list are the position markers of the nodes.

[0293] The CFG' full-path generation algorithm based on inheritance-based depth backtracking may include:

[0294] Perform a depth-first pre-order traversal on CFG', record the position markers of the traversed nodes. When the first branch node is traversed and the path downward from the first branch node is completely searched, all the path information between the first branch node and the end node corresponding to the first branch node is used as the relative path of the first branch node and recorded at the first branch node. If there is a second branch node, and the second branch node is the previous visited branch node of the first branch node in the traversal order, then when the first branch node is traversed for the second time from the second branch node, stop searching for the path downward from the first branch node, splice the path segment between the second branch node and the first branch node with the relative path of the first branch node, and record the splicing result as the relative path of the second branch node at the second branch node.

[0295] 1.7: Construct the input parameter dictionary of the objective function, which is used to store the correspondence between the parameter information and parameter values of the objective function.

[0296] The parameter information of the objective function includes name, bit width, mapping type, sign status, value list;

[0297] The name refers to the original name of the parameter of the objective function.

[0298] The bit width refers to the binary length of the value that the parameter type can represent.

[0299] The sign status refers to the value range expressed by the value list. This value range includes two types: centered at the origin and centered at the leftmost.

[0300] The mapping type refers to the basic data type to which the parameter type of the objective function can be mapped. The basic data types include integer (int) and floating point (float).

[0301] The value list is the parameter value expressed by a binary array.

[0302] The parameter values are initialized through an initialization strategy. The initialization strategies include random initialization, all-zero initialization, and middle-value initialization.

[0303] Second step: Processing of the genetic algorithm

[0304] Use the parameter values in the input parameter dictionary as chromosomes, and update and iterate the input parameter dictionary through the genetic algorithm until the optimization goal of the genetic algorithm is reached or the number of iterations reaches the set maximum number of times.

[0305] 2.1: Updating and iterating the input parameter dictionary through the genetic algorithm may include:

[0306] Restore the types and parameter values of the input parameters in the input parameter dictionary to their original parameter forms, run the target function, and obtain the nodes covered by CFG'.

[0307] Compare the covered nodes with all the nodes of CFG' one by one in the traversal order. Determine the coverage of each branch node and the child nodes of the branch node in CFG' according to the reachable set of each branch node in CFG', and determine the covered paths of CFG' according to the coverage.

[0308] Determining the coverage of each branch node and the child nodes of the branch node in CFG' according to the reachable set of each node in CFG' means:

[0309] When the traversed node is a conditional branch node, compare the covered nodes with the reachable set of the conditional branch node. If there is a node in the covered nodes corresponding to a certain branch in the reachable set of the conditional branch node, it means the branch is covered.

[0310] When the traversed node is a loop branch node, compare the covered nodes with the reachable set of the loop branch node. If the covered nodes contain all the nodes in the reachable set of the loop branch node, it means the loop body corresponding to the loop branch node is covered, and continue to traverse the end node corresponding to the loop branch node.

[0311] 2.2: Determine the optimization individuals according to the set optimization objectives, as well as the fitness evaluation methods corresponding to the chromosomes, which may include:

[0312] If the optimization objective is to cover all the edges of CFG', determine the edges covered by CFG' through the covered paths of CFG' corresponding to each chromosome, merge the edges covered by the chromosome, obtain the set of edges covered by the chromosome, use the edges with the parent node of the covered edge set as the branch node as the optimization individuals, use the fitness of the parent node of the optimization individual as the fitness of the optimization individual, and determine the fitness corresponding to the current chromosome according to the fitness of all the optimization individuals in the covered edge set corresponding to the current chromosome.

[0313] If the optimization objective is to cover all the paths of CFG', each chromosome obtains a covered path of CFG' through environmental interaction feedback, and uses the covered path of CFG' as the optimization individual; determine the fitness of the optimization individual based on the fitness of all the branch nodes included in the covered path of CFG'; determine the fitness corresponding to the current chromosome according to the fitness of the optimization individual;

[0314] If the optimization goal is to cover all the edges of CFG', the edges covered by CFG' can also be determined through the paths covered by the CFG' corresponding to each chromosome. The edges covered by the chromosome are merged to obtain the set of edges covered by the chromosome, and one of the edges in the set of covered edges is used as the base edge. Starting from the two nodes of the base edge, extend in two directions, namely, towards the root node and the child node of the edge. When the node of the edge contains the root node, no further extension is made towards the root node. When the node of the edge contains the terminal node, no further extension is made towards the child node. When multiple parent nodes or multiple child nodes are encountered during the extension process, select one of the nodes to continue the extension. The selection method can be random selection, or selection of the first parent / child node. A extended path is obtained through the extension of the edge. If there is an edge in the extended path whose parent node is a branch node, the extended path is used as an optimized individual, and the fitness of the optimized individual is determined based on the fitness of the parent node. The fitness of the current chromosome is determined according to the fitness of all the optimized individuals in the set of extended paths corresponding to the current chromosome.

[0315] 2.3: Determine the absolute value of the difference between the values on both sides of the operator at the branch node covered by CFG' according to the chromosome. Determine the distance difference of the branch node based on the absolute value in combination with the coverage of the branch node and the child nodes of the branch node. Convert the distance difference into the fitness of the branch node. The fitness has an inverse correlation with the distance difference.

[0316] Determining the distance difference of the branch node based on the absolute value in combination with the coverage of the branch node and the child nodes of the branch node includes:

[0317] Take the normalized value of the absolute value determined by the chromosome when the branch node is first covered as the initial distance difference of the branch node. After the test case determined by the current chromosome is executed, obtain the coverage of each branch node of CFG' and the child nodes of the branch node. The coverage refers to the final coverage of the node after multiple executions of the test case. Determine the distance difference of the branch node based on the absolute value of the difference between the values on both sides of the operator at the covered branch node of CFG' determined by the current chromosome in combination with the coverage.

[0318] If the branch node is covered, there are uncovered child nodes of the branch node, and it is not in the critical state, then the distance difference is equal to the initial distance difference.

[0319] If the branch node is covered, there are uncovered child nodes of the branch node, and it is in the critical state, then the distance difference is represented by a very small value, such as 10-6.

[0320] If the branch node and all its child nodes are covered, then the distance difference is equal to 0.

[0321] If neither the branch node nor all of its child nodes are covered, the distance difference is equal to 1, and the fitness of the branch node is not calculated.

[0322] The conversion of the distance difference into the fitness of the branch node can be done through the following calculation formula:

[0323]

[0324] Where dist represents the distance difference and fit represents the fitness.

[0325] 2.4: Determine the fitness of the optimized individual based on the fitness of the covered branch nodes in CFG', and determine the fitness of the chromosome based on the fitness of the optimized individual. Genetic sampling of the chromosomes in the current population (Species) according to the fitness of the current population includes:

[0326] Calculate the sampling probability of each chromosome in the current population according to the fitness of the current population. The calculation formula is as follows:

[0327]

[0328] Where Ps i is the sampling probability of the i-th chromosome, fit i is the fitness corresponding to the i-th chromosome, fit n is the fitness corresponding to the n-th chromosome, N c is the total number of all chromosomes in the current population.

[0329] Calculate the fitness variance of the current population according to the fitness of the current population. The calculation formula is as follows:

[0330]

[0331] Where D fit is the population fitness variance, E fit is the population fitness mean, fit n is the fitness corresponding to a chromosome in the current population, N c refers to the number of chromosomes in the current population.

[0332] Determine the genetic sampling method of the chromosomes through the fitness variance of the current population, and sample the current population according to the genetic sampling method, including:

[0333] If the fitness variance of the current population is greater than the preset minimum fitness variance, perform probability sampling with replacement according to the sampling probability of each chromosome, and the sampling quantity is the number of chromosomes set for the population.

[0334] If the fitness variance of the current population is less than the preset minimum fitness variance, then sort the chromosomes according to the fitness corresponding to each chromosome in descending order, and extract a certain number of chromosomes corresponding to the fitness at the front positions as the chromosomes with stable inheritance, and retain them in the population after iteration; then, according to the sampling probability of each chromosome, perform probability sampling with replacement on all the chromosomes in the current population until the sum of the number of sampled chromosomes and the number of extracted chromosomes reaches the number of chromosomes set for the population; or perform probability sampling with replacement on the chromosomes in the population after extracting the chromosomes with stable inheritance until the sum of the number of sampled chromosomes and the number of extracted chromosomes reaches the number of chromosomes set for the population.

[0335] Determine the genetic sampling method of chromosomes through the fitness variance of the current population, and the calculation formula is as follows:

[0336]

[0337]

[0338] Among them, KCS represents the set of chromosomes with stable inheritance, CSC represents the set of chromosomes with sampling inheritance, C i represents the chromosome with inheritance, i is a variable, Sample(C i ) represents the sampling of the chromosome with inheritance, N C represents the number of chromosomes set for the population, K n represents the number of chromosomes with stable inheritance, fiti represents the fitness corresponding to the chromosome with inheritance, MaxOrd(fiti) represents the number of chromosomes with inheritance after sorting the chromosomes in the current population in descending order according to the fitness, D fit represents the fitness variance of the population, D mfit represents the preset minimum fitness variance. The sum of the lengths of the two sets KCS and CSC is equal to the number of chromosomes N in the entire population C .

[0339] When D fit is greater than or equal to D mfit , it means that the fitness of all chromosomes in the current population is very distinct, that is, the fitness of some of the chromosomes is particularly high, while the fitness of others is particularly low, and there is an obvious difference in the selection probability. Probability sampling can extract chromosomes with high fitness. Therefore, the genetic sampling method of chromosomes directly selects the sampling inheritance method: CSC = Sample(C i ), and the length of CSC is N C .

[0340] When D fit is less than D mfitWhen it indicates that the fitness of all chromosomes in the current population is not significantly distinguishable, that is, the sampling probabilities of all chromosomes in the current population are similar. To ensure that chromosomes with high fitness can be smoothly inherited to the next generation, it is necessary to actively retain at least several chromosomes with the highest fitness once. Therefore, the genetic sampling method of chromosomes simultaneously selects two methods: stable inheritance and sampling inheritance. Set the length of KCS to K n and the length of CSC to N C -K n After sorting the fitness values corresponding to each chromosome in the current population from largest to smallest, first extract the first K n chromosomes to form KCS, and then sample to obtain N C -K n chromosomes in CSC.

[0341] 2.5: For each chromosome in the chromosome set obtained by genetic sampling, successively take one chromosome as a benchmark and perform environmental interaction with other chromosomes. Mutate the chromosomes after environmental interaction, and use the set of mutated chromosomes as the new population.

[0342] Environmental interaction includes: For the genes in two chromosomes, randomly extract a part of the continuous gene fragments that represent the same parameters for environmental interaction.

[0343] Mutation includes: Preset a mutation probability, select some genes for each chromosome according to the mutation probability, and select some sites for the genes according to the mutation probability to swap the numerical values of 0 and 1.

[0344] 2.6: Update the parameter values in the input parameter dictionary according to the obtained new population;

[0345] 2.7: Repeat steps 2.1 to 2.6 until the optimization goal of the genetic algorithm is reached or the number of iterations reaches the set maximum number of iterations.

[0346] 2.8: Generate the target test cases of the target function based on the updated input parameter dictionary obtained.

[0347] The following gives a specific implementation:

[0348] (1) Construct the CFG corresponding to the function:

[0349] A control flow graph (CFG) is an abstract representation of a process or program, representing all the paths that a program will traverse during execution. CFG uses a graph to represent the possible execution flows of all basic blocks in a process, and can also reflect the real-time execution process of a process. Each node in the graph represents a basic block. A CFG can display the relationship between basic blocks in a process, the dynamic execution status, and the statement table corresponding to each basic block.

[0350] CFG is usually constructed by obtaining information about all basic blocks of a program through static code analysis and then obtaining the basic block information.

[0351] Figure 2 An example of an objective function is shown. Figure 2 The objective function shown can be divided into basic blocks. The nodes corresponding to these basic blocks are identified as 44-54, node 43 is the entry, and node 55 is the exit.

[0352] Figure 2 The original CFG of the objective function shown can be expressed as Figure 5 shown.

[0353] Abstract Syntax Tree (AST), or simply Syntax tree, is an abstract representation of the grammatical structure of source code. AST represents the grammatical structure of a programming language in a tree-like form, and each node on the tree represents a structure in the source code. The reason why the syntax is "abstract" is that the syntax here does not represent every detail that appears in the real syntax. For example, nested parentheses are implied in the structure of the tree and are not presented in the form of nodes. Conditional jump statements such as if-condition-then can be represented using nodes with two branches.

[0354] (ii) Get the node information list of the AST corresponding to the function:

[0355] The AST corresponding to the above function can be as follows Figure 6 As shown. Among the nodes owned by the overall syntax tree of the target function, only the coverage of nodes such as selection statements and loop statements is associated with the changes in test cases. That is, only specific node information can reflect the accuracy of test case generation. Therefore, it is first necessary to obtain these node information from the syntax tree by traversal. This application performs pre-order traversal according to the depth-first search algorithm to obtain a node information list of AST.

[0356] The Depth-First-Search (DFS) algorithm is a type of search algorithm. It traverses the nodes of a tree along the depth of the tree, searching the branches of the tree as deep as possible. When all the edges of node v have been explored, the search will backtrack to the starting node of the edge that discovered node v. This process continues until all the nodes reachable from the source node have been discovered. If there are still undiscovered nodes, one of them is selected as the source node and the above process is repeated. The entire process is repeated until all nodes have been visited.

[0357] Preorder Traversal (DLR): Preorder traversal first visits the root node, then traverses the left subtree, and finally traverses the right subtree. When traversing the left and right subtrees, it still first visits the root node, then traverses the left subtree, and finally traverses the right subtree.

[0358] Perform preorder traversal on the above AST according to the depth-first search algorithm as Figure 7 shown.

[0359] As Figure 7 shown, the numbers 1 - 12 on the left in [] are the traversal order numbers of the nodes in the AST. The node identifiers corresponding to the nodes that generate selection statements and / or loop statements among the above nodes are: 44, 49, 51. The information list of these branch nodes is as follows:

[0360]

[0361] (3) Expand the nodes of the CFG based on the information list of branch nodes:

[0362] There may be a multi - condition state in the selection statements of the source code function. In the CFG, this is reflected as a certain node having multiple conditions. At this time, it needs to be expanded into the form of sub - conditions, which can more clearly distinguish the different actual coverage paths of test cases in the CFG, especially under multiple conditions. And after splitting into sub - conditions, its granularity is improved, and the distance feedback of the subsequent genetic algorithm at the nodes will be more detailed, making it easier for the genetic algorithm to converge and obtain test cases that accurately cover new paths.

[0363] Generally, multi - conditions are complex logical operations, and the number of parameters at the condition is more than two, but the result is a boolean variable, that is, a binary value of 1 or 0. The input situations are diverse, while the output result is binary, that is, a many - to - two mapping. For the result, it is impossible to reflect the differences of all different inputs. After splitting the multi - condition into sub - conditions and converting it into a conditional subtree to replace the original multi - condition node in the CFG, different conditions are used as separate nodes, and the CFG can represent more paths, making the finally generated test cases more and more accurate.

[0364] Based on the above branch node information list, it can be known that the node with node identifier 51 is a multi-condition node. It is necessary to expand the node with node identifier 51 in the above CFG, and correspondingly, it is necessary to expand the child nodes of node 51. The local control flow chart with node 51 as the root node can be as Figure 8 shown.

[0365] The local control flow chart after expanding node 51 can be as Figure 9 shown.

[0366] Replace the local control flow chart with node 51 as the root node in the original CFG with the expanded local control flow chart. The replaced CFG' is as Figure 3 shown.

[0367] The above nodes 61 and 62 are the nodes expanded from node 51. Among them, "then

[61] " is a virtual node used to connect two single-condition nodes and shares a node identifier with node 61.

[0368] (4) Mark the positions of the nodes in the CFG:

[0369] Mark the positions of the nodes in the CFG according to the traversal order. The position mark is used to uniquely determine a node in the CFG. If the pre-order traversal of CFG' is performed according to the depth-first search algorithm, the position marks of the nodes in CFG' can be as Figure 10 shown. Record the serial number of each node traversed as the position mark.

[0370] (5) Determine the depth level marks of the nodes in the CFG:

[0371] The position marks cannot reflect the mutual relationship between nodes. In order to determine the path information of the CFG, other information needs to be combined to reflect it. In this application, the position marks are combined with the depth levels to determine the paths in the CFG.

[0372] Traverse the CFG, and determine the depth level of the nodes in the CFG according to the number of nodes between the traversed node and the root node.

[0373] (1) Assign the depth level of the root node as 0; traverse downward from the root node, and add 1 to the depth level of the current node for each traversed node. For example, the depth level of node 0 in CFG' is 0, and the depth level of node 1 is 1.

[0374] (2) For a selection branch, the depth level of the branch node of the selection branch is the depth level determined by the previously traversed node plus 1. The depth levels of the child nodes of the branch node are determined according to the distances between the child nodes of the branch node and the branch node. If the numbers of nodes included in different branches under the same selection branch node are different, then according to the traversal order, the depth level of the branch end node that determines the depth level first is used as the depth level of other branch end nodes, so that the depth levels of the branch end nodes of different branches under the same selection branch node are the same.

[0375] For example, nodes 1, 6, and 8 in CFG' are branch nodes of selection branches. When the depth level of node 1 has been determined to be 1, taking the child nodes of node 1 as an example to determine the depth levels: the depth level of node 2 is 2, the depth level of node 3 is 3, the depth level of node 13 is 2, and the depth level of node 14 is 3.

[0376] For the case where the numbers of nodes included in different branches under the same selection branch node are different, it can be as Figure 11 shown.

[0377] For example, Figure 11 shown, for the two conditional branch end nodes 20 and 4 of node 1, their depth levels are both 4.

[0378] During the traversal process, the branch nodes of a loop branch are traversed at least once, and adding 1 to the depth level determined by the previously traversed node of the branch node will result in more than one value. Therefore, the depth levels of the branch nodes of a loop branch are determined according to the following rules:

[0379] For a loop branch, during each traversal process, adding 1 to the depth level determined by the previously traversed node of the branch node of the loop branch is used as the depth level of the branch node of the loop branch to be determined. The minimum value among the depth levels of the branch nodes of the loop branch to be determined is used as the depth level of the branch node of the loop branch. The depth levels of the child nodes of the branch node are determined according to the distances between the child nodes of the branch node and the branch node.

[0380] For example, node 4 in CFG' is a loop branch node, the depth level of node 4 is 4, node 5 is a child node of node 4, and the depth level of node 5 is 5. After traversing to node 5, node 4 will be traversed again, and at this time the depth level will increase to 6, but because it originally had a depth level value of 4, then only the depth level of 4 is retained at this time.

[0381] In addition, for the complex situation where a conditional branch is included in a loop branch, such as Figure 12 shown.

[0382] Taking Figure 12The middle node 10 is a loop branch node, and a conditional branch is nested in this loop branch. The node 12 is a conditional branch node. When traversing downward normally to mark the depth levels of each node, since a loop structure forms a cycle, after traversing to node 16, node 10 will be traversed again. At this time, the depth level mark is increased to 7, but because it originally had a level of 3, only the depth level of 3 is retained at this time.

[0383] Taking CFG' as an example, after performing position marking and determining the depth levels, the position markings and depth level information of each node in CFG' are as shown in [], where the left value is the position marking and the right value is the depth level. Specifically, it can be as Figure 13 shown.

[0384] (6) Obtain the reachable set of the branch nodes of the CFG:

[0385] The reachable set of a branch node is: the set of all nodes that can be reached during the process from this node downward to the corresponding end node of this node. Among them, the processing of conditional branch nodes and loop branch nodes will be slightly different.

[0386] Taking the Figure 14 shown CFG as an example, for a loop branch node, such as node 10, which is a branch node of a for loop statement, the set of nodes that can be reached is {11, 12, 13, 14, 16}. Note that although node 15 is connected to node 10, as the exit of the loop structure, it is not included in the reachable set. Because the meaning of the reachable set is to assist in making decisions about the next node's direction when restoring the path. For example, when reaching node 10, to determine whether to enter this loop or exit this loop, it is necessary to determine whether there is an intersection between the reachable set of node 10 and the covered node set. If there is no intersection, then the next node will be the exit node, which is node 15 here.

[0387] For a conditional branch node, such as node 3 that does not trigger a loop structure, its reachable set is the complete set {4, 5, 6, 7, 8} that reaches the end node 6 separately from its two child nodes 4 and 7.

[0388] Taking CFG' as an example, nodes 1, 4, 6, and 8 in CFG' are branch nodes. The reachable set of node 1 is {2, 3, 13, 14}, the reachable set of node 4 is {5}, the reachable set of node 6 is {7, 8, 9, 10, 12}, and the reachable set of node 8 is {9, 10, 12}.

[0389] (7) Generation of all paths of the CFG:

[0390] The process of a test case being executed in a real program is reflected in, for example, Figure 15One of the paths is shown in the control flow chart, and each test case will definitely correspond to a complete path when the program execution ends normally. After the algorithm runs to completion, the node coverage and path coverage in the control flow chart represent the coverage of the generated test cases for the objective function.

[0391] A complete path of the CFG is, for example, [0, 1, 2, 3, 4, 5]. Each branch node has a relative path, which describes all the paths between the current branch node and the next branch node or the exit node. For example, the relative paths of node 3 are the two paths between node 3 and node 6, which are [3, 4, 5, 6] and [3, 7, 5, 6] respectively.

[0392] The statistical order of the relative paths is that the nodes closer to the exit node are calculated first. Combining with the depth-first principle, the relative paths of node 3 are calculated first. When calculating node 1 and traversing to node 3, it is not necessary to traverse the nodes below node 3 again. Instead, the path segment between node 1 and node 3 is directly combined with the relative paths of node 3 to form the paths [1, 2, 3, 4, 5, 6] and [1, 2, 3, 7, 5, 6]. Similarly, the relative paths of node 1 combined with node 9 form [1, 8, 9, 10, 11, 6] and [1, 8, 9, 12, 11, 6]. Further up is the entry node 0. Appending node 0 to the beginning of the above four paths forms the full paths of this CFG.

[0393] (8) Parameter dictionary of the objective function:

[0394] For a function, its input parameters may be of basic types, or complex types and custom types. Fundamentally, all parameters can be expanded into nested basic types. When the basic types are further divided, they are actually two most basic categories: integer quantities and floating-point numbers, and are further distinguished by attributes such as bit width and whether it is a pointer. Then these information can be called type information. Complex types such as structures and classes can be expanded into sets of these basic types, and the same is true for custom types. Therefore, the input parameters of a function can be characterized as a set of type information as a whole.

[0395] The input parameter dictionary stores key-value pairs of input parameters and parameter values, and the parameter values exist in the form of a list. Each element of the list is a binary array containing only 0 and 1. Usually, the length of the parameter value list is 1. When the type of the input parameter is a pointer, the length of the list may exceed 1. In each iteration of the chromosome in the genetic algorithm, the input parameter dictionary is updated with the cached results. Using the form of a binary array can better adapt to the cross and mutation links of the algorithm. The initialization strategy of the parameter value can be any one of random initialization, all-zero initialization, intermediate value initialization, etc.

[0396] The input parameter dictionary constructed in this step can be equivalent to the aforementioned input parameter dictionary. For example, the input parameter dictionary can be as Figure 16 shown.

[0397] This input parameter dictionary contains key-value pairs of two parameters, a and b, and their parameter values. Among them, the parameter information includes name, bit width (bw), sign status (sign), mapping type (_type), shape, and pointer bit width (pw).

[0398] The key of parameter a is a_0. The following number 0 indicates the sequence number of this piece of information in the entire input parameter dictionary. The name is the original name of the parameter, a. The bw indicates that 21 binary numbers should be used to represent the value of a. The sign being True indicates that it is signed, that is, the value range can include positive and negative numbers. The _type being int indicates that this is an integer. The shape being empty indicates that this is a constant. The pw only represents the bit width of the pointer expressed by the shape of each dimension when the shape is not empty.

[0399] (9) Automatically generating test cases through the genetic algorithm can be as Figure 17 shown, specifically including:

[0400] Preprocessing: including the generation of CFG, the acquisition of the edge set of CFG, the acquisition of all paths of CFG, the generation of the parameter dictionary of the function, etc.

[0401] The processing of the genetic algorithm can include Scheme 1, Scheme 2, and Scheme 3;

[0402] Collection of test case results and statistics of relevant indicators.

[0403] The three schemes have the same preprocessing method of data and the same final data storage method, with the genetic algorithm as the main heuristic exploration algorithm. The difference lies in the different target objects participating in the convergence or evaluation of the algorithm. That is, Scheme 1 is a genetic algorithm based on edge coverage, Scheme 2 is a genetic algorithm based on path coverage, and Scheme 3 is a genetic algorithm based on sampled edge extended path coverage.

[0404] (10) The genetic algorithm based on edge coverage can be as follows Figure 18 as shown.

[0405] The genetic algorithm based on edge coverage (hereinafter referred to as Solution 1) generates test cases with the goal of covering all edges. For a function object, the genetic algorithm is executed only once to obtain all test case results.

[0406] In each iteration of the population, all chromosomes generate a set of covered nodes SCN through environmental interaction. A minimum path P of all nodes included in SCN can be obtained through the path recovery algorithm, as well as the corresponding edge set SE0 of P. There may be edges in SE0 that are not included in RE. These edges will be taken out of SE0, merged into RE, and removed from SE, which is called updating SE. When SE is empty, that is, all edges have been included in RE, it proves that all edges of the CFG have corresponding test cases to cover, and the algorithm will terminate at this time.

[0407] The manifestation of the genetic algorithm is only in numerical changes, that is, only two numerical change means, crossover and mutation, are used to change the values of the test cases expressed by the chromosomes. The general genetic algorithm stipulates a fixed goal, and all chromosomes of the population are collectively optimized to approach the target result. However, SE in this algorithm, as the target edge set, is constantly changing during the algorithm process. When it cannot change, it is often the case when SE is empty, which already means the termination of the algorithm.

[0408] At the same time, the fitness calculated by this algorithm has a delay effect. The distance calculation of the chromosome occurs after the update of SE. The distance it calculates is already after the optimization goal has changed, that is, the future goal, rather than the goal corresponding to the current population iteration round. If there are edges in the current iteration of the chromosome that are not included, that is, a better result is produced, it does not mean that the calculated distance will be a small value. That is, a good result obtained by the chromosome in the current population iteration round does not completely mean that the gene has a higher probability of being passed on, and this is not linearly related.

[0409] For example, assume that the CFG of the input function can be as follows Figure 21 as shown.

[0410] The numbers in the brackets below the node names represent the position markers of the nodes. a and b represent the two input parameters of the function. Assume that there are currently chromosome C1 (a = 0, b = 5) and chromosome C2 (a = 3, b = 3). If the SE before update is the entire edge set of this CFG, that is, SE = [(0,1),(1,2),(1,3),(2,3),(3,4),(3,5),(4,5)], excluding the edges provided in common, the new edge coverage set provided by C1 will be SE1 = [(1,2),(2,3)], and C2 will provide SE2 = [(1,3)]. Let the updated SE be SEU, then SEU = [(3,4),(4,5)]. At this time, the calculated distance of C1 is the absolute value of the difference between the a value of C1 at node 1 and the value on the right side of the conditional expression, plus the absolute value of the difference between the b value of C1 at node 2 and the value on the right side of the conditional expression, that is, Dist1 = |2 - 1| + |5 - 1| = 5. Similarly, the distance of C2, Dist2 = |3 - 1| + |3 - 1| = 4. C1 provides one more new edge coverage than C2, but in the next round of population iteration, the genes of C2 are more likely to be passed on.

[0411] The above distance calculation, that is, the fitness calculation, is generally only valid within each round of population iteration, rather than between each round of iteration. That is, there is no absolute comparability between the average fitness calculated by the population chromosomes in the current round of iteration and the average fitness calculated by the population chromosomes in the next round, because SE is changing dynamically, that is, the optimization objectives of the two are changing. If SE does not change for several consecutive rounds, the validity of the average fitness of each round can continue at this time, and the average fitness of these rounds is comparable. This brings instability in convergence, but at the same time enhances the randomness of the algorithm, increases the convergence speed, and is more likely to get rid of local optima.

[0412] (XI) The genetic algorithm based on path coverage can be as Figure 19 shown.

[0413] The genetic algorithm based on path coverage (hereinafter referred to as Scheme 2) aims to cover all paths. Different from Scheme 1, its optimized individual is a specific path, which means that when generating test cases for a target function, the total number of all paths that can be shown by its CFG will determine the number of times the genetic algorithm is executed. Therefore, in the algorithm block diagram, the end of the algorithm can be determined by the calculated distance of the chromosome. When the distance is 0, it means that the input parameters of the function expressed by the current chromosome, after the function is executed, the generated path is exactly the same as the target path. The reason why Scheme 1 cannot control the end of the algorithm by distance is that when SE is empty, the distance of the current chromosome must be 0, and when SE is not empty, a non-zero distance can also be calculated. That is, the determination of whether SE is empty implies the determination of a distance of 0.

[0414] Since the number of paths in the CFG affects the number of times the algorithm is executed, to reduce the total time cost, during the interaction between each chromosome and the environment, if an unrecorded path is generated, then this path will be retained, removed from the SP, saving the time for the algorithm to specifically explore this path once.

[0415] Since the goal of the algorithm remains clear and unchanged each time, its convergence is more stable, but at the same time the randomness decreases, and it is difficult to guarantee the convergence speed, especially in the case where the decision interval at the condition is extremely small, or the decision of continuous conditions. At the same time, due to the phenomenon of path explosion, this algorithm can only be used for the case where the scale of the CFG is small, that is, the total number of paths is small.

[0416] (12) The genetic algorithm based on sampled edge extended path coverage can be as Figure 20 shown.

[0417] The genetic algorithm based on sampled edge extended path coverage (hereinafter referred to as Solution 3) aims to cover all edges. Different from Solution 1, this algorithm takes one sampled edge as the target edge each time, and then extends one definite edge from the two nodes of the target edge towards the root node and the leaf node respectively. When multiple parent nodes or multiple child nodes are encountered during the extension process, selection can be made by means of random selection, first parent / child node selection, etc. After determining the unique target path, the distance and fitness are calculated through interaction with the environment. During this process, the unrecorded edges will be updated to reduce the overall number of algorithm iterations. Obviously, this algorithm is a combination of Solution 1 and Solution 2, with the set of target edges as the main object for judging the end of the algorithm, a definite path after sampled edge extension for calculating distance and fitness, and the total number of edges as the number of times the algorithm is executed, but this number will gradually decrease as the algorithm progresses.

[0418] A specific embodiment is provided below.

[0419] Figure 22 The source code with low complexity shown.

[0420] Figure 22 The path coverage result of the CFG of the source code shown can be as Figure 23 shown.

[0421] At this time, the test cases and paths can be as Figure 24 shown.

[0422] The numbers in the path are the numbers on the left side of the CFG node name, indicating the position numbers of the nodes.

[0423] Figure 25 The source code with higher complexity shown.

[0424] Figure 25The path coverage of the CFG shown can be combined as Figure 26A , Figure 26B and Figure 26C as shown. Figures 26A to 26C Connect the lines with the same serial numbers in

[0425] At this time, some test cases and paths can be as Figure 27A , Figure 27B and Figure 27C shown.

[0426] As Figure 28 shown, an embodiment of the present disclosure provides a program testing device, and the device includes:

[0427] An acquisition module, configured to use the input parameters of the target function as the chromosomes of the genetic algorithm to run the target function, and acquire the coverage of the nodes in the first control flow graph CFG corresponding to the target function; the nodes include branch nodes; the branch nodes correspond to the selection statements or loop statements of the target function;

[0428] A first determination module, configured to determine a distance difference according to at least one of the absolute value of the difference between the values on both sides of the judgment conditional operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node;

[0429] A second determination module, configured to determine the fitness of the branch node according to the distance difference;

[0430] An update module, configured to determine the parameter value after updating the input parameters according to the fitness of the branch node;

[0431] A generation module, configured to generate test cases of the target function according to the parameter value after updating the input parameters.

[0432] In some embodiments, the first determination module is specifically configured to perform at least one of the following:

[0433] If the branch node is covered for the first time, determine the distance difference based on the absolute value of the difference between the values on both sides of the judgment conditional operator corresponding to the branch node when it is covered for the first time;

[0434] If the branch node is not covered for the first time, determine the distance difference according to whether the child nodes of the branch node are completely covered and the absolute value of the difference between the values on both sides of the judgment conditional operator corresponding to the chromosome used when the branch node is covered this time;

[0435] If the branch node is not covered, determine that the distance difference has a first value.

[0436] In some embodiments, the first determination module is further configured to, if the branch node is not covered for the first time and there are uncovered child nodes of the branch node, determine the distance difference according to the state of the judgment condition corresponding to the chromosome used for covering the branch node this time;

[0437] If the branch node is not covered for the first time and all child nodes of the branch node are covered, determine that the distance difference has a second value.

[0438] In some embodiments, the first determination module is further configured to perform at least one of the following:

[0439] If the branch node is not covered for the first time and there are uncovered child nodes of the branch node and the judgment condition corresponding to the chromosome used for covering the branch node this time is in a critical state, determine that the distance difference has a third value; the critical state means that the difference between the values on both sides of the operator of the judgment condition of the branch node is a specified value and the judgment result of the judgment condition is false;

[0440] If the branch node is not covered for the first time and there are uncovered child nodes of the branch node and the judgment condition corresponding to the chromosome used for covering the branch node this time is not in a critical state, determine the distance difference based on the absolute value of the difference between the values on both sides of the operator of the judgment condition corresponding to the chromosome used for covering the branch node this time. In some embodiments, the second determination module is used to determine the fitness of the branch node according to the distance difference.

[0441] In some embodiments, the second determination module is further used to determine the fitness according to a functional relationship where dist is the distance difference and fit is the fitness.

[0442] In some embodiments, the first determination module is specifically configured to determine the coverage situation of the child nodes of the branch node according to the reachable set of the branch node in the first CFG; the reachable set is used to represent the set of position marks of all nodes experienced when traversing from the branch node to the end node corresponding to the branch node; the end node refers to the exit node of the branch with the branch node as the root node.

[0443] In some embodiments, the first determination module is specifically configured to determine the coverage situation of the child nodes of the branch node according to the reachable set of the branch node in the first CFG, including:

[0444] When the branch node is the branch node corresponding to the selection statement, compare the nodes covered in the current traversal with the reachable set of the branch node. If there is a node in the nodes covered in the current traversal that corresponds to a certain branch in the reachable set of the conditional branch node, it is determined that the branch corresponding to the branch node is covered; if the branch is covered, the child nodes on the branch are covered.

[0445] When the branch node is the branch node corresponding to the loop statement, compare the nodes covered in the current traversal with the reachable set of the branch node. If the nodes covered in the current traversal include all the nodes in the reachable set of the branch node, it is determined that the loop body of the branch node is covered, and continue to traverse the end node corresponding to the branch node; if the loop body of the branch node is covered, the child nodes of the branch node included in the loop body are covered.

[0446] In some embodiments, the updating module is specifically configured to determine the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm, and different optimization individuals correspond to different evaluation methods; determine the fitness of the optimization individual corresponding to the branch node according to the fitness of the branch node; determine the fitness of the chromosome corresponding to the optimization individual according to the fitness of the optimization individual; update the parameter value of the input parameter according to the fitness of the chromosome.

[0447] In some embodiments, the updating module is further configured to take all the edges of the first CFG as the optimization objective, determine the covered edges of the first CFG corresponding to each chromosome as the covered edges of the first CFG; merge the covered edges corresponding to the chromosomes to obtain the edge set covered by the chromosomes; take the edges with the parent node as the branch node in the edge set as the optimization individual.

[0448] In some embodiments, the updating module is further configured to take all the paths of the first CFG as the optimization objective, obtain the covered paths in the first CFG through environmental interaction feedback for each chromosome; take the covered paths in the first CFG as the optimization individual.

[0449] In some embodiments, the updating module is further configured to take all the edges of the first CFG as the optimization objective, determine the covered edges of the first CFG corresponding to each chromosome as the covered edges of the first CFG;

[0450] Merge the covered edges corresponding to the chromosomes to obtain the edge set covered by the chromosomes;

[0451] Taking one edge in the edge set as the base edge and extending it in two directions towards the root node and the child nodes of the base edge to obtain an extended path; wherein, when encountering multiple nodes or multiple child nodes during the extension process, one node is selected to continue the extension until the root node and / or the end node; using the extended path as the optimization individual.

[0452] In some embodiments, the first determination module is further configured to traverse the first CFG in the traversal order to obtain the position marks of the traversed nodes; determine the depth level of the corresponding nodes according to the number of nodes between the traversed nodes and the root node; and determine the reachable set of each branch node in the first CFG according to the position mark and depth level of a node.

[0453] In some embodiments, the first determination module is further configured to traverse the first CFG downward from the root node with a depth level of 0, and increment the depth level by 1 for each traversed node; when traversing to the branch node of a selection statement, determine the depth level of the branch node of the selection statement by incrementing the depth level of the previous traversed node by 1; determine the depth level of the child nodes of the branch node according to the distance between the child nodes of the branch node and the branch node; when the number of nodes included in different branches under the branch node of the same selection statement is different, use the depth level of the end node of the branch with the depth level determined first in the traversal order as the depth level of the end nodes of all branches of the branch node; when traversing to the branch node of a loop statement, determine the alternative depth level of the branch node of the loop statement by incrementing the depth level of the previous traversed node by 1; when there are multiple alternative depth levels, use the minimum value among the multiple alternative depth levels as the depth level of the branch node of the loop statement; and determine the depth level of the child nodes of the branch node of the loop statement according to the number of nodes between the child nodes of the branch node of the loop statement and the branch node of the loop statement.

[0454] In some embodiments, the first determination module is further configured to traverse to the child nodes of the branch node in the traversal order, record the position marks of all nodes from the branch node containing each child node to the corresponding end node of the branch node in the reachable set; if there are sibling nodes with the same depth level among the child nodes of the branch node, remove the nodes that have been recorded from the reachable set among all nodes from the branch node containing the sibling nodes to the corresponding end node of the branch node until all child nodes of the branch node are included in the reachable set; the reachable set of the branch node does not include the branch node; if the branch node is the branch node of a loop statement, the reachable set does not include the corresponding end node of the branch node.

[0455] In some embodiments, the update module is configured to perform update iterations of the genetic algorithm according to the fitness of the chromosome until the optimization objective of the genetic algorithm is reached or the number of update iterations reaches a set maximum number of iterations; and obtain the updated parameter value of the input parameter according to the population corresponding to the genetic algorithm when the iteration stops.

[0456] In some embodiments, the apparatus further includes:

[0457] A CFG module, configured to generate a second CFG according to the objective function; one node in the second CFG corresponds to one statement of the objective function;

[0458] An expansion module, configured to expand multiple conditions involved in a branch node into multiple single conditions when the second CFG includes a branch node; the branch node corresponds to a selection statement and / or a loop statement of the objective function;

[0459] A construction sub-module, configured to construct a sub-CFG according to the multiple single conditions; wherein, one node in the sub-CFG corresponds to one of the single conditions;

[0460] An obtaining module, configured to replace the corresponding branch node in the second CFG with the sub-CFG to obtain the first CFG.

[0461] In some embodiments, the apparatus further includes:

[0462] A traversal module, configured to pre-order traverse the abstract syntax tree (AST) of the objective function to obtain a node information list of the branch node; the node information list includes:

[0463] The node identifier of the branch node;

[0464] The node type; the node type includes: a non-conditional type, a single-conditional type, and / or a multi-conditional type;

[0465] The judgment condition.

[0466] In some embodiments, the expansion module is configured to, when the second CFG includes a branch node, expand the multiple conditions involved in the branch node into multiple single conditions based on the logical operators in the judgment condition of the multi-conditional type branch node.

[0467] It should be noted that: when describing the above test case generation method provided by the embodiment, only the division of the above program modules is used for illustration. In practical applications, the above processing can be allocated to different program modules according to needs, that is, the internal structure of the device is divided into different program modules to complete all or part of the above-described processing. In addition, the test case generation device provided by the above embodiment and the embodiment of the test case generation method belong to the same concept. For the specific implementation process, please refer to the method embodiment, which will not be elaborated here.

[0468] Based on the hardware implementation of the above program modules, and in order to implement the method of the embodiments of the present application, the embodiments of the present application further provide an electronic device. Figure 12 Only the exemplary structure of the test case generation device is shown, rather than all structures, and part or all of the structures shown can be implemented according to needs. Figure 29 The part or all of the structures shown.

[0469] Such as Figure 29 As shown, the electronic device 1000 provided by the embodiments of the present application includes: at least one processor 1001, a memory 1002, a user interface 1003, and at least one network interface 1004. Each component in the electronic device 1000 is coupled together through a bus system 1005. It can be understood that the bus system 1005 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 1005 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, in Figure 29 All kinds of buses are labeled as the bus system 1005.

[0470] Among them, the user interface 1003 may include a display, a keyboard, a mouse, a trackball, a click wheel, a button, a touchpad, or a touch screen, etc.

[0471] The memory 1002 in the embodiments of the present application is used to store various types of data to support the operation of the test case generation device. Examples of these data include: any computer program for operating on the test case generation device.

[0472] The test case generation method disclosed in the embodiments of the present application can be applied to the processor 1001 or implemented by the processor 1001. The processor 1001 may be an integrated circuit chip with signal processing capabilities. During implementation, the steps of the test case generation method can be completed by the integrated logic circuit in the hardware of the processor 1001 or instructions in software form. The above-mentioned processor 1001 may be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 1001 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. Combining the steps of the method disclosed in the embodiments of the present application can be directly embodied as being executed and completed by the hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. The software module may be located in the storage medium, and this storage medium is located in the memory 1002. The processor 1001 reads the information in the memory 1002 and combines its hardware to complete the steps of the test case generation method provided in the embodiments of the present application.

[0473] In an exemplary embodiment, the electronic device can be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontroller units (MCUs), microprocessors, or other electronic components, and is used to execute the foregoing method.

[0474] It can be understood that the memory 1002 can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read-Only Memory), an erasable programmable read-only memory (EPROM, Erasable Programmable Read-Only Memory), an electrically erasable programmable read-only memory (EEPROM, Electrically Erasable Programmable Read-Only Memory), a ferromagnetic random access memory (FRAM, ferromagnetic random access memory), a flash memory (Flash Memory), a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM, Compact Disc Read-Only Memory); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM, Random Access Memory), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as a static random access memory (SRAM, Static Random Access Memory), a synchronous static random access memory (SSRAM, Synchronous Static Random Access Memory), a dynamic random access memory (DRAM, Dynamic Random Access Memory), a synchronous dynamic random access memory (SDRAM, Synchronous Dynamic Random Access Memory), a double data rate synchronous dynamic random access memory (DDR SDRAM, Double Data Rate Synchronous Dynamic Random Access Memory), an enhanced synchronous dynamic random access memory (ESDRAM, Enhanced Synchronous Dynamic Random Access Memory), a sync link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), a direct rambus random access memory (DRRAM, Direct Rambus Random Access Memory).The memories described in the embodiments of the present application are intended to include, but are not limited to, these and any other suitable types of memories.

[0475] In an exemplary embodiment, the embodiments of the present application also provide a storage medium, namely a computer storage medium, specifically a computer-readable storage medium. For example, it includes a memory 1002 storing a computer program, and the above computer program can be executed by a processor 1001 of an electronic device to complete the steps of the method in the embodiments of the present application. The computer-readable storage medium can be a memory such as ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface memory, optical disc, or CD-ROM.

[0476] It should be noted that: "first", "second", etc. are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence.

[0477] In addition, the technical solutions described in the embodiments of the present application can be combined arbitrarily without conflict.

[0478] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A test case generation method, characterized in that, The method includes: Taking the input parameters of the objective function as the chromosomes of the genetic algorithm to run the objective function, and obtaining the coverage of the nodes in the first control flow graph (CFG) corresponding to the objective function; the nodes include branch nodes; the branch nodes correspond to the selection statements or loop statements of the objective function; Determining a distance difference according to at least one of the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node; Determining the fitness of the branch node according to the distance difference; Determining the updated parameter value of the input parameter according to the fitness of the branch node; Generating a test case for the objective function according to the updated parameter value of the input parameter.

2. The method according to claim 1, wherein Determining a distance difference according to at least one of the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node, including at least one of the following: If the branch node is covered for the first time, determining the distance difference based on the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the branch node when it is covered for the first time; If the branch node is not covered for the first time, determining the distance difference according to whether the child nodes of the branch node are completely covered and the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the chromosome used for covering the branch node this time; If the branch node is not covered, determining that the distance difference has a first value.

3. The method according to claim 2, wherein If the branch node is not covered for the first time, determining the distance difference according to whether the child nodes of the branch node are completely covered and the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the chromosome used for covering the branch node this time, including at least one of the following: If the branch node is not covered for the first time and there are uncovered child nodes of the branch node, determining the distance difference according to the state of the judgment condition corresponding to the chromosome used for covering the branch node this time; If the branch node is not covered for the first time and all child nodes of the branch node are covered, determining that the distance difference has a second value.

4. The method according to claim 3, wherein If the branch node is not covered for the first time and there are uncovered child nodes of the branch node, determining the distance difference according to the state of the judgment condition corresponding to the chromosome used for covering the branch node this time, including: If the branch node is not covered for the first time and there are uncovered child nodes of the branch node and the judgment condition corresponding to the chromosome used for covering the branch node this time is in a critical state, determining that the distance difference has a third value; the critical state means that the difference between the values on both sides of the operator of the judgment condition of the branch node is a specified value and the judgment result of the judgment condition is false; If the branch node is not covered for the first time and there are uncovered child nodes of the branch node, and the judgment condition corresponding to the chromosome used to cover the branch node this time is not in a critical state, determine the distance difference based on the absolute value of the difference between the values on both sides of the judgment condition operator corresponding to the chromosome used to cover the branch node this time.

5. The method according to any one of claims 1 to 4, characterized in that, The determining the fitness of the branch node according to the distance difference includes: According to the functional relationship determine the fitness; Where dist is the distance difference and fit is the fitness.

6. The method according to any one of claims 1 to 4, characterized in that, Running the objective function with the input parameters of the objective function as the chromosomes of the genetic algorithm to obtain the coverage of the nodes in the first control flow graph CFG corresponding to the objective function, includes: Determine the coverage of the child nodes of the branch node according to the reachable set of the branch node in the first CFG; the reachable set is used to represent the set of position markers of all nodes experienced by the branch node when traversing to the end node corresponding to the branch node; the end node refers to the exit node of the branch with the branch node as the root node.

7. The method according to claim 6, characterized in that, Determine the coverage of the child nodes of the branch node according to the reachable set of the branch node in the first CFG, includes: When the branch node is the branch node corresponding to the selection statement, compare the nodes covered in this traversal with the reachable set of the branch node. If there is a node in the nodes covered in this traversal that corresponds to a certain branch in the reachable set of the conditional branch node, it is determined that the branch corresponding to the branch node is covered; if the branch is covered, the child nodes on the branch are covered; When the branch node is the branch node corresponding to the loop statement, compare the nodes covered in this traversal with the reachable set of the branch node. If the nodes covered in this traversal include all the nodes in the reachable set of the branch node, it is determined that the loop body of the branch node is covered, and continue to traverse the end node corresponding to the branch node; if the loop body of the branch node is covered, the child nodes of the branch node included in the loop body are covered.

8. The method according to claim 1, characterized in that, The determining the parameter value of the updated input parameter according to the fitness of the branch node includes: Determine the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm. Different evaluation methods correspond to different optimized individuals; Determine the fitness of the optimized individual corresponding to the branch node according to the fitness of the branch node; Determine the fitness of the chromosome corresponding to the optimized individual according to the fitness of the optimized individual; Update the parameter value of the input parameter according to the fitness of the chromosome.

9. The method according to claim 8, characterized in that, The determining the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm includes: Taking all the edges of the first CFG as the optimization objective, determine the edges covered by the first CFG corresponding to each chromosome as the edges covered by the first CFG; Merge the edges covered by the chromosome to obtain the set of edges covered by the chromosome; Taking the edges with the parent node as the branch node in the edge set as the optimized individual.

10. The method according to claim 8, characterized in that, Determining the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm includes: Taking all paths of the first CFG as the optimization objective, and obtaining the covered paths in the first CFG for each chromosome through environmental interaction feedback; Taking the covered paths in the first CFG as the optimization individuals.

11. The method according to claim 8, characterized in that, Determining the evaluation method of the fitness of the chromosome according to the optimization objective corresponding to the genetic algorithm includes: Taking all edges of the first CFG as the optimization objective, and determining the covered edges of the first CFG for each chromosome corresponding to the covered paths of the first CFG; Merging the covered edges corresponding to the chromosome to obtain the set of covered edges corresponding to the chromosome; Taking one edge in the edge set as the base edge and extending in two directions of the root node and the child node of the base edge to obtain an extended path; wherein, when encountering multiple nodes or multiple child nodes during the extension process, select one node to continue the extension until the root node and / or the end node; Taking the extended path as the optimization individual.

12. The method according to claim 6, wherein The method further includes: Traversing the first CFG in the traversal order to obtain the position marks of the traversed nodes; Determining the depth level of the corresponding node according to the number of nodes between the traversed node and the root node; Determining the reachable set of each branch node in the first CFG according to the position mark and depth level of a node.

13. The method according to claim 12, characterized in that, Determining the depth level of the corresponding node according to the number of nodes between the traversed node and the root node includes: Traversing the first CFG downward from the root node with a depth level of 0, and adding 1 to the depth level for each traversed node; When traversing to the branch node of the selection statement, determining that the depth level of the previous traversed node plus 1 is the depth level of the branch node of the selection statement; Determining the depth level of the child node of the branch node according to the distance between the child node of the branch node and the branch node; When the number of nodes included in different branches under the branch node of the same selection statement is different, taking the depth level of the end node of the branch with the depth level determined first according to the traversal order as the depth level of the end nodes of all branches of the branch node; When traversing to the branch node of the loop statement, determining that the depth level of the previous traversed node plus 1 is the alternative depth level of the branch node of the loop statement; When there are multiple alternative depth levels, taking the minimum value of the multiple alternative depth levels as the depth level of the branch node of the loop statement; Determining the depth level of the child node of the branch node of the loop statement according to the number of nodes at the distance between the child node of the branch node of the loop statement and the branch node of the loop statement.

14. The method according to claim 12, wherein Determining the reachable set of each branch node in the first CFG according to the position mark and depth level of a node includes: Traversing to the child node of the branch node in the traversal order, and recording the position marks of all nodes from the branch node containing each child node to the corresponding end node of the branch node into the reachable set; If there are sibling nodes with the same depth level among the child nodes of the branch node, then the nodes that have been recorded among all the nodes traversing from the branch node containing the sibling nodes to the end node corresponding to the branch node are removed from the reachable set until all the child nodes of the branch node are included in the reachable set; the reachable set of the branch node does not include the branch node; if the branch node is a branch node of a loop statement, then the reachable set does not include the end node corresponding to the branch node.

15. The method according to any one of claims 1 to 4 and 8 to 14, wherein updating the parameter value of the input parameter according to the fitness of the chromosome comprises: Performing update iteration of the genetic algorithm according to the fitness of the chromosome until the optimization objective of the genetic algorithm is reached or the number of update iterations reaches the set maximum number of iterations; Obtaining the updated parameter value of the input parameter according to the population corresponding to the genetic algorithm when the iteration stops.

16. The method according to any one of claims 1 to 4 and 8 to 14, characterized in that, The method further comprises: Generating a second CFG according to the objective function; one node in the second CFG corresponds to one statement of the objective function; When the second CFG contains a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions; the branch node corresponds to a selection statement and / or a loop statement of the objective function; Constructing a sub-CFG according to the multiple single conditions; wherein one node in the sub-CFG corresponds to one of the single conditions; Replacing the corresponding branch node in the second CFG with the sub-CFG to obtain the first CFG.

17. The method according to claim 16, wherein The method further comprises: Performing pre-order traversal on the abstract syntax tree AST of the objective function to obtain a node information list of the branch node; the node information list includes: The node identifier of the branch node; The node type; the node type includes: non-conditional type, single-conditional type, and / or multi-conditional type; The judgment condition.

18. The method according to claim 17, wherein When the second CFG contains a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions comprises: When the second CFG contains a branch node, expanding the multiple conditions involved in the branch node into multiple single conditions based on the logical operator in the judgment condition of the multi-conditional type branch node.

19. A test case generation device, characterized in that, The apparatus comprises: An acquisition module, configured to run the objective function with the input parameter of the objective function as the chromosome of the genetic algorithm, and acquire the coverage of the nodes in the first control flow graph CFG corresponding to the objective function; the nodes include branch nodes; the branch nodes correspond to selection statements or loop statements of the objective function; A first determination module, configured to determine a distance difference according to at least one of the absolute value of the difference between the numerical values on both sides of the judgment condition operator corresponding to the branch node, the coverage of the branch node, and the coverage of the child nodes of the branch node; A second determination module, configured to determine the fitness of the branch node according to the distance difference; An update module, configured to determine the updated parameter value of the input parameter according to the fitness of the branch node; A generation module, configured to generate a test case of the objective function according to the parameter value after the input parameter is updated.

20. An electronic device, characterized in that, Comprising: a processor and a memory for storing a computer program capable of running on the processor, wherein when the processor is used to run the computer program, it executes the steps of the method according to any one of claims 1 to 18.

21. A computer storage medium, characterized in that, The computer storage medium stores one or more programs, and the one or more programs can be executed by one or more processors, so that the one or more processors execute the test case generation method according to any one of claims 1 to 18.