A software bug localization method for multi-coverage use case generation and multi-method fusion

Using the instrumentation method and the symbolic execution tool KLEE to generate test cases with multiple coverages, combined with the results of multiple automatic bug location methods, and using the ranking learning algorithm to integrate the suspicion scores, it solves the time-consuming and tedious problem of writing test cases in software engineering. This solves the problem of poor bug locating method and achieves more efficient bug locating effect.

CN118012767BActive Publication Date: 2024-09-10ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410215761.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-27
Publication Date
2024-09-10
Estimated Expiration
2044-02-27

AI Technical Summary

Technical Problem

In software engineering, writing test cases is time-consuming and labor-intensive, and existing automatic software error location methods have limitations and cannot effectively meet multiple coverage standards and improve bug location effects.

Method used

The instrumentation method and the symbolic execution tool KLEE are used to generate test cases that meet various coverage rates, and static analysis and dynamic analysis are combined to integrate the results of multiple automatic bug location methods. The ranking learning algorithm is used to integrate the suspicion scores to improve the accuracy of bug location. accuracy.

Benefits of technology

The generated test case set can improve the probability of bug detection and location effect, improve the accuracy of automatic bug location, and surpass the effect of a single method.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118012767B
    Figure CN118012767B
Patent Text Reader

Abstract

The present invention discloses a software bug location method for multi-coverage use case generation and multi-method fusion. For unit testing, the present invention uses a stub method and a symbolic execution tool KLEE, first extracts the judgment expression and conditional expression of the code, generates a driving function using code stubs and assertions, and then inputs the converted code into a symbolic execution engine, generates and selects test cases that meet multiple coverages, and forms a test case set that meets multiple coverages; then, the test cases in the test case set are used as input, the function to be tested is executed, and the bug location results of multiple automatic bug location methods are collected by combining static analysis and dynamic analysis, including program slicing method, program spectrum method, and coverage element switching method, and then the suspicion scores of various methods collected are integrated using the ranking learning algorithm LambdaMART to obtain more accurate automatic bug location results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer information processing software engineering test automation, and in particular to a software bug location method oriented to multi-coverage case generation and multi-method fusion. Background Art

[0002] In the process of software engineering, writing test cases and locating software bugs are two very time-consuming and laborious tasks. In addition, the coverage of the written test cases greatly affects the effectiveness of software bug locating. However, in the software development process, there are two problems: (1) Due to the development deadline, testers and developers may not be able to write a sufficiently dense set of test cases that meet multiple coverage standards for software error detection and location; if they want to write test cases with high coverage standards, it will be very time-consuming and laborious. (2) Existing automatic software error location methods such as program spectrum method, program slicing method, program history method, coverage element switching method, etc. can only use a certain type of program information and have limitations. Summary of the invention

[0003] In view of the above two problems, the present invention proposes a software bug localization method for multi-coverage use case generation and multi-method fusion.

[0004] For unit testing, the present invention uses the instrumentation method and the symbolic execution tool KLEE to first extract the judgment expression and conditional expression of the code, use code instrumentation and assertions to generate a driving function, and then input the converted code into the symbolic execution engine to generate and select test cases that meet multiple coverage rates to form a test case set that meets multiple coverage rates; then, the test cases in the test case set are used as input to execute the function to be tested, and static analysis and dynamic analysis are combined to collect bug location results of various automatic bug location methods, including program slicing method, program spectrum method, and coverage element switching method, and then the ranking learning algorithm LambdaMART is used to integrate the suspicion scores collected from various methods to obtain more accurate automatic bug location results.

[0005] Beneficial effects of the present invention:

[0006] For the automatic test case generation part, the present invention uses the symbolic execution tool KLEE to generate test cases, but since the original KLEE can only generate test cases for statement coverage and path coverage, it does not support enough coverage types. Therefore, the present invention proposes to use a plugging method to guide the symbolic execution tool to generate test cases that meet multiple coverages such as decision coverage, condition coverage, condition / decision coverage, and modified condition / decision coverage, so as to improve the probability of detecting bugs in the test case set, and thus improve the effect of subsequent automatic bug location.

