Software defect positioning method and system based on multi-stream model fusion
By combining test case reduction and weighting strategies with a multilayer perceptron model to integrate multiple features, the problem of insufficient utilization of test cases in existing software defect localization methods is solved, achieving a more efficient defect localization effect.
Patent Information
- Application Number
- CN202511526964.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2045-10-24
AI Technical Summary
Existing software defect localization methods rely on test case execution information and assume that all test cases have the same defect-revealing ability, resulting in the underutilization of test case potential. Furthermore, traditional methods are inefficient and difficult to adapt to the debugging needs of large-scale systems.
A test case reduction strategy is adopted to filter out high-coverage test cases that pass. A test case weighting strategy is used to weight the remaining test cases. By combining spectral features, variation features, local semantic features and global structural features, feature fusion is performed through a multilayer perceptron model to achieve software defect localization.
It effectively reduces the time cost of variation testing, reflects the ability of different test cases to reveal defects, and improves the accuracy and efficiency of defect localization.
Smart Images

Figure CN121029619A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of software maintenance, specifically relating to a software defect localization method and system based on multi-flow model fusion. Background Technology
[0002] Software development is inherently a complex engineering activity. Due to factors such as unclear requirements, tight development cycles, or insufficient testing, software defects are almost unavoidable. These defects can not only lead to functional errors but also become entry points for attackers, thus threatening the overall security of the software. To improve the stability and security of software systems, defect localization has become a critical task in software engineering. The core objective of defect localization is to quickly and accurately identify the specific code location that causes failures or abnormal behavior. However, with the continuous increase in the scale and complexity of modern software, traditional methods relying on manual debugging and experience-based analysis are inefficient and difficult to adapt to the debugging needs of large-scale systems. Therefore, how to improve the accuracy and efficiency of defect localization through automation has become an important research direction in the fields of software engineering and software security in recent years, and has gradually attracted widespread attention from academia and industry.
[0003] Existing fault localization techniques mainly include spectrum-based fault localization (SBFL), mutation-based fault localization (MBFL), and learning-based fault localization (LBFL) methods. Test cases play a crucial role in software fault localization. Both coverage-based methods (such as SBFL and MBFL) and learning-based methods rely on information related to test cases to locate defects. Therefore, the quality and distribution of test cases directly affect the performance of the defect localization model. However, most existing research treats all test cases as equally important, without fully exploring their varying contributions to defect localization. In reality, some test cases may be very helpful in defect localization, while others may introduce noise or redundant information. Therefore, effectively identifying and utilizing high-value test cases has become an important direction for improving defect localization performance. Summary of the Invention
[0004] The purpose of this invention is to address the aforementioned challenges in defect localization using existing technologies by providing a software defect localization method and system based on multi-flow model fusion. This invention proposes a novel test case reduction strategy and a novel test case weighting strategy to reduce the cost of variant testing and effectively reflect the defect-revealing capabilities of different test cases. Furthermore, combining four different types of features effectively enhances the representational capabilities of code statements, thereby achieving better defect localization results.
[0005] The specific technical solution adopted in this invention is as follows:
[0006] In a first aspect, the present invention provides a software defect localization method based on multi-flow model fusion, comprising:
[0007] S1. Execute all test cases for the software program to be tested and record the coverage of each statement by each test case; at the same time, based on the execution results of each test case, classify the test cases whose actual execution results are inconsistent with the expected results into the failed test case set, and classify the remaining test cases into the passed test case set.
[0008] S2. Reduce the test case set by deleting test cases whose statement coverage is greater than the average statement coverage. Combine the remaining test cases and the set of failed test cases into a reduced test case set. For each test case in the reduced test case set, calculate the reciprocal of the natural logarithm of its statement coverage and use it as the weight.
[0009] S3. For each statement in the software program to be tested that is covered by the failed test cases, calculate the spectral features and variation features of each statement based on the doubt calculation formula defined by the weight. At the same time, learn the context of the statement through a neural network model to obtain the local semantic features of each statement. After representing the abstract syntax tree and control flow diagram of each statement respectively, they are then fused to obtain the global structural features of each statement.
[0010] S4. For each statement in the software program to be tested that is covered by failed test cases, the spectral features and the mutation features are concatenated as the first input feature, and the local semantic features and the global structural features are concatenated as the second input feature. These are input into a pre-trained defect localization predictor. The two input features are mapped to one-dimensional vectors and then matrix multiplied to obtain a fusion matrix. The fusion matrix is then mapped to a one-dimensional vector again and normalized using Softmax to obtain the suspicion score of each statement. Finally, the suspicion score is used as a positive correlation index for defective statements to filter out suspected defective statements, thereby achieving software defect localization.
[0011] As a preferred embodiment of the first aspect above, each statement has three spectral features, which are obtained by normalizing the weighted Ochiai doubt value, the weighted Tarantula doubt value, and the weighted DStar doubt value, respectively.
[0012] The weighted Ochiai skepticism value is obtained by dividing the first numerator and the first denominator.
[0013] The first numerator is the sum of the weights of all failed test cases covering the current statement;
[0014] The first denominator is the square root of the product of the sum of the weights of all test cases in the failed test case set and the sum of the weights of all test cases covering the current statement in the reduced test case set.
[0015] The weighted Tarantula skepticism value is obtained by dividing the second numerator term by the second denominator term;
[0016] The second numerator is the sum of the weights of all failed test cases covering the current statement divided by the sum of the weights of all test cases in the set of failed test cases;
[0017] The second denominator is obtained by summing the first sub-item and the second sub-item. The first sub-item is obtained by dividing the sum of the weights of all failed test cases covering the current statement by the sum of the weights of all test cases in the set of failed test cases. The second sub-item is obtained by dividing the sum of the weights of all passed test cases covering the current statement by the sum of the weights of all test cases in the set of passed test cases.
[0018] The weighted DStar skepticism value is obtained by dividing the third numerator and the third denominator.
[0019] The third numerator is obtained by exponentiation of the sum of the weights of all failed test cases covering the current statement;
[0020] The third denominator is obtained by adding the sum of the weights of all test cases in the set of passed test cases that cover the current statement to the sum of the weights of all test cases in the set of failed test cases that do not cover the current statement.
[0021] As a preferred embodiment of the first aspect above, the method for extracting the variation features of each statement is as follows:
[0022] The mutation testing tool generates different variants of the software program to be tested, and each variant corresponds to a syntax modification of a statement.
[0023] Then, the suspicion score for each variant in the variant set of the current statement is calculated. The suspicion score is obtained by dividing the fourth numerator and the fourth denominator. The fourth numerator is the sum of the weights of all test cases in the set of failed test cases that cover the current statement after executing the current variant. The fourth denominator is the square root of the product of the third and fourth sub-items. The third sub-item is the sum of the weights of all test cases in the set of failed test cases that cover the current statement after executing the current variant. The fourth sub-item is the sum of the weights of all test cases in the set of failed test cases that cover the current statement after executing the current variant.
[0024] Finally, the maximum suspicion score of all variants in the variant set is taken as the weighted MBFL suspicion value, and after normalization, the variant feature of the current statement is obtained.
[0025] As a preferred embodiment of the first aspect mentioned above, each category of doubt value among the weighted Ochiai doubt value, weighted Tarantula doubt value, weighted DStar doubt value, and weighted MBFL doubt value is converted into a feature value using the same normalization operation. The specific conversion method is as follows: for the current normalized doubt value category, the doubt values of all statements in that category are sorted in descending order, and the ranking of each statement is determined. Then, the ratio of the ranking of each statement to the total number of statements is calculated, and 1 is subtracted from the ratio to obtain the feature value obtained after the normalization operation of this statement.
[0026] As a preferred option in the first aspect mentioned above, the method for extracting local semantic features of each statement is as follows:
[0027] The context code block centered on the current statement is generated by code slicing, and the current statement is marked by preset start and end markers; then the context code block is sequentially input into the backbone network and encoder to obtain the local semantic features of the current statement;
[0028] The backbone network and encoder need to be pre-concatenated with a decoder for training. During training, the context code block is first input into the backbone network, converted into an embedding vector by the embedding layer, and then input into the Bi-LSTM model to obtain the hidden layer output. The hidden layer output is then compressed in dimension by the encoder based on a multilayer perceptron to obtain the local semantic features of the current sentence. Finally, the local semantic features are reconstructed to the same dimension as the hidden layer output by the decoder based on a multilayer perceptron, and the reconstruction loss is calculated. The parameters of the cascaded model are optimized by minimizing the reconstruction loss.
[0029] As a preferred option in the first aspect mentioned above, the global structural feature extraction method for each statement is as follows:
[0030] First, generate the control flow graph (CFG) and abstract syntax tree (AST) of the method containing the current statement e. Then, use the Node2Vec algorithm to embed nodes in the control flow graph (CFG) and abstract syntax tree (AST) to obtain node embedding vectors. Concatenate the node embedding vectors corresponding to the current statement in the control flow graph and abstract syntax tree to obtain the global structural features.
[0031] As a preferred embodiment of the first aspect, the defect localization predictor includes three multilayer perceptrons and a Softmax layer. The first input feature is mapped to a one-dimensional vector through the first multilayer perceptron, and the second input feature is mapped to a one-dimensional vector through the second multilayer perceptron. The two one-dimensional vectors are multiplied by matrix to obtain a fusion matrix, which is then mapped to a one-dimensional vector through the third multilayer perceptron and passed through the Softmax layer to output a suspicion score. Furthermore, the defect localization predictor is pre-supervised learning with the goal of minimizing the batch hinge loss.
[0032] Secondly, the present invention provides a software defect localization system based on multi-flow model fusion, comprising:
[0033] The program input module is used for users to input the software program to be tested;
[0034] The defect localization module is used to obtain the defect statement localization result in the software defect localization method based on multi-flow model fusion as described in any of the first aspects above.
[0035] The result output module is used to output the location results of defect statements in the software program to be tested according to a preset output method.
[0036] Thirdly, the present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, can implement the software defect localization method based on multi-stream model fusion as described in any of the first aspects above.
[0037] Fourthly, the present invention provides a computer electronic device, which includes a memory and a processor;
[0038] The memory is used to store computer programs;
[0039] The processor is configured to, when executing the computer program, implement the software defect localization method based on multi-stream model fusion as described in any of the first aspects above.
[0040] Compared with the prior art, the present invention has the following advantages:
[0041] This invention, based on information entropy theory, proposes a test case reduction strategy and a test case weighting strategy. These strategies not only effectively reduce the time cost of mutation testing but also effectively reflect the ability of different test cases to uncover defects. By redefining the skepticism calculation formula through test case weights, discriminative spectral and mutation features are obtained. A novel neural network model is designed to learn the context of code statements to acquire local semantic features. Global structural features of code statements are obtained by representing and fusing abstract syntax trees and control flow graphs separately. This invention achieves more expressive representation vectors by fusing four different types of features, effectively improving the model's defect localization accuracy. Attached Figure Description
[0042] Figure 1 The flowchart shows the steps of a software defect localization method based on multi-flow model fusion.
[0043] Figure 2 A schematic diagram illustrating the process of extracting four different types of features from a target statement;
[0044] Figure 3 A schematic diagram of the training framework for the encoder-decoder model designed for extracting semantic features from code.
[0045] Figure 4 A schematic diagram of the module composition of a software defect localization system based on multi-flow model fusion;
[0046] Figure 5 This is a schematic diagram of the structure of a computer electronic device. Detailed Implementation
[0047] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention can be practiced in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. Technical features in various embodiments of the present invention can be combined accordingly without mutual conflict.
[0048] In the description of this invention, it should be understood that the terms "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature.
[0049] In software development and maintenance, defect localization plays a crucial role in ensuring software quality. Most existing defect localization methods rely on test case execution information or coverage relationships, but they often implicitly assume that all test cases have the same defect-revealing ability, leading to underutilization of test case potential. Inspired by this, this invention provides a software defect localization method based on multi-flow model fusion. In this method, a test case reduction strategy is first used to filter out high-coverage, passing test cases to reduce the cost of mutation testing. Then, a test case weighting strategy is used to weight the remaining test cases to reflect their defect-revealing ability. Next, four types of features are extracted: spectral features, mutation features, local semantic features, and global structural features. Spectral features and mutation features are calculated using a weighted skepticism formula, while local semantic features and global structural features are obtained through deep learning techniques. Finally, these four types of features are fused and input into a defect localization predictor trained on a multilayer perceptron (MLP) to locate defective statements.
[0050] like Figure 1 As shown, in a preferred embodiment of the present invention, a software defect localization method based on multi-flow model fusion is provided, the specific steps of which are shown in S1~S4.
[0051] S1. Execute all test cases for the software program to be tested and record the coverage of each statement by each test case; simultaneously, based on the execution results of all test cases, classify the test cases whose actual execution results are inconsistent with the expected results into the failed test case set (denoted as...). The remaining test cases are added to the set of passed test cases (denoted as ). ).
[0052] It should be noted that the statements in this invention refer to code statements in the software program to be tested. For different software programs to be tested, the test cases to be executed can be selected according to actual needs. The specific testing methods are conventional techniques in software engineering and are not limited thereto. The coverage of each statement by the above test cases can be recorded using a code coverage tool (such as Cobertura) when all test cases are executed. The coverage of code statements by each test case can be recorded in a predefined manner.
[0053] In embodiments of the present invention, a code coverage tool can be used to record the coverage of code statements by each test case, generating a coverage matrix. In the coverage matrix, rows represent test cases, columns represent code statements, and matrix elements are Boolean values: 1 indicates that the test cases in the row containing the element cover the statements in the column containing the element, and 0 indicates that the test cases in the row containing the element do not cover the statements in the column containing the element. The total number of rows in the coverage matrix equals the total number of test cases, and the total number of columns equals the total number of code statements. Therefore, the coverage matrix can be used directly to count the number of test cases covering different statements and the set of test cases covering any statement. Of course, the coverage matrix is mainly introduced to facilitate subsequent statistics and set filtering, but it is not the only way to record the coverage of each statement by test cases.
[0054] In addition, in embodiments of the present invention, when executing all test cases, it is also necessary to record the execution result of each test case, and then divide the test cases into test case sets. and the set of failed test cases To avoid ambiguity, the meanings of "passing" and "failing" for test cases are defined as follows: In the test case execution results, "passing" indicates that the actual execution result of the test case matches the expected result, while "failing" indicates that the actual execution result of the test case does not match the expected result. Therefore, in this invention, test cases whose actual execution result does not match the expected result can be classified into the set of failed test cases. The remaining test cases are added to the set of passed test cases. Through the test case set and the set of failed test cases Initially, all sets are empty.
[0055] S2. Reduce the set of test cases by deleting test cases whose statement coverage exceeds the average statement coverage. Combine the remaining test cases and the set of failed test cases into the reduced set of test cases. ; for the reduced test case set For each test case in the dataset, calculate the inverse of the natural logarithm of its statement coverage and use it as the weight.
[0056] It should be noted that the core of this invention's reduction of the test case set is a test case reduction strategy that uses the average statement coverage as a filter to remove high-coverage test cases, thereby reducing the cost of mutation testing. Specifically, the reduction only applies to passing test cases; failing test cases are not reduced and are retained. Therefore, the average statement coverage in this invention refers to the average statement coverage of all test cases in the passing test case set.
[0057] In embodiments of the present invention, a specific set of reduced test cases is provided. The construction process is as follows:
[0058] First, for the test case set For each test case in the set, calculate its statement coverage using the coverage matrix; then, for each test case that passes the test case set... Calculate the average statement coverage of all test cases in the set; finally, for each test case that passes the test case set... Test cases with statement coverage exceeding the average statement coverage are deleted, while those with less than the average statement coverage are retained in the simplified test case set. In the middle, and at the same time, the entire set of failed test cases. It is also directly added to the reduced test case set. .therefore, The test cases retained include all failed test cases and passed test cases with less statement coverage than the average statement coverage.
[0059] For ease of description, this invention will use the reduced test case set. Override a statement A subset of is denoted as .
[0060] Additionally, it should be noted that step S2 of this invention also requires using a test case weighting strategy to weight the remaining test cases to reflect their ability to reveal defects. Specifically, for the reduced test case set... For each test case in the set, the natural logarithm of its statement coverage needs to be calculated, and then the reciprocal of the natural logarithm is taken as the weight of that test case. In an embodiment of the present invention, for the reduced test case set... Each test case in The number of statements it covers is defined as Then the weight of the test case The calculation formula is:
[0061]
[0062] Where log is the natural logarithm function.
[0063] It is particularly important to note that if test cases This test case covers 0 statements. To avoid division by zero in subsequent calculations, this test case can be used. weight Let it be a positive number close to zero. In embodiments of the present invention, this close-to-zero value can be specifically set as... .
[0064] S3. For each statement in the software program to be tested that is covered by the failed test cases, calculate the spectral features and variation features of each statement based on the doubt calculation formula defined by the weight. At the same time, learn the context of the statement through a neural network model to obtain the local semantic features of each statement. After representing the abstract syntax tree and control flow graph of each statement respectively, they are fused to obtain the global structural features of each statement.
[0065] It should be noted that spectral features are features obtained by the spectrum-based fault localization (SBFL) method, and will be referred to as SBFL features thereafter; mutation features are features obtained by the mutation-based fault localization (MBFL) method, and will be referred to as MBFL features thereafter.
[0066] Traditional SBFL features include three skepticism values: Ochiai, Tarantula, and DStar, each with its own existing skepticism calculation formula. However, this invention utilizes a test case weighting strategy to weight the retained test cases. Therefore, it is necessary to redefine the skepticism calculation formulas for Ochiai, Tarantula, and DStar based on the test case weights, and calculate the weighted Ochiai skepticism value, weighted Tarantula skepticism value, and weighted DStar skepticism value. After normalizing these three weighted skepticism values, three weighted SBFL features are formed.
[0067] Therefore, in the embodiments of the present invention, each statement has three spectral features, namely SBFL features, which are obtained by normalizing the weighted Ochiai skepticism value, the weighted Tarantula skepticism value, and the weighted DStar skepticism value, respectively. The skepticism calculation formulas for the weighted Ochiai skepticism value, the weighted Tarantula skepticism value, and the weighted DStar skepticism value are based on the skepticism calculation formulas defined by the weights. Simultaneously, the skepticism calculation formula for the variant feature, namely MBFL feature, is also based on the skepticism calculation formulas defined by the weights. A schematic diagram illustrating the process of extracting four different types of features from the target statement is shown below. Figure 2 As shown below, these redefined formulas for calculating skepticism will be described in detail.
[0068] 1) The weighted Ochiai skepticism value is obtained by dividing the first numerator by the first denominator. The first numerator is the set of all failed test cases covering the current statement. The sum of the weights of the test cases. The first denominator is the set of failed test cases. The arithmetic square root of the product obtained by multiplying the sum of the weights of all test cases in the current statement by the sum of the weights of all test cases in the reduced test case set that cover the current statement.
[0069] 2) The weighted Tarantula skepticism value is obtained by dividing the second numerator by the second denominator. The second numerator is determined by the set of all failed test cases covering the current statement. The sum of the weights of the test cases divided by the set of failed test cases. The sum of the weights of all test cases in the current statement. The second denominator is obtained by summing the first and second sub-terms, where the first sub-term is the sum of all failed test cases covering the current statement (i.e., the set). The sum of the weights of the test cases divided by the set of failed test cases. The second sub-item is obtained by summing the weights of all test cases in the set, and is derived from all passed test cases covering the current statement (i.e., the set). The sum of the weights of the test cases divided by the set of test cases. The sum of the weights of all test cases is obtained.
[0070] 3) The weighted DStar skepticism value is obtained by dividing the third numerator by the third denominator. The third numerator is determined by the set of all failed test cases covering the current statement. The sum of the weights is obtained by exponentiation. The third denominator is obtained by adding the sum of the weights of all test cases in the set of passed test cases that cover the current statement to the sum of the weights of all test cases in the set of failed test cases that do not cover the current statement.
[0071] The above weighted Ochiai skepticism value Weighted Tarantula skepticism score Weighted DStar skepticism value The degree of suspicion can be calculated using the following formulas:
[0072]
[0073]
[0074]
[0075] in: and These represent a failed test case and a successful test case, respectively. and These represent overwrite statements. Failed test cases and coverage statements Successful test cases, and These represent overwrite statements. Failed test case set and coverage statements The set of test cases passed. To reduce the set of test cases Override statement The test example set, for One of the test cases included. To pass the test case set, it's important to note that the successful test case set... The formula above has been simplified beforehand, therefore... This represents the reduced set of successful test cases. The weight of a test case is indicated by its index, for example... For test cases The corresponding weights For test cases The corresponding weights follow the same pattern. "*" represents a preset optional value, which acts as a power in the formula. In the embodiments of this invention, "*" is preferably set to 2. It represents belonging to the set But not belonging to A set of test cases.
[0076] Therefore, based on the redefined skepticism calculation formula with the aforementioned weights, a weighted Ochiai skepticism value can be calculated for each statement. Weighted Tarantula skepticism score Weighted DStar skepticism value .
[0077] Furthermore, the weighted Ochiai skepticism value, weighted Tarantula skepticism value, and weighted DStar skepticism value of all statements are normalized to convert them into SBFL feature values. The specific conversion method is as follows:
[0078] For each category of the current normalized doubt value, sort the doubt values of all statements in that category in descending order and determine the ranking of each statement. Then, calculate the ratio of the ranking of each statement to the total number of statements, and subtract this ratio from 1 to obtain the feature value obtained after the normalization operation of this statement.
[0079] For any statement Weighted Ochiai skepticism score Weighted Tarantula skepticism score Weighted DStar skepticism value After normalization, the resulting SBFL eigenvalues This can be expressed by the formula as follows:
[0080]
[0081] in For statement The weighted skepticism values of all statements are ranked in descending order (ranking numbers from 1 to N). This represents the total number of statements in the software program to be tested. It's important to note that since there are three categories of weighted skepticism values, they need to be ranked in descending order for each category, and then the aforementioned normalization process is performed within each category.
[0082] 4) The method for extracting the variation features of each statement is as follows:
[0083] Use mutation testing tools (such as Major) to generate different variants of the software program to be tested. Each variant corresponds to a syntax modification of a statement, and the same statement may have multiple variants.
[0084] Then calculate the set of variants for the current statement. The doubt score for each variant is obtained by dividing the fourth numerator and the fourth denominator. The fourth numerator is the sum of the weights of all test cases in the set of failed test cases that cover the current statement after executing the current variant. The fourth denominator is the square root of the product of the third and fourth sub-items. The third sub-item is the sum of the weights of all test cases in the set of failed test cases that cover the current statement after executing the current variant. The fourth sub-item is the sum of the weights of all test cases in the set of failed test cases that cover the current statement after executing the current variant.
[0085] Finally, the maximum suspicion score of all variants in the variant set is taken as the weighted MBFL suspicion value, and after normalization, the variant feature of the current statement is obtained.
[0086] In an embodiment of the present invention, if the mutation testing tool modifies statement e when generating a variant in the software program to be tested, that is, if the generated variant is regarded as statement e... The variant of. Therefore, for the statement The set of variants Calculate the weighted MBFL skepticism score. The skepticism integral can be calculated using the following formula:
[0087]
[0088] in Refers to the execution of variants The next failed test case, Refers to the execution of variants The subsequent set of failed test cases, Refers to the execution of variants Post-overwrite statement A test case, This refers to the overwrite statement after executing the mutant. The set of test cases, Refers to the execution of variants Post-overwrite statement The set of failed test cases;
[0089] The method for normalizing the weighted MBFL skepticism values to convert them into MBFL features can be similar to the SBFL feature normalization operation described above, that is, normalizing all statements... Weighted MBFL skepticism score Sort in descending order and determine each statement. Ranking Then calculate each statement MBFL eigenvalues .
[0090] In addition to obtaining spectral features and variation features, each statement also needs to learn the context of the statement through a neural network model to obtain the local semantic features of each statement. The global structural features of each statement are obtained by representing the abstract syntax tree and control flow graph of each statement separately and then fusing them.
[0091] In an embodiment of the present invention, the method for extracting local semantic features of each statement is as follows:
[0092] The system generates context code blocks centered on the current statement through code slicing, and marks the current statement using preset start and end markers. These context code blocks are then sequentially input into the backbone network and encoder to obtain the local semantic features of the current statement. Crucially, the backbone network and encoder require a pre-concatenated decoder for training before actual inference. During training, the context code blocks are first input into the backbone network, converted into embedding vectors by the embedding layer, and then input into a Bi-LSTM model to obtain the hidden layer output. The hidden layer output is then dimensionality-compressed by a multilayer perceptron-based encoder to obtain the local semantic features of the current statement. Finally, the local semantic features are reconstructed to the same dimension as the hidden layer output by the multilayer perceptron-based decoder, and the reconstruction loss is calculated. The parameters of the cascaded model are optimized by minimizing the reconstruction loss.
[0093] See also Figure 3 The diagram illustrates the training framework for the aforementioned backbone network, encoder, and decoder. The specific process within this framework is as follows:
[0094] 1. For each statement Context code blocks are generated through code slicing, with a token length of [missing information]. Taking statement 'e' as the center, extract the statements before and after it. _ tokens, forming a token length of _ The context code block, and with a special token " <startfocus>"and" <endfocus>"mark Location;
[0095] 2. Design a new encoder-decoder based model, comprising a backbone, an encoder, and a decoder. In an embodiment of this invention, the backbone consists of an embedding layer and a Bi-LSTM network, while the encoder and decoder each employ a two-layer MLP. The backbone's embedding layer stores each statement... The context code block is converted into a vector sequence, which is then input into the Bi-LSTM network to obtain the hidden layer output. ,in The number of tokens in the context code block. For the embedding dimension. Then, the hidden layer output is processed by an encoder (2-layer MLP). Compressed into a 4-dimensional vector , as a statement The semantic features are then processed by a decoder (2-layer MLP) to... Restore to Decoder output with the same dimensional size .
[0096] 3. Based on decoder output and the encoder's hidden layer output The reconstruction loss MSE can then be calculated, and its formula can be expressed as:
[0097]
[0098] The training objective of the aforementioned backbone network, encoder, and decoder training framework is to minimize the reconstruction loss. After training is complete, the decoder can be removed, and the corresponding backbone network and encoder can be cascaded to extract local semantic features from the context code blocks of the statement.
[0099] Furthermore, in the embodiments of the present invention, the global structural feature extraction method for each statement is as follows:
[0100] First, the control flow graph (CFG) and abstract syntax tree (AST) of the method containing the current statement e are generated. Then, the Node2Vec algorithm is used to embed nodes in the CFG and AST respectively, obtaining node embedding vectors. The embedding vectors of the corresponding nodes of statement e in the CFG and AST are concatenated to obtain the global structural features of statement e. In this embodiment, the embedding vectors of CFG and AST have a dimension of 2, so the final global structural features are 4-dimensional structural features.
[0101] S4. For each statement in the software program to be tested that is covered by failed test cases, the spectral features and the mutation features are concatenated as the first input feature, and the local semantic features and the global structural features are concatenated as the second input feature. These are input into a pre-trained defect localization predictor. The two input features are mapped to one-dimensional vectors and then matrix multiplied to obtain a fusion matrix. The fusion matrix is then mapped to a one-dimensional vector again and normalized using Softmax to obtain the suspicion score of each statement. Finally, the suspicion score is used as a positive correlation index for defective statements to filter out suspected defective statements, thereby achieving software defect localization.
[0102] It should be noted that the mappings in the above-mentioned defect localization predictor can all be implemented using MLP, and the defect localization predictor needs to be pre-trained before it can be used for inference. Therefore, the defect localization predictor contains three multilayer perceptrons and a softmax layer. The first input feature is mapped to a one-dimensional vector through the first multilayer perceptron, the second input feature is mapped to a one-dimensional vector through the second multilayer perceptron, the two one-dimensional vectors are multiplied to obtain a fusion matrix, and then mapped to a one-dimensional vector through the third multilayer perceptron and passed through the softmax layer to output a suspicion score; and the defect localization predictor is pre-trained under supervised learning with the goal of minimizing the batch hinge loss.
[0103] Specifically, in the embodiments of the present invention, the feature fusion input and model training process in the above-mentioned defect localization predictor are as follows:
[0104] A) Concatenate the spectral features and variation features into the first input feature. The local semantic features and global structural features are concatenated to form the second input feature. ;
[0105] B) Regarding the first input features Map it to a vector using a single MLP layer. For the second input features Map it to a vector using a single MLP layer. ;
[0106] C) Multiply the outputs of the two MLPs using matrix multiplication. The results are fused into an 8×8 fusion matrix, which is then converted into a one-dimensional output vector through another MLP layer. This one-dimensional output vector is then normalized by Softmax to obtain the suspicion score.
[0107] D) Batch sampling is performed on a set of labeled statements. Each batch contains both faulty statements and normal statements. The statement sample set can be constructed from historical project versions of the software program to be inspected. Each batch needs to be input into the defect localization and prediction model for training. The loss function used for training is the batch hinge loss, calculated as follows:
[0108]
[0109] in This is the marginal parameter (which can be set to 1.0 in this embodiment). The first in the batch The predicted suspiciousness score of a defective statement. The first in the batch The predicted suspiciousness score of each normal statement. In optimizing the model parameters, this embodiment uses AdamW as the optimizer with a learning rate of 0.001 and a total of 50 iterations.
[0110] Therefore, the trained defect localization predictor can be used for actual defect localization. The process involves applying the trained model to the program to be tested, calculating the suspicion score for each statement covered by failed test cases, and then using the suspicion score as a positive correlation indicator to filter out suspected defective statements. The specific filtering method can be designed according to actual needs. In this embodiment, all code statements covered by failed test cases can be sorted in descending order of suspicion score; statements ranked higher have a higher probability of being defective and should be checked first.
[0111] In summary, the defect localization predictor of this invention can effectively improve the defect localization accuracy of the model by fusing four different types of features to obtain a more expressive representation vector.
[0112] It should be noted that the method steps shown in S1 to S4 above can essentially be implemented in the form of computer programs or software functional modules.
[0113] Therefore, based on the same inventive concept, such as Figure 4 As shown, the present invention also provides a software defect localization system based on multi-flow model fusion, corresponding to the software defect localization method based on multi-flow model fusion provided in the above embodiments, which includes:
[0114] The program input module is used for users to input the software program to be tested;
[0115] The defect localization module is used to obtain the defect statement localization result in the software defect localization method based on multi-flow model fusion as described in the above embodiments.
[0116] The result output module is used to output the location results of defect statements in the software program to be tested according to a preset output method.
[0117] It should be noted that both the program input module and the result output module described above can provide corresponding program input and result output through a GUI interface or other command input / output methods. The defect location module, however, can be implemented by running the corresponding location algorithm in the background. The specific input and output formats can be designed according to actual needs and are not limited thereto.
[0118] Furthermore, based on the same inventive concept, such as Figure 5 As shown, the present invention also provides a computer electronic device corresponding to the software defect localization method based on multi-flow model fusion provided in the above embodiments, which includes a memory and a processor;
[0119] The memory is used to store computer programs;
[0120] The processor is configured to implement the software defect localization method based on multi-stream model fusion as described above when executing the computer program.
[0121] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0122] Therefore, based on the same inventive concept, the present invention provides a computer-readable storage medium corresponding to the software defect localization method based on multi-flow model fusion. The storage medium stores a computer program, which, when executed by a processor, can realize the software defect localization method based on multi-flow model fusion as described above.
[0123] Therefore, based on the same inventive concept, the present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, can realize the software defect localization method based on multi-stream model fusion as described above.
[0124] Specifically, in the computer-readable storage medium of the above three embodiments, the stored computer program is executed by a processor, which can perform the aforementioned steps S1 to S4.
[0125] It is understood that the aforementioned storage media may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Furthermore, the storage media may also be various media capable of storing program code, such as USB flash drives, external hard drives, magnetic disks, or optical discs.
[0126] It is understood that the processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0127] It should also be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the system described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. In the embodiments provided in this application, the division of steps or modules in the system and method is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple modules or steps may be combined or integrated together, and a module or step may also be split.
[0128] The present invention will further demonstrate the detailed implementation process and technical effects of the software defect localization method based on multi-flow model fusion shown in steps S1 to S4 on a specific dataset through a specific embodiment, so as to facilitate understanding of the technical effects of the present invention.
[0129] Example
[0130] The steps in this embodiment are the same as those in steps S1 to S4 above, which describe the software defect localization method based on multi-flow model fusion. Therefore, they will not be repeated here. The main focus is on demonstrating the specific dataset, some specific parameter settings, and implementation results of this embodiment. For ease of description, the method shown in steps S1 to S4 will be referred to as the method of this invention, and the defect localization predictor used will be denoted as WetFL.
[0131] Experimental Dataset: The Defect4J (V1.2.0) dataset is an open-source dataset widely used for software defect localization research. It collects 395 real defects from 6 Java projects, including faulty version code, fixed version code, test cases, and coverage information, and labels the specific defect locations. This dataset features multiple projects, multiple versions, and real defects, facilitating the evaluation of various defect localization and automated program repair methods, and ensuring the reproducibility of experiments.
[0132] Evaluation metrics: Top1, Top3, Top5, MAR, and MFR. Higher values for Top1, Top3, and Top5 are better, while lower values for MAR and MFR are better.
[0133] The specific experimental results of this embodiment are as follows:
[0134] (1) Algorithm comparison results
[0135] Table 1. Comparison results of this invention with other algorithms on the Defect4J dataset.
[0136]
[0137] Table 1 compares the software defect localization results of this invention with other comparative methods on the Defect4J dataset. As can be seen from the summary results in Table 1, this invention has significant advantages over other comparative methods.
[0138] (2) Ablation test results
[0139] Table 2 Impact of Key Components
[0140]
[0141] In Table 2, "w / o weighted strategy" means removing the weighted strategy; both SBFL and MBFL features directly use the standard skepticism calculation formula. "w / o reduction strategy" means the test case set is not reduced. "w / o weighted strategy & reduction strategy" means removing the weighted strategy while also not reducing the test case set. "w / o batch hinge loss function" means replacing the batch hinge loss function used to train the defect localization predictor with the standard hinge loss function.
[0142] As can be seen from the results in Table 2, removing any component will lead to a decrease in WetFL's performance. Removing the weighted strategy will cause a significant performance drop, while removing the batch hinge loss function will result in a smaller performance drop.
[0143] Table 3. The Role of Four Types of Characteristics
[0144]
[0145] The results in Table 3 show that removing any feature type leads to a performance decrease. Removing the SBFL feature significantly reduces WetFL's performance, while removing the MBFL feature results in a smaller performance decrease. Furthermore, the results indicate that semantic and structural features have similar effects on improving WetFL's performance.
[0146] Table 4. Comparison Experiments with Other Weighted Strategies
[0147]
[0148] As can be seen from the results in Table 4, the test case weighting strategy proposed in this invention significantly outperforms the results of the three test case weighting strategies: Proximity, WTC, and BWSBFL.
[0149] Table 5. Comparison experiments with other reduction strategies
[0150]
[0151] As can be seen from the results in Table 5, the test case reduction strategy proposed in this invention significantly outperforms the results of the three test case reduction strategies: Proximity, WTC, and BWSBFL.
[0152] The embodiments described above are merely some preferred implementations of the present invention and are not intended to limit the invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the invention. Therefore, all technical solutions obtained through equivalent substitution or transformation fall within the protection scope of the present invention.< / endfocus> < / startfocus>
Claims
1. A software defect localization method based on multi-flow model fusion, characterized in that, The method comprises the following steps: S1, execute all test cases for the software program to be detected, and record the coverage of each test case to each code statement; meanwhile, based on the execution results of all test cases, the test cases with actual execution results inconsistent with expected results are classified into a failed test case set, and the remaining test cases are classified into a passed test case set; S2, reduce the passed test case set, delete the test cases with a statement coverage number greater than an average statement coverage number, and combine the remaining test cases and the failed test case set into a reduced test case set; for each test case in the reduced test case set, calculate the reciprocal of the natural logarithm of the statement coverage number as a weight; S3, calculate the frequency spectrum feature and the mutation feature of each statement covered by the failed test case in the software program to be detected based on a suspicious degree calculation formula defined by the weight, learn the local semantic feature of each statement through a neural network model, obtain the global structure feature of each statement by respectively representing the abstract syntax tree and the control flow chart of each statement and then fusing them, and obtain the global structure feature of each statement; S4, for each statement covered by the failed test case in the software program to be detected, splice the frequency spectrum feature and the mutation feature as a first input feature, splice the local semantic feature and the global structure feature as a second input feature, input the pre-trained defect positioning predictor, map the two input features into one-dimensional vectors respectively, perform matrix multiplication to obtain a fusion matrix, map the fusion matrix into a one-dimensional vector again, and perform Softmax normalization to obtain a suspicious degree score of each statement; Finally, the suspicious degree score is used as a positive correlation index of a defect statement to screen out suspected defect statements, and software defect positioning is realized.
2. The software defect localization method based on multi-flow model fusion according to claim 1, wherein, The frequency spectrum feature of each statement has three, which are obtained by normalizing weighted Ochiai suspicious degree values, weighted Tarantula suspicious degree values and weighted DStar suspicious degree values; The weighted Ochiai suspicious degree value is obtained by dividing a first numerator term by a first denominator term; The first numerator term is the sum of the weights of all failed test cases covering the current statement; The first denominator term is the arithmetic square root of the product of the sum of the weights of all test cases in the failed test case set and the sum of the weights of all test cases covering the current statement in the reduced test case set; The weighted Tarantula suspicious degree value is obtained by dividing a second numerator term by a second denominator term; The second numerator term is obtained by dividing the sum of the weights of all failed test cases covering the current statement by the sum of the weights of all test cases in the failed test case set; The second denominator term is obtained by summing a first sub-term and a second sub-term, the first sub-term is obtained by dividing the sum of the weights of all the failed test cases covering the current statement by the sum of the weights of all the test cases in the failed test case set, and the second sub-term is obtained by dividing the sum of the weights of all the passed test cases covering the current statement by the sum of the weights of all the test cases in the passed test case set; The weighted DStar suspiciousness value is obtained by dividing a third numerator term by a third denominator term; The third numerator term is obtained by raising the sum of the weights of all the failed test cases covering the current statement to a power; The third denominator term is obtained by adding the sum of the weights of all the test cases in the passed test case set covering the current statement to the sum of the weights of all the test cases in the failed test case set not covering the current statement.
3. The software defect localization method based on multi-flow model fusion according to claim 2, wherein, The extraction method of the mutation feature of each statement is as follows: A mutation test tool is used to generate different mutants of the software program to be detected, and each mutant corresponds to a syntax modification of a statement; Then, the suspiciousness score of each mutant in the mutant set of the current statement is calculated, the suspiciousness score is obtained by dividing a fourth numerator term by a fourth denominator term, the fourth numerator term is the sum of the weights of all the test cases in the failed test case set covering the current statement after executing the current mutant, and the fourth denominator term is the arithmetic square root of the product of a third sub-term and a fourth sub-term, the third sub-term is the sum of the weights of all the test cases in the test case set covering the current statement after executing the current mutant, and the fourth sub-term is the sum of the weights of all the test cases in the failed test case set after executing the current mutant; Finally, the maximum suspiciousness score of all the mutants in the mutant set is taken as the weighted MBFL suspiciousness value, and the mutation feature of the current statement is obtained after normalization operation.
4. The software defect localization method based on multi-flow model fusion according to claim 3, wherein, Each of the weighted Ochiai suspiciousness value, the weighted Tarantula suspiciousness value, the weighted DStar suspiciousness value, and the weighted MBFL suspiciousness value is converted into a feature value by the same normalization operation, and the specific conversion method is as follows: for the current normalized suspiciousness value category, the suspiciousness values of all the statements in this category are sorted in descending order, and the ranking of each statement is determined, then the ranking of each statement is divided by the total number of statements, and the feature value of this statement after normalization operation is obtained by subtracting the ratio from 1.
5. The software defect localization method based on multi-flow model fusion according to claim 1, wherein, The local semantic feature extraction method of each statement is as follows: A context code block centered on the current statement is generated by code slicing, and the current statement is marked by a preset start and end marker; then the context code block is input into the trunk network and the encoder in turn to obtain the local semantic feature of the current statement; The backbone network and the encoder need to be cascaded with a decoder in advance for training; during training, the context code block is first input into the backbone network, is converted into an embedding vector through an embedding layer, is input into a Bi-LSTM model to obtain hidden layer output, is subjected to dimension compression by the encoder based on the multilayer perceptron to obtain the local semantic feature of the current sentence, and finally the local semantic feature is reconstructed to the same dimension as the hidden layer output through the decoder based on the multilayer perceptron to calculate the reconstruction loss, and the parameters of the cascaded model are optimized by minimizing the reconstruction loss.
6. The software defect localization method based on multi-flow model fusion according to claim 1, wherein, The global structure feature extraction method of each sentence is: First, the control flow graph and the abstract syntax tree of the method in which the current sentence is located are generated, and then the Node2Vec algorithm is used to perform node embedding on the control flow graph and the abstract syntax tree to obtain node embedding vectors; the global structure feature is obtained by splicing the node embedding vectors corresponding to the current sentence in the control flow graph and the abstract syntax tree.
7. The software defect localization method based on multi-flow model fusion according to claim 1, wherein, The defect positioning predictor includes three multilayer perceptrons and a Softmax layer, the first input feature is mapped into a one-dimensional vector through the first multilayer perceptron, the second input feature is mapped into a one-dimensional vector through the second multilayer perceptron, the two one-dimensional vectors are fused into a matrix through matrix multiplication, and then mapped into a one-dimensional vector through the third multilayer perceptron and the Softmax layer, and the suspicious score is output; the defect positioning predictor is supervised learning with the minimum batch hinge loss as the target. 8.A software defect locating system based on multi-flow model fusion, characterized in that, It comprises: a program input module for user to input the software program to be detected; a defect positioning module for obtaining the defect sentence positioning result in the software program to be detected according to the software defect positioning method based on multi-flow model fusion according to any one of claims 1-7; a result output module for outputting the defect sentence positioning result in the software program to be detected according to a preset output mode.
9. A computer program product comprising computer programs / instructions, characterized in that, The computer program / instruction is executed by the processor to realize the software defect positioning method based on multi-flow model fusion according to any one of claims 1-7.
10. A computer electronic device, comprising: It comprises a memory and a processor; The memory is used to store a computer program; The processor is used to realize the software defect positioning method based on multi-flow model fusion according to any one of claims 1-7 when executing the computer program.
Citation Information
Patent Citations
Incremental defect positioning method based on frequency spectrum
CN105975388A
Multi-defect positioning method, system and equipment based on two-dimensional program spectrum
CN115185814A
Software error positioning method based on error propagation modeling and defect feature enhancement
CN115617650A
Defect positioning technology based on positioning keyword extraction
CN118114098A
Cited By
Avionics system defect positioning system based on code semantic analysis
CN121958136A