A software fault location method based on comprehensive statement association graph
By constructing a comprehensive statement association graph and combining a GraphSage graph neural network, the problem that abstract syntax trees in the existing technology cannot describe control flow and data flow is solved, and more efficient software failure location is achieved.
Patent Information
- Application Number
- CN202411259388.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-09-10
AI Technical Summary
The existing software fault location method based on statement association graph cannot fully describe the control flow, data flow and call relationships due to its dependence on an abstract syntax tree, resulting in inefficient fault location in complex program structures and fault scenarios.
Build a comprehensive statement association diagram, and form a more comprehensive program relationship diagram by obtaining the relationship between control flow, data flow and function call, and combine it with the GraphSage graph neural network for fault location.
It significantly improves the accuracy and efficiency of fault location, can more effectively describe the control and data relationship between statements, and improves the efficiency of software testing and maintenance.
Smart Images

Figure CN118779249B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software fault location, and in particular to a software fault location method based on a comprehensive statement association graph. Background Art
[0002] With the continuous advancement of information technology, the scale and internal structure complexity of software systems are increasing, which greatly increases the complexity and cost of software maintenance. Traditional fault location technology mainly focuses on the source code level, using various static and dynamic analysis techniques, including compilation spectrum analysis, dynamic slicing, coverage analysis and other methods to identify possible fault sources. With the development of machine learning technology, especially the rise of graph neural networks, many researchers have begun to use methods based on statement association graphs to improve the efficiency of fault location.
[0003] The current software fault location methods based on statement association graphs mainly use abstract syntax trees to describe the relationship between statements and as an analysis method. The abstract syntax tree mainly displays the grammatical structure of the program. It is a hierarchical structure. By obtaining the statement association relationship in the abstract syntax tree and using test cases to connect different methods to form a complete program statement association graph, these program statement association graphs are analyzed and fault located using the graph neural network method. These methods have achieved certain results, but because the abstract syntax tree is suitable for parsing and syntax analysis, it cannot fully display the control flow, data flow and call relationship. Therefore, the above methods are limited to syntax analysis for the description of statement relationship information in the program, and lack in-depth analysis of dynamic behavior, program execution and data processing. This cannot achieve good fault location efficiency for some complex program structures and fault location scenarios. Summary of the invention
[0004] In order to solve the above problems in the prior art, the present invention proposes a software fault location method based on a comprehensive statement association graph, which uses statement association relationship information to improve the efficiency of fault location. The core of the present invention is to use the control flow, data flow and function call relationship in the program to construct a comprehensive statement association graph. In view of the problem that the existing fault location technology can only obtain shallow grammatical relationships when using an abstract syntax tree, the present invention achieves an accurate description of the dynamic behavior and data processing inside the program by obtaining control flow information, data flow information and function call relationships, optimizes the information description capability of the program relationship graph, and thus improves the accuracy and efficiency of fault location.
[0005] The complete technical solution of the present invention includes:
[0006] A software fault location method based on a comprehensive statement association graph, wherein the software includes multiple functions, each function is composed of multiple statements, the statements include common statements, conditional statements, loop control statements and function call statements, and there are declarations, assignments and uses of variables between the statements; the method is characterized by comprising the following steps:
[0007] Step 1: Establish a starting point for each function in the software, defined as a virtual starting node "start", indicating the entry of the function; establish a unique identifier for each statement in the software, defined as a statement node; define the control flow information and data flow information in the software program as edges;
[0008] Step 2: Create a directed graph , where: V is the set of nodes in the graph, E is the set of edges in the graph;
[0009] Step 3: Run different test cases and define the path covered by each test case as a sequence. Then map each sequence to the directed graph G established in step 2 to obtain a comprehensive statement association graph.
[0010] Step 4: Use the comprehensive statement association diagram obtained in step 3 to locate the software fault.
[0011] Furthermore, in step 1, all virtual start nodes and statement nodes represent various functions and statements in the software program.
[0012] Furthermore, step 2 specifically includes:
[0013] For each function Create a directed subgraph ,in is a function The set of all virtual start nodes and statement nodes in , is a function Internal edge set about control flow information and data flow information;
[0014] For any function call relationship, define a set C, which includes all cross-function call edges; that is, .
[0015] For all directed subgraphs Take the union to get V, for all directed subgraphs And the set C is taken as the union to get E. That is, for the directed graph G:
[0016]
[0017]
[0018] Furthermore, the control flow information includes conditional judgment, function call and sequential execution of statements, and the data flow information includes declaration, assignment and use of variables.
[0019] Furthermore, in the actual fault location calculation, the virtual start node is ignored to avoid irrelevant influence on the result.
[0020] Furthermore, the method for establishing the sequence is: statistically analyzing the coverage information of the test case for all statements and representing it as a vector composed of 0 and 1, wherein during the test of the test case, the executed statements are represented as 1, and the non-executed statements are represented as 0, and all the statement nodes represented as 1 constitute the sequence of the test case.
[0021] Furthermore, GraphSage graph neural network is used to locate software faults using the obtained comprehensive statement association graph.
[0022] The advantages of the present invention over the prior art are:
[0023] The present invention constructs a comprehensive statement association graph by analyzing the program code, obtaining the control flow, data flow and function call relationship in the program, and then using this information to assist in quickly and accurately locating faults in the software. Compared with other fault location methods that use statement association graphs based on abstract syntax trees, the comprehensive statement association graph of the present invention can more effectively describe information such as control relationships, data relationships and method calls between functions between statements, solve the problem of insufficient use of statement association information in current fault location methods, improve location efficiency, and thus significantly improve the efficiency and accuracy of fault location during software testing and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A schematic diagram for generating the comprehensive sentence association diagram described in the present invention.
[0025] Figure 2 This is a flow chart of the software fault location method using a comprehensive statement association graph described in the present invention.
[0026] Figure 3 The present invention is a flowchart of an embodiment of the method for locating software faults using a comprehensive statement association graph. DETAILED DESCRIPTION
[0027] The present invention is described in detail below in conjunction with the embodiments and drawings, but it should be understood that the embodiments and drawings are only used to exemplify the present invention and do not constitute any limitation on the protection scope of the present invention. All reasonable changes and combinations within the scope of the inventive concept of the present invention fall within the protection scope of the present invention.
[0028] A control flow graph is a directed graph used to represent the control flow of a program. In a control flow graph, a node represents a basic block (a straight-through code sequence without branches and jumps), and an edge represents a transfer in the control flow and data flow. A data flow graph is a graph used to represent the data processing process of a system, focusing on how data flows and transforms in the system. A method call graph is a directed graph used to represent the calling relationship of methods or functions in a program. In a method call graph, a node represents a method or function, and an edge represents the calling relationship between methods or functions.
[0029] like Figure 1 As shown in FIG. 1 , this method first introduces a virtual starting node "start" to indicate the initial point of entering each function. This node is used to simplify the representation of function calls in the graph, but in the actual fault location calculation, this node will be ignored to avoid irrelevant effects on the results.
[0030] Each function consists of a series of statements S, including normal statements, conditional statements, loop control statements, and function call statements. There are also declarations, assignments, and uses of variables between statements. Calls between functions are represented by specific call edges. Figure 1 Each node in the program represents an independent program statement or function entry, and each edge represents a transfer in the control flow and data flow, including the sequential execution of conditional judgments and function call statements; as well as the declaration, assignment, and use of variables.
[0031] In the representation of test coverage, the present invention uses edge sets to describe which test cases cover which program paths. Such a representation helps to intuitively capture how test cases interact with program code and how to infer potential error locations through test coverage paths.
[0032] In order to accurately describe the graph-based coverage representation, the present invention first defines the following main elements:
[0033] Function nodes and statement nodes: represent the functions and statements in the program, and each statement has a unique identifier.
[0034] The function node is a virtual starting node: a starting point is defined for each function, indicating the entry of the function.
[0035] Edge: represents the control flow and data flow information in the program. The control flow includes condition judgment, function call and sequential execution of statements. The data flow includes the declaration, assignment and use of variables.
[0036] Run different test cases, define the path covered by each test case as a sequence, and then obtain a comprehensive statement association graph based on the correspondence of each sequence to the directed graph G. Use the comprehensive statement association graph to locate software faults.
[0037] For example, test cases The covered path can be defined as a sequence, , the elements in its sequence For test cases Statement nodes and virtual nodes executed at runtime, and , Representation Statement and The relationship between the edges.
[0038] like Figure 1 As shown, in this example, the corresponding definition in function A is as follows:
[0039] .
[0040] The corresponding definition in function B is as follows:
[0041]
[0042] Function calls: .
[0043] For the entire graph, the corresponding definition is as follows:
[0044] .
[0045] For test cases, the corresponding definitions are as follows:
[0046]
[0047] .
[0048] Through the above representation, the statement association relationship and test coverage can be clearly described.
[0049] like Figure 2-Figure 3 As shown, the software fault location method using the comprehensive statement association graph in the present invention includes the following steps:
[0050] Step 1: Select 54 versions of the data set for test case screening for fault location tasks. The data sets are from two Java open source projects. The basic description information is shown in Table 1.
[0051] Table 1 Description of Java open source project related information
[0052]
[0053] Step 2: The control flow information, data flow information and function call relationship of the program can be obtained through static analysis tools. In this method, the understand static analysis tool is used to obtain the above information.
[0054] set up is a directed graph, where: V is the set of nodes in the graph, E It is the set of edges in the graph, representing the program control flow, data flow, and function call relationship.
[0055] For the program to be analyzed n functions, each function Corresponding to a subgraph ,in is the set of all statements and virtual start nodes in the function, It is the edge set of internal control flow and function call.
[0056] For the calling relationship of any function, the present invention defines a set C, which includes all the calling edges across functions, namely .
[0057] We get a directed graph G containing the program's control flow information, data flow information, and function call relationships:
[0058] , .
[0059] Step 3: The statement coverage information of the test cases can be obtained through automatic tools such as GZoltar, and a total of n test cases are obtained. The statement coverage information of the test cases is counted and represented in the form of a vector composed of 0 and 1, so as to obtain the vectorized coverage information of all test cases. The test case coverage information is represented as ,in Indicates the test case number, Indicates the number of the statement in the test case; =1 indicates the corresponding test case During execution, the statement ; =0 indicates a test case Statements are not executed during execution , the test case The statement nodes with a result of 1 are extracted and form test cases sequence.
[0060] Step 4: Combine the control flow information, data flow information and function call relationship of the program obtained in step 2 with the test case coverage information obtained in step 3.
[0061] As mentioned before, the paths covered by a test case t can be defined as a sequence, ,in and In this way, the coverage information of the vectorized test cases and statements obtained in step 3 is described as a sequence, and corresponding to the directed graph G obtained in step 2, the coverage of each test case on the statement nodes in the graph can be accurately described in the graph.
[0062] Through the above representation, the statement association relationship and test coverage can be clearly described to form a complete comprehensive statement association graph.
[0063] Step 5: The fault location method needs to be combined with a graph neural network to analyze the comprehensive statement association graph for fault location. This method selects the classic GraphSage graph neural network to analyze the comprehensive statement association graph to locate the faulty statement.
[0064] This embodiment selects the classic fault localization algorithm Ochiai and two fault localization algorithms based on graph learning for comparative experiments, including AGFL based on graph convolutional neural network and WEGAT based on weighted execution graph and graph attention network, to verify the performance of the method. In the comparison results, the experimental results of this method are marked as StasogFL.
[0065] The following indicators are used to evaluate the fault location efficiency:
[0066] Top-N: This metric counts the number of incorrect versions that have at least one incorrect element among the first N elements of the list.
[0067] Mean First Rank (MFR): For each faulty version, the first rank is the rank of the first faulty element in the list. For each item, MFR calculates the average of all first ranks in all faulty versions.
[0068] Mean Average Rank (MAR): For each faulty version, the mean rank is the average rank of all faulty elements in the list. For each item, MAR calculates the average of the mean ranks of all faulty versions.
[0069] Table 2 Average localization efficiency of CSV dataset
[0070]
[0071] Table 3 Average positioning efficiency of the Mockito dataset
[0072]
[0073] After using this method, the fault location efficiency of the three methods, Ochiai, AGFL, and WEGAT, has been significantly improved. In the Csv dataset, the MFR of this method is 4.41 and the MAR is 5.44, which are 38.1% and 35.3% higher than those of Ochiai, respectively; the Top-N indicators of this method are better than those of Ochiai, AGFL, and WEGAT. In the Mockito dataset, the MFR and MAR of this method are 67.73% and 58.23% higher than those of Ochiai, respectively; the Top-5 of this method is better than that of Ochiai, AGFL, and WEGAT, and the Top-1 and Top-3 indicators are slightly different from those of the other methods.
[0074] The embodiment of the present invention forms a comprehensive statement association graph by accurately extracting and describing statement association information in a program, effectively supporting high-precision fault location. It can be seen from the above examples that the fault location efficiency of the method is better, and it can provide better support for fault location and software testing and debugging.
[0075] The above applications are only some implementation methods of the present application. For those skilled in the art, several modifications and improvements can be made without departing from the creative concept of the present application, and these all belong to the protection scope of the present application.
Claims
1. A software fault location method based on a comprehensive statement association graph, wherein the software includes multiple functions, each function consists of multiple statements, the statements include common statements, conditional statements, loop control statements and function call statements, and there are declarations, assignments and uses of variables between statements; characterized in that: The steps include: Step 1: Establish a starting point for each function in the software, defined as a virtual starting node, indicating the entry of the function; establish a unique identifier for each statement in the software, defined as a statement node; define the control flow information and data flow information in the software program as edges; all virtual starting nodes and statement nodes represent various functions and statements in the software program; the control flow information includes conditional judgment and function call, as well as sequential execution of statements; the data flow information includes declaration, assignment and use of variables; Step 2: Create a directed graph , where: V is the node set in the directed graph, E is the edge set in the directed graph, specifically including: For each function Create a directed subgraph ,in is a function The set of all virtual start nodes and statement nodes in , is a function Internal edge set about control flow information and data flow information; For any function call relationship, define a set C, which includes all cross-function call edges; For all directed subgraphs Take the union to get V, for all directed subgraphs And the union of set C gives E ; Step 3: Run different test cases and define the path covered by each test case as a sequence, and then map each sequence to the directed graph established in step 2. G The comprehensive sentence association diagram is obtained above; the method for establishing the sequence is: Count the coverage information of all statements of the test case and represent it as a vector composed of 0 and 1, where the executed statements of the test case during the test are represented as 1, and the unexecuted statements are represented as 0, and all the statement nodes represented as 1 constitute the sequence of the test case; Step 4: Use the GraphSage graph neural network and the comprehensive statement association graph obtained in step 3 to locate the software fault. In the actual fault location calculation, ignore the virtual start node.