[0007] As for the bug location part, existing studies have shown that the automatic bug location technology that uses ranking learning to fuse multiple methods is better than any of the sub-methods involved in the fusion in terms of bug location effect. Therefore, the present invention proposes that after executing the automatically generated test cases and collecting program information, the bug location rankings of the program spectrum method, program slicing method, and covering element switching method are calculated, and ranking learning is used to fuse the information of various methods to improve the effect of automatic bug location. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] Figure 1 It is the overall flow chart of the present invention;

[0009] Figure 2 It is a flow chart of source code analysis;

[0010] Figure 3 This is an example diagram of generating instrumentation code and assertion code;

[0011] Figure 4 is an example graph of the generated driving function;

[0012] Figure 5 This is an example diagram of the results of the program slicing method;

[0013] Figure 6 This is an example diagram of the results of the program spectrum method;

[0014] Figure 7 This is an example diagram of the results of the covering element switching method;

[0015] Figure 8 2 is an example diagram of the ranking learning result of the embodiment. DETAILED DESCRIPTION

[0016] The present invention is further described in detail below in conjunction with the accompanying drawings and implementation methods.

[0017] Consider the two problems mentioned above: (1) developers manually write test cases that cannot meet sufficient coverage standards, which leads to insufficient bug localization results, and (2) a single automatic bug localization method is not effective enough.

[0018] The present invention provides a software bug location method for generating multiple coverage use cases and integrating multiple methods. The overall flow chart is shown in the attached figure. Figure 1 shown.

[0019] Step 1: Preprocess, insert, generate driver functions, etc. on the functions in the source code file, so that the subsequent symbolic execution tool KLEE can generate test cases that meet the conditional combination coverage for the processed functions.

[0020] Step 2: Submit the code processed in step 1 to the symbolic execution tool KLEE to generate test cases that meet the conditional combination coverage for the function under test, and select test cases that meet four coverage rates, including decision coverage, condition coverage, condition / decision coverage, and modified condition / decision coverage, as the final test case set.

[0021] Step 3: Perform static and dynamic analysis on the program under test to collect the information required for each bug location technology.

[0022] Step 4: Based on the information of static analysis and dynamic analysis obtained in step 3, run the automatic bug localization method to obtain the results of multiple bug localization methods.

[0023] Step 5: Ranking learning combines the results of all automatic bug localization methods to achieve better bug localization results.

[0024] Furthermore, step 1: preprocess, insert, generate driver functions and other operations on the functions in the source code file, so that the subsequent symbolic execution tool KLEE can generate test cases that meet the conditional combination coverage for the processed functions.

[0025] Step 1-1: Code analysis. Based on the LibTooling library of the clang compiler, design a code conversion tool to extract the judgment expression, parse the conditional expression, build the expression tree, calculate the path set, and prepare for the subsequent replacement of the entire judgment expression to generate the stub code and assertion code. The specific steps of preprocessing are as follows. Figure 2 shown.

[0026] Step 1-2: Generate instrumentation code and assertion code so that KLEE can generate test cases that meet the conditional combination coverage. After obtaining the judgment expression, conditional expression, constructing the expression tree, and calculating the path set in step 1-1, replace the original judgment expression with some clauses connected by comma operators, including some assertion functions; the replaced instrumentation code will not change the original meaning of the judgment expression, but after entering KLEE, it can generate test cases that meet the conditional combination coverage. The final replacement effect is shown in the attached figure. Figure 3 As shown. Figure 3 Some details are as follows:

[0027] (1) Attachment Figure 3 The example as a whole inserts the code if(a>0&&b>0&&c>0){res++;}.

[0028] (2) _kappa_ stores the evaluation result of the conditional expression, with the result of one condition occupying one bit.

[0029] (3) The two macro definitions _expect_0 and _expect_1 define the expected value of _kappa_. If the current expression value is T, the value of the corresponding bit is 1; if the current expression value is F / X, the value of the corresponding bit is 0.

[0030] (4) _expect_0 indicates a short-circuit condition. If one of the three conditions is F, the result is F: FXX|F, XFX|F, XXF|F. The value of the short-circuit bit is also recorded as 0. At this time, the value of each bit of _kappa_ is 000, so the value of _expect_0 is 0.

[0031] (5) _expect_1 means that the result is T only when all three conditions are T: TTT|T. In this case, the value of _kappa_ is 111, so the expected value is 7.

[0032] (6) When inserting a replacement (a>0&&b>0&&c>0), the global variable _Cond_Value_ stores the value of the judgment expression so that the insertion does not change the original meaning.

