Software detection method and device
By using the detection model and anomaly positioning knowledge base in software detection to obtain and analyze code attribute information, the problems of low detection accuracy and long cycle time in the existing technology are solved, and efficient and accurate software detection and modification suggestion generation are achieved.
Patent Information
- Application Number
- CN202411402386.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-01-24
AI Technical Summary
Due to the limitations of personal experience, the accuracy of the existing software detection methods is not high, resulting in repeated modification and verification problems. The period of solving abnormal codes is long, which affects the project development cycle and cannot meet actual needs.
By obtaining the attribute information set to detect the code, and enter the pre -built detection model to obtain an abnormal code information. Then, find the corresponding scene optimization solution from the abnormal positioning knowledge base, generate a prompt word and enter the detection model, and obtain the modification suggestions of the abnormal code.
A complete and accurate software detection method is implemented, which can not only detect abnormal code information, but also provide personalized and accurate modification suggestions, and improve test efficiency and project development progress.
Smart Images

Figure CN119357013A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for software detection. Background Art
[0002] Software detection is an important and indispensable stage in the software project development process. Existing software detection methods usually rely on the coding experience of R&D personnel, manually combing and analyzing the code, or using the code print log to detect software code anomalies.
[0003] In the process of implementing the present invention, the inventors found that the prior art has the following problems:
[0004] The existing software detection methods, due to the limitations of personal experience, have low accuracy in judgment and detection, and there will be problems of repeated modification and repeated verification. The cycle for solving abnormal codes is long, which affects the project development cycle and cannot meet actual needs well. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and device for software detection, which realizes a complete and accurate software detection. Through the detection model, not only the abnormal code information is detected, but also the modification suggestions for the abnormal code are obtained. In addition, the prompt words of the scenario optimization solution generated based on the abnormal location knowledge base ensure the personalization and accuracy of the modification suggestions output by the detection model.
[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for software detection is provided, comprising:
[0007] Acquire a code to be detected, extract and process attribute information of the code to be detected, and generate an attribute information set of the code to be detected;
[0008] Input the attribute information set and the code to be detected into a pre-built detection model, and obtain abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model;
[0009] According to the abnormal code information, searching for a scenario optimization solution corresponding to the abnormal code information from a pre-built abnormal location knowledge base;
[0010] According to the scenario optimization solution, prompt words of the scenario optimization solution are generated, and the prompt words are input into the detection model to obtain modification suggestions for the abnormal code output by the detection model.
[0011] Optionally, the attribute information set is stored in the form of a code graph; attribute information of the code to be detected is extracted and processed to generate the attribute information set of the code to be detected, including: extracting parameter variable information, code method information and summary information of the code to be detected from the code to be detected; screening the parameter variable information, code method information and summary information to obtain key parameter information, key code method information and key summary information; using the key parameter information, the key code method information and the key summary information as nodes, jointly associating them with the identification node of the code to be detected to generate a code graph of the code to be detected.
[0012] Optionally, the attribute information set and the code to be detected are input into a pre-built detection model to obtain abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model, including: inputting the code map and the code to be detected into the detection model, and the detection model performs parameter transfer analysis, variable correlation analysis, call chain analysis and control flow analysis on the code to be detected based on the code map to obtain abnormal code information corresponding to the abnormal code output by the detection model.
[0013] Optionally, based on the exception code information, a scenario optimization solution corresponding to the exception code information is searched from a pre-built exception location knowledge base, including: searching from the exception location knowledge base for a location category that matches the exception category in the exception code information; determining the business scenario corresponding to the exception code based on the code attribution information in the exception code information; and searching from the exception location knowledge base for a scenario optimization solution corresponding to the location category in the business scenario.
[0014] Optionally, based on the scene optimization plan, prompt words for the scene optimization plan are generated, including: searching for a prompt word template that matches the scene information in the scene optimization plan from a preset prompt word template library; filling the optimization elements in the scene optimization plan into the to-be-filled positions in the prompt word template to obtain the prompt words for the scene optimization plan.
[0015] Optionally, the detection model is constructed in the following manner: selecting a training code, and slicing the training code into segments to obtain multiple code slices; marking each code slice by judging whether the code segment in each code slice is normal, and then generating a sample set; using the sample set to train a predefined initial detection model, and fine-tuning the parameters of the trained detection model to obtain the detection model with the ability to detect abnormal code.
[0016] Optionally, after obtaining the exception code information corresponding to the exception code in the code to be detected output by the detection model, the method also includes: pruning and filtering the exception code information to obtain key information of the exception code after pruning and filtering, so as to use the key information of the exception code to search for the scenario optimization solution corresponding to the exception code information from the exception location knowledge base.
[0017] Optionally, the acquisition of the code to be detected and the generation of the attribute information set are implemented using a streaming processing tool; after generating the attribute information set of the code to be detected, the method also includes: storing the attribute information set in a column storage database, and when using the detection model to detect abnormal codes, querying the attribute information set from the column storage database.
[0018] According to a second aspect of an embodiment of the present invention, there is provided a software detection device, comprising:
[0019] An attribute information set generation module is used to obtain a code to be detected, extract and process attribute information of the code to be detected, and generate an attribute information set of the code to be detected;
[0020] An abnormal code detection module, used for inputting the attribute information set and the code to be detected into a pre-built detection model, and obtaining abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model;
[0021] An optimization solution determination module is used to search for a scenario optimization solution corresponding to the abnormal code information from a pre-built abnormality location knowledge base according to the abnormal code information;
[0022] The modification suggestion acquisition module is used to generate prompt words of the scenario optimization solution according to the scenario optimization solution, and input the prompt words into the detection model to obtain modification suggestions for the abnormal code output by the detection model.
[0023] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for software detection, including:
[0024] one or more processors;
[0025] a storage device for storing one or more programs,
[0026] When the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the embodiment of the present invention.
[0027] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0028] According to a fifth aspect of an embodiment of the present invention, there is provided a computer program product, including a computer program, wherein when the computer program is executed by a processor, the method provided in the first aspect of the embodiment of the present invention is implemented.
[0029] An embodiment of the invention has the following advantages or beneficial effects: by obtaining the code to be detected, and extracting and processing the attribute information of the code to be detected, an attribute information set of the code to be detected is generated; the attribute information set and the code to be detected are input into a pre-built detection model to obtain the abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model; according to the abnormal code information, the scenario optimization solution corresponding to the abnormal code information is searched from a pre-built abnormal location knowledge base; according to the scenario optimization solution, prompt words of the scenario optimization solution are generated, and the prompt words are input into the detection model to obtain the modification suggestions of the abnormal code output by the detection model. A technical solution realizes a complete and accurate software detection method. Through the detection model, not only the abnormal code information is detected, but also the modification suggestions of the abnormal code are obtained. In addition, the prompt words of the scenario optimization solution generated based on the abnormal location knowledge base ensure the personalization and accuracy of the modification suggestions output by the detection model. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0031] Figure 1 is a schematic diagram of the main process of the software detection method according to an embodiment of the present invention;
[0032] Figure 2 is a flowchart of a method for software detection according to a reference embodiment of the present invention;
[0033] Figure 3 is a schematic diagram of a code spectrum of an embodiment of the present invention;
[0034] Figure 4 It is a schematic diagram of the generation process of the code map of an embodiment of the present invention;
[0035] Figure 5 is a schematic diagram of a code detection process according to an embodiment of the present invention;
[0036] Figure 6 is a schematic diagram of prompt word generation according to an embodiment of the present invention;
[0037] Figure 7 is a schematic diagram of the overall functional architecture of software detection according to an embodiment of the present invention;
[0038] Figure 8 is a schematic diagram of main modules of a software detection device according to an embodiment of the present invention;
[0039] Fig. 9 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0040] Fig.10 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0041] It should be noted that the acquisition, storage and application of user personal information involved in the technical solution of the present disclosure are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0042] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0043] The existing software detection methods, due to the limitations of personal experience, have low accuracy in judgment and detection, and there will be problems of repeated modification and repeated verification. The cycle for solving abnormal codes is long, which affects the project development cycle and cannot meet actual needs well.
[0044] In order to solve the above-mentioned problems existing in the prior art, the present invention proposes a method for software detection, which first uses a detection model to obtain abnormal code information in the code to be detected based on an attribute information set generated by the code to be detected, and then searches for a scenario optimization solution corresponding to the abnormal code information from an abnormality location knowledge base, and generates prompt words for the scenario optimization solution. Finally, the prompt words and the detection model are used to obtain modification suggestions for the abnormal code, thereby realizing a complete and accurate software detection. The detection model not only detects the abnormal code information, but also obtains modification suggestions for the abnormal code. In addition, the prompt words of the scenario optimization solution generated based on the abnormality location knowledge base ensure the personalization and accuracy of the modification suggestions output by the detection model.
[0045] Figure 1 is a schematic diagram of the main process of the software detection method according to an embodiment of the present invention, such as Figure 1 As shown, the software detection method of the embodiment of the present invention includes the following steps S101 to S104.
[0046] Step S101: Acquire a code to be detected, extract and process attribute information of the code to be detected, and generate an attribute information set of the code to be detected.
[0047] Specifically, in the development process of a software project, R&D personnel or software quality management personnel need to perform code detection on the completed code segments according to the project nodes to check whether there are any irregular, erroneous, or abnormal codes with execution risks in the software code. The detection system receives the software detection task and obtains the code to be detected by parsing the received software detection task, or indirectly obtains the code to be detected by parsing the storage address of the code to be detected obtained by the software detection task.
[0048] Taking into account the different sizes of the codes to be tested, in order to facilitate the subsequent detection of the codes to be tested, the code attribute information of the codes to be tested is first extracted, such as the total number of code lines, version number, input and output parameters involved in the code, etc., and classified according to the extracted information category. For example, the total number of code lines and version number belong to the summary information category and are divided into the same group. Finally, the attribute information of various categories is standardized and processed to generate a standardized and clearly structured attribute information set.
[0049] According to one embodiment of the present invention, the acquisition of the code to be detected and the generation of the attribute information set are implemented using a streaming processing tool; after generating the attribute information set of the code to be detected, the method also includes: storing the attribute information set in a column storage database, and when using the detection model to detect abnormal code, querying the attribute information set from the column storage database.
[0050] Specifically, considering that the detection system is faced with massive code resources, in order to improve the efficiency and reliability of software detection, the embodiment of the present invention uses a streaming processing tool, such as the Flink module, to be responsible for data processing in the entire detection system, obtains the code to be detected through Flink, uses the Flink program to read the code to be detected as a data stream, extracts and processes the attribute information, and generates an attribute information set.
[0051] In addition, after generating the attribute information set, a column storage database, such as ClickHouse, is used to store the attribute information set. This not only uses an efficient compression algorithm to reduce data storage occupancy, but also has high concurrency query capabilities. When using the detection model to detect abnormal code, the attribute information set of the code to be detected can be obtained from the column storage database efficiently and quickly, providing more assistance for the software detection of the embodiment of the present invention.
[0052] Step S102: input the attribute information set and the code to be detected into a pre-built detection model, and obtain abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model.
[0053] Specifically, the embodiment of the present invention uses a large model learning algorithm to perform anomaly detection on the code to be detected. Specifically, the bidirectional encoding representation model BERT model can be used to input the attribute information set and the code to be detected into the detection model. The attribute information set is mainly used to prompt the detection model with the technical direction of analyzing and detecting the code to be detected. For example, if the attribute information contains the input and output parameters of the code to be detected, then the detection model will detect whether there are anomalies in the code related to the parameter definition, parameter usage, and parameter transfer of the output and input parameters. After traversing all the information in the attribute information set to analyze the code to be detected, the model will obtain all the abnormal codes in the code for summary, and output the summarized abnormal codes.
[0054] According to one embodiment of the present invention, the detection model is constructed in the following manner: selecting a training code, and slicing the training code into segments to obtain a plurality of code slices; marking each code slice by judging whether the code segment in each code slice is normal, and then generating a sample set; using the sample set to train a predefined initial detection model, and fine-tuning the parameters of the trained detection model to obtain the detection model with the ability to detect abnormal codes.
[0055] Specifically, the detection model of the embodiment of the present invention needs to be trained and fine-tuned before use. According to the business field to which the software detection task belongs, the training code of the same business field is selected, the training code is segmented and sliced, the attribute information of the code is extracted from each code slice, the attribute information set of each code slice is generated, and the code slices are marked whether they are abnormal. The specific format example is as follows:
[0056] { "slice": [{"line":"line code content","row":"line number"}], "result":{"label":"sample label","module_name":"code base name","commit_id":"code version","file_path":"file name","risk_happend_line":"line where the exception occurred"} }; Combined with the specific code content of each code slice, a sample set is generated.
[0057] Furthermore, the sample set is divided into training set, validation set and test set according to the preset ratio of training set, validation set and test set. The training set is used to train the pre-defined initial detection model, and the validation set and test set are used to perform parameter fine-tuning and performance testing on the trained detection model. When the performance of the detection model meets the requirements, a detection model with the ability to detect abnormal codes is obtained.
[0058] The embodiment of the present invention utilizes the automatic iteration and learning capabilities of the large model. After the model is put into use, the training set can be updated based on user feedback on the model output results, thereby realizing automatic iteration and updating of the model to adaptively meet various needs of software detection.
[0059] According to another embodiment of the present invention, after obtaining the exception code information corresponding to the exception code in the code to be detected output by the detection model, the method also includes: pruning and filtering the exception code information to obtain key information of the exception code after pruning and filtering, so as to use the key information of the exception code to search for a scenario optimization solution corresponding to the exception code information from the exception location knowledge base.
[0060] Specifically, after obtaining the abnormal code information corresponding to the abnormal code output by the detection model, the abnormal code output by the detection model can be directly fed back to the user. The abnormal code information can also be screened, and the pruning and filtering algorithm of the business system is called to prune and filter the acquired abnormal code information to filter out the key information in all abnormal code information. It can be understood that the pruning and filtering of the embodiment of the present invention can be directly deployed in the output module of the detection model in addition to being deployed in the detection system, and can be selected as needed; and the abnormal code information mentioned in the embodiment of the present invention can also be understood as abnormal code features, such as the position information / features of the abnormal code in the detection code, the abnormal category information / features of the abnormal code, etc., and accordingly, the abnormal code key information obtained after pruning and filtering can also be understood as abnormal code key features. Then, when searching for scene optimization solutions in the subsequent search, the abnormal code key information after pruning and filtering can be used to find the scene optimization solutions corresponding to the key information.
[0061] Step S103: According to the exception code information, a scenario optimization solution corresponding to the exception code information is searched from a pre-built exception location knowledge base.
[0062] Specifically, although the detection model outputs the exception code information of the exception code existing in the code, and the detection model has the ability to output corresponding modification suggestions for the exception code, since the detection model is an open and general model, the modification suggestions directly given are general suggestions, and users often need to make appropriate modifications before they can be used in specific code programs. In order to solve this problem, the embodiment of the present invention pre-constructs an exception location knowledge base for each specific business scenario code, and the R&D personnel of this business scenario provide corresponding scenario optimization solutions based on historical exception code records to construct an exception location knowledge base. It can be understood that the exception location knowledge base customized by the embodiment of the present invention can be implemented in the form of components for easier use.
[0063] For example, in a warehousing business scenario, if an inventory quantity parameter in the code method body occupies a large memory space of 10M, then this inventory quantity parameter has potential performance risks, and this record will be added to the exception location knowledge base. Accordingly, R&D personnel will provide scenario optimization solutions for the warehousing business scenario based on the exception problem, such as re-releasing the memory space of the inventory quantity parameter and allocating 40% to store the inventory information forms of other SKU items.
[0064] From the above, it can be seen that the anomaly location knowledge base provides common exception code examples and corresponding scenario optimization solutions based on specific business scenarios. It can not only be used to locate anomalies, but also to query the corresponding scenario optimization solutions, providing scenario-based information support for the detection model of the embodiment of the present invention to generate accurate exception code modification suggestions.
[0065] Furthermore, according to the exception code information of the exception code output by the detection model, the exception code record matching the exception code information is searched from the exception location knowledge base, and then the corresponding scenario optimization solution is obtained.
[0066] Step S104: Generate prompt words for the scenario optimization solution according to the scenario optimization solution, input the prompt words into the detection model, and obtain modification suggestions for the abnormal code output by the detection model.
[0067] Specifically, the detection system generates prompt words for the queried scenario optimization solution according to the scenario optimization solution corresponding to the abnormal code found in the abnormal location knowledge base and the prompt word generation strategy agreed upon by the detection model. The detection model's ability to generate modification suggestions is utilized, and prompt words that are easy for the detection model to understand are input into the detection model. The detection model generates modification suggestions for the abnormal code in a specific business scenario based on the received prompt words and the abnormal code detected above. Normally, the modification suggestions in the embodiments of the present invention are directly usable modification codes, and of course, they can also be text guidance for code modification, with modification codes being preferred, so that R&D personnel can directly use the modification suggestions to replace the abnormal code, which is more convenient and efficient.
[0068] Figure 2 1 is a flowchart of a method for software detection according to a reference embodiment of the present invention. As another embodiment of the present invention, Figure 2 As shown, the software detection method may include:
[0069] Step S201: obtain a code to be detected, extract and process attribute information of the code to be detected, and generate an attribute information set of the code to be detected, wherein the attribute information set is stored in the form of a code graph.
[0070] Specifically, considering that the attribute information set of the code to be detected contains multi-dimensional information such as the variables of the code, the library where the code is located, and the method body information of the code, in order to improve the readability of the attribute information set and improve the efficiency of the detection model in reading the attribute information, the embodiment of the present invention concretizes the attribute information set in the form of a code map. Each attribute information in the attribute information set of a code to be detected is organized according to the agreed data structure of the code map to generate a code map representing the code attribute information set.
[0071] The embodiment of the present invention converts code attribute information into a code map in graphic form, which greatly improves the readability and reading efficiency of the attribute information, facilitates the detection model to quickly parse the attribute information of the code to be detected, and improves the efficiency of the detection model in detecting abnormal codes.
[0072] According to one embodiment of the present invention, attribute information of the code to be detected is extracted and processed to generate an attribute information set of the code to be detected, including: extracting parameter variable information, code method information and summary information of the code to be detected from the code to be detected; screening the parameter variable information, code method information and the summary information to obtain key parameter information, key code method information and key summary information; using the key parameter information, the key code method information and the key summary information as nodes, jointly associating them with the identification node of the code to be detected to generate a code graph of the code to be detected.
[0073] Specifically, for the construction of the code map, different extraction rules are first configured according to the needs of the business scenario. Different extraction rules stipulate different extraction contents, as well as screening strategies based on the specific attribute information extracted. The business scenario corresponding to the code to be detected is obtained, and the corresponding extraction rules are determined according to the business scenario. The business scenario of the embodiment of the present invention uses the default extraction rules to extract all parameter variable information contained in the code (such as parameter name, parameter type, code method body where the parameter is located, parameter initial value, etc.), code method information (number of lines of the method body, type of the method body, name of the method body, location of the method body in the code, whether the method body has an external call relationship, etc.) and code summary information (library to which the code belongs, code version, class to which the code belongs, total number of lines of code, interface composition of the code, etc.) from the code to be detected.
[0074] Further, according to the screening strategy in the extraction rules, the screening strategy of the embodiment of the present invention can screen key attributes from each extraction category (for example, remove non-key default parameters from all parameter variables in the above-mentioned parameter variable information), or screen key information from all attribute information (for example, remove non-key information such as parameter initial values from parameter variable information). Of course, the two screening methods can also be used in combination, and the specific selection is based on needs. The embodiment of the present invention selects key parameters, key code methods, and key summary information from all parameter variables, code methods, and summary information according to the screening strategy in the extraction rules. The specific screening can be matched and screened by enumeration or regular expression. Of course, it can also be screened by logical judgment, such as screening key parameter variables according to the type of parameter variables and the code method body where the parameters are located.
[0075] Finally, define the identification node of the code to be detected. The identification node can use the identification generation tool to generate a unique identification for the code. Then, the filtered key parameter information, key code method information, and key summary information are used as nodes and associated with the identification node to construct a code graph for the code to be detected.
[0076] Figure 3 It is a schematic diagram of the code map of the embodiment of the present invention. CodeID102 is the identification node of the code to be detected, and the library name, code version, class name, code method body name, method body line number, output parameter variable name, and input parameter variable name are used as nodes, which are connected to the identification node of the code to be detected, forming the code map of the embodiment of the present invention.
[0077] Figure 4 This is a schematic diagram of the generation process of the code map of the embodiment of the present invention. The stream processing tool Flink is used to obtain the code to be detected to form a data stream, and the attribute information of the data stream of the code to be detected is extracted through the Flink program task, and the code map containing input and output parameters, code method information, code summary information and other information is obtained according to the data structure of the code map, and the generated code map is stored in the column storage database clickhouse.
[0078] Step S202: input the code graph and the code to be detected into the detection model. The detection model performs parameter transfer analysis, variable correlation analysis, call chain analysis and control flow analysis on the code to be detected based on the code graph to obtain abnormal code information corresponding to the abnormal code output by the detection model.
[0079] Based on the pre-built detection model, the above-generated code map and the code to be detected are input into the detection model together. The detection model determines the main analysis direction of this code detection according to the received code map, and performs anomaly detection on the code to be detected according to each node in the code map. Taking the above-constructed code map as an example, according to the input and output parameters in the code map, the code parameter transfer analysis and variable correlation analysis are performed; according to the information of each code method in the code map, the code call chain analysis is performed; according to the code summary information, the overall control flow analysis of the code is performed. Finally, all the features of the abnormal code corresponding to the abnormalities in various analysis results are extracted and summarized to form abnormal code information containing abnormal problems and corresponding abnormal code features, and finally the detection results of this code detection are output through the output interface of the model. It can be understood that if the code does not detect an abnormality, then the detection result shows that no abnormality is detected.
[0080] Figure 5 It is a schematic diagram of the code detection process of an embodiment of the present invention. First, the code data to be detected is obtained from the column storage database clickhouse. The code data to be detected contains the code to be detected and the code map generated by extracting and processing the attribute information of the code to be detected. The code map and the code to be detected are input into the detection model BERT large model, and the detection model is used to perform parameter transfer analysis on the code to be detected (for example, it is detected that a certain code block uses a large number of parameters. After parameter transfer analysis, it is determined that these parameters have been transferred and referenced in a loop many times, then the code block may have abnormal parameter usage), variable correlation analysis, call chain analysis and control flow analysis. Finally, all the abnormal code features that are abnormal in various analysis results are extracted and summarized to obtain abnormal code features, and the abnormal code features are pruned and filtered to obtain the key information of the abnormal code after the final filtering.
[0081] Step S203: According to the exception code information, a scenario optimization solution corresponding to the exception code information is searched from a pre-built exception location knowledge base.
[0082] According to one embodiment of the present invention, based on the exception code information, a scenario optimization solution corresponding to the exception code information is searched from a pre-built exception location knowledge base, including: searching from the exception location knowledge base for a location category that matches the exception category in the exception code information; determining the business scenario corresponding to the exception code based on the code attribution information in the exception code information; and searching from the exception location knowledge base for a scenario optimization solution corresponding to the location category in the business scenario.
[0083] Specifically, when the detection model of the embodiment of the present invention performs anomaly detection analysis on the code, in addition to detecting the anomalies existing in the code, it can also determine the anomaly category to which the anomaly belongs. For example, through parameter transfer analysis, it is found that a parameter is not released after being transferred multiple times, then the code segment of the parameter has an anomaly, and the anomaly type is memory leak. Specific anomaly categories include but are not limited to memory overflow, memory leak, interface security, etc.
[0084] Furthermore, in addition to the exception code, each exception code record in the exception location knowledge base also has the location category corresponding to the exception code, and the exception location knowledge base also provides scene optimization solutions corresponding to the location category in different business scenarios. According to the exception category in the exception code information output by the detection model, the location category that matches the exception category in the exception code information is searched in the exception location knowledge base, and then the business scenario corresponding to the exception code is determined according to the code attribution information in the exception code information, and then the scene optimization solution corresponding to the location category in the determined business scenario is searched from the exception location knowledge base. It is realized that a personalized and accurate scene optimization solution is obtained based on the exception code information.
[0085] It can be understood that the exception category and location category of the embodiment of the present invention can be implemented directly in the form of text or in the form of label identification, and the exception code records in the exception location knowledge base are not limited to programming languages, and can be various commonly used programming languages such as C, C++, Java, Python, etc., to better meet actual use.
[0086] Step S204: searching a preset prompt word template library for a prompt word template that matches the scene information in the scene optimization solution.
[0087] Specifically, in order to obtain accurate modification suggestions, the embodiment of the present invention presets a prompt word template library that can be recognized by the detection model, and defines the corresponding prompt word template library according to different scenarios. After obtaining the scenario optimization solution corresponding to the exception code, the prompt word template consistent with it is searched from the prompt word template library according to the scenario information. For example, for the logistics cost control business scenario, there is a corresponding prompt word template "In the logistics cost control scenario, for (a certain exception category), please correct and optimize the exception code from the aspects of (XXX), (XXX) and (XXX)".
[0088] Step S205: fill the optimization elements in the scene optimization solution into the to-be-filled positions in the prompt word template to obtain the prompt words of the scene optimization solution.
[0089] Specifically, based on the prompt word template found above, the optimization element content in the scenario optimization solution obtained from the abnormality location knowledge base, and the abnormality category of the abnormality code, are filled in the position to be filled in the prompt word template, and the prompt word of the scenario optimization solution corresponding to the abnormality code is generated. It can be understood that when the number of optimization elements exceeds the number of positions to be filled in the prompt word template, the number of positions to be filled in the prompt word template can be expanded, or according to the priority of the optimization elements specified in the scenario optimization solution, the target optimization elements that meet the number of positions to be filled in the prompt word template are selected from the highest priority, and the selected target optimization elements are filled in the prompt word template from front to back in the order of selection.
[0090] Figure 6 This is a schematic diagram of prompt word generation in an embodiment of the present invention. The first is the construction and maintenance of the exception location knowledge base. User R&D personnel enter the exception codes encountered daily, and clarify the location categories corresponding to the exception codes, and mark the location categories with category tags to form exception code records. At the same time, corresponding scenario optimization solutions are provided for the exception codes of the location categories in different business scenarios. The embodiment of the present invention supports the entry of exception codes in multiple languages (C, C++, Java, Python, etc.). Then, the category tag of the exception category in the exception code information output by the detection model is matched with the category tag of the exception location knowledge base to obtain a matching result. Then, based on the code attribution information in the exception code information, the business scenario corresponding to the exception code is determined, and the scenario optimization solution corresponding to the matching category tag in the business scenario is searched from the exception location knowledge base. Finally, based on the scenario optimization solution, the prompt word of the scenario optimization solution is generated.
[0091] Step S206: input the prompt word into the detection model to obtain modification suggestions for the abnormal code output by the detection model.
[0092] Specifically, the prompt words of the scenario solution that matches the business scenario where the abnormal code is located are input into the detection model, and the abnormal code information corresponding to the abnormal code in the code to be detected obtained from the detection model is also input into the detection model. The detection model optimizes and improves the abnormal code according to the received prompt words and abnormal code information, and generates a modified code for the abnormal code. In this way, users or R&D personnel can directly use the modified code output by the detection model, which greatly improves the efficiency of software code detection.
[0093] Figure 7It is a schematic diagram of the overall functional architecture of software detection in an embodiment of the present invention. Software detection is mainly divided into four functional architectures, among which the column storage database Clickhouse is used for data storage of the entire system, such as training set data and prediction data for detection model training, as well as various data storage of the entire customized anomaly positioning knowledge base component platform. The BERT detection model uses a large model learning algorithm to analyze the code according to the input code map and the code to be detected, perform anomaly detection, and output modification suggestions for the abnormal code according to the prompt words given by the abnormal positioning knowledge base component platform. The customized abnormal positioning knowledge base component platform collects abnormal code records and provides corresponding scenario optimization solutions, which are specifically stored in the form of configuration information to form an abnormal positioning knowledge base, and accurately locates the scenario optimization solution corresponding to the abnormal code through matching of category tags, so that the system can generate corresponding prompt words according to the scenario optimization solution. The streaming processing tool Flink is responsible for data processing in the entire system, such as passing the code to be detected to the detection model in real time for anomaly detection, generating code maps, etc.
[0094] The software detection method provided by the embodiment of the present invention is based on a customized anomaly location knowledge base. After the detection model detects the anomaly code information of the anomaly code, a scenario optimization solution consistent with the business scenario where the anomaly code is located is obtained, and then corresponding prompt words are generated, so that the detection model can not only detect the anomaly code, but also provide corresponding personalized and accurate modification suggestions that can directly replace the anomaly code, which greatly improves the detection efficiency of the software, not only promotes the development progress of the software project, but also ensures the quality of the software project.
[0095] Figure 8 FIG. 1 is a schematic diagram of the main modules of the software detection device according to an embodiment of the present invention. Figure 8 As shown, the software detection device 800 mainly includes an attribute information set generation module 801, an abnormal code detection module 802, an optimization solution determination module 803 and a modification suggestion acquisition module 804.
[0096] The attribute information set generation module 801 is used to obtain the code to be detected, extract and process the attribute information of the code to be detected, and generate the attribute information set of the code to be detected;
[0097] The abnormal code detection module 802 is used to input the attribute information set and the code to be detected into a pre-built detection model, and obtain abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model;
[0098] The optimization solution determination module 803 is used to search for a scenario optimization solution corresponding to the abnormality code information from a pre-built abnormality location knowledge base according to the abnormality code information;
[0099] The modification suggestion acquisition module 804 is used to generate prompt words of the scenario optimization solution according to the scenario optimization solution, and input the prompt words into the detection model to obtain modification suggestions for the abnormal code output by the detection model.
[0100] According to one embodiment of the present invention, the attribute information set is stored in the form of a code graph; the attribute information set generation module 801 is also used to: extract parameter variable information, code method information and summary information of the code to be detected from the code to be detected; filter the parameter variable information, code method information and the summary information to obtain key parameter information, key code method information and key summary information; use the key parameter information, the key code method information and the key summary information as nodes, and associate them with the identification node of the code to be detected to generate a code graph of the code to be detected.
[0101] According to another embodiment of the present invention, the abnormal code detection module 802 is also used to: input the code graph and the code to be detected into the detection model, and the detection model performs parameter transfer analysis, variable correlation analysis, call chain analysis and control flow analysis on the code to be detected based on the code graph to obtain abnormal code information corresponding to the abnormal code output by the detection model.
[0102] According to another embodiment of the present invention, the optimization solution determination module 803 is also used to: search the exception location knowledge base for a location category that matches the exception category in the exception code information; determine the business scenario corresponding to the exception code based on the code attribution information in the exception code information; and search the exception location knowledge base for a scenario optimization solution corresponding to the location category in the business scenario.
[0103] According to another embodiment of the present invention, the modification suggestion acquisition module 804 is further used to: search for a prompt word template that matches the scene information in the scene optimization solution from a preset prompt word template library; fill the optimization elements in the scene optimization solution into the to-be-filled position in the prompt word template to obtain the prompt word of the scene optimization solution.
[0104] According to another embodiment of the present invention, the detection model is constructed in the following manner: selecting a training code, and segmenting and slicing the training code to obtain a plurality of code slices; marking each of the code slices by judging whether the code segments in each of the code slices are normal, and then generating a sample set; using the sample set to train a predefined initial detection model, and fine-tuning the parameters of the trained detection model to obtain the detection model with the ability to detect abnormal codes.
[0105] According to another embodiment of the present invention, the software detection device 800 also includes a filtering module (not shown in the figure), which is used to: after obtaining the abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model, prune and filter the abnormal code information to obtain the abnormal code key information after pruning and filtering, so as to use the abnormal code key information to search the scenario optimization solution corresponding to the abnormal code information from the abnormal location knowledge base.
[0106] According to another embodiment of the present invention, the acquisition of the code to be detected and the generation of the attribute information set are implemented using a streaming processing tool; the software detection device 800 also includes a storage module (not shown in the figure), which is used to: after generating the attribute information set of the code to be detected, store the attribute information set in a column storage database, and when using the detection model to detect abnormal code, query the attribute information set from the column storage database.
[0107] Fig. 9 is an exemplary system architecture diagram to which embodiments of the present invention can be applied.
[0108] like Fig. 9 As shown, system architecture 900 may include terminal devices 901, 902, 903, network 904 and server 905. Network 904 is used to provide a medium for communication links between terminal devices 901, 902, 903 and server 905. Network 904 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0109] Users can use terminal devices 901, 902, 903 to interact with server 905 through network 904 to receive or send messages, etc. Various communication client applications, such as software detection applications, etc., can be installed on terminal devices 901, 902, 903 (only as an example).
[0110] The terminal devices 901 , 902 , and 903 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0111] Server 905 can be a server that provides various services, such as a background management server that provides support for software detection performed by users using terminal devices 901, 902, and 903 (only as an example). The background management server can obtain the code to be detected, extract and process the attribute information of the code to be detected, and generate an attribute information set of the code to be detected; input the attribute information set and the code to be detected into a pre-built detection model, and obtain the abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model; according to the abnormal code information, search the scene optimization solution corresponding to the abnormal code information from the pre-built abnormal location knowledge base; according to the scene optimization solution, generate the prompt word of the scene optimization solution, and input the prompt word into the detection model, obtain the modification suggestion of the abnormal code output by the detection model, and feed back the processing result (such as the detection result, etc. - only as an example) to the terminal device.
[0112] It should be noted that the software detection method provided in the embodiment of the present invention is generally executed by the server 905 , and accordingly, the software detection device is generally set in the server 905 .
[0113] It should be understood that Fig. 9 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0114] Reference below Fig.10 , Fig.10 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. Fig.10 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0115] like Fig.10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage part 1008 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the operation of the system 1000 are also stored. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other through a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0116] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0117] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1009, and / or installed from the removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the above-mentioned functions defined in the system of the present invention are executed.
[0118] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination thereof.
[0119] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0120] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor including: an attribute information set generation module, an abnormal code detection module, an optimization solution determination module, and a modification suggestion acquisition module.
[0121] Among them, the names of these modules do not constitute a limitation on the modules themselves in certain cases. For example, the attribute information set generation module can also be described as "a module used to obtain the code to be detected, extract and process the attribute information of the code to be detected, and generate the attribute information set of the code to be detected."
[0122] On the other hand, the present invention also provides a computer-readable medium, which may be included in the device described in the embodiment; or it may exist independently and not be assembled into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by a device, the device includes: obtaining the code to be detected, extracting and processing the attribute information of the code to be detected, and generating the attribute information set of the code to be detected; inputting the attribute information set and the code to be detected into a pre-built detection model, and obtaining the abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model; according to the abnormal code information, searching the scene optimization solution corresponding to the abnormal code information from the pre-built abnormal location knowledge base; according to the scene optimization solution, generating the prompt word of the scene optimization solution, and inputting the prompt word into the detection model to obtain the modification suggestion of the abnormal code output by the detection model.
[0123] The technical solution according to the embodiment of the present invention has the following advantages or beneficial effects: by obtaining the code to be detected, and extracting and processing the attribute information of the code to be detected, an attribute information set of the code to be detected is generated; the attribute information set and the code to be detected are input into a pre-built detection model to obtain abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model; according to the abnormal code information, a scenario optimization solution corresponding to the abnormal code information is searched from a pre-built abnormality location knowledge base; according to the scenario optimization solution, prompt words of the scenario optimization solution are generated, and the prompt words are input into the detection model to obtain the modification suggestions of the abnormal code output by the detection model. The technical solution realizes a complete and accurate software detection method. Not only the abnormal code information is detected by the detection model, but also the modification suggestions of the abnormal code are obtained. In addition, the prompt words of the scenario optimization solution generated based on the abnormality location knowledge base ensure the personalization and accuracy of the modification suggestions output by the detection model.
[0124] The specific implementation methods described herein do not constitute limitations on the scope of protection of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A method for software detection, characterized in that: include: Acquire a code to be detected, extract and process attribute information of the code to be detected, and generate an attribute information set of the code to be detected; Input the attribute information set and the code to be detected into a pre-built detection model, and obtain abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model; According to the abnormal code information, searching for a scenario optimization solution corresponding to the abnormal code information from a pre-built abnormal location knowledge base; According to the scenario optimization solution, prompt words of the scenario optimization solution are generated, and the prompt words are input into the detection model to obtain modification suggestions for the abnormal code output by the detection model.
2. The method according to claim 1, characterized in that: The attribute information set is stored in the form of a code map; Extracting and processing the attribute information of the code to be detected to generate an attribute information set of the code to be detected, including: Extracting parameter variable information, code method information and summary information of the code to be detected from the code to be detected; Screening the parameter variable information, the code method information and the summary information to obtain key parameter information, key code method information and key summary information; The key parameter information, the key code method information and the key summary information are used as nodes and are associated with the identification node of the code to be detected to generate a code graph of the code to be detected.
3. The method according to claim 2, characterized in that Inputting the attribute information set and the code to be detected into a pre-built detection model, and obtaining abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model, including: The code graph and the code to be detected are input into the detection model. The detection model performs parameter transfer analysis, variable correlation analysis, call chain analysis and control flow analysis on the code to be detected based on the code graph, and obtains abnormal code information corresponding to the abnormal code output by the detection model.
4. The method according to claim 1, characterized in that: According to the abnormal code information, searching for a scenario optimization solution corresponding to the abnormal code information from a pre-built abnormal location knowledge base includes: Searching the abnormality location knowledge base for a location category that matches the abnormality category in the abnormality code information; Determine the business scenario corresponding to the exception code according to the code attribution information in the exception code information; The scenario optimization solution corresponding to the positioning category in the business scenario is searched from the abnormal positioning knowledge base.
5. The method according to claim 1, characterized in that Generating prompt words of the scene optimization solution according to the scene optimization solution includes: Searching for a prompt word template matching the scene information in the scene optimization solution from a preset prompt word template library; The optimization elements in the scene optimization solution are filled in the to-be-filled positions in the prompt word template to obtain the prompt words of the scene optimization solution.
6. The method according to claim 1, characterized in that The detection model is constructed in the following way; Selecting a training code, and slicing the training code into segments to obtain a plurality of code slices; By judging whether the code segments in each of the code slices are normal, marking each of the code slices, and thus generating a sample set; The sample set is used to train a predefined initial detection model, and parameters of the trained detection model are fine-tuned to obtain the detection model capable of detecting abnormal codes.
7. The method according to claim 1, characterized in that After obtaining the abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model, the method further includes: The exception code information is pruned and filtered to obtain key information of the exception code after pruning and filtering, so as to use the key information of the exception code to search for a scenario optimization solution corresponding to the exception code information from the exception location knowledge base.
8. The method according to claim 1, characterized in that The acquisition of the code to be detected and the generation of the attribute information set are achieved by using a streaming processing tool; After generating the attribute information set of the code to be detected, the method further includes: The attribute information set is stored in a column storage database, and when the detection model is used to detect abnormal codes, the attribute information set is queried from the column storage database.
9. A software detection device, characterized in that: include: An attribute information set generation module is used to obtain a code to be detected, extract and process attribute information of the code to be detected, and generate an attribute information set of the code to be detected; An abnormal code detection module, used for inputting the attribute information set and the code to be detected into a pre-built detection model, and obtaining abnormal code information corresponding to the abnormal code in the code to be detected output by the detection model; An optimization solution determination module is used to search for a scenario optimization solution corresponding to the abnormal code information from a pre-built abnormality location knowledge base according to the abnormal code information; The modification suggestion acquisition module is used to generate prompt words of the scenario optimization solution according to the scenario optimization solution, and input the prompt words into the detection model to obtain modification suggestions for the abnormal code output by the detection model.
10. A mobile electronic device terminal, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
11. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Abnormal code detection method and device based on artificial intelligence
CN120011245A
Method for repairing Bluetooth communication abnormity and electronic equipment
CN120602956A
Abnormal code detection method and system based on artificial intelligence
CN121349835A
An abnormal code detection method and system based on artificial intelligence
CN121349835B