Software defect prediction method, electronic equipment and storage medium

By predicting software defects based on the target function, using abstract syntax trees and recurrent neural networks to automatically predict code defects and software defects, the problem of low efficiency and accuracy in the existing methods is solved, and prediction efficiency and accuracy are improved.

CN120448276APending Publication Date: 2025-08-08AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510647275.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-20
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

Existing software defect prediction methods rely on manual design statistical measurements, resulting in low prediction efficiency and accuracy, making it difficult to ensure prediction efficiency while taking into account prediction accuracy.

Method used

By obtaining the source code of the software to be predicted and its target functions, determining the target code associated with the target functions, and making defect predictions based on the target functions, using abstract syntax trees and recurrent neural networks to automatically achieve the prediction of code defects and software defects.

Benefits of technology

It improves the efficiency and accuracy of software defect prediction, can realize automated software defect prediction without manual design, and helps to reasonably allocate testing resources and improve testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448276A_ABST
    Figure CN120448276A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a software defect prediction method, electronic equipment and a storage medium. The method comprises the steps that source codes of to-be-predicted software and target functions corresponding to the to-be-predicted software are obtained, and the target functions are functions required to be possessed by the to-be-predicted software; determining a target code associated with the target function from the source code, and performing defect prediction on the target code according to the target function to obtain a code defect condition; and predicting the software defect condition of the to-be-predicted software according to the code defect condition. According to the technical scheme provided by the embodiment of the invention, the software defect prediction efficiency and precision are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a software defect prediction method, electronic equipment, and storage medium. Background Art

[0002] With the continuous advancement of social informatization, various types of software are widely used in all walks of life. Software requirements can be quickly developed and put into use as soon as possible. Software defect prediction is a method to discover code defects during the software development process.

[0003] Statistical metrics are standards or indicators used to measure and evaluate various attributes and characteristics in the software development and maintenance process. Current software defect prediction is based on statistical metrics.

[0004] However, statistical measurement requires human participation. Therefore, the use of statistical measurement for software defect detection will be affected by human factors, resulting in low prediction efficiency and accuracy, which needs to be solved urgently. Summary of the Invention

[0005] The embodiments of the present invention provide a software defect prediction method, an electronic device, and a storage medium, which improve the efficiency and accuracy of software defect prediction.

[0006] According to one aspect of the present invention, a software defect prediction method is provided, which may include:

[0007] Obtaining the source code of the software to be predicted and the target function corresponding to the software to be predicted, wherein the target function is the function that the software to be predicted is required to have;

[0008] Determine the target code associated with the target function from the source code, and perform defect prediction on the target code based on the target function to obtain the code defect situation;

[0009] According to the code defect situation, the software defect situation of the software to be predicted is predicted.

[0010] According to another aspect of the present invention, an electronic device is provided, which may include:

[0011] at least one processor; and

[0012] a memory communicatively connected to at least one processor; wherein,

[0013] The memory stores a computer program that can be executed by at least one processor. The computer program is executed by the at least one processor so that the at least one processor implements the software defect prediction method provided by any embodiment of the present invention when executing the computer program.

[0014] According to another aspect of the present invention, a computer-readable storage medium is provided, on which computer instructions are stored. The computer instructions are used to enable a processor to implement the software defect prediction method provided by any embodiment of the present invention when executed.

[0015] The technical solution of the embodiment of the present invention obtains the source code of the software to be predicted and the target function corresponding to the software to be predicted, wherein the target function is the function that the software to be predicted is required to have. Then, from the source code, the target code associated with the target function is determined, and based on the target function, the target code is defect predicted to obtain the code defect situation. Based on the target function, the target code can be defect-checked to achieve the participation of the target function in software defect prediction. Finally, based on the code defect situation, the software defect situation of the software to be predicted is predicted to achieve defect prediction of the software to be predicted. The above technical solution, by performing software defect prediction based on the target function, can realize automatic software defect prediction without manually designing statistical metrics, thereby improving the efficiency and accuracy of software defect prediction.

[0016] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0018] Figure 1 is a flowchart of a software defect prediction method provided according to an embodiment of the present invention;

[0019] Figure 2 is a flowchart of another software defect prediction method provided by an embodiment of the present invention;

[0020] Figure 3 is a schematic diagram of an abstract syntax tree in another software defect prediction method provided according to an embodiment of the present invention;

[0021] Figure 4 is a flowchart of another software defect prediction method provided according to an embodiment of the present invention;

[0022] Figure 5 is a schematic diagram of a first recurrent neural network in another software defect prediction method provided according to an embodiment of the present invention;

[0023] Figure 6 This is a flowchart of an optional example of another software defect prediction method provided by an embodiment of the present invention;

[0024] Figure 7 This is a structural block diagram of a software defect prediction device provided according to an embodiment of the present invention;