[0033] Step 1-3: Generate driver function code. Before using KLEE to generate test cases for the tested function, it is generally necessary to manually write a driver program to define the function parameters, symbolize the function input variables, and call the tested function, which will cause labor waste. Therefore, the present invention uses a method for automatically generating a driver function to complete this step, thereby improving the automation rate of the entire workflow. The effect of the final generated driver function is shown in the attached figure. Figure 4 As shown, Figure 4 The details are as follows:

[0034] (1) In the sample code, a global variable b and two function parameters a and c are defined. When generating the driver function, these variables need to be processed differently.

[0035] (2) For the function parameter a, first define it as a variable, and then call klee_make_symbolic to symbolize it.

[0036] (3) For the global variable b, it has been defined in the code, so there is no need to redefine it. Just use klee_make_symbolic to symbolize it.

[0037] (4) Variable c is a pointer. Its definition is different from that of variable a. Here, the pointer variable is not directly symbolized. Instead, the variable pointed to by the pointer is defined and symbolized first, and then the pointer is allowed to point to the variable. Figure 4In the example, you need to first define the variable __c__ that the pointer points to, symbolize __c__, and then let c point to __c__. For multiple levels of pointers, repeat this process until it points to a non-pointer variable.

[0038] Step 2: Submit the code processed in step 1 to the symbolic execution tool KLEE to generate test cases that meet conditional combination coverage for the function under test, and select test cases that meet four types of coverage, including decision coverage, condition coverage, condition / decision coverage, and modified condition / decision coverage, as the final test case set.

[0039] Step 2-1: Execute the function under test and generate test cases. By executing the automatically generated driver function, KLEE can generate test cases that meet the conditional combination coverage for the function under test. According to the coverage definition standard, when the test case set meets the conditional combination coverage, it also meets the judgment coverage, condition coverage, condition / judgment coverage, and modified condition / judgment coverage. However, compared with the test case sets of the other four coverage standards, the test case set that meets the conditional combination coverage will have some redundant test cases. Therefore, the test case selection algorithm in the subsequent step 2-2 can be used to select test cases that meet the four coverage rates of judgment coverage, condition coverage, condition / judgment coverage, and modified condition / judgment coverage. (The definitions of various test coverage rates are shown in Table 1)

[0040] Table 1 Definitions of five coverage ratios

[0041]

[0042]

[0043] Step 2-2: Test case selection. The present invention adopts two types of algorithms in terms of test case selection: (1) depth-first search or breadth-first search algorithm, (2) greedy algorithm. The depth-first search or breadth-first search algorithm will conduct an exhaustive search of the test case set to ensure that the searched test case set is the most streamlined while meeting the corresponding coverage standard, but the time consumed is exponentially related to the number of test cases, which is relatively time-consuming. The greedy algorithm will delete a test case from the current test case set each time until the deletion of any test case will cause the coverage of the current test case set to decrease. It takes less time, but the test case set is not streamlined enough. Considering the advantages and disadvantages of the two algorithms, the present invention adopts a strategy of combining the two algorithms. When the number of test cases in the test case set is large, the greedy algorithm is adopted; when the number of test cases in the test case set is small, the depth-first search or breadth-first search algorithm is adopted.

[0044] Step 3: Perform static and dynamic analysis on the program under test to collect the information required for each bug location technology.

[0045] Step 3-1: Static analysis: Analyze the AST structure of the source code to obtain the program dependency graph (PDG) corresponding to the source code.

[0046] Step 3-2: Dynamic analysis. Take the test case set generated in step 2 as input, execute the tested function, and count the coverage information (including statement coverage, decision coverage) of each test case corresponding to different program elements, as well as the results of correctness or incorrectness of execution; finally, two coverage matrices and result vector R are obtained, where the two coverage matrices represent the coverage matrices of the two types of coverage elements respectively, and the statement coverage matrix is ​​recorded as M s , the matrix of decision coverage is recorded as M D .

[0047] Step 4: Based on the information of static analysis and dynamic analysis obtained in step 3, run the automatic bug localization method to obtain the results of multiple bug localization methods.

