Fault injection method and device, fault test method and device, computer equipment and medium
By using the fault injector to generate and inject a fault program in the fault testing, the problem of inefficient fault testing in the prior art is solved, and a more efficient fault testing process is achieved.
Patent Information
- Application Number
- CN202411716397.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-11
AI Technical Summary
The existing technology is inefficient in fault testing, and it is necessary to re-modify the fault library and compile the product source code, resulting in reduced testing efficiency.
Generate a fault program through a fault injector and inject it into the target function instead of inserting it into the source code of the target process. This method allows the faulty program to process input parameters and/or return parameters when the target function is called by the target process, thereby simulating the fault and generating a new faulty program by modifying the request when needed, avoiding recompiling the source code.
Improves the efficiency of fault testing, reduces time cost and complexity during the test process, and allows developers to quickly respond to and adjust fault testing strategies.
Smart Images

Figure CN119597630A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of fault testing, and in particular to a fault injection method, a fault testing method, an apparatus, a computer device and a medium. Background Art
[0002] In the field of software development and operation and maintenance, in order to improve the reliability and stability of the developed products, during the testing phase, developers will actively inject faults into the products to test the product's ability to handle faults.
[0003] In the related art, a hot patch technology is usually used to replace the Syscall instruction Hook system call of the Libc library to simulate the system call failure; Figure 1 As shown, the fault injection method in the related art requires that the fault injection library be embedded into the source code of the product, and the corresponding fault injection library must be compiled and linked. When the injected fault needs to be adjusted and modified, not only the fault program in the fault library needs to be modified again, but also the source code of the product needs to be recompiled, which makes the efficiency of fault testing low.
[0004] Therefore, how to improve the efficiency of fault testing is an issue that needs to be addressed urgently. Summary of the invention
[0005] Based on this, it is necessary to provide a fault injection method, fault testing method, device, computer equipment and medium that can improve the efficiency of fault testing in response to the above technical problems.
[0006] In a first aspect, the present application provides a fault injection method, comprising:
[0007] Obtain a fault modification request, wherein the parameters of the fault modification request include at least a target signature, a target identifier, a fault type, a modification content, and an injection period;
[0008] Calling a fault injector to generate a fault program corresponding to the fault modification request;
[0009] The fault injector is used to inject the fault program into a target function, wherein when the target function is called by a target process, the fault program is used to process the input parameters and / or return parameters of the target function; the target function is the function corresponding to the target signature, and the target process is the service process corresponding to the target identifier.
[0010] In one embodiment, calling a fault injector to generate a fault program corresponding to the fault modification request includes:
[0011] Calling the fault injector to match various parameters in the fault modification request and determine the program content corresponding to each of the parameters;
[0012] The program content corresponding to each of the parameters is filled into the program template to obtain the fault program corresponding to the fault modification request.
[0013] In one embodiment, injecting the fault program into a target function using the fault injector includes:
[0014] Determine a target compiler and a target compilation type based on at least one parameter in the fault correction request;
[0015] Compiling the fault program based on the target compiler and the target compilation type to obtain compiled fault bytecode;
[0016] The fault bytecode is injected into the target function using the fault injector.
[0017] In one embodiment, injecting the fault bytecode into the target function using the fault injector includes:
[0018] Based on the target signature, determining a target address for storing the target function;
[0019] The fault injector is used to inject the fault bytecode into the target function corresponding to the target address.
[0020] In one of the embodiments, the method further comprises: receiving a fault clearing request, wherein the parameters of the fault clearing request at least include a clearing signature and a clearing identifier;
[0021] Calling the fault injector, and determining a storage address storing a function to be cleared based on the clearing signature, wherein the function to be cleared is a function corresponding to the clearing signature;
[0022] A program to be cleared is determined based on various parameters in the clearing request, and the program to be cleared is deleted, wherein the program to be cleared includes at least one of the fault programs injected into the function to be cleared.
[0023] In one embodiment, the method further comprises:
[0024] Receive a query request, and based on the query request, obtain status information of each injected fault program, the status information including fault type, running status, and running times;
[0025] The state information of each injected fault program is sent to the target device.
[0026] In a second aspect, the present application provides a fault testing method, the method comprising:
[0027] When the current process calls the target function, determining whether there is a target program corresponding to the current process in each fault program injected into the target function; the target program is used to process the input parameters or output parameters of the target function when the current process calls the target function;
[0028] If it is determined that the target program corresponding to the current process exists, a fault parameter is fed back to the current process, where the fault parameter is a parameter obtained after the target program processes the input parameter and / or output parameter of the target function.
[0029] In a third aspect, the present application further provides a fault testing device, the device comprising a request acquisition module, a program generation module and an injection module, wherein:
[0030] A request acquisition module, used to acquire a fault modification request, wherein the parameters of the fault modification request include at least a target signature, a target identifier, a fault type, a modification content, and an injection period;
[0031] A program generation module, used for calling a fault injector to generate a fault program corresponding to the fault modification request;
[0032] An injection module is used to use the fault injector to inject the fault program into a target function, wherein when the target function is called by a target process, the fault program is used to process the input parameters and / or return parameters of the target function; the target function is the function corresponding to the target signature, and the target process is the service process corresponding to the target identifier.
[0033] In a fourth aspect, the present application further provides a fault testing device, the device comprising a determination module and a feedback module, wherein:
[0034] A determination module, used for determining whether there is a target program corresponding to the current process in each fault program injected into the target function when the current process calls the target function; the target program is used for processing the input parameters or output parameters of the target function when the current process calls the target function;
[0035] The feedback module feeds back fault parameters to the current process if it is determined that the target program corresponding to the current process exists, wherein the fault parameters are parameters obtained after the target program processes the input parameters and / or output parameters of the target function.
[0036] In a fifth aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of any one of the methods in the first aspect or the second aspect are implemented.
[0037] In a sixth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods in the first aspect or the second aspect described above.
[0038] In a seventh aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of any one of the methods in the first aspect or the second aspect above.
[0039] The above-mentioned fault injection method, fault testing method, device, computer equipment and medium generate a corresponding fault program based on a fault injector based on the acquired fault modification request, and the fault program is not inserted into the source code of the target process to be tested, but is injected into the target function called by the target process to be tested, so that when the target function is called by the target process, the fault program can process the input parameters and / or return parameters of the target function, which makes the target function feed back to the target process with incorrect parameters, thereby realizing the simulation of the target process running fault; and each time the injected fault program needs to be modified, it is only necessary to input a fault modification request so that the fault injector generates a new fault program to inject into the function called by the target process, without the need to readjust and compile the source code of the target product, thereby improving the efficiency of fault testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 A logical diagram of fault injection in related technologies;
[0042] Figure 2 A schematic diagram of a fault injection method in one embodiment;
[0043] Figure 3 A schematic diagram of steps for generating a fault program in one embodiment;
[0044] Figure 4 A schematic diagram of a process of compiling a faulty program in one embodiment;
[0045] Figure 5 A schematic diagram of the steps of troubleshooting in one embodiment;
[0046] Figure 6 A schematic diagram of a monitoring process for an injected fault program in one embodiment;
[0047] Figure 7 is a flowchart of a fault injection method in another embodiment;
[0048] Figure 8 A schematic diagram of a fault injection scenario in another embodiment;
[0049] Fig. 9 A code schematic diagram of fault injection in another embodiment;
[0050] Fig.10 A schematic diagram of a flow chart of a fault testing method in an embodiment;
[0051] Fig.11 A schematic diagram of a fault injection and fault testing scenario in one embodiment;
[0052] Fig.12 is a structural block diagram of a fault injection device in one embodiment;
[0053] Fig.13 is a structural block diagram of a fault testing device in one embodiment;
[0054] Fig.14 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] In an exemplary embodiment, a fault injection method is provided, and the method is applied to a computer device as an example for explanation, wherein the computer device may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices, and portable wearable devices, and the Internet of Things devices may be smart speakers, smart TVs, smart air conditioners, smart car devices, etc. The portable wearable device may be a smart watch, a smart bracelet, a head-mounted device, etc.; the server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0057] Here are some explanations of some terms used in the fault injection method of this application:
[0058] EBPF (Extended Berkeley Packet Filter): It is a powerful virtual machine technology in the Linux kernel. It provides a set of safe runtime constraints and verification mechanisms to ensure system stability while extending kernel functions.
[0059] Fault Injection: is a method used to test and verify the behavior and recovery capabilities of a computer system or software program in the event of a fault. Fault injection simulates various failure scenarios by intentionally introducing errors or anomalies to observe the system's response, detect potential problems, and evaluate the system's reliability and robustness.
[0060] Kprobe (Kernel Probe): is a mechanism for inserting probes at any location in the Linux kernel. It allows developers to insert EBPF probes at specific kernel functions or instructions to capture, record, and modify runtime information at these locations.
[0061] Kretprobe (Kernel Return Probe): is an extension of Kprobe that can insert EBPF probes when a function returns, thereby capturing, recording, and modifying runtime information at these locations.
[0062] Uprobe (User-space Probe) is a mechanism for inserting probes into user-space programs. It allows developers to insert EBPF probes at any location in a user-space program without modifying the program's source code.
[0063] Uretprobe (User-space Return Probe): is an extension of Uprobe, similar to Kretprobe, which can insert EBPF probes when user-space functions return.
[0064] EBPF_MAP (Extended Berkeley Packet Filter Map): is a data structure used by EBPF programs and user processes to store and share data.
[0065] The fault injection method provided in the embodiment of the present application may specifically include steps 110 to 130. Figure 2 As shown, where:
[0066] Step 110: Obtain a fault modification request, the parameters of which include at least a target signature, a target identifier, a fault type, modification content, and an injection period.
[0067] For the embodiments of the present application, the fault modification request may be input by the user, or may be pre-configured and acquired by the computer device under corresponding triggering conditions. In one possible implementation, the fault modification request is acquired by the computer device at a preset time; in another possible implementation, the fault modification request may be matched with the development progress of the product, that is, the fault modification request corresponding to the product at different development progresses is pre-set, and when the development progress of the product is updated, the computer device acquires the latest development progress of the product, and then acquires the corresponding fault modification request according to the development progress.
[0068] Among them, when the product is running, some processes of the product need to call the pre-stored functions in the target function library. The target signature is the function signature of the target function that needs to be injected with faults. The function signature is unique and represents the identity of the function and the function implemented. The target identifier is the identifier of one or more processes in the product. Based on the actual test requirements, it may be necessary to test all processes that call the target function, or it may be necessary to test only one or several processes that call the target function. The target identifier represents the process to be tested. Among them, the fault type is the type of fault added. For example, the fault type can be to modify the input parameters of the target function and / or to modify the return parameters of the target function; the classification of fault types is not specifically limited in the embodiments of the present application. The modification content is the specific logic to be injected with faults, that is, the specific content of modifying the corresponding data in the process. The injection period is the period for injecting faults. For example, the injection period can be permanent or single.
[0069] Step 120: Call the fault injector to generate a fault program corresponding to the fault modification request.
[0070] For the embodiment of the present application, the fault injector is a pre-built component that can generate a corresponding fault program based on a fault modification request. In one possible implementation, the fault injector is configured to parse each parameter in the fault modification request, obtain parsing information corresponding to each parameter, and then match it in a pre-built program mapping table based on the parsing information corresponding to each parameter, thereby obtaining the program content corresponding to each parameter in the fault modification request, and then construct a fault program based on the program content corresponding to each parameter. Among them, the program mapping table includes probe types and program contents corresponding to each parameter type.
[0071] In another possible implementation, the fault injector can be built based on a pre-trained LLM (Large Language Model) model, that is, after parsing the fault modification request, the parsing information corresponding to each parameter in the fault modification request is obtained, and then the parsing information is organized into an input template of the LLM model and input into the fault injector to obtain the fault program output by the fault injector.
[0072] Among them, the specific logic of the fault injector generating the fault program based on the fault injection request is not specifically limited in the embodiments of the present application.
[0073] Step 130: Use a fault injector to inject a fault program into a target function, wherein when the target function is called by a target process, the fault program is used to process input parameters and / or return parameters of the target function; the target function is a function corresponding to a target signature, and the target process is a service process corresponding to a target identifier.
[0074] For the embodiment of the present application, the fault injector is also configured to inject the generated fault program into the target function corresponding to the target signature, so that when the target process corresponding to the target identifier in the product calls the target function, the injected fault program can process the input parameters and / or return parameters of the input target function, so that the target process receives the erroneous return parameters returned by the target function, thereby realizing the simulation of the fault.
[0075] In the above fault injection method, a fault injector generates a corresponding fault program based on the acquired fault modification request, and the fault program is not inserted into the source code of the target process to be tested, but is injected into the target function called by the target process to be tested, so that when the target function is called by the target process, the fault program can process the input parameters and / or return parameters of the target function, which means that the target function feeds back incorrect parameters to the target process, thereby simulating the running fault of the target process; and each time the injected fault program needs to be modified, it is only necessary to input a fault modification request so that the fault injector generates a new fault program and injects it into the function called by the target process, without the need to readjust and compile the source code of the target product, thereby improving the efficiency of fault testing.
[0076] In one embodiment, referring to Figure 3 , step 120 may specifically include step 121 and step 122, wherein:
[0077] Step 121: calling the fault injector to match various parameters in the fault modification request and determine the program content corresponding to each parameter;
[0078] Specifically, in an embodiment of the present application, the fault injector is configured to parse each parameter in the fault modification request, obtain the parsing information corresponding to each parameter, and then match it in a pre-built program mapping table based on the parsing information corresponding to each parameter, thereby obtaining the program content corresponding to each parameter in the fault modification request, and then constructing the fault program based on the program content corresponding to each parameter. The program mapping table includes the probe type and program content corresponding to each parameter type.
[0079] Among them, the data carried by the fault modification request may be encoded data or natural language. Therefore, the fault injector is first called to parse the fault modification request to obtain the parsing information of each parameter; the parsing information is a structural parameter or code parameter in a preset format. The specific type of the parsing information is not specifically limited in the embodiment of the present application.
[0080] Specifically, after the target signature is parsed, the parsed information obtained is the target address where the target function and target parameters are stored; after the target identifier is parsed, the parsed information obtained is the PID (Process Identifier) identifier of the target process; after the fault type is parsed, the parsed information obtained is the modification of the input parameters and / or return parameters of the target parameters; after the modified content is parsed, the parsed information obtained is the logic of the parameter modification or the modified content; after the injection period is parsed, the parsed information obtained is the validity period of the injected fault program, or the number of valid times. Furthermore, the mapping relationship table stores the program content (program code) corresponding to each parameter. Based on the parsed information of each parameter, the fault injector matches from the mapping relationship table to determine the program content corresponding to each parameter.
[0081] Furthermore, the target function may be a function called by a service process in the kernel of the product, or a function called by a process in a user space program; therefore, after parsing the parsed information of the target signature, the function type of the target function is determined, and the function type indicates whether the function is called by a process in the kernel or a process in the user space; then the program content corresponding to the target signature is determined based on the type of the target function. For example, if the target function is a function called by a service process in the kernel, the program content matching the kernel probe Kprobe can be used.
[0082] Step 122: Fill the program content corresponding to each parameter into the program template to obtain the fault program corresponding to the fault modification request.
[0083] Specifically, the program template can be a preset fixed template, or it can be a target template determined based on the target process or target function. In one possible implementation, the target function may be a function called by a service process in the kernel of the product, or it may be a function called by a process in a user space program. Therefore, the target template is matched from the preset program templates based on the function type of the target function determined in the above steps. For example, if the target function is a function called by a service process in the kernel, then the target template matched based on the function type of the target function should be a program template that matches the kernel probe Kprobe. In another possible implementation, the process type of the target process can also be directly determined. The process type characterizes whether the process is a service process in the kernel or a service process in the user space, and then the target template is matched from the preset program templates based on the type of the target process.
[0084] In one embodiment, referring to Figure 4 In step 130, the process may specifically include steps 131 to 133, wherein:
[0085] Step 131: determine a target compiler and a target compilation type based on at least one parameter in the fault correction request;
[0086] Step 132: Compile the faulty program based on the target compiler and the target compilation type to obtain compiled faulty bytecodes.
[0087] Specifically, in the embodiment of the present application, the fault program generated based on the fault modification request needs to be compiled into a corresponding format before it can be loaded and run; wherein, the target compiler and target compilation type required to compile the fault program can be a preset compiler and compilation type, such as the compilation type can be Elf (Executable and Linkable Format). Further, the target compiler and target compilation type can be determined from a plurality of preset compilers and compilation types based on at least one parameter in the request; in one possible implementation method, the target compilation type can be a type that matches the function type or programming language of the target function, and the target compilation type can also be a type that matches the process type of the target process; and then the target compiler is determined based on the determined target compilation type; the specific method for determining the target compilation type and the target compiler is not specifically limited in the embodiment of the present application, as long as the fault bytecode obtained after compilation can run stably.
[0088] Step 133: Use a fault injector to inject the fault bytecode into the target function.
[0089] Specifically, based on the target signature, the target address of the target function is determined, and then the fault injector is used to inject the fault bytecode into the target function corresponding to the target address. The target address of the target function can be obtained based on the parsing information obtained after parsing the target signature in step 121.
[0090] The above content explains how to generate a fault program corresponding to a fault modification request, and how to inject the generated fault program into the corresponding target function. In fact, a fault modification request is equivalent to a fault injection request. Moreover, the target function injected into a fault modification request can be a target function that has been injected with a fault program, or a target function that has not been injected with a fault program.
[0091] In one embodiment, a method for clearing a faulty program that has been injected into a function is further described, referring to Figure 5 , specifically including steps 140 to 160, wherein:
[0092] Step 140: Receive a fault clearing request, where the parameters of the fault clearing request include at least a clearing signature and a clearing identifier.
[0093] Specifically, in one possible scenario, the fault test of the product may be to perform fault testing on the complete product after the services of each module of the product are built, or it may be necessary to perform fault testing on the product when the services of some modules of the product are built. A topology diagram is constructed in advance based on the module architecture / service architecture of the product, where each node in the topology diagram represents a service process or a service process tree (including multiple associated process sets), and the changes between nodes represent the input and output of data; then, corresponding fault injection requests and fault clearing requests are configured for each node.
[0094] When it is necessary to perform fault testing on an incomplete product, the current product is traversed to obtain the various service processes that have been built, and then the development progress of the product is determined based on the matching of the various service processes that have been built in the product's topological relationship diagram. Then, the fault injection requests and / or fault clearing requests corresponding to the various development processes that have been built in the topological relationship diagram are obtained.
[0095] Step 150: calling the fault injector to determine the storage address of the function to be cleared based on the clearing signature, where the function to be cleared is the function corresponding to the clearing signature;
[0096] Step 160: determine the program to be cleared based on various parameters in the clearing request, and delete the program to be cleared, wherein the program to be cleared includes at least one of the faulty programs that has been injected into the function to be cleared.
[0097] Specifically, the fault clearing request at least includes a clearing signature and / or a clearing identifier, wherein the clearing signature is the signature of the function (the function to be cleared) injected by the fault program, and when the process corresponding to the clearing identifier (the process to be cleared) calls the function corresponding to the clearing signature, the fault program that has been injected is executed. Further, when the fault clearing request only includes the clearing signature, the fault injector is called, the storage address of the function to be cleared is determined based on the clearing signature, and then all the fault programs injected into the function to be cleared are deleted; when the fault clearing request only includes the clearing identifier, the fault injector is called, all the functions that can be called by the process to be cleared are determined based on the clearing identifier, and then the fault programs injected into these functions are deleted. In the case where the fault clearing request includes the clearing signature and the clearing identifier, the fault injector is called, the storage address of the function to be cleared is determined based on the clearing signature, and then the program to be cleared is determined based on the parameters in the clearing request, and the program to be cleared is deleted. Among them, the program to be cleared includes at least one of the fault programs injected into the function to be cleared.
[0098] Furthermore, when the fault injector injects a fault program into the corresponding function in response to any fault modification request, and when injecting a fault program into the corresponding function based on any fault clearing request parameter, a corresponding execution log will be generated, which records the time when the fault program is injected into the function or the time when the fault program is deleted from the injected function.
[0099] In one embodiment, in order to facilitate the management and monitoring of each fault program that has been injected, in the embodiment of the present application, a monitoring process for each fault program that has been injected is also included, referring to Figure 6 , which may specifically include step 170 and step 180, wherein:
[0100] Step 170: receiving a query request, and obtaining status information of each injected fault program based on the query request, the status information including fault type, running status, and running times;
[0101] Step 180: Send the status information of each injected faulty program to the target device.
[0102] Specifically, the query request may be sent by a user, or may be automatically generated at preset intervals, or may be generated in response to the injection action of a new fault program. The generation process of the query request is not specifically limited in the embodiment of the present application. Among them, each fault program injected can send its status information to the target device through the PERF_EVENT mechanism. The status information includes the fault type, running status, and number of runs, and may also include information such as whether the fault injection is successful. The present application does not specifically limit the specific content of the status information. By receiving the status information of each fault program, the fault injector can monitor the operation of each injected fault program in real time and provide feedback to the developer.
[0103] In an exemplary embodiment, the present application provides a fault injection method, which specifically includes steps S1 to S6, wherein:
[0104] Step S1, start the fault management program.
[0105] Specifically, in step S1, the fault management program is a resident user process that provides services to the outside through an HTTP (HyperText Transfer Protocol) or API (Application Programming Interface) interface. Users can submit fault injection requests, fault clearing requests, and query requests through the interface.
[0106] Step S2: dynamically generate an EBPF program.
[0107] Specifically, in step S2, when the fault management service receives a fault modification request or a fault injection request from a user, it will dynamically generate an EBPF program based on the various parameters in the request (such as function entry point, fault type, modification content, etc.), where the function entry point is the signature of the function to be injected with the fault, that is, the target signature. The generated EBPF program (fault program) can modify the input parameters and / or return parameters of the corresponding function to simulate different types of faults.
[0108] Step S3: compile the EBPF program.
[0109] Specifically, in step S3, the generated EBPF program code is compiled into Elf format bytecode so that it can be loaded and executed by the kernel. During the compilation process, an appropriate compiler and compilation options are determined to ensure that the generated fault bytecode can run correctly.
[0110] Step S4: Mount the EBPF program to the probe point.
[0111] Specifically, in step S4, the compiled fault bytecode will be mounted to the specified probe point, which can be any one of Kprobe, Kretprobe, Uprobe or Uretprobe points. The probe point is determined based on the function type of the target function to be inserted into the fault, and the function type indicates whether the target function is a function called by the kernel of the system or a function called by the user space; the probe points Kprobe, Kretprobe, Uprobe or Uretprobe correspond to the entry point and return point of the function called by the system and the entry point and return point of the function called by the user. When the target function is called, the corresponding EBPF program will be triggered to execute, thereby modifying the behavior of the target function.
[0112] Step S5: process limitation and status monitoring.
[0113] Specifically, in step S5, in order to ensure the accuracy of fault injection, for each injected EBPF program (fault program), each fault program is limited to only be effective for the specified PID process (target process) through EBPF_MAP. This means that for an injected fault program, only a specific process will be affected by the fault program. The EBPF program reports the running status (status information) to the fault management service through the PERF_EVENT (performance analysis tool) mechanism, including information such as whether the fault injection is successful. By receiving this status information, the fault management service can monitor the running status of each injected EBPF program in real time and provide feedback to the user.
[0114] Step S6: troubleshooting and querying.
[0115] Specifically, in step S6, the user can submit a fault clearing request through HTTP or API interface. After receiving the clearing request, the fault management service will unmount the corresponding EBPF program so that the corresponding function can be correctly called and process parameters by the corresponding process. At the same time, the user can also query the injection status of the current fault program to the fault, and the fault management service will provide detailed status information, including which processes are being injected with faults, fault types, etc.
[0116] In the above fault injection method, a fault injector generates a corresponding fault program based on the acquired fault modification request, and the fault program is not inserted into the source code of the target process to be tested, but is injected into the target function called by the target process to be tested, so that when the target function is called by the target process, the fault program can process the input parameters and / or return parameters of the target function, which makes the target function feed back to the target process with wrong parameters, thereby realizing the simulation of the target process running fault; and each time the injected fault program needs to be modified, it is only necessary to input the fault modification request so that the fault injector generates a new fault program and injects it into the function called by the target process, without the need to readjust and compile the source code of the target product, thereby improving the efficiency of fault testing.
[0117] This application provides an example of fault injection:
[0118] A scenario for using a fault injector in a test is Figure 8 As shown, the test suite initiates a fault injection (modification) request to the fault injection manager. The fault injection request includes the PID of the injected process, the function signature of the injected fault, the fault injection method (input parameter or return value), the injection strategy (single injection or permanent effect, etc.). After receiving the fault injection (modification) request, the fault injection manager converts the request into an EBPF program (fault program) and calls the Clang compiler to compile it into an Elf format binary file, and then mounts the compiled binary file (bytecode) to the corresponding function of Kprobe or Uprobe. The test suite sends a fault test request to the service (product) under test, and the service process under test executes it. When the service process under test calls the function of the fault program injected with the fault, the fault program is executed and then the input parameters and return values of the function are modified to achieve the purpose of fault injection. The test suite determines whether the service process under test can recover as expected after a fault occurs through the response of the service under test.
[0119] The following code example injects faults: Fig. 9 As shown in the figure, when the process with process ID 12345 calls the Open function to open a disk file named Filename, the file name will be replaced with ". / not_exist.data" before the actual open operation is performed. Since the file does not exist, the Open function call will fail. Of course, the EBPF program (fault program) generated in the actual fault test will be much more complicated than this example, because the EBPF program will contain a lot of logic that interacts with the fault management program, which will not be repeated here.
[0120] Through the fault injection method of the embodiment of the present application, the injected fault program is completely decoupled from the source code of the product, forming a non-intrusive fault injection. And because the fault program injected by the present application adopts EBPF technology, the modification of function input parameters and return values is realized by mounting Kprobe, Kretprobe, Uprobe and Uretprobe. In this way, faults can be injected and modified without modifying the source code of the product, ensuring the integrity and stability of the source code of the product.
[0121] The fault injector allows the user to finely control the fault injection strategy by inputting a fault modification request. For example, the number of fault injections can be set, and fault injection can be specified only for specific functions. This flexibility makes the fault testing of the product more accurate and meets different testing requirements. And through the fault injection method of the present application, the fault injection strategy can be flexibly adjusted. When modifying the fault injection strategy, there is no need to recompile the source code corresponding to the product process, only the test suite (fault program) needs to be adjusted. This greatly improves the test efficiency, reduces the time cost incurred by recompiling the source code of the product process, and makes the fault injection test more convenient and efficient. Developers can independently choose to perform fault injection for each function that may fail in the product, not only for kernel calls in the system, but also for user-defined functions. In this way, a wider range of fault scenarios can be covered during the development and testing phase of the product to discover more potential problems and improve the robustness of the product.
[0122] In one embodiment, the present application provides a fault testing method, referring to Fig.10 The method may specifically include step 210 and step 220, wherein:
[0123] Step 210: when the current process calls the target function, determine whether there is a target program corresponding to the current process in each fault program injected into the target function; the target program is used to process the input parameters or output parameters of the target function when the current process calls the target function;
[0124] Step 220: If it is determined that there is a target program corresponding to the current process, the fault parameter is fed back to the current process, where the fault parameter is a parameter obtained after the target function processes the input parameter or output parameter of the target function.
[0125] Specifically, for the method of injecting the target program (fault program), please refer to the limitation of injecting the fault program into the target function in the above fault injection method embodiment, which will not be repeated here. When the product is executed by a computer device, when the current process calls the target function, if the target function is injected with the fault program, the fault program will be executed, thereby modifying the input parameters of the input target function and / or the output parameters of the target function, and the target function will feed back the erroneous parameters processed by the fault program to the current process, so that the parameters obtained by the current process are faulty.
[0126] In one of the examples, a diagram of injecting faults into the target function and testing the current process is shown below. Fig.11 The test suite initiates a fault injection (modification) request to the fault injection manager. The fault injection request includes the PID of the injected process, the function signature of the injected fault, the fault injection method (input parameter or return value), the injection strategy (single injection or permanent effect, etc.). After receiving the fault injection (modification) request, the fault injection manager (fault injector) converts the request into an EBPF program (fault program) and calls the Clang compiler to compile it into an Elf format binary file, and then mounts the compiled binary file (bytecode) to the corresponding function of Kprobe or Uprobe. The test suite sends a fault test request to the service (product) under test, and the process of the service under test executes it. When the service process under test calls the function of the fault program injected with the fault, the fault program is executed and then the input parameters and return values of the function are modified to achieve the purpose of fault injection. The test suite determines whether the service process under test can recover as expected after a fault occurs through the response of the service under test.
[0127] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0128] Based on the same inventive concept, the embodiment of the present application also provides a fault injection device for implementing the fault injection method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more fault injection device embodiments provided below can refer to the limitations of the fault injection method above, and will not be repeated here.
[0129] In an exemplary embodiment, Fig.12 As shown, a fault injection device is provided, including a request acquisition module 1201, a program generation module 1202 and an injection module 1203, wherein:
[0130] The request acquisition module 1201 is used to acquire a fault modification request, wherein the parameters of the fault modification request include at least a target signature, a target identifier, a fault type, a modification content, and an injection period;
[0131] A program generation module 1202, used to call a fault injector to generate a fault program corresponding to a fault modification request;
[0132] The injection module 1203 is used to use the fault injector to inject the fault program into the target function, wherein when the target function is called by the target process, the fault program is used to process the input parameters and / or return parameters of the target function; the target function is the function corresponding to the target signature, and the target process is the service process corresponding to the target identifier.
[0133] In the above-mentioned fault injection device, a fault injector generates a corresponding fault program based on the acquired fault modification request, and the fault program is not inserted into the source code of the target process to be tested, but is injected into the target function called by the target process to be tested, so that when the target function is called by the target process, the fault program can process the input parameters and / or return parameters of the target function, which means that the target function feeds back incorrect parameters to the target process, thereby simulating the running fault of the target process; and each time the injected fault program needs to be modified, it is only necessary to input a fault modification request so that the fault injector generates a new fault program and injects it into the function called by the target process, without the need to readjust and compile the source code of the target product, thereby improving the efficiency of fault testing.
[0134] In one embodiment, the program generation module 1202 is specifically used to:
[0135] Call the fault injector to match the parameters in the fault modification request and determine the program content corresponding to each parameter;
[0136] The program contents corresponding to each parameter are filled into the program template to obtain the fault program corresponding to the fault modification request.
[0137] In one embodiment, the injection module 1203 is specifically used to:
[0138] determining a target compiler and a target compilation type based on at least one parameter in the fault correction request;
[0139] Compile the fault program based on the target compiler and the target compilation type to obtain compiled fault bytecode;
[0140] Utilize the fault injector to inject faulty bytecode into the target function.
[0141] In one embodiment, the injection module 1203 is specifically used to:
[0142] Based on the target signature, determine the target address where the target function is stored;
[0143] The fault injector is used to inject the fault bytecode into the target function corresponding to the target address.
[0144] In one embodiment, the fault injection device further includes a fault clearing module, and the fault clearing module is specifically used to:
[0145] receiving a fault clearing request, wherein the parameters of the fault clearing request include at least a clearing signature and a clearing identifier;
[0146] Call the fault injector to determine the storage address of the function to be cleared based on the clearing signature, where the function to be cleared is the function corresponding to the clearing signature;
[0147] The program to be cleared is determined based on various parameters in the clearing request, and the program to be cleared is deleted. The program to be cleared includes at least one of the fault programs that has been injected into the function to be cleared.
[0148] In one embodiment, the fault injection device further includes a monitoring module, and the monitoring module is specifically used to:
[0149] Receive a query request, and based on the query request, obtain status information of each fault program that has been injected, the status information including the fault type, running status, and running times;
[0150] The status information of each injected fault program is sent to the target device.
[0151] Based on the same inventive concept, the embodiment of the present application also provides a fault testing device for implementing the fault testing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more fault testing device embodiments provided below can refer to the limitations of the fault testing method above, and will not be repeated here.
[0152] In an exemplary embodiment, Fig.13 As shown, a fault testing device is provided, including a determination module 1301 and a feedback module 1302, wherein:
[0153] The determination module 1301 is used to determine whether there is a target program corresponding to the current process in each fault program injected into the target function when the current process calls the target function; the target program is used to process the input parameters or output parameters of the target function when the current process calls the target function;
[0154] Feedback module 1302, if it is determined that there is a target program corresponding to the current process, then feeds back fault parameters to the current process, where the fault parameters are parameters obtained after the target program processes the input parameters and / or output parameters of the target function.
[0155] Each module in the above-mentioned fault injection device and fault testing device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.
[0156] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.14As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a fault injection method and / or a fault testing method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0157] Those skilled in the art will understand that Fig.14 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0158] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of the above-mentioned fault injection method embodiment and / or fault testing method embodiment are implemented.
[0159] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned fault injection method embodiment and / or fault testing method embodiment are implemented.
[0160] In one embodiment, a computer program product is provided, including a computer program, which implements the steps of the above-mentioned fault injection method embodiment and / or fault testing method embodiment when executed by a processor.
[0161] It should be noted that 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, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0162] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0163] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0164] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A fault injection method, characterized in that: The method comprises: Obtain a fault modification request, wherein the parameters of the fault modification request include at least a target signature, a target identifier, a fault type, a modification content, and an injection period; Calling a fault injector to generate a fault program corresponding to the fault modification request; The fault injector is used to inject the fault program into a target function, wherein when the target function is called by a target process, the fault program is used to process the input parameters and / or return parameters of the target function; the target function is the function corresponding to the target signature, and the target process is the service process corresponding to the target identifier.
2. The method according to claim 1, characterized in that The calling of the fault injector to generate a fault program corresponding to the fault modification request includes: Calling the fault injector to match various parameters in the fault modification request and determine the program content corresponding to each of the parameters; The program content corresponding to each of the parameters is filled into the program template to obtain the fault program corresponding to the fault modification request.
3. The method according to claim 1, characterized in that The step of injecting the fault program into a target function by using the fault injector comprises: Determine a target compiler and a target compilation type based on at least one parameter in the fault correction request; Compiling the fault program based on the target compiler and the target compilation type to obtain compiled fault bytecode; The fault bytecode is injected into the target function using the fault injector.
4. The method according to claim 3, characterized in that The step of injecting the fault bytecode into the target function by using the fault injector comprises: Based on the target signature, determining a target address for storing the target function; The fault injector is used to inject the fault bytecode into the target function corresponding to the target address.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Receiving a fault clearing request, wherein the parameters of the fault clearing request include at least a clearing signature and a clearing identifier; Calling the fault injector, and determining a storage address storing a function to be cleared based on the clearing signature, wherein the function to be cleared is a function corresponding to the clearing signature; A program to be cleared is determined based on various parameters in the clearing request, and the program to be cleared is deleted, wherein the program to be cleared includes at least one of the fault programs injected into the function to be cleared.
6. The method according to claim 1, characterized in that The method further comprises: Receive a query request, and based on the query request, obtain status information of each injected fault program, the status information including fault type, running status, and running times; The state information of each injected fault program is sent to the target device.
7. A fault testing method, characterized in that: The method comprises: When the current process calls the target function, determining whether there is a target program corresponding to the current process in each fault program injected into the target function; the target program is used to process the input parameters or output parameters of the target function when the current process calls the target function; If it is determined that the target program corresponding to the current process exists, a fault parameter is fed back to the current process, where the fault parameter is a parameter obtained after the target program processes the input parameter and / or output parameter of the target function.
8. A fault injection device, characterized in that: The device comprises a request acquisition module, a program generation module and an injection module, wherein: A request acquisition module, used to acquire a fault modification request, wherein the parameters of the fault modification request include at least a target signature, a target identifier, a fault type, a modification content, and an injection period; A program generation module, used for calling a fault injector to generate a fault program corresponding to the fault modification request; An injection module is used to use the fault injector to inject the fault program into a target function, wherein when the target function is called by a target process, the fault program is used to process the input parameters and / or return parameters of the target function; the target function is the function corresponding to the target signature, and the target process is the service process corresponding to the target identifier.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Fault analysis method and device, medium and program product
CN120704936A
Fault injection method and apparatus, fault testing method and apparatus, computer device, and medium
WO2026114043A1