A software defect positioning method and system based on multi-flow model fusion

By combining test case reduction and weighting strategies with multiple feature fusion methods, the problem of insufficient utilization of test cases in existing software defect localization methods is solved, achieving more efficient and accurate defect localization.

CN121029619BActive Publication Date: 2026-02-13HANGZHOU DIANZI UNIVERSITY BINJIANG INSTITUTE CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511526964.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-24
Publication Date
2026-02-13
Estimated Expiration
2045-10-24

AI Technical Summary

Technical Problem

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.

Method used

A test case reduction strategy is adopted to filter out high-coverage test cases. The remaining test cases are weighted using a test case weighting strategy. Combining spectral features, variation features, local semantic features, and global structural features, the code statement context is learned through a neural network model. Finally, the four features are fused and input into a multilayer perceptron for defect localization.

Benefits of technology

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.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121029619B_ABST
    Figure CN121029619B_ABST
Patent Text Reader

Abstract

The application discloses a software defect positioning method and system based on multi-flow model fusion. The method first filters out test cases with high coverage by using a test case reduction strategy, and weights the remaining test cases by using a test case weighting strategy to reflect their ability to reveal defects. Then, frequency spectrum features and variation features, local semantic features and global structure features are extracted, wherein the frequency spectrum features and the variation features are calculated by a weighted suspiciousness formula, and the local semantic features and the global structure features are obtained by a deep learning technology. Finally, the four types of features are fused and input into a defect positioning predictor trained by a multi-layer perception machine to obtain a suspiciousness score of each code statement, so that the suspected defect statements are screened out by taking the suspiciousness score as a positive correlation index of the defect statements, and software defect positioning is realized. The application can effectively reveal the code defect mode, thereby improving the accuracy of software defect positioning.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the field of software maintenance, and particularly relates to a software defect positioning method and system based on multi-flow model fusion. BACKGROUND

[0002] Software development is essentially a complex engineering activity. Due to unclear requirements, tight development cycles, or insufficient testing, software defects are almost inevitable. These defects not only may lead to functional errors, but also may become entry points for attackers, thereby threatening the overall security of the software. In order to improve the stability and security of software systems, defect positioning has become a key task in software engineering. The core goal of defect positioning is to quickly and accurately identify the specific code location that causes faults or abnormal behaviors. However, with the continuous increase in the size and complexity of modern software, traditional methods that rely on manual debugging and experience analysis are inefficient and difficult to adapt to the debugging needs of large-scale systems. Therefore, how to use automated means to improve the accuracy and efficiency of defect positioning has become an important research direction in the field 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 methods (spectrum-based fault localization, SBFL), mutation-based methods (mutation-based fault localization, MBFL), and learning-based methods (learning-based fault localization, LBFL). In software fault localization, test cases (Test Case) play a crucial role. Whether it is coverage-based methods (such as SBFL and MBFL) or learning-based methods, they rely on information related to test cases to locate defects. Therefore, the quality and distribution of test cases directly affect the performance of defect localization models. However, most existing researches treat all test cases as equally important, without fully exploring their differences in contribution to defect localization. In fact, some test cases may be very helpful for defect localization, while others may introduce noise or redundant information. Therefore, effectively identifying and utilizing high-value test cases has become an important direction to improve the performance of defect localization. SUMMARY

[0004] The purpose of the present application is to provide a software defect location method and system based on multi-flow model fusion to solve the above-mentioned challenges in the prior art in the problem of defect location. The present application proposes a new test case reduction strategy and a new test case weighting strategy to reduce the cost of mutation testing and effectively reflect the ability of different test cases to expose defects. In addition, by combining four different types of features, the representation ability of the code statements can be effectively enhanced, thereby achieving better defect location effect.

[0005] The specific technical solutions adopted by the present application are as follows:

[0006] In a first aspect, the present application provides a software defect location method based on multi-flow model fusion, comprising:

[0007] S1, execute all test cases for the software program to be detected, and record the coverage of each test case for each statement; at the same time, based on the execution results of all test cases respectively, the test cases whose actual execution results are inconsistent with the expected results are classified into a failed test case set, and the remaining test cases are classified into a passed test case set;

[0008] S2, reduce the passed test case set, delete the test cases whose statement coverage is greater than the average statement coverage, 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 inverse of the natural logarithm of the statement coverage number as the weight;