[0048] Step 4-1: Program slicing method. The slicing method adopted by the present invention is the dynamic execution slicing method. Here, the program dependency graph obtained in step 3-1 is taken, and all the test cases that failed to execute in step 3-2 are taken at the same time. The statements passed by all failed test cases are put into the same set, and the program statements related to the abnormal variable are taken as a slice. All slices are constructed in sequence, and then the intersection of all dynamic slices related to a certain abnormal variable is taken. This is the set of program statements where the bug may exist, and the suspicion scores of all program statements are obtained. Examples are shown in the attached Figure 5 .

[0049] Step 4-2: Program spectrum method. The statement coverage matrix M obtained from step 3-2 s With the result vector R, the statistical statement covers 4 key data in the matrix: N CS 、N CF 、N US 、N UF , where N CS Indicates the number of successful test cases covering this statement, N CF Indicates the number of failed test cases covering this statement, N US Indicates the number of successful test cases that do not cover this statement, N UF Indicates the number of failed test cases that do not cover this statement. The DStar formula is used to calculate the suspicion, and the suspicion is ranked to obtain a suspicion ranking list. The higher the real bug is located in the ranking list, the better the effect is. For example, see the attached Figure 6 . The DStar formula is:

[0050]

[0051] Among them, N CFThe * in the upper right corner represents the exponential coefficient, which is 2 here.

[0052] Step 4-3: Covering element switching method. The basic idea of ​​the covering element switching method is similar to the program spectrum method in step 4-2, and the statistical covering matrix M is still used. D In the form of the result vector R, the DStar formula in step 4-2 is used to calculate the suspicion. However, when counting the coverage matrix, the basic element of coverage is not the statement, but other coverage elements, such as program branches or DU-pairs. Here, program branches are used as the coverage elements for calculating suspicion. After calculating the corresponding suspicion for each program branch, the scores are assigned to the relevant statements using the following three rules:

[0053] (1) For a decision statement, take the larger value of TRUE and FALSE in the corresponding branch as the score;

[0054] (2) For statements that appear before the current judgment statement in the basic block where the current judgment statement is located, if the intermediate variables involved in these statements affect the value of the judgment condition, the larger value of TRUE and FALSE in the corresponding branch is assigned to these statements as a score;

[0055] (3) After the above two steps (1) and (2), if there are still some statements that have not been assigned points, find all the control dependency branch conditions corresponding to these statements and assign the maximum suspicion degree to the remaining statements. Figure 7 .

[0056] Step 5: Ranking learning combines the results of all automatic bug localization methods to achieve better bug localization results.

[0057] Step 5-1: Collect the suspicion of bug location and construct the feature vector. Each method in steps 4-1 to 4-3 can collect the suspicion score of the statement. After normalizing them, the three suspicion scores constitute a feature vector of a program statement. Then, this feature vector is labeled with 0 / 1, where 0 means that the statement does not contain a bug and 1 means that it contains a bug.

[0058] Step 5-2: Use the ranking learning algorithm LambdaMART to learn the feature vector and expected value in step 5-1. After training, the model can integrate the information of the three methods and give a final suspicion score to locate the bug at the statement level more accurately.

[0059] Example:

[0060] S1. The following function is used to determine the right triangle:

[0061]

[0062] After the attached Figure 3 , Attachment Figure 4 After inserting the stub and generating the driver function, you can run KLEE to get the test cases that meet the conditional combination coverage. After selecting, you can get the test case set that meets the conditional coverage, decision coverage, conditional decision coverage, and modified conditional decision coverage:

[0063] Use Case 1 Use Case 2 Use Case 3 Use Case 4 Use Case 5 Use Case 6 Use Case 7 4,4,0 3,4,5 0,0,0 4,5,3 4,0,0 2,2,2 5,4,3

[0064] For the four target coverages of the instrumentation method of the present invention, the generated test cases have the following results for a given function, satisfying the target coverages:

[0065]

[0066]

[0067] In this embodiment, when manually writing test cases, it is easy for people to assume that a is a right-angled edge, and then miss the situation where b or c is a right-angled edge, resulting in reduced coverage and poor bug location results. However, after using the plugging method proposed in the present invention to generate test cases that meet multiple coverages, this situation can be avoided.

[0068] S2. After static and dynamic analysis of the use cases generated by the target function execution, the results of the three automatic bug location methods are obtained as shown in the attached figure. Figure 5 , Attachment Figure 6 , Attachment Figure 7 As shown, Figure 5 The results of the program slicing method are shown in the following figure. Figure 6 The results of the program spectrum method are shown in the following table. Figure 7 This is the result of the overlay element switching method.

