Software multi-defect positioning method and device based on variable dependency relationship and clustering
By constructing a variable dependency network model and graph editing distance metric similarity, and combining it with the K-medoids algorithm for clustering, the problem of inaccurate defect clustering in existing technologies is solved, achieving efficient and accurate multi-defect localization and automated debugging.
Patent Information
- Application Number
- CN202511673472.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-14
- Publication Date
- 2026-02-27
AI Technical Summary
Existing technologies fail to effectively utilize the deep semantic information of programs in multi-defect localization of software, resulting in poor defect clustering performance in multi-defect scenarios, making it difficult to accurately distinguish different defects and reducing localization efficiency.
By constructing a variable dependency network model, data dependency, control dependency, and functional dependency are extracted. Graph editing distance is used to measure similarity, and K-medoids algorithm is used for clustering to generate independent defect focus rankings.
It significantly improves the accuracy of defect clustering and the efficiency of multi-defect localization, can accurately distinguish defects from different root causes, reduces the burden of manual review, and improves software debugging efficiency.
Smart Images

Figure CN121579343A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of software defect positioning, and particularly relates to a software defect positioning method and device based on variable dependency and clustering. BACKGROUND
[0002] In the software development process, defects are inevitable. The time cost of manually positioning defects is high. Software defect positioning technology is an algorithm that helps testers find defects by analyzing the logic, results and execution status of test cases of software, and is one of the popular research topics in the field of software development at home and abroad in recent years. In real systems, software usually contains multiple defects, and the same failed test case may be related to different defects. Existing research shows that applying traditional methods to mixed failure test cases related to different failure causes will reduce their effectiveness.
[0003] In the field of software multi-defect research, the parallel debugging method is often used, and all faults are divided into several mutually exclusive groups according to the root cause of triggering software failure. The division process aims to achieve two goals: one is to make the number of generated groups equal to the number of faults; the second is that the failed test cases in the same group are triggered by the same fault. The clustering effect of failed test cases affects the effect of defect positioning. The clustering effect of failed test cases is largely dependent on how to represent defects, generate proxy objects for failed test cases, and measure the similarity between fault proxies. Existing research mainly based on code coverage or statistical debugging fault proximity gives an evaluation of failed test cases by extracting execution coverage information or suspiciousness ranking list. In most studies, distance calculation methods such as Euclidean distance or Kendall tau distance are used to measure the similarity of different test cases. These methods perform poorly in scenarios where failed test cases cover the same code path but have different defect triggering reasons. This "same coverage profile" phenomenon is proven to be widespread in practice. The reason is that coverage information cannot effectively represent the relationship between different parts of the program.
[0004] In addition to coverage information, source code as a structured text also contains rich syntax and semantic information and information about the interaction between variables. Existing defect representation methods based on coverage fail to fully utilize these deep program semantic information, which limits the ability to accurately group failed test cases in a multi-defect scenario. SUMMARY
[0005] In view of the deficiencies of the prior art, the application provides a software multi-defect positioning method and device based on variable dependency and clustering, which extracts the variable dependency relationship in the failed test case to provide more accurate defect classification basis for parallel debugging, effectively distinguishes different defects under the same code coverage, and improves the accuracy of defect clustering.
[0006] A software multi-defect localization method based on variable dependency and clustering, comprising the following steps:
[0007] Step 1, program execution and data collection
[0008] Execute the program to be debugged and the test case set, and collect the statement coverage information of the failed test cases according to the test results.
[0009] Step 2, constructing a variable dependency network model
[0010] Step 2.1, extraction of dependency relationship between variables
[0011] Based on the program part covered by the failed test cases obtained in step 1, the dependency relationship between variables is extracted by analyzing the program source code, including data dependency, control dependency and function dependency.
[0012] Step 2.2, construction of variable dependency network model
[0013] The linear dependency relationship between variables is converted into a directed graph model, which uses nodes to represent variables and edges to represent the dependency relationship between variables, as the variable dependency network of the failed test cases.
[0014] Step 3, measure the similarity
[0015] The graph edit distance is used to capture the topological structure changes in the variable dependency network of different failed test cases, including the increase and decrease of nodes and the change of edge connection mode, and the edit operation cost is mapped to the interval [0, 1] through normalization processing, as the distance between failed test cases, realizing the standardized similarity measurement across programs and defects.
[0016] Step 4, clustering and generating defect focus ranking
[0017] According to the distance between each failed test case, clustering is carried out, first clustering number estimation and initial center allocation. By calculating the latent value of each variable dependency network model, the number of clusters is dynamically determined, and the model with the highest latent value is selected as the initial clustering center.
[0018] Finally, for each cluster, an independent defect focus suspiciousness ranking is generated, realizing the parallel localization of multiple defects.
[0019] A software multi-defect localization device based on variable dependency and clustering, comprising:
[0020] A variable dependency relationship extraction module is used to extract the dependency relationship between different variables for each failed test case.
[0021] The variable dependency network model uses nodes in a directed graph to represent variables and edges to represent dependencies between variables, and uses the directed graph as a defect feature of a failed test case.
[0022] The distance metric module uses graph edit distance as the distance between different defect features of failed test cases.
[0023] The clustering analysis module clusters based on the distance between failed test cases output by the distance metric module, and generates an independent defect focus suspiciousness ranking for each cluster.
[0024] The present application has the following beneficial effects:
[0025] 1. The variable dependency network model is constructed by static analysis technology, and multiple semantic relationships such as data dependency, control dependency and function dependency between program variables are extracted to form a structured network representation with rich semantic information, thereby realizing detailed description of defect propagation path and impact range, solving the limitations of traditional code coverage information in semantic expression, not only representing program behavior more comprehensively from the semantic level, supporting cross-function and cross-module dependency capture, but also providing a more discriminative feature basis for defect positioning, test case priority sorting and other tasks, which helps to improve multi-defect differentiation ability and automated debugging efficiency.
[0026] 2. The graph edit distance is used as a similarity measurement method, and the addition, deletion and modification operation costs of nodes and edges are quantified to effectively identify the differences in the topological structure between different variable dependency networks, accurately capture the semantic structure changes composed of variable dependency relationships, and accurately distinguish different defect types according to the differences in the underlying dependency networks even if multiple failed test cases cover the same code path during execution. The discrimination ability and clustering accuracy in the defect clustering process are significantly improved, which provides reliable and detailed division basis for subsequent parallel debugging and multi-defect positioning, reduces the burden of manual review, and improves software debugging efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0027] Figure 1 Flowchart of a software multi-defect positioning method based on variable dependency relationships and clustering
[0028] Figure 2 Schematic diagram of a software multi-defect positioning device based on variable dependency relationships and clustering DETAILED DESCRIPTION
[0029] The present application will be further explained and described below in conjunction with the accompanying drawings;
[0030] As Figure 1As shown, a software multi-defect positioning method based on variable dependency and clustering optimizes the distance measurement method to improve the clustering effect of failed test cases, and then improves the accuracy of multi-defect positioning, which includes the following steps:
[0031] Step 1, program execution and data collection
[0032] This embodiment uses Chart, Closure, Lang, Math and Time five projects from the dataset Defects4J as the original software defect dataset, generates a version containing multiple defects by injecting defects. Execute the test suite, and collect the statement-level coverage information of the test cases during execution as the original data for quantifying the distance between test cases. According to the test results, all test cases are divided into successful test cases and failed test cases.
[0033] Step 2, build variable dependency network model
[0034] The identified failed test cases and their coverage information are extracted according to the established rules, and the variable dependency network model is constructed:
[0035] Step 2.1, extraction of inter-variable dependency
[0036] Use the Tree-sitter tool to build the abstract syntax tree of the Java program, traverse from the root node of the syntax tree, and automatically determine the dependency relationship according to the node type, including data dependency, control dependency and function dependency. Three types, add variables and corresponding dependency relationship labels to the result set, realize the automatic extraction of variable dependency relationship in Java program.
[0037] Data dependency (dd): the data dependency between variables is reflected in the assignment statement in the code:
[0038]
[0039] In the above formula, the change of variables b and c will cause the change of a, so there is a data dependency relationship between variable a and variables b and c. The change of variable b will indirectly affect variable d by affecting variable a, but this indirect influence is not considered as a dependency relationship between variables b and d.
[0040] Control dependency (cd): if there are control structures such as if, for, while, etc. in the program, and the variable is used in the condition expression, then the assignment variable in the structure depends on the condition variable:
[0041] if (con > 3) { h = 0;}
[0042] In the above if statement, h controls the process and depends on con.
[0043] Functional dependency (fd): If a method call exists in the program, and the variable is passed or receives a return value during the call, it is marked as a functional dependency.
[0044] h = f()
[0045] In the above program, the function h depends on the method f.
[0046] Step 2.2: Construction of the Variable Dependency Network Model
[0047] The result set of variable dependency extraction contains source variables, target variables, and dependency type labels. This result set is transformed into a directed graph data structure, with each unique variable serving as a vertex to construct a set of nodes. Directed edges are established from the source variable to the target variable according to the dependency direction, and the dependency type label is used as the attribute value of the directed edge; finally, a complete directed graph model of variable dependencies, i.e., a variable dependency network model, is constructed.
[0048] The obtained variable dependency network model can serve as an effective alternative to test cases, used to characterize failed test cases f. i The defective characteristics.
[0049] Step 3: Measure the similarity of representations
[0050] Given n failed test cases, select any two failed test cases f. i f j …defect characterization P i P j A graph edit distance calculation method based on the Hungarian algorithm is adopted. By solving the optimal matching between nodes and comprehensively calculating the edge editing operations, the minimum graph edit cost is obtained, which is used as the failure test case f. i f j The distance d between ij The distances between each pair of n failed test cases are statistically analyzed to generate a symmetric distance matrix D, providing a quantitative basis for subsequent analysis.
[0051] Step 4: In this embodiment, the K-medoids algorithm is used to cluster the defect representations of failed test cases and estimate the number of independent faults that can be revealed by the failed test cases. For each fault category, the defect representation that can reveal the fault earliest is set as the initial centroid of the clustering algorithm.
[0052] After the clustering of failed test cases is completed, for each generated fault-focused cluster, a separate defect localization sub-process is initiated. All the failed test cases in the current cluster are combined with all the available successful test cases in the test suite to form a local sample set for analysis. On this basis, the spectrum-based fault localization technique is applied, and the Ochiai formula is used to generate an independent and exclusive suspiciousness ranking list for each such sample set for review.
[0053] In cluster-based multi-defect localization, accurate estimation of the number of faults is a key step before clustering. Since mainstream clustering algorithms cannot automatically identify the number of real defect clusters, incorrect number estimation will directly affect the clustering effect: overestimating the value of k will lead to overfitting, resulting in redundant reports and increasing the review burden; underestimating the value of k will cause underfitting, leading to unclear localization results and reducing the usability of the report. To prove that the proposed method can effectively improve the accuracy of fault number estimation, it is compared with existing defect characterization methods based on code coverage in terms of fault number estimation and clustering effect. Table 1 shows the statistics of the correct number of defects:
[0054] Table 1
[0055]
[0056] wherein, represents a method using the number of statement executions as a failure feature, represents a method using binary information to record whether a statement is covered as a failure feature, both of which use the Euclidean distance to measure the similarity between failures.
[0057] As can be seen from the results in Table 1, the proposed method is more accurate in fault number estimation than the other two methods. The proposed method correctly estimates the number of 208 defects, which is an improvement of 25.3% and 10.6% compared to the other two methods.
[0058] In terms of clustering effect, four clustering evaluation indicators are used to quantify the degree of agreement between the results and the true classes, including the consistency between two clustering results, the JC (Jaccard Coefficient) that measures the proportion of correctly classified sample pairs in the clustering results, the Precision that measures the proportion of truly belonging to the same class among the sample pairs classified into the same cluster, and the Recall that measures the proportion of correctly classified sample pairs in the truly belonging to the same class. The higher the indicator value, the better the clustering effect of the method. The clustering effect evaluation is shown in Table 2: Table 2
[0059]
[0060]
[0061] The results show that the method performs well in the above two key stages. Experimental data show that the application can more accurately distinguish software defects of different origins, thereby providing effective support for defect positioning in a multi-defect scenario.
[0062] A software multi-defect positioning device based on variable dependency and clustering, as shown in Figure 2 , comprises:
[0063] A variable dependency extraction module is configured to extract the dependency between different variables for each failed test case.
[0064] A variable dependency network model uses nodes in a directed graph to represent variables and edges to represent the dependency between variables, and uses the directed graph as a defect feature of the failed test case.
[0065] A distance measurement module uses the graph edit distance as the distance between different defect features of the failed test cases.
[0066] A clustering analysis module performs clustering based on the distance between the failed test cases output by the distance measurement module, and generates an independent defect-focused suspiciousness ranking for each cluster.
Claims
1. A software multi-defect positioning method based on variable dependency and clustering, executing a program to be debugged and a test case set, collecting statement coverage information of failed test cases according to test results, clustering according to the distance between each failed test case, generating an independent defect-focused suspiciousness ranking for each cluster, and realizing parallel positioning of multiple defects; characterized in that: Based on the program part covered by the failed test case, the dependency relationship between variables is extracted by analyzing the program source code; the linear dependency relationship between variables is converted into a directed graph model, and the node represents the variable and the edge represents the dependency relationship between variables as the variable dependency network of the failed test case; The graph edit distance is used to capture the topological structure changes in the variable dependency network of different failed test cases, including the increase and decrease of nodes and the change of edge connection mode, and the edit operation cost is mapped to the interval [0, 1] through normalization processing as the distance between failed test cases.
2. The software multi-defect localization method based on variable dependency and clustering of claim 1, wherein: The Tree-sitter tool is used to construct the abstract syntax tree of the program, and the root node of the syntax tree is traversed to automatically judge the dependency relationship according to the node type.
3. The software multi-defect localization method based on variable dependency and clustering of claim 2, wherein: The dependency relationship includes data dependency, control dependency and function dependency.
4. The software multi-defect localization method based on variable dependency and clustering of claim 1, wherein: For two failed test cases f i , j the variable dependency network P i , P j , the graph edit distance calculation method based on the Hungarian algorithm is adopted, the optimal matching between nodes is solved, and the editing operation of the edge is comprehensively calculated to obtain the minimum graph editing cost as the distance d i , f j between the failed test cases f ij .
5. The software multiple defect location method based on variable dependency and clustering as claimed in claim 4 wherein: The K-medoids algorithm is used to cluster the failed test cases.
6. A computer readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of any one of claims 1-5.
7. A software multi-defect localization apparatus based on variable dependency and clustering, taking as input statement coverage information of failed test cases of a program, outputting defect-focused suspiciousness ranking, characterized in that: Comprise: a variable dependency relationship extraction module for extracting the dependency relationship between different variables for each input failed test case; a variable dependency network model using nodes in a directed graph to represent variables and edges to represent the dependency relationship between variables, using a directed graph as a defect feature of a failed test case; a distance measurement module using graph edit distance as the distance between different failed test case defect features; a cluster analysis module based on the distance between failed test cases output by the distance measurement module to cluster, and generate an independent defect focus suspiciousness ranking for each cluster.