[0025] Figure 8 It is a structural diagram of an electronic device for implementing the software defect prediction method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0027] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. The situations of "target", "original", etc. are similar and will not be repeated here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or that are inherent to these processes, methods, products or devices.

[0028] Before introducing the embodiments of the present invention, an exemplary explanation is given of the implementation process of the current solution for software defect prediction and the reasons why the problem of low prediction efficiency and accuracy occurs, so as to better understand why the solution proposed in the embodiments of the present invention can improve the efficiency and accuracy of software defect prediction.

[0029] Statistical metrics are standards or indicators used to measure and evaluate various attributes and characteristics in the software development and maintenance process. The metrics in statistical metrics can provide quantitative information on software quality, development efficiency, and code complexity. For example, common metrics include lines of code (LOC) and cyclomatic complexity. The quantitative information provided by metrics can provide a basis for software defect detection. Therefore, most existing software defect prediction methods are based on statistical metrics. However, statistical metrics require manual design and construction. The design and construction of statistical metrics for each code file in the source code takes a lot of time, so the construction cycle is long and the prediction effect is low due to manual influence. Although a small number of software defect prediction methods are constructed based on code semantic information, eliminating the tedious feature construction process in statistical metrics, their semantic information acquisition is not comprehensive, resulting in low prediction accuracy. In summary, the prediction accuracy of the above two software defect prediction methods is low, especially it is difficult to ensure prediction efficiency while taking into account prediction accuracy.

[0030] To address this, embodiments of the present invention perform software defect prediction based on target functions, enabling automatic software defect prediction without manually designing statistical metrics, thereby improving the efficiency and accuracy of software defect prediction. This will be explained in detail below.

[0031] Figure 1 This is a flowchart of a software defect prediction method provided in an embodiment of the present invention. This embodiment is applicable to software defect prediction scenarios. The method can be performed by a software defect prediction device provided in an embodiment of the present invention. This device can be implemented in software and / or hardware and can be integrated into an electronic device, such as various user terminals or servers.

[0032] See also Figure 1 The method of the embodiment of the present invention specifically includes the following steps:

[0033] S110 , obtaining source code of the software to be predicted and target functions corresponding to the software to be predicted, wherein the target functions are functions that the software to be predicted is required to have.

[0034] The software to be predicted can be understood as software to be defect-predicted.

[0035] Source code can be understood as code that can be compiled or interpreted to generate the software to be predicted.

[0036] The target function can be understood as the function that the software to be predicted needs to have; the number of target functions can be at least one.

[0037] In the embodiment of the present invention, source code and target functions may be acquired.

[0038] S120 , determining target codes associated with the target function from the source code, and performing defect prediction on the target code according to the target function to obtain code defect status.

[0039] Among them, the target code is the code associated with the target function in the source code, and can also be understood as the code involved in realizing the target function; the number of target codes can be one or more; the target code can be embodied in the granularity of code files, that is, each target code can be a code file.

[0040] In the embodiment of the present invention, the target code can be determined from the source code through the target function.

[0041] The code defect situation can be understood as a situation that characterizes whether the target code has defects; the code defect situation can, for example, include at least one of whether the target code has defects, the location of the defects, the type of defects, and the severity of the defects.

[0042] In an embodiment of the present invention, the target code is used as the prediction granularity, that is, according to the target function, the target code is predicted to obtain the code defect situation. For example, the target code can be converted into code semantic information, and the target function can be converted into functional semantic information. According to the code semantic information and the functional semantic information, the target code is predicted to obtain the code defect situation.

[0043] S130: Predicting software defect conditions of the software to be predicted based on the code defect conditions.

[0044] Among them, the software defect situation can be understood as a situation that characterizes whether the target software has defects; the software defect situation can, for example, include at least one of whether the software has defects, the location of the defects in the source code and / or the corresponding target code, the type of defects, and the importance of the defects, etc.

[0045] In an embodiment of the present invention, the software defect situation of the software to be predicted can be predicted based on the code defect situation. For example, the code defect situation can be used as the predicted software defect situation; for another example, the code defect situation and the defect situation obtained by other software prediction methods such as statistical measurement can be used as the predicted software defect situation; and so on.

[0046] In an embodiment of the present invention, by predicting defects in the target code according to the target function, and then predicting the software defect situation based on the code defect situation, in addition to improving the efficiency and accuracy of software defect prediction, the actual functional requirements of the software to be predicted can be taken into account, so that the software defect situation can reflect the functional defects of the software, thereby improving the comprehensiveness of software defect prediction.

