Movatterモバイル変換


[0]ホーム

URL:


CN117009252B - Fault injection testing method and device based on function replacement - Google Patents

Fault injection testing method and device based on function replacement
Download PDF

Info

Publication number
CN117009252B
CN117009252BCN202311285981.4ACN202311285981ACN117009252BCN 117009252 BCN117009252 BCN 117009252BCN 202311285981 ACN202311285981 ACN 202311285981ACN 117009252 BCN117009252 BCN 117009252B
Authority
CN
China
Prior art keywords
function
replaced
code
fault
modified
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311285981.4A
Other languages
Chinese (zh)
Other versions
CN117009252A (en
Inventor
刘念
罗实
王永恒
葛晓东
周宇
陈昱宇
张宝龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Lab
Original Assignee
Zhejiang Lab
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang LabfiledCriticalZhejiang Lab
Priority to CN202311285981.4ApriorityCriticalpatent/CN117009252B/en
Publication of CN117009252ApublicationCriticalpatent/CN117009252A/en
Application grantedgrantedCritical
Publication of CN117009252BpublicationCriticalpatent/CN117009252B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

Abstract

The description discloses a fault injection test method and device based on function replacement, which can acquire a code to be tested, determine a function call chain based on the code to be tested, determine a function to be replaced according to the function call chain, modify the function code of the function to be replaced to add the fault code to be injected into the function to be replaced to obtain a modified function, generate a dynamic link library corresponding to the modified function, further inject the dynamic link library into a process where the function to be replaced is located, replace the function to be replaced in the process with the modified function, finally trigger the modified function to complete fault triggering according to a preset triggering rule, complete fault injection test according to system related information obtained after the fault triggering, and achieve flexible and safe fault injection.

Description

Translated fromChinese
一种基于函数替换的故障注入测试方法及装置A fault injection testing method and device based on function replacement

技术领域Technical field

本说明书涉及软件测试技术领域,尤其涉及一种基于函数替换的故障注入测试方法及装置。This specification relates to the technical field of software testing, and in particular to a fault injection testing method and device based on function replacement.

背景技术Background technique

目前软件系统的故障注入测试手段主要有以下几种:At present, the fault injection testing methods of software systems mainly include the following:

1、在目标服务器部署故障注入系统,该系统独立于业务系统,通过调用操作系统命令来注入系统级异常,包括CPU高/内存泄漏/网络延迟/磁盘写满等。这种故障注入方法存在灵活性不足的问题:系统级故障太宽泛,不能模拟真实的应用系统异常,比如特定进程/组件内存泄漏、资源未释放(连结数过多、文件句柄占用)等。1. Deploy a fault injection system on the target server. This system is independent of the business system and injects system-level exceptions by calling operating system commands, including high CPU/memory leaks/network delays/disk full, etc. This fault injection method has the problem of insufficient flexibility: system-level faults are too broad and cannot simulate real application system abnormalities, such as memory leaks in specific processes/components, unreleased resources (too many connections, occupied file handles), etc.

2、应用系统部署在服务器之前在业务源代码中添加故障用例库,并在业务运行时通过命令/消息来触发故障生效。这种故障注入方法存在的不足为:需要侵入业务系统,改造业务系统代码,埋下了很多未触发的异常,不够安全可靠。另外,该方法不够灵活,如果要修改故障用例库,需要重新部署业务系统。2. Before the application system is deployed on the server, add a fault use case library in the business source code, and trigger the fault to take effect through commands/messages when the business is running. The shortcomings of this fault injection method are: it needs to invade the business system and modify the business system code, which leaves many untriggered exceptions and is not safe and reliable enough. In addition, this method is not flexible enough. If you want to modify the faulty use case library, you need to redeploy the business system.

因此,如何提高故障注入的灵活性以及安全性,则是亟待解决的问题。Therefore, how to improve the flexibility and security of fault injection is an issue that needs to be solved urgently.

发明内容Contents of the invention

本说明书提供一种基于函数替换的故障注入测试方法及装置,以部分的解决现有技术存在的上述问题。This specification provides a fault injection testing method and device based on function replacement to partially solve the above problems existing in the existing technology.

本说明书采用下述技术方案:This manual adopts the following technical solutions:

本说明书提供了一种导基于函数替换的故障注入测试方法,包括:This manual provides a fault injection testing method based on function replacement, including:

获取待测试代码,并基于所述待测试代码,确定函数调用链;Obtain the code to be tested and determine the function call chain based on the code to be tested;

根据所述函数调用链,确定待替换函数;Determine the function to be replaced according to the function call chain;

对所述待替换函数的函数代码进行修改,以将需要注入的故障代码添加到所述待替换函数中,得到修改后函数,并生成所述修改后函数对应的动态链接库;Modify the function code of the function to be replaced to add the fault code that needs to be injected to the function to be replaced, obtain a modified function, and generate a dynamic link library corresponding to the modified function;

将所述动态链接库注入到所述待替换函数所在的进程,以将所述进程中的待替换函数替换为所述修改后函数;Inject the dynamic link library into the process where the function to be replaced is located, so as to replace the function to be replaced in the process with the modified function;

响应于预设的触发规则,触发所述修改后函数以完成故障触发,根据故障触发后得到的系统相关信息,完成故障注入测试,所述系统相关信息至少包括系统日志以及响应信息。In response to the preset triggering rules, the modified function is triggered to complete the fault triggering, and the fault injection test is completed based on the system-related information obtained after the fault is triggered. The system-related information at least includes system logs and response information.

可选地,基于所述待测试代码,确定函数调用链,具体包括:Optionally, based on the code to be tested, determine the function call chain, specifically including:

通过Callgraph工具生成所述待测试代码的静态函数调用链,作为得到的函数调用链。Use the Callgraph tool to generate a static function call chain of the code to be tested as the resulting function call chain.

可选地,根据所述函数调用链,确定待替换函数,具体包括:Optionally, determine the function to be replaced according to the function call chain, specifically including:

确定所述函数调用链中的各函数;Determine each function in the function call chain;

从所述各函数确定出满足预设条件的函数,作为候选函数,其中,所述预设条件包括:函数属于用户态函数、函数不属于多线程函数以及函数不属于静态函数和静态函数中包含的函数中的至少一种;Determine a function that satisfies preset conditions from each of the functions as a candidate function, where the preset conditions include: the function belongs to a user-mode function, the function does not belong to a multi-threaded function, and the function does not belong to a static function and is included in a static function. At least one of the functions;

从所述候选函数中,确定出待替换函数。From the candidate functions, a function to be replaced is determined.

可选地,将所述动态链接库注入到所述待替换函数所在的进程,具体包括:Optionally, inject the dynamic link library into the process where the function to be replaced is located, specifically including:

确定所述待替换函数所在的进程,作为目标进程;Determine the process in which the function to be replaced is located, as the target process;

加载所述动态链接库对应的进程,并为所述动态链接库对应的进程分配内存空间;Load the process corresponding to the dynamic link library, and allocate memory space for the process corresponding to the dynamic link library;

获取所述目标进程中待替换函数对应的地址,以及所述动态链接库对应的进程中所述修改后函数对应的地址;Obtain the address corresponding to the function to be replaced in the target process, and the address corresponding to the modified function in the process corresponding to the dynamic link library;

将寄存器中所述待替换函数对应的地址替换为所述动态链接库对应的进程中所述修改后函数对应的地址;Replace the address corresponding to the function to be replaced in the register with the address corresponding to the modified function in the process corresponding to the dynamic link library;

保存所述寄存器的数据和状态,以完成注入。Save the data and status of said register to complete the injection.

可选地,所述触发规则包括:在所述待测试代码对应的业务系统中进行按钮点击、在命令行中输入预设指令以及在所述业务系统中进行消息发送中的至少一种。Optionally, the triggering rule includes at least one of: clicking a button in the business system corresponding to the code to be tested, entering a preset instruction in the command line, and sending a message in the business system.

可选地,根据故障触发后得到的系统相关信息,完成故障注入测试,具体包括:Optionally, complete the fault injection test based on the system-related information obtained after the fault is triggered, including:

获取系统日志中的错误日志,包括内存泄漏日志、磁盘满日志;Obtain error logs in the system log, including memory leak logs and disk full logs;

获取所述待测试代码对应的业务系统对故障检测的告警信息;Obtain the alarm information of fault detection by the business system corresponding to the code to be tested;

获取所述业务系统在不同故障触发后的响应信息,所述响应信息对应的响应包括服务超时、卡顿现象,以及系统重启;Obtain the response information of the business system after different faults are triggered. The responses corresponding to the response information include service timeout, stuck phenomenon, and system restart;

通过诊断工具进行现象分析,得到分析结果;Conduct phenomenon analysis through diagnostic tools and obtain analysis results;

根据所述错误日志、所述告警信息、所述响应信息以及所述分析结果,完成故障注入测试。Complete the fault injection test according to the error log, the alarm information, the response information and the analysis results.

可选地,所述方法还包括:Optionally, the method also includes:

将寄存器中所述待替换函数对应的地址还原,并将所述动态链接库删除,以恢复所述待测试代码对应的业务系统。Restore the address corresponding to the function to be replaced in the register, and delete the dynamic link library to restore the business system corresponding to the code to be tested.

本说明书提供了一种基于函数替换的故障注入测试装置,包括:This manual provides a fault injection test device based on function replacement, including:

获取模块,用于获取待测试代码,并基于所述待测试代码,确定函数调用链;The acquisition module is used to obtain the code to be tested and determine the function call chain based on the code to be tested;

确定模块,用于根据所述函数调用链,确定待替换函数;A determination module, used to determine the function to be replaced according to the function call chain;

修改模块,用于对所述待替换函数的函数代码进行修改,以将需要注入的故障代码添加到所述待替换函数中,得到修改后函数,并生成所述修改后函数对应的动态链接库;Modification module, used to modify the function code of the function to be replaced, to add the fault code that needs to be injected to the function to be replaced, obtain the modified function, and generate a dynamic link library corresponding to the modified function ;

注入模块,用于将所述动态链接库注入到所述待替换函数所在的进程,以将所述进程中的待替换函数替换为所述修改后函数;An injection module, configured to inject the dynamic link library into the process where the function to be replaced is located, so as to replace the function to be replaced in the process with the modified function;

触发模块,用于响应于预设的触发规则,触发所述修改后函数以完成故障触发,根据故障触发后得到的系统相关信息,完成故障注入测试,所述系统相关信息至少包括系统日志以及响应信息。A trigger module, configured to trigger the modified function in response to a preset trigger rule to complete fault triggering, and complete fault injection testing based on system-related information obtained after the fault is triggered. The system-related information at least includes system logs and responses. information.

本说明书提供了一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述基于函数替换的故障注入测试方法。This specification provides a computer-readable storage medium. The storage medium stores a computer program. When the computer program is executed by a processor, the above-mentioned fault injection test method based on function replacement is implemented.

本说明书提供了一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述基于函数替换的故障注入测试方法。This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the above-mentioned fault injection testing method based on function replacement.

本说明书采用的上述至少一个技术方案能够达到以下有益效果:At least one of the above technical solutions adopted in this manual can achieve the following beneficial effects:

从上述基于函数替换的故障注入测试方法中可以看出,该方法可以获取待测试代码,并基于所述待测试代码,确定函数调用链,根据该函数调用链,确定待替换函数,而后,对该待替换函数的函数代码进行修改,以将需要注入的故障代码添加到该待替换函数中,得到修改后函数,并生成修改后函数对应的动态链接库,进而,将动态链接库注入到待替换函数所在的进程,以将进程中的待替换函数替换为修改后函数,最后,响应于预设的触发规则,触发修改后函数以完成故障触发,根据故障触发后得到的系统相关信息,完成故障注入测试,系统相关信息至少包括系统日志以及响应信息。It can be seen from the above fault injection test method based on function replacement that this method can obtain the code to be tested, and determine the function call chain based on the code to be tested. According to the function call chain, determine the function to be replaced, and then, The function code of the function to be replaced is modified to add the fault code that needs to be injected to the function to be replaced, the modified function is obtained, and the dynamic link library corresponding to the modified function is generated, and then the dynamic link library is injected into the function to be replaced. Replace the process where the function is located to replace the function to be replaced in the process with the modified function. Finally, in response to the preset triggering rules, trigger the modified function to complete the fault triggering. According to the system-related information obtained after the fault triggering, complete For fault injection testing, system-related information at least includes system logs and response information.

从上述内容中可以看出,本方法可以确定出需要注入故障代码的函数、并添加故障代码,进而通过生成动态链接库并注入相应进程的方式,直接进行故障注入,相比于现有技术1,能够灵活地按照所需要的故障进行故障注入,相比于现有技术2,不需要直接对业务系统的业务代码进行改造,从而达到了灵活、安全的进行故障注入。As can be seen from the above content, this method can determine the function that needs to inject fault code, add the fault code, and then directly perform fault injection by generating a dynamic link library and injecting the corresponding process. Compared with the existing technology 1 , can flexibly inject faults according to required faults. Compared with the existing technology 2, there is no need to directly modify the business code of the business system, thereby achieving flexible and safe fault injection.

附图说明Description of drawings

此处所说明的附图用来提供对本说明书的进一步理解,构成本说明书的一部分,本说明书的示意性实施例及其说明用于解释本说明书,并不构成对本说明书的不当限定。在附图中:The drawings described here are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation of this specification. In the attached picture:

图1为本说明书提供的一种基于函数替换的故障注入测试方法的流程示意图;Figure 1 is a schematic flow chart of a fault injection testing method based on function replacement provided in this manual;

图2为本说明书提供的一种挑选待替换函数的流程示意图;Figure 2 is a schematic flow chart of selecting functions to be replaced provided in this specification;

图3为本说明书提供的一种函数调用链的示意图;Figure 3 is a schematic diagram of a function call chain provided in this manual;

图4为本说明书提供的一种注入动态链接库的流程示意图;Figure 4 is a schematic flow chart of injecting a dynamic link library provided in this manual;

图5为本说明书提供的一种基于函数替换的故障注入测试装置示意图;Figure 5 is a schematic diagram of a fault injection test device based on function replacement provided in this specification;

图6为本说明书提供的对应于图1的电子设备示意图。FIG. 6 is a schematic diagram of the electronic device corresponding to FIG. 1 provided in this specification.

具体实施方式Detailed ways

为使本说明书的目的、技术方案和优点更加清楚,下面将结合本说明书具体实施例及相应的附图对本说明书技术方案进行清楚、完整地描述。显然,所描述的实施例仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本说明书保护的范围。In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only some of the embodiments of this specification, but not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of this specification.

以下结合附图,详细说明本说明书各实施例提供的技术方案。The technical solutions provided by each embodiment of this specification will be described in detail below with reference to the accompanying drawings.

图1为本说明书中提供的一种基于函数替换的故障注入测试方法的流程示意图,具体包括以下步骤:Figure 1 is a schematic flow chart of a fault injection testing method based on function replacement provided in this manual, which specifically includes the following steps:

S100:获取待测试代码,并基于所述待测试代码,确定函数调用链。S100: Obtain the code to be tested, and determine the function calling chain based on the code to be tested.

S102:根据所述函数调用链,确定待替换函数。S102: Determine the function to be replaced according to the function call chain.

本说明书中的基于函数替换的故障注入测试方法可以应用在故障注入测试的场景中。The fault injection testing method based on function replacement in this manual can be applied in fault injection testing scenarios.

首先,服务器可以获取待测试代码,并基于该待测试代码,确定函数调用链。First, the server can obtain the code to be tested and determine the function call chain based on the code to be tested.

应用程序的每个业务和功能都是由很多函数调用链组成的,函数替换时如果能将调用链中的某个函数保留原代码,并插入故障代码(能够模拟运行时出现故障的代码),那程序实际运行时没有破坏原函数的功能,又能快速地模拟出业务异常现象,并以此来检验应用程序的故障处理能力。Each business and function of the application is composed of many function call chains. When replacing the function, if a certain function in the call chain can retain the original code and insert a fault code (a code that can simulate a fault during runtime), The program does not destroy the function of the original function when it is actually run, and can quickly simulate business anomalies, and use this to test the application's fault handling capabilities.

图2为本说明书提供的一种挑选待替换函数的流程示意图。Figure 2 is a schematic flowchart of selecting functions to be replaced provided in this specification.

因此,可以如图2所示,确定出函数调用链,并挑选需要替换的函数,包括以下步骤:Therefore, as shown in Figure 2, you can determine the function call chain and select the functions that need to be replaced, including the following steps:

S201:生成某个模块的函数调用链。S201: Generate a function call chain of a certain module.

S202:函数筛选。S202: Function filtering.

S203:业务影响分析。S203: Business impact analysis.

其中,待测试代码可以是开发出的一套业务系统对应的代码,此时,可以先通过静态分析的方式,确定出待测试代码的函数调用链(可以是某个需要进行故障注入测试的模块的函数调用链),具体的,可以通过Callgraph工具生成该待测试代码的静态函数调用链,作为得到的函数调用链。Among them, the code to be tested can be the code corresponding to a set of business systems developed. At this time, the function call chain of the code to be tested can be determined through static analysis (it can be a module that needs fault injection testing). function call chain). Specifically, the Callgraph tool can be used to generate a static function call chain of the code to be tested as the obtained function call chain.