[0009] S3, for each statement covered by the failed test case in the software program to be detected, calculate the frequency spectrum feature and the mutation feature of each statement based on the suspicious degree calculation formula defined by the weight, learn the context where the statement is located through a neural network model to obtain the local semantic feature of each statement, and obtain the global structure feature of each statement by representing the abstract syntax tree and the control flow graph of each statement respectively and then fusing them;

[0010] 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 the first input feature, splice the local semantic feature and the global structure feature as the second input feature, input into a pre-trained defect location predictor, map the two input features into one-dimensional vectors respectively, then perform matrix multiplication to obtain a fusion matrix, map the fusion matrix into a one-dimensional vector again, and then perform Softmax normalization to obtain the suspicious degree score of each statement; finally, use the suspicious degree score as the positive correlation index of the defect statement to screen out the suspected defect statement, and realize software defect location.

[0011] As a preferred embodiment of the first aspect, the spectrum feature of each statement includes three features, which are normalized weighted Ochiai suspiciousness value, weighted Tarantula suspiciousness value and weighted DStar suspiciousness value respectively.

[0012] The weighted Ochiai suspiciousness value is obtained by dividing the first numerator by the first denominator.

[0013] The first numerator is the sum of the weights of all the failed test cases covering the current statement.

[0014] The first denominator is the arithmetic square root of the product of the sum of the weights of all the test cases in the failed test case set and the sum of the weights of all the test cases covering the current statement in the reduced test case set.

[0015] The weighted Tarantula suspiciousness value is obtained by dividing the second numerator by the second denominator.

[0016] The second numerator is the sum of the weights of all the failed test cases covering the current statement divided by the sum of the weights of all the test cases in the failed test case set.

[0017] The second denominator is obtained by summing the first sub-item and the second sub-item, wherein the first sub-item 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-item 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.

[0018] The weighted DStar suspiciousness value is obtained by dividing the third numerator by the third denominator.

[0019] The third numerator is obtained by performing power operation on the sum of the weights of all the failed test cases covering the current statement.

[0020] The third denominator 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.

[0021] As a preferred embodiment of the first aspect, the variation feature of each statement is extracted in the following manner:

[0022] A variation test tool is used to generate different variants of the software program to be detected, and each variant corresponds to a syntax modification of a statement.

[0023] Then the suspiciousness score of each mutant in the mutant set of the current statement is calculated, which is obtained by dividing a fourth numerator by a fourth denominator, the fourth numerator is the sum of the weights of all test cases in the failed test case set covering the current statement after executing the current mutant, and the fourth denominator is the arithmetic square root of the product of a third sub-item and a fourth sub-item, the third sub-item is the sum of the weights of all test cases in the test case set covering the current statement after executing the current mutant, and the fourth sub-item is the sum of the weights of all test cases in the failed test case set after executing the current mutant;

[0024] Finally, the maximum suspiciousness score of all mutants in the mutant set is taken as the weighted MBFL suspiciousness value, and after normalization operation, the mutation feature of the current statement is obtained.

[0025] As a preferred embodiment of the first aspect, the same normalization operation is used to convert each of the weighted Ochiai suspiciousness value, the weighted Tarantula suspiciousness value, the weighted DStar suspiciousness value and the weighted MBFL suspiciousness value into a feature value, and the specific conversion method is as follows: for the current normalized suspiciousness value category, the suspiciousness values of all statements of this 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 the feature value of this statement after normalization operation is obtained by subtracting the ratio from 1.

[0026] As a preferred embodiment of the first aspect, the local semantic feature extraction method 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 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;

[0028] The trunk network and the encoder need to be pre-cascaded with a decoder for training; during training, the context code block is first input into the trunk network, and then converted into an embedding vector by an embedding layer and input into a Bi-LSTM model to obtain hidden layer output, and then the hidden layer output is dimensionally compressed by a multilayer perceptron-based encoder to obtain the local semantic feature of the current statement, and finally the local semantic feature is reconstructed to the same dimension as the hidden layer output by a multilayer perceptron-based decoder to calculate the reconstruction loss, and the parameters of the cascaded model are optimized by minimizing the reconstruction loss.

[0029] As a preferred embodiment of the first aspect, the global structure feature extraction method of each statement is as follows:

[0030] First, the control flow graph (CFG) and the abstract syntax tree (AST) of the method where the current statement e is located are generated, and then the node embedding vectors of the control flow graph (CFG) and the abstract syntax tree (AST) are obtained by using the Node2Vec algorithm, and the global structure features are obtained by splicing the node embedding vectors corresponding to the current statement in the control flow graph and the abstract syntax tree.

[0031] As a preferred embodiment of the first aspect, the defect location predictor comprises three multilayer perceptrons and a Softmax layer, the first input feature is mapped into a one-dimensional vector by the first multilayer perceptron, the second input feature is mapped into a one-dimensional vector by the second multilayer perceptron, the two one-dimensional vectors are fused into a matrix by matrix multiplication, and then the matrix is mapped into a one-dimensional vector by the third multilayer perceptron and output by the Softmax layer, and the defect location predictor is pre-trained by supervised learning with the goal of minimizing the batch hinge loss.

[0032] In a second aspect, the present application provides a software defect location system based on multi-flow model fusion, comprising:

[0033] A program input module is configured to receive a software program to be detected from a user;

[0034] A defect location module is configured to locate a defect statement in the software program to be detected according to the software defect location method based on multi-flow model fusion according to any one of the first aspect;

[0035] A result output module is configured to output the defect statement in the software program to be detected according to a preset output mode.

[0036] In a third aspect, the present application provides a computer program product comprising computer programs / instructions, which, when executed by a processor, can implement the software defect location method based on multi-flow model fusion according to any one of the first aspect.

[0037] In a fourth aspect, the present application provides a computer electronic device comprising a memory and a processor;

[0038] The memory is configured to store computer programs;

[0039] The processor is configured to implement the software defect location method based on multi-flow model fusion according to any one of the first aspect when the computer programs are executed.

[0040] Compared with the prior art, the present application has the following beneficial effects:

[0041] The application is based on information entropy theory, and proposes a test case reduction strategy and a test case weighting strategy, which not only effectively reduces the time cost of mutation testing, but also effectively reflects the ability of different test cases to expose defects; the suspiciousness calculation formula is redefined through the weight of the test case, the discriminative spectral features and mutation features are obtained; the local semantic features are obtained by designing a new neural network model to learn the context of the code statement; the global structural features of the code statement are obtained by respectively representing and fusing the abstract syntax tree and the control flow graph. The application obtains more expressive representation vectors by fusing four different types of features, which can effectively improve the defect positioning accuracy of the model. BRIEF DESCRIPTION OF DRAWINGS

[0042] Figure 1 A flow chart of steps of the software defect positioning method based on multi-flow model fusion;

[0043] Figure 2 A process schematic diagram of extracting four different types of features of the target statement;

[0044] Figure 3 An encoder-decoder model training framework schematic diagram designed for extracting code semantic features;

[0045] Figure 4 A module composition schematic diagram of the software defect positioning system based on multi-flow model fusion;

[0046] Figure 5 A structural schematic diagram of a computer electronic device. DETAILED DESCRIPTION

[0047] In order to make the above-mentioned purposes, features and advantages of the application more obvious and easy to understand, the specific embodiments of the application will be described in detail below with reference to the drawings. In the following description, a large number of specific details are set forth in order to facilitate a full understanding of the application. However, the application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without departing from the spirit of the application, so the application is not limited by the specific embodiments disclosed below. The technical features in each embodiment of the application can be combined accordingly without conflict.

[0048] In the description of the application, it should be understood that the terms "first" and "second" are only used for distinguishing purposes of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features limited by "first" and "second" can explicitly or implicitly include at least one of the features.

[0049] In software development and maintenance, software defect localization plays a crucial role in ensuring software quality. Existing defect localization methods mostly rely on test case execution information or coverage relationship, but they usually implicitly assume that all test cases have the same defect revealing ability, which can lead to the underutilization of test case potential. Inspired by this, the present application provides a software defect localization method based on multi-flow model fusion. In this method, first, a test case reduction strategy is used to filter out high-coverage passing test cases to reduce the cost of mutation testing, and a test case weighting strategy is used to weight the remaining test cases to reflect their defect revealing ability. Then, four types of features are extracted, including spectral features, mutation features, local semantic features and global structure features. Among them, spectral features and mutation features are calculated through a weighted suspiciousness formula, while local semantic features and global structure features are obtained through deep learning technology. Finally, the four types of features are fused and input into a defect localization predictor trained based on a multi-layer perceptron (MLP) to locate defect statements.

