Fault injection method and device, electronic equipment and storage medium

By obtaining the function content of the kernel function in the user state and modifying it to the objective function content, the injection test failures in the kernel function are achieved, and the problem of limited application scenarios of existing fault injection technology is solved, which improves the flexibility and effect of fault injection.

CN119883877APending Publication Date: 2025-04-25BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311387393.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-24
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The application scenarios of existing fault injection technology are limited, resulting in fault injection not being flexible enough, affecting the fault injection effect.

Method used

In the user state, obtain the function content of the kernel function, and determine the target test case based on the kernel function, including the objective function content, and modify the function content of the kernel function to the objective function content to inject test failures corresponding to the target test case into the kernel function.

Benefits of technology

Effectively broaden the application scenarios of fault injection, improve the flexibility and effect of fault injection, and realize fault injection in user and kernel states.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883877A_ABST
    Figure CN119883877A_ABST
Patent Text Reader

Abstract

The invention provides a fault injection method and device, electronic equipment and a storage medium. The method comprises the steps that function content of a kernel function is acquired in a user mode; according to the kernel function, a target test case is determined, and the target test case comprises target function content; and modifying the function content of the kernel function into the target function content so as to inject a test fault corresponding to the target test case into the kernel function. Through the fault injection method and device, the application scene of fault injection can be effectively widened, the flexibility of fault injection is improved, and the fault injection effect is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of software testing, and in particular to a fault injection method, device, electronic device and storage medium. Background Art

[0002] Fault injection is a testing technique used to simulate faults or abnormal conditions in software or systems to evaluate their effects and performance in such situations. Fault injection can help developers and testers understand the behavior and response of the system in different situations and discover possible defects and vulnerabilities. Fault injection techniques can be used in different stages of software development, such as unit testing, integration testing, system testing, and performance testing. Among the related technologies, one is to use the Kprobe function or Kretprobe function of the kernel instruction set to implement fault injection. The Kprobe function allows developers to insert breakpoints at the entrance or exit of the kernel function to observe and track the execution process of the kernel function, and can inject faults or abnormal conditions under specific conditions. The Kretprobe function is a dynamic tracing mechanism for executing custom code when the kernel function returns. Similar to the Kprobe function, the Kretprobe function is also a non-invasive technology that allows developers to insert code for monitoring and analysis when the kernel function returns. Another is to form fault injection in the user state by using instructions and application programming interfaces (APIs).

[0003] In these methods, the application scenarios of fault injection are relatively constrained, resulting in inflexibility of fault injection and affecting the effect of fault injection. Summary of the invention

[0004] The present disclosure aims to solve one of the technical problems in the related art at least to some extent.

[0005] To this end, the present disclosure proposes a fault injection method, device, electronic device, non-transitory computer-readable storage medium storing computer instructions, and computer program product, which can effectively broaden the application scenarios of fault injection, improve the flexibility of fault injection, and improve the fault injection effect.

[0006] The fault injection method proposed in the embodiment of the first aspect of the present disclosure includes: obtaining the function content of the kernel function in user mode; determining the target test case based on the kernel function, wherein the target test case includes: the target function content; modifying the function content of the kernel function to the target function content to inject a test fault corresponding to the target test case into the kernel function.

[0007] The fault injection device proposed in the second aspect of the embodiment of the present disclosure includes: an acquisition module, used to obtain the function content of the kernel function in user mode; a determination module, used to determine the target test case according to the kernel function, wherein the target test case includes: the target function content; and a modification module, used to modify the function content of the kernel function into the target function content, so as to inject a test fault corresponding to the target test case into the kernel function.

[0008] The electronic device proposed in the embodiment of the third aspect of the present disclosure includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method proposed in the above embodiment of the present disclosure is implemented.

[0009] The fourth aspect of the present disclosure provides a non-temporary computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method provided in the above embodiment of the present disclosure.

[0010] The fifth aspect of the present disclosure provides a computer program product. When the instructions in the computer program product are executed by a processor, the method provided in the above embodiment of the present disclosure is performed.

[0011] The fault injection method, device, electronic device, and non-transitory computer-readable storage medium storing computer instructions provided by the present invention obtain the function content of the kernel function in user mode, and determine the target test case based on the kernel function, wherein the target test case includes: the target function content, and modifies the function content of the kernel function to the target function content, so as to inject a test fault corresponding to the target test case into the kernel function, thereby effectively broadening the application scenarios of fault injection, improving the flexibility of fault injection, and improving the effect of fault injection.

[0012] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will be obvious from the following description or learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The above and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0014] Figure 1 is a flowchart of a fault injection method proposed in an embodiment of the present disclosure;

[0015] Figure 2 is a schematic diagram of a fault injection scenario in an embodiment of the present disclosure;

[0016] Figure 3 is a flowchart of a fault injection method proposed in another embodiment of the present disclosure;

[0017] Figure 4 is a flowchart of a fault injection method proposed in another embodiment of the present disclosure;

[0018] Figure 5 is a schematic diagram of a fault injection process in an embodiment of the present disclosure;

[0019] Figure 6 is a structural schematic diagram of a fault injection device proposed in an embodiment of the present disclosure;

[0020] Figure 7 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0021] Embodiments of the present disclosure are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present disclosure, and are not to be construed as limitations of the present disclosure. On the contrary, the embodiments of the present disclosure include all changes, modifications, and equivalents that fall within the spirit and connotation of the appended claims.

[0022] Figure 1 It is a flowchart of a fault injection method proposed in an embodiment of the present disclosure.

[0023] This embodiment takes the fault injection method configured as a fault injection device as an example. In this embodiment, the fault injection method can be configured in a fault injection device. The fault injection device can be set in a server, or can also be set in an electronic device, without limitation. This embodiment takes the fault injection method configured in an electronic device as an example. Among them, the electronic device is a hardware device such as a smart phone, a tablet computer, a personal digital assistant, an e-book, etc. with various operating systems.

[0024] It should be noted that the execution subject of the embodiment of the present disclosure may be, for example, a central processing unit (CPU) in a server or electronic device in terms of hardware, or may be, for example, a related background service in a server or electronic device in terms of software, without limitation.

[0025] like Figure 1 As shown, the fault injection method includes:

[0026] S101: Obtain the function content of the kernel function in user mode.

[0027] Among them, User Mode is an operation mode in a computer system, also known as User Space. In User Mode, applications and user processes can directly access the hardware devices and resources of the computer system and perform various tasks and operations. In User Mode, applications can access the hardware devices and resources in Kernel Mode through system calls or library functions. Relatively speaking, Kernel Mode is a higher-privileged operation mode in a computer system, also known as Kernel Space. In Kernel Mode, the kernel and operating system run in the highest privileged environment provided by the CPU, have the highest level of system resources and hardware permissions, and can directly access and control various hardware devices and resources in the system. The existence of User Mode and Kernel Mode is to ensure the security, stability and reliability of the system. By separating applications and operating systems and running them in different operation modes, security vulnerabilities and system crashes can be effectively avoided, and the maintainability and scalability of the system can be improved.

[0028] In the disclosed embodiment, fault injection is supported for one or more kernel functions in the kernel space, and the kernel function may belong to a corresponding kernel module, thereby implementing fault injection for one or more kernel modules. The function content contained in the kernel function before the fault injection may be referred to as the function content. For example, the function content may be, for example, a kernel function parameter or a return value.

[0029] In the disclosed embodiments, it is possible to obtain the function content of a kernel function in user mode to support fault injection into a kernel module, thereby effectively expanding the application scenarios of fault injection.

[0030] S102: Determine a target test case according to the kernel function, wherein the target test case includes: target function content.

[0031] Among them, the fault case to be tested can be called a test case. The target test case can be a test case that matches the kernel function. The target test case can be applied in the kernel module to verify the performance of the device equipped with the test kernel module. The target test case in the embodiment of the present disclosure may include the target function content, and the target function content refers to the function content corresponding to the injected fault case in the process of injecting faults into the kernel function. In other words, processing the content of the kernel function into the target function content can achieve the injection of corresponding faults into the kernel function.

[0032] In some embodiments, the function content includes at least one of an initial parameter type, a structure parameter to be filled, and an initial return value, and the target function content includes at least one of a target parameter type, a target structure parameter, and a target return value, thereby supporting effective injection of faults into kernel functions.

[0033] In some embodiments, before fault injection, the parameter type contained in the kernel function can be referred to as the initial parameter type. In a function declaration or function definition, a formal parameter is a local variable used to receive the actual parameter (Actual Argument) passed when the function is called. A formal parameter is a placeholder in a function definition, which is used to specify the input required by the function. The structure parameter to be filled refers to the structure parameter initially contained in the kernel function. A structure parameter (StructParameter) refers to a formal parameter that passes a structure as a parameter to a function. A structure is a user-defined data type that can contain multiple member variables of different types, and a structure parameter is passed to a function by value or reference. The return value obtained after executing the kernel function can be referred to as the initial return value.

[0034] In some embodiments, the parameter type corresponding to the fault case may be referred to as the target parameter type. The structure parameter corresponding to the fault case may be referred to as the target structure parameter. The return value corresponding to the fault case may be referred to as the target return value.

[0035] In some embodiments, after obtaining the function content of the kernel function in the user mode, the target test case can also be determined according to the kernel function. For example, the function type supported by the kernel function can be determined, and the corresponding test case can be determined as the target test case with reference to the function type; or, the test case can be dynamically configured according to the kernel function, and the configured test case can be used as the target test case; of course, the target test case can also be determined according to the kernel function based on any other possible method, and there is no limitation to this.

[0036] In some embodiments, the kernel module to which the kernel function belongs can be determined, and a set of candidate test cases corresponding to the kernel module can be determined, wherein the candidate test case set includes candidate test cases, and the candidate test cases are used as target test cases to quickly and accurately determine the target test cases.

[0037] That is to say, in the embodiments of the present disclosure, a test case set can be configured for each kernel module. The configured test case set can be called a candidate test case set. Each candidate test case set can contain one or more candidate test cases. The candidate test cases can be configured for the kernel module in user mode, and there is no restriction on this.

[0038] In some embodiments, in the process of determining a set of candidate test cases corresponding to a kernel module, it is possible to determine a function type corresponding to the kernel module and determine a candidate business module corresponding to the function type, wherein a set of candidate test cases has been configured in the candidate business module in user mode, and the set of candidate test cases configured for the corresponding candidate business module is used as a set of candidate test cases corresponding to the kernel module. Since the corresponding set of candidate test cases has been configured for the candidate business module in user mode, and supports corresponding association between the candidate business module and the kernel module in the functional dimension, it is possible to inject faults from the user mode to the kernel mode, and expand the scope of application of fault injection to each kernel module, thereby realizing fault injection into each kernel module of the electronic device.

[0039] like Figure 2 As shown, Figure 2 It is a schematic diagram of the fault injection scenario in the embodiment of the present disclosure. It includes user space and kernel space, and the kernel space includes multiple detection functions. Different detection functions (detection functions can be expressed as inject tags) correspond to detecting kernel functions in corresponding kernel modules to obtain the function content of kernel functions. Different kernel modules correspond to a business module (which can be called a candidate business module) in the user space. Each candidate business module has been configured with a candidate test case set in the user state. For example, the display case set represents a candidate test case set configured for a candidate business module that provides a display function, the multimedia case set represents a candidate test case set configured for a candidate business module that provides a multimedia function, the performance power consumption case set represents a candidate test case set configured for a candidate business module that provides a performance power consumption management function, the sensor case set represents a candidate test case set configured for a candidate business module that provides a sensing function, and the input and output (Input Output, IO) load case set, represents the candidate test case set configured for the candidate business module that provides input and output functions, process case set, represents the candidate test case set configured for the candidate business module that provides process management functions, memory case set, represents the candidate test case set configured for the candidate business module that provides memory management functions, file system case set, represents the candidate test case set configured for the candidate business module that provides file system. Each candidate test case set may contain test cases.

[0040] Figure 2Each test case set in the user space can respond to the upper-level white-box test. Each candidate business module is compiled into a binary form and a normalized instruction set is implemented using shell instructions for the upper-level application package (such as Android application package (APK)) to call to implement fault injection. Figure 2 For the description of the kernel space detection function in, please refer to the subsequent embodiments.

[0041] S103: Modify the function content of the kernel function into the target function content, so as to inject a test fault corresponding to the target test case into the kernel function.

[0042] After determining the target test case according to the kernel function and obtaining the target function content included in the target test case, the function content of the kernel function can be modified to the target function content to inject a test fault corresponding to the target test case into the kernel function.

[0043] In some embodiments, in the process of modifying the function content of the kernel function to the target function content, the initial parameter type of the kernel function can also be modified to the target parameter type, and the target structure parameter can be filled into the to-be-filled structure parameter of the kernel function, and the initial return value of the kernel function can be modified to the target return value, thereby effectively injecting faults into the kernel function.

[0044] In this embodiment, by obtaining the function content of the kernel function in user mode and determining the target test case based on the kernel function, wherein the target test case includes: the target function content, and modifying the function content of the kernel function into the target function content, so as to inject a test fault corresponding to the target test case into the kernel function, the application scenarios of fault injection can be effectively broadened, the flexibility of fault injection can be improved, and the fault injection effect can be improved.

[0045] In the disclosed embodiments, in the process of modifying the function content of the kernel function into the target function content, the function content of the kernel function can be modified into the target function content in the user state, or the function content of the kernel function can be modified into the target function content in the kernel state, thereby supporting fault injection in the user state or the kernel state, which can be effectively applied not only to the user state, but also to the kernel state, thereby greatly improving the applicability and practicality of fault injection.

[0046] Figure 3 It is a flowchart of a fault injection method proposed in another embodiment of the present disclosure.

[0047] like Figure 3 As shown, the fault injection method includes:

[0048] S301: Obtain the function content of the kernel function in user mode.

[0049] For example, an electronic device can be equipped with the Linux kernel. The proc file system in the Linux kernel is a virtual file system that provides an access interface to the kernel's internal data structure and system status. The file system presents various information in the system in the form of files and directories, such as process information, hardware device information, memory status, etc. The proc file system is dynamically generated and maintained by the kernel. When the system starts, the kernel creates the proc file system and automatically fills in the files and directories therein. Each file and directory represents a data structure or state related to the kernel, and the corresponding information can be accessed and modified by reading and writing these files. The proc file system in the Linux kernel can be used to create two nodes, node 1: / proc / mi_kporbe and node 2: proc / mi_kretprobe. These two nodes are combined with the Kprobe function (the Kprobe function is used to insert the detection function) to implement the function of modifying and reading kernel parameters and return values ​​in user mode.

[0050] See also above Figure 2 , the above Figure 2 Interface 1 includes: proc / mi_kprobe interface or proc / mi_kretprobe interface, wherein the proc / mi_kprobe interface or proc / mi_kretprobe interface may include an open interface, a write interface, a read interface, and an ioctl interface part, which are used to implement corresponding functions. For example, the open interface corresponds to the enable function, indicating the start of reading the function content, the write interface indicates the write function, the read interface indicates the read function, and the ioctl interface indicates the function of transferring the initial content function.