[0047] It should be noted that in the development process of software projects, software testing work occupies a lot of manpower and material resources. How to compress software testing time and reasonably allocate testing resources is the key to speeding up the progress of software development. In order to speed up the progress of software development, various automated testing tools are currently being used, such as by writing automated test scripts to save a lot of human resources. However, for large software systems, even using automated testing tools to write scripts for all functions for testing is very time-consuming. According to statistics, 80% of software defects are often concentrated in 20% of the code. Therefore, how to find the test focus and test the code with emphasis is the key to improving software testing efficiency. On this basis, based on the function-targeted software defect prediction of the embodiment of the present invention, the test focus test scope can be indicated to the tester to improve the testing efficiency. Specifically, after predicting the software defect situation of the software to be predicted, the target function corresponding to the target code of the defect characterized by the software defect situation can be tested in a focused manner, thereby reducing the testing workload and helping to reasonably allocate testing resources.

[0048] The technical solution of the embodiment of the present invention obtains the source code of the software to be predicted and the target function corresponding to the software to be predicted, wherein the target function is the function that the software to be predicted is required to have. Then, from the source code, the target code associated with the target function is determined, and based on the target function, the target code is defect predicted to obtain the code defect situation. Based on the target function, the target code can be defect-checked to achieve the participation of the target function in software defect prediction. Finally, based on the code defect situation, the software defect situation of the software to be predicted is predicted to achieve defect prediction of the software to be predicted. The above technical solution, by performing software defect prediction based on the target function, can realize automatic software defect prediction without manually designing statistical metrics, thereby improving the efficiency and accuracy of software defect prediction.

[0049] An optional technical solution obtains target functions corresponding to the software to be predicted, including: obtaining each target function of the software to be predicted corresponding to the software to be predicted; determining the target code associated with the target function from the source code, including: for each target function, determining the target code associated with the target function from the source code; predicting the software defect situation of the software to be predicted based on the code defect situation, including: predicting the software defect situation of the software to be predicted based on the code defect situation corresponding to each target function.

[0050] In the embodiment of the present invention, each target function corresponding to the software to be predicted may be acquired.

[0051] In an embodiment of the present invention, in addition to determining the target code associated with each target function from the source code, the source code may be classified according to each target function to obtain the target code corresponding to each target function. It should be noted that each target function may correspond to the same target code.

[0052] In an embodiment of the present invention, the software defect situation is predicted based on the code defect situation corresponding to each target function. For example, the code defect situation corresponding to each target function can be used as the predicted software defect situation.

[0053] In an embodiment of the present invention, for each target function, at least one target code associated with the target function can be determined from the source code; for each target code, defects can be predicted for the target code according to the target function to obtain the code defect situation of the target code; and the software defect situation can be predicted based on the code defect situation corresponding to each target code corresponding to each target function.

[0054] In the embodiment of the present invention, each target function is obtained to predict the software defect situation according to the code defect situation corresponding to each target function, which can improve the comprehensiveness of the software defect situation.

[0055] An optional technical solution, the number of target codes is at least one; based on the target function, defects are predicted for the target code to obtain code defect conditions, including: for each target code, based on the target function, defects are predicted for the target code to obtain code defect conditions; based on the code defect conditions, software defect conditions of the software to be predicted are predicted, including: based on the code defect conditions corresponding to each target code, software defect conditions of the software to be predicted are predicted.

[0056] In an embodiment of the present invention, for each target code in at least one target code, defect prediction can be performed on the target code according to the target function to obtain the code defect situation, and then the software defect situation can be predicted according to the code defect situation corresponding to each target code, which can improve the comprehensiveness of the software defect situation.

[0057] Figure 2 This is a flowchart of another software defect prediction method provided in an embodiment of the present invention. This embodiment is optimized based on the above-mentioned technical solutions. In this embodiment, optionally, based on the target function, defect prediction is performed on the target code to obtain code defect conditions, including: determining the abstract syntax tree of the target code and traversing the abstract syntax tree to obtain the word sequence of the target code; based on the target function and the word sequence, defect prediction is performed on the target code to obtain code defect conditions. Among them, the explanations of the same or corresponding terms as those in the above-mentioned embodiments are not repeated here.

[0058] See also Figure 2 The method of this embodiment may specifically include the following steps:

[0059] S210 , obtaining source code of the software to be predicted and target functions corresponding to the software to be predicted, wherein the target functions are functions that the software to be predicted is required to have.

[0060] S220. Determine the target code associated with the target function from the source code.

[0061] S230: Determine an abstract syntax tree of the target code, and traverse the abstract syntax tree to obtain a word sequence of the target code.

[0062] The Abstract Syntax Tree (AST) is an abstract representation of the syntax structure of the target code. Figure 3 The abstract syntax tree of a target code is a tree structure that can be used to represent the syntax hierarchy and structure of the target code. It can ignore the details of the specific syntax and only focus on the basic structure and relationship of the syntax.

[0063] A token sequence can be understood as a sequence of basic units in the target code; a token sequence can also be understood as a node sequence, that is, the tokens in the token sequence can be the node names of nodes in the abstract syntax tree.

