Test case generation method and device and storage medium

By decomposing communication protocols for multiple levels, and constructing structures and rules of binary tree generation test cases, the problem of low test coverage in the existing technology has been solved, and effective coverage of all levels of communication protocols is achieved.

CN119383123AActive Publication Date: 2025-01-28GUANGDONG POWER GRID CO LTD +1
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202411592626.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-08
Publication Date
2025-01-28
Estimated Expiration
2044-11-08

AI Technical Summary

Technical Problem

Existing test case generation methods are usually to build test cases for a certain feature or certain characteristics of the communication protocol, which cannot cover all levels of the communication protocol, resulting in low test coverage.

Method used

By decomposing the target protocol into multiple levels, the structural binary tree and the corresponding rule binary tree of each level protocol are constructed, and these binary trees are traveled to generate a one -dimensional matrix, and the test case is finally filled.

Benefits of technology

Make sure that each data field is filled in accordance with its generation rules, which can cover all levels of the target protocol, effectively improve the test coverage and improve the reliability of test cases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119383123A_ABST
    Figure CN119383123A_ABST
Patent Text Reader

Abstract

The invention discloses a test case generation method and device and a storage medium. The method comprises the following steps: decomposing a target protocol into a plurality of hierarchical protocols; constructing a structure binary tree and a corresponding rule binary tree of each level of protocol; traversing each structure binary tree to generate a one-dimensional matrix corresponding to each structure binary tree; and traversing each regular binary tree, filling the first node data of each regular binary tree into the one-dimensional matrix of the binary tree with the corresponding structure, and generating a test case of the target protocol. According to the invention, the structure binary tree and the corresponding rule binary tree of each level of protocol are constructed, and the first node data of each rule binary tree is filled into the one-dimensional matrix of the corresponding structure binary tree to generate the test case, so that each data field can be ensured to be filled according to the corresponding generation rule; and the corresponding test case can be generated based on the whole target protocol, all levels of the target protocol can be covered, and the test coverage rate is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a test case generation method, device and storage medium. Background Art

[0002] With the rapid development of information technology, the security and stability of communication protocols have become important issues in the field of information security. The development of communication protocol fuzz testing technology came into being in this context and has gradually become one of the key technologies to ensure communication security.

[0003] Existing test case generation methods usually construct test cases for a certain feature or certain features of the communication protocol, which cannot cover all levels of the communication protocol, resulting in low test coverage. Summary of the invention

[0004] The present invention provides a test case generation method, device and storage medium to solve the technical problem that some test case generation methods usually construct test cases for a certain characteristic or certain characteristics of a communication protocol and cannot cover all levels of the communication protocol, resulting in low test coverage.

[0005] The present invention provides a test case generation method, comprising:

[0006] Decompose the target protocol into multiple levels of protocols;

[0007] Construct the structural binary tree and corresponding regular binary tree of each level of protocol;

[0008] Traversing each of the structured binary trees to generate a one-dimensional matrix corresponding to each of the structured binary trees;

[0009] Each of the regular binary trees is traversed, and the first node data of each of the regular binary trees is filled into the one-dimensional matrix of the corresponding structured binary tree to generate a test case for the target protocol.

[0010] Furthermore, the target protocol is decomposed into multiple hierarchical protocols, including:

[0011] Based on a preset protocol layering model, determining the hierarchical structure of the target protocol;

[0012] Based on the hierarchical structure, the target protocol is decomposed into a plurality of hierarchical protocols.

[0013] Furthermore, the construction of the structural binary tree and the corresponding regular binary tree of each level of protocol includes:

[0014] Determine the node structure of each layer protocol; wherein the node structure includes data nodes and rule nodes;

[0015] A structural binary tree is constructed according to the data nodes, and a regular binary tree corresponding to the structural binary tree is constructed according to the regular nodes.

[0016] Furthermore, traversing each of the structured binary trees to generate a one-dimensional matrix corresponding to each of the structured binary trees includes:

[0017] The second node data of each structured binary tree is traversed, each second node data is used as an element of a one-dimensional matrix, and all node elements constitute a one-dimensional matrix corresponding to the structured binary tree.