该工具可以指定某个文件或者函数列表,并指定函数调用深度来筛选结果。一个函数调用另一个函数,很多个函数组合在一起就形成了函数调用链的展示,例如函数funcA调用函数funcB,展示就是funcA->funcB,函数funcB调用函数funcC,展示就是funcB->funcC,那么函数调用链就是funcA->funcB->funcC。This tool can specify a file or function list, and specify the function call depth to filter the results. One function calls another function, and many functions are combined to form a display of the function call chain. For example, function funcA calls function funcB, and the display is funcA->funcB. Function funcB calls function funcC, and the display is funcB->funcC. Then The function call chain is funcA->funcB->funcC.

Callgraph工具对某个目录生成的静态函数调用链可以如图2所示。The static function call chain generated by the Callgraph tool for a certain directory can be shown in Figure 2.

图3为本说明书提供的一种函数调用链的示意图。Figure 3 is a schematic diagram of a function call chain provided in this specification.

根据图3展示的函数调用图可以分析出不同的函数调用链,比如这两个调用链:1、A->B->C->D->E,2、A->B->G->D->E。According to the function call graph shown in Figure 3, different function call chains can be analyzed, such as these two call chains: 1. A->B->C->D->E, 2. A->B->G- >D->E.

而后,可以根据确定出的函数调用链,确定出待替换函数。其中,可以确定函数调用链中的各函数,并从各函数确定出满足预设条件的函数,作为候选函数,其中,预设条件包括:函数属于用户态函数、函数不属于多线程函数以及函数不属于静态函数和静态函数中包含的函数中的至少一种,而后,可以从候选函数中,确定出待替换函数。Then, the function to be replaced can be determined based on the determined function call chain. Among them, each function in the function call chain can be determined, and a function that meets the preset conditions can be determined from each function as a candidate function, where the preset conditions include: the function belongs to the user mode function, the function does not belong to the multi-threaded function, and the function At least one of the functions that do not belong to the static function and the static function, and then the function to be replaced can be determined from the candidate functions.