[0064] In an embodiment of the present invention, the abstract syntax tree of the target code may be determined, for example, by using a compilation tool.

[0065] In an embodiment of the present invention, the abstract syntax tree may be traversed to obtain a word-gram sequence. For example, the abstract syntax tree may be traversed and a sequence consisting of node names of the tree nodes obtained through the traversal may be used as a word-gram sequence.

[0066] S240: Based on the target function and word sequence, defect prediction is performed on the target code to obtain code defect status.

[0067] In an embodiment of the present invention, defects in the target code can be predicted based on the target function and word sequence to obtain the code defect situation.

[0068] S250: Predicting software defect conditions of the software to be predicted based on the code defect conditions.

[0069] The technical solution of the embodiment of the present invention determines the abstract syntax tree of the target code, traverses the abstract syntax tree to obtain a word sequence, and predicts defects in the target code based on the target function and the word sequence to obtain the code defect situation, which can make the code information in the word sequence more comprehensive, thereby improving the accuracy of the target code defect prediction.

[0070] An optional technical solution is provided for traversing an abstract syntax tree to obtain a word sequence of a target code, including: initializing the word sequence of the target code; using the root node of the abstract syntax tree as the traversal entry and recursively traversing the abstract syntax tree; for each tree node in the traversed abstract syntax tree, adding a preset start identifier to the node name of the tree node, adding the node name with the added start identifier to the word sequence, and when the tree node is a fallback node, adding a preset end identifier to the node name of the tree node, adding the node name with the added end identifier to the word sequence, wherein the target code includes the node name; when the traversal of the abstract syntax tree is completed, a word sequence is obtained.

[0071] In the embodiment of the present invention, the word sequence may be initialized, for example, the word sequence may be initialized to be empty.

[0072] The root node can be understood as the root node of the abstract syntax tree.

[0073] In an embodiment of the present invention, the root node can be used as the traversal entry and the abstract syntax tree can be traversed recursively. The recursive traversal of the abstract syntax tree can specifically include accessing the left node of the current tree node traversed. If the left node is empty, the child nodes of the current tree node are accessed to the right, for example, the right node of the current tree node is accessed.

[0074] A tree node can be understood as a node in an abstract syntax tree.

[0075] The start identifier can be understood as a preset identifier that indicates the location in the target code where the execution of the code begins.

[0076] The node name can be understood as the name of a tree node; the node name represents the code at the corresponding tree node in the target code.

[0077] In an embodiment of the present invention, for each tree node traversed, a start identifier can be added to the node name of the tree node, and the node name with the start identifier added can be added to the word sequence. For example, when a tree node is traversed, the node name of the tree node can be spliced with the start identifier start as a prefix, and the start identifier can be added to the node name of the tree node, and the node name with the spliced prefix can be added to the word sequence.

[0078] The fallback node can be understood as a tree node where the traversal falls back.

[0079] The end marker can be understood as a preset marker indicating the location of exiting the execution code in the target code.

[0080] In an embodiment of the present invention, when a tree node is a fallback node, an end identifier is added to the node name of the tree node, and the node name with the end identifier added is added to the word sequence. For example, when the traversal falls back to a certain tree node, the tree node is a fallback node, and the node name of the tree node is spliced with the end identifier end as a prefix, and the end identifier is added to the node name of the tree node, and the node name with the spliced prefix is added to the word sequence.

[0081] In the embodiment of the present invention, after the abstract syntax tree traversal is completed, a word sequence added to each node name can be obtained.

[0082] The word-gram sequence obtained by the solution of the embodiment of the present invention can make the code semantic information determined based on the word-gram sequence more comprehensive, thereby improving the prediction accuracy of defect prediction for the target code based on the code semantic information.

[0083] In an embodiment of the present invention, a recursive manner is adopted to traverse the abstract syntax tree, and for each tree node traversed, a start identifier is added to the node name of the tree node, and the node name to which the start identifier has been added is added to the word sequence. In addition, when the tree node is a fallback node, an end identifier is added to the node name of the tree node, and the node name to which the end identifier has been added is added to the word sequence. This allows the obtained word sequence to reflect the entry and exit positions of the target code, and further allows the word sequence to reflect the execution process of the target code. Based on the word sequence, defect prediction is performed on the target code, which can improve the accuracy of defect prediction of the target code.

[0084] Figure 4 It is a flowchart of another software defect prediction method provided in an embodiment of the present invention. This embodiment is optimized based on the above-mentioned technical solutions. In this embodiment, optionally, based on the target function and word sequence, defect prediction is performed on the target code to obtain the code defect situation, including: vector conversion of the word sequence to obtain a first vector sequence; word segmentation processing of the target function, and vector conversion of the obtained word segmentation processing result to obtain a second vector sequence; based on the first vector sequence, the second vector sequence and the defect prediction model, defect prediction is performed on the target code to obtain the code defect situation. Among them, the explanation of the terms that are the same as or corresponding to the above-mentioned embodiments will not be repeated here.