[0069] It is particularly important to note that Figure 6 The calculation results of the suspicion degree for row 6 are shown in the attached Figure 7 The calculation results of the suspicion degree of the 5True branch are all infinite. This is because the formula used this time is The * parameter used is 2, for the attached Figure 6 The calculation results of the suspicion degree for row 4 are shown in the attached Figure 7 For the calculation results of the suspicion of the 3True branch, the N CF are both 2, that is, the number of test cases that cover this line and fail is 2, and N UF and N CS The number of test cases is 0, which means that the number of test cases that do not cover this line and fail is 0, and the number of test cases that cover this line and succeed is 0; then, the calculation formula and the result should be Hence the result is infinite.

[0070] S3. After vectorizing and sorting the results of program slicing, program spectrum, and covering element switching, we get the results of sorting learning. The example results of sorting learning are shown in the attached figure. Figure 8 .

[0071] In this embodiment, the result of sorting learning is better than the program slicing method and the covering element switching method, but because the program spectrum method has already located the line where the bug is located in the first place, the result of sorting learning also locates the line where the bug is located in the first place, and it cannot be shown here to be better than the program spectrum method. However, from the overall statistical results, sorting learning will combine the advantages of different methods. When facing different bugs, the overall probability of locating the bug is higher than that of all single methods.

Claims

1. A software bug location method for multi-coverage use case generation and multi-method fusion, characterized by The method comprises the following steps: Step 1: Preprocess, insert, and generate driver functions for the functions in the source code file; Step 2: Submit the code processed in step 1 to the symbolic execution tool to generate test cases that meet the conditional combination coverage for the tested function, and select the test cases that meet the coverage requirements as the final test case set; Step 3: Perform static and dynamic analysis on the program under test to collect the information required for each bug location technology; Step 4: Based on the information of static analysis and dynamic analysis obtained in step 3, run the automatic bug localization method to obtain the results of multiple bug localization methods; Step 5: Ranking learning combines the results of all automatic bug localization methods to obtain better bug localization results; The preprocessing in step 1 obtains a determination expression, a conditional expression, an expression tree and a path set; the determination expression is replaced with clauses connected by a comma operator, including an assertion function; the replaced stub code does not change the original meaning of the determination expression, so that after inputting the symbolic execution tool, a test case that satisfies the conditional combination coverage can be generated; The coverage requirement met in step 2 refers to meeting the four coverage requirements of determination coverage, condition coverage, condition / determination coverage, and modified condition / determination coverage; Step 5 is as follows: Step 5-1: Collect the suspicion of bug location and construct the feature vector; Each bug location method can collect the suspicion scores of the statements. After normalization, multiple suspicion scores form a feature vector of a program statement. Then the feature vector is labeled with 0 / 1, where 0 means that the statement does not contain a bug and 1 means that it contains a bug. Step 5-2: Use the ranking learning algorithm LambdaMART to learn the feature vector and expected value in step 5-1; after training, the ranking learning algorithm LambdaMART gives a final suspicion score, so as to more accurately locate the bug at the statement level.

2. According to claim 1, a software bug location method for multi-coverage use case generation and multi-method fusion, characterized in that: The automatic running bug location method includes a program slicing method, a program spectrum method and a covering element switching method.

3. The software bug location method for generating multiple coverage use cases and integrating multiple methods according to claim 2, characterized in that: The covering element switching method uses program branches as covering elements for calculating suspicion when counting the covering matrix.

4. The software bug location method for multi-coverage use case generation and multi-method fusion according to claim 3, characterized in that: After calculating the corresponding suspicion for each program branch, the score is assigned to the relevant statement using the following three rules: (1) For a judgment statement, take the larger value of TRUE and FALSE in the corresponding branch as the score; (2) For statements that appear before the current judgment statement in the basic block where the current judgment statement is located, if the intermediate variables involved in these statements affect the value of the judgment condition, the larger value of TRUE and FALSE in the corresponding branch is assigned to these statements as a score; (3) After the above two steps (1) and (2), if there are still some statements that have not been assigned points, find all the control dependency branch conditions corresponding to these statements and assign the maximum suspicion score to the remaining statements.