Method and device for generating test case based on stateful communication protocol model
By generating JSON format objects based on large language models and building a stateful communication protocol model, the problem of low efficiency of traditional testing tools is solved, and more efficient test coverage and accuracy recognition are achieved.
Patent Information
- Application Number
- CN202510495899.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-21
- Publication Date
- 2025-08-08
AI Technical Summary
Traditional testing tools rely on manually defining the protocol working mode for stateful communication protocol testing, lack scalability and low efficiency, making it difficult to effectively cover all possible state-dependent scenarios.
By filtering the redundant text of the stateful communication protocol text to be modeled, a large language model is used to generate objects in JSON format, a stateful communication protocol model is built, and a test case is generated based on actual parameters.
Improves test coverage and accuracy, can identify blind spots in the test, and ensures the stability and security of the communication system.
Smart Images

Figure CN120448260A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of protocol security testing, and in particular to a method and device for generating test cases based on a stateful communication protocol model. Background Art
[0002] A stateful communication protocol is one in which two or more communicating parties need to maintain a record or state of previously exchanged information. This allows the system to determine how to respond to subsequent communication requests based on previous state. Stateful communication protocols are commonly used in applications that require maintaining connection state, such as MQTT and AMQP in network communications.
[0003] In IoT scenarios, the application of stateful communication protocols is crucial, especially in terms of transmission reliability and identity authentication. Testing stateful communication protocols is crucial for building a stable, secure, and scalable IoT ecosystem. Especially in the face of device diversity and complex network environments, stateful communication protocol testing becomes a key link in maintaining the health of the entire system and user trust. However, contextual dependencies in stateful communication protocols mean that the behavior and responses of the protocol depend on previous interactions or states, which brings additional challenges to stateful communication protocol testing. Testing tools must be able to understand and simulate the behavior of state machines, including state transitions and the impact of historical information, while also handling complex conditional logic to ensure that tests cover all possible state-dependent scenarios.
[0004] However, traditional testing tools for stateful communication protocols mainly rely on manually defined protocol working modes, which lacks scalability and is inefficient. Summary of the Invention
[0005] In view of this, the present invention provides a method and device for generating test cases based on a stateful communication protocol model, which can solve the above technical problems.
[0006] In order to solve the above technical problems, the present invention is implemented as follows.
[0007] A method for generating test cases based on a stateful communication protocol model, comprising:
[0008] Step S1: filtering redundant text of the stateful communication protocol text to be modeled, determining a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, inputting the large language model prompt word into the large language model, and generating multiple JSON format objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON format object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled;
[0009] Step S2: Constructing a stateful communication protocol model corresponding to the stateful communication protocol text to be modeled based on all objects in JSON format, including:
[0010] Each JSON format object is regarded as a node, and a directed edge corresponding to the node is constructed based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint. The attribute of the node is constructed based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint; the second data packet is the data packet corresponding to the JSON format object, and the second data packet interaction behavior constraint is the constraint condition during the second data packet interaction;
[0011] Step S3: Based on the actual parameters of the scenario to be tested, instantiate the stateful communication protocol model to generate test cases.
[0012] Preferably, the step S1 of filtering redundant text of the stateful communication protocol text to be modeled includes:
[0013] Step S11: for the stateful communication protocol text to be modeled stored in the webpage, use a web crawler to crawl each text content; for the stateful communication protocol text to be modeled stored locally, use a parser of the corresponding format to parse the text content;
[0014] Step S12: establishing a keyword library, and filtering redundant texts of the stateful communication protocol text to be modeled based on the keyword library, to obtain several protocol specification items that must be followed and must not be followed in the stateful communication protocol text to be modeled.
[0015] Preferably, step S1 determines a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, inputs the large language model prompt word into the large language model, and generates multiple JSON format objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON format object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled, including:
[0016] Step S13: Determine a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, wherein the large language model prompt word is a five-tuple including an instruction, a definition of an output JSON format object, a conversion rule, a conversion example, and a protocol specification entry; the conversion rule includes a conversion parameter, a data packet name, and an enumeration type of a protocol behavior;
[0017] The definition of the output JSON format object includes the format definition of the parameter type of the output JSON format object and the format definition of the protocol data packet interaction behavior of the output JSON format object; the conversion parameters include the first data packet name, the first parameter, the first attribute and the first constraint, and the first constraint includes the first data packet interaction behavior constraint and the first attribute constraint; the first data packet name, the first parameter, the first attribute and the first constraint are respectively the data packet name, parameter, attribute and constraint specified in the protocol specification entry; the first data packet is the data packet specified in the protocol specification entry;
[0018] Step S14: inputting the large language model prompt words into the open source large language model; generating multiple objects in JSON format to be verified corresponding to the filtered stateful communication protocol text to be modeled;
[0019] Step S15: Verify the objects in the JSON format to be verified. If all the objects in the JSON format to be verified pass the verification, then use each object in the JSON format to be verified as the filtered object in the JSON format corresponding to the stateful communication protocol text to be modeled; if there are objects in the JSON format to be verified that fail the verification, iterate the open source large language model and enter step S14.
[0020] Preferably, the format definition of the protocol data packet interaction behavior of the output JSON format object specifies five JSON keys, which are the operation object name, the second data packet name, the second parameter, the second attribute, and the second constraint;
[0021] The operation object name indicates the operation object of the second data packet; the second data packet has the same content as the first data packet;
[0022] The second data packet name corresponds to the first data packet name and is a data packet name specified in the protocol specification item;
[0023] The second parameter corresponds to the first parameter and is a parameter specified in the protocol specification item, i.e., a data packet field of the second data packet;
[0024] The second attribute corresponds to the first attribute and is an attribute specified in the protocol specification item, indicating that the attribute is subject to attribute constraints;
[0025] The second constraint corresponds to the first constraint. The second constraint includes a second data packet interaction behavior constraint and a second attribute constraint. The second data packet interaction behavior constraint is a constraint condition for the second data packet interaction. The second attribute constraint is a constraint on the value of the attribute of the second data packet.
[0026] Preferably, step S2, constructing a directed edge corresponding to the node based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint, and constructing the attribute of the node based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint, includes:
[0027] Step S21: Classify the node according to the functional type of the data packets sent by the node, construct an interaction paradigm, determine the number of data packets corresponding to the node and the working stage corresponding to the node based on the interaction paradigm; determine the data packet interaction type based on the number of data packets, and determine the protocol behavior based on the working stage; when the number of data packets is one, the data packet interaction type is single data packet interaction; when the number of data packets is greater than one, the data packet interaction type is multi-data packet interaction; the interaction paradigm includes a model for determining the number of data packets corresponding to the node and a model for determining the working stage corresponding to the node;
[0028] Step S22: When the data packet interaction type is multi-data packet interaction, a directed edge is added to the node based on each data packet. The adding method is as follows: determining the sending sequence of the data packet, and based on the sending sequence, when the node is determined to be the output node, querying the corresponding node based on the second data packet name and the operation object name corresponding to the data packet as the input node, and establishing a directed edge pointing to the input node between the output node and the input node; adding attribute information to the directed edge based on the protocol behavior corresponding to the output node and the second data packet interaction behavior constraint corresponding to the data packet;
[0029] When the data packet interaction type is single data packet interaction, the properties of the node are constructed based on the second property and the second property constraint of the JSON format object corresponding to the node.
[0030] A method for testing based on a stateful communication protocol model, using the method for generating test cases as described above, includes:
[0031] Step S4: obtaining a stateful communication protocol text to be modeled, and generating a test case based on the stateful communication protocol model corresponding to the stateful communication protocol text to be modeled and actual data of the test scenario;
[0032] Step S5: Perform testing using test cases.
[0033] A method and apparatus for generating test cases based on a stateful communication protocol model, comprising:
[0034] A conversion module is configured to filter redundant text of the stateful communication protocol text to be modeled, determine a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, input the large language model prompt word into the large language model, and generate a plurality of JSON formatted objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON formatted object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled;
[0035] Model generation module: This module is configured to build a stateful communication protocol model corresponding to the stateful communication protocol text to be modeled based on all JSON format objects, including:
[0036] Each JSON format object is regarded as a node, and a directed edge corresponding to the node is constructed based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint. The attribute of the node is constructed based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint; the second data packet is the data packet corresponding to the JSON format object, and the second data packet interaction behavior constraint is the constraint condition during the second data packet interaction;
[0037] Test case generation module: configured to instantiate the stateful communication protocol model to generate test cases based on the actual parameters of the scenario to be tested.
[0038] A device for testing based on a stateful communication protocol model, the device using the method for generating test cases as described above, comprising:
[0039] Instantiation module: configured to obtain a stateful communication protocol text to be modeled, and generate a test case based on the stateful communication protocol model corresponding to the stateful communication protocol text to be modeled and actual data of the test scenario;
[0040] Test module: Configured for testing using test cases.
[0041] The present invention provides a computer-readable storage medium, wherein a plurality of instructions are stored in the storage medium; the plurality of instructions are used for a processor to load and execute the method described above.
[0042] The present invention provides an electronic device, characterized in that the electronic device includes:
[0043] A processor, which is used to execute multiple instructions;
[0044] A memory for storing a plurality of instructions;
[0045] The plurality of instructions are used to be stored by the memory and loaded and executed by the processor to implement the method as described above.
[0046] Beneficial effects:
[0047] This paper generates a stateful communication protocol model based on the stateful protocol specification. This model and the specific stateful communication protocol to be tested are then used to generate test cases. Testers then verify the stateful protocol's compliance with the standard based on the test scenario, detecting potential compatibility issues, performance bottlenecks, and security vulnerabilities. Furthermore, the stateful communication protocol model helps the testing team understand the complexity and details of the stateful communication protocol, enabling more effective identification of blind spots in testing, improving test coverage and accuracy, and ensuring the stable and secure operation of the resulting communication system. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 A flow chart of a method for generating test cases based on a stateful communication protocol model according to the present invention;
[0049] Figure 2 A schematic diagram of the architecture for constructing a stateful communication protocol model for the present invention;
[0050] Figure 3 A schematic diagram of the process of constructing a stateful communication protocol model for the present invention;
[0051] Figure 4 A schematic diagram of filtering redundant text from a modeled stateful communication protocol text according to the present invention;
[0052] Figure 5 This is a schematic diagram of converting the stateful communication protocol text to be modeled after filtering out redundant text into JSON format in the present invention;
[0053] Figure 6 This is a schematic diagram of the structure of the device for generating test cases based on a stateful communication protocol model according to the present invention. DETAILED DESCRIPTION
[0054] The present invention is described in detail below with reference to the accompanying drawings and embodiments.
[0055] like Figure 1-Figure 3 As shown, the present invention proposes a method for generating test cases based on a stateful communication protocol model, the method comprising:
[0056] Step S1: filtering redundant text of the stateful communication protocol text to be modeled, determining a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, inputting the large language model prompt word into the large language model, and generating multiple JSON format objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON format object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled;
[0057] Step S2: Constructing a stateful communication protocol model corresponding to the stateful communication protocol text to be modeled based on all objects in JSON format, including:
[0058] Each JSON format object is regarded as a node, and a directed edge corresponding to the node is constructed based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint. The attribute of the node is constructed based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint; the second data packet is the data packet corresponding to the JSON format object, and the second data packet interaction behavior constraint is the constraint condition during the second data packet interaction;
[0059] Step S3: Based on the actual parameters of the scenario to be tested, instantiate the stateful communication protocol model to generate test cases.
[0060] like Figure 4-Figure 5 As shown in FIG. 1 , the step S1 of filtering redundant text of the stateful communication protocol text to be modeled includes:
[0061] Step S11: for the stateful communication protocol text to be modeled stored in the webpage, use a web crawler to crawl each text content; for the stateful communication protocol text to be modeled stored locally, use a parser of the corresponding format to parse the text content;
[0062] Step S12: establishing a keyword library, and filtering redundant texts of the stateful communication protocol text to be modeled based on the keyword library, to obtain several protocol specification items that must be followed and must not be followed in the stateful communication protocol text to be modeled.
[0063] The step S1 determines a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, inputs the large language model prompt word into the large language model, and generates multiple JSON format objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON format object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled, including:
[0064] Step S13: Determine a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, wherein the large language model prompt word is a five-tuple including an instruction, a definition of an output JSON format object, a conversion rule, a conversion example, and a protocol specification entry; the conversion rule includes a conversion parameter, a data packet name, and an enumeration type of a protocol behavior;
[0065] The definition of the output JSON format object includes the format definition of the parameter type of the output JSON format object and the format definition of the protocol data packet interaction behavior of the output JSON format object; the conversion parameters include the first data packet name, the first parameter, the first attribute and the first constraint, and the first constraint includes the first data packet interaction behavior constraint and the first attribute constraint; the first data packet name, the first parameter, the first attribute and the first constraint are respectively the data packet name, parameter, attribute and constraint specified in the protocol specification entry; the first data packet is the data packet specified in the protocol specification entry;
[0066] Step S14: inputting the large language model prompt words into the open source large language model; generating multiple objects in JSON format to be verified corresponding to the filtered stateful communication protocol text to be modeled;
[0067] Step S15: Verify the objects in the JSON format to be verified. If all the objects in the JSON format to be verified pass the verification, then use each object in the JSON format to be verified as the filtered object in the JSON format corresponding to the stateful communication protocol text to be modeled; if there are objects in the JSON format to be verified that fail the verification, iterate the open source large language model and enter step S14.
[0068] Furthermore, the format definition of the protocol data packet interaction behavior of the output JSON format object specifies five JSON keys, which are the operation object name, the second data packet name, the second parameter, the second attribute, and the second constraint;
[0069] The operation object name indicates the operation object of the second data packet; the second data packet has the same content as the first data packet;
[0070] For example, the operation object is a server or a client.
[0071] The second data packet name corresponds to the first data packet name and is a data packet name specified in the protocol specification item;
[0072] The second parameter corresponds to the first parameter and is a parameter specified in the protocol specification item, i.e., a data packet field of the second data packet;
[0073] The second attribute corresponds to the first attribute and is an attribute specified in the protocol specification item, indicating that the attribute is subject to attribute constraints;
[0074] The second constraint corresponds to the first constraint. The second constraint includes a second data packet interaction behavior constraint and a second attribute constraint. The second data packet interaction behavior constraint is a constraint condition for the second data packet interaction. The second attribute constraint is a constraint on the value of the attribute of the second data packet.
[0075] For example, the enumeration types corresponding to the second attribute include "Value," "Length," and "Status." Value indicates that the value is subject to attribute constraints, Length indicates that the field length is subject to attribute constraints, and Status indicates that the status is subject to attribute constraints. When the value is subject to attribute constraints, the second attribute constraint is used to restrict the value range.
[0076] Step S2, constructing a directed edge corresponding to the node based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint, and constructing the attribute of the node based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint, includes:
[0077] Step S21: Classify the node according to the functional type of the data packet sent by the node, construct an interaction paradigm, and determine the number of data packets corresponding to the node and the working stage corresponding to the node based on the interaction paradigm; determine the data packet interaction type based on the number of data packets, and determine the protocol behavior based on the working stage; when the number of data packets is one, the data packet interaction type is single data packet interaction, and when the number of data packets is greater than one, the data packet interaction type is multi-data packet interaction; the interaction paradigm includes a model for determining the number of data packets corresponding to the node and a model for determining the working stage corresponding to the node.
[0078] For example, the MQTT protocol includes CONNECT and CONNACK packets for establishing a connection, and PUBLISH and PUBACK packets for publishing messages. Based on the protocol specifications, a coarse-grained interaction paradigm is created. This interaction paradigm consists of two sub-models: a model that determines the number of packets corresponding to a node and a model that determines the working phase of a node.
[0079] Step S22: When the data packet interaction type is multi-data packet interaction, a directed edge is added to the node based on each data packet. The adding method is as follows: determining the sending sequence of the data packet, and based on the sending sequence, when the node is determined to be the output node, querying the corresponding node based on the second data packet name and the operation object name corresponding to the data packet as the input node, and establishing a directed edge pointing to the input node between the output node and the input node; adding attribute information to the directed edge based on the protocol behavior corresponding to the output node and the second data packet interaction behavior constraint corresponding to the data packet;
[0080] When the data packet interaction type is single data packet interaction, the properties of the node are constructed based on the second property and the second property constraint of the JSON format object corresponding to the node.
[0081] In the present invention, protocol behaviors include connection and authentication, for example.
[0082] For example, a single-packet field constraint in the MQTT v5 protocol specification states: "Topic Names and Topic Filters are UTF-8 Encoded Strings; they MUST NOT encode to more than 65,535 bytes." This specification applies to the Topic field of the PUBLISH packet during the MQTT v5 message publishing phase. For example, a multi-packet interaction constraint in the MQTT v5 protocol specification states: "APUBACK packet MUST contain the same Packet Identifier as the PUBLISH packet that was originally sent." This specification applies to both the PUBLISH and PUBACK packets during the MQTT v5 message publishing phase.
[0083] The present invention also provides a method for testing based on a stateful communication protocol model, which uses the method for generating test cases as described above, including:
[0084] Step S4: obtaining a stateful communication protocol text to be modeled, and generating a test case based on the stateful communication protocol model corresponding to the stateful communication protocol text to be modeled and actual data of the test scenario;
[0085] Step S5: Perform testing using test cases.
[0086] like Figure 6 As shown, the present invention also provides a device for generating test cases based on a stateful communication protocol model, the device comprising:
[0087] A conversion module is configured to filter redundant text of the stateful communication protocol text to be modeled, determine a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, input the large language model prompt word into the large language model, and generate a plurality of JSON formatted objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON formatted object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled;
[0088] Model generation module: This module is configured to build a stateful communication protocol model corresponding to the stateful communication protocol text to be modeled based on all JSON format objects, including:
[0089] Each JSON format object is regarded as a node, and a directed edge corresponding to the node is constructed based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint. The attribute of the node is constructed based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint; the second data packet is the data packet corresponding to the JSON format object, and the second data packet interaction behavior constraint is the constraint condition during the second data packet interaction;
[0090] Test case generation module: configured to instantiate the stateful communication protocol model to generate test cases based on the actual parameters of the scenario to be tested.
[0091] The present invention also provides a device for testing based on a stateful communication protocol model, which uses the method for generating test cases as described above, including:
[0092] Instantiation module: configured to obtain a stateful communication protocol text to be modeled, and generate a test case based on the stateful communication protocol model corresponding to the stateful communication protocol text to be modeled and actual data of the test scenario;
[0093] Test module: Configured for testing using test cases.
[0094] The above specific embodiments merely illustrate the design principles of the present invention. The shapes and names of the components described herein may vary and are not limiting. Therefore, those skilled in the art may modify or substitute equivalents for the technical solutions described in the above embodiments. Such modifications and substitutions, without departing from the inventive spirit and technical solutions of the present invention, shall fall within the scope of protection of the present invention.
Claims
1. A method for generating test cases based on a stateful communication protocol model, characterized in that: include: Step S1: filtering redundant text of the stateful communication protocol text to be modeled, determining a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, inputting the large language model prompt word into the large language model, and generating multiple JSON format objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON format object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled; Step S2: Constructing a stateful communication protocol model corresponding to the stateful communication protocol text to be modeled based on all objects in JSON format, including: Each JSON format object is regarded as a node, and a directed edge corresponding to the node is constructed based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint. The attribute of the node is constructed based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint; the second data packet is the data packet corresponding to the JSON format object, and the second data packet interaction behavior constraint is the constraint condition during the second data packet interaction; Step S3: Based on the actual parameters of the scenario to be tested, instantiate the stateful communication protocol model to generate test cases.
2. The method according to claim 1, wherein The step S1, filtering redundant text of the stateful communication protocol text to be modeled, includes: Step S11: for the stateful communication protocol text to be modeled stored in the webpage, use a web crawler to crawl each text content; for the stateful communication protocol text to be modeled stored locally, use a parser of the corresponding format to parse the text content; Step S12: establishing a keyword library, and filtering redundant texts of the stateful communication protocol text to be modeled based on the keyword library, to obtain several protocol specification items that must be followed and must not be followed in the stateful communication protocol text to be modeled.
3. The method according to any one of claims 1 to 2, wherein The step S1 determines a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, inputs the large language model prompt word into the large language model, and generates multiple JSON format objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON format object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled, including: Step S13: Determine a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, wherein the large language model prompt word is a five-tuple including an instruction, a definition of an output JSON format object, a conversion rule, a conversion example, and a protocol specification entry; the conversion rule includes a conversion parameter, a data packet name, and an enumeration type of a protocol behavior; The definition of the output JSON format object includes the format definition of the parameter type of the output JSON format object and the format definition of the protocol data packet interaction behavior of the output JSON format object; the conversion parameters include the first data packet name, the first parameter, the first attribute and the first constraint, and the first constraint includes the first data packet interaction behavior constraint and the first attribute constraint; the first data packet name, the first parameter, the first attribute and the first constraint are respectively the data packet name, parameter, attribute and constraint specified in the protocol specification entry; the first data packet is the data packet specified in the protocol specification entry; Step S14: inputting the large language model prompt words into the open source large language model; generating multiple objects in JSON format to be verified corresponding to the filtered stateful communication protocol text to be modeled; Step S15: Verify the objects in the JSON format to be verified. If all the objects in the JSON format to be verified pass the verification, then use each object in the JSON format to be verified as the filtered object in the JSON format corresponding to the stateful communication protocol text to be modeled; if there are objects in the JSON format to be verified that fail the verification, iterate the open source large language model and enter step S14.
4. The method according to claim 3, wherein The format definition of the protocol data packet interaction behavior of the output JSON format object specifies five JSON keys, which are the operation object name, the second data packet name, the second parameter, the second attribute, and the second constraint; The operation object name indicates the operation object of the second data packet; the second data packet has the same content as the first data packet; The second data packet name corresponds to the first data packet name and is a data packet name specified in the protocol specification item; The second parameter corresponds to the first parameter and is a parameter specified in the protocol specification item, i.e., a data packet field of the second data packet; The second attribute corresponds to the first attribute and is an attribute specified in the protocol specification item, indicating that the attribute is subject to attribute constraints; The second constraint corresponds to the first constraint. The second constraint includes a second data packet interaction behavior constraint and a second attribute constraint. The second data packet interaction behavior constraint is a constraint condition for the second data packet interaction. The second attribute constraint is a constraint on the value of the attribute of the second data packet.
5. The method according to claim 4, wherein Step S2, constructing a directed edge corresponding to the node based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint, and constructing the attribute of the node based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint, includes: Step S21: Classify the node according to the functional type of the data packets sent by the node, construct an interaction paradigm, determine the number of data packets corresponding to the node and the working stage corresponding to the node based on the interaction paradigm; determine the data packet interaction type based on the number of data packets, and determine the protocol behavior based on the working stage; when the number of data packets is one, the data packet interaction type is single data packet interaction; when the number of data packets is greater than one, the data packet interaction type is multi-data packet interaction; the interaction paradigm includes a model for determining the number of data packets corresponding to the node and a model for determining the working stage corresponding to the node; Step S22: When the data packet interaction type is multi-data packet interaction, a directed edge is added to the node based on each data packet. The adding method is as follows: determining the sending sequence of the data packet, and based on the sending sequence, when the node is determined to be the output node, querying the corresponding node based on the second data packet name and the operation object name corresponding to the data packet as the input node, and establishing a directed edge pointing to the input node between the output node and the input node; adding attribute information to the directed edge based on the protocol behavior corresponding to the output node and the second data packet interaction behavior constraint corresponding to the data packet; When the data packet interaction type is single data packet interaction, the properties of the node are constructed based on the second property and the second property constraint of the JSON format object corresponding to the node.
6. A method for testing based on a stateful communication protocol model, the method using the method for generating test cases according to any one of claims 1 to 5, characterized in that: include: Step S4: obtaining a stateful communication protocol text to be modeled, and generating a test case based on the stateful communication protocol model corresponding to the stateful communication protocol text to be modeled and actual data of the test scenario; Step S5: Perform testing using test cases.
7. A device for generating test cases based on a stateful communication protocol model, characterized in that: include: A conversion module is configured to filter redundant text of the stateful communication protocol text to be modeled, determine a large language model prompt word corresponding to the filtered stateful communication protocol text to be modeled, input the large language model prompt word into the large language model, and generate a plurality of JSON formatted objects corresponding to the filtered stateful communication protocol text to be modeled, wherein each JSON formatted object corresponds to a protocol specification entry in the filtered stateful communication protocol text to be modeled; Model generation module: This module is configured to build a stateful communication protocol model corresponding to the stateful communication protocol text to be modeled based on all JSON format objects, including: Each JSON format object is regarded as a node, and a directed edge corresponding to the node is constructed based on the data packet interaction type of the data packet sent by the node, the protocol behavior corresponding to the node, and the second data packet interaction behavior constraint. The attribute of the node is constructed based on the second attribute of the JSON format object corresponding to the node and the second attribute constraint; the second data packet is the data packet corresponding to the JSON format object, and the second data packet interaction behavior constraint is the constraint condition during the second data packet interaction; Test case generation module: configured to instantiate the stateful communication protocol model to generate test cases based on the actual parameters of the scenario to be tested.
8. A device for testing based on a stateful communication protocol model, the device using the method for generating test cases according to any one of claims 1 to 5, characterized in that: include: Instantiation module: configured to obtain a stateful communication protocol text to be modeled, and generate a test case based on the stateful communication protocol model corresponding to the stateful communication protocol text to be modeled and actual data of the test scenario; Test module: Configured for testing using test cases.
9. A computer-readable storage medium, characterized in that The storage medium stores a plurality of instructions; the plurality of instructions are used by a processor to load and execute the method according to any one of claims 1 to 6.
10. An electronic device, characterized in that: The electronic device comprises: A processor, which is used to execute multiple instructions; A memory for storing a plurality of instructions; The plurality of instructions are used to be stored in the memory and loaded and executed by the processor according to any one of claims 1 to 6.