[0085] See also Figure 4 The method of this embodiment may specifically include the following steps:

[0086] S310 , obtaining source code of the software to be predicted and target functions corresponding to the software to be predicted, wherein the target functions are functions that the software to be predicted is required to have.

[0087] S320. Determine the target code associated with the target function from the source code.

[0088] S330: Determine an abstract syntax tree of the target code, and traverse the abstract syntax tree to obtain a word sequence of the target code.

[0089] S340: Perform vector conversion on the word sequence to obtain a first vector sequence.

[0090] The first vector sequence can be understood as a vector sequence obtained by performing vector conversion on a word sequence; the first vector sequence can be a numerical vector sequence.

[0091] In an embodiment of the present invention, the word-gram sequence can be vectorized to obtain a first vector sequence. For example, the word-gram sequence can be vectorized to obtain a first vector sequence through word embedding, wherein word embedding is a technology that maps words (word-grams) to real number vectors, which can represent each word as a vector with continuous values. This representation form can better reflect the semantic relationship between words in the vector space, thereby more effectively capturing and understanding the semantic similarity between words.

[0092] S350: Perform word segmentation processing on the target function, and perform vector conversion on the obtained word segmentation processing result to obtain a second vector sequence.

[0093] The word segmentation processing result can be understood as the result obtained by performing word segmentation processing on the target function.

[0094] In an embodiment of the present invention, a word segmentation process may be performed on the target function, for example, by a word segmenter. It should be noted that the word segmentation process may be understood as decomposing the target function into at least one phrase, and using a sequence consisting of at least one phrase as a word segmentation result.

[0095] The second vector sequence can be understood as a sequence of vectors obtained by performing vector conversion on the word segmentation processing result; the second vector sequence can be a sequence of numerical vectors.

[0096] In an embodiment of the present invention, the word segmentation processing result can be vectorized to obtain a second vector sequence. For example, the word segmentation processing result can be vectorized through word embedding or a pre-trained model to obtain the second vector sequence.

[0097] S360: Perform defect prediction on the target code based on the first vector sequence, the second vector sequence, and the defect prediction model to obtain code defect status.

[0098] Among them, the defect prediction model is a model used to predict defects in the target code; the defect prediction model can be, for example, a classification network, etc. In the embodiment of the present invention, there is no specific limitation on the type of the defect prediction model; the defect prediction model can, for example, use machine learning and other technologies to learn defective code and non-defective code in historical versions of software projects to achieve the function of predicting defects in the target code.

[0099] In an embodiment of the present invention, defect prediction can be performed on the target code based on the first vector sequence, the second vector sequence and the defect prediction model to obtain the code defect situation. For example, the first vector sequence and the second vector sequence can be input into the defect prediction model to perform defect prediction on the target code through the defect prediction model, and the code defect situation can be determined based on the output result of the defect prediction model.

[0100] S370: Predicting software defect conditions of the software to be predicted based on the code defect conditions.

[0101] The technical solution of the embodiment of the present invention performs vector conversion on the word sequence to obtain a first vector sequence, and performs word segmentation processing on the target function, and performs vector conversion on the obtained word segmentation processing result to obtain a second vector sequence. Then, based on the first vector sequence, the second vector sequence and the defect prediction model, defects are predicted on the target code to obtain the code defect situation. The defect prediction model can be used to predict defects on the target code through the first vector sequence and the second vector sequence that are easily processed by the defect prediction model.

[0102] An optional technical solution predicts defects in the target code based on a first vector sequence, a second vector sequence, and a defect prediction model to obtain a code defect situation, including: mapping the first vector sequence dimension to the target dimension through a first recurrent neural network to obtain code semantic information; mapping the second vector sequence dimension to the target dimension through a second recurrent neural network to obtain functional semantic information; and predicting defects in the target code based on the code semantic information, the functional semantic information, and the defect prediction model to obtain a code defect situation.

[0103] Among them, the recurrent neural network is a type of neural network architecture specially designed for processing sequence data, which can map input data of different lengths to the same dimension. On this basis, the first recurrent neural network is a recurrent neural network used to map the first vector sequence dimension to the target dimension, and the second recurrent neural network is used to map the second vector sequence dimension to the target dimension; the first recurrent neural network and the second recurrent neural network can be the same recurrent neural network or different recurrent neural networks; in the embodiment of the present invention, there is no specific limitation on the structure and parameters of the first recurrent neural network and the second recurrent neural network.

[0104] The target dimension can be understood as the dimension to which the dimensions of the first vector sequence and the second vector sequence are mapped; the target dimension can be preset, or determined based on the dimension of the first vector sequence and / or the dimension of the second vector sequence, and so on.