也就是说,函数筛选主要考虑这三个方面:In other words, function filtering mainly considers these three aspects:

一、用户态与内核态函数。1. User-mode and kernel-mode functions.

每个函数调用链的函数包括这两类:应用程序函数(用户态函数)和系统函数(库函数),应用程序函数的调用在用户态,系统函数(库函数)的调用往往在内核态,应用程序函数和系统函数是两个不同形态,这两个都可以用函数替换的方式来进行故障注入,但方法有较大差异,本发明主要考虑用户态函数对业务程序的影响,因此对系统函数比如D、E、H、L、M不考虑函数替换。The functions of each function call chain include two categories: application functions (user mode functions) and system functions (library functions). Application functions are called in user mode, while system functions (library functions) are often called in kernel mode. Application functions and system functions are two different forms. Both of them can use function replacement to perform fault injection, but the methods are quite different. This invention mainly considers the impact of user-mode functions on business programs, so it affects the system Functions such as D, E, H, L, and M are not considered for function substitution.

二、多线程影响。2. The impact of multi-threading.

函数执行需要数据和代码,数据包括函数形参、局部变量、全局变量、静态局部变量等。有的数据是保存在线程的栈空间,比如形参、局部变量,在多线程条件下每个线程的栈空间是独立的,函数调用不受影响。而有的数据是保存在进程堆内存,比如全局变量,在多线程条件下会共同访问该全局变量的堆内存首地址,会有安全问题,虽然引入互斥锁时会解决该问题,但是如果替换多线程下的函数,容易导致加锁后替换后的函数执行发生异常引起锁等待、死锁。Function execution requires data and code. Data includes function parameters, local variables, global variables, static local variables, etc. Some data is stored in the thread's stack space, such as formal parameters and local variables. Under multi-thread conditions, the stack space of each thread is independent, and function calls are not affected. Some data is stored in the process heap memory, such as global variables. Under multi-thread conditions, the first address of the heap memory of the global variable will be jointly accessed, which will cause security problems. Although this problem will be solved when a mutex lock is introduced, but if Replacing functions under multi-threading can easily lead to exceptions in the execution of the replaced function after locking, causing lock waits and deadlocks.