[0018] Furthermore, the second node data includes at least one of random data, enumeration data and string data.

[0019] The present invention also provides a test case generating device, comprising:

[0020] A protocol decomposition module is used to decompose the target protocol into multiple layers of protocols;

[0021] Binary tree construction module, used to construct the structural binary tree and corresponding regular binary tree of each level of protocol;

[0022] A one-dimensional matrix generation module, used for traversing each of the structured binary trees and generating a one-dimensional matrix corresponding to each of the structured binary trees;

[0023] The test case generation module is used to traverse each of the regular binary trees, fill the node data of each of the regular binary trees into the one-dimensional matrix of the corresponding structured binary tree, and generate a test case for the target protocol.

[0024] Furthermore, the protocol decomposition module is also used for:

[0025] Based on a preset protocol layering model, determining the hierarchical structure of the target protocol;

[0026] Based on the hierarchical structure, the target protocol is decomposed into a plurality of hierarchical protocols.

[0027] Furthermore, the binary tree construction module is also used for:

[0028] Determine the node structure of each layer protocol; wherein the node structure includes data nodes and rule nodes;

[0029] A structural binary tree is constructed according to the data nodes, and a regular binary tree corresponding to the structural binary tree is constructed according to the regular nodes.

[0030] The present invention also provides a terminal device, comprising: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and the processor implements the test case generation method as described above when executing the computer program.

[0031] The present invention also provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the test case generation method as described above.

[0032] The embodiment of the present invention constructs a structural binary tree and a corresponding regular binary tree for each level of the protocol, and fills the first node data of each regular binary tree into the one-dimensional matrix of the corresponding structural binary tree to generate test cases. This can ensure that each data field is filled according to its corresponding generation rule, and can generate corresponding test cases based on the entire target protocol, which can cover all levels of the target protocol and effectively improve the test coverage.

[0033] Furthermore, the embodiment of the present invention constructs a structural binary tree according to data nodes, and constructs a regular binary tree corresponding to the structural binary tree according to rule nodes, ensuring that each data field of the protocol has a clear generation rule, thereby effectively improving the reliability of test cases. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 It is a flowchart of a test case generation method provided by an embodiment of the present invention;

[0035] Figure 2 is a schematic diagram of a binary tree structure provided by an embodiment of the present invention;

[0036] Figure 3 is a schematic diagram of a layer traversal provided by an embodiment of the present invention;

[0037] Figure 4 The structure diagram of the test case generation device provided by the embodiment of the present invention is DETAILED DESCRIPTION

[0038] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0039] In the description of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the feature. In the description of this application, unless otherwise specified, "plurality" means two or more.

[0040] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0041] See also Figure 1 , an embodiment of the present invention provides a test case generation method, comprising:

[0042] S1. Decompose the target protocol into multiple hierarchical protocols;

[0043] In the embodiment of the present invention, the target protocol may be a communication protocol, and may be decomposed into multiple layer protocols according to the actual situation of the target protocol, for example, decomposed into L1, L2, L3, etc. layer protocols.

[0044] S2. Construct the structural binary tree and corresponding rule binary tree of each level protocol;

[0045] In an embodiment of the present invention, constructing a structural binary tree can provide a clear hierarchical representation of the protocol data structure, which is helpful for understanding and analyzing the complex structure of the protocol; constructing a rule binary tree can define how to generate and select the values ​​of the protocol data fields, thereby effectively improving the controllability of the test case.

[0046] S3, traverse each structural binary tree and generate a one-dimensional matrix corresponding to each structural binary tree;

[0047] In the embodiment of the present invention, the one-dimensional matrix provides a linear storage method for the protocol data, which is beneficial to improving the reliability of the data storage of the structured binary tree node, thereby providing the necessary data structure for the subsequent generation of test cases.

[0048] S4. Traverse each regular binary tree, fill the first node data of each regular binary tree into the one-dimensional matrix of the corresponding structured binary tree, and generate a test case for the target protocol.

