Software defect detection method and device for power digital system and storage medium

By obtaining historical source programs from the log files of the power digital system, preprocessing and automated static code analysis, extracting the feature index information of the source code, and fine-tuning training using the pre-trained model to build a multi-classification software defect detection model, the solution is In the prior art, software defect detection methods have weaker functions in capturing code defect semantics, and realize more accurate software defect detection and efficient defect detection process.

CN119441004AActive Publication Date: 2025-02-14ELECTRIC POWER RES INST CHINA SOUTHERN POWER GRID CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411531922.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-02-14
Estimated Expiration
2044-10-30

AI Technical Summary

Technical Problem

In the prior art, software defect detection methods have weak functions in capturing code defect semantics, resulting in inaccurate prediction results and high cost of constructing detection models.

Method used

By obtaining historical source programs from the log files of the power digital system, preprocessing and automated static code analysis, extracting the feature index information of the source code, and fine-tuning training using the pre-trained model to build a multi-classification software defect detection model.

Benefits of technology

More accurate software defect detection is achieved, reducing the possibility of failure after the system is launched, and defect detection is efficiently carried out under limited computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119441004A_ABST
    Figure CN119441004A_ABST
Patent Text Reader

Abstract

The invention provides a software defect detection method and device for an electric power digital system and a storage medium. The method comprises the steps of obtaining a historical source program from a log file; preprocessing the source code content to generate a standardized code file conforming to the prediction model; performing automatic analysis on the source code by adopting an automatic static code analysis script to obtain an analyzed code file, and extracting feature index information in the file; determining a set of the abstract syntax trees of all the analyzed source codes and the corresponding feature index information as a feature data set, and training the pre-training model by adopting the feature data set to obtain a multi-classification software defect detection model; and inputting the to-be-tested source program into the multi-classification software defect detection model for prediction to obtain a prediction result. According to the method, high accuracy is taken as a main target, and a training method with efficient parameters is operated, so that the economic cost of the detection method is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of software defect detection, and in particular to a software defect detection method for a power digital system, a software defect detection device for a power digital system, a computer-readable storage medium, and an electronic device. Background Art

[0002] With the development of information technology and the continuous expansion of its application scope, software systems are playing an increasingly important role in various fields. As a key visualization system in the energy field, the power digital system plays an important role in power production, transmission, distribution and management. However, with the increasing complexity and continuous expansion of the functions of the power digital system, software defects are becoming increasingly prominent, bringing huge challenges to the stability and security of the system.

[0003] Traditional software testing and quality assurance methods often rely on manual testing and static code analysis, which have problems such as low efficiency, limited coverage, and inability to fully detect various defects. Especially in large and complex software systems such as power digital systems, manual testing and analysis are costly and time-consuming, and are weak in capturing the semantics of code defects, resulting in omissions or misjudgments, leading to the accumulation of defects and the decline of system stability. Summary of the invention

[0004] The main purpose of the present application is to provide a software defect detection method for a power digital system, a software defect detection device for a power digital system, a computer-readable storage medium and an electronic device, so as to at least solve the problem that the software defect detection method in the prior art is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high cost of building a detection model.