函数的代码保存在公共空间,对所有线程是共享的,当替换多线程下的函数时,一部分线程执行旧函数,一部分线程执行新函数,在不是原子操作的前提下,会引起局部变量的不一致引发不可预知的逻辑问题。The code of the function is stored in the public space and is shared by all threads. When replacing a function under multi-threading, some threads will execute the old function and some threads will execute the new function. If the operation is not atomic, it will cause inconsistency in local variables. Causing unpredictable logical problems.

综上,从数据和代码两方面来考虑都不能选择多线程执行下的函数进行替换,多线程的函数标志是通过pthread_create系统函数创建,创建时参数指定了调用的函数名,该函数就是多线程函数。To sum up, considering both the data and code aspects, you cannot choose a function under multi-thread execution for replacement. The multi-thread function flag is created through the pthread_create system function. When creating, the parameters specify the name of the called function. This function is multi-threaded. function.

三、静态函数及静态函数内部的函数。3. Static functions and functions inside static functions.

静态函数的作用域仅局限于声明它的文件中,它的内部函数地址是不可见的,不能被其他文件引用,因此函数替换不能考虑静态函数及其内部的函数。The scope of a static function is limited to the file in which it is declared. Its internal function address is invisible and cannot be referenced by other files. Therefore, function replacement cannot consider static functions and their internal functions.

S104:对所述待替换函数的函数代码进行修改,以将需要注入的故障代码添加到所述待替换函数中,得到修改后函数,并生成所述修改后函数对应的动态链接库。S104: Modify the function code of the function to be replaced to add the fault code that needs to be injected to the function to be replaced, obtain a modified function, and generate a dynamic link library corresponding to the modified function.

确定出待替换函数后,可以对待替换函数的函数代码进行修改,以将需要注入的故障代码添加到待替换函数中,得到修改后函数,并生成该修改后函数对应的动态链接库。After determining the function to be replaced, the function code of the function to be replaced can be modified to add the fault code that needs to be injected into the function to be replaced, obtain the modified function, and generate a dynamic link library corresponding to the modified function.

其中,确定出待替换函数后,开发人员可以人为将待替换函数的函数代码进行修改(当然,也可以通过接收需要注入的故障代码来自动得到修改后函数),并将修改后函数保存在本地,而后,服务器可以生成修改后函数对应的动态链接库。Among them, after determining the function to be replaced, the developer can manually modify the function code of the function to be replaced (of course, the modified function can also be automatically obtained by receiving the fault code that needs to be injected), and save the modified function locally. , and then the server can generate the dynamic link library corresponding to the modified function.

这里提到的将待替换函数的函数代码进行修改,得到修改后函数,并不是指直接将原有的待替换函数修改,而是指得到待替换函数的函数代码,并在待替换函数的函数代码中添加故障代码,得到修改后函数,也就是说修改后函数是除待替换函数的另一函数,而原有的待替换函数依然存在,这样也方便后续将修改后函数对应的动态链接库删除,以将待测试代码对应的业务系统还原。The modification of the function code of the function to be replaced and obtaining the modified function mentioned here does not mean directly modifying the original function to be replaced, but refers to obtaining the function code of the function to be replaced and using it in the function of the function to be replaced. Add the fault code to the code to get the modified function. That is to say, the modified function is another function besides the function to be replaced, and the original function to be replaced still exists. This also facilitates the subsequent use of the dynamic link library corresponding to the modified function. Delete to restore the business system corresponding to the code to be tested.

(1)编写用于替换待替换函数的修改后函数(1) Write a modified function that replaces the function to be replaced

假定待替换函数名为original_func,修改后函数为replaced_func。Assume that the function to be replaced is named original_func, and the modified function is replaced_func.

original_func代码示例如下:The original_func code example is as follows:

int original_func(int a, const char *b){int original_func(int a, const char *b){

//代码省略//Code omitted

......

return 0;return 0;

}}

假定注入的故障为模拟业务内存泄漏,那修改后函数代码示例如下:Assuming that the injected fault is a simulated business memory leak, the modified function code example is as follows:

int replaced_func(int a, const char *b){int replaced_func(int a, const char *b){

//原代码保持不变//Original code remains unchanged

......

//下面添加内存泄漏的代码//Add memory leak code below

char *temp = (char *)malloc(300* sizeof(char));char *temp = (char *)malloc(300* sizeof(char));

temp = b;temp = b;

return 0;return 0;

}}

修改后函数replaced_func中申请了一块300字节的内存,并将内存地址传给指针temp,然后将指针temp又指向了b,直到函数结束。这导致300字节内存地址没有指针指向它,无法找回,不能释放内存地址,造成了内存泄漏。每调用一次该函数,就会造成300字节的内存泄漏,根据实际测试需要,可以更改这个数值。After the modification, the function replaced_func applies for a 300-byte memory, passes the memory address to the pointer temp, and then points the pointer temp to b until the function ends. This results in the 300-byte memory address having no pointer pointing to it, making it impossible to retrieve it, and the memory address cannot be released, causing a memory leak. Each time this function is called, a memory leak of 300 bytes will occur. This value can be changed according to actual testing needs.

(2)制作动态链接库(2) Make a dynamic link library

动态链接库是一个*.so文件,它包含了修改后函数(包含触发故障代码),可以通过gcc(linux c语言编译器)编译生成动态链接库libload.so文件。The dynamic link library is a *.so file, which contains the modified function (including the trigger fault code), and can be compiled by gcc (linux c language compiler) to generate the dynamic link library libload.so file.

假定函数original_func的文件名为func_rep.c,编译命令如下,即可生成libload.so动态链接库:Assume that the file name of function original_func is func_rep.c and the compilation command is as follows to generate the libload.so dynamic link library:

“gcc func_rep.c -shared -fPIC -o libload.so”"gcc func_rep.c -shared -fPIC -o libload.so"

S106:将所述动态链接库注入到所述待替换函数所在的进程,以将所述进程中的待替换函数替换为所述修改后函数。S106: Inject the dynamic link library into the process where the function to be replaced is located, so as to replace the function to be replaced in the process with the modified function.

而后,可以将得到的修改后函数对应的动态链接库注入到待替换函数所在的进程,以将该进程中的待替换函数替换为修改后函数。Then, the dynamic link library corresponding to the obtained modified function can be injected into the process where the function to be replaced is located, so that the function to be replaced in the process is replaced with the modified function.