[0049] In an embodiment of the present invention, by constructing a structural binary tree and a corresponding regular binary tree for each level of the protocol, and filling the first node data of each regular binary tree into the one-dimensional matrix of the corresponding structural binary tree to generate a test case, it can ensure that each data field is filled according to its corresponding generation rule, and can generate a corresponding test case based on the entire target protocol, which can cover all levels of the target protocol and effectively improve the test coverage.

[0050] In one embodiment, step S1, decomposing the target protocol into multiple hierarchical protocols, includes:

[0051] S11. Determine the hierarchical structure of the target protocol based on a preset protocol hierarchical model;

[0052] In an embodiment of the present invention, the overall structure of the target protocol can be mapped to a preset protocol layering model. The protocol layering model can be designed based on the OSI seven-layer model or the TCP / IP four-layer model. The protocol layering model can decompose the communication protocol into several layers, and each layer structure has specific functions and protocols. For example, in the LTE network architecture, the interface protocol is divided into three layers: the physical layer (PHY), the L2 data link layer (including PDCP, RLC, MAC layer) and the L3 network layer (including NAS, RRC layer). The embodiment of the present invention can clearly identify the various layers of the target protocol and determine the relationship between them through the preset protocol layering model.

[0053] S12. Based on the hierarchical structure, decompose the target protocol into multiple hierarchical protocols.

[0054] In the embodiment of the present invention, after the hierarchical structure is determined, the target protocol is decomposed into specific multiple hierarchical protocols based on the hierarchical structure, and each functional module of the protocol can be allocated to the corresponding layer to achieve. For example, the physical layer is responsible for transmitting the original bit stream, the data link layer is responsible for the transmission and error detection of the frame, the network layer is responsible for the routing of the data packet, the transport layer provides an end-to-end interface, and the application layer processes specific application data.

[0055] The embodiment of the present invention can construct a comprehensive test case for each layer protocol by performing hierarchical decomposition on the target protocol, thereby ensuring that each part of the protocol can be fully tested, thereby improving the test coverage.

[0056] In one embodiment, step S2, constructing a structural binary tree and a corresponding regular binary tree of each layer protocol, includes:

[0057] S21, determining the node structure of each layer of the protocol; wherein the node structure includes data nodes and rule nodes;

[0058] In the embodiment of the present invention, the data types of the data node include int16, int32, int64 and string; the rule types of the rule node include random rule and enumeration rule, wherein the random rule is used to generate random numbers, and the enumeration rule is used to enumerate a known set. The embodiment of the present invention can effectively increase the diversity of test cases by defining different rules, thereby effectively improving the test coverage.

[0059] S22. Construct a structural binary tree T1 according to the data nodes, and construct a regular binary tree TR1 corresponding to the structural binary tree according to the rule nodes.

[0060] In an embodiment of the present invention, a regular binary tree and a structural binary tree are in a corresponding relationship, and the quantity ratio thereof is 1:1, wherein the data nodes in the structural binary tree correspond to the regular nodes in the regular binary tree, the structure of the regular binary tree is the same as the structure of the structural binary tree, the nodes in the regular binary tree correspond to the node data in the structural binary tree, and the nodes in the regular binary tree can be variant rules, wherein the variant rules can be added according to actual needs.

[0061] The embodiment of the present invention constructs a structural binary tree according to data nodes, and constructs a regular binary tree corresponding to the structural binary tree according to rule nodes, ensuring that each data field of the protocol has a clear generation rule, thereby effectively improving the reliability of test cases.

[0062] In one embodiment, step S3, traversing each structure binary tree to generate a one-dimensional matrix corresponding to each structure binary tree, includes:

[0063] The second node data of each structured binary tree is traversed, each second node data is used as an element of a one-dimensional matrix, and all node elements constitute a one-dimensional matrix corresponding to the structured binary tree.

[0064] In the embodiment of the present invention, the number of elements in the constructed one-dimensional matrix corresponds to the number of nodes in the structured binary tree, and each time a node is traversed, a corresponding one-dimensional matrix element is generated, thereby forming a one-dimensional matrix.

[0065] In one embodiment, the second node data includes at least one of random data, enumeration data, and string data.