[0105] Code semantic information can be understood as information that can reflect the semantics of the target code.

[0106] Functional semantic information can be understood as information that can reflect the semantics of the target function.

[0107] It can be understood that since the target code and the target function may be of different lengths, the word sequences corresponding to the target code and the target function may be of different lengths, and thus the dimensions of the first vector sequence and the second vector sequence may also be different; in the case where there are multiple target codes, since different target codes may be of different lengths, the word sequences corresponding to different target codes may be of different lengths, and thus the dimensions of the first vector sequences corresponding to different target codes may also be different. Therefore, in an embodiment of the present invention, regardless of whether the target code and the target function are of the same length, and regardless of whether the length of at least one target code corresponding to the target function is the same, the first vector sequence and the second vector sequence can be uniformly mapped to the target dimension through a recurrent neural network to facilitate processing by a subsequent defect prediction model.

[0108] In the embodiment of the present invention, the first vector sequence dimension can be mapped to the target dimension through the first recurrent neural network to obtain code semantic information, for example, see Figure 5 , the first vector sequence (token1, token2…token n ) are respectively inputted forwardly and backwardly into the bidirectional long short-term memory network (LSTM) as the first recurrent neural network, so that the hidden layer in the bidirectional long short-term memory network can obtain the positive feature H ln and reverse feature H rn The reverse features obtained by input are concatenated to obtain the code semantic information H m .

[0109] In an embodiment of the present invention, the second vector sequence dimension can be mapped to the target dimension through a second recurrent neural network to obtain functional semantic information. For example, the second vector sequence can be input forwardly and reversely into a bidirectional long short-term memory network serving as the second recurrent neural network, so that the hidden layer in the bidirectional long short-term memory network can concatenate the forward features obtained by the forward input and the reverse features obtained by the reverse input to obtain functional semantic information.

[0110] In an embodiment of the present invention, defect prediction can be performed on the target code based on the code semantic information, functional semantic information and the defect prediction model to obtain the code defect situation. For example, the code semantic information and the functional semantic information can be spliced to obtain splicing information, and the splicing information can be input into the defect prediction model to perform defect prediction on the target code, and the code defect situation can be determined based on the output result of the defect prediction model.

[0111] In an embodiment of the present invention, the first vector sequence dimension can be mapped to the target dimension through a first recurrent neural network to obtain code semantic information, and the second vector sequence dimension can be mapped to the target dimension through a second recurrent neural network to obtain functional semantic information. Then, based on the code semantic information, functional semantic information and the defect prediction model, defects are predicted for the target code to obtain the code defect situation. The defect prediction model can be used to predict defects for the target code using code semantic information and functional semantic information of the same dimension that are easily processed by the defect prediction model.

[0112] Based on the above scheme, another optional technical scheme is to map the first vector sequence dimension to the target dimension through a first recurrent neural network to obtain code semantic information, including: arranging the vectors in the first vector sequence in reverse order to obtain a third vector sequence; inputting the first vector sequence and the third vector sequence into the first recurrent neural network, and mapping the first vector sequence dimension to the target dimension based on the output result of the first recurrent neural network to obtain code semantic information.

[0113] The third vector sequence is a sequence obtained by arranging the vectors in the first vector sequence in reverse order.

[0114] In an embodiment of the present invention, the vectors in the first vector sequence are arranged in reverse order to obtain a third vector sequence, and then the first vector sequence and the third vector sequence are input into the first recurrent neural network. That is, the first vector sequence is input into the first recurrent neural network in the forward direction (first vector sequence) and the reverse direction (third vector sequence), respectively. Based on the output result of the first recurrent neural network, the first vector sequence dimension is mapped to the target dimension to obtain code semantic information, so that the code semantic information mapped to the target dimension can have a more comprehensive feature representation.

[0115] In order to better understand the technical solution of the above embodiment of the present invention, an optional example is provided here. Figure 6 , obtain source code and target function; determine target code from source code; parse and obtain abstract syntax tree of target code, and traverse the abstract syntax tree through traversal algorithm to obtain word sequence (node sequence); vectorize the word sequence through word embedding to obtain a first vector sequence; map the first vector sequence dimension to the target dimension through a first recurrent neural network (recurrent neural network) to obtain code semantic information; perform word segmentation on target function; vectorize the obtained word segmentation result through word embedding or pre-training model to obtain a second vector sequence; map the second vector sequence dimension to the target dimension through a second recurrent neural network (recurrent neural network) to obtain functional semantic information; perform defect prediction on target code based on code semantic information, functional semantic information and defect prediction model (classification model) to obtain code defect situation; predict software defect situation of the software to be predicted based on the code defect situation.