其中,可以确定出待替换函数所在的进程,作为目标进程,而后,可以加载动态链接库(包含有修改后函数)对应的进程,并为该动态链接库对应的进程分配内存空间,而后,获取目标进程中待替换函数对应的地址,以及动态链接库对应的进程中修改后函数对应的地址,最后,可以将寄存器中待替换函数对应的地址(即,超始地址)替换为动态链接库对应的进程中修改后函数对应的地址,并保存寄存器的数据和状态,以完成注入。Among them, the process in which the function to be replaced can be determined as the target process, and then the process corresponding to the dynamic link library (including the modified function) can be loaded, and the memory space corresponding to the dynamic link library can be allocated, and then, the process corresponding to the dynamic link library can be obtained. The address corresponding to the function to be replaced in the target process, and the address corresponding to the modified function in the process corresponding to the dynamic link library. Finally, the address corresponding to the function to be replaced in the register (i.e., the super-start address) can be replaced with the address corresponding to the dynamic link library The address corresponding to the modified function in the process, and save the data and status of the register to complete the injection.

图4为本说明书提供的一种注入动态链接库的流程示意图。Figure 4 is a schematic flowchart of injecting a dynamic link library provided in this specification.

注入动态链接库的流程可以如图4所示,步骤详细过程如下:The process of injecting the dynamic link library can be shown in Figure 4. The detailed steps are as follows:

S401:确认目标函数original_func所在的进程,通过gdb(调试工具)命令:infooriginal_func查看进程中该函数是否存在,记录进程号pid。S401: Confirm the process where the target function original_func is located. Use the gdb (debugging tool) command: infooriginal_func to check whether the function exists in the process and record the process number pid.

S402:通过系统接口ptrace来加载libload.so(即动态链接库文件)进程,并调用系统接口mmap进行分配内存空间,这样libload.so中的函数可以通过地址来访问。S402: Load the libload.so (dynamic link library file) process through the system interface ptrace, and call the system interface mmap to allocate memory space, so that the functions in libload.so can be accessed through addresses.

S403:通过系统接口dlsym来获取这两个函数的地址:original_func和replaced_func。S403: Obtain the addresses of these two functions through the system interface dlsym: original_func and replaced_func.

S404:在寄存器中将original_func函数超始地址替换为replaced_func函数地址,修改机器指令为jmp。S404: Replace the starting address of the original_func function with the replaced_func function address in the register, and modify the machine instruction to jmp.

S405:寄存器数据和状态保存,结束注入过程。S405: Register data and status are saved, ending the injection process.

在此附上各系统接口的作用,如表1所示。Attached here are the functions of each system interface, as shown in Table 1.

表1Table 1

S108:响应于预设的触发规则触发所述修改后函数以完成故障触发,根据故障触发后得到的系统相关信息,完成故障注入测试,所述系统相关信息至少包括系统日志以及响应信息。S108: Trigger the modified function in response to the preset triggering rule to complete the fault triggering, and complete the fault injection test based on the system-related information obtained after the fault triggering. The system-related information at least includes system logs and response information.

完成注入后,服务器可以响应于预设的触发规则,触发上述修改后函数以完成故障触发,根据故障触发后得到的系统相关信息,可以完成故障注入测试,这里提到的系统相关信息至少包括系统日志以及响应信息。After the injection is completed, the server can respond to the preset triggering rules and trigger the above modified function to complete the fault triggering. Based on the system-related information obtained after the fault is triggered, the fault injection test can be completed. The system-related information mentioned here at least includes the system Logs and response information.

需要说明的是,上述触发规则可以包括:在该待测试代码对应的业务系统中进行按钮点击、在命令行中输入预设指令以及在业务系统中进行消息发送等,这里提到的待测试代码对应的业务系统可以部署在上述服务器中,在修改后函数对应的触发规则在服务器中产生后,服务器触发修改后函数,即可以触发修改后函数内部的故障代码。It should be noted that the above triggering rules may include: clicking buttons in the business system corresponding to the code to be tested, entering preset instructions in the command line, and sending messages in the business system, etc. The code to be tested mentioned here The corresponding business system can be deployed in the above-mentioned server. After the triggering rule corresponding to the modified function is generated in the server, the server triggers the modified function, that is, the fault code inside the modified function can be triggered.

其中,根据函数调用链,可以找到能够触发修改后函数的函数调用的触发规则,比如按钮点击、命令行、消息等。Among them, according to the function call chain, you can find the triggering rules that can trigger the function call of the modified function, such as button clicks, command lines, messages, etc.

需要说明的是,若是不通过本说明书提供的方式进行函数替换,那么在代码执行时,执行到original_func函数是按照原有的函数代码进行执行,而通过本方法进行了动态链接库的注入后,在执行到original_func函数时,将跳转到replaced_func函数进行执行。It should be noted that if the function replacement is not performed through the method provided in this manual, then when the code is executed, the original_func function is executed according to the original function code, and after the dynamic link library is injected through this method, When the original_func function is executed, it will jump to the replaced_func function for execution.

即,函数替换后,当调用original_func函数时,该函数首地址操作符已替换,直接跳转到replaced_func函数执行,这时将触发replaced_func中的故障代码,这时可以快速地对系统注入异常。在一些需要重复注入异常的场景比如内存泄漏、资源占用等,可以触发多次相应的触发规则,如多次点击按钮来触发异常。That is, after the function is replaced, when the original_func function is called, the first address operator of the function has been replaced and jumps directly to the replaced_func function for execution. At this time, the fault code in the replaced_func will be triggered, and an exception can be quickly injected into the system. In some scenarios that require repeated injection of exceptions, such as memory leaks, resource occupation, etc., the corresponding trigger rules can be triggered multiple times, such as clicking a button multiple times to trigger an exception.

故障触发后,可以根据故障触发后得到的系统相关信息,完成故障注入测试,其中,系统相关信息至少包括系统日志以及响应信息。After the fault is triggered, the fault injection test can be completed based on the system-related information obtained after the fault is triggered. The system-related information at least includes system logs and response information.

具体的,可以获取系统日志中的错误日志,包括内存泄漏日志、磁盘满日志等,获取待测试代码对应的业务系统对故障检测的告警信息,获取业务系统在不同故障触发后的响应信息,这里提到的响应信息对应的响应包括服务超时、卡顿现象,以及系统重启等,还可以通过诊断工具进行现象分析,得到分析结果,从而可以根据错误日志、告警信息、响应信息以及分析结果,完成故障注入测试。Specifically, you can obtain the error logs in the system log, including memory leak logs, disk full logs, etc., obtain the alarm information for fault detection of the business system corresponding to the code to be tested, and obtain the response information of the business system after different faults are triggered, here The responses corresponding to the mentioned response information include service timeout, stuck phenomenon, system restart, etc. You can also use diagnostic tools to analyze the phenomenon and obtain the analysis results, so that you can complete the operation based on the error log, alarm information, response information, and analysis results. Fault injection testing.

也就是说,可以在故障触发后,可以通过业务系统的错误日志、告警信息、响应信息、诊断工具得到的分析结果等,来确定故障注入是否成功,以及确定业务系统是否对注入的故障产生了正确的反应。That is to say, after a fault is triggered, you can use the error logs, alarm information, response information, analysis results obtained by diagnostic tools, etc. of the business system to determine whether the fault injection is successful and whether the business system has responded to the injected fault. Correct response.

即,故障触发后根据故障类型可以针对性地观察、分析和检测,可以包括以下四点:That is, after a fault is triggered, it can be observed, analyzed and detected in a targeted manner according to the fault type, which can include the following four points:

(1)检查错误日志。例如,上述replaced_func函数执行一次就有内存泄漏,达到一定程度时会产生内存溢出,这时系统申请内存就有异常错误日志:java.lang.OutOfMemoryError。(1) Check the error log. For example, if the above replaced_func function is executed once, there will be a memory leak. When it reaches a certain level, a memory overflow will occur. At this time, the system will have an exception error log when applying for memory: java.lang.OutOfMemoryError.

(2)检查业务系统对故障的反应。如果业务系统对一些故障会有检测和告警,检查这些告警信息与故障现象是否一致,这些故障包括:磁盘空间、内存空间、cpu等。(2) Check the response of the business system to the failure. If the business system detects and alerts some faults, check whether the alarm information is consistent with the fault phenomenon. These faults include: disk space, memory space, CPU, etc.

本实施例中出现内存泄漏,会有内存空间不足的告警和CPU高的告警。In this embodiment, if a memory leak occurs, there will be an alarm for insufficient memory space and an alarm for high CPU.

(3)检查业务响应。检查业务在不同故障触发后的响应(比如服务响应慢、重启、扩容等),与预期响应结果是否一致。本例中出现内存泄漏,影响业务功能的响应时间,出现卡顿和超时现象。(3) Check the business response. Check whether the response of the business after different faults are triggered (such as slow service response, restart, expansion, etc.) is consistent with the expected response result. In this example, a memory leak occurs, which affects the response time of business functions and causes freezes and timeouts.

(4)系统分析、诊断、记录。有些故障触发后现象不太容易直观看到,需要通过诊断工具或诊断程序来判断故障是否注入成功,比如网络丢包、数据库表锁超时等。(4) System analysis, diagnosis, and recording. The phenomena after some faults are triggered are not easy to see visually. It is necessary to use diagnostic tools or diagnostic programs to determine whether the fault injection is successful, such as network packet loss, database table lock timeout, etc.

需要说明的是,本方法可以在故障注入测试完成后,方便地将待测试代码对应的业务系统恢复原状,即恢复为故障注入测试前的状态,即,可以将寄存器中所述待替换函数对应的地址还原,还原寄存器的状态数据,以及直接将动态链接库删除,以恢复所述待测试代码对应的业务系统。It should be noted that this method can conveniently restore the business system corresponding to the code to be tested to its original state after the fault injection test is completed, that is, to the state before the fault injection test. That is, the function to be replaced in the register can be corresponding to Address restoration, restoration of register status data, and direct deletion of the dynamic link library to restore the business system corresponding to the code to be tested.

动态链接库在加载时记录了原始函数信息,再用同样的方法将寄存器中记录指令的地址恢复到原始数据,进程将不再加载动态链接库。The dynamic link library records the original function information when loading, and then uses the same method to restore the address of the recorded instruction in the register to the original data, and the process will no longer load the dynamic link library.

需要说明的是,为了便于描述,将执行本方法的执行主体作为服务器进行描述,执行主体可以是台式电脑、服务器、大型的服务平台等,在此不进行限定。It should be noted that, for the convenience of description, the execution subject that executes this method is described as a server. The execution subject can be a desktop computer, a server, a large service platform, etc., and is not limited here.

相比于其他故障注入测试方法,本发明实施例具有如下优点:Compared with other fault injection testing methods, embodiments of the present invention have the following advantages:

基于业务系统和场景来进行故障注入,作用于业务系统的进程和组件,可以精准地模拟真实的业务场景异常,这些异常相比其他故障注入的系统级异常更真实和精准;Fault injection based on business systems and scenarios can accurately simulate real business scenario exceptions by acting on the processes and components of the business system. These exceptions are more realistic and accurate than system-level exceptions injected by other faults;

相比于应用系统部署在服务器之前在业务源代码中添加故障用例库,并在业务运行时通过命令/消息来触发故障生效,本发明具有不浸入、不重启业务系统的优点,在业务系统正常运行时动态地替换函数,完成故障代码的注入,并根据需要随时触发故障,另外故障的恢复非常方便,只需要将替换函数的地址重新写回原函数的地址即可,不影响业务的运行,这种故障注入方式具有安全灵活的特点;Compared with adding a fault use case library in the business source code before the application system is deployed on the server, and triggering the fault to take effect through commands/messages when the business is running, the present invention has the advantage of not immersing or restarting the business system. When the business system is normal, Dynamically replace functions during runtime, complete the injection of fault codes, and trigger faults at any time as needed. In addition, fault recovery is very convenient. You only need to rewrite the address of the replacement function back to the address of the original function, without affecting the operation of the business. This fault injection method is safe and flexible;

相比于动态替换字节码技术,动态字段码通过JVM接口重写进程class字节码文件,实现函数的动态替换,但该技术有许多限制,不允许有成员变量和方法,不允许改变类的属性,不允许创建对象,只能调用静态方法,本发明没有这些限制,可以更改变量值,调用其他方法,灵活地编写故障代码来触发异常。Compared with dynamic replacement bytecode technology, dynamic field code rewrites the process class bytecode file through the JVM interface to achieve dynamic replacement of functions. However, this technology has many limitations. Member variables and methods are not allowed, and class changes are not allowed. Attributes do not allow object creation and can only call static methods. The present invention does not have these restrictions. Variable values can be changed, other methods can be called, and fault codes can be flexibly written to trigger exceptions.

以上为本说明书的一个或多个实施例提供基于函数替换的故障注入测试方法,基于同样的思路,本说明书还提供了基于函数替换的故障注入测试装置,如图5所示。The above provides a fault injection testing method based on function replacement for one or more embodiments of this specification. Based on the same idea, this specification also provides a fault injection testing device based on function substitution, as shown in Figure 5.

图5为本说明书提供的一种基于函数替换的故障注入测试装置示意图,包括;Figure 5 is a schematic diagram of a fault injection test device based on function replacement provided in this specification, including;

获取模块501,用于获取待测试代码,并基于所述待测试代码,确定函数调用链;The acquisition module 501 is used to obtain the code to be tested, and determine the function call chain based on the code to be tested;

确定模块502,用于根据所述函数调用链,确定待替换函数;Determination module 502, used to determine the function to be replaced according to the function call chain;

修改模块503,用于对所述待替换函数的函数代码进行修改,以将需要注入的故障代码添加到所述待替换函数中,得到修改后函数,并生成所述修改后函数对应的动态链接库;Modification module 503, used to modify the function code of the function to be replaced, to add the fault code that needs to be injected to the function to be replaced, obtain a modified function, and generate a dynamic link corresponding to the modified function library;

注入模块504,用于将所述动态链接库注入到所述待替换函数所在的进程,以将所述进程中的待替换函数替换为所述修改后函数;Injection module 504 is used to inject the dynamic link library into the process where the function to be replaced is located, so as to replace the function to be replaced in the process with the modified function;

触发模块505,用于响应于预设的触发规则,触发所述修改后函数以完成故障触发,根据故障触发后得到的系统相关信息,完成故障注入测试,所述系统相关信息至少包括系统日志以及响应信息。The trigger module 505 is configured to respond to the preset trigger rules, trigger the modified function to complete the fault trigger, and complete the fault injection test based on the system-related information obtained after the fault trigger. The system-related information at least includes system logs and Response information.