[0066] In one embodiment, step S4, traversing each regular binary tree, filling the first node data of each regular binary tree into the one-dimensional matrix of the corresponding structured binary tree, and generating a test case of the target protocol, includes:

[0067] S41, initializing a one-dimensional matrix;

[0068] S42, traverse each rule binary tree and generate test data according to the rules defined therein;

[0069] S43, filling the test data into the position of the corresponding structure binary tree node in the one-dimensional matrix, ensuring that the generated data is stored in the correct position according to the traversal order of the structure binary tree, including pre-order order, in-order order and post-order order;

[0070] S44. For non-leaf nodes in the regular binary tree, recursively perform steps S42-S43 on their child nodes to ensure that test data of all child nodes are generated and filled:

[0071] S45. After filling the one-dimensional matrix, verify whether the generated data complies with the protocol specification. If so, convert the filled one-dimensional matrix into a test case format of the target protocol.

[0072] See also Figure 2 , is a schematic diagram of a binary tree provided by an embodiment of the present invention. Figure 3 , is a schematic diagram of a hierarchical traversal provided by an embodiment of the present invention, wherein A, B, C, D, etc. in the figure are all binary tree nodes.

[0073] The implementation of the embodiments of the present invention has the following beneficial effects:

[0074] The embodiment of the present invention constructs a structural binary tree and a corresponding regular binary tree for each level of the protocol, and fills the first node data of each regular binary tree into the one-dimensional matrix of the corresponding structural binary tree to generate test cases. This can ensure that each data field is filled according to its corresponding generation rule, and can generate corresponding test cases based on the entire target protocol, which can cover all levels of the target protocol and effectively improve the test coverage.

[0075] Furthermore, the embodiment of the present invention constructs a structural binary tree according to data nodes, and constructs a regular binary tree corresponding to the structural binary tree according to rule nodes, ensuring that each data field of the protocol has a clear generation rule, thereby effectively improving the reliability of test cases.

[0076] See also Figure 4 Based on the same inventive concept as the above embodiment, an embodiment of the present invention provides a test case generating device, comprising:

[0077] The protocol decomposition module 10 is used to decompose the target protocol into multiple layers of protocols;

[0078] A binary tree construction module 20, used to construct a structural binary tree and a corresponding regular binary tree for each level of protocol;

[0079] A one-dimensional matrix generation module 30, used for traversing each structure binary tree and generating a one-dimensional matrix corresponding to each structure binary tree;

[0080] The test case generation module 40 is used to traverse each regular binary tree, fill the node data of each regular binary tree into the one-dimensional matrix of the corresponding structured binary tree, and generate a test case for the target protocol.

[0081] In one embodiment, the protocol decomposition module 10 is further used to:

[0082] Based on the preset protocol layering model, determine the hierarchical structure of the target protocol;

[0083] Based on the hierarchical structure, the target protocol is decomposed into multiple hierarchical protocols

[0084] In one embodiment, the binary tree construction module 20 is further used for:

[0085] Determine the node structure of each layer of the protocol; wherein the node structure includes data nodes and rule nodes;

[0086] A structural binary tree is constructed based on the data nodes, and a regular binary tree corresponding to the structural binary tree is constructed based on the rule nodes.

[0087] In one embodiment, the one-dimensional matrix generation module 30 is further used for:

[0088] The second node data of each structured binary tree is traversed, each second node data is used as an element of a one-dimensional matrix, and all node elements constitute a one-dimensional matrix corresponding to the structured binary tree.

[0089] In one embodiment, the second node data includes at least one of random data, enumeration data, and string data.

[0090] Correspondingly, an embodiment of the present invention also provides a terminal device, including: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, the test case generation method of any one of the above embodiments is implemented.

[0091] The terminal device of this embodiment includes: a processor, a memory, and a computer program and computer instructions stored in the memory and executable on the processor. When the processor executes the computer program, each step in the above embodiment 1 is implemented, for example Figure 1 Alternatively, when the processor executes the computer program, the functions of each module / unit in the above device embodiment, such as the test case generation module 40, are implemented.

