Code coverage tool testing method based on automatic synthesis of structured programs
Through the method of automatic synthesis of structured programs, multiple control flow structure sequences are generated and program frameworks are built. The correctness of code coverage tools is verified by invariant forms, and the problem of insufficient testing complexity and universality of code coverage tools in the existing technology is solved, achieving more efficient testing and more accurate results.
Patent Information
- Application Number
- CN202210428792.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-22
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2042-04-22
AI Technical Summary
The existing code coverage tool accuracy testing methods have problems such as complex structure, unfavorable for debugging, poor versatility, inability to quickly apply to different languages, and huge workloads for subsequent manual analysis.
Using the method of automatic synthesis of structured programs, multiple control flow structure sequences are generated through enumeration algorithms, a program framework is built, and the concept of invariant is used as a test oracle to generate invariant to verify the correctness of coverage report.
It reduces the complexity of test case programs, reduces the workload of manual analysis, ensures the universality and correctness of the test, and finds multiple errors in the LLVM coverage tool, the mainstream C compiler.
Smart Images

Figure CN114780406B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a code coverage tool testing method based on automatic synthesis of structured programs. Background Art
[0002] Code coverage is a metric in software testing that describes the proportion and extent of source code in a program that is tested, analyzed from the level of detail of coverage of source program statements.
[0003] Code coverage is widely used in many software testing technologies, such as regression testing based on coverage, compiler testing, debugging optimization, etc. By analyzing the uncovered code in the coverage report, we can infer whether the previous test design is sufficient, whether the uncovered areas are blind spots in the design, etc., and then we can supplement the test case design; if useless code is detected in the program, we can infer the unreasonableness in the code design. It can be seen that code coverage plays an important role in both scientific research and actual production. Therefore, the correctness of the code coverage tool is very critical.
[0004] Currently, there is little work focusing on coverage tool correctness testing. After investigating the existing work, it is found that there are two main methods for testing the correctness of code coverage tools: differential testing and metamorphosis testing. The test cases of the above two methods are from Csmith and existing compiler test suites. These test programs are complex in structure and not conducive to debugging, and the subsequent manual analysis workload is huge; and the current work is focused on C language coverage tools, and the methods are less versatile and cannot be quickly applied to different languages. In addition, to ensure the universality of the test method, it is necessary to solve the test Oracle problem, that is, how to judge whether the report given by a coverage tool is correct. Summary of the invention
[0005] Currently, there are few tools for code coverage, and most of them have problems such as complex structure, inconvenient debugging, poor versatility, inability to quickly adapt to different languages, and huge workload for subsequent manual analysis. To solve the above problems, the present invention is implemented through the following technical solutions.
[0006] A code coverage tool testing method based on automatic synthesis of structured programs, characterized by comprising the following steps:
[0007] Step 1): Input the number of control flow structures n contained in the automatically synthesized structured program, and use the enumeration algorithm to repeatedly arrange and generate multiple control flow structure sequences, where one structure sequence is represented by SS[n+1]={S0,S1,...,S n}, where S0 is the Main function structure, and the rest of S1 to S n For control flow structures;
[0008] Step 2): According to the properties of the control flow itself and the position in the structure sequence, for each structure S in the sequence index Initialize the insertable point position array PS index [], each position array internal element is a pair of two tuples of insertable point positions;
[0009] Step 3): Take the structure sequence obtained in step 1) and the position array corresponding to each structure obtained in step 2) as input, build a program framework consisting of the Main function and the control flow structure. During the construction process, use the enumeration plus deduplication algorithm to generate a program for each control flow structure S index (1≤index≤n) from the position array PS index-1 [] selects a reasonable pair as the control flow structure insertion point. When all S index (1≤index≤n) The corresponding insertion positions are determined, and the program framework is built;
[0010] Step 4): According to the grammatical rule constraints, randomly select a reasonable expression as a conditional judgment statement for each control flow structure, and randomly insert a number of expression statements, assignment statements, jump statements, etc. into the program framework to enrich the semantic information of the generated program;
[0011] Step 5): In step 4), different conditional judgment statements, expression statements or assignment statements may use the same variable, so a declaration statement deduplication algorithm is introduced to select the lower bound of the declaration position in the current program for each variable, and randomly select a position information from the upper bound of the position information to the current lower bound to insert the declaration statement to ensure that the generated program can be compiled correctly;
[0012] Step 6): Analyze the control flow structure, judgment statements and jump statements determined in step 5) to eliminate explicit dead loops;
[0013] Step 7): Add empty statements to the control flow structure without any structured statements inside, build a complete structured program, and synthesize the test program source code corresponding to the program;
[0014] Step 8): predict the execution status of the structure generated in step 7), mark the control flow structure and statements according to the explicit execution, explicit non-execution and unclear execution status, and generate invariants by combining the program structure information and the execution status marking results;
[0015] Step 9): Call the compiler coverage tool to generate a coverage report corresponding to the test program source code in step 7), and use the invariant rule to test the correctness of the coverage report. If the report does not satisfy the invariant, it is considered that there may be an error in the coverage tool.
[0016] The above method for testing a code coverage tool based on automatic synthesis of structured programs is characterized in that, in step 1), the control flow structures for repeated permutation using the enumeration algorithm are 5 common selection structures If / If-Else and loop structures For / While / Do-While. When the number of input control flows is n, the algorithm will generate 5 n control flow structure sequences, and the first element of all sequences is Main.
[0017] The above method for testing a code coverage tool based on automatic synthesis of structured programs is characterized in that, in step 2), there is one Main function structure and n control flow structures in the structure sequence. Each structure corresponds to an insertable point position array PS[]. A total of n + 1 insertable point position arrays PS0 to PS n exist in a structure sequence; the elements in all insertable point position arrays are several pairs Pair, and the form of Pair is <index, position>, where index represents the index in the structure sequence and position represents the internal code block index of the structure.
[0018] The above method for testing a code coverage tool based on automatic synthesis of structured programs is characterized in that, in step 3), for each control flow structure S index (1 ≤ index ≤ n), when selecting a reasonable Pair from the position array PS index-1 [] as the insert point of the control flow structure, a constraint relationship needs to be followed to ensure that the generated synthesized program framework is unique.
[0019] The above method for testing a code coverage tool based on automatic synthesis of structured programs is characterized in that a deduplication algorithm is used to describe the constraint relationship. The deduplication algorithm stipulates that for two control flow structures S i and S j (i < j), the selected Pairs i =<index i , position i > and Pair j =<index j , position j > must satisfy the following conditions: (index i < index j ) ∨ ((index i = index j ) ∧ (position i ≤ position j ))).
[0020] The above-mentioned code coverage tool testing method based on automatic synthesis of structured programs is characterized in that the declaration position of the variable in the step 5) is represented by a position binary pair Pair. If the Pairs of two variables are the same, it means that the two variables are located in the same code block and the scopes of the two variables are also the same; the declaration statement deduplication algorithm solves the conflict between the two pairs corresponding to the same variable, and uses the least common multiple idea to select the declaration position with a larger scope to ensure the correctness of program compilation.
[0021] The above-mentioned code coverage tool testing method based on automatic synthesis of structured programs is characterized in that, in step 8), the selectable labels for predicting and marking the control flow structure and statement execution status in the program framework generated in step 7) are Executed, UN-Executed and Unknown; the invariant generated in step 8) is an equation that uses code line numbers to describe the expected coverage results.
[0022] The above-mentioned code coverage tool testing method based on automatic synthesis of structured programs is characterized in that the compiler coverage tool called in step 9) affects the way of defining coverage. Different compilers define coverage in different ways. Before using invariant verification, the coverage report is read for format conversion, and the execution number is translated into a numerical format according to the meaning specified by the compiler. The execution number -1 is used to represent the unobserved points in the coverage report given by the compiler.
[0023] The present invention adopts the above technical solution and has the following beneficial effects:
[0024] 1. The present invention utilizes the idea of structured programming to divide the program into several control flow structure modules, and splices and synthesizes them in a combined and nested manner, which effectively reduces the complexity of the test case program, greatly reduces the workload of subsequent manual analysis of coverage tool errors, and ensures rich structured information of the program.
[0025] 2. The present invention proposes the concept of invariants as test oracle. The invariant rules shield the differences in syntax of different languages, use line numbers as the test basis, and use reachability analysis results to generate invariants, thereby ensuring the correctness of the test oracle and the universality of the generation method.
[0026] 3. The method of code coverage tool testing based on automatic synthesis of structured programs described in the present invention has currently found multiple errors in the LLVM coverage tool of the mainstream C language compiler. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a schematic diagram of the overall flow of an embodiment of the present invention.
[0028] Figure 2 Generate structural sequence diagrams for the present invention.
[0029] Figure 3 This is a schematic diagram of initializing the position array of the present invention. DETAILED DESCRIPTION
[0030] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0031] Figure 1 FIG. 1 is a flow chart of a code coverage tool testing method based on automatic synthesis of structured programs according to the present invention. Figure 1 As shown, it mainly includes the following steps:
[0032] Step 1): Input the number of control flow structures n contained in the automatically synthesized structured program, and use the enumeration algorithm to repeatedly arrange and generate multiple control flow structure sequences, one of which can be expressed as SS[n+1]={Main,S1,...,S n}.
[0033] The step 1) specifically comprises the following steps:
[0034] Step 1.1) Initialize the structure sequence array SS[n+1] according to the number of input control flow structures n, where the first element of all sequences is initialized to Main, indicating that all control flow structures exist in the body of the main function method.
[0035] Step 1.2) The present invention supports the generation of the following five common control flow structures, namely, the selection structure If / If-Else and the loop structure For / While / Do-While. After determining that the number of control flows is n, the enumeration algorithm performs repeatable arrangement. Since the control flow structure allows repetition, the elements at each position have 5 different ways of being selected, so a total of 5 are generated. n A control flow structure sequence, where the generated structure sequence {Main, S For ,S While ,S IfElse The process of Figure 2 shown.
[0036] Step 2): According to the properties of the control flow itself and the position in the structure sequence, for each structure S in the sequence index Initialize the insertable point position array PS index [], each position array internal element is a pair of two tuples of insertable point positions;
[0037] There are n structures in the control flow structure sequence. The method performs a index Initialize an insertable position array PS index, which means that when the structure S is added to the program index After that, the next structure S index+1 All reasonable places to insert.
[0038] The elements in the position array are pairs of the form<index,position> , indicating an insertable point in the current structure. Index indicates the index of the control flow structure to be inserted in the structure sequence, ranging from 0 to n. Position indicates the index of the code block inside the control flow structure, that is, the part enclosed by curly braces "{" and "}". For the Main function, If structure, For / While / Do-While loop structure with only one code block inside, the position value can only be 0; for the If-Else structure with two code blocks inside, the position value can be 0 or 1.
[0039] The position array initialization algorithm is as follows: when index = 0, PS0 is initialized to [<0,0>]; when index = i, the corresponding control flow structure is S i If the structure is IF / For / While / Do-While and there is only one code block enclosed in curly braces, then PS i =PS i-1 +<i,0> ; If this structure is If-Else, with two code blocks inside, then PS i =PS i-1 +<i,0> +<i,1> .
[0040] Combined with the actual structure sequence {Main,S For ,S While ,S IfElse} Explain the process of initializing the position array. The initialization process is as follows Figure 3 As shown:
[0041] (1) When index = 0, the control flow structure is Main. This structure has only one method body, so the position array PS0 = [<0,0>], that is, S For The only selectable insertion point is within the method body (position = 0) of the Main function (index = 0).
[0042] (2) When index = 1, the For structure has only one internal code block, so the position array PS1 is updated to [<0,0>,<1,0>], indicating that the next structure S While There are two places where it can be inserted, namely the Main structure and the For structure.
[0043] (3) When index = 2, the While structure also has only one internal code block. Therefore, the updated position array PS2 = [<0,0>, <1,0>, <2,0>].
[0044] (4) When index = 3, the If-Else structure has two internal code blocks. The updated position array PS3 = [<0,0>, <1,0>, <2,0>, <3,0>, <3,1>].
[0045] Step 3): Using the structure sequence obtained in Step 1 and the position array corresponding to each structure obtained in Step 2 as inputs, build a program framework consisting of the Main function and control flow structures. During the building process, use the method of enumeration plus duplicate removal algorithm to select a reasonable Pair from the position array PS index (1 ≤ index ≤ n) as the insertion point of the control flow structure. When all S index-1 [] have determined their corresponding insertion positions, the program framework building is completed; index (1 ≤ index ≤ n)
[0046] Step 3.1): When index = 1, the control flow structure S1 selects an insertion position pair Pair from the position array PS0[]. Therefore, only <0,0> can be selected.
[0047] Step 3.2): When index > 1, the control flow structure S index selects an insertion position pair Pair from the position array PS index-1 []. The selection of this pair needs to satisfy the constraints of the duplicate removal algorithm.
[0048] Step 3.3): The constraints of the duplicate removal algorithm are as follows. It stipulates that for two control flow structures S i and S j (i < j), the Pair i = <index i , position i > and Pair j = <index j , position j > must satisfy the following conditions:
[0049] (index i < index j ) ∨ ((index i = index j ) ∧ (position i ≤ position j ))
[0050] If this condition is not met, it means that the program framework arranged in this way is repeated, so it is discarded by the deduplication algorithm and the insertion point position Pair of the next round is directly selected.
[0051] Step 4): According to the grammatical rule constraints, randomly select a reasonable expression as a conditional judgment statement for each control flow structure, and randomly insert a number of expression statements, assignment statements, jump statements, etc. to enrich the semantic information of the generated program. The specific steps are as follows:
[0052] Step 4.1) Set the control flow structure conditional statement. Different structures have different judgment conditions or loop conditions. The selection structure If and If-Else require the conditional statement to be a Boolean expression; the conditional statement of the For loop structure includes an initialization statement, a judgment conditional statement, and a control conditional statement; the conditional statement of While and Do-While is a Boolean expression, usually a variable value judgment for self-increment. Therefore, the present invention matches each structure in the structure sequence with a reasonable conditional statement according to its grammatical requirements.
[0053] Step 4.2) Conditional statement variation: Based on the grammatical rules, the invention makes a series of variations on conditional statements, such as a For loop without a termination condition, and a conditional expression that is always true or always false, to provide information for subsequent prediction of program execution.
[0054] Step 4.3) Add expression statements, assignment statements, and jump statements reasonably. Except for jump statements, other statements do not directly affect the program execution flow. The basic statements in the method body are executed in the order of their appearance. The invention includes statements such as variable declaration, variable increment and decrement, and allocation of pointer memory space. Weak jump instructions affect the execution flow of the current structure and its internal code blocks. The invention includes break statements in loops. Strong jump instructions affect the overall execution flow of the program. The invention includes return statements and exit functions.
[0055] Step 4.4) After the program framework is determined, the position array PS3 of S3: [<0,0>,<1,0>,<2,0>,<3,0>,<3,1>] is all the current insertable positions. When the above statements are added to the program framework, the random insertion strategy is adopted to ensure the randomness of the execution order of statements in the same method body. At the same time, the following constraints must be met:
[0056] (1) Basic statements can be added at any position;
[0057] (2) Weak jump instructions can only be added to loop structures;
[0058] (3) The return and exit statements in the strong jump instructions have no restrictions on the insertion position.
[0059] Step 5): In step 4), different conditional judgment statements, expression statements or assignment statements may use the same variable, so a declaration statement deduplication algorithm is introduced to select the lower bound of the declaration position in the current program for each variable, and randomly select a position information from the upper bound of the position information to the current lower bound to insert the declaration statement to ensure that the generated program can be compiled correctly. The specific steps are as follows:
[0060] Step 5.1) Traverse all variables used in the program and save their occurrence location information.
[0061] Step 5.2) If the position information is empty, it means that the variable is not used and does not need to be declared; if there is only one position information, it means that the variable has only been used once, so this position information is the lower bound of the declaration statement, and the declaration statement can select any upper node of the position information; if there is more than one position information, it means that the variable has been used multiple times. At this time, it is necessary to find the minimum upper bound of the two position information as the lower bound of this declaration statement.
[0062] In step 5.3), the upper bound of all variable declaration statements is outside the Main function, that is, global variables. Therefore, the variable declaration statement can randomly select a position information from the upper bound global variable to the lower bound of the declaration statement calculated in step 5.2) as the insertion position of this variable declaration statement.
[0063] Step 6): Analyze the control flow structure, judgment statements and jump statements determined in step 5) to eliminate explicit dead loops. Since the control flow statement is modified in step 4), an infinite loop structure is introduced, and it is necessary to traverse the control flow structure sequence {Main, S1, ..., S n}, and for each control flow structure S i To make an explicit infinite loop judgment, the specific steps are as follows:
[0064] Step 6.1) S i For Main function or selection structure If or If-Else, judgment is made in no order;
[0065] Step 6.2) S i For a loop structure, if (1) the loop does not have a loop termination conditional statement; or (2) the loop termination conditional statement is always true, it is necessary to determine whether the code block inside the loop contains a jump statement;
[0066] Step 6.3) If the inner code block of the loop does not contain any jump statements, this loop structure is an explicit infinite loop, so you need to randomly add jump statements such as return / exit / break in the inner code block; if the inner code block contains jump statements, but it is not sure whether to execute them, it defaults to a non-explicit infinite loop, which will be handled when executing the compiler script.
[0067] This step can eliminate explicit dead loops in the program, but in order to ensure the richness of program semantics, all possible dead loops are not eliminated. Therefore, when the source file is executed later to generate a coverage report, the execution time is judged. If it exceeds 3 seconds, the program is marked as timeout_error and is subsequently handled manually.
[0068] Step 7): Add empty statements to the control flow structure without any structured statements inside, build a complete structured program, and synthesize the test program source code corresponding to the program.
[0069] If the control flow structure code block does not have any statements, a control flow structure without curly braces and inner statements will be generated when the program is generated, and the generated program source code will produce errors when it is compiled. Therefore, after completing the above insertion of expression statements, jump statements, and declaration statements, add an empty statement ";" to the structure with an empty code block to avoid compilation errors.
[0070] Step 8): Predict the execution of the structure generated in step 7), mark the control flow structure and statements according to the explicit execution, explicit non-execution and unclear execution, and generate invariants by combining the program structure information and the execution status marking results. The specific steps are as follows:
[0071] Step 8.1) The rules for marking the execution of the control flow structure S are as follows:
[0072] (1) If the superstructure containing S is marked as UN-Executed, S is also UN-Executed;
[0073] (2) If a jump statement is encountered while traversing other structures at the same level as structure S, S is marked as UN-Executed;
[0074] (3) If control flow structure A and structure S are at the same level, and according to the previous labeling result, control flow structure A contains a termination statement that must be executed, then structure S is marked as UN-Executed
[0075] Step 8.2) The execution of the inner code block of the control flow structure S is determined by its own structure and the nature of the conditional expression. The calculation rules for the execution of the inner code block of S are as follows (if S is an If-Else structure, the execution of the else_body code block is as follows):
[0076] (1) If either the conditional expression or its own execution status is UN-Executed, the inner code block is also UN-Executed (else_body is Executed);
[0077] (2) If either the conditional expression or its own execution status is Unknown, the inner code block is also Unknown (else_body is Unknown);
[0078] (3) If both the conditional expression and the execution status itself are Executed, the inner code block is also Executed (else_body is UN-Executed).
[0079] The priority of the above rules is (1)>(2)>(3).
[0080] Step 8.3) Generate invariants. The present invention introduces the concept of invariants to represent a universal test oracle. An invariant is a constraint that uses line numbers to describe the execution flow of a program, such as the number of executions between two lines is equal, the number of executions of a line should be zero, and so on. The generation of invariants mainly uses the execution status labels of the previous steps and the properties of the structure itself. The rules for generating invariants are as follows:
[0081] (1) For control flow structures and statements marked as Executed, the execution count must be greater than 0;
[0082] (2) For control flow structures and statements marked as UN-Executed, the execution count must be 0;
[0083] (3) In the Main function, the sum of the execution times of all forced jump statements is no more than 1;
[0084] (4) The execution count of the Main function entry must be 1;
[0085] (5) For non-loop structures and statements at the same level in the same code block, if they are both marked as Executed, the execution times of the corresponding line numbers are equal;
[0086] (6) In the IfElse structure, the sum of the execution times of the if_body code block and the else_body code block is equal to the execution times of the IfElse conditional expression;
[0087] (7) For a loop structure without a loop termination condition, the number of times the loop condition is executed is equal to the number of times the statements inside the loop are executed;
[0088] (8) The number of times the conditional expression of the loop structure is executed is not less than the number of times the statements inside the loop are executed, and so on.
[0089] Step 9): Call the compiler coverage tool to generate a coverage report corresponding to the test program source code in step 7), and use the invariant generated in step 8) to test the correctness of the coverage report. If the report does not satisfy the invariant, it is considered that there may be an error in the coverage tool. The specific steps are as follows:
[0090] Step 9.1) Call the compiler coverage tool test script to determine the script execution status, whether the source program is compiled correctly, whether the executable program execution times out, and whether it is executed correctly to generate a valid coverage report.
[0091] Step 9.2) Convert the generated coverage report into the array report[]. report[line]=count means that the code with line number line in the coverage report is executed count times. Different compilers have different definitions of execution status. For example, GCC uses the string "#####" to indicate that this line is not executed, but LLVM uses the number 0 to indicate it.
[0092] Step 9.3) reads the invariant rules generated in step 8) to verify the correctness of report[]. If the invariant rules are not met, it is considered that the coverage tool may have errors.
[0093] The above is only a preferred embodiment of the present invention, but the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Any simple modification, equivalent changes and modifications made to the above embodiments by any technician familiar with the profession according to the technical essence of the present invention without departing from the principle and spirit of the present invention shall be included in the protection scope of the present invention.
Claims
1. A code coverage tool testing method based on automatic synthesis of structured programs, characterized in that: The steps include: Step 1): Input the number of control flow structures n contained in the automatically synthesized structured program, and use the enumeration algorithm to repeatedly arrange and generate multiple control flow structure sequences, where one structure sequence is represented by SS[n+1]={S0,S1,...,S n }, where S0 is the Main function structure, and the rest of S1 to S n For control flow structures; Step 2): According to the properties of the control flow itself and the position in the structure sequence, for each structure S in the sequence index Initialize the insertable point position array PS index [], each position array internal element is a pair of two tuples of insertable point positions; Step 3): Take the structure sequence obtained in step 1) and the position array corresponding to each structure obtained in step 2) as input, build a program framework consisting of the Main function and the control flow structure. During the construction process, use the enumeration plus deduplication algorithm to generate a program for each control flow structure S index (1≤index≤n) from the position array PS index-1 [] selects a reasonable pair as the control flow structure insertion point. When all S index (1≤index≤n) The corresponding insertion positions are determined, and the program framework is built; Step 4): According to the grammatical rule constraints, randomly select a reasonable expression as a conditional judgment statement for each control flow structure, and randomly insert a number of expression statements, assignment statements, jump statements, etc. into the program framework to enrich the semantic information of the generated program; Step 5): In step 4), different conditional judgment statements, expression statements or assignment statements may use the same variable, so a declaration statement deduplication algorithm is introduced to select the lower bound of the declaration position in the current program for each variable, and randomly select a position information from the upper bound of the position information to the current lower bound to insert the declaration statement to ensure that the generated program can be compiled correctly; Step 6): Analyze the control flow structure, judgment statements and jump statements determined in step 5) to eliminate explicit dead loops; Step 7): Add empty statements to the control flow structure without any structured statements inside, build a complete structured program, and synthesize the test program source code corresponding to the program; Step 8): predict the execution status of the structure generated in step 7), mark the control flow structure and statements according to the explicit execution, explicit non-execution and unclear execution status, and generate invariants by combining the program structure information and the execution status marking results; Step 9): Call the compiler coverage tool to generate a coverage report corresponding to the test program source code in step 7), and use the invariant rule to test the correctness of the coverage report. If the report does not satisfy the invariant, it is considered that there may be an error in the coverage tool.
2. The method for code coverage tool testing based on automatic synthesis of structured programs according to claim 1, characterized in that: In step 1), the control flow structures that are repeatedly arranged using the enumeration algorithm are 5 common selection structures If / If-Else and loop structures For / While / Do-While. When the number of input control flows is n, the algorithm will generate 5 n A sequence of control flow structures, the first element of all sequences is Main.
3. The method for code coverage tool testing based on automatic synthesis of structured programs according to claim 1, characterized in that: In the step 2), the structure sequence has a Main function structure and n control flow structures, each structure corresponds to an insertable point position array PS[], and a structure sequence has a total of n+1 insertable point position arrays PS0 to PS n ; All elements in the array of insertable point positions are pairs of two-tuples, and the Pair shape is<index,position> , where index represents the index in the structure sequence, and position represents the index of the code block inside the structure.
4. The method for code coverage tool testing based on structured program automatic synthesis according to claim 1, characterized in that: In step 3), each control flow structure S index (1≤index≤n), from the position array PS index-1 When selecting a reasonable Pair as the control flow structure insertion point in [], a constraint relationship needs to be observed to ensure that the generated synthetic program framework is unique.
5. The method for code coverage tool testing based on automatic synthesis of structured programs according to claim 4, characterized in that: Describe the constraint relationship using a deduplication algorithm, where the deduplication algorithm stipulates two control flow structures S i and S j (i < j), and the selected Pair i = <index i , position i > and Pair j = <index j , position j > must satisfy the following conditions: (index i <index j )∨((index i =index j )∧(position i ≤position j ))。 6. The method for code coverage tool testing based on structured program automatic synthesis according to claim 1, characterized in that: The declaration position of the variable in step 5) is represented by a position tuple Pair. If the Pairs of two variables are the same, it means that the two variables are located in the same code block and the scopes of the two variables are also the same. The declaration statement deduplication algorithm solves the conflict between the two Pairs corresponding to the same variable, and uses the least common multiple idea to select the declaration position with a larger scope to ensure the correctness of program compilation.
7. The method for code coverage tool testing based on structured program automatic synthesis according to claim 1, characterized in that: In step 8), when predicting and marking the control flow structure and statement execution status in the program framework generated in step 7), three selectable labels are Executed, UN-Executed and Unknown. The invariant generated in step 8) is an equation that uses code line numbers to describe the expected coverage results.
8. The method for code coverage tool testing based on structured program automatic synthesis according to claim 1, characterized in that: The compiler coverage tool called in step 9) affects the way coverage is defined. Different compilers define coverage differently. Before using invariant verification, the coverage report is read for format conversion. The execution count is translated into a numerical format according to the meaning specified by the compiler, and the execution count -1 is used to represent unobserved points in the coverage report given by the compiler.
Citation Information
Patent Citations
Test program control stream path set creation method based on base path
CN101216803A
Unit test automatic execution method based on test case automatic generation algorithm
CN110543421A