[0116] Figure 7 This is a structural block diagram of a software defect prediction device provided by an embodiment of the present invention. The device is used to execute the software defect prediction method provided by any of the above embodiments. The device and the software defect prediction method of the above embodiments belong to the same inventive concept. For details not fully described in the embodiment of the software defect prediction device, please refer to the embodiment of the above software defect prediction method. Figure 7 The device may specifically include: a target function acquisition module 410, a code defect situation acquisition module 420 and a software defect situation prediction module 430.

[0117] The target function acquisition module 410 is used to acquire the source code of the software to be predicted and the target function corresponding to the software to be predicted, wherein the target function is the function that the software to be predicted is required to have;

[0118] The code defect situation obtaining module 420 is used to determine the target code associated with the target function from the source code, and perform defect prediction on the target code based on the target function to obtain the code defect situation;

[0119] The software defect situation prediction module 430 is used to predict the software defect situation of the software to be predicted based on the code defect situation.

[0120] Optionally, the code defect situation obtaining module 420 includes:

[0121] The word-unit sequence obtaining submodule is used to determine the abstract syntax tree of the target code and traverse the abstract syntax tree to obtain the word-unit sequence of the target code;

[0122] The first code defect situation obtaining submodule is used to predict defects in the target code according to the target function and word sequence to obtain the code defect situation.

[0123] Optionally, based on the above device, a word-unit sequence obtaining submodule includes:

[0124] A word sequence initialization unit, used to initialize the word sequence of the target code;

[0125] An abstract syntax tree traversal unit is used to traverse the abstract syntax tree recursively using the root node of the abstract syntax tree as a traversal entry;

[0126] a node name adding unit, for adding a preset start identifier to the node name of each tree node in the traversed abstract syntax tree, adding the node name with the start identifier added to the word sequence, and, if the tree node is a fallback node, adding a preset end identifier to the node name of the tree node, adding the node name with the end identifier added to the word sequence, wherein the target code includes the node name;

[0127] The word unit sequence obtaining unit is used to obtain the word unit sequence when the abstract syntax tree traversal is completed.

[0128] Optionally, based on the above device, a submodule for obtaining the first code defect condition includes:

[0129] A first vector sequence obtaining unit, configured to perform vector conversion on the word sequence to obtain a first vector sequence;

[0130] A second vector sequence obtaining unit is used to perform word segmentation processing on the target function and perform vector conversion on the obtained word segmentation processing result to obtain a second vector sequence;

[0131] The code defect situation obtaining unit is used to perform defect prediction on the target code according to the first vector sequence, the second vector sequence and the defect prediction model to obtain the code defect situation.

[0132] Optionally, based on the above device, a code defect situation obtaining unit includes:

[0133] A code semantic information obtaining subunit is used to map the first vector sequence dimension to the target dimension through a first recurrent neural network to obtain code semantic information;

[0134] A functional semantic information obtaining subunit is used to map the second vector sequence dimension to the target dimension through a second recurrent neural network to obtain functional semantic information;

[0135] The code defect situation obtaining subunit is used to predict defects on the target code based on code semantic information, functional semantic information and defect prediction model to obtain code defect situation.

[0136] Optionally, based on the above device, a code semantic information obtaining subunit is specifically used for:

[0137] Arrange the vectors in the first vector sequence in reverse order to obtain a third vector sequence;

[0138] The first vector sequence and the third vector sequence are input into the first recurrent neural network, and according to the output result of the first recurrent neural network, the first vector sequence dimension is mapped to the target dimension to obtain code semantic information.

[0139] Optionally, the target function acquisition module 410 includes:

[0140] The target function acquisition submodule is used to obtain the target functions of the software to be predicted corresponding to the software to be predicted;

[0141] The code defect situation obtaining module 420 includes:

[0142] A target code determination submodule is used to determine, for each target function, a target code associated with the target function from the source code;

[0143] The software defect prediction module 430 includes:

[0144] The first software defect situation prediction submodule is used to predict the software defect situation of the software to be predicted according to the code defect situation corresponding to each target function.

[0145] Optionally, the number of target codes is at least one;

[0146] The code defect situation obtaining module 420 includes:

[0147] The second code defect situation obtaining submodule is used to predict defects of the target code according to the target function for each target code to obtain the code defect situation;

[0148] The software defect prediction module 430 includes:

[0149] The second software defect situation prediction submodule is used to predict the software defect situation of the software to be predicted according to the code defect situation corresponding to each target code.

[0150] The software defect prediction device provided by the embodiment of the present invention obtains the source code of the software to be predicted and the target function corresponding to the software to be predicted through a target function acquisition module, wherein the target function is the function that the software to be predicted is required to have. Then, through the code defect situation acquisition module, the target code associated with the target function is determined from the source code, and based on the target function, the target code is defect predicted to obtain the code defect situation. The target function can be involved in software defect prediction by performing defect detection on the target code based on the target function. Finally, the software defect situation prediction module predicts the software defect situation of the software to be predicted based on the code defect situation, thereby realizing defect prediction of the software to be predicted. The above-mentioned device, by performing software defect prediction based on the target function, can realize automatic software defect prediction without manually designing statistical metrics, thereby improving the efficiency and accuracy of software defect prediction.