[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a software defect detection method for an electric power digital system is provided, comprising: obtaining a historical source program of the electric power digital system from a log file of the electric power digital system, the historical source program including all source program codes of the electric power digital system in the development stage, and defect codes generated when the electric power digital system is running in a historical period; preprocessing the source code content in the historical source program to generate a standardized code file that conforms to a prediction model; writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file; determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as an input feature to fine-tune a pre-trained model to obtain a multi-classification software defect detection model for the historical source program; inputting a source program to be tested into the multi-classification software defect detection model for prediction to obtain a prediction result, wherein the prediction result includes a defect prediction situation and a defect prediction type of the source program to be tested.

[0006] Optionally, the source code content in the historical source program is preprocessed to generate a standardized code file that conforms to the prediction model, including: performing an integrity check on the source code file in the historical source program to obtain a complete source code and an incomplete source code, the integrity check including a logic integrity check and a function dependency integrity check; filtering out the incomplete source code in the historical source program to obtain a complete source code file that only includes the complete source code; performing noise processing on the complete source code file to remove noise information of each source code in the complete source code file to obtain the standardized code file.

[0007] Optionally, an automated static code analysis script is written to automatically parse the source code content in the standardized code file to obtain a parsed code file, and characteristic index information of each source code in the parsed code file is extracted, including: writing the automated static code analysis script based on the Joern library of a third-party code analysis tool; using the written automated static code analysis script to automatically parse the standardized code file to obtain a parsed code file; extracting the abstract syntax tree and characteristic index information of each source code in the parsed code file, the abstract syntax tree is an abstract representation sequence that represents the syntax structure of the source code in a tree structure, the characteristic index information includes original indicators, Halstead indicators, cyclomatic complexity indicators and maintainability index, the original indicators are unprocessed data or measurements directly collected from the historical source program, the Halstead indicators are software metrics indicators used to measure the complexity and scale of software code, the cyclomatic complexity indicators are used to measure the control flow complexity and structured degree in the source code file, and the maintainability index is used to evaluate the maintainability and readability of the software code.

[0008] Optionally, the feature data set is used as an input feature to fine-tune the pre-trained model, and the resulting multi-classification software defect detection model for the historical source program includes: determining the code defect type based on all the source code in the parsed code file in conjunction with the error log in the system log file; using a text embedding model to map the abstract syntax tree representation sequence of all the source code in the parsed code file to a continuous vector space to obtain a digital vector of each source code; fusing the feature indicator information of each source code with the digital vector to obtain a feature sequence of each source code; building a prediction model architecture, first using a pre-trained CodeBert model to further extract code semantic features of the input feature sequence, and constructing a random forest classifier to predict the extracted semantic features; in the model training process, using the Dora fine-tuning training method to train the pre-trained model according to the feature data set and the code defect type to obtain the multi-classification software defect detection model.

[0009] Optionally, determining the code defect type according to all the source codes in the parsed code file in conjunction with the error log in the system log file includes: performing statistical analysis on the defect conditions of all the source codes in the parsed code file according to the error log to obtain the occurrence frequency of each source code defect; sorting the occurrence frequency of each source code defect from large to small according to the occurrence frequency of each source code defect; determining the labels of the first to fifth categories of source code defects as corresponding code defect types; and uniformly determining the labels of the sixth category of source code defects as other defects in the code defect types, and the sixth category of source code defects are all the source code defects except the first to fifth categories of source code defects.

[0010] Optionally, after the source program to be tested is input into the multi-classification software defect detection model for prediction and a prediction result is obtained, the method further includes: generating a detection report representing the source program to be tested in the form of a JSON file based on the prediction result, wherein the key value of the JSON file is the file name of each code in the source program to be tested, and the value value is the defect prediction situation corresponding to each code in the source program to be tested, and the defect prediction situation is defective or non-defective. When the defect prediction situation is defective, the label information of the defect is noted.

[0011] Optionally, the updated source code data backed up in the log file of the power digital system is regularly obtained; the current defect detection accuracy of the multi-classification software defect detection model at the current moment is determined; when the current defect detection accuracy of the multi-classification software defect detection model is less than or equal to a preset accuracy, the historical source program is integrated with the updated source code data to obtain an updated source code file; the incremental learning method and the updated source code file are used to re-fine-tune and train the multi-classification software defect detection model to implement an updated defect detection model.

[0012] According to another aspect of the present application, a software defect detection device for an electric power digital system is provided, comprising: a collection unit, for obtaining a historical source program of the electric power digital system from a log file of the electric power digital system, wherein the historical source program includes all source program codes of the electric power digital system in the development stage, and defect codes generated when the electric power digital system is running in a historical period; a preprocessing unit, for preprocessing the source code content in the historical source program to generate a standardized code file that conforms to a prediction model; a parsing unit, for writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file; a determination unit, for determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as an input feature to fine-tune a pre-trained model to obtain a multi-classification software defect detection model for the historical source program; and a prediction unit, for inputting a source program to be tested into the multi-classification software defect detection model for prediction to obtain a prediction result, wherein the prediction result includes a defect prediction situation and a defect prediction type of the source program to be tested.

[0013] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the software defect detection methods for a power digital system.

[0014] According to another aspect of the present application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing any one of the above-mentioned software defect detection methods for power digital systems.

[0015] Applying the technical solution of the present application, the above-mentioned software defect detection method for the power digital system first obtains the historical source program of the power digital system from the log file of the power digital system, and the historical source program includes all the source program codes of the power digital system in the development stage, and the defect code generated when the power digital system is running in the historical period; then the source code content in the historical source program is preprocessed to generate a standardized code file that conforms to the prediction model; an automated static code analysis script is written to automatically parse the source code content in the standardized code file to obtain a parsed code file, and the feature index information of each source code in the parsed code file is extracted; then the set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information is determined as a feature data set, and the feature data set is used as the input feature to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for the historical source program; finally, the source program to be tested is input into the multi-classification software defect detection model for prediction to obtain a prediction result, and the prediction result includes the defect prediction situation and defect prediction type of the source program to be tested. This method integrates source code content and code metrics, constructs a feature sequence containing rich semantic information, and constructs a multi-classification software defect detection model based on pre-trained CodeBert. It effectively predicts the defects of the source code of the version to be released by mining the defect features of the historical version source code files, thereby reducing the possibility of failure after the system is launched. The Dora fine-tuning method is adopted to greatly reduce the parameter calculation steps in the model training process, so that efficient defect detection can still be achieved under limited computing resources. It solves the problem that the software defect detection method in the existing technology is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high cost of building the detection model. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The drawings constituting part of the present application are used to provide a further understanding of the present application. The exemplary embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0017] Figure 1 A hardware structure block diagram of a mobile terminal for executing a software defect detection method for a power digital system provided in an embodiment of the present application is shown;

[0018] Figure 2 A schematic flow chart of a software defect detection method for a power digital system provided according to an embodiment of the present application is shown;

[0019] Figure 3 A neural network principle diagram provided according to an embodiment of the present application is shown;

[0020] Figure 4A schematic flow chart of another method for detecting software defects in a power digital system provided according to an embodiment of the present application is shown;

[0021] Figure 5 A structural block diagram of a software defect detection device for a power digital system provided according to an embodiment of the present application is shown.

[0022] The above drawings include the following reference numerals:

[0023] 102, processor; 104, memory; 106, transmission device; 108, input and output devices. DETAILED DESCRIPTION

[0024] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

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

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] As introduced in the background technology, with the development of artificial intelligence and machine learning technology in the prior art, intelligent software defect detection methods have received widespread attention and application. By using machine learning algorithms and big data analysis technology, potential defect patterns and features can be mined from massive data to achieve efficient detection and diagnosis of complex software systems. For example, a defect detection model based on deep learning can automatically learn and identify different types of defects with high accuracy and generalization ability. However, these models are still poor in the ability to capture the semantics of code defects, which affects the prediction results of the model to a certain extent. In addition, pre-trained models often require a large amount of computing resources, which increases the operating costs of the software development team. In order to solve the problem that the software defect detection method in the prior art is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high detection model construction costs, the embodiments of the present application provide a software defect detection method for a power digital system, a software defect detection device for a power digital system, a computer-readable storage medium and an electronic device.

[0028] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0029] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 1 is a hardware structure block diagram of a mobile terminal for a software defect detection method for a power digital system according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0030] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the software defect detection method for the power digital system in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof. The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0031] In this embodiment, a software defect detection method for a power digital system running on a mobile terminal, a computer terminal or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0032] Figure 2 1 is a flow chart of a method for detecting software defects in a power digital system according to an embodiment of the present application. Figure 2 As shown, the method comprises the following steps:

[0033] Step S201, obtaining a historical source program of the power digital system from a log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in the development stage, and defect codes generated when the power digital system is running in a historical period;

[0034] Specifically, by analyzing historical source programs to understand possible defects in the power digital system, a large amount of source code is provided for subsequent efficient parameter detection, which helps to improve the stability and reliability of the system.

[0035] Among them, the required content is collected from the log backup file of the power digital system, which mainly includes the following code information: all source program codes of the system during the development stage, which are usually written in mainstream programming languages ​​such as Python, Java, and C++; the defect errors and corresponding fault addresses saved by the system during operation recorded in the log file, and the corresponding source code files are marked as defect files.

[0036] In some examples, preliminary experiments were completed in the large Python development defect dataset PyTraceBugs, which can help software testers to mine the five major defects, other types of defects, and non-polluted code segments commonly seen in Python development. Taking AUC as the evaluation indicator, the above example prediction model can achieve an AUC value of 0.85 and can improve the training speed by nearly 10% during the model training process.

[0037] Step S202, preprocessing the source code content in the above historical source program to generate a standardized code file that conforms to the prediction model;

[0038] Specifically, through integrity checking and noise processing, the quality of the source code can be effectively improved and the logical integrity of the source code can be ensured.

[0039] The process of preprocessing the source code content in the historical source program to generate a standardized code file that conforms to the prediction model includes the following steps:

[0040] Step S301, performing integrity check on the source code files in the historical source program to obtain complete source code and incomplete source code, wherein the integrity check includes a logic integrity check and a function dependency integrity check;

[0041] Step S302, filtering out the incomplete source code in the historical source program to obtain a complete source code file including only the complete source code;

[0042] Step S303: performing noise processing on the complete source code file to remove noise information of each source code in the complete source code file to obtain the standardized code file.

[0043] Specifically, through integrity checking and noise processing, the complete source code can be screened out and noise information can be removed, thereby improving code quality and enhancing code reliability.

[0044] Among them, a detailed integrity check is performed on each source code file, mainly checking the logical integrity and function dependency integrity of the source code file to ensure that the source code file does not contain missing or damaged parts. For source code files that are detected to contain incomplete parts, they are screened out to ensure the quality of the preprocessed code files. The retained source code files are further cleaned up to remove noise information such as comments and extra blank lines contained in them.

[0045] Step S203, writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file;

[0046] Specifically, the automated static code analysis script can quickly parse a large number of source code files, saving manpower and time costs, and can extract feature indicator information from the source code files, providing a basis for the subsequent construction of software defect detection models.

[0047] Among them, writing an automated static code analysis script to automatically parse the source code content in the above-mentioned standardized code file to obtain a parsed code file, and extracting characteristic indicator information of each source code in the above-mentioned parsed code file includes the following steps:

[0048] Step S401, writing the above-mentioned automated static code analysis script based on the third-party code analysis tool Joern library;

[0049] Step S402, using the written automated static code analysis script to automatically parse the above-mentioned standardized code file to obtain a parsed code file;

[0050] Step S403, extracting the abstract syntax tree and characteristic index information of each source code in the above-mentioned parsed code file, wherein the above-mentioned abstract syntax tree is an abstract representation sequence that represents the syntax structure of the source code in a tree structure, and the above-mentioned characteristic index information includes original index, Halstead index, cyclomatic complexity index and maintainability index, wherein the above-mentioned original index is the unprocessed data or measurement value directly collected from the above-mentioned historical source program, the above-mentioned Halstead index is a software metric index used to measure the complexity and scale of software code, the above-mentioned cyclomatic complexity index is used to measure the control flow complexity and structured degree in the source code file, and the above-mentioned maintainability index is used to evaluate the maintainability and readability of the software code.

[0051] Specifically, automated static code analysis tools can improve code quality and security, reduce potential vulnerabilities and errors, and construct four types of code feature indicators required for multi-classification defect detection models, integrating the abstract syntax tree of the source code and code metrics to construct a feature sequence containing rich semantic information.

[0052] Among them, the third-party code analysis tool Joern is integrated to write an automated static code analysis script to systematically and efficiently extract the four types of code feature indicators required to build a multi-classification defect detection model:

[0053] Raw indicators: This indicator information is the basic unprocessed data or measurement value collected directly from the source code file, specifically using the number of code lines and the number of logical code lines;

[0054] Halstead Metrics: A set of software metrics used to measure the complexity and size of software code, specifically using three metrics: program length, volume, and quantification difficulty;

[0055] Cyclomatic complexity index: This index is used to measure the control flow complexity and structuredness in the source code file;

[0056] Maintainability Index: This metric is used to evaluate the maintainability and readability of software code to help developers evaluate and improve the quality of the code.

[0057] Step S204, determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as input features to fine-tune the pre-trained model, thereby obtaining a multi-classification software defect detection model for the historical source program;

[0058] Specifically, the multi-classification software defect detection model obtained through training can detect software defects more accurately, help developers find and fix software defects in a timely manner, and improve software quality.

[0059] The above-mentioned feature data set is used as input features to fine-tune the pre-trained model, and the resulting multi-classification software defect detection model for historical source programs includes the following steps:

[0060] Step S501, determining the code defect type according to all the above source codes in the above parsed code file and the error log in the system log file;

[0061] Among them, according to all the above source codes in the above parsed code file, in conjunction with the error log in the system log file, the code defect type is determined, including:

[0062] Step S601, performing statistical analysis on the defects of all the above source codes in the above parsed code file according to the error log, and obtaining the occurrence frequency of each source code defect;

[0063] Step S602, sorting the occurrence frequencies of the above-mentioned source code defects from large to small according to the occurrence frequencies of the above-mentioned source code defects;

[0064] Step S603, determining the labels of the first to fifth types of source code defects as corresponding code defect types;

[0065] Step S604: uniformly determine the labels of the sixth category of source code defects as other defects in the above code defect types. The sixth category of source code defects are all the above source code defects except the first to fifth category of source code defects.

[0066] Specifically, by statistically analyzing the frequency of occurrence of source code defects, the specific circumstances of various defects can be more intuitively understood.

[0067] Among them, a detailed statistical analysis is conducted on the defects in the source code files. According to the frequency of occurrence of system defects, the top five frequently occurring defects are determined as major fault categories. The label of each major category is its specific defect cause. Other defects that are not classified into the major fault categories are uniformly regarded as minor fault categories. The labels of the minor fault categories are set as other defects, and their defect causes are not described in detail.

[0068] Step S502, using a text embedding model to map the abstract syntax tree representation sequences of all the above source codes in the above parsed code file to a continuous vector space to obtain a digital vector of each of the above source codes;

[0069] Step S503, combining the characteristic index information of each of the above source codes with the above digital vector to obtain a characteristic sequence of each of the above source codes;

[0070] In some instances, the metrics and digital vector representation of each source code file are combined to form a feature sequence, which can be as follows: \Source code feature sequence: CLS, abstract syntax tree digital vector, [SEP], metric information, [EOS];

[0071] Among them, [CLS] is used to mark the beginning of a feature sequence, [SEP] is used to distinguish the metric information from the digital vector of the abstract syntax tree, and [EOS] is used to mark the end of a feature sequence. By separating the metric features and the source code abstract syntax tree sequence, the pre-trained model can better mine the key features of each part.

[0072] Step S504, building a prediction model architecture, first using the pre-trained CodeBert model to further extract the code semantic features of the input feature sequence, and constructing a random forest classifier to predict the extracted semantic features;

[0073] Among them, the source code feature sequence processed by the above steps is divided into a training set and a test set in a ratio of 8:2 to ensure that the defect ratio in each data set remains consistent.

[0074] A multi-classification software defect detection model based on the pre-trained CodeBert model is constructed and its parameters are initialized. The detection model uses the pre-trained CodeBert model to learn the abstract representation of the code and uses random forest to build a classifier to predict defects in the abstract representation of the code. The classifier supports predicting whether the code belongs to the top five major fault categories, minor fault categories, or no defects.

[0075] Specifically, Figure 3 As shown, Figure 3 It is part of the neural network used, including an input feature, an original pre-trained model weight, an A matrix and a B matrix introduced by Dora. During the model training process, by freezing the weight matrix of the original pre-trained model, only the A matrix and the B matrix will be updated).

[0076] Step S505, during the model training process, the Dora fine-tuning training method is used to train the pre-trained model according to the above feature data set and the above code defect type to obtain the above multi-classification software defect detection model.

[0077] Among them, a parameter-efficient training method based on Dora is adopted. The parameters of the pre-trained CodeBert are frozen during the training process, and the weights of the defect detection model are optimized by updating the A and B matrices added by Dora. After the Dora weight matrix is ​​introduced, all weight vectors of the self-attention layer and the fully connected layer of the model are frozen during the training process. The self-attention layer and the fully connected layer are optimized only by updating the introduced Dora matrix, which greatly reduces the number of parameters that need to be optimized for the training model.

[0078] Specifically, a multi-classification software defect detection model based on pre-trained CodeBert was constructed. By mining the defect features of historical version source code files, the defect situation of the source code of the version to be released can be effectively predicted, thereby reducing the possibility of failure after the system is launched.

[0079] Step S205 , input the source program to be tested into the above-mentioned multi-classification software defect detection model for prediction to obtain a prediction result, which includes the defect prediction status and defect prediction type of the source program to be tested.

[0080] Specifically, the method adopts Dora's fine-tuning training method, which greatly reduces the parameter calculation steps in the model training process, so that the present invention can still achieve efficient defect detection under limited computing resource conditions.

[0081] Among them, after the source program to be tested is input into the above-mentioned multi-classification software defect detection model for prediction and the prediction result is obtained, the above-mentioned method also includes: based on the above-mentioned prediction result, generating a detection report representing the above-mentioned source program to be tested in the form of a JSON file, wherein the key value of the above-mentioned JSON file is the file name of each code in the above-mentioned source program to be tested, and the value value is the defect prediction situation corresponding to each code in the above-mentioned source program to be tested, and the above-mentioned defect prediction situation is defective or non-defective. When the above-mentioned defect prediction situation is defective, the label information of the defect is indicated.

[0082] Specifically, the JSON file format is concise and clear, easy to read and parse, and can be easily automated and analyzed through code. In addition, JSON files can also be integrated with other tools and systems to achieve more functions and improve work efficiency.

[0083] In some instances, software testing engineers input the source code content to be tested into the built multi-classification defect detection model for prediction, and generate a defect detection report in the form of a JSON file, where the key value of the JSON file is the source code file name, and the value value is the defect prediction status of the corresponding source code file.

[0084] The above method further comprises the following steps:

[0085] Step S701, regularly obtaining updated source code data backed up in the log file of the above-mentioned power digital system;

[0086] Step S702, determining the current defect detection accuracy of the multi-classification software defect detection model at the current moment;

[0087] Step S703, when the current defect detection accuracy of the multi-classification software defect detection model is less than or equal to the preset accuracy, integrating the historical source program with the updated source code data to obtain an updated source code file;

[0088] Step S704, using an incremental learning method and the updated source code file to re-fine-tune and train the multi-classification software defect detection model to implement an updated defect detection model.

[0089] Specifically, the updated source code data backed up in the log file can be regularly obtained to ensure that the data used by the model is the latest, which helps to improve the accuracy and performance of the model. When the current defect detection accuracy is not up to standard, timely integration of historical source programs and updated source code data and retraining of the model can help improve the accuracy of defect detection.

[0090] Among them, the source code files of the new version are collected and the defect detection of the existing multi-classification defect detection model in the version of the program to be released is evaluated. If the model performance does not meet expectations, the existing files are reintegrated with the new version files, and the multi-classification defect detection model is retrained using incremental learning to avoid retraining the entire model from scratch.

[0091] The above-mentioned software defect detection method for the electric power digital system of the present application first obtains the historical source program of the electric power digital system from the log file of the electric power digital system, and the historical source program includes all the source program codes of the electric power digital system in the development stage, and the defect code generated when the electric power digital system is running in the historical period; then the source code content in the historical source program is preprocessed to generate a standardized code file that conforms to the prediction model; an automated static code analysis script is written to automatically parse the source code content in the standardized code file to obtain a parsed code file, and feature index information of each source code in the parsed code file is extracted; then the set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information is determined as a feature data set, and the feature data set is used as the input feature to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for the historical source program; finally, the source program to be tested is input into the multi-classification software defect detection model for prediction to obtain a prediction result, and the prediction result includes the defect prediction situation and defect prediction type of the source program to be tested. This method integrates source code content and code metrics, constructs a feature sequence containing rich semantic information, and constructs a multi-classification software defect detection model based on pre-trained CodeBert. It effectively predicts the defects of the source code of the version to be released by mining the defect features of the historical version source code files, thereby reducing the possibility of failure after the system is launched. The Dora fine-tuning method is adopted to greatly reduce the parameter calculation steps in the model training process, so that efficient defect detection can still be achieved under limited computing resources. It solves the problem that the software defect detection method in the existing technology is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high cost of building the detection model.

[0092] In order to enable those skilled in the art to more clearly understand the technical solution of the present application, the implementation process of the software defect detection method for the power digital system of the present application will be described in detail below in combination with specific embodiments.

[0093] This embodiment relates to a specific software defect detection method for a power digital system, such as Figure 4 As shown, the following steps are included:

[0094] Step S1: Collecting historical source programs of system backup according to the log files of the power digital system;

[0095] Step S2: preprocessing the collected historical source programs to generate standardized code files that conform to the prediction model;

[0096] Step S3: Write a static code analysis script to parse the standardized code file and extract key parameters and feature information in the code;

[0097] Step S4: Summarize the feature information of each source code to construct a data set, and build a multi-classification software defect detection model based on the pre-trained model;

[0098] Step S5: input the source program to be tested into the constructed multi-classification defect detection model for prediction, and generate a defect detection report according to the model prediction results;

[0099] Step S6: regularly collect source code data backed up in the system log, periodically update the multi-classification defect detection model, and improve system development based on the defect detection report;

[0100] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0101] The embodiment of the present application also provides a software defect detection device for a power digital system. It should be noted that the software defect detection device for a power digital system in the embodiment of the present application can be used to execute the software defect detection method for a power digital system provided in the embodiment of the present application. The device is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0102] The following is an introduction to a software defect detection device for a power digital system provided in an embodiment of the present application.

[0103] Figure 5 Schematic diagram of a software defect detection device for a power digital system according to an embodiment of the present application. Figure 5As shown, the device includes: a collection unit 10, a preprocessing unit 20, a parsing unit 30, a determination unit 40 and a prediction unit 50, the collection unit 10 is used to obtain the historical source program of the above-mentioned power digital system from the log file of the power digital system, and the above-mentioned historical source program includes all the source program codes of the above-mentioned power digital system in the development stage, and the defect code generated when the above-mentioned power digital system is running in the historical period; the preprocessing unit 20 is used to preprocess the source code content in the above-mentioned historical source program to generate a standardized code file that conforms to the prediction model; the parsing unit 30 is used to write an automated static code analysis script to analyze the source code in the above-mentioned standardized code file The content is automatically parsed to obtain a parsed code file, and feature indicator information of each source code in the above parsed code file is extracted; the determination unit 40 is used to determine the set of abstract syntax trees and their corresponding feature indicator information of all the above source codes in the above parsed code file as a feature data set, and use the above feature data set as input features to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for historical source programs; the prediction unit 50 is used to input the source program to be tested into the above multi-classification software defect detection model for prediction to obtain a prediction result, which includes the defect prediction situation and defect prediction type of the source program to be tested.

[0104] The software defect detection device for the electric power digital system of the present application comprises: a collection unit, a preprocessing unit, a parsing unit, a determination unit and a prediction unit, wherein the collection unit is used to obtain the historical source program of the electric power digital system from the log file of the electric power digital system, the historical source program includes all the source program codes of the electric power digital system in the development stage, and the defect code generated when the electric power digital system is running in the historical period; the preprocessing unit is used to preprocess the source code content in the historical source program to generate a standardized code file that conforms to the prediction model; the parsing unit is used to write an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extract the feature index information of each source code in the parsed code file; the determination unit is used to determine the set of abstract syntax trees of all source codes in the parsed code file and their corresponding feature index information as a feature data set, and use the feature data set as an input feature to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for the historical source program; the prediction unit is used to input the source program to be tested into the multi-classification software defect detection model for prediction to obtain a prediction result, and the prediction result includes the defect prediction situation and defect prediction type of the source program to be tested. The device integrates source code content and code metrics, constructs a feature sequence containing rich semantic information, and constructs a multi-classification software defect detection model based on pre-trained CodeBert. It effectively predicts the defects of the source code of the version to be released by mining the defect features of the historical version source code files, thereby reducing the possibility of failure after the system is launched. It adopts a parameter-efficient training method, which greatly reduces the parameter calculation steps in the model training process, so that efficient defect detection can still be achieved under limited computing resources. It solves the problem that the software defect detection method in the prior art is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high cost of building the detection model.

[0105] In some instances, the preprocessing unit includes a first checking module, a first screening module and a first processing module. The first checking module is used to perform an integrity check on the source code file in the above historical source program to obtain a complete source code and an incomplete source code. The above integrity check includes a logic integrity check and a function dependency integrity check. The first screening module is used to screen out the incomplete source code in the above historical source program to obtain a complete source code file that only includes the above complete source code. The first processing module is used to perform noise processing on the above complete source code file to remove the noise information of each source code in the above complete source code file to obtain the above standardized code file. Through integrity checking and noise processing, the complete source code can be screened out and the noise information can be removed, thereby improving the code quality and the reliability of the code.

[0106] In some examples, the parsing unit includes a first writing module, a first parsing module and a second processing module, wherein the first writing module is used to write the above-mentioned automated static code analysis script based on the third-party code analysis tool Joern library; the first parsing module is used to use the written automated static code analysis script to automatically parse the above-mentioned standardized code file to obtain the parsed code file; the second processing module is used to extract the abstract syntax tree and the characteristic index information of each source code in the above-mentioned parsed code file, wherein the above-mentioned abstract syntax tree is an abstract representation sequence that represents the syntax structure of the source code in a tree structure, and the above-mentioned characteristic index information includes the original index, the Halstead index, the cyclomatic complexity index and the maintainability index, wherein the above-mentioned original index is the unprocessed data or measurement value directly collected from the above-mentioned historical source program, the above-mentioned Halstead index is a software metric index used to measure the complexity and scale of the software code, the above-mentioned cyclomatic complexity index is used to measure the control flow complexity and structured degree in the source code file, and the above-mentioned maintainability index is used to evaluate the maintainability and readability of the software code. The method integrates the abstract syntax tree representation sequence and the code metric index of the source code to construct a characteristic sequence containing rich semantic information.

[0107] In some instances, the determination unit includes a first determination module, a third processing module, a first fusion module, a fourth processing module and a first training module. The first determination module is used to determine the code defect type based on all the above source codes in the above parsed code file and the error log in the system log file; the third processing module is used to use a text embedding model to map the abstract syntax tree representation sequence of all the above source codes in the above parsed code file to a continuous vector space to obtain the digital vector of each of the above source codes; the first fusion module is used to fuse the feature index information of each of the above source codes with the above digital vector to obtain the feature sequence of each of the above source codes; the fourth processing module is used to build a prediction model architecture, first using a pre-trained CodeBert model to further extract the code semantic features of the input feature sequence, and constructing a random forest classifier to predict the extracted semantic features; the first training module is used to use the Dora fine-tuning training method in the model training process to train the pre-trained model according to the above feature data set and the above code defect type to obtain the above multi-classification software defect detection model. This method constructs a multi-classification software defect detection model based on pre-trained CodeBert, and effectively predicts the defects of the source code of the version to be released by mining the defect features of the historical version source code files, thereby reducing the possibility of failure after the system is launched.

[0108] In some examples, the first determination module includes a first analysis module, a fifth processing module, a second determination module, and a third determination module. The first analysis module is used to perform statistical analysis on the defects of all the above-mentioned source codes in the above-mentioned parsed code file according to the error log to obtain the occurrence frequency of each source code defect; the fifth processing module is used to sort the occurrence frequency of each source code defect from large to small according to the occurrence frequency of each source code defect; the second determination module is used to determine the labels of the first to fifth source code defects as the corresponding code defect types; the third determination module is used to uniformly determine the labels of the sixth type of source code defects as other defects in the above-mentioned code defect types, and the sixth type of source code defects are all the above-mentioned source code defects except the first to fifth types of source code defects. By statistically analyzing the occurrence frequency of source code defects, the specific conditions of various defects can be more intuitively understood.

[0109] In some instances, the device further includes a sixth processing module, which is used to input the source program to be tested into the multi-classification software defect detection model for prediction, and after obtaining the prediction result, generate a detection report representing the source program to be tested in the form of a JSON file according to the prediction result, wherein the key value of the JSON file is the file name of each code in the source program to be tested, and the value value is the defect prediction corresponding to each code in the source program to be tested, and the defect prediction is defective or non-defective. When the defect prediction is defective, the label information of the defect is indicated. The JSON file format is concise and clear, easy to read and parse, and can be conveniently processed and analyzed automatically through code.

[0110] In some instances, the device further includes a first acquisition module, a fourth determination module, a seventh processing module, and an eighth processing module. The first acquisition module is used to periodically acquire the updated source code data backed up in the log file of the power digital system; the fourth determination module is used to determine the current defect detection accuracy of the multi-classification software defect detection model at the current moment; the seventh processing module is used to integrate the historical source program with the updated source code data to obtain an updated source code file when the current defect detection accuracy of the multi-classification software defect detection model is less than or equal to the preset accuracy; the eighth processing module is used to re-fine-tune and train the multi-classification software defect detection model using an incremental learning method and the updated source code file to achieve an updated defect detection model. This method timely integrates the historical source program and the updated source code data and retrains the model when the current defect detection accuracy does not meet the standard, which helps to improve the accuracy of defect detection.

[0111] The software defect detection device for the power digital system includes a processor and a memory. The acquisition unit and the like are stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions. The modules are all located in the same processor; or, the modules are located in different processors in any combination.

[0112] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the kernel parameters are adjusted to solve the problem that the software defect detection method in the prior art is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high detection model construction costs.

[0113] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0114] An embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the software defect detection method for the power digital system.

[0115] Specifically, the software defect detection method for the power digital system includes:

[0116] Step S201, obtaining a historical source program of the power digital system from a log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in the development stage, and defect codes generated when the power digital system is running in a historical period;

[0117] Specifically, by analyzing historical source programs to understand possible defects in the power digital system, a large amount of source code is provided for subsequent efficient parameter detection, which helps to improve the stability and reliability of the system.

[0118] Step S202, preprocessing the source code content in the above historical source program to generate a standardized code file that conforms to the prediction model;

[0119] Specifically, through integrity checking and noise processing, the quality of the source code can be effectively improved and the logical integrity of the source code can be ensured.

[0120] Step S203, writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file;

[0121] Specifically, the automated static code analysis script can quickly parse a large number of source code files, saving manpower and time costs, and can extract feature indicator information from the source code files, providing a basis for the subsequent construction of software defect detection models.

[0122] Step S204, determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as input features to fine-tune the pre-trained model, thereby obtaining a multi-classification software defect detection model for the historical source program;

[0123] Specifically, the multi-classification software defect detection model obtained through training can detect software defects more accurately, help developers find and fix software defects in a timely manner, and improve software quality.

[0124] Step S205 , input the source program to be tested into the above-mentioned multi-classification software defect detection model for prediction to obtain a prediction result, which includes the defect prediction status and defect prediction type of the source program to be tested.

[0125] Specifically, the method adopts Dora's fine-tuning training method, which greatly reduces the parameter calculation steps in the model training process, so that the present invention can still achieve efficient defect detection under limited computing resource conditions.

[0126] An embodiment of the present invention provides a processor, and the processor is used to run a program, wherein the software defect detection method for a power digital system is executed when the program is run.

[0127] Specifically, the software defect detection method for the power digital system includes:

[0128] Step S201, obtaining a historical source program of the power digital system from a log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in the development stage, and defect codes generated when the power digital system is running in a historical period;

[0129] Specifically, by analyzing historical source programs to understand possible defects in the power digital system, a large amount of source code is provided for subsequent efficient parameter detection, which helps to improve the stability and reliability of the system.

[0130] Step S202, preprocessing the source code content in the above historical source program to generate a standardized code file that conforms to the prediction model;

[0131] Specifically, through integrity checking and noise processing, the quality of the source code can be effectively improved and the logical integrity of the source code can be ensured.

[0132] Step S203, writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file;

[0133] Specifically, the automated static code analysis script can quickly parse a large number of source code files, saving manpower and time costs, and can extract feature indicator information from the source code files, providing a basis for the subsequent construction of software defect detection models.

[0134] Step S204, determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as input features to fine-tune the pre-trained model, thereby obtaining a multi-classification software defect detection model for the historical source program;

[0135] Specifically, the multi-classification software defect detection model obtained through training can detect software defects more accurately, help developers find and fix software defects in a timely manner, and improve software quality.

[0136] Step S205 , input the source program to be tested into the above-mentioned multi-classification software defect detection model for prediction to obtain a prediction result, which includes the defect prediction status and defect prediction type of the source program to be tested.

[0137] Specifically, the method adopts Dora's fine-tuning training method, which greatly reduces the parameter calculation steps in the model training process, so that the present invention can still achieve efficient defect detection under limited computing resource conditions.

[0138] An embodiment of the present invention provides a device, the device including a processor, a memory, and a program stored in the memory and executable on the processor, and when the processor executes the program, at least the following steps are implemented:

[0139] Step S201, obtaining a historical source program of the power digital system from a log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in the development stage, and defect codes generated when the power digital system is running in a historical period;

[0140] Specifically, by analyzing historical source programs to understand possible defects in the power digital system, a large amount of source code is provided for subsequent efficient parameter detection, which helps to improve the stability and reliability of the system.

[0141] Step S202, preprocessing the source code content in the above historical source program to generate a standardized code file that conforms to the prediction model;

[0142] Specifically, through integrity checking and noise processing, the quality of the source code can be effectively improved and the logical integrity of the source code can be ensured.

[0143] Step S203, writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file;

[0144] Specifically, the automated static code analysis script can quickly parse a large number of source code files, saving manpower and time costs, and can extract feature indicator information from the source code files, providing a basis for the subsequent construction of software defect detection models.

[0145] Step S204, determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as input features to fine-tune the pre-trained model, thereby obtaining a multi-classification software defect detection model for the historical source program;

[0146] Specifically, the multi-classification software defect detection model obtained through training can detect software defects more accurately, help developers find and fix software defects in a timely manner, and improve software quality.

[0147] Step S205 , input the source program to be tested into the above-mentioned multi-classification software defect detection model for prediction to obtain a prediction result, which includes the defect prediction status and defect prediction type of the source program to be tested.

[0148] Specifically, the method adopts Dora's fine-tuning training method, which greatly reduces the parameter calculation steps in the model training process, so that the present invention can still achieve efficient defect detection under limited computing resource conditions.

[0149] The devices in this article can be servers, PCs, PADs, mobile phones, etc.

[0150] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initializing at least the following method steps:

[0151] Step S201, obtaining a historical source program of the power digital system from a log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in the development stage, and defect codes generated when the power digital system is running in a historical period;

[0152] Specifically, by analyzing historical source programs to understand possible defects in the power digital system, a large amount of source code is provided for subsequent efficient parameter detection, which helps to improve the stability and reliability of the system.

[0153] Step S202, preprocessing the source code content in the above historical source program to generate a standardized code file that conforms to the prediction model;

[0154] Specifically, through integrity checking and noise processing, the quality of the source code can be effectively improved and the logical integrity of the source code can be ensured.

[0155] Step S203, writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature index information of each source code in the parsed code file;

[0156] Specifically, the automated static code analysis script can quickly parse a large number of source code files, saving manpower and time costs, and can extract feature indicator information from the source code files, providing a basis for the subsequent construction of software defect detection models.

[0157] Step S204, determining a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and using the feature data set as input features to fine-tune the pre-trained model, thereby obtaining a multi-classification software defect detection model for the historical source program;

[0158] Specifically, the multi-classification software defect detection model obtained through training can detect software defects more accurately, help developers find and fix software defects in a timely manner, and improve software quality.

[0159] Step S205 , input the source program to be tested into the above-mentioned multi-classification software defect detection model for prediction to obtain a prediction result, which includes the defect prediction status and defect prediction type of the source program to be tested.

[0160] Specifically, the method adopts Dora's fine-tuning training method, which greatly reduces the parameter calculation steps in the model training process, so that the present invention can still achieve efficient defect detection under limited computing resource conditions.

[0161] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0162] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0163] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0166] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0167] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0168] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0169] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0170] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:

[0171] 1) The software defect detection method for the electric power digital system of the present application first obtains the historical source program of the electric power digital system from the log file of the electric power digital system, and the historical source program includes all the source program codes of the electric power digital system in the development stage, and the defect codes generated when the electric power digital system is running in the historical period; then the source code content in the historical source program is preprocessed to generate a standardized code file that conforms to the prediction model; an automated static code analysis script is written to automatically parse the source code content in the standardized code file to obtain a parsed code file, and the feature index information of each source code in the parsed code file is extracted; then the set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information is determined as a feature data set, and the feature data set is used as the input feature to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for the historical source program; finally, the source program to be tested is input into the multi-classification software defect detection model for prediction to obtain a prediction result, and the prediction result includes the defect prediction situation and defect prediction type of the source program to be tested. This method integrates source code content and code metrics, constructs a feature sequence containing rich semantic information, and constructs a multi-classification software defect detection model based on pre-trained CodeBert. It effectively predicts the defects of the source code of the version to be released by mining the defect features of the historical version source code files, thereby reducing the possibility of failure after the system is launched. The Dora fine-tuning method is adopted to greatly reduce the parameter calculation steps in the model training process, so that efficient defect detection can still be achieved under limited computing resources. It solves the problem that the software defect detection method in the existing technology is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high cost of building the detection model.

[0172] 2) The software defect detection device for the power digital system of the present application includes: a collection unit, a preprocessing unit, a parsing unit, a determination unit and a prediction unit. The collection unit is used to obtain the historical source program of the power digital system from the log file of the power digital system. The historical source program includes all the source program codes of the power digital system in the development stage and the defect code generated when the power digital system is running in the historical period; the preprocessing unit is used to preprocess the source code content in the historical source program to generate a standardized code file that conforms to the prediction model; the parsing unit is used to write an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extract the feature index information of each source code in the parsed code file; the determination unit is used to determine the set of abstract syntax trees of all source codes in the parsed code file and their corresponding feature index information as a feature data set, and use the feature data set as an input feature to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for the historical source program; the prediction unit is used to input the source program to be tested into the multi-classification software defect detection model for prediction to obtain a prediction result, and the prediction result includes the defect prediction situation and defect prediction type of the source program to be tested. The device integrates source code content and code metrics, constructs a feature sequence containing rich semantic information, and constructs a multi-classification software defect detection model based on pre-trained CodeBert. It effectively predicts the defects of the source code of the version to be released by mining the defect features of the historical version source code files, thereby reducing the possibility of failure after the system is launched. It adopts a parameter-efficient training method, which greatly reduces the parameter calculation steps in the model training process, so that efficient defect detection can still be achieved under limited computing resources. It solves the problem that the software defect detection method in the prior art is weak in capturing the semantics of code defects, resulting in inaccurate prediction results and high cost of building the detection model.

