Fuzz test case generation method and device, computer device, and storage medium
By analyzing virtual function call points and data flow and control flow information to generate fuzzy test cases, the problem of inaccurate fuzzy test case generation in existing technologies is solved, achieving higher accuracy and readability.
Patent Information
- Application Number
- CN202311438549.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-31
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2043-10-31
AI Technical Summary
Existing technologies, when generating fuzz test cases, directly analyze the usage of external software, leading to inaccurate generation and an inability to correctly detect the program status and vulnerabilities of the software under test.
By analyzing the virtual function call points in the intermediate representation code of external software, the target call list is obtained, and fuzz test cases are generated by combining the data flow and control flow information of the software under test, thus avoiding direct analysis of how the external software is used.
It improves the accuracy of fuzz test case generation, ensures the accuracy of detecting the program status and vulnerabilities of the software under test, and improves the readability and standardization of fuzz test case code.
Smart Images

Figure CN119961137B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of software testing, and more particularly, to a method and device for generating a fuzz test case, a computer device, and a storage medium. BACKGROUND
[0002] Fuzz testing is an effective testing method for checking the security of an information system. Fuzz testing explores program states and detects program vulnerabilities by driving fuzz test cases to input highly random data into a program. Writing fuzz test case code is a necessary step for fuzz testing software. In related technologies, fuzz test case code is usually generated by analyzing the usage of the software to be tested and then generating fuzz test cases according to the usage. However, this approach may not be accurate when generating fuzz test cases for some software. SUMMARY
[0003] The present application provides a method and device for generating a fuzz test case, a computer device, and a storage medium, which improves the accuracy of fuzz test case generation.
[0004] In a first aspect, the present application provides a method for generating a fuzz test case. The method includes: obtaining an intermediate representation code of an external software corresponding to a software to be tested; determining a target call list of a virtual function call point in the intermediate representation code corresponding to an external interface of the software to be tested, wherein the target call list includes interface information of an external interface called by the external software when calling the software to be tested; determining calling information of the software to be tested according to the target call list and data flow information and control flow information corresponding to the software to be tested, wherein the data flow information and the control flow information are determined based on data access instructions and control flow switching instructions in the intermediate representation code, and the calling information includes dependent data when the external software calls the external interface and control dependency relationship information between the external software and the external interface called by the external software; and generating a fuzz test case according to the calling information, wherein the fuzz test case is used for fuzz testing of the external software calling the software to be tested.
[0005] In a second aspect, an embodiment of the present application provides a device for generating a fuzz test case, the device comprising: a data acquisition module, a target call list determination module, a call information determination module, and a fuzz test case generation module, wherein the data acquisition module is configured to acquire intermediate representation code of external software corresponding to a software to be tested; the target call list determination module is configured to determine a target call list of a virtual function call point corresponding to an external interface of the software to be tested according to the intermediate representation code, wherein the target call list comprises interface information of the external interface called by the external software when the external software calls the software to be tested; the call information determination module is configured to determine call information of the software to be tested according to the target call list and data flow information and control flow information corresponding to the software to be tested, wherein the data flow information and the control flow information are determined based on data access instructions and control flow switching instructions in the intermediate representation code, and the call information comprises dependent data of the external software when the external software calls the external interface of the software to be tested and a control dependency relationship of the external software calling the external interface of the software to be tested in the control flow information; and the fuzz test case generation module is configured to generate a fuzz test case according to the call information, wherein the fuzz test case is used for fuzz testing the external software calling the software to be tested.
[0006] In a third aspect, an embodiment of the present application provides a computer device, comprising: one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more application programs are configured to execute the method for generating a fuzz test case provided in the first aspect.
[0007] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, wherein the computer readable storage medium stores program codes, and the program codes can be invoked by a processor to execute the method for generating a fuzz test case provided in the first aspect.
[0008] The method provided in the present application comprises the following steps: first, acquiring intermediate representation code of external software corresponding to a software to be tested; second, analyzing a virtual function call point in the intermediate representation code to obtain a target call list corresponding to an external interface of the software to be tested; and third, generating a fuzz test case according to the target call list, data flow information and control flow information corresponding to the software to be tested, and a template of the fuzz test case. The fuzz test case is generated by analyzing the virtual function call point, which avoids analysis errors and abnormal fuzz test cases caused by directly analyzing the usage mode of the external software to the software to be tested, and improves the accuracy of generating the fuzz test case. BRIEF DESCRIPTION OF DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort based on these drawings.
[0010] Figure 1 A flowchart of a method for generating a fuzz test case according to one embodiment of the present application is shown.
[0011] Figure 2 A flowchart of a method for generating a fuzz test case according to another embodiment of the present application is shown.
[0012] Figure 3 A flowchart of a method for generating a fuzz test case according to yet another embodiment of the present application is shown.
[0013] Figure 4 A block diagram of a device for generating a fuzz test case according to one embodiment of the present application is shown.
[0014] Figure 5 A block diagram of a computer device for executing a method for generating a fuzz test case according to an embodiment of the present application is shown.
[0015] Figure 6 A storage unit for storing or carrying program codes for implementing a method for generating a fuzz test case according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0016] In order to make the person in the art better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described in the following with reference to the drawings in the embodiments of the present application.
[0017] In the related automatic generation scheme of the fuzz test case code, the external test software is analyzed, the usage mode of the external interface of the software to be tested is extracted, the usage code of the external interface of the software to be tested is reconstructed using the usage mode, and the fuzz test case is generated based on the usage code.
[0018] But such fuzzy test case is based on external software directly calling the software to be tested, and some assembly language software is not directly calling the software to be tested, but indirectly calling through virtual function, for example, C language and C++ language. Therefore, when generating the fuzzy test case of the software written in C language or C++ language, if the use mode of the external software is directly extracted and the corresponding fuzzy test case is generated based on the use mode, the complete data flow and control flow cannot be analyzed and collected, so the use mode of the external interface cannot be normally analyzed, which will lead to inaccurate fuzzy test case, and then using the incorrect fuzzy test case will lead to incorrect test result when testing the software to be tested, and the purpose of fuzzy testing of the software to be tested cannot be achieved.
[0019] To solve the above problems, the inventors provide the fuzzy test case generation method, device, computer device and storage medium, which analyzes the virtual function call point to generate the fuzzy test case, avoids the analysis error caused by directly analyzing the use mode of the external software to the software to be tested and generates the abnormal fuzzy test case, and improves the accuracy of the fuzzy test case generation. The specific fuzzy test case generation method is described in detail in the subsequent embodiments.
[0020] The fuzzy test case generation method provided by the embodiments of the present application will be described in detail below in combination with the drawings.
[0021] Please refer to Figure 1 , Figure 1 The flowchart of the fuzzy test case generation method provided by one embodiment of the present application is shown. In the specific embodiment, the fuzzy test case generation method is applied to the fuzzy test case generation device 300 as shown in Figure 4 and the computer device 100 configured with the fuzzy test case generation device 300. Figure 5 The specific process of the embodiment will be described below with the computer device as an example. It can be understood that the computer device applied in the embodiment can be a computer device, a server device, a vehicle terminal, etc., which is not limited here. The flow shown in Figure 1 will be described in detail. The fuzzy test case generation method can specifically include the following steps:
[0022] Step S110: obtaining the intermediate representation code of the external software corresponding to the software to be tested.
[0023] The external software corresponding to the software to be tested refers to software that calls the software to be tested or provides the software to be tested with interaction with a user and / or other software. It should be noted that the software to be tested needs to be linked with the external software to obtain a complete application and implement all functions of the application.
[0024] In the embodiments of the present application, the intermediate representation code refers to intermediate code (IR). The intermediate representation code is a data structure code that can be understood by a computer after the external software is compiled, and is used to implement the linkage between the external software and the software to be tested. The intermediate representation codes obtained by different external software are different, and in this case, the specific forms of the intermediate representation code are not limited. The intermediate representation code of the external software can be obtained by compiling the external software. The software to be tested can be software written in C language or C++ language.
[0025] Step S120: determining a target call list of the virtual function call point corresponding to the external interface of the software to be tested according to the virtual function call point in the intermediate representation code, wherein the target call list includes interface information of the external interface called by the external software when calling the software to be tested.
[0026] In the intermediate representation code, there is a good data relationship representation between the external software and the software to be tested. The data relationship representation can be linear representation, and can also be nonlinear representation. In the embodiments of the present application, the data relationship representation between the external software and the software to be tested in the intermediate representation code is nonlinear representation. The nonlinear representation is preferably a virtual function call point. The data relationship representation between the external software and the software to be tested can also be set according to actual needs, and is not limited here.
[0027] In the embodiments of the present application, the external software implements the external interface of the external function calling the software to be tested through the virtual function calling point of the intermediate representation code. If the usage mode of the external software is directly extracted, the usage mode of the virtual function calling point is obtained, rather than the usage mode of the external software to the software to be tested. Moreover, the same virtual function calling point can call different external interfaces of different software. If the virtual function calling point of the external software is directly analyzed, the external interface of other software can be analyzed, and the fuzzy test case can be generated according to the analysis result. Such a fuzzy test case can affect the result of the fuzzy test, so that the program state and the program vulnerability of the software to be tested cannot be accurately detected. Therefore, before testing the software to be tested, the external interface corresponding to the virtual function calling point needs to be screened, so that the external interface calling list corresponding to one or more virtual function calling points of the intermediate representation code only contains the external interface of the current software to be tested, the target calling list of the virtual function calling point is obtained, and the target calling list only contains the interface information of the external interface of the current software to be tested, so as to ensure that the fuzzy test case obtained by analyzing the virtual function calling point only contains the related information of the software to be tested. The interface information can include the software to be tested corresponding to the external interface, the data transmitted by the external interface, the related interface information of the corresponding relationship between the external interface and the virtual function calling point, and the interface information can be added, modified and deleted by the user. In the scheme of the embodiments of the present application, the specific interface information is not limited.
[0028] In some embodiments, the screening method of the external interface corresponding to the virtual function calling point can be screening according to the name of the external interface, or the external interfaces of different software to be tested can be labeled first, and then the external interfaces are screened according to the labels. The screening method of the external interface is not limited here.
[0029] Step S130: determining the calling information of the software to be tested according to the target calling list and the data flow information and the control flow information corresponding to the software to be tested, wherein the data flow information and the control flow information are determined based on the data access instruction and the control flow switching instruction in the intermediate representation code, and the calling information includes the dependent data when the external software calls the external interface and the control dependent relationship information between the external software and the external interface.
[0030] The data flow information refers to a set of ordered data sequences with input data and output data composed of all data required and / or generated by the external software when calling the software to be tested. The control flow information refers to the sequence of the execution of the external interfaces in the software to be tested. The control dependency relationship information refers to the relationship information between other external interfaces used by the external software when calling the external interface. It should be noted that the data flow information and the control flow information can be obtained by identifying and / or analyzing the intermediate representation code. The data flow information and the control flow information can be in the form of a data flow graph and a control flow graph formed by the external interfaces as data flow nodes and control flow nodes, or in the form of a table, which is not limited herein.
[0031] According to the above dependency data in the calling information, the data type, the data attribute, and the data result corresponding to the data in the fuzzy test case can be determined. According to the control dependency relationship information in the calling information, the execution condition and the execution sequence of the fuzzy test case can be determined. Then, according to the data type, the data attribute, the data result corresponding to the data, the execution condition, and the execution sequence, the fuzzy test case for fuzzily testing the calling of the external software to the software to be tested can be generated.
[0032] Step S140: generating a fuzzy test case according to the calling information, the fuzzy test case being used for fuzzily testing the calling of the external software to the software to be tested.
[0033] The fuzzy test case refers to a computer program used for fuzz testing. The fuzzy test case includes, but is not limited to, fuzzy test data, an execution condition corresponding to the fuzzy test data, and a test result corresponding to the fuzzy test case.
[0034] In the embodiment of the present application, according to the above dependency data in the calling information, the data type, the data attribute, and the data result corresponding to the data in the fuzzy test case can be determined. According to the control dependency relationship information in the calling information, the execution condition and the execution sequence of the fuzzy test case can be determined. Then, according to the data type, the data attribute, the data result corresponding to the data, the execution condition, and the execution sequence, the fuzzy test case for fuzzily testing the calling of the external software to the software to be tested can be generated.
[0035] The method for generating a fuzz test case provided in the embodiments of the present application first acquires the intermediate representation code of the external software corresponding to the software to be tested, then analyzes the virtual function call points in the intermediate representation code to acquire the target call list corresponding to the external interface of the software to be tested, and finally generates the fuzz test case according to the target call list, the data flow information and the control flow information of the software to be tested, and the template of the fuzz test case. The fuzz test case is generated by analyzing the virtual function call points, which avoids the analysis errors and the generation of abnormal fuzz test cases caused by directly analyzing the usage mode of the external software to the software to be tested, and improves the accuracy of the generation of the fuzz test case.
[0036] Referring to Figure 2 , Figure 2 A flowchart of a method for generating a fuzz test case provided in another embodiment of the present application is shown. The method for generating a fuzz test case is applied to the computer device described above, and the following will be described in detail with reference to the flowchart shown in Figure 2 The method for generating a fuzz test case can specifically include the following steps:
[0037] Step S201: Acquire the intermediate representation code of the external software corresponding to the software to be tested.
[0038] In the embodiments of the present application, step S210 can refer to the content of other embodiments, which will not be described here again.
[0039] Step S202: Acquire the interface call list corresponding to each virtual function call point in the intermediate representation code.
[0040] The interface call list includes but is not limited to the interface name of the called external interface, the call parameter of the called external interface, and the dependent data when the external interface is called, and other interface information.
[0041] In the embodiments of the present application, the virtual function call point can call one or more external interfaces of the software to be tested, or can call one or more external interfaces of multiple software to be tested. The interface call list corresponding to each virtual function call point can be pre-stored in a storage unit. When the intermediate representation code corresponding to the external software is obtained after the external software is compiled, the corresponding interface call list is acquired from the storage unit according to the virtual function call point in the intermediate representation code. The acquisition of the interface call list can also be the extraction of the virtual function call point and the external interface corresponding to the virtual function from the intermediate representation code, so as to obtain the interface call list corresponding to each virtual function call point. The acquisition method of the interface call list corresponding to the virtual function call point is not specifically limited here.
[0042] Step S203: determining interface information of an external interface called by the external software when calling the to-be-tested software based on the interface call list corresponding to each virtual function call point.
[0043] Since the virtual function call point also calls external interfaces of other software, in order to ensure the accuracy of the fuzz testing on the to-be-tested software, the interface information in the interface call list corresponding to the virtual function call point needs to be screened. The screening manner can be screening according to the interface name in the interface information. It should be noted that the external interface needs to be named strictly according to the naming specification when naming, so as to improve the accuracy of screening the call information in the interface call list. The screening manner can also be screening according to the data relied on when calling the external interface. The screening manner of the interface information in the interface call list is not limited here.
[0044] Exemplarily, the interface call list corresponding to each virtual function call point can be as shown in Table 1:
[0045]
[0046] Table 1
[0047] As shown in Table 1, the external interfaces called by different virtual function call points are different, and the parameters called are also different.
[0048] Step S204: determining the target call list according to the interface information.
[0049] In the embodiment of the present application, the interface information of the external interface of the to-be-tested software in the interface call list of all virtual function call points in the intermediate representation code is comprehensively determined, and the target call list of the virtual function call point is determined. The interface information in the target call list can be the same as the interface information in the interface call list, or can be different, and can be customized by the user. The interface information in the target call list is not limited here.
[0050] Exemplarily, if the to-be-tested software is software 1, the target call list can be as shown in Table 2:
[0051]
[0052] Table 2
[0053] As shown in Table 2, the target call list only includes the interface information of the external interface of the to-be-tested software.
[0054] Step S205: determining the data flow information and the control flow information based on the data access instruction and the control flow switching instruction in the intermediate representation code.
[0055] The data access instruction is an instruction for accessing and operating data, and includes but is not limited to data instructions, data editing instructions, data moving instructions, and the like. In the embodiment of the present application, the data access instruction specifically refers to an instruction for accessing and operating data relied on by an external interface when the external software calls the external interface of the software to be tested.
[0056] The control flow switching instruction is an instruction for changing the execution order of a program, and includes but is not limited to jump instructions, branch instructions, and the like. In the embodiment of the present application, the control flow switching instruction specifically refers to a switching instruction for changing the interface call when the external software calls the external interface of the software to be tested.
[0057] According to the data access instruction, data flow information in the process of calling the external interface of the software to be tested by the external software is obtained, and according to the control flow switching instruction, control flow information in the process of calling the external interface of the software to be tested by the external software is obtained.
[0058] For example, in the process of calling the external interface of the software to be tested by the external software, data A, data B, and data C are relied on. The data access instruction can be that data B is accessed when calling the external interface 1 according to the data access instruction, data B is switched to data A when calling the external interface 2 according to the data access instruction, and data C is edited to obtain edited data C according to the data access instruction when calling the external interface 3. At this time, the corresponding data flow information is {data B, data A, edited data C}. In the calling process, the execution order of the called external interface can also be changed according to the control flow switching instruction. When the control flow switching instruction is not used, the control flow information is {external interface 1, external interface 2, external interface 3}. According to the control flow switching instruction, after calling the external interface 1, the external interface 3 is called, and after calling the external interface 3, the external interface 2 is called again. At this time, the control flow information is {external interface 1, external interface 3, external interface 2}. At this time, the data flow information will also change according to the change of the calling order of the external interface, and the latest data flow information {data B, edited data C, data A} is obtained. The data flow information and the control flow information obtained according to different data access instructions and different control flow switching instructions are different.
[0059] Step S206: According to the control flow information, determine the control dependency relationship information between the external interfaces called by the external software.
[0060] In the embodiment of the present application, the control dependency relationship refers to the control logic relationship between the external interfaces. The control dependency relationship includes but is not limited to sequential dependency and jump dependency.
[0061] For example, external interface 1 is called first, then external interface 2 is called, external interface 4 is called by jumping, and then external interface 3 is called. External interface 1 and external interface 2 are sequentially dependent, external interface 2 and external interface 4 are jump dependent, and external interface 2 and external interface 3 are sequentially dependent.
[0062] In some embodiments, the control flow information includes a control flow node graph, and determining the control dependency information between the external interfaces of the external software call according to the control flow information includes: obtaining the control dependency information between the external interfaces based on a connection relationship between nodes corresponding to the external interfaces in the control flow node graph.
[0063] The control flow node graph refers to a node graph in which nodes are connected according to execution order. The connection relationship includes, but is not limited to, serial connection, parallel connection, hierarchical connection, and various connection relationships. Serial connection refers to the connection of two nodes in a certain order, and the output of the previous node is used as the input of the next node. Parallel connection refers to the parallel connection of multiple nodes, and the output of each node is used as the input of other nodes. Hierarchical connection refers to some nodes as child nodes of high-level nodes, forming a hierarchical structure.
[0064] In the embodiments of the present application, since one external interface corresponds to one or more nodes in the control flow node graph, the control dependency between the external interfaces can be determined according to the connection relationship between the nodes in the control flow node graph.
[0065] Step S207: determining the dependent data when the external software calls the external interface of the software to be tested according to the data flow information.
[0066] In the embodiments of the present application, the dependent data refers to the data used when the external software calls the external interface. For example, data A is used when the external software calls external interface 1, and data C is used when the external software calls external interface 2. Therefore, the dependent data of external interface 1 is data A, and the dependent data of external interface 2 is data C.
[0067] Step S208: creating the test data based on the dependent data.
[0068] In the embodiments of the present application, the dependent data corresponding data type, data attribute, and data entity can be obtained according to the dependent data when the external software calls the external interface, and the corresponding test data can be created according to the dependent data corresponding data type, data attribute, and data entity. The creation of the test data can be automatically created by a test data creation program, or manually created according to the dependent data corresponding data type, data attribute, and data entity by a test personnel. The creation of the test data is not specifically limited herein,
[0069] Step S209: generating, according to the control dependency relationship information and the test data, and based on a template of the fuzz test case, a fuzz test case for the external software to perform fuzz testing on the software to be tested.
[0070] In order to facilitate the management of the fuzz test case, a template of the fuzz test case is introduced. The template of the fuzz test case defines the format of the fuzz test case, so that the fuzz test cases generated according to the template are consistent in format.
[0071] In the embodiments of the present application, the control dependency relationship information provides the execution dependency relationship between the external interfaces of the external software calling the software to be tested, and the test data provides the data used by the external software when calling the external interfaces of the software to be tested. According to the template of the fuzz test case, the fuzz test cases consistent in format are generated, which facilitates the management of the test cases by the tester.
[0072] The method for generating a fuzz test case provided in the embodiments of the present application can more clearly obtain how the external software calls the software to be tested and the data used in the calling process by analyzing the target calling list of the virtual function calling point in the intermediate representation code of the external software, the control flow information and the data flow information corresponding to the software to be tested, avoids the extraction error caused by directly extracting the usage of the external software, makes the fuzz test case generated based on the target for fuzz testing more accurate, improves the accuracy of the generated fuzz test case, improves the accuracy of detecting the state and program vulnerability of the software to be tested, and in the embodiments of the present application, a unified template is used to generate the fuzz test case, which improves the readability and standardization of the fuzz test case code.
[0073] Please refer to Figure 3 , Figure 3 A flowchart of a method for generating a fuzz test case provided in another embodiment of the present application is shown. The method for generating a fuzz test case is applied to the computer device described above, and the following will be described in detail with respect to the flowchart shown in Figure 3 The method for generating a fuzz test case can specifically include the following steps:
[0074] Step S310: obtaining the intermediate representation code of the external software corresponding to the software to be tested.
[0075] Step S320: determining, according to the virtual function calling point corresponding to the external interface of the software to be tested in the intermediate representation code, the target calling list of the virtual function calling point, wherein the target calling list includes the interface information of the external interface called by the external software when calling the software to be tested.
[0076] Step S330: determining the calling information of the to-be-tested software according to the target calling list and data flow information and control flow information corresponding to the to-be-tested software, wherein the data flow information and the control flow information are determined based on data access instructions and control flow switching instructions in the intermediate representation code, and the calling information includes dependent data when the external software calls the external interface and control dependency relationship information between the external software and the external interface.
[0077] In the embodiments of the present application, steps S310-S330 can refer to the content of other embodiments, which will not be repeated here.
[0078] Step S340: constructing data declaration corresponding to the dependent data according to a data type and a data entity corresponding to the dependent data.
[0079] The data declaration includes but is not limited to the type of data, data name and data initial value. Different assembly languages have different definition methods of data declaration, which will not be specifically limited here. Defining the data declaration of the data before using the data in the program can help improve the readability and maintainability of the code.
[0080] For example, "age = 30" represents a data declaration that defines a data age of integer type and the initial value of the data is 30.
[0081] Step S350: creating the test data according to the data declaration.
[0082] In the embodiments of the present application, since the data declaration includes the type of data, data name and data initial value, the data declaration can be changed or directly used according to the fuzzy test requirement, so as to create the test data.
[0083] For example, the fuzzy test requirement is "test age is 50", at this time, "age = 30" is changed to "age = 50", and at this time, the test data is "age = 50".
[0084] Step S360: determining the logical calling sequence when the external software calls the external interface according to the control dependency relationship.
[0085] In the embodiments of the present application, the control dependency relationship indicates the calling sequence when the external software calls the external interface, and the logical calling sequence is obtained according to the calling sequence.
[0086] For example, the external software calls the external interface 1, the external interface 2 and the external interface 3, and the control dependency indicates that the external software calls the external interface 2 first, then calls the external interface 1, and finally calls the external interface 3. At this time, the corresponding logical call sequence is {external interface 2, external interface 1, external interface 3}.
[0087] Step S370: According to the logical call sequence and the test data, and based on the template of the fuzz test case, a fuzz test case for the external software to perform the fuzz test on the software to be tested is generated.
[0088] In the embodiment of the present application, the logical call sequence provides a call sequence for the external software to call the external interface, and the test data provides data for the external software to call the external interface. According to the logical call sequence and the test data, the code body of the fuzz test case is obtained, and then the code body is automatically generated according to the template of the fuzz test case, so as to generate the fuzz test case with the call sequence and the test data.
[0089] The method for generating the fuzz test case provided in the embodiment of the present application first acquires the call sequence between the external interfaces of the software to be tested according to the control flow information, then determines the data type and the data entity of the data used by the external software when calling the external interfaces of the software to be tested according to the dependency data acquired from the data flow information, and finally generates the fuzz test case based on the template of the fuzz test case according to the call sequence and the data declaration created by the data type and the data entity, so that the generated fuzz test case is more accurate, and the generation of the fuzz test case is performed by using the unified template, thereby improving the readability and the standardization of the code of the fuzz test case.
[0090] Please refer to Figure 4Fig. 3 is a structural block diagram of a device for generating a fuzz test case according to an embodiment of the present application, which shows a structural block diagram of a device for generating a fuzz test case 300 according to an embodiment of the present application. The device for generating a fuzz test case 300 applies the computer device described above. The device for generating a fuzz test case 300 comprises a data obtaining module 310, a target call list determining module 320, a call information determining module 330, and a fuzz test case generating module 340. The data obtaining module 310 is configured to obtain an intermediate representation code of an external software corresponding to a software to be tested. The target call list determining module 320 is configured to determine a target call list of a virtual function call point corresponding to an external interface of the software to be tested according to the virtual function call point in the intermediate representation code of the external software. The target call list comprises interface information of the external interface called by the external software when the external software calls the software to be tested. The call information determining module 330 is configured to determine call information of the software to be tested according to the target call list, data flow information, and control flow information corresponding to the software to be tested. The data flow information and the control flow information are determined based on data access instructions and control flow switching instructions in the intermediate representation code. The call information comprises dependent data when the external software calls the external interface of the software to be tested in the data flow information and control dependent relationships of the external software calling the external interface of the software to be tested in the control flow information. The fuzz test case generating module 340 is configured to generate a fuzz test case according to the call information. The fuzz test case is used for fuzz testing the external software calling the software to be tested.
[0091] In some embodiments, the target call list determining module 320 can be specifically configured to obtain an interface call list corresponding to each virtual function call point in the intermediate representation code; determine interface information of the external interface called by the external software when the external software calls the software to be tested based on the interface call list corresponding to each virtual function call point; and determine the target call list according to the interface information.
[0092] In a possible implementation, the call information determining module 330 can be configured to determine the data flow information and the control flow information based on the data access instructions and the control flow switching instructions in the intermediate representation code; determine control dependent relationship information between the external interfaces called by the external software according to the control flow information; determine dependent data when the external software calls the external interface of the software to be tested according to the data flow information; and determine the call information corresponding to the software to be tested according to the control dependent relationship information and the dependent data.
[0093] Optionally, the control flow information comprises a control flow node graph, and the calling information determining module 330 is further configured to acquire the control dependency relationship information between the external interfaces based on a connection relationship between nodes corresponding to the external interfaces in the control flow node graph.
[0094] In some embodiments, the fuzz test case generating module 340 is specifically configured to create the test data based on the dependency data, and generate the fuzz test case for the external software to perform the fuzz test on the to-be-tested software based on a template of the fuzz test case according to the control dependency relationship information and the test data.
[0095] Optionally, the fuzz test case generating module 340 is further configured to determine a logical calling sequence when the external software calls the external interfaces according to the control dependency relationship, and generate the fuzz test case for the external software to perform the fuzz test on the to-be-tested software based on a template of the fuzz test case according to the logical calling sequence and the test data.
[0096] In some embodiments, the fuzz test case generating module 340 is further configured to construct a data declaration corresponding to the dependency data according to a data type and a data entity corresponding to the dependency data, and create the test data according to the data declaration.
[0097] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described apparatuses and modules can refer to the corresponding process in the foregoing method embodiments, which will not be described herein.
[0098] In several embodiments provided in the present application, the coupling between the modules can be electrical, mechanical or other forms of coupling.
[0099] In addition, each functional module in each embodiment of the present application can be integrated in one processing module, or each module can exist physically independently, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software functional module.
[0100] In summary, the scheme provided in the application first acquires the intermediate representation code of the external software corresponding to the software to be tested, then analyzes the virtual function call point in the intermediate representation code to acquire the target call list corresponding to the external interface of the software to be tested, and finally generates the fuzz test case according to the target call list, the data flow information and the control flow information corresponding to the software to be tested, and the template of the fuzz test case. The fuzz test case is generated by analyzing the virtual function call point, which avoids the analysis errors and the generation of abnormal fuzz test cases caused by directly analyzing the use mode of the external software to the software to be tested, and improves the accuracy of the fuzz test case generation.
[0101] Reference is made to Figure 5 which shows a structural block diagram of a computer device provided in an embodiment of the application. The computer device 100 can be a computer device, a server device, a vehicle-mounted terminal, or the like, which can run an application program. The computer device 100 in the application can include one or more of the following components: a processor 110, a memory 120, and one or more application programs, wherein the one or more application programs can be stored in the memory 120 and configured to be executed by the one or more processors 110, and the one or more application programs are configured to perform the method as described in the foregoing method embodiment.
[0102] The processor 110 can include one or more processing cores. The processor 110 connects various parts in the entire computer device 100 by various interfaces and lines, performs various functions of the computer device 100 and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 110 can integrate a combination of one or several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, the user interface, and the application program, etc.; the GPU is responsible for rendering and drawing display content; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 110, but be realized by a separate communication chip.
[0103] The memory 120 can include a random access memory (RAM) and can also include a read-only memory (ROM). The memory 120 can be used to store instructions, programs, codes, code sets, or instruction sets. The memory 120 can include a program storage area and a data storage area, where the program storage area can store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing each of the following method embodiments, etc. The data storage area can also store data created by the computer device 100 in use (such as a phone book, audio and video data, chat record data, etc.).
[0104] Reference is made to Figure 6 which shows a structural block diagram of a computer readable storage medium provided by an embodiment of the present application. The computer readable storage medium 200 stores program codes therein, which can be invoked by a processor to execute the methods described in the above method embodiments.
[0105] The computer readable storage medium 200 can be an electronic storage such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer readable storage medium 200 includes a non-transitory computer readable medium. The computer readable storage medium 200 has a storage space for the program codes 210 to execute any of the above methods. These program codes can be read from or written to one or more computer program products. The program codes 210 can be compressed in an appropriate form, for example.
[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to some technical features thereof, without departing from the spirit and scope of the technical solutions of the present application.
Claims
1. A method for generating fuzz test cases, characterized in that, The method includes: Obtain the intermediate representation code of the external software corresponding to the software under test; Based on the virtual function call points in the intermediate representation code that correspond to the external interfaces of the software under test, a target call list for the virtual function call points is determined, wherein the target call list includes interface information of the external interfaces called by the external software when calling the software under test; Based on the target call list and the data flow information and control flow information corresponding to the software under test, the call information of the software under test is determined. The data flow information and the control flow information are determined based on the data access instructions and control flow switching instructions in the intermediate representation code. The call information includes the dependency data when the external software calls the external interface and the control dependency relationship information between the external interfaces called by the external software. Based on the call information, fuzz test cases are generated, which are used to fuzz test the external software's calls to the software under test.
2. The method according to claim 1, characterized in that, The step of determining the target call list of virtual function call points based on the virtual function call points corresponding to the external interfaces of the software under test in the intermediate representation code includes: Obtain the interface call list corresponding to each virtual function call point in the intermediate representation code; Based on the interface call list corresponding to each virtual function call point, determine the interface information of the external interface called by the external software when calling the software under test; Based on the interface information, determine the target call list.
3. The method according to claim 1, characterized in that, The step of determining the call information of the software under test based on the target call list and the data flow information and control flow information corresponding to the software under test includes: The data flow information and control flow information are determined based on the data access instructions and control flow switching instructions in the intermediate representation code; Based on the control flow information, determine the control dependency information between the external interfaces called by the external software; Based on the data stream information, determine the dependency data when the external software calls the external interface of the software under test; Based on the control dependency information and the dependency data, the calling information corresponding to the software under test is determined.
4. The method according to claim 3, characterized in that, The control flow information includes a control flow node graph. The step of obtaining control dependency information between the external interfaces of the external software calling the software under test, based on the control flow information, includes: Based on the connection relationship between the nodes corresponding to the external interfaces in the control flow node graph, the control dependency relationship information between the external interfaces is obtained.
5. The method according to any one of claims 1-4, characterized in that, The step of generating fuzz test cases based on the invocation information includes: Based on the aforementioned dependency data, test data is created; Based on the control dependency information and test data, and using the template of the fuzz test case, fuzz test cases are generated for the external software to perform fuzz testing on the software under test.
6. The method according to claim 5, characterized in that, The step of generating fuzz test cases for the external software to perform fuzz testing on the software under test, based on the control dependency information and test data, and using a fuzz test case template, includes: Based on the control dependency relationship, determine the logical call sequence when the external software calls the external interface; Based on the logical call sequence and test data, and using the template of the fuzz test case, generate fuzz test cases for the external software to perform fuzz testing on the software under test.
7. The method according to claim 5, characterized in that, Before creating the test data based on the dependency data, the method further includes: Based on the data type and data entity corresponding to the dependent data, construct the data declaration corresponding to the dependent data; The test data is created based on the data statement.
8. A device for generating fuzzy test cases, characterized in that, The device includes: a data acquisition module, a target call list determination module, a call information determination module, and a fuzzy test case generation module, wherein... The data acquisition module is used to acquire the intermediate representation code of the external software corresponding to the software under test; The target call list determination module is used to determine the target call list of the virtual function call points based on the virtual function call points in the intermediate representation code that correspond to the external interfaces of the software under test. The target call list includes the interface information of the external interfaces called by the external software when it calls the software under test. The call information determination module is used to determine the call information of the software under test based on the target call list and the data flow information and control flow information corresponding to the software under test. The data flow information and the control flow information are determined based on the data access instructions and control flow switching instructions in the intermediate representation code. The call information includes the dependency data in the data flow information when the external software calls the external interface of the software under test and the control dependency relationship of the external software calling the external interface of the software under test in the control flow information. The fuzz test case generation module is used to generate fuzz test cases based on the call information. The fuzz test cases are used to fuzz test the external software's call to the software under test.
9. A computer device, characterized in that, include: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications being configured to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Method and apparatus for testing a code file
US20190317882A1
Unit testing method based on automatic generation of path coverage test cases
US20210209008A1