A phased error localization method based on graph neural network
By introducing a two-stage positioning method of graph neural networks in software testing, combining control flow and data dependence information, the problem that the existing technology cannot distinguish program entities of the same spectrum is solved, and more efficient error positioning is achieved, and through Tarantula- The DNN-GNN hierarchical acceleration strategy improves computational efficiency.
Patent Information
- Application Number
- CN202210418068.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-20
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2042-04-20
AI Technical Summary
Existing spectrum-based mislocalization techniques cannot distinguish program entities with the same program spectrum, and traditional positioning strategies have insufficient precision and efficiency, resulting in inefficiency of developers during debugging.
A two-stage positioning method based on graph neural network is adopted, combining the control flow of the statement and data dependence information, and the positioning accuracy is improved through graph structure information, and a Tarantula-DNN-GNN hierarchical acceleration strategy is adopted to reduce computational overhead.
It improves the accuracy and efficiency of mislocalization, can more accurately distinguish statements with the same spectrum, and reduces the time overhead caused by graph neural network computing, and is more in line with the developers' usage habits in real scenarios.
Smart Images

Figure CN114741304B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to software error location. The present invention provides an error location method based on a graph neural network to improve the accuracy of error location. Background Art
[0002] In software development, debugging has always been a time-consuming, labor-intensive and tedious process. Studies have found that in some projects, debugging can account for 80% of the development time. In order to reduce the time overhead of the debugging process, researchers have proposed automatic error localization technology, which aims to reduce the time overhead of debugging by automatically identifying potential fault locations.
[0003] Currently, spectrum-based bug localization (SBFL) is the most widely used type of automatic bug localization technology. SBFL calculates the suspicion scores of program entities (such as statements, basic blocks, and functions) by analyzing the program spectrum, and then ranks them. The program spectrum records information related to the execution of program entities. For a program entity s, its program spectrum can be represented as a four-tuple (e f ,e p ,n f ,n p ). Among them, e f is the number of test cases that executed s and failed, e p is the number of test cases that have been executed successfully, n f is the number of test cases that failed without executing s, n p is the number of test cases that were executed successfully without executing s. The spectrum can be converted into a suspicion score by the error localization formula. Generally speaking, a program entity executed by more failed test cases is more suspicious than a program entity executed by more successful test cases. In recent years, many spectrum-based error localization methods based on different assumptions have been proposed, such as Ochiai and Jaccrad, who proposed a new error localization formula, and MULTRIC, which uses machine learning methods to integrate existing error localization techniques. However, because the SBFL technique relies on the program spectrum to calculate the suspicion, SBFL cannot distinguish program entities with the same program spectrum.
[0004] Program structure is crucial for analyzing and understanding programs. In recent years, in program structure, control flow reflects the execution order of program entities, and data flow records the definition and use of variables, reflecting the data dependencies between program entities. However, most spectrum-based error localization methods regard program entities as isolated individuals without considering the relationship between them. Therefore, we propose an error localization method based on graph neural network, which combines the suspicion score calculated by SBFL with the function graph structure and calculates it through graph neural network to distinguish statements with the same spectrum for precise location.
[0005] In terms of positioning, the present invention adopts a two-stage positioning strategy. At present, the two most commonly used positioning strategies are statement-level positioning and function-level positioning. Statement-level positioning is based on statement granularity, and a statement-level sorting list is given according to the suspicion score of the statement. Function positioning is based on function granularity, and a function-level sorting list is given according to the suspicion score of the function. It is generally believed that statement-level error positioning is too fine, because adjacent statements in the sorting list are often far apart in the program, such as in two different functions or even in two different files. This leads to a large span when developers check according to this list, and often need to repeatedly check different functions or documents, lacking coherence. Function positioning is relatively rough, and developers cannot obtain any hints in the function. Therefore, unlike the previous error positioning strategy, the present invention adopts a two-stage positioning strategy, first giving a function-level sorting list, and then when the developer checks a certain function, dynamically generating a statement-level sorting list of each statement in the function, so that more sufficient and effective information can be provided to the developer, which is conducive to improving the efficiency of error positioning.
[0006] At the same time, in order to reduce the extra time overhead caused by extracting the program graph structure and using graph neural networks for calculations, the present invention adopts the Tarantula-DNN-GNN hierarchical acceleration strategy. The present invention does not use GNN to calculate all functions, but first uses Tarantula technology to preliminarily sort the functions, and then uses DNN and more complex GNN models in turn to further sort the top-ranked functions, thereby reducing the time overhead caused by the use of graph neural networks. Summary of the invention
[0007] Technical problem: This paper proposes a phased error localization method based on graph neural network, which can improve the positioning accuracy of SBFL technology.
[0008] Technical solution: The present invention is a phased error location method based on graph neural network. By analyzing the control flow information and data dependency information of statements in program functions, the control flow graph and data dependency graph of program functions are extracted, and the graph neural network is used to learn the intrinsic relationship between statements in the function. By introducing graph structure information, the problem that traditional SBFL technology cannot distinguish program entities with the same spectrum is solved, thereby improving the location accuracy. The present invention divides the location process into two stages, and successively gives a sorted list of the function level and the statement level within the function, which is more in line with the developer's usage habits. In order to reduce time overhead, the present invention adopts a Tarantula-DNN-GNN hierarchical acceleration strategy to improve the location efficiency.
[0009] This method uses the function graph as the basic unit, combines the spectrum-based error localization technology SBFL with the graph neural network GNN, and divides the localization into two stages, namely function-level localization and statement-level localization within the function. In the localization process, a hierarchical acceleration strategy is used to efficiently and accurately locate errors. The specific steps of this method are as follows:
[0010] Step 1: Use a test case set containing at least one failure case to test a target program containing defects, and count the frequency spectrum information of the target program at the statement level and the function level respectively; and select functions that have covered at least one failure error case and put them into the first function set M1 to be sorted;
[0011] Step 2: For all functions in the first function set M1 to be sorted, the Tarantula formula is used to calculate the suspicion score of each function statement, and the maximum suspicion of the statements in the function is taken as the suspicion of the function. Then, the functions are sorted from high to low according to their suspicion. After that, the top 50 functions are selected and put into the second function set M2 to be sorted for further sorting.
[0012] Step 3, use multiple suspicion calculation formulas to calculate the suspicion scores of all statements in each function in the second function set M2 to be sorted, and combine them into a suspicion vector, use the trained fully connected neural network DNN to calculate the suspicion of each function in M2, and sort each function from high to low according to the suspicion score calculated by DNN, then select the top 10 functions and put them into the third function set M3 to be sorted for more accurate sorting;
[0013] Step 4, statically analyze all functions in the third to-be-sorted function set M3, extract the control flow graph and data dependency graph of each function, and synthesize the suspicion vectors of the statements in each function to obtain the feature graph of each function;
[0014] Step 5: Input the function feature graphs obtained in step 4 into the trained graph neural network-based sorting model for more accurate sorting. At this point, all functions have been sorted, and a sorted list of program functions is obtained. Check each function according to this list until the error function is found.
[0015] Step 6: When the sorted list obtained in step 5 is checked to any function m, the function feature graph of m is input into the trained node prediction graph neural network for two-stage error location, and a list of statements in m is obtained, sorted from high to low according to the degree of suspicion. The defective statements in the function are located as quickly as possible through the prompts of this list.
[0016] in,
[0017] In step 1, for any statement s in the target program, its spectrum information is defined as a four-tuple (e f ,e p ,n f ,n p ), where e f is the number of test cases that executed s and failed, e p is the number of test cases that have been executed successfully, n f is the number of test cases that failed without executing s, n p is the number of test cases that were not executed and were successfully executed.
[0018] In step 1, for any function m, its spectrum information is defined as a quaternion (e f ,e p ,n f ,n p ), where e f is the number of test cases that have executed m and failed, e p is the number of test cases that have been executed successfully, n f is the number of test cases that failed without executing m, n p is the number of test cases that were not executed and were successfully executed.
[0019] In step 1, filter out the functions that have covered at least one failure error case, and f Functions with error ≠ 0 are put into the first set of functions to be arranged M1, and functions not put into the first set of functions to be arranged M1 are considered to be irrelevant to the error.
[0020] In step 3, multiple suspicion calculation formulas are used to calculate the suspicion score of each statement and combine them into a suspicion vector. Specifically, for each statement s of each function m in the second set of functions to be sorted M2, multiple classic error location formulas are used to calculate its suspicion and splice them into a suspicion vector v.
[0021] In step 4, all functions in the third set of functions to be sorted M3 are statically analyzed to extract the control flow graph g of each function. cfg and the data dependency graph g ddg , and synthesize the suspicion vectors of the statements in each function to obtain the characteristic graph of each function; for each function m in the third set of functions to be sorted M3, its control flow graph is represented by an adjacency matrix C, whose size is a×a, where a is the number of rows of valid code in function m; the value C in the i-th row and j-th column of the matrix ij Indicates the flow of control flow; if C ij If 1 is set, it means that there is control flow from the i-th statement of this function to the j-th statement of this function. ij If it is 0, it means that there is no control flow from the ith statement of this function to the jth statement of this function; the data dependency graph is represented by the adjacency matrix D, whose size is also a×a. The value of the ith row and jth column of the matrix represents the data dependency of the program statement; if it is 1, it means that the ith statement depends on the data defined or modified by the jth statement, and if it is 0, it means that the ith statement does not depend on the data defined or modified by the jth statement; then, the control flow graph g is obtained by synthesis. cfg , data dependency graph g ddg , and the suspicion vector corresponding to each statement in m, to obtain the function feature graph of function m represents all nodes in g, each node represents a statement in function m, ε represents all edges in g, and edges represent the relationship between statements; Represents the type of edge in g. There are four types of edges: data flow inflow, data flow outflow, control flow inflow, and control flow outflow; represents the characteristic matrix of g, Represents the feature of the i-th node, whose value is the suspicion vector obtained in step 3.
[0022] The sorting described in step 5 uses quick sort as the overall sorting framework, and uses a trained graph neural network-based sorting model to compare the suspicion of any two functions; the model consists of a graph embedding layer and a fully connected layer. The graph embedding layer is used to extract the features of the function graph, and the fully connected layer is used to compare the suspicion of the extracted features. The input is two feature graphs g1 and g2, and the output result represents which of g1 and g2 is more likely to be the wrong location.
[0023] Step 6 performs two-stage error location to obtain a list of statements in function m sorted from high to low by suspicion, inputs the function feature graph into the trained node prediction graph neural network that is sensitive to edge weights, obtains the probability of each node being a defective node, and sorts them according to their probability to obtain a suspicion-ranked list of statements in the function.
[0024] Unlike the one-stage model, the two-stage model takes into account the weight of each edge in the graph. The edge weight is obtained by inputting the spectrum of the edge into a trained neural network, where the spectrum of the edge is similar to the spectrum of the sentence, reflecting the coverage information of the edge during the execution process.
[0025] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages: by using graph neural networks to capture the connections between statements in program functions, and combining the connections between statements in functions with the suspicion vectors of statements, the accuracy of error location is further improved; by utilizing the advantages of graph neural networks for both graph embedding and node embedding, the program function graph is used as the basic unit, and a graph neural network-based model is used to perform phased error location, first performing function-level location and then performing statement-level location within the function, which is more in line with the developer's habit of troubleshooting defects in real scenarios; by extracting the dependencies of program functions rather than the dependencies of the entire program, and adopting the Tarantula-DNN-GNN hierarchical acceleration strategy, the computing efficiency is effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 This is a flow chart of the phased error localization method based on graph neural network.
[0027] Figure 2 This is a schematic diagram of the Tarantula-DNN-GNN hierarchical acceleration strategy.
[0028] Figure 3 is a schematic diagram of the function characteristic diagram,
[0029] Figure 4 This is a schematic diagram of a one-stage model.
[0030] Figure 5 Schematic diagram of the two-stage model. DETAILED DESCRIPTION
[0031] The present invention is a phased error location method based on graph neural network. By analyzing the control flow information and data dependency information of statements in program functions, the control flow graph and data dependency graph of program functions are extracted, and the graph neural network is used to learn the intrinsic relationship between statements in the function. The problem that traditional SBFL technology cannot distinguish program entities with the same spectrum is solved by introducing graph structure information, thereby improving the location accuracy. The present invention divides the location process into two stages, and successively gives the sorted lists of function level and statement level in the function, which is more in line with the developer's usage habits. In order to reduce time overhead, the present invention adopts a Tarantula-DNN-GNN hierarchical acceleration strategy to improve the location efficiency. Figure 1 The specific process of this method is given. Figure 2The hierarchical acceleration strategy proposed by the present invention is demonstrated. The present invention generally includes the following steps:
[0032] Step 1: Use a test case set containing at least one failure case to test the target program containing defects, and count the frequency spectrum information of the target program at the statement level and function level; and select functions that have covered at least one failure error case and put them into the function set M1 to be sorted;
[0033] Step 2, use the classic SBFL formula Tarantula to calculate the suspicion score of each function in the function set M1 to be sorted, and sort each function from high to low according to the suspicion score calculated by Tarantula. Then, select the top 50 functions and put them into the function set M2 to be sorted for further sorting;
[0034] Step 3, use multiple suspicion calculation formulas to calculate the suspicion scores of each function statement in the function set M2, and combine them into a suspicion vector, use the trained fully connected neural network (DNN) to calculate the suspicion of each function in M2, and sort each function from high to low according to the suspicion score calculated by the DNN, then select the top 10 functions and put them into the function set to be sorted M3 for more accurate sorting;
[0035] Step 4, statically analyze all functions in the function set M3, extract the control flow graph and data dependency graph of each function, and synthesize the suspicion vector of the statements in each function to obtain the feature graph of each function;
[0036] Step 5: Input the function feature graphs obtained in step 4 into the trained graph neural network-based sorting model for more accurate sorting, and obtain a sorted list of program functions. At this point, all functions have been sorted, and they are checked one by one according to this list until the error function is found;
[0037] Step 6. When the suspicion list obtained in step 5 is checked to any function m, the function feature graph of m is input into the trained node prediction graph neural network that is sensitive to edge weights for two-stage error location, and a list of statements in m is obtained, sorted from high to low by suspicion. The defective statements in the function are located as quickly as possible through the prompts of this list.
[0038] The following sections further describe some specific details of the implementation process:
[0039] 1. Step 2 uses the classic SBFL formula Tarantula to calculate the suspicion score of any function m in the function set M1 to be sorted. The specific sub-steps include: using the Tarantula formula to calculate the suspicion score of each statement in function m. For statement s, given its spectrum (e f ,e p ,n f ,np ), the formula for calculating the suspicion of statement s using Tarantula is as follows:
[0040]
[0041] After obtaining the suspicion of each statement in function m, take the maximum suspicion as the suspicion score of function m.
[0042]
[0043] 2. In step 3, the suspicion calculation formula is used to calculate the suspicion vector of each statement. For each statement s of each function m in the function set, multiple classic error location formulas are used to calculate its suspicion and splice it into a suspicion vector v s .
[0044]
[0045] Among them, F is the SBFL error location formula set, including Ochiai, Tarantula, Dstar, Wong2, Nashi1, Nashi2, Jaccard and RussellRao.
[0046] 3. In step 4, for each function m in the function set M3, synthesize its control flow graph g cfg , data dependency graph g ddg , the suspicion vector corresponding to each statement in m, and obtain the characteristic graph of the function in, Represents all nodes in the graph g. In the present invention, each node in the graph corresponds to a statement in the original function. Represents the relationship type (edge type) in the graph. In the present invention, the relationship type is divided into control flow and data flow. ε represents all the edges in the graph. is the node feature. Figure 3 This is an example of a function feature graph.
[0047] 4. Step 5 uses the trained graph neural network-based ranking model to compare the suspicion of any two functions. Figure 4 The structure of this sorting model is shown. The model consists of two parts: a graph embedding layer and a fully connected layer. The graph embedding layer is used to extract the features of the function graph, and the fully connected layer is used to compare the suspicion of the extracted features. The input is two feature graphs g1 and g2, and the output result represents which of g1 and g2 is more likely to be the wrong location. The calculation formula of the graph embedding layer is as follows:
[0048]
[0049]
[0050]
[0051]
[0052] in, represents the hidden value of node u at the kth iteration; represents all neighboring nodes ending at node v; where W k is the weight of the k-th layer of the neural network, and there are K layers in total; σ represents the activation function, such as ReLU, Sigmoid; aggregate is the aggregation operation, which can be min, max or average; concat is the concatenation operation. After obtaining the embedded representation of each node in the graph g, the embedded representation of the graph is obtained through the readout operation. The readout is public as follows:
[0053]
[0054] Where D is the node feature dimension, that is, the number of suspicion formulas selected. After obtaining the graph embedding representation h of g1 and g2 g1 and h g2 Finally, a fully connected neural network (fc1) is used to compare the suspicion of g1 and g2:
[0055] p=fc1(h g1 ,h g2 )
[0056] 5. Step 6 performs the second stage of error location to obtain a suspicion list of statements within the function. Figure 5 The figure is a schematic diagram of the two-stage model. The function feature graph is input into the trained node prediction graph neural network to obtain the probability of each node being a defective node. Unlike the one-stage model, the two-stage model takes into account the weight of each edge in the function graph. The edge weight is obtained by inputting the edge spectrum into a trained neural network. The edge spectrum reflects the coverage information of the path during execution. Similar to the statement spectrum, for any edge e, its spectrum can also be expressed as a four-tuple (ef e ,ep e ,nf e ,np e ). Among them, ef e Represents the number of test cases that executed the path and failed, ep e Represents the number of test cases that executed this path and succeeded; nf e Represents the number of test cases that did not execute the path and failed to execute, np e represents the number of test cases that were executed successfully without executing the path. ijOnly when the statements represented by source node i and destination node j are covered by test case t, we consider e ij Covered by test case t. Afterwards, the edge spectrum is input into the trained fully connected neural network (fc2) to obtain the weight of the edge:
[0057] w ij =fc2(ef eij ,ep eij ,nf eij ,np eij )
[0058] After obtaining the weight of each edge, the embedding representation of each node is calculated. The node embedding calculation formula is as follows:
[0059]
[0060]
[0061]
[0062]
[0063] Finally, the fully connected neural network (fc3) is used to calculate the probability s of each node being an error node v , the formula is as follows:
[0064]
Claims
1. A phased error localization method based on graph neural network, characterized by This method uses the function graph as the basic unit, combines the spectrum-based error localization technology SBFL with the graph neural network GNN, and divides the localization into two stages, namely function-level localization and statement-level localization within the function. In the localization process, a hierarchical acceleration strategy is used to efficiently and accurately locate errors. The specific steps of this method are as follows: Step 1: Use a test case set containing at least one failure case to test a target program containing defects, and count the frequency spectrum information of the target program at the statement level and the function level respectively; and select functions that have covered at least one failure error case and put them into the first function set M1 to be sorted; Step 2: For all functions in the first function set M1 to be sorted, the Tarantula formula is used to calculate the suspicion score of each function statement, and the maximum suspicion of the statements in the function is taken as the suspicion of the function. Then, the functions are sorted from high to low according to their suspicion. After that, the top 50 functions are selected and put into the second function set M2 to be sorted for further sorting. Step 3, use multiple suspicion calculation formulas to calculate the suspicion scores of all statements in each function in the second function set M2 to be sorted, and combine them into a suspicion vector, use the trained fully connected neural network DNN to calculate the suspicion of each function in M2, and sort each function from high to low according to the suspicion score calculated by DNN, then select the top 10 functions and put them into the third function set M3 to be sorted for more accurate sorting; Step 4, statically analyze all functions in the third to-be-sorted function set M3, extract the control flow graph and data dependency graph of each function, and synthesize the suspicion vectors of the statements in each function to obtain the feature graph of each function; For each function m in the third set of functions to be sorted M3, its control flow graph is represented by an adjacency matrix C, whose size is a×a, where a is the number of rows of valid code in function m; the value C in the i-th row and j-th column of the matrix ij Indicates the flow of control flow; if C ij If 1 is set, it means that there is control flow from the i-th statement of this function to the j-th statement of this function. ij If it is 0, it means that there is no control flow from the ith statement of this function to the jth statement of this function; the data dependency graph is represented by the adjacency matrix D, whose size is also a×a. The value of the ith row and jth column of the matrix represents the data dependency of the program statement; if it is 1, it means that the ith statement depends on the data defined or modified by the jth statement, and if it is 0, it means that the ith statement does not depend on the data defined or modified by the jth statement; then, the control flow graph g is obtained by synthesis. cfg , data dependency graph g ddg , and the suspicion vector corresponding to each statement in m, to obtain the function feature graph of function m represents all nodes in g, each node represents a statement in function m, ε represents all edges in g, and edges represent the relationship between statements; Represents the type of edge in g. There are four types of edges: data flow inflow, data flow outflow, control flow inflow, and control flow outflow; represents the characteristic matrix of g, Represents the feature of the i-th node, whose value is the suspicion vector obtained in step 3; Step 5: Input the function feature graphs obtained in step 4 into the trained graph neural network-based sorting model for more accurate sorting. At this point, all functions have been sorted, and a sorted list of program functions is obtained. Check each function according to this list until the error function is found. Step 6: When the sorted list obtained in step 5 is checked to any function m, the function feature graph of m is input into the trained node prediction graph neural network for two-stage error location, and a list of statements in m is obtained, sorted from high to low according to the degree of suspicion. The defective statements in the function are located as quickly as possible through the prompts of this list.
2. According to claim 1, a phased error localization method based on graph neural network is characterized in that In step 1, for any statement s in the target program, its spectrum information is defined as a four-tuple (e f ,e p ,n f ,n p ), where e f is the number of test cases that executed s and failed, e p is the number of test cases that have been executed successfully, n f is the number of test cases that failed without executing s, n p is the number of test cases that were not executed and were successfully executed.
3. According to claim 1, a phased error localization method based on graph neural network is characterized in that In step 1, for any function m, its spectrum information is defined as a quaternion (e f ,e p ,n f ,n p ), where e f is the number of test cases that have executed m and failed, e p is the number of test cases that have been executed successfully, n f is the number of test cases that failed without executing m, n p is the number of test cases that were not executed and were successfully executed.
4. The phased error localization method based on graph neural network according to claim 1 is characterized in that In step 1, filter out the functions that have covered at least one failure error case, and f Functions with error ≠ 0 are put into the first set of functions to be arranged M1, and functions not put into the first set of functions to be arranged M1 are considered to be irrelevant to the error.
5. The phased error localization method based on graph neural network according to claim 1 is characterized in that In step 3, multiple suspicion calculation formulas are used to calculate the suspicion score of each statement and combine them into a suspicion vector. Specifically, for each statement s of each function m in the second set of functions to be sorted M2, multiple classic error location formulas are used to calculate its suspicion and splice them into a suspicion vector v.
6. The phased error localization method based on graph neural network according to claim 1 is characterized in that The sorting described in step 5 uses quick sort as the overall sorting framework, and uses a trained graph neural network-based sorting model to compare the suspicion of any two functions; the model consists of a graph embedding layer and a fully connected layer. The graph embedding layer is used to extract the features of the function graph, and the fully connected layer is used to compare the suspicion of the extracted features. The input is two feature graphs g1 and g2, and the output result represents which of g1 and g2 is more likely to be the wrong location.
7. The phased error localization method based on graph neural network according to claim 1 is characterized in that Step 6 performs two-stage error location to obtain a list of statements in function m sorted from high to low by suspicion, inputs the function feature graph into the trained node prediction graph neural network that is sensitive to edge weights, obtains the probability of each node being a defective node, and sorts them according to their probability to obtain a suspicion-ranked list of statements in the function.
Citation Information
Patent Citations
Software defect positioning method based on frequency spectrum and neural network algorithm
CN110515826A
Defect positioning method based on context awareness
CN112965894A