[0092] Exemplarily, the computer program can be divided into one or more modules / units, one or more modules / units are stored in a memory and executed by a processor to complete the present invention. One or more modules / units can be a series of computer program instruction segments that can complete specific functions, and the instruction segments are used to describe the execution process of the computer program in a terminal device. For example, the test case generation module 40 is used to traverse each regular binary tree, fill the node data of each regular binary tree into the one-dimensional matrix of the corresponding structured binary tree, and generate a test case for the target protocol.

[0093] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the schematic diagram is merely an example of a terminal device and does not constitute a limitation on the terminal device. The terminal device may include more or fewer components than shown in the diagram, or may combine certain components, or different components. For example, the terminal device may also include an input / output device, a network access device, a bus, etc.

[0094] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device.

[0095] The memory can be used to store computer programs and / or modules. The processor realizes various functions of the terminal device by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the mobile terminal, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Med ia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0096] Among them, if the module / unit integrated in the terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.

[0097] Correspondingly, an embodiment of the present invention also provides a computer-readable storage medium, the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the test case generation method of any one of the above embodiments.

[0098] The above specific embodiments further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above are only specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.

Claims

1. A test case generation method, characterized in that: include: Decompose the target protocol into multiple levels of protocols; Construct the structural binary tree and corresponding regular binary tree of each level of protocol; Traversing each of the structured binary trees to generate a one-dimensional matrix corresponding to each of the structured binary trees; Each of the regular binary trees is traversed, and the first node data of each of the regular binary trees is filled into the one-dimensional matrix of the corresponding structured binary tree to generate a test case for the target protocol.

2. The test case generation method according to claim 1, characterized in that: The target protocol is decomposed into multiple hierarchical protocols, including: Based on a preset protocol layering model, determining the hierarchical structure of the target protocol; Based on the hierarchical structure, the target protocol is decomposed into a plurality of hierarchical protocols.

3. The test case generation method according to claim 1, characterized in that: The construction of the structural binary tree and the corresponding regular binary tree of each layer protocol includes: Determine the node structure of each layer protocol; wherein the node structure includes data nodes and rule nodes; A structural binary tree is constructed according to the data nodes, and a regular binary tree corresponding to the structural binary tree is constructed according to the regular nodes.

4. The test case generation method according to claim 1, characterized in that: The traversing each of the structured binary trees to generate a one-dimensional matrix corresponding to each of the structured binary trees includes: The second node data of each structured binary tree is traversed, each second node data is used as an element of a one-dimensional matrix, and all node elements constitute a one-dimensional matrix corresponding to the structured binary tree.

5. The test case generation method according to claim 4, characterized in that: The second node data includes at least one of random data, enumeration data and character string data.

6. A test case generating device, characterized in that: include: A protocol decomposition module is used to decompose the target protocol into multiple layers of protocols; Binary tree construction module, used to construct the structural binary tree and corresponding regular binary tree of each level of protocol; A one-dimensional matrix generation module, used for traversing each of the structured binary trees and generating a one-dimensional matrix corresponding to each of the structured binary trees; The test case generation module is used to traverse each of the regular binary trees, fill the node data of each of the regular binary trees into the one-dimensional matrix of the corresponding structured binary tree, and generate a test case for the target protocol.

7. The test case generating device according to claim 6, characterized in that: The protocol decomposition module is also used for: Based on a preset protocol layering model, determining the hierarchical structure of the target protocol; Based on the hierarchical structure, the target protocol is decomposed into a plurality of hierarchical protocols.

8. The test case generating device according to claim 6, characterized in that: The binary tree construction module is also used to: Determine the node structure of each layer protocol; wherein the node structure includes data nodes and rule nodes; A structural binary tree is constructed according to the data nodes, and a regular binary tree corresponding to the structural binary tree is constructed according to the regular nodes.

9. A terminal device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the test case generation method according to any one of claims 1 to 5 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the test case generation method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Regularization state machine model design method with stateful protocol

    CN104142888A

  • Recursive algorithm-based test case matrix generation method and device

    CN109614331A

  • Network protocol compliance checking method and system

    CN112637022A

  • Method and device for acquiring test sample

    CN112860549A

  • Protocol test case object generation method and system

    CN115269368A