[0151] The software defect prediction device provided by the embodiment of the present invention can execute the software defect prediction method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0152] It is worth noting that in the embodiment of the above-mentioned software defect prediction device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0153] Figure 8A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.

[0154] like Figure 8 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. Various programs and data required for the operation of the electronic device 10 can also be stored in the RAM 13. The processor 11, ROM 12, and RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0155] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0156] The processor 11 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the software defect prediction method.

[0157] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product that includes a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication unit 19, or installed from the storage unit 18, or installed from the ROM 12. When the computer program is executed by the processor 11, the above-mentioned functions defined in the method of the embodiment of the present invention are performed.

[0158] In some embodiments, the software defect prediction method can be implemented as a computer program that is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the software defect prediction method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to execute the software defect prediction method in any other appropriate manner (e.g., by means of firmware).

[0159] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on a chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0160] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0161] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0162] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0163] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0164] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.

[0165] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.

[0166] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

Claims

1. A software defect prediction method, characterized in that: include: Obtaining source code of the software to be predicted and target functions corresponding to the software to be predicted, wherein the target functions are functions that the software to be predicted is required to have; Determining target code associated with the target function from the source code, and performing defect prediction on the target code based on the target function to obtain code defect status; According to the code defect situation, the software defect situation of the software to be predicted is predicted.

2. The method according to claim 1, characterized in that The step of performing defect prediction on the target code according to the target function to obtain code defect information includes: Determining an abstract syntax tree of the target code, and traversing the abstract syntax tree to obtain a word sequence of the target code; According to the target function and the word sequence, defect prediction is performed on the target code to obtain code defect status.

3. The method according to claim 2, characterized in that The traversing the abstract syntax tree to obtain a word sequence of the target code includes: Initializing a word sequence of the target code; Using the root node of the abstract syntax tree as a traversal entry, traversing the abstract syntax tree in a recursive manner; For each tree node in the traversed abstract syntax tree, adding a preset start identifier to the node name of the tree node, adding the node name with the start identifier to the word sequence, and if the tree node is a fallback node, adding a preset end identifier to the node name of the tree node, adding the node name with the end identifier to the word sequence, wherein the target code includes the node name; When the abstract syntax tree traversal is completed, the word sequence is obtained.

4. The method according to claim 2, characterized in that The step of performing defect prediction on the target code according to the target function and the word sequence to obtain code defect information includes: Performing vector conversion on the word-unit sequence to obtain a first vector sequence; Performing word segmentation processing on the target function, and performing vector conversion on the obtained word segmentation processing results to obtain a second vector sequence; Defect prediction is performed on the target code according to the first vector sequence, the second vector sequence and a defect prediction model to obtain code defect conditions.

5. The method according to claim 4, characterized in that The performing defect prediction on the target code according to the first vector sequence, the second vector sequence, and the defect prediction model to obtain code defect conditions includes: Mapping the first vector sequence dimension to a target dimension through a first recurrent neural network to obtain code semantic information; Mapping the second vector sequence dimension to the target dimension through a second recurrent neural network to obtain functional semantic information; Defect prediction is performed on the target code based on the code semantic information, the functional semantic information and the defect prediction model to obtain code defect conditions.

6. The method according to claim 5, characterized in that Mapping the first vector sequence dimension to a target dimension through a first recurrent neural network to obtain code semantic information includes: Arrange the vectors in the first vector sequence in reverse order to obtain a third vector sequence; The first vector sequence and the third vector sequence are input into a first recurrent neural network, and according to an output result of the first recurrent neural network, the first vector sequence dimension is mapped to a target dimension to obtain code semantic information.

7. The method according to claim 1, characterized in that The obtaining of the target function of the software to be predicted corresponding to the software to be predicted includes: Obtaining target functions of the software to be predicted corresponding to the software to be predicted; Determining the target code associated with the target function from the source code includes: For each of the target functions, determining a target code associated with the target function from the source code; The predicting of the software defect situation of the software to be predicted according to the code defect situation includes: The software defect conditions of the software to be predicted are predicted based on the code defect conditions corresponding to the target functions.

8. The method according to claim 1, characterized in that The number of said target codes is at least one; The step of performing defect prediction on the target code according to the target function to obtain code defect information includes: For each target code, performing defect prediction on the target code according to the target function to obtain code defect status; The predicting of the software defect situation of the software to be predicted according to the code defect situation includes: The software defect conditions of the software to be predicted are predicted according to the code defect conditions corresponding to the target codes.

9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the software defect prediction method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the software defect prediction method according to any one of claims 1 to 8 when executed.