[0050] As shown in Figure 1 , in a preferred embodiment of the present application, a software defect localization method based on multi-flow model fusion is provided, and the specific steps are shown as S1-S4.

[0051] S1, execute all test cases for the software program to be detected, and record the coverage of each test case for each statement; at the same time, based on the execution results of all test cases respectively, the test cases whose actual execution results are inconsistent with the expected results are classified into a failed test case set (denoted as ), and the remaining test cases are classified into a passing test case set (denoted as ).

[0052] It should be noted that the statement in the present application refers to the code statement in the software program to be detected. For different software programs to be detected, the test cases to be executed can be selected according to actual needs, and the specific test method belongs to the conventional technology in software engineering, which can not be limited. The coverage of the above test cases for each statement can be recorded by a code coverage tool (such as Cobertura) when all test cases are executed, and the coverage of each test case for the code statement can be recorded in a set manner.

[0053] In the embodiments of the present application, the coverage of each test case on the code statements can be recorded by a code coverage tool to generate a coverage matrix; in the coverage matrix, the rows represent the test cases, the columns represent the code statements, and the matrix elements are Boolean values, 1 indicating that the test case of the row covers the statement of the column, and 0 indicating that the test case of the row does not cover the statement of the column. The total number of rows of the coverage matrix is equal to the total number of test cases, and the total number of columns is equal to the total number of code statements. Thus, the number of test cases covering different statements and the test case set covering any statement can be directly counted by the coverage matrix subsequently. Of course, the introduction of the coverage matrix is mainly to facilitate the subsequent statistics and set selection, but it is not the only way to record the coverage of each test case on each statement.

[0054] In addition, in the embodiments of the present application, the execution results of each test case are also recorded when all the test cases are executed, and then the test cases are divided into a passing test case set and a failing test case set . In order to avoid ambiguity, the meanings of passing and failing of the test cases are defined as follows: in the execution results of the test cases, passing indicates that the actual execution result of the test case is consistent with the expected result, and failing indicates that the actual execution result of the test case is not consistent with the expected result. Therefore, in the present application, the test cases whose actual execution results are not consistent with the expected results are classified into the failing test case set , and the remaining test cases are classified into the passing test case set . The passing test case set and the failing test case set are initially empty sets.

[0055] S2, the passing test case set is reduced, the test cases whose statement coverage numbers are greater than the average statement coverage number are deleted, and the remaining test cases and the failing test case set are combined to form a reduced test case set ; for each test case in the reduced test case set , the reciprocal of the natural logarithm of the statement coverage number thereof is calculated and used as a weight.

[0056] It should be noted that the core of the reduction of the passing test case set in the present application is to adopt a test case reduction strategy using the average statement coverage number as a filter to filter out the passing test cases with high coverage, so as to reduce the cost of mutation testing. The object of the reduction is only the passing test cases, and the failing test cases do not need to be reduced, and all the failing test cases are directly retained. Therefore, the average statement coverage number in the present application refers to the average value of the statement coverage numbers of all the test cases in the passing test case set.

[0057] In an embodiment of the present application, the specific reduced test case set The construction process is as follows:

[0058] First, for each test case in the test case set , the number of statement covers is calculated in combination with the coverage matrix; then, the average number of statement covers is calculated for all test cases in the test case set ; finally, the test cases in the test case set whose number of statement covers exceeds the average number of statement covers are deleted, while those whose number of statement covers does not exceed the average number of statement covers are retained in the reduced test case set , and the entire failed test case set is directly added to the reduced test case set . Thus, the test cases retained in the reduced test case set include all the failed test cases and the passed test cases whose number of statement covers is lower than the average number of statement covers.

[0059] For ease of description, the present application refers to the subset of the reduced test case set that covers a certain statement as .

[0060] In addition, it should be noted that the S2 step of the present application also needs to use a test case weighting strategy to weight the remaining test cases to reflect their ability to reveal defects. Specifically, for each test case in the reduced test case set , the natural logarithm of the number of statement covers is calculated, and then the reciprocal of the natural logarithm value is taken as the weight of the test case. In an embodiment of the present application, for each test case in the reduced test case set , the number of statement covers covered by the test case is defined as , and the weight of the test case is calculated according to the following formula:

[0061]

[0062] where log is the natural logarithm function.