可选地,所述获取模块501具体用于,通过Callgraph工具生成所述待测试代码的静态函数调用链,作为得到的函数调用链。Optionally, the acquisition module 501 is specifically configured to use the Callgraph tool to generate a static function call chain of the code to be tested as the obtained function call chain.

可选地,所述确定模块502具体用于,确定所述函数调用链中的各函数;从所述各函数确定出满足预设条件的函数,作为候选函数,其中,所述预设条件包括:函数属于用户态函数、函数不属于多线程函数以及函数不属于静态函数和静态函数中包含的函数中的至少一种;从所述候选函数中,确定出待替换函数。Optionally, the determination module 502 is specifically configured to determine each function in the function call chain; determine from each function a function that satisfies preset conditions as a candidate function, wherein the preset conditions include : The function belongs to a user-mode function, the function does not belong to a multi-threaded function, and the function does not belong to at least one of a static function and a function included in a static function; from the candidate functions, a function to be replaced is determined.

可选地,所述注入模块504具体用于,确定所述待替换函数所在的进程,作为目标进程;加载所述动态链接库对应的进程,并为所述动态链接库对应的进程分配内存空间;获取所述目标进程中待替换函数对应的地址,以及所述动态链接库对应的进程中所述修改后函数对应的地址;将寄存器中所述待替换函数对应的地址替换为所述动态链接库对应的进程中所述修改后函数对应的地址;保存所述寄存器的数据和状态,以完成注入。Optionally, the injection module 504 is specifically configured to determine the process in which the function to be replaced is located as the target process; load the process corresponding to the dynamic link library, and allocate memory space for the process corresponding to the dynamic link library. ; Obtain the address corresponding to the function to be replaced in the target process, and the address corresponding to the modified function in the process corresponding to the dynamic link library; Replace the address corresponding to the function to be replaced in the register with the dynamic link The address corresponding to the modified function in the process corresponding to the library; save the data and status of the register to complete the injection.

可选地,所述触发规则包括:在所述待测试代码对应的业务系统中进行按钮点击、在命令行中输入预设指令以及在所述业务系统中进行消息发送中的至少一种。Optionally, the triggering rule includes at least one of: clicking a button in the business system corresponding to the code to be tested, entering a preset instruction in the command line, and sending a message in the business system.

可选地,所述触发模块505具体用于,获取系统日志中的错误日志,包括内存泄漏日志、磁盘满日志;获取所述待测试代码对应的业务系统对故障检测的告警信息;获取所述业务系统在不同故障触发后的响应信息,所述响应信息对应的响应包括服务超时、卡顿现象,以及系统重启;通过诊断工具进行现象分析,得到分析结果;根据所述错误日志、所述告警信息、所述响应信息以及所述分析结果,完成故障注入测试。Optionally, the trigger module 505 is specifically configured to obtain error logs in the system log, including memory leak logs and disk full logs; obtain alarm information on fault detection by the business system corresponding to the code to be tested; obtain the The response information of the business system after different faults are triggered. The responses corresponding to the response information include service timeout, stuck phenomenon, and system restart; analyze the phenomenon through diagnostic tools to obtain the analysis results; according to the error log, the alarm information, the response information and the analysis results to complete the fault injection test.

可选地,所述装置还包括:Optionally, the device also includes:

还原模块506,用于将寄存器中所述待替换函数对应的地址还原,并将所述动态链接库删除,以恢复所述待测试代码对应的业务系统。The restoration module 506 is used to restore the address corresponding to the function to be replaced in the register and delete the dynamic link library to restore the business system corresponding to the code to be tested.

本说明书还提供了一种计算机可读存储介质,该存储介质存储有计算机程序,计算机程序可用于执行上述基于函数替换的故障注入测试方法。This specification also provides a computer-readable storage medium that stores a computer program. The computer program can be used to execute the above fault injection testing method based on function replacement.

本说明书还提供了图6所示的电子设备的示意结构图。如图6所述,在硬件层面,该电子设备包括处理器、内部总线、网络接口、内存以及非易失性存储器,当然还可能包括其他业务所需要的硬件。处理器从非易失性存储器中读取对应的计算机程序到内存中然后运行,以实现基于函数替换的故障注入测试方法。This specification also provides a schematic structural diagram of the electronic device shown in Figure 6. As shown in Figure 6, at the hardware level, the electronic device includes a processor, internal bus, network interface, memory and non-volatile memory, and of course may also include other hardware required for business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the fault injection testing method based on function replacement.

当然,除了软件实现方式之外,本说明书并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logical unit, and may also be hardware or logic device.