[0051] In the disclosed embodiment, the function content of the kernel function can be obtained in the user mode based on the proc / mi_kprobe interface or the proc / mi_kretprobe interface. The example description of the proc / mi_kprobe interface or the proc / mi_kretprobe interface can be used to implement kernel func return value modification, kernel func parameter modification, kernel func parameter reading, kernel func return value reading, fault clearing, all faults clearing, viewing the return value injection fault list, viewing the parameter injection fault list, etc., wherein kernel func represents a kernel function.

[0052] S302: Determine a target test case according to the kernel function, wherein the target test case includes: target function content.

[0053] For the description of S302, please refer to the above embodiment, which will not be repeated here.

[0054] S303: Transfer the target function content from the user state to the kernel state.

[0055] The disclosed embodiments not only support modifying the function content of a kernel function into the target function content in user mode, but also support modifying the function content of a kernel function into the target function content in kernel mode.

[0056] In some embodiments, the function content of the kernel function obtained in the user state can be passed to the kernel state to support the modification of the function content of the kernel function to the target function content in the kernel state. For example, the ioctl interface (also abbreviated as proc_ioctl interface) of the proc file system in the above-mentioned Linux kernel can be used to call the copy_from_user function and the copy_to_user function to realize the transfer of the function content (such as function parameter data and return value data) from the user state to the kernel state, wherein the copy_from_user function is a function in the Linux kernel, which is used to copy the data in the user space (User Space) to the kernel space (Kernel Space). The copy_to_user function is a function in the Linux kernel, which is used to copy the data in the kernel space (Kernel Space) to the user space (UserSpace), and there is no restriction on this.

[0057] S304: modifying the function content of the kernel function to the target function content in the kernel state.

[0058] After the target function content is transferred from the user state to the kernel state, the function content of the kernel function can be modified to the target function content in the kernel state.

[0059] In some embodiments, in the process of modifying the function content of a kernel function to the target function content in kernel state, the initial parameter type of the kernel function can also be modified to the target parameter type in kernel state, and the target structure parameter can be filled into the to-be-filled structure parameter of the kernel function in kernel state, and the initial return value of the kernel function can be modified to the target return value in kernel state, thereby effectively injecting faults into the kernel function.

[0060] In this embodiment, by obtaining the function content of the kernel function in the user state, and determining the target test case according to the kernel function, wherein the target test case includes: the target function content, and modifying the function content of the kernel function to the target function content, so as to inject the test fault corresponding to the target test case into the kernel function, the application scenario of fault injection can be effectively broadened, the flexibility of fault injection can be improved, and the effect of fault injection can be improved. It is also possible to modify the function content of the kernel function to the target function content in the kernel state, thereby supporting the implementation of fault injection in the kernel state, which can be effectively applied not only to the user state, but also to the kernel state, greatly improving the applicability and practicality of fault injection.

[0061] Figure 4 It is a flowchart of a fault injection method proposed in another embodiment of the present disclosure.

[0062] like Figure 4 As shown, the fault injection method includes:

[0063] S401: Determine a detection function corresponding to a kernel module to which a kernel function belongs, wherein the detection function is used to identify function content of the kernel function.

[0064] In some embodiments, the kernel space may include one or more kernel modules. Different kernel modules support different business functions. A detection function can be inserted into each kernel module in advance, and the function content of the kernel function in the kernel module can be obtained based on the detection function.

[0065] See also above Figure 2 The detection function may be, for example, a memory inject tag (which can be understood as a detection function related to memory), a device driver inject tag (a detection function related to a device driver), a sche inject tag (a detection function related to a process), and the like.

[0066] S402: Obtain function content according to the kernel function and the detection function.

[0067] In some embodiments, after determining the detection function corresponding to the kernel module to which the kernel function belongs, the function content can be obtained by executing the kernel function and the detection function.

[0068] In some embodiments, the detection function includes: a first detection function and / or a second detection function, wherein the first detection function is used to identify the initial parameter type and / or the structure parameter to be filled in the kernel function, and the second detection function is used to identify the initial return value of the kernel function. Then, the first detection function can be executed in user mode, and the kernel function can be executed to obtain the initial parameter type and / or the structure parameter to be filled in, and the second detection function can be executed in the process of executing the kernel function to obtain the initial return value, and the kernel function can be exited. Thereby, the initial parameter type and / or the structure parameter to be filled in, and the initial return value can be effectively obtained.

[0069] For example, the Kprobe function can be used to insert a probe before the function entry and function exit of the kernel function (an optional example of inserting a detection function). Before the execution of the detected kernel function, a fault injection function A (an optional example of the first detection function) is executed. Function A is used to identify the matching function parameter type and content. After the match is successful, it supports the modification of the function parameters. Before the detected function exits, a fault injection function B (an optional example of the second detection function) is executed. Function B is used to identify the matching function parameter content and type, and the function return value is modified after the match is successful. Thereby, the kernel function parameters and return values ​​can be modified. Among them, the first detection function can be executed before the kernel function is executed, and the second detection function can be executed before the kernel function is exited.

[0070] S403: Determine a target test case according to the kernel function, wherein the target test case includes: target function content.

[0071] S404: Modify the function content of the kernel function into the target function content, so as to inject a test fault corresponding to the target test case into the kernel function.

[0072] For the description of S403 - S404 , please refer to the above embodiment for details, which will not be repeated here.

[0073] In this embodiment, by obtaining the function content of the kernel function in user mode, and determining the target test case according to the kernel function, wherein the target test case includes: the target function content, and modifying the function content of the kernel function to the target function content, so as to inject the test fault corresponding to the target test case into the kernel function, the application scenario of fault injection can be effectively broadened, the flexibility of fault injection can be improved, and the effect of fault injection can be improved. By determining the detection function corresponding to the kernel module to which the kernel function belongs, wherein the detection function is used to identify the function content of the kernel function, and obtaining the function content according to the kernel function and the detection function, it is possible to effectively obtain the initial parameter type and / or the structure parameter to be filled, as well as the initial return value.

[0074] The fault injection method in the above embodiment can be illustrated as follows:

[0075] Taking the example of an electronic device equipped with a Linux kernel, you can use the cmd command to convert vmlinux into a vmlinux.h header file. This header file contains all the structures and type definitions of the Linux kernel. Use the user mode tool to include the header file to obtain the size of the kernel function structure and the offset of each parameter, and modify the parameter type of the kernel function according to the test case, and fill in the structure parameters. Inject the corresponding fault into the kernel function by reading and writing the interface provided by the kernel mi_kprobe module. After receiving the corresponding data, the kernel mi_kprobe module parses and determines the structure parameter data, registers the corresponding kprobe probe, forms a detection function, and injects the corresponding fault.

[0076] Among them, vmlinux is an executable file generated by the compilation of the Linux kernel. It is a binary executable file of the compiled and linked Linux kernel, which contains the complete kernel code and symbol information. "cmd command" usually refers to the command prompt (Command Prompt) command in the Windows operating system. Command Prompt is a command line interface provided by Windows, also known as the command line terminal or command line window. In Command Prompt, various commands can be used to perform various operations, such as file management, system configuration, network management, etc. vmlinux.h is a header file generated by the compilation of the Linux kernel, which contains the symbol table information of the kernel. This header file is usually used by developers, tools, and script writers to analyze the symbol table information of the Linux kernel. The mi_kprobe module is a kernel module that provides the function of inserting and processing Kprobe in the Linux kernel. Kprobe is a dynamic stub technology used to insert code at key locations such as the entry or exit of a kernel function in order to monitor, track, or modify the execution of a kernel function. Kprobe (Kernel Probe) probe is a technology for dynamic debugging and analysis in the Linux kernel. Allows developers to insert code at key locations such as the entry or exit of a kernel function to monitor, trace, and modify the execution of a kernel function.

[0077] like Figure 5 As shown, Figure 5 Schematic diagram of the fault injection process in the embodiment of the present disclosure. Figure 5, convert vmlinux into the vmlinux.h header file, use the user mode tool to include the header file to obtain the kernel structure parameter size and elements (an optional example of function content), and determine the need to fill the inject_para_t structure (an optional example of the structure parameters to be filled) according to the test case, call the open interface, write interface, and copy_from_user function in the proc / mi_kprobe interface to obtain the inject_para_t structure data, match the structure parameter data, and register the corresponding kprobe probe to determine and match the kernel function parameters. If the match is successful, modify the parameter type and / or fill the structure parameters and / or modify the return value to inject the fault. If the match is not successful, do not inject the fault. Figure 5 In the user state, the mi_fault bin program can use the two nodes / proc / mi_kporbe and / proc / mi_kretprobe provided by the kernel, and the interface to derive the fault injection case set of each functional module. For example, the case set of the display class can inject and modify the serial peripheral interface (SPI) bus data of the display screen, as well as the backlight data to achieve fault injection. Each module uses the functions provided by mi_kprobe and mi_kretprobe to form a test case set for each fault injection in the user state, and the upper APK is called in the form of shell or binary. A normalized shell instruction set can also be provided for testing or developer verification.

[0078] The fault injection types supported in the embodiments of the present disclosure may include: stability fault injection, file type fault, bus type fault, process type fault, memory type fault, system call fault, CPU load injection, disk IO load injection, disk fill injection, process kill injection (kill process), process stop injection (pause process injection), shell script function delayed execution injection, etc.

[0079] In the disclosed embodiment, the formal parameters and return values ​​of the kernel function are read and modified in the user mode, providing a basis for fault injection. A fault injection case set (an optional example of a test case set) is formed for each business module of the electronic device, providing support for subsequent testing.

[0080] Figure 6 It is a structural diagram of a fault injection device proposed in an embodiment of the present disclosure.

[0081] like Figure 6As shown, the fault injection device 60 includes:

[0082] The acquisition module 601 is used to acquire the function content of the kernel function in the user mode.

[0083] The determination module 602 is used to determine a target test case according to the kernel function, wherein the target test case includes: target function content.

[0084] The modification module 603 is used to modify the function content of the kernel function into the target function content, so as to inject a test fault corresponding to the target test case into the kernel function.

[0085] It should be noted that the above explanation of the fault injection method is also applicable to the fault injection device of this embodiment, and will not be repeated here.

[0086] In this embodiment, by obtaining the function content of the kernel function in user mode and determining the target test case based on the kernel function, wherein the target test case includes: the target function content, and modifying the function content of the kernel function into the target function content, so as to inject a test fault corresponding to the target test case into the kernel function, the application scenarios of fault injection can be effectively broadened, the flexibility of fault injection can be improved, and the fault injection effect can be improved.

[0087] Figure 7 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown. Figure 7 The electronic device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0088] like Figure 7 As shown, the electronic device 12 is in the form of a general purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a memory 28, and a bus 18 that connects various system components (including the memory 28 and the processing unit 16).

[0089] The bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor or a local bus using any of a variety of bus structures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnection (PCI) bus.

[0090] The electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0091] The memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache 32. The electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 7 Not shown, often called a "hard drive").

[0092] although Figure 7 Not shown in the figure, a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a compact disc read only memory (hereinafter referred to as: CD-ROM), a digital versatile disc read only memory (hereinafter referred to as: DVD-ROM) or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.

[0093] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in the memory 28, such program modules 42 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described in the present disclosure.

[0094] The electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), may also communicate with one or more devices that enable the human body to interact with the electronic device 12, and / or communicate with any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 22. In addition, the electronic device 12 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20. As shown, the network adapter 20 communicates with other modules of the electronic device 12 through a bus 18. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0095] The processing unit 16 executes various functional applications and data processing by running the programs stored in the memory 28, such as implementing the methods mentioned in the above embodiments.