[0063] It should be particularly noted that if a test case covers 0 statement, to avoid a zero divisor in the subsequent calculation process, the weight of the test case can be set to a near-zero value of a positive number. In an embodiment of the present application, the specific near-zero value can be set to .

[0064] S3, calculate the spectrum feature and the mutation feature of each statement based on the suspiciousness calculation formula defined by the weight, and learn the local semantic feature of each statement by using a neural network model to learn the context in which the statement is located, obtain the global structure feature of each statement by respectively representing the abstract syntax tree and the control flow graph of each statement and then fusing them.

[0065] It should be noted that the spectrum feature is a feature obtained by a spectrum-based fault localization (SBFL) method, which is also referred to as an SBFL feature hereinafter; and the mutation feature is a feature obtained by a mutation-based fault localization (MBFL) method, which is also referred to as an MBFL feature hereinafter.

[0066] The traditional SBFL features include three suspiciousness values of Ochiai, Tarantula and DStar, and the suspiciousness calculation formulas of the three are prior art. However, in the present application, the test cases are weighted by using the test case weighting strategy, and therefore, the suspiciousness calculation formulas of Ochiai, Tarantula and DStar need to be redefined based on the weight of the test case, and weighted Ochiai suspiciousness values, weighted Tarantula suspiciousness values and weighted DStar suspiciousness values are calculated. After normalization processing of the three weighted suspiciousness values, three weighted SBFL features are formed.

[0067] Therefore, in the embodiments of the present application, the spectrum feature, i.e., the SBFL feature, of each statement has three, which are obtained by normalization operation of the weighted Ochiai suspiciousness value, the weighted Tarantula suspiciousness value and the weighted DStar suspiciousness value. The suspiciousness calculation formulas of the weighted Ochiai suspiciousness value, the weighted Tarantula suspiciousness value and the weighted DStar suspiciousness value are based on the suspiciousness calculation formula defined by the weight. Meanwhile, the suspiciousness calculation formula of the mutation feature, i.e., the MBFL feature, is also based on the suspiciousness calculation formula defined by the weight. The process of extracting four different types of features of the target statement is shown in FIG. 1. Figure 2 The redefined suspiciousness calculation formulas will be described in detail as follows.

[0068] 1) The weighted Ochiai suspiciousness value is obtained by dividing the first numerator term by the first denominator term. The first numerator term is the sum of the weights of all the failed test cases (i.e., the set ) covering the current statement. The first denominator term is the sum of the weights of the failed test cases the sum of the weights of all test cases in the reduced test case set.

[0069] 2) The weighted Tarantula suspiciousness value is obtained by dividing the second numerator term by the second denominator term. The second numerator term is obtained by dividing the sum of the weights of all failing test cases (i.e., the set ) that cover the current statement by the sum of the weights of all test cases in the failing 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 failing test cases (i.e., the set ) that cover the current statement by the sum of the weights of all test cases in the failing test case set . The second sub-term is obtained by dividing the sum of the weights of all passing test cases (i.e., the set ) that cover the current statement by the sum of the weights of all test cases in the passing test case set .

[0070] 3) 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 to a power the sum of the weights of all failing test cases (i.e., the set ) that cover the current statement. The third denominator term is obtained by adding the sum of the weights of all test cases in the passing test case set that cover the current statement to the sum of the weights of all test cases in the failing test case set that do not cover the current statement.

[0071] The weighted Ochiai suspiciousness value , the weighted Tarantula suspiciousness value , and the weighted DStar suspiciousness value , described above, can be calculated using the following suspiciousness calculation formulas, respectively:

[0072]

[0073]

[0074]

[0075] wherein: and represent a failing test case and a passing test case, respectively, and represent a failing test case that covers statement and a passing test case that covers statement , respectively, and respectively represent the failed test case set covering the statements and the passed test case set covering the statements . is the reduced test case set covering the statements , is a test case contained in . is the passed test case set, it should be noted that since the successful test case set has been reduced in advance, the in the above formula represents the reduced successful test case set. is the weight of the test case , is the weight of the test case , and so on. The "*" represents a preset optional value, which is a power in the formula, and in the embodiment of the present application, the "*" is preferably set to 2. represents the test case set belonging to the set but not belonging to .

[0076] Thus, based on the above weight redefined suspiciousness calculation formula, the weighted Ochiai suspiciousness value , the weighted Tarantula suspiciousness value , and the weighted DStar suspiciousness value can be calculated for each statement.

[0077] Further, the weighted Ochiai suspiciousness value, the weighted Tarantula suspiciousness value, and the weighted DStar suspiciousness value of all statements are converted into SBFL characteristic values by normalization operation, and the specific conversion method is as follows:

[0078] For the current normalized suspiciousness value category, the suspiciousness values of all statements of this 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 the characteristic value of this statement after normalization operation is obtained by subtracting the ratio from 1.

[0079] The weighted Ochiai suspiciousness value , the weighted Tarantula suspiciousness value , and the weighted DStar suspiciousness value of any statement are normalized, and the SBFL characteristic value obtained By formula can be expressed as:

[0080]

[0081] Wherein is the sentence In all sentences in the descending order of weighted suspicious degree value (ranking number from 1~N), Is the total number of sentences in the software program to be detected. It should be noted that since the weighted suspicious degree value has three categories, it is necessary to rank in descending order by category, and then normalize within the category.

[0082] 4) The extraction method of the mutation feature of each sentence is as follows:

[0083] Use mutation test tool (such as Major) to generate different mutants of the software program to be detected, each mutant corresponds to a syntax modification of a sentence, and there may be multiple mutants for the same sentence.

[0084] Then calculate the suspicious degree score of each mutant in the mutant set of the current sentence, which 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 failed test case set that covers the current sentence after executing the current mutant, and the fourth denominator is the arithmetic square root of the product of the third item and the fourth item, the third item is the sum of the weights of all test cases in the test case set that covers the current sentence after executing the current mutant, and the fourth item is the sum of the weights of all test cases in the failed test case set after executing the current mutant.

[0085] Finally, take the maximum suspicious degree score of all mutants in the mutant set as the weighted MBFL suspicious degree value, and get the mutation feature of the current sentence after normalization operation.

[0086] In the embodiment of the application, if the mutation test tool is used to generate mutants of the software program to be detected, the statement e is modified, that is, the generated mutant is regarded as the mutant of the statement Therefore, for the mutant set of the statement The suspicious degree integral of the weighted MBFL suspicious degree value The calculation formula can be expressed as:

[0087]

[0088] Wherein Refers to a failed test case after executing the mutant Refers to a failed test case after executing the mutant​​​ The subsequent set of failed test cases, Refers to executing variants Post-overwrite statement A test case, This refers to the overwrite statement after executing the mutant. The set of test cases, Refers to executing 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 sentence , generate a context code block by code slicing, taking the sentence e as the center, and taking tokens before and after the center as the context, forming a context code block with a length of tokens, and using a special token to mark the context code block. <startfocus>"and" <endfocus>” label of the location;

[0095] 2. Design a new encoder-decoder model, including a backbone, an encoder and a decoder. In the embodiment of the present application, the backbone is composed of an Embedding layer and a Bi-LSTM network, and the encoder and the decoder each adopt a 2-layer MLP. The Embedding layer of the backbone converts each context code block of a sentence into a vector sequence, and then inputs the vector sequence into the Bi-LSTM network to obtain hidden layer output , wherein is the token number of the context code block, is the embedding dimension. Then the hidden layer output is compressed into a 4-dimensional vector by the encoder (2-layer MLP) as the semantic feature of the sentence ; and is restored to the decoder output with the same dimension size as by the decoder (2-layer MLP).

[0096] 3. Based on the decoder output and the hidden layer output of the encoder, the reconstruction loss MSE can be calculated, and the formula can be expressed as:

[0097]

[0098] The training target of the training framework of the above backbone, encoder and decoder is to minimize the above reconstruction loss , and after training, the decoder can be removed, and the corresponding backbone and encoder can be cascaded to extract the local semantic features of the context code blocks of the sentences.

[0099] In addition, in the embodiment of the present application, the global structure feature extraction method of each sentence is as follows:

[0100] First, the control flow graph (CFG) and the abstract syntax tree (AST) of the current sentence e are generated, and then the Node2Vec algorithm is used to perform node embedding on the control flow graph (CFG) and the abstract syntax tree (AST) to obtain node embedding vectors. The global structure feature of the sentence e is obtained by splicing the embedding vectors of the nodes corresponding to the sentence e in the control flow graph and the abstract syntax tree. In the embodiment, the embedding vector dimensions of CFG and AST are 2 respectively, so the final global structure feature is a 4-dimensional structure feature. ​

[0101] S4, for each statement covered by a failed test case in the software program to be detected, splicing the spectrum feature and the mutation feature to serve as a first input feature, splicing the local semantic feature and the global structure feature to serve as a second input feature, inputting into a pre-trained defect location predictor, mapping the two input features into one-dimensional vectors respectively and then performing matrix multiplication to obtain a fusion matrix, mapping the fusion matrix into a one-dimensional vector again and then performing Softmax normalization to obtain a suspicious degree score of each statement; finally, taking the suspicious degree score as a positive correlation index of a defect statement to screen out suspected defect statements, and realizing software defect location.

[0102] It should be noted that the mapping in the above defect location predictor can be realized by MLP, and the defect location predictor needs to be pre-trained before being actually used for inference. Therefore, the defect location predictor contains three multilayer perceptrons and a Softmax layer, the first input feature is mapped into a one-dimensional vector by the first multilayer perceptron, the second input feature is mapped into a one-dimensional vector by the second multilayer perceptron, the two one-dimensional vectors are fused into a fusion matrix by matrix multiplication, and then the fusion matrix is mapped into a one-dimensional vector by the third multilayer perceptron and is processed by the Softmax layer, and the suspicious degree score is output; and the defect location predictor is pre-trained to minimize the batch hinge loss for supervised learning.

[0103] Specifically, in the embodiments of the present application, the feature fusion input and the model training process in the above defect location predictor are as follows:

[0104] A) Splice the spectrum feature and the mutation feature into the first input feature , splice the local semantic feature and the global structure feature into the second input feature ;

[0105] B) For the first input feature , use one layer of MLP to map it into a vector , for the second input feature , use one layer of MLP to map it into a vector ;

[0106] C) The outputs of the two MLPs are fused into an 8x8 fusion matrix by matrix multiplication , and then the fusion matrix is converted into a one-dimensional output vector by another layer of MLP, and the one-dimensional output vector is normalized by Softmax to obtain the suspicious degree 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 the processor, and the steps S1-S4 can be executed.

[0125] It can be understood that the storage medium described above can include a random access memory (RAM) and a non-volatile memory (NVM), such as at least one disk memory. Meanwhile, the storage medium can also be a U disk, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0126] It can be understood that the processor described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0127] In addition, it should be noted that the skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system described above can refer to the corresponding process in the foregoing method embodiments, which will not be described here. In each embodiment provided in the present application, the division of steps or modules in the system and method is only a logical functional division, and actual implementation can have another division mode, for example, multiple modules or steps can be combined or integrated together, or a module or step can be split.

[0128] The present application will further demonstrate the detailed implementation process and technical effects of the software defect positioning method based on multi-flow model fusion shown in the steps S1-S4 on specific data sets through a specific embodiment, so as to facilitate the understanding of the technical effects of the present application.

[0129] Embodiment

[0130] The steps of this embodiment are the same as the software defect positioning method based on multi-flow model fusion shown in the foregoing S1-S4 steps, which will not be repeated here. The specific data set, part of the specific parameter setting and implementation results of this embodiment are mainly shown. In order to facilitate description, the method shown in S1-S4 steps is referred to as the method of the present application, wherein the defect positioning predictor used is referred to as WetFL.

[0131] Experimental data set: Defect4J (V1.2.0) dataset is an open source dataset widely used in software defect positioning research, which collects 395 real defects from 6 Java projects, including fault version code, repair version code, test cases and coverage information, and annotates the specific defect location. The dataset has the characteristics of multi-project, multi-version and real defect, which facilitates the evaluation of various defect positioning and automatic program repair methods and ensures the reproducibility of the experiment.

[0132] Evaluation index: Top1, Top3, Top5, MAR and MFR. The higher the values of Top1, Top3 and Top5 are, the better, and the lower the values of MAR and MFR are, the better.

[0133] The specific experimental results of this embodiment are as follows:

[0134] (1) Algorithm comparison results

[0135] Table 1 Comparison results of the present application and other algorithms on Defect4J dataset

[0136]

[0137] Table 1 is the comparison of software defect positioning results of the present application and other comparative methods on Defect4J dataset. From the summary results in Table 1, it can be seen that the present application has obvious advantages over other comparative methods.

[0138] (2) Ablation experiment results

[0139] Table 2 Influence of key components

[0140]

[0141] In Table 2, w / o weighting strategy represents removing the weighting strategy, and the SBFL feature and the MBFL feature are directly calculated by using the conventional suspiciousness calculation formula. w / o simplification strategy represents that the test case set is not simplified. w / o weighting strategy & simplification strategy represents that the weighting strategy is removed and the test case set is not simplified. w / o batch hinge loss function represents replacing the batch hinge loss function of the training defect positioning predictor with the conventional hinge loss function.

[0142] As can be seen from the results in Table 2, removing any one component results in a decrease in the performance of WetFL, with the removal of the weighting strategy resulting in a large decrease in performance and the removal of the batch hinge loss function resulting in a smaller decrease in performance.

[0143] Table 3 Effects of four types of features

[0144]

[0145] As can be seen from the results in Table 3, removing any one type of feature results in a decrease in the performance of WetFL, with the removal of the SBFL features resulting in a large decrease in performance and the removal of the MBFL features resulting in a smaller decrease in performance. In addition, as can be seen from the results, semantic features and structural features have a similar effect on the improvement in the performance of WetFL.

[0146] Table 4 Comparative experiments with other weighting strategies

[0147]

[0148] As can be seen from the results in Table 4, the results of the test case weighting strategy proposed in the present application are significantly better than the results of the Proximity, WTC and BWSBFL test case weighting strategies.

[0149] Table 5 Comparative experiments with other reduction strategies

[0150]

[0151] As can be seen from the results in Table 5, the results of the test case reduction strategy proposed in the present application are significantly better than the results of the Proximity, WTC and BWSBFL test case reduction strategies.

[0152] The above-described embodiments are only some of the preferred implementation schemes of the present application, but are not intended to limit the present application. Those of ordinary skill in the relevant art can make various changes and modifications without departing from the spirit and scope of the present application. Therefore, any technical scheme obtained by equivalent replacement or equivalent transformation falls within the scope of the present application.< / endfocus> < / startfocus>

Claims

1. A software defect localization method based on multi-flow model fusion, characterized in that, include: S1. Execute all test cases for the software program to be tested and record the coverage of each code 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. 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. 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. S4. For each statement in the software program to be tested that is covered by a failed test case, the spectral feature and the mutation feature are concatenated as the first input feature, and the local semantic feature and the global structural feature 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 indicator for defective statements to filter out suspected defective statements, thereby achieving software defect localization.

2. The software defect localization method based on multi-flow model fusion as described in claim 1, characterized in that, 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. The weighted Ochiai skepticism value is obtained by dividing the first numerator and the first denominator. The first numerator is the sum of the weights of all failed test cases covering the current statement; 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. The weighted Tarantula skepticism value is obtained by dividing the second numerator term by the second denominator term; 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; 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. The weighted DStar skepticism value is obtained by dividing the third numerator and the third denominator. The third numerator is obtained by exponentiation of the sum of the weights of all failed test cases covering the current statement; 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.

3. The software defect localization method based on multi-flow model fusion as described in claim 2, characterized in that, The method for extracting the variation features of each statement is as follows: 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. 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. 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.

4. The software defect localization method based on multi-flow model fusion as described in claim 3, characterized in that, Each of the weighted Ochiai doubt value, weighted Tarantula doubt value, weighted DStar doubt value, and weighted MBFL doubt value categories is converted into feature values ​​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.

5. The software defect localization method based on multi-flow model fusion as described in claim 1, characterized in that, The method for extracting local semantic features of each statement is as follows: 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; 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.

6. The software defect localization method based on multi-flow model fusion as described in claim 1, characterized in that, The method for extracting the global structural features of each statement is as follows: First, generate the control flow graph and abstract syntax tree of the method containing the current statement. Then, use the Node2Vec algorithm to embed nodes in the control flow graph and abstract syntax tree to obtain node embedding vectors. Finally, 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.

7. The software defect localization method based on multi-flow model fusion as described in claim 1, characterized in that, 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. The defect localization predictor is pre-supervised learning with the goal of minimizing the batch hinge loss.

8. A software defect localization system based on multi-flow model fusion, characterized in that, include: The program input module is used for users to input the software program to be tested; 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 one of claims 1 to 7. 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.

9. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it can implement the software defect localization method based on multi-flow model fusion as described in any one of claims 1 to 7.

10. A computer electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; 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 one of claims 1 to 7.

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