在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device, PLD)(例如现场可编程门阵列(Field Programmable GateArray,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware DescriptionLanguage)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(RubyHardware Description Language)等,目前最普遍使用的是VHDL(Very-High-SpeedIntegrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。In the 1990s, improvements in a technology could be clearly distinguished as hardware improvements (for example, improvements in circuit structures such as diodes, transistors, switches, etc.) or software improvements (improvements in method processes). However, with the development of technology, many improvements in today's method processes can be regarded as direct improvements in hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement of a method flow cannot be implemented using hardware entity modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic functions are determined by the user programming the device. Designers can program themselves to "integrate" a digital system on a PLD, instead of asking chip manufacturers to design and produce dedicated integrated circuit chips. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented using "logic compiler" software, which is similar to the software compiler used in program development and writing. Before compiling, The original code must also be written in a specific programming language, which is called Hardware Description Language (HDL). There is not only one type of HDL, but many types, such as ABEL (Advanced Boolean Expression Language) , AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones currently are VHDL (Very-High-SpeedIntegrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that by simply logically programming the method flow using the above-mentioned hardware description languages and programming it into the integrated circuit, the hardware circuit that implements the logical method flow can be easily obtained.

控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20 以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (eg, software or firmware) executable by the (micro)processor. , logic gates, switches, Application Specific Integrated Circuit (ASIC), programmable logic controllers and embedded microcontrollers. Examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the memory control logic. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program code, the controller can be completely programmed with logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded logic by logically programming the method steps. Microcontroller, etc. to achieve the same function. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the means for implementing various functions can be considered as structures within hardware components as well as software modules implementing the methods.

上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or A combination of any of these devices.

为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本说明书时可以把各单元的功能在同一个或多个软件和/或硬件中实现。For the convenience of description, when describing the above device, the functions are divided into various units and described separately. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and/or hardware.

本领域内的技术人员应明白,本说明书的实施例可提供为方法、系统、或计算机程序产品。因此,本说明书可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本说明书可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will understand that embodiments of the present specification may be provided as methods, systems, or computer program products. Thus, the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects. Furthermore, the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.

本说明书是参照根据本说明书实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。This specification is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the specification. It will be understood that each process and/or block in the flowchart illustrations and/or block diagrams, and combinations of processes and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions executed by the processor of the computer or other programmable data processing device produce a use A device for realizing the functions specified in a process or processes in a flowchart and/or a block or blocks in a block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory that causes a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction means, the instructions The device implements the functions specified in a process or processes in the flowchart and/or in a block or blocks in the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions may also be loaded onto a computer or other programmable data processing device, causing a series of operating steps to be performed on the computer or other programmable device to produce computer-implemented processing, thereby executing on the computer or other programmable device. Instructions provide steps for implementing the functions specified in a process or processes of a flowchart diagram and/or a block or blocks of a block diagram.

在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.

内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer-readable media, random access memory (RAM), and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.

计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information. Information may be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory. (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, Magnetic tape cassettes, tape magnetic disk storage or other magnetic storage devices or any other non-transmission medium can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.

还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the terms "comprises," "comprises," or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements not only includes those elements, but also includes Other elements are not expressly listed or are inherent to the process, method, article or equipment. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of additional identical elements in a process, method, article, or device that includes the stated element.

本领域技术人员应明白,本说明书的实施例可提供为方法、系统或计算机程序产品。因此,本说明书可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will appreciate that embodiments of the present specification may be provided as methods, systems, or computer program products. Thus, the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects. Furthermore, the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.

本说明书可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本说明书,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。This specification may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present description may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through communications networks. In a distributed computing environment, program modules may be located in both local and remote computer storage media including storage devices.

本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。Each embodiment in this specification is described in a progressive manner. The same and similar parts between the various embodiments can be referred to each other. Each embodiment focuses on its differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For relevant details, please refer to the partial description of the method embodiment.

以上所述仅为本说明书的实施例而已,并不用于限制本说明书。对于本领域技术人员来说,本说明书可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本说明书的权利要求范围之内。The above descriptions are only examples of this specification and are not intended to limit this specification. Various modifications and variations may occur to those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification shall be included in the scope of the claims of this specification.

Claims (10)

CN202311285981.4A2023-10-072023-10-07Fault injection testing method and device based on function replacementActiveCN117009252B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202311285981.4ACN117009252B (en)2023-10-072023-10-07Fault injection testing method and device based on function replacement

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202311285981.4ACN117009252B (en)2023-10-072023-10-07Fault injection testing method and device based on function replacement

Publications (2)

Publication NumberPublication Date
CN117009252A CN117009252A (en)2023-11-07
CN117009252Btrue CN117009252B (en)2024-01-02

Family

ID=88574741

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202311285981.4AActiveCN117009252B (en)2023-10-072023-10-07Fault injection testing method and device based on function replacement

Country Status (1)

CountryLink
CN (1)CN117009252B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN117312040A (en)*2023-11-082023-12-29之江实验室Remote self-service maintenance method and device for equipment, storage medium and equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US7757215B1 (en)*2006-04-112010-07-13Oracle America, Inc.Dynamic fault injection during code-testing using a dynamic tracing framework
CN105550080A (en)*2015-11-262016-05-04广州华多网络科技有限公司Method, apparatus and system for performing server program fault injection based on Linux
CN105653979A (en)*2015-12-292016-06-08银江股份有限公司Code injection based privacy information protection method
CN108614764A (en)*2016-12-122018-10-02中国航空工业集团公司西安航空计算技术研究所IMA application software fault filling methods
CN110262972A (en)*2019-06-172019-09-20中国科学院软件研究所A kind of failure testing tool and method towards micro services application
CN112714015A (en)*2020-12-232021-04-27上海科梁信息工程股份有限公司Communication data fault injection method and system, communication device and storage medium
CN114064114A (en)*2021-11-192022-02-18云控智行科技有限公司Dynamic library generation method and device
CN114691504A (en)*2022-03-282022-07-01北京交通大学 A fault injection method based on call instruction replacement

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US7757289B2 (en)*2005-12-122010-07-13Finjan, Inc.System and method for inspecting dynamically generated executable code

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US7757215B1 (en)*2006-04-112010-07-13Oracle America, Inc.Dynamic fault injection during code-testing using a dynamic tracing framework
CN105550080A (en)*2015-11-262016-05-04广州华多网络科技有限公司Method, apparatus and system for performing server program fault injection based on Linux
CN105653979A (en)*2015-12-292016-06-08银江股份有限公司Code injection based privacy information protection method
CN108614764A (en)*2016-12-122018-10-02中国航空工业集团公司西安航空计算技术研究所IMA application software fault filling methods
CN110262972A (en)*2019-06-172019-09-20中国科学院软件研究所A kind of failure testing tool and method towards micro services application
CN112714015A (en)*2020-12-232021-04-27上海科梁信息工程股份有限公司Communication data fault injection method and system, communication device and storage medium
CN114064114A (en)*2021-11-192022-02-18云控智行科技有限公司Dynamic library generation method and device
CN114691504A (en)*2022-03-282022-07-01北京交通大学 A fault injection method based on call instruction replacement

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
Enhancement of fault injection techniques based on the modification of VHDL code;Baraza J C 等;IEEE Transactions on Very Large Scale Integration Systems;全文*
基于"龙芯"的VxWorks系统函数在轨更新研究;史毅龙;薛长斌;;电子设计工程(第21期);全文*
基于Pspice的电路仿真故障注入的方法研究;陈隽;蔡金燕;李刚;;信息技术(第01期);全文*
模型驱动的VxWorks操作系统故障注入与鲁棒性测试研究;朱晓燕;吴际;尚会波;;科研信息化技术与应用(第03期);全文*

Also Published As

Publication numberPublication date
CN117009252A (en)2023-11-07

Similar Documents

PublicationPublication DateTitle
Yan et al.Systematic testing for resource leaks in Android applications
Hu et al.Efficiently, effectively detecting mobile app bugs with appdoctor
CN110554965B (en)Automated fuzz testing method, related equipment and computer readable storage medium
US8468501B2 (en)Partial recording of a computer program execution for replay
EP3785125B1 (en)Selectively tracing portions of computer process execution
Huo et al.Improving oracle quality by detecting brittle assertions and unused inputs in tests
EP3921734B1 (en)Using historic execution data to visualize tracepoints
EP2850525A1 (en)Assisting development tools through inserted code statements
US10209984B2 (en)Identifying a defect density
US11599445B2 (en)Watcher: precise and fully-automatic on-site failure diagnosis
CN107820608A (en)For the method and apparatus for the Debugging message for producing, capture, storing and loading the test script to fail
CN117009252B (en)Fault injection testing method and device based on function replacement
Sen et al.Jalangi: a tool framework for concolic testing, selective record-replay, and dynamic analysis of JavaScript
Jiang et al.ReTestDroid: towards safer regression test selection for android application
US7793160B1 (en)Systems and methods for tracing errors
WO2021061219A1 (en)Reducing trace recording overheads with targeted recording via partial snapshots
CN109582542B (en)Method for dumping core of embedded system
YanProgram analyses for understanding the behavior and performance of traditional and mobile object-oriented software
Hermann et al.Getting to know you: Towards a capability model for java
Toffalini et al.Practical static analysis of context leaks in Android applications
Cioroaica et al.Accelerated simulated fault injection testing
Van Der Kouwe et al.On the soundness of silence: Investigating silent failures using fault injection experiments
Toffalini et al.Static analysis of context leaks in android applications
US20170123959A1 (en)Optimized instrumentation based on functional coverage
DavydovDetecting Memory Leaks in Long-Running Applications

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp