Code fault sample generation method, apparatus and device, and computer program product
By obtaining the call structure information of code functions and injecting faults into the terminal nodes, code fault samples are generated, which solves the problem of difficulty in obtaining long-link fault samples, realizes efficient and automated sample generation, and improves the training and fault tracing capabilities of large language models.
Patent Information
- Application Number
- CN202511502114.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-17
- Publication Date
- 2026-02-06
AI Technical Summary
In real production environments, long-chain code fault samples are difficult to obtain due to their low natural occurrence rate. This results in insufficient training dataset size and quality for large language models in the field of long-chain fault diagnosis, limiting the model's performance and fault tracing capabilities.
By obtaining the call structure information of code functions, call samples with link length greater than or equal to a preset length threshold are identified, and fault injection operations are performed on the end nodes to generate code fault samples.
It achieves automated and efficient generation of code fault samples, significantly reducing manpower and time costs, providing high-quality training and evaluation corpora, and improving the training quality of large language models and the practicality of fault tracing tasks.
Smart Images

Figure CN121478622A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method, apparatus, device, and computer program product for generating code fault samples. Background Technology
[0002] Currently, the performance of Large Language Models (LLMs) depends on training corpora from different code scenarios, and the quantity and quality of the training corpora largely determine the model's final performance. However, in real-world production environments, long-chain code failure samples are difficult to obtain due to their low natural occurrence rate. A long chain refers to a call chain with high complexity and a long execution path; this makes obtaining failure samples in the domain of long-chain code failures a significant challenge. Summary of the Invention
[0003] This application provides a method, apparatus, device, and computer program product for generating code fault samples, which can automatically and efficiently generate code fault samples and improve the generation quality and effect of code fault samples to a certain extent.
[0004] In a first aspect, embodiments of the present invention provide a method for generating code fault samples, comprising: Obtain the call structure information of code functions, which includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of code functions, and the directed edges are used to identify the call relationship between code functions. Based on the call structure information, a call sample is determined, wherein the link length of the call sample is greater than or equal to a preset length threshold; Perform a fault injection operation on the end node in the call sample to obtain a fault injection sample; Based on the fault injection sample, a code fault sample is generated.
[0005] Secondly, embodiments of the present invention provide an apparatus for generating code fault samples, comprising: The first acquisition module is used to acquire the call structure information of code functions. The call structure information includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of code function, and the directed edges are used to identify the call relationship between code functions. The first determining module is used to determine a call sample based on the call structure information, wherein the link length of the call sample is greater than or equal to a preset length threshold. The first processing module is used to perform fault injection operations on the end nodes in the call sample to obtain a fault injection sample. The first processing module is further configured to generate a code fault sample based on the fault injection sample.
[0006] Thirdly, embodiments of the present invention provide an electronic device, including: a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method in the first aspect described above.
[0007] Fourthly, embodiments of the present invention provide a computer storage medium for storing a computer program, which, when executed by a computer, implements the method described in the first aspect above.
[0008] Fifthly, embodiments of the present invention provide a computer program product, comprising: a computer-readable storage medium storing computer instructions, which, when executed by one or more processors, cause one or more processors to perform the steps of the method described in the first aspect.
[0009] The code fault sample generation method, apparatus, device, and computer program product provided in this embodiment obtains the call structure information of code functions, determines call samples based on the call structure information, performs fault injection operations on the end nodes in the call samples to obtain fault injection samples, and generates code fault samples based on the fault injection samples. This effectively realizes the automated and efficient generation of code fault samples. This not only significantly reduces the manpower and time costs required for constructing code fault samples, but also provides high-quality training and evaluation corpora for long-chain fault tracing tasks, further improving the practicality of the method. Attached Figure Description
[0010] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 A schematic diagram illustrating a method for generating code fault samples, provided as an exemplary embodiment of this application; Figure 2 A flowchart illustrating a method for generating code fault samples, provided as an exemplary embodiment of this application; Figure 3 A schematic diagram illustrating the call structure information of code functions provided for an exemplary embodiment of this application; Figure 4 This is a schematic diagram illustrating a process of performing fault injection operations on the end node in the call sample to obtain a fault injection sample, provided as an exemplary embodiment of this application. Figure 5A schematic diagram illustrating the process of generating a code fault sample based on the fault injection sample, provided as an exemplary embodiment of this application; Figure 6 A flowchart illustrating the process of generating a code fault sample based on the fault injection sample, as provided in another exemplary embodiment of this application; Figure 7 A schematic diagram illustrating a sample truncation operation on an adjusted sample, provided as another exemplary embodiment of this application; Figure 8 A schematic diagram illustrating the principle of a method for generating long-link code fault tracing samples, provided for an exemplary embodiment of this application; Figure 9 A schematic diagram of a code fault sample generation apparatus provided for an exemplary embodiment of this application; Figure 10 A schematic diagram of the structure of an electronic device provided for an exemplary embodiment of this application. Detailed Implementation
[0011] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0012] It should be noted that, in the case of user information involved in the embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0013] The various models involved in this application (including but not limited to language models or large models) comply with relevant laws and standards. Furthermore, the technical solutions provided in the embodiments of this application can employ deep learning models with relatively large parameter scales. The large model is merely an example, and the embodiments of this application do not limit the number of model parameters supported by the deep learning model used, aiming to meet actual needs. The deep learning models involved in the embodiments of this application can be artificial intelligence-based language models (LM) or multimodal models (MM).
[0014] Additionally, it should be noted that when user interaction operations or triggering operations are involved in the embodiments of this application, these operations include, but are not limited to, various interaction methods such as touch operations, gesture operations, voice operations, head movement operations, and eye movement operations. Touch operations include, but are not limited to, click operations, double-click operations, long-press operations, swipe operations, pinch operations, or mouse hover operations. Swipe operations include, but are not limited to, straight-line swipes and curved-line swipes.
[0015] Terminology definition: Fault tracing: also known as code fault analysis or root cause analysis, refers to finding the root cause of faults or defects in software or systems through analysis, tracing and localization.
[0016] Long chain: In a distributed software system or a complex monolithic system, a call chain that spans multiple services, modules or functions and has a long execution path is generated to complete a user request or application process. In some instances, a long chain may correspond to at least three rounds of dialogue or at least several rounds of dialogue.
[0017] Sample generation: refers to the process of designing and creating data samples or datasets for a specific purpose, such as training, fine-tuning, validating or evaluating a Large Language Model (LLM).
[0018] To facilitate understanding of the method, apparatus, device, and computer program product for generating code fault samples provided in the embodiments of this application, the relevant technologies are briefly described below: Currently, the performance of Large Language Models (LLMs) depends on training corpora from different code scenarios, and the quantity and quality of the training corpora largely determine the model's final performance. However, in the field of long-chain code fault diagnosis, obtaining high-quality fault samples faces challenges. On the one hand, in real production environments, long-chain code fault samples are difficult to obtain due to their low natural occurrence rate; on the other hand, the process of manually constructing datasets involves multiple complex steps such as data collection, cleaning, annotation, and validation, often relying on a large amount of manual experience and time investment, resulting in high costs and long cycles.
[0019] In the training of large language models, the aforementioned problems can easily lead to insufficient scale and quality of training datasets. This becomes a key bottleneck restricting the ability of large language models to trace faults in long links, thereby limiting the training effect of the model on specific fault types and causing its performance to fail to meet the requirements of practical applications.
[0020] To address the aforementioned technical problems, embodiments of this application provide a method, apparatus, device, and computer program product for generating code fault samples, as detailed in the appendix. Figure 1 As shown, the execution entity of the code fault sample generation method can be a code fault sample generation device 200, which can be implemented as a local server, a cloud server, or an edge server. Specifically, when the code fault sample generation device 200 is implemented as a cloud server, the code fault sample generation method can be executed in the cloud. Several computing nodes (cloud servers) can be deployed in the cloud, each with computing, storage, and other processing resources. In the cloud, multiple computing nodes can be organized to provide a certain service; of course, a single computing node can also provide one or more services. The cloud can provide this service by providing a service interface, which users call to use the corresponding service. Service interfaces include Software Development Kits (SDKs), Application Programming Interfaces (APIs), etc.
[0021] The code fault sample generation device 200 is communicatively connected to the client 100. The client 100 is used by users to trigger the code fault sample generation operation. The client 100 can be any computing device with some information interaction capability; specifically, it can be a mobile phone, personal computer (PC), tablet computer, configuration application, etc. Furthermore, the basic structure of the client 100 may include at least one processor. The number of processors depends on the client's configuration and type. The client 100 may also include memory, which can be volatile, such as Random Access Memory (RAM), or non-volatile, such as Read-Only Memory (ROM), flash memory, etc., or both types. The memory typically stores the operating system (OS), one or more applications, and may also store program data. In addition to the processing unit and memory, the client 100 also includes some basic configurations, such as a network interface card (NIC) chip, I / O bus, display components, and some peripheral devices. Optionally, some peripheral devices may include, for example, a keyboard, mouse, stylus, printer, etc. Other peripheral devices are well known in the art and will not be described in detail here.
[0022] The code fault sample generation device 200 refers to a device capable of generating code fault samples in a network virtual environment. It typically refers to a device that utilizes a network for information planning and code fault sample generation. Specifically, the code fault sample generation device 200 can be implemented as a network model for generating code fault samples. Physically, the code fault sample generation device 200 can be any device capable of providing computing services and performing corresponding subsequent operations, such as a processor, server, etc. The code fault sample generation device 200 mainly consists of a processor, hard disk, memory, system bus, etc., and its architecture is similar to that of a general-purpose computer.
[0023] In this embodiment described above, the code fault sample generation device 200 and the client 100 are connected via a network, which can be a wireless or wired network connection. If the code fault sample generation device 200 and the client 100 are connected via a communication connection, the mobile network standard can be any one of 2G (Global System for Mobile Communications GSM), 2.5G (General Packet Radio Service GPRS), 3G (Wideband Code Division Multiple Access (WCDMA), Time Division Synchronous Code Division Multiple Access (TD-SCDMA), 4G (Long Term Evolution LTE), 4G+ (Enhanced Long Term Evolution LTE+), Global Microwave Access Interoperability (WiMax), 5G, 6G, etc.
[0024] In this embodiment of the application, the client 100 is used for users to perform applications to generate or obtain sample generation requests for triggering the generation operation of code fault samples. The sample generation request can be determined based on the user's human-computer interaction operation. In order to stably implement the generation operation of code fault samples, the sample generation request can be sent to the code fault sample generation device 200.
[0025] The code fault sample generation device 200 is used to obtain a sample generation request sent by the client 100, and then obtain the call structure information of the code function based on the obtained sample generation request. The obtained call structure information includes multiple nodes and directed edges located between the nodes. The nodes are used to identify the type of code function, and different nodes correspond to different code function types. The directed edges are used to identify the call relationship between code functions. Then, the call sample can be determined based on the call structure information. The number of determined call samples can be one or more, and the link length of the determined call sample is greater than or equal to a preset length threshold, that is, the obtained call sample is a long link sample.
[0026] Since the identified call samples correspond to code information used for normal data processing operations, in order to obtain faulty code samples, after determining the call samples, a fault injection operation can be performed on the terminal node (i.e., the last called function) in the call samples to obtain fault injection samples. The fault injection operation can be implemented based on a pre-trained fault injection model. Furthermore, to ensure the quality and effectiveness of the generated code fault samples, at least one intermediate node in the fault injection samples can be adaptively adjusted. This automates and efficiently generates code fault samples, significantly reducing the manpower and time costs required for constructing code fault samples. It also provides high-quality training and evaluation corpora for long-chain fault tracing tasks, further improving the practicality of the method.
[0027] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0028] Figure 2 A flowchart illustrating a method for generating code fault samples, provided as an exemplary embodiment of this application; see attached diagram. Figure 2 As shown, this embodiment provides a method for generating code fault samples. The execution subject of this method is a code fault sample generation device, which can be implemented as software or a combination of software and hardware. When the code fault sample generation device is implemented as hardware, it can specifically be various electronic devices capable of performing code fault sample generation operations. In some instances, the code fault sample generation device can be implemented as a server, cloud server, etc. When the code fault sample generation device (hereinafter referred to as "generation device") is implemented as software, it can be installed in the electronic devices exemplified above. Specifically, the code fault sample generation method provided in this embodiment may include: Step S201: Obtain the call structure information of the code function. The call structure information includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of the code function, and the directed edges are used to identify the call relationship between the code functions.
[0029] Step S202: Based on the call structure information, determine the call sample, and the link length of the call sample is greater than or equal to a preset length threshold.
[0030] Step S203: Perform a fault injection operation on the end node in the call sample to obtain a fault injection sample.
[0031] Step S204: Generate code fault samples based on fault injection samples.
[0032] The specific implementation methods and principles of each of the above steps are explained in detail below: Step S201: Obtain the call structure information of the code function. The call structure information includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of the code function, and the directed edges are used to identify the call relationship between the code functions.
[0033] When a user has a need to generate code fault samples, the generation device can obtain the call structure information of the code functions. The obtained call structure information may include multiple nodes and directed edges between any two nodes. The nodes are used to identify the type of code function, and the directed edges are used to identify the call relationship between code functions.
[0034] For example, see attached document. Figure 3 As shown, the obtained call structure information may include: node A, node B1, node B2, node B3... node E1, node E2 and node F, etc. Node A is the starting node of the call structure information, and node F is the ending node of the call structure information. There can be a directed edge between any two of the above nodes. For example, there is a directed edge between node A and node B1, which is used to identify that the code function corresponding to node A calls the code function corresponding to node B1. Or, there is a directed edge between node D2 and node E2, and the code function corresponding to node D2 calls the code function corresponding to node E2. Similarly, there is a directed edge between node D3 and node E2, and the code function corresponding to node D3 also calls the code function corresponding to node E2.
[0035] In some instances, the call structure information of code functions can be obtained through communication access operations with a client. In this case, obtaining the call structure information of code functions may include: identifying a client that is communicatively connected to the generation device, wherein the client may store the call structure information of code functions; and then obtaining the call structure information of code functions by actively or passively accessing the client. This effectively ensures the stability and reliability of obtaining the call structure information of code functions.
[0036] In other instances, the call structure information of code functions can be obtained not only through communication access operations with the client, but also through code parsing operations on a pre-defined code library. In this case, obtaining the call structure information of code functions may include: obtaining a pre-defined code library, which includes code information used to implement data processing operations; parsing the code information in the pre-defined code library to determine the call relationships between code functions; and constructing the call structure information of code functions based on the call relationships.
[0037] The function call structure information can be either a pre-built static call graph or a call graph constructed based on a preset code library. To obtain the function call structure information through the call graph construction operation, a preset code library can be obtained first. This preset code library may include code information used to implement normal data processing operations. In some instances, the preset code library can be stored on a preset server or in a preset database, and determined by accessing the preset server or database.
[0038] After obtaining the preset code library, the code information in the preset code library can be parsed to determine the call relationships between code functions. In some instances, the parsing operation of code information can be implemented based on the parsing plugin corresponding to the preset code library. In this case, parsing the code information in the preset code library to determine the call relationships between code functions may include: identifying the parsing plugin corresponding to the preset code library; and using the parsing plugin to perform static parsing of the code information to determine the call relationships between code functions.
[0039] After obtaining the preset codebase, a corresponding parsing plugin can be determined. This plugin can be chosen based on the code type within the preset codebase. For example, if the code in the preset codebase is of type Java, then the corresponding parsing plugin will be a Java code parsing plugin. This parsing plugin can then be used to perform static parsing of the code information, thereby reliably determining the call relationship between any two functions within the code.
[0040] In other instances, for code information, the parsing operation can be implemented not only based on the parsing plugin corresponding to the preset code library, but also in combination with the expected type of the call relationship. In this case, parsing the code information in the preset code library to determine the call relationship between code functions may include: determining the expected type of the call relationship; using the preset parsing tool to parse the code information in the preset code library to determine the call relationship between code functions that match the expected type.
[0041] To accurately determine the call relationships between code functions, the expected type of the call relationship can be determined first. This expected type can be determined based on user interaction, or it can be implemented as a pre-configured default type. In some instances, the expected type of the call relationship can include at least one of the following: direct call type, indirect call type, recursive call type, tail recursive call type, etc. After determining the expected type of the call relationship, a preset parsing tool can be used to parse the code information in a preset code library. This allows for a stable determination of the call relationships between code functions that match the expected type, effectively ensuring the flexibility and reliability of determining the call relationships between code functions. The preset parsing tool can be a code parsing tool selected by the user.
[0042] Step S202: Based on the call structure information, determine the call sample, and the link length of the call sample is greater than or equal to a preset length threshold.
[0043] After obtaining the call structure information of the code function, the call structure information can be analyzed and processed to determine one or more call samples. If the link length of the determined call sample is greater than or equal to the preset length threshold, it means that the determined call sample can correspond to a multi-turn dialogue operation with the large language model. Therefore, the determined call sample can be identified as a long link sample that conforms to the preset rules.
[0044] In some instances, call samples can be determined directly by filtering the call structure information of code functions based on a preset length threshold. Determining call samples based on call structure information may include: determining a preset length threshold for limiting the link length of call samples, wherein the preset length threshold may be determined based on human-computer interaction, or the preset length threshold may be a pre-configured default parameter; and using the preset length threshold to select links in the call structure information to determine at least one preset number of call samples.
[0045] For example, if the preset length threshold is 3, then the link samples corresponding to 3 or more rounds of dialogue operations in the call structure information can be determined as call samples. In this case, the call samples can include: link samples corresponding to 3 rounds of dialogue operations, link samples corresponding to 4 rounds of dialogue operations, link samples corresponding to 5 rounds of dialogue operations, etc.; or, if the preset length threshold is 5, then the link samples corresponding to 5 or more rounds of dialogue operations in the call structure information can be determined as call samples. In this case, the call samples can include: link samples corresponding to 5 rounds of dialogue operations, link samples corresponding to 6 rounds of dialogue operations, link samples corresponding to 7 rounds of dialogue operations, etc. This can reliably and accurately determine the call samples.
[0046] In other instances, the call sample can be determined not only by directly filtering the call structure information based on a preset length threshold, but also by analyzing and processing the call structure information based on a sample filtering model. In this case, determining the call sample based on the call structure information can include: determining a pre-trained sample filtering model; inputting the call structure information into the sample filtering model for analysis and processing, and obtaining at least one call sample output by the sample filtering model. This also ensures the accuracy and reliability of determining at least one call sample.
[0047] Step S203: Perform a fault injection operation on the end node in the call sample to obtain a fault injection sample.
[0048] After determining the call sample, since the code information corresponding to the call sample is often the code line used to implement normal data processing operations, in order to generate a code sample with faults, a fault injection operation can be performed on the end node (i.e. the last called code function) in the determined call sample, thereby obtaining a fault injection sample, which corresponds to a code fault.
[0049] In some instances, fault injection can be implemented using the first major language model. In this case, performing fault injection on the end nodes in the call sample to obtain fault injection samples may include: determining the first major language model to implement the fault injection operation; and using the first major language model to perform fault injection on the end nodes in the call sample to obtain fault injection samples.
[0050] The first major language model can be a pre-configured dedicated major language model for implementing fault injection operations. When there is a fault injection requirement, the first major language model for implementing fault injection operations can be determined first, and then the first major language model can be used to perform fault injection operations on the end nodes in the call sample, thereby obtaining fault injection samples.
[0051] Specifically, the first major language model can inject fault types such as "parameter value modification" and "parameter processing logic change" into the end nodes of the call samples. The fault type of "parameter value modification" can include any one of the following: "parameter value set to null" fault type, "parameter value exceeds threshold" fault type, etc., so as to reliably obtain fault injection samples with different types of faults.
[0052] Step S204: Generate code fault samples based on fault injection samples.
[0053] After obtaining the fault injection sample, code fault samples can be generated based on it. In some instances, the fault injection sample can be directly identified as the code fault sample. Alternatively, in other instances, since the fault injection sample is a faulty sample obtained through a fault injection operation, in order to ensure that the fault injected by the fault injection sample is propagated upwards along the fault injection sample's path to the starting node of the path, after obtaining the fault injection sample, code adjustment operations can be performed on at least one intermediate node in the fault injection sample. Specifically, code adaptation adjustments for injecting faults can be performed on at least one intermediate node in the fault injection sample, thereby stably generating code fault samples.
[0054] In some instances, code fault samples can be generated by automatically annotating adjusted samples based on fault injection information. In this case, generating code fault samples based on fault injection samples may include: adjusting the code of at least one intermediate node in the fault injection sample to obtain an adjusted sample; determining the fault injection information corresponding to the adjusted sample, wherein the fault injection information includes at least one of the following: fault type, fault location, and fault injection parameters corresponding to the code fault sample; and automatically annotating the adjusted sample based on the fault injection information to generate structured code fault samples.
[0055] In order to ensure the accuracy and reliability of the generated code fault samples and improve their practicality, after obtaining the fault injection sample, code adjustment operations can be performed on at least one intermediate node in the fault injection sample. The code adjustment operation can include the deletion operation of the preset code protection mechanism, so as to make the injected fault as far as possible as possible to be transmitted upward along the fault injection sample link to the starting node of the link, thereby obtaining the adjusted sample.
[0056] Since the faults corresponding to the code fault samples are determined through fault injection operations, in order to improve the convenience and reliability of applying the code fault samples, fault injection information corresponding to the adjusted samples can be determined. The fault injection information may include at least one of the following: fault type, fault location, fault injection parameters, etc. The aforementioned fault injection information can be determined based on the recorded information of the fault injection operation.
[0057] After determining the fault injection information corresponding to the adjusted sample, the adjusted sample can be automatically labeled based on the fault injection information. The automatic labeling operation can be implemented by processing the adjusted sample based on a pre-trained labeling network model, or the automatic labeling operation can be implemented by associating the fault injection information with the adjusted sample and generating structured code fault samples. This effectively ensures the accuracy and reliability of the generated code fault samples.
[0058] The code fault sample generation method provided in this embodiment obtains the call structure information of code functions, determines call samples based on the call structure information, performs fault injection operations on the end nodes in the call samples to obtain fault injection samples, and generates code fault samples based on the fault injection samples. This effectively realizes automated and efficient generation of code fault samples. This not only significantly reduces the manpower and time costs required for constructing code fault samples, but also provides high-quality training and evaluation corpora for long-chain fault tracing tasks. Then, based on a sufficient amount of training and evaluation corpora, large language models can be trained, thereby ensuring the training quality and effect of large language models and further improving the practicality of the method.
[0059] Figure 4 This is a flowchart illustrating a fault injection operation on the end node of a call sample to obtain a fault injection sample, provided as an exemplary embodiment of this application; based on the above embodiment, refer to the appendix... Figure 4 As shown, for fault injection samples, they can be obtained not only by performing fault injection operations on the call samples based on the first major language model, but also by performing fault injection operations on the preset function parameters corresponding to the determined end nodes. In this case, performing fault injection operations on the end nodes in the call samples to obtain fault injection samples can include: Step S401: Determine the preset function parameters corresponding to the end node. The probability that the preset function parameters are passed between the end node and the start node in the calling sample is greater than or equal to a preset probability threshold.
[0060] For the terminal nodes in the call sample, in order to reliably implement the fault injection operation, the preset function parameters corresponding to the terminal nodes can be determined first. Since the code function corresponding to a terminal node often has one or more function parameters, when the code function corresponds to a function parameter, the corresponding function parameter can be determined as the preset function parameter corresponding to the terminal node.
[0061] When a code function has multiple function parameters, a preset function parameter for implementing the fault injection operation can be determined from among the multiple function parameters. The number of preset function parameters can be one or more. In order to ensure the transitivity and stability of the injected fault, the probability that the preset function parameter is passed between the end node and the start node in the calling sample can be greater than or equal to a preset probability threshold.
[0062] For example, when the code function identified by the end node corresponds to function parameters a, b, and c, the probability of each function parameter being passed between the end node and the start node in the call sample can be determined first. For instance, the probability of function parameter a being passed is p1, the probability of function parameter b being passed is p2, and the probability of function parameter c being passed is p3, where p1 < p3 < p2. Then, the function parameter b corresponding to p2 can be determined as the preset function parameter corresponding to the end node. This effectively ensures the accuracy and reliability of determining the preset function parameter. Furthermore, since the determined preset function parameter has a high probability of being passed throughout the entire call sample, when performing fault injection operations based on the preset function parameter, the degree of transmission of the injected fault throughout the entire call sample can be improved to a certain extent, which is beneficial to improving the quality and effect of code fault sample generation.
[0063] Step S402: Perform fault injection operation on the end node based on preset function parameters to obtain fault injection samples.
[0064] After determining the preset function parameters corresponding to the terminal node, fault injection operations can be performed on the terminal node based on the determined preset function parameters to obtain fault injection samples. In some instances, fault injection operations can be implemented by processing the preset function parameters and the terminal node based on a pre-trained large language model, or by modifying the preset function parameters. In this case, obtaining fault injection samples by performing fault injection operations on the terminal node based on the preset function parameters can include: modifying the parameter values of the preset function parameters, for example, setting the parameter values of the preset function parameters to null, or adjusting the parameter values of the preset function parameters to exceed a preset standard threshold range, thereby obtaining fault injection samples after modification; or modifying the data processing logic corresponding to the preset function parameters, for example, modifying the trigger conditions corresponding to the preset function parameters, thereby obtaining fault injection samples; or introducing null pointers into the preset function parameters, thereby stably obtaining fault injection samples.
[0065] In this embodiment, by determining the preset function parameters corresponding to the end node, and then performing fault injection operation on the end node based on the preset function parameters, fault injection samples can be obtained stably, which is beneficial to improving the quality and effect of generating code fault samples based on fault injection samples.
[0066] Figure 5 This application provides a schematic flowchart illustrating the generation of code fault samples based on fault injection samples, as an exemplary embodiment. Based on the above embodiments, refer to the appendix... Figure 5 As shown, for code fault samples, they can be generated not only by automatically annotating the adjusted samples based on fault injection information, but also by using a large language model to perform code adjustment operations on the fault injection samples. In this case, generating code fault samples based on fault injection samples can include: Step S501: Determine the second major language model to implement the code adjustment operation.
[0067] The second major language model can be a pre-configured dedicated major language model used to implement code adaptation and adjustment tasks. When there is a need for code adjustment, the second major language model used to implement the code adjustment operation can be determined. In some instances, the second major language model can be determined by accessing a preset region.
[0068] Step S502: Use the second language model to adjust the code of at least one intermediate node in the fault injection sample to generate a code fault sample.
[0069] After determining the second language model, it can be used to adjust the code of at least one intermediate node in the fault injection sample to generate a code fault sample. In some instances, after obtaining the fault injection sample, it can be input into the second language model according to a preset prompt template for analysis and processing. This allows for code adjustment of at least one intermediate node in the fault injection sample, thereby obtaining the code fault sample generated by the second language model and effectively ensuring the quality and effectiveness of the generated code fault sample.
[0070] In other instances, code adjustment can be implemented as detecting and removing code protection mechanisms. In this case, using the second language model to adjust the code of at least one intermediate node in the fault injection sample to generate a code fault sample may include: using the second language model to determine the node code corresponding to each of the at least one intermediate node; based on the node code, detecting whether the corresponding intermediate node is associated with a preset code protection mechanism; if the intermediate node is associated with a preset code protection mechanism, using the second language model to remove and adjust the code protection mechanism to generate a code fault sample.
[0071] Since the code fault samples are obtained based on fault injection operations, in order to ensure that the injected faults can be propagated upwards to the starting node in the fault injection sample, it is necessary to perform code adjustment operations on at least one intermediate node in the fault injection sample. Specifically, for the injected faults, code adaptation adjustments can be performed on at least one intermediate node in the fault injection sample.
[0072] However, for intermediate nodes in fault injection samples, there may be corresponding code protection mechanisms. The corresponding code protection mechanisms refer to the technical means adopted in the coding, compilation, and runtime stages to defend against common vulnerabilities (such as null pointers, buffer overflows, and injection attacks). The configured code protection mechanisms can effectively prevent the code from being destroyed, tampered with, reverse-engineered, or exploited during runtime or static analysis, thereby improving the security, robustness, and reliability of the software.
[0073] For intermediate nodes, if a fault injection sample contains an intermediate node with a corresponding code protection mechanism, this mechanism will affect the propagation of the injected fault along the link corresponding to the fault injection sample. Without adjusting the code protection mechanism, the quality of the generated code fault samples will be reduced. Therefore, after obtaining the fault injection sample, a second language model can be used to analyze and process it to determine the node code corresponding to at least one intermediate node in the sample. Then, the second language model can be used to analyze the node code to detect whether the corresponding intermediate node is associated with a preset code protection mechanism. If the intermediate node is associated with a preset code protection mechanism, the second language model can be used to clean and adjust the code protection mechanism. That is, the second language model can adaptively clean the code corresponding to the code protection mechanism while keeping the original application logic unchanged, thereby stably generating code fault samples.
[0074] In this embodiment, by determining a second major language model for implementing code adjustment operations, and then using the second major language model to adjust the code of at least one intermediate node in the fault injection sample, it can be ensured that the injected fault can be propagated up the link corresponding to the call sample to the starting method of the link, thereby improving the quality and efficiency of generating code fault samples.
[0075] Figure 6 This application provides a flowchart illustrating the generation of code fault samples based on fault injection samples, as another exemplary embodiment of the present application; based on any of the above embodiments, refer to the appendix... Figure 6 As shown, code fault samples can be generated not only by adjusting the code of at least one intermediate node in the fault injection sample, but also by combining validity checks. In this case, generating code fault samples based on fault injection samples can include: Step S601: Adjust the code of at least one intermediate node in the fault injection sample to obtain the adjusted sample.
[0076] After obtaining the fault injection sample, code adjustment operations can be performed on at least one intermediate node in the fault injection sample to reliably obtain the adjusted sample. The specific implementation of the code adjustment operation is similar to the implementation of "using the second largest language model to adjust the code of at least one intermediate node in the fault injection sample" in the above embodiment, and can be referred to the above description for details, which will not be repeated here.
[0077] For the adjusted sample, after obtaining the adjusted sample, a validity test operation can be performed on the adjusted sample. At this time, the method in this embodiment may further include: determining a third language model for validating the adjusted sample; using the third language model to perform validity test on the adjusted sample and obtaining the test result.
[0078] The third language model can be a pre-configured dedicated language model for implementing validity checks. When validity checks are required, the third language model can be determined. In some instances, the third language model can be determined by accessing a preset region. The third language model can then be used to perform validity checks on the adjusted sample. Specifically, the adjusted sample can be input into the third language model according to a preset prompt template for validity checks. Validity checks can include at least one of the following: detecting whether the adjusted sample contains fault information, detecting whether the fault injected into the adjusted sample is propagated from the end node to the start node, etc., thereby obtaining the detection result output by the third language model. This detection result can include a first result indicating that the adjusted sample has passed the validity check, or a second result indicating that the adjusted sample has failed the validity check.
[0079] Step S602: If the adjusted sample passes the validity test, the adjusted sample is identified as a code fault sample.
[0080] If the adjusted sample passes the validity test, it means that the obtained adjusted sample meets the user's expected requirements for generating fault samples. Therefore, the obtained adjusted sample can be identified as a code fault sample, which effectively ensures the accuracy and reliability of identifying code fault samples.
[0081] Correspondingly, if the adjusted sample fails the validity check, it indicates that the obtained adjusted sample does not meet the user's expected requirements for generating faulty samples. In this case, the adjusted sample can be prevented from being identified as a code faulty sample. Alternatively, if the adjusted sample fails the validity check, in order to reliably obtain code faulty samples, the process can return to the fault injection operation step. Specifically, the fault injection operation can be re-performed on the terminal nodes in the identified call sample to obtain a new fault injection sample. Then, code adjustment operations can be performed on at least one intermediate node in the fault injection sample to obtain a new adjusted sample. Finally, a validity check operation can be performed on the adjusted sample until an adjusted sample that meets the validity check operation is generated.
[0082] In some instances, validity checks may include detecting whether the fault injected into the adjusted sample is propagated upwards from the end node to the start node. If the fault injected into the adjusted sample is not propagated upwards from the end node to the start node, in order to ensure the quality and effectiveness of code fault sample acquisition, the actual destination node of the fault injected into the adjusted sample can be determined. Then, based on the actual destination node, a sample truncation operation can be performed on the adjusted sample to generate code fault samples.
[0083] For example, see attached document. Figure 7 As shown, the link where the adjusted sample is located includes nodes A, B2, C2, D1, E1, and F. When performing fault injection on parameter a in the terminal node A, the actual node reached by the fault injected into the adjusted sample can be detected. If the actual node reached is node E1, in order to ensure the quality and effect of the generated code fault sample, the adjusted sample can be truncated based on the actual node E1, thereby obtaining a new code fault sample. At this time, the link where the code fault sample is located includes nodes A, B2, C2, D1, and E1. This effectively ensures that the injected fault can be propagated upwards along the link to the starting method corresponding to the code fault sample, thereby improving the quality and effect of the generated code fault sample.
[0084] In this embodiment, by adjusting the code of at least one intermediate node in the fault injection sample, an adjusted sample is obtained. If the adjusted sample passes the validity test, the adjusted sample is identified as a code fault sample, thus effectively ensuring the accuracy and reliability of identifying code fault samples.
[0085] For specific applications, please refer to the appendix. Figure 8 As shown, this application embodiment provides a method for generating long-link code fault tracing samples based on a Large Language Model (LLM). This method leverages the code understanding and generation capabilities of LLM to automatically and efficiently generate long-link code fault tracing samples of specific fault types from the codebase. This provides a more efficient data generation approach for constructing training datasets, thereby ensuring the quality of training dataset construction and supplementation operations. This not only significantly reduces the manpower and time costs required for training dataset construction but also provides high-quality training and evaluation corpora for long-link fault tracing tasks. Specifically, the method may include the following steps: Step 1: Construct the code call graph.
[0086] When it is necessary to generate code fault samples, the generation of code fault tracing samples can be triggered. At this time, a preset code library can be determined first. This preset code library includes code information used for normal data processing operations for tasks in one domain or multiple domains. Then, static or dynamic analysis can be performed on the preset code library to parse the call relationships between methods (code functions) and construct a code call graph based on the call relationships. The code call graph includes multiple nodes and directed edges between any two nodes. The nodes are used to identify function types, and the directed edges are used to identify the call relationships between code functions. For example, when node A points to node B, it means that the code function corresponding to node A calls the code function corresponding to node B.
[0087] When resolving call relationships, Java's default plugins can be used first to perform static analysis on the code information in the default code library. If the default plugins cannot resolve the call relationships between methods, dynamic analysis can be performed on the code in the default code library. Specifically, the limiting information of the default relationships can be determined first, and a manually selected code parsing tool can be used to filter out the call relationships in the default code library that meet the limiting information. This effectively ensures the accuracy and reliability of resolving the call relationships between methods.
[0088] Step 2: Select a call sample from a long call chain.
[0089] After constructing the code call graph, one or more long method call links consisting of multiple nodes and edges can be selected based on a preset link length threshold (preset values, such as 3, 5, 8, 10, etc.). When there are multiple long method call links, the link lengths of any two long method call links can be the same or different. Then, the call sample corresponding to the long call link can be determined. The link length of the long call link (i.e., the number of rounds of dialogue interaction with the large language model during data processing) is greater than or equal to the preset link length threshold. For example, a long call link can refer to a link with more than or equal to 3 rounds of dialogue, or a long call link can refer to a link with more than or equal to 5 rounds of dialogue.
[0090] Step 3: Perform fault injection on the call sample to obtain the fault injection sample.
[0091] After obtaining the call sample, the first LLM can be used to perform fault injection operations on the end nodes of the link corresponding to the call sample. Specifically, the parameters to be injected into the end nodes of the call sample can be determined first. The determined parameters to be injected can preferably be the parameters corresponding to the end nodes that run through the entire link to the call sample. After determining the parameters to be injected, fault injection operations can be performed on the parameters to be injected. For example, the first LLM can be used to modify the parameter values of the parameters to be injected (including: adjusting the parameter values of the parameters to be injected to null, or adjusting the parameter values of the parameters to be injected to exceed a preset standard threshold range, etc.), to change the parameter processing logic of the parameters to be injected, or to introduce null pointer operations into the parameters to be injected, etc., thereby obtaining a fault injection sample.
[0092] Step 4: Perform link adaptation modification on the fault injection sample to obtain the adjusted sample.
[0093] After obtaining the fault injection sample, in order to ensure that the fault parameters injected in step 3 above can be passed up the link from the end node to the start node, the second LLM can be used to modify the code of one or more intermediate nodes in the link corresponding to the fault injection sample. This can adapt the parameter transmission path while maintaining the original method's data processing logic and minimizing changes.
[0094] Specifically, the code adaptation and modification operation of one or more intermediate nodes in the link corresponding to the fault injection sample using the second LLM can include: analyzing and processing the fault injection sample using the second LLM to determine one or more intermediate nodes in the link corresponding to the fault injection sample; then determining the node code information corresponding to each of the one or more intermediate nodes; and using the second LLM to detect whether there is a code protection mechanism in the node code; if there is a code protection mechanism in the node code, the second LLM can be used to clean up and adjust the code protection mechanism in the node code, thereby generating an adjusted sample; if there is no code protection mechanism in the node code, there is no need to modify the code of the fault injection sample, and the fault injection sample is directly determined as the adjusted sample, thus effectively ensuring the accuracy and reliability of obtaining the adjusted sample.
[0095] Step 5: Verify and screen the effectiveness of the adjusted samples.
[0096] After obtaining the adjusted sample, a third LLM can be used to perform validity and reachability checks on the code involved in the entire call chain of the adjusted sample to determine whether the injected fault can be effectively transmitted to the starting node of the adjusted sample and to obtain the verification results. The obtained verification results may include a first result to indicate that the adjusted sample has passed the validity verification, or the verification results may include a second result to indicate that the adjusted sample has failed the validity verification.
[0097] Step 6: Generate code fault tracing samples.
[0098] Specifically, if the verification result is "valid" (the first result used to identify whether the adjusted sample has passed the validity verification), the obtained adjusted sample can be identified as a valid code fault tracing sample and saved. Furthermore, the code fault tracing sample can be automatically labeled based on the injected fault information (including fault type, location, and influencing parameters) to form a structured dataset. If the verification result is "invalid" (the second result used to identify whether the adjusted sample has failed the validity verification), then step 3 above is returned for re-execution until a valid code fault tracing sample is generated or the preset maximum number of attempts is reached.
[0099] The technical solution provided in this application embodiment realizes an end-to-end, complete, automated method for generating structured fault samples from a codebase. Specifically, this method uses multiple LLMs with clearly defined functional divisions to collaboratively complete fault injection, link adaptability modification, and validity verification operations. This achieves fully automated sample generation without manual intervention, thereby improving the quality and effectiveness of generated code fault tracing samples and filling the technological gap in the field of high-quality automated sample generation for long-link fault tracing. Furthermore, since the fault injection, link adaptability modification, and validity verification operations are based on multiple different LLMs... The LM collaborative process achieves decoupling and efficient execution of complex code modification tasks. For code fault tracing samples, the end-to-end process from fault injection to validity judgment has a valid sample generation pass rate of over 80%, significantly improving data construction efficiency and sample validity. After obtaining code fault tracing samples, they can be used as training data for LLM training operations and can also be flexibly used to build evaluation benchmarks for specific scenarios. This significantly shortens the sample production cycle and reduces resource consumption, and has high versatility and scalability, further enhancing the practicality of the technical solution.
[0100] Figure 9 A schematic diagram of a code fault sample generation apparatus provided as an exemplary embodiment of this application; see attached diagram. Figure 9 As shown, this embodiment provides a code fault sample generation apparatus, which is used to perform the above-described... Figure 2 The method for generating code fault samples shown may specifically include: The first acquisition module 11 is used to acquire the call structure information of code functions. The call structure information includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of code function, and the directed edges are used to identify the call relationship between code functions. The first determining module 12 is used to determine the call sample based on the call structure information, wherein the link length of the call sample is greater than or equal to a preset length threshold. The first processing module 13 is used to perform fault injection operations on the end nodes in the call sample to obtain a fault injection sample. The first processing module 13 is also used to generate code fault samples based on the fault injection samples.
[0101] The device for generating code fault samples in this embodiment can also perform the above-described... Figures 1-8 The description of the embodiments shown is for reference only, and will not be elaborated upon here.
[0102] Furthermore, in some of the processes described in the above embodiments and accompanying drawings, multiple operations appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear herein, or they may be executed in parallel. The operation numbers, such as 11, 12, etc., are merely used to distinguish different operations and do not represent any execution order. Additionally, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should be noted that the descriptions such as "first" and "second" in this document are used to distinguish different messages, devices, modules, etc., and do not represent a sequential order, nor do they limit "first" and "second" to different types.
[0103] like Figure 10 As shown, this embodiment provides an electronic device for performing the above-described... Figure 2 The method for generating code fault samples shown includes an electronic device that may include a memory 24 and a processor 25.
[0104] Memory 24 is used to store computer programs and can be configured to store various other data to support operation on the electronic device. Examples of this data include instructions for any application or method used to operate on the electronic device, data structures, contact data, phone book data, messages, pictures, videos, etc.
[0105] The processor 25, coupled to the memory 24, is used to execute the computer program in the memory 24 for: obtaining call structure information of code functions, the call structure information including multiple nodes and directed edges between the nodes, the nodes being used to identify the type of code function, and the directed edges being used to identify the call relationship between code functions; determining call samples based on the call structure information, the link length of the call samples being greater than or equal to a preset length threshold; performing fault injection operations on the end nodes in the call samples to obtain fault injection samples; and generating code fault samples based on the fault injection samples.
[0106] Furthermore, such as Figure 10 As shown, the electronic device also includes other components such as a communication component 26, a display 27, a power supply component 28, and an audio component 29. Figure 10 The diagram only shows some components and does not mean that the electronic device includes only these components. Figure 10 The components shown. Additionally... Figure 10 The components within the center frame are optional, not mandatory, and their specific requirements depend on the product form of the work node. In this embodiment, the work node can be a terminal device such as a desktop computer, laptop computer, smartphone, or IoT device, or a server-side device such as a conventional server, cloud server, or server array. If the work node in this embodiment is implemented as a terminal device such as a desktop computer, laptop computer, or smartphone, it may include... Figure 10 The components within the center frame; if the working node in this embodiment is implemented as a server-side device such as a conventional server, cloud server, or server array, it may not include... Figure 10 The component within the center frame.
[0107] The aforementioned memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random-Access Memory (SRAM), Electrically Erasable Programmable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0108] The aforementioned communication component is configured to facilitate wired or wireless communication between the device containing the communication component and other devices. The device containing the communication component can access wireless networks based on communication standards, such as 2G, 3G, 4G / LTE, 5G, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.
[0109] The aforementioned display includes a screen, which may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a Touch Panel, the screen can be implemented as a touchscreen to receive input signals from the user. The Touch Panel includes one or more touch sensors to sense touches, swipes, and gestures on the Touch Panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation.
[0110] The aforementioned power supply components provide power to various components within the device in which they reside. These power supply components may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power to the device in which they reside.
[0111] The aforementioned audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) configured to receive external audio signals when the device containing the audio component is in an operating mode, such as call mode, recording mode, or voice recognition mode. The received audio signals can be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals.
[0112] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to implement the steps in the above-described method embodiments. The computer-readable storage medium includes volatile or non-volatile components, or a combination thereof, and can be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access 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), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technologies, CD-ROM, Digital Video Disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium. Accordingly, this application also provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor is able to implement the steps in the above method embodiments. It should be understood that each step or combination of steps in the above method flow can be implemented by the computer program or instructions. In addition, these computer programs or instructions can be applied to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device, so that the processor of the general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device can be implemented as a means to implement the corresponding functions in the above method embodiments.
[0113] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0114] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for generating code fault samples, characterized in that, include: Obtain the call structure information of code functions, which includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of code functions, and the directed edges are used to identify the call relationship between code functions. Based on the call structure information, a call sample is determined, wherein the link length of the call sample is greater than or equal to a preset length threshold; Perform a fault injection operation on the end node in the call sample to obtain a fault injection sample; Based on the fault injection sample, a code fault sample is generated.
2. The method according to claim 1, characterized in that, Obtain the function call structure information, including: Obtain a preset code library, which includes code information for implementing data processing operations; The code information in the preset code library is parsed to determine the calling relationships between code functions; Based on the aforementioned call relationship, the call structure information of the code function is constructed.
3. The method according to claim 2, characterized in that, The code information in the preset code library is parsed to determine the calling relationships between code functions, including: Identify the parsing plugin corresponding to the preset code library; The parsing plugin is used to perform static parsing on the code information to determine the calling relationships between code functions.
4. The method according to claim 2, characterized in that, The code information in the preset code library is parsed to determine the calling relationships between code functions, including: Determine the expected type of the call relationship; The code information in the preset code library is parsed using a preset parsing tool to determine the calling relationship between code functions that are compatible with the expected type.
5. The method according to claim 1, characterized in that, Based on the aforementioned call structure information, the call sample is determined, including: Determine a preset length threshold for limiting the link length of the call sample; Using the preset length threshold, link selection is performed in the call structure information to determine at least one preset number of call samples.
6. The method according to claim 1, characterized in that, Perform a fault injection operation on the end node in the call sample to obtain a fault injection sample, including: The primary language model for implementing fault injection operations was determined. The first large language model is used to perform fault injection operation on the end node in the call sample to obtain a fault injection sample.
7. The method according to claim 1, characterized in that, Perform a fault injection operation on the end node in the call sample to obtain a fault injection sample, including: Determine a preset function parameter corresponding to the end node, wherein the probability that the preset function parameter is passed between the end node and the start node in the call sample is greater than or equal to a preset probability threshold. Based on the preset function parameters, a fault injection operation is performed on the end node to obtain the fault injection sample.
8. The method according to claim 7, characterized in that, Based on the preset function parameters, a fault injection operation is performed on the end node to obtain the fault injection sample, including: The fault injection sample is obtained by modifying the parameter values of the preset function; or, Modify the data processing logic corresponding to the preset function parameters to obtain the fault injection sample; or, A null pointer is introduced into the preset function parameters to obtain the fault injection sample.
9. The method according to claim 1, characterized in that, Based on the aforementioned fault injection sample, a code fault sample is generated, including: Identify the second largest language model for implementing code tweaking operations; The code fault sample is generated by adjusting the code of at least one intermediate node in the fault injection sample using the second major language model.
10. The method according to claim 9, characterized in that, The code fault sample is generated by adjusting at least one intermediate node in the fault injection sample using the second major language model, including: Using the second major language model, determine the node code corresponding to each of the at least one intermediate node; Based on the node code, detect whether the corresponding intermediate node is associated with a preset code protection mechanism; If the intermediate node is associated with a preset code protection mechanism, the second major language model is used to clear and adjust the code protection mechanism to generate the code fault sample.
11. The method according to any one of claims 1-10, characterized in that, Based on the aforementioned fault injection sample, a code fault sample is generated, including: At least one intermediate node in the fault injection sample is modified to obtain the modified sample; If the adjusted sample passes the validity test, the adjusted sample is identified as the code fault sample.
12. The method according to claim 11, characterized in that, After obtaining the adjusted sample, the method further includes: A third major language model was determined for validity testing of the adjusted samples; The adjusted samples are then tested for validity using the third language model to obtain the test results.
13. The method according to any one of claims 1-10, characterized in that, Based on the aforementioned fault injection sample, a code fault sample is generated, including: At least one intermediate node in the fault injection sample is modified to obtain the modified sample; Determine the fault injection information corresponding to the adjusted sample, wherein the fault injection information includes at least one of the following: fault type, fault location, and fault injection parameters corresponding to the code fault sample; The adjusted samples are automatically labeled based on the fault injection information to generate structured code fault samples.
14. An apparatus for generating code fault samples, characterized in that, include: The first acquisition module is used to acquire the call structure information of code functions. The call structure information includes multiple nodes and directed edges between the nodes. The nodes are used to identify the type of code function, and the directed edges are used to identify the call relationship between code functions. The first determining module is used to determine a call sample based on the call structure information, wherein the link length of the call sample is greater than or equal to a preset length threshold. The first processing module is used to perform fault injection operations on the end nodes in the call sample to obtain a fault injection sample. The first processing module is further configured to generate a code fault sample based on the fault injection sample.
15. An electronic device, characterized in that, include: A memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method of any one of claims 1-13.
16. A computer program product, characterized in that, include: A computer program, when executed by a processor of an electronic device, causes the processor to perform the steps of the method of any one of claims 1-13.