[0096] In order to implement the above embodiments, the present disclosure further proposes a non-transitory computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method proposed in the above embodiments of the present disclosure is implemented.

[0097] In order to implement the above embodiments, the present disclosure further proposes a computer program product. When instructions in the computer program product are executed by a processor, the method proposed in the above embodiments of the present disclosure is executed.

[0098] It should be noted that, in the description of the present disclosure, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present disclosure, unless otherwise specified, the meaning of "plurality" is two or more.

[0099] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present disclosure includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present disclosure belong.

[0100] It should be understood that the various parts of the present disclosure can be implemented in hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0101] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0102] In addition, each functional unit in each embodiment of the present disclosure may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0103] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.

[0104] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0105] Although the embodiments of the present disclosure have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present disclosure. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present disclosure.

Claims

1. A fault injection method, characterized in that: The method comprises: Get the function content of the kernel function in user mode; According to the kernel function, a target test case is determined, wherein the target test case includes: target function content; The function content of the kernel function is modified to the target function content, so as to inject a test fault corresponding to the target test case into the kernel function.

2. The method according to claim 1, characterized in that The modifying the function content of the kernel function to the target function content includes any one of the following: Modifying the function content of the kernel function into the target function content in the user state; In kernel mode, the function content of the kernel function is modified to the target function content.

3. The method according to claim 2, characterized in that Before modifying the function content of the kernel function to the target function content in the kernel state, the method further includes: The target function content is transferred from the user state to the kernel state.

4. The method according to claim 1, characterized in that The function content includes at least one of an initial parameter type, a structure parameter to be filled, and an initial return value, and the target function content includes at least one of a target parameter type, a target structure parameter, and a target return value.

5. The method according to claim 4, characterized in that The step of modifying the function content of the kernel function to the target function content includes: Modify the initial parameter type of the kernel function to the target parameter type; Fill the target structure parameter into the to-be-filled structure parameter of the kernel function; The initial return value of the kernel function is modified to the target return value.

6. The method according to claim 1, characterized in that Determining a target test case according to the kernel function includes: Determine the kernel module to which the kernel function belongs; Determining a set of candidate test cases corresponding to the kernel module, wherein the set of candidate test cases includes candidate test cases; The candidate test case is used as the target test case.

7. The method according to claim 6, characterized in that The determining of a set of candidate test cases corresponding to the kernel module comprises: Determining a function type corresponding to the kernel module; Determine a candidate service module corresponding to the function type, wherein a candidate test case set has been configured in the candidate service module in user mode; The candidate test case set configured corresponding to the corresponding candidate business module is used as the candidate test case set corresponding to the kernel module.

8. The method according to claim 1, characterized in that The step of obtaining the function content of the kernel function in the user mode includes: Determine a detection function corresponding to the kernel module to which the kernel function belongs, wherein the detection function is used to identify the function content of the kernel function; The function content is obtained according to the kernel function and the detection function.

9. The method according to claim 8, characterized in that The detection function includes: a first detection function and / or a second detection function, wherein the first detection function is used to identify the initial parameter type and / or the structure parameter to be filled in the kernel function, and the second detection function is used to identify the initial return value of the kernel function; Wherein, obtaining the function content according to the kernel function and the detection function includes: Execute the first detection function in user mode, and execute the kernel function to obtain the initial parameter type and / or the structure parameter to be filled; Execute the second detection function during the execution of the kernel function to obtain the initial return value; Exit execution of the kernel function.

10. A fault injection device, characterized in that: The device comprises: The acquisition module is used to obtain the function content of the kernel function in user mode; A determination module, used to determine a target test case according to the kernel function, wherein the target test case includes: target function content; A modification module is used to modify the function content of the kernel function to the target function content, so as to inject a test fault corresponding to the target test case into the kernel function.

11. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 9.

12. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: in, The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 9.

13. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 9.