[0173] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A software defect detection method for a power digital system, characterized in that: include: Acquire the historical source program of the power digital system from the log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in the development stage and defect codes generated when the power digital system is running in the historical period; Preprocessing the source code content in the historical source program to generate a standardized code file that conforms to the prediction model; Writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature indicator information of each source code in the parsed code file; Determine a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and use the feature data set as input features to fine-tune the pre-trained model to obtain a multi-classification software defect detection model for historical source programs; The source program to be tested is input into the multi-classification software defect detection model for prediction to obtain a prediction result, which includes a defect prediction situation and a defect prediction type of the source program to be tested.

2. The method according to claim 1, characterized in that Preprocess the source code content in the historical source program to generate a standardized code file that conforms to the prediction model, including: Performing integrity check on source code files in the historical source program to obtain complete source code and incomplete source code, wherein the integrity check includes a logic integrity check and a function dependency integrity check; Screening out the incomplete source code in the historical source program to obtain a complete source code file including only the complete source code; The complete source code file is subjected to noise processing to remove noise information of each source code in the complete source code file to obtain the standardized code file.

3. The method according to claim 1, characterized in that Writing an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and extracting feature indicator information of each source code in the parsed code file, including: Writing the automated static code analysis script based on the third-party code analysis tool Joern library; The standardized code file is automatically parsed using a written automated static code analysis script to obtain a parsed code file; The abstract syntax tree and characteristic index information of each source code in the parsed code file are extracted, wherein the abstract syntax tree is an abstract representation sequence that represents the syntax structure of the source code in a tree structure, and the characteristic index information includes original index, Halstead index, cyclomatic complexity index and maintainability index, wherein the original index is unprocessed data or measurement value directly collected from the historical source program, the Halstead index is a software metric used to measure the complexity and scale of software code, the cyclomatic complexity index is used to measure the control flow complexity and structured degree in the source code file, and the maintainability index is used to evaluate the maintainability and readability of the software code.

4. The method according to claim 1, characterized in that: The feature data set is used as input features to fine-tune the pre-trained model, and the resulting multi-classification software defect detection model for historical source programs includes: Determine the type of code defect based on all the source codes in the parsed code file and the error log in the system log file; Using a text embedding model, the abstract syntax tree representation sequences of all the source codes in the parsed code file are mapped to a continuous vector space to obtain a digital vector of each source code; Merging the characteristic index information of each source code with the digital vector to obtain a characteristic sequence of each source code; Build the prediction model architecture. First, use the pre-trained CodeBert model to further extract the code semantic features of the input feature sequence, and build a random forest classifier to predict the extracted semantic features. During the model training process, the Dora fine-tuning training method is adopted to train the pre-trained model according to the feature data set and the code defect type to obtain the multi-classification software defect detection model.

5. The method according to claim 4, characterized in that Determine the code defect type based on all the source codes in the parsed code file and the error log in the system log file, including: Performing statistical analysis on all source code defects in the parsed code file according to the error log to obtain the occurrence frequency of each source code defect; Sort the occurrence frequencies of the source code defects from large to small according to the occurrence frequencies of the source code defects; Determine the labels of the first to fifth types of source code defects as corresponding code defect types; The labels of the sixth category of source code defects are uniformly determined as other defects in the code defect type, and the sixth category of source code defects are all the source code defects except the first to fifth category of source code defects.

6. The method according to claim 1, characterized in that After inputting the source program to be tested into the multi-classification software defect detection model for prediction and obtaining the prediction result, the method further includes: According to the prediction result, a detection report representing the source program to be tested is generated in the form of a JSON file, wherein the key value of the JSON file is the file name of each code in the source program to be tested, and the value value is the defect prediction corresponding to each code of the source program to be tested, and the defect prediction status is defective or non-defective. When the defect prediction status is defective, the label information of the defect is indicated.

7. The method according to claim 1, characterized in that The method further comprises: regularly obtaining updated source code data backed up in a log file of the power digital system; Determine the current defect detection accuracy of the multi-classification software defect detection model at the current moment; In the case where the current defect detection accuracy of the multi-classification software defect detection model is less than or equal to a preset accuracy, integrating the historical source program with the updated source code data to obtain an updated source code file; The incremental learning method and the updated source code file are used to re-fine-tune and train the multi-classification software defect detection model to achieve an updated defect detection model.

8. A software defect detection device for a power digital system, characterized in that: include: A collection unit, used for acquiring a historical source program of the power digital system from a log file of the power digital system, wherein the historical source program includes all source program codes of the power digital system in a development stage and defect codes generated when the power digital system is running in a historical period; A preprocessing unit, used to preprocess the source code content in the historical source program to generate a standardized code file that conforms to the prediction model; A parsing unit, used to write an automated static code analysis script to automatically parse the source code content in the standardized code file to obtain a parsed code file, and to extract feature indicator information of each source code in the parsed code file; A determination unit, configured to determine a set of abstract syntax trees of all the source codes in the parsed code file and their corresponding feature index information as a feature data set, and use the feature data set as input features to fine-tune the pre-trained model, thereby obtaining a multi-classification software defect detection model for the historical source program; The prediction unit is used to input the source program to be tested into the multi-classification software defect detection model for prediction to obtain a prediction result, wherein the prediction result includes the defect prediction situation and defect prediction type of the source program to be tested.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the software defect detection method for a power digital system according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing the software defect detection method for a power digital system as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Software source code defect detection method and system, electronic equipment and storage medium

    CN113641586A

  • Software integration evaluation method based on machine learning and static analysis

    CN114490344A

  • Cross-project defect prediction method and system based on code semantics and grammar

    CN117149624A

  • Software defect prediction method and model, terminal and storage medium

    CN118245373A