Database testing method and device based on protocol layer interaction, equipment and medium

By generating and parameterizing SQL statements and combining them with session states to generate protocol test cases, the problem of existing database testing methods being unable to dynamically interact with and perceive SQL semantics is solved, achieving comprehensive coverage of database protocols and defect detection.

CN122285496APending Publication Date: 2026-06-26BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIHANG UNIV
Filing Date
2026-03-16
Publication Date
2026-06-26

Smart Images

  • Figure CN122285496A_ABST
    Figure CN122285496A_ABST
Patent Text Reader

Abstract

This invention provides a database testing method, apparatus, electronic device, and storage medium based on protocol layer interaction. It generates test SQL statements, performs parameterization to form parameter placeholder structures, and extracts parameter constraint information. Based on the parameter placeholder structures, parameter constraint information, and the current session state, it generates protocol test cases, sequentially sends multiple protocol data packets, receives and parses response data packets returned by the database system, records communication error information during response reading, and updates the current session state based on the parsing results of the response data packets. When the communication error information is detected during response reading, if a crash occurs or the verification results are inconsistent, an error report is generated. This invention can cover protocol processing paths under different execution stages and interaction sequences, reduce invalid requests with semantically invalid or easily rejected requests, improve the validity of test input, and enhance the coverage depth and defect detection capability of database protocol testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database testing technology, and in particular to a database testing method, apparatus, electronic device, and storage medium based on protocol layer interaction. Background Technology

[0002] As a core component of information systems, the security and stability of database systems are of paramount importance. To discover potential defects in database systems, existing technologies mainly fall into three categories: The first category is script-based database protocol auditing testing schemes. These schemes pre-configure database tasks and scripts, control the number and rate of execution to generate protocol data, and then compare and verify it with audit results. The protocol request content, sequence, and interaction methods of this scheme are all predetermined by the task configuration, lacking the ability to dynamically generate and adjust protocol interactions based on database responses and session states, and failing to cover protocol processing paths under complex session states and boundary conditions. The second category is SQL-generation-based database fuzzing testing schemes. These schemes dynamically acquire database states to generate SQL query sequences that conform to the current database schema, and use code coverage as feedback to guide the generation and variation of SQL statements. This scheme uses SQL statements as the core test object, while the protocol requests and responses during database communication are handled by the client. The first type is automated testing, where the client cannot directly control or mutate the request content, field encoding, and interaction sequence of the protocol layer during testing. This makes it difficult to access the implementation details of the database in the protocol processing stages such as request parsing, parameter passing, and result return. The second type is general protocol fuzzing testing schemes, such as the open-source tool BooFuzz. This scheme manually defines the protocol message format and mutates the fields, sends malformed messages to the target under test, and listens for abnormal responses. When testing database systems, this scheme does not combine the database's unique SQL execution semantics and session state information to generate protocol requests. There is a lack of effective correlation between the protocol messages and the current execution context of the database. Many messages are semantically or state-wise invalid and are easily rejected by the database in the early stages. This makes it difficult to fully cover the protocol processing paths related to statement lifecycle, session state evolution, and complex interactions. Summary of the Invention

[0003] This invention provides a database testing method, apparatus, electronic device, and storage medium based on protocol layer interaction, which solves the shortcomings of traditional database testing methods. Script-based solutions lack dynamic protocol interaction capabilities, SQL-based solutions cannot control protocol layer details, and general protocol fuzz testing lacks awareness of SQL semantics and session states, resulting in difficulty in fully covering content related to protocol state evolution.

[0004] This invention provides a database testing method based on protocol layer interaction, comprising: Generate test SQL statements, and parameterize the test SQL statements to form parameter placeholder structures, and extract parameter constraint information; Based on the parameter placeholder structure, the parameter constraint information, and the current session state, protocol test cases are generated, which are multiple protocol data packets arranged in chronological order. The system sends the multiple protocol data packets to the database system in sequence, receives and parses the response data packets returned by the database system, records communication error information during the response reading process, and updates the current session state based on the parsing result of the response data packets. The expected response to the protocol request is determined based on the preset database protocol specification and the current session state. When the communication abnormality information is detected during the response reading process, the database system is further checked to see if it has crashed. If no crash occurs, the actual response will be checked for consistency with the expected response. If a crash occurs or the verification results are inconsistent, an error report will be generated.

[0005] According to the database testing method based on protocol layer interaction provided by the present invention, the steps of generating test SQL statements, parameterizing the test SQL statements to form parameter placeholder structures, and extracting parameter constraint information include: Initialize the SQL seed pool and populate it with a randomized SQL seed pool. Select a seed from the SQL seed pool, mutate it, and generate a test SQL statement; Replace the variable constants, expressions, or predicate conditions in the test SQL statement with placeholders to form a parameter placeholder structure; Extract the number and type of parameters corresponding to the placeholders, and use them as the parameter constraint information.

[0006] According to the database testing method based on protocol layer interaction provided by the present invention, the step of generating protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state includes: The parameter placeholder structure, the parameter constraint information, and the current session state are associated to construct a generation context; Based on the generation context, the type, timing relationship, and field values ​​of the protocol data packets in the protocol test cases to be generated are determined, and a sequence of protocol data packets matching the generation context is generated as the protocol test cases.

[0007] According to the database testing method based on protocol layer interaction provided by the present invention, the generation of protocol test cases further includes: A protocol test case seed pool is constructed based on multiple protocol test cases. Protocol test cases are selected from the protocol test case seed pool and mutated to generate new protocol test cases. The mutations include field-level mutations and / or timing mutations, wherein the field-level mutations are used to mutate the flag field, control field, parameter type field, or parameter value field in the protocol data packet, and the timing mutations are used to perform insertion, deletion, replacement, or rearrangement operations on the protocol data packet sequence.

[0008] The database testing method based on protocol layer interaction provided by the present invention further includes: For the same SQL statement, maintain the coverage corresponding to the SQL statement; After a single protocol test case is executed, the code coverage generated during the execution of the single protocol test case is obtained, and the code coverage is compared with the coverage corresponding to the SQL statement. If the code coverage is higher than the coverage corresponding to the SQL statement, then the single protocol test case is added to the protocol test case seed pool, and the coverage corresponding to the SQL statement is updated using the code coverage. After the batch of protocol test cases corresponding to the SQL statement are executed, the code coverage generated during the execution of the batch of protocol test cases is obtained, and the code coverage is compared with the global coverage. If the code coverage is higher than the global coverage, then update the global coverage and add the SQL seed corresponding to the SQL statement to the SQL seed pool.

[0009] According to the database testing method based on protocol layer interaction provided by the present invention, updating the current session state based on the parsing result of the response data packet includes: Parse the response data packet to identify its type and key field information; Based on the type and key field information of the response data packet, determine the state changes related to protocol interaction in the current session; the state changes include at least one of the following: When the response data packet indicates that the preprocessor statement was created successfully, the identifier of the newly created preprocessor statement and its corresponding parameter information are recorded; When the response packet indicates that the preprocessing statement has been executed successfully, the preprocessing statement is confirmed to be in a valid state for subsequent protocol test case generation. When a response data packet indicates that the creation or execution of a preprocessing statement has failed, the corresponding failure information is recorded to adjust the subsequent test case generation strategy. When the response data packet indicates that the preprocessed statement was released successfully, the corresponding preprocessed statement that has been recorded is marked as invalid. When the response packet indicates a change in session connection status, user identity information, or session variables, the corresponding session status change is determined based on the status indication information in the response packet. Based on the determined state changes, update the maintained current session state record.

[0010] According to the database testing method based on protocol layer interaction provided by the present invention, the step of generating an error report if a crash or inconsistent verification results occur includes: Based on the preprocessed statement identifier and validity status maintained in the current session state, and in conjunction with the preset database protocol specification, determine the expected response type and expected response content corresponding to the currently sent protocol request. Receive the actual response data packet returned by the database system and detect whether any communication abnormalities occur during the response reading process; When the communication anomaly is detected, the system further checks whether the database system has crashed; if the database system crash is detected, the crash information is recorded and an error report is generated. When no database system crash is detected, the actual response data packet is parsed to obtain the actual response type and actual response content; The actual response type is compared with the expected response type, and the actual response content is compared with the expected response content. When the actual response type is inconsistent with the expected response type, or when the actual response content is inconsistent with the expected response content, the response is determined to be abnormal, and an error report is generated.

[0011] The present invention also provides a database testing apparatus, comprising: The SQL generation module is used to generate test SQL statements, parameterize the test SQL statements to form a parameter placeholder structure, and extract parameter constraint information. The protocol test case generation module is used to generate protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state. The protocol test cases are multiple protocol data packets arranged in chronological order. The update module is used to send the multiple protocol data packets to the database system in sequence, receive and parse the response data packets returned by the database system, record communication error information during the response reading process, and update the current session state based on the parsing result of the response data packets. The error detection module is used to determine the expected response to the protocol request based on the preset database protocol specification and the current session state, and to detect whether the database system has crashed when a communication abnormality is detected; if no database system crash is detected, the actual response is checked for consistency with the expected response; and an error report is generated when a database system crash is detected or the actual response is found to be inconsistent with the expected response.

[0012] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the database testing method based on protocol layer interaction as described in any of the preceding claims.

[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the database testing method based on protocol layer interaction as described above.

[0014] This invention provides a database testing method, apparatus, electronic device, and storage medium based on protocol layer interaction. The method generates test SQL statements, parameterizes these statements to form parameter placeholder structures, and extracts parameter constraint information. Based on the parameter placeholder structures, parameter constraint information, and the current session state, protocol test cases are generated, consisting of multiple protocol data packets arranged in chronological order. These protocol data packets are sent sequentially to a database system. The system receives and parses response data packets returned by the database system, recording communication error information during response reading and updating the current session state based on the parsing results of the response data packets. The expected response to the protocol request is determined according to a preset database protocol specification and the current session state. When communication error information is detected during response reading, the system further checks whether the database system has crashed. If no crash occurs, the actual response is checked for consistency with the expected response. If a crash occurs or the check result is inconsistent, an error report is generated. The data packet sequence formed during database protocol interaction serves as the basic unit of the test case. During execution, the system parses responses and updates the session state to drive the dynamic construction of subsequent protocol requests, thereby covering protocol processing paths under different execution stages and interaction sequences. By parameterizing test SQL statements to extract parameter placeholder structures and parameter constraint information, the dependency relationship between SQL semantics and protocol interaction is characterized. Based on this, the fields and timing of protocol requests are constrained, reducing a large number of invalid requests that are semantically invalid and easily rejected early, thus improving the validity of test input. This allows the testing process to be carried out collaboratively in two dimensions: SQL generation and protocol request generation. This further covers the database protocol processing path associated with SQL execution. Based on protocol specifications, session states, and SQL semantic constraints, response expectations are determined and consistency checks are performed. This can detect anomalies such as crashes and timeouts, as well as identify semantic problems such as missing termination packets, mismatched metadata entries, mismatched response types, and invalid preprocessing statements still returning success. This improves the coverage depth and defect detection capability of database protocol testing. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0016] Figure 1 This is a flowchart of a database testing method based on protocol layer interaction provided in an embodiment of the present invention; Figure 2 This is an example diagram of the SQL statement generation process provided in an embodiment of the present invention; Figure 3 This is an example diagram of the protocol test case generation process provided in an embodiment of the present invention; Figure 4 This is an example diagram of the protocol test case execution flow provided in an embodiment of the present invention; Figure 5 This is an example diagram of the response data packet verification and anomaly determination process based on response expectation provided in an embodiment of the present invention; Figure 6 This is one of the functional structure diagrams of the database testing device provided in the embodiments of the present invention; Figure 7 This is the second functional structure diagram of the database testing device provided in the embodiments of the present invention; Figure 8 This is a functional structure diagram of the electronic device provided in the embodiments of the present invention. Detailed Implementation

[0017] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0018] Figure 1 A flowchart of a database testing method based on protocol layer interaction provided in an embodiment of the present invention is shown below. Figure 1 As shown, the database testing method based on protocol layer interaction provided in this embodiment of the invention includes: Step 101: Generate a test SQL statement, and parameterize the test SQL statement to form a parameter placeholder structure, and extract parameter constraint information; Step 102: Based on the parameter placeholder structure, the parameter constraint information, and the current session state, generate protocol test cases, wherein the protocol test cases are multiple protocol data packets arranged in chronological order; Step 103: Send the multiple protocol data packets to the database system in sequence, receive and parse the response data packets returned by the database system, record communication error information during the response reading process, and update the current session state based on the parsing result of the response data packets; Step 104: Determine the expected response to the protocol request based on the preset database protocol specification and the current session state. If the communication abnormality information is detected during the response reading process, further check whether the database system has crashed. If no crash occurs, verify the consistency between the actual response and the expected response. If a crash occurs or the verification result is inconsistent, generate an error report.

[0019] Traditional database testing methods, such as script-based solutions, lack dynamic protocol interaction capabilities, SQL-based solutions cannot control protocol layer details, and general protocol fuzz testing lacks awareness of SQL semantics and session states, making it difficult to fully cover content related to protocol state evolution.

[0020] The database testing method based on protocol layer interaction provided in this invention uses the data packet sequence formed during database protocol interaction as the basic unit of test cases. During execution, it parses responses and updates session states to drive the dynamic construction of subsequent protocol requests, thereby covering protocol processing paths under different execution stages and interaction sequences. By parameterizing test SQL statements to extract parameter placeholder structures and parameter constraint information, it characterizes the dependency relationship between SQL semantics and protocol interaction, and constrains the fields and timing of protocol requests accordingly. This reduces a large number of semantically invalid requests that are easily rejected early, improving the validity of test input. The testing process can be carried out collaboratively in both SQL generation and protocol request generation dimensions, further covering the database protocol processing paths associated with SQL execution. Furthermore, based on protocol specifications, session states, and SQL semantic constraints, it determines response expectations and performs consistency checks. This can detect anomalies such as crashes and timeouts, as well as semantic problems such as missing termination packets, mismatched metadata entries, mismatched response types, and invalid preprocessing statements still returning success, thereby improving the coverage depth and defect detection capability of database protocol testing.

[0021] Based on any of the above embodiments, the step of generating a test SQL statement, parameterizing the test SQL statement to form a parameter placeholder structure, and extracting parameter constraint information includes: Step 201: Initialize the SQL seed pool by randomly generating the SQL seed pool. Step 202: Select a seed from the SQL seed pool for mutation to generate a test SQL statement; Step 203: Replace the variable constants, expressions, or predicate conditions in the test SQL statement with placeholders to form a parameter placeholder structure; Step 204: Extract the number of parameters and parameter types corresponding to the placeholders, as the parameter constraint information.

[0022] like Figure 2As shown, the SQL statement generator internally maintains an SQL seed pool and global coverage information. The SQL seed pool is initially empty and filled randomly. Each SQL seed is a binary sequence associated with a priority. When generating test SQL statements, the SQL statement generator first selects the highest priority seed from the SQL seed pool, mutates it to generate a new binary sequence, and maps this binary sequence to a test SQL statement. Subsequently, the test SQL statement is parameterized to form a parameter placeholder structure. This parameterization process replaces variable constants, expressions, or predicate conditions in the SQL statement with placeholders, resulting in a parameterized statement. After parameterization, the SQL statement generator extracts the number of parameters and parameter type constraints corresponding to the SQL statement. The parameter type constraints describe the acceptable data type range, length constraints, and other necessary semantic constraints for each placeholder parameter. Finally, the SQL statement generator sends the parameterized SQL statement and its parameter number and parameter type constraints to the protocol test case generator to construct the generation context for protocol test cases. After the protocol test cases are executed, the coverage collector returns the summary results of code coverage collected during the execution of one round of protocol test cases corresponding to the SQL statement. The SQL statement generator compares the summary results of coverage with its maintained global coverage. When a coverage improvement is detected, the global coverage is updated and the corresponding SQL seed is added to the SQL seed pool for subsequent mutation and generation. When no coverage improvement is detected, the corresponding SQL seed is discarded.

[0023] Based on any of the above embodiments, the step of generating protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state includes: Step 301: Associate the parameter placeholder structure, the parameter constraint information, and the current session state to construct a generation context; Step 302: Based on the generation context, determine the type, timing relationship and field values ​​of the protocol data packets in the protocol test cases to be generated, and generate a protocol data packet sequence that matches the generation context as the protocol test cases.

[0024] like Figure 3As shown, the protocol test case generator receives parameterized SQL statements, parameter counts, and parameter type constraints from the SQL statement generator, and obtains the current session state to construct a generation context. The generation context includes the parameterized SQL statements, their parameter counts and type constraints, the current session state, and necessary information related to connection interaction. This generation context serves as the basis for constructing the data packet sequence in the protocol test cases. The session state includes session-level state information related to the preprocessed statements, used to record the identifiers and parameter information of preprocessed statements that have been established or expired in the current session. Based on the generation context, the protocol test case generator generates a batch of protocol test cases.

[0025] The protocol test cases are sequential data packet sequences arranged in chronological order. Each protocol test case corresponds to a set of data packet sequences, which include preprocessing request data packets, execution request data packets, and data packets related to session state such as reset and close. When generating test cases, the protocol test case generator maintains a protocol test case seed pool, which is initially empty and then randomly generated based on the generation context to populate it.

[0026] In this embodiment of the invention, the generation of protocol test cases further includes: A protocol test case seed pool is constructed based on multiple protocol test cases. Protocol test cases are selected from the protocol test case seed pool and mutated to generate new protocol test cases. The mutations include field-level mutations and / or timing mutations, wherein the field-level mutations are used to mutate the flag field, control field, parameter type field, or parameter value field in the protocol data packet, and the timing mutations are used to perform insertion, deletion, replacement, or rearrangement operations on the protocol data packet sequence.

[0027] In this embodiment of the invention, the protocol test case generator selects the highest priority protocol test case from the protocol test case seed pool and mutates it under the constraints of the generation context to obtain new protocol test cases. The mutation includes field-level mutation and temporal mutation, wherein field-level mutation is used to mutate the flag field, control field, parameter type field, and parameter value field in the data packet, and temporal mutation is used to perform insertion, deletion, replacement, or rearrangement operations on the data packet sequence.

[0028] Based on any of the above embodiments, the database testing method based on protocol layer interaction further includes: Step 401: For the same SQL statement, maintain the coverage rate corresponding to the SQL statement; Step 402: After the execution of a single protocol test case is completed, obtain the code coverage generated during the execution of the single protocol test case, and compare the code coverage with the coverage corresponding to the SQL statement; Step 403: If the code coverage is higher than the coverage corresponding to the SQL statement, then add the single protocol test case to the protocol test case seed pool, and update the coverage corresponding to the SQL statement using the code coverage. Step 404: After the batch of protocol test cases corresponding to the SQL statement is executed, obtain the code coverage generated during the execution of the batch of protocol test cases, and compare the code coverage with the global coverage. Step 405: If the code coverage is higher than the global coverage, update the global coverage and add the SQL seed corresponding to the SQL statement to the SQL seed pool.

[0029] In this embodiment of the invention, after a single protocol test case is executed, the coverage collector collects the code coverage of the database system during the execution of the protocol test case and sends the coverage to the protocol test case generator. The protocol test case generator compares the coverage with its maintained SQL statement coverage. When an improvement in coverage is detected, the corresponding protocol test case is added to the protocol test case seed pool and the SQL statement coverage is updated. When no improvement in coverage is detected, the corresponding protocol test case is discarded.

[0030] In this embodiment of the invention, after the protocol test case is executed, the coverage collector returns the summary result of the code coverage collected during the execution of one round of protocol test cases corresponding to the SQL statement. The SQL statement generator compares the summary result of the coverage with its maintained global coverage. When a coverage improvement is detected, the global coverage is updated and the corresponding SQL seed is added to the SQL seed pool for subsequent mutation and generation. When no coverage improvement is detected, the corresponding SQL seed is discarded.

[0031] Based on any of the above embodiments, updating the current session state according to the parsing result of the response data packet includes: Step 501: Parse the response data packet to identify the type and key field information of the response data packet; Step 502: Based on the type and key field information of the response data packet, determine the state changes related to protocol interaction in the current session; the state changes include at least one of the following: When the response data packet indicates that the preprocessor statement was created successfully, the identifier of the newly created preprocessor statement and its corresponding parameter information are recorded; When the response packet indicates that the preprocessing statement has been executed successfully, the preprocessing statement is confirmed to be in a valid state for subsequent protocol test case generation. When a response data packet indicates that the creation or execution of a preprocessing statement has failed, the corresponding failure information is recorded to adjust the subsequent test case generation strategy. When the response data packet indicates that the preprocessed statement was released successfully, the corresponding preprocessed statement that has been recorded is marked as invalid. When the response packet indicates a change in session connection status, user identity information, or session variables, the corresponding session status change is determined based on the status indication information in the response packet. Step 503: Based on the determined state change, update the maintained current session state record.

[0032] like Figure 4 As shown, the protocol test case executor receives protocol test cases output by the protocol test case generator. Each protocol test case corresponds to a set of data packet sequences arranged in chronological order. During execution, the protocol test case executor sends the data packet sequences from the protocol test cases in chronological order and synchronously receives response data packets returned by the database system. The executor parses the received response data packets, including identifying the response data packet type, parsing key fields and necessary metadata, and identifying the boundaries and termination conditions of the response sequence. After parsing the response data packets, the current session state is updated according to the response results. The session state is used to maintain state information related to protocol interaction in the current session, including recording, updating, or clearing protocol-related states such as preprocessing statements involved in the session based on the response results. During execution, the protocol test case executor records abnormal read events such as read timeouts and connection disconnections. The response data packets and the recorded abnormal events are sent together to the error detector.

[0033] Based on any of the above embodiments, the step of generating an error report if a crash or inconsistent verification results occur includes: Step 601: Based on the preprocessed statement identifier and validity status maintained in the current session state, and in conjunction with the preset database protocol specification, determine the expected response type and expected response content corresponding to the currently sent protocol request; Step 602: Receive the actual response data packet returned by the database system, and detect whether any communication abnormalities occur during the response reading process; Step 603: When the communication anomaly is detected, further detect whether the database system has crashed; if the database system crash is detected, record the crash information and generate an error report; Step 604: When no database system crash is detected, parse the actual response data packet to obtain the actual response type and actual response content; Step 605: Compare the actual response type with the expected response type, and compare the actual response content with the expected response content; Step 606: When the actual response type is inconsistent with the expected response type, or the actual response content is inconsistent with the expected response content, it is determined to be a response anomaly, and an error report is generated.

[0034] like Figure 5 As shown, the error detector receives the response data and its parsing results, as well as abnormal read events, output by the protocol test case executor, and determines the expected response to the request based on the current session state. When a communication anomaly such as read timeout or connection loss is received, the error detector records the communication anomaly and checks whether the database system has crashed. If a crash occurs, it saves the protocol test case that triggered the problem and related information, and generates an error report. If no abnormal read event is received or no crash occurs, the response data packet is verified according to the database protocol specification. When an inconsistency is detected between the actual response and the expected response, it is determined to be a semantic problem. The inconsistency includes situations such as the response data packet type not matching the request type, the response sequence timing not conforming to the protocol specifications, whether the response terminates according to the protocol, and the response field values ​​or the number of metadata entries not meeting the protocol constraints, and initiating an execution request for an expired preprocessing statement but receiving a successful response, which are inconsistent with the session state. When a semantic problem is detected, the error detector saves the protocol test case that triggered the problem and related information, and generates an error report.

[0035] Based on any of the above embodiments, the database testing method based on protocol layer interaction provided by the embodiments of the present invention specifically includes: S1. The SQL statement generator randomly generates DDL (Data Definition Language) and DML (Data Manipulation Language) statements and sends them to the protocol test case executor. The protocol test case executor encapsulates the statements into protocol data packets and executes them to change the database system state. When the cumulative number of executed DDL and DML statements reaches a preset limit, the current database state is cleared and the database state is re-established.

[0036] S2. The SQL statement generator generates test SQL statements based on code coverage feedback. These statements are parameterized to form a parameter placeholder structure, and constraint information such as the number and type of parameters is extracted. The parameterized SQL statement and parameter constraint information are then sent to the protocol test case generator. The SQL statement generator maintains an SQL seed pool and global coverage. Each seed in the SQL seed pool is a binary sequence, initially empty and filled randomly. When generating test SQL statements, the highest priority seed is selected from the seed pool for mutation, and the mutated seed is mapped to an SQL statement. The test SQL statement is then parameterized to form a parameter placeholder structure, and constraint information such as the number and type of parameters is extracted and sent to the protocol test case generator. After the protocol test case corresponding to the SQL statement is executed, the system's code coverage during this round of test case execution is obtained from the coverage collector as the coverage of the SQL statement. This coverage is compared with the global coverage. If the coverage improves, the global coverage is updated, the corresponding seed is marked as interesting, and added to the SQL seed pool for subsequent mutation; otherwise, the seed is discarded.

[0037] S3. The protocol test case generator, using code coverage as feedback, generates a batch of protocol test cases based on the parameterized SQL statements, parameter constraint information, and the current session state, and sends them to the protocol test case executor. These protocol test cases are a sequence of data packets arranged in chronological order. The protocol test case generator receives the parameterized SQL statements and their parameter constraint information from the SQL statement generator, and constructs a generation context based on the current session state. Based on this generation context, it generates a batch of data packet sequences arranged in chronological order as a batch of protocol test cases and sends them to the protocol test case executor. The protocol test case generator maintains a protocol test case seed pool, which is initially empty and filled randomly based on the generation context. When generating protocol test cases, the highest priority protocol test case is selected from the seed pool, and mutated based on the generation context to obtain a new data packet sequence. For the same SQL statement, the protocol test case generator maintains the coverage corresponding to that SQL statement, initially empty. After a single protocol test case is executed, the coverage result is obtained from the coverage collector and compared with the maintained SQL statement coverage. If the SQL statement coverage is improved, the protocol test case is determined to be interesting and added to the protocol test case seed pool for subsequent mutation, and the SQL statement coverage statistics are updated.

[0038] S4. The protocol test case executor sends the generated protocol test cases to the database system for execution, obtains and parses the response data packets returned by the database system, and records abnormal read events such as read timeout and connection disconnection during the response reading process. Based on the response parsing results, it updates the current session state and sends the response data packets and recorded abnormal read events to the error detector. Specifically, the protocol test case executor sends the data packet sequence in the protocol test cases sequentially and receives the response data packets returned by the database system. It parses the response data packets according to the database protocol specification and updates the current session state based on the response parsing results. The session state includes status information related to preprocessing statements. During the response data packet reading process, it records abnormal read events such as read timeout and connection disconnection, and sends the response data packets and recorded abnormal events to the error detector.

[0039] S5. The error detector, based on the database protocol specification and the current session state, determines the expected response to the protocol request and verifies the response data packet returned by the database system. Simultaneously, it detects communication anomalies such as read timeouts and connection drops. When the actual response is found to be inconsistent with the expected response, or when a database system crash is detected due to a communication anomaly, an error report is generated and the test case is saved. Specifically, the error detector receives the response data sent by the protocol test case executor and determines the expected response to the protocol request based on the database protocol specification and the current session state. During the response reading process, if a read timeout or connection drop occurs, it checks whether the database system has crashed. If a database system crash is detected, the crash information is recorded. When no communication anomaly occurs or no database system crash is detected, the response data packet returned by the database system is verified. If the actual response is found to be inconsistent with the expected response, it is determined to be a semantic problem. When a semantic problem is detected or a database system crash is detected, the test case is saved and an error report is generated.

[0040] S6. The coverage collector gathers the database system code coverage after the execution of this round of test cases and sends the code coverage to the SQL statement generator and the protocol test case generator to guide test case generation and mutation. The coverage collector collects the database system code coverage after test case execution and sends it to the SQL statement generator and the protocol test case generator respectively. The coverage sent to the SQL statement generator is the sum of the code coverage after the execution of a batch of protocol test cases corresponding to the same SQL statement; the coverage sent to the protocol test case generator is the code coverage after the execution of a single protocol test case. The SQL statement generator and the protocol test case generator determine whether the seeds for generating test cases are interesting based on the coverage growth and update the seed pool for subsequent generation and mutation.

[0041] S7. Repeat steps S1 to S6.

[0042] The database testing method based on protocol layer interaction provided in this invention uses the data packet sequence formed during database protocol interaction as the basic unit of test cases. During testing, protocol requests are dynamically constructed around changes in the database protocol state. The protocol test cases are not limited to a single type of protocol data packet, but are composed of multiple database protocol requests combined in sequence. These data packets include protocol requests carrying SQL execution semantics, as well as control-type protocol requests that drive and reflect the session interaction process. By continuously parsing the protocol responses returned by the database during interaction execution and using this to advance the generation of subsequent protocol requests, test cases can cover the processing paths of the database protocol at different execution stages, different interaction sequences, and boundary conditions. By parameterizing the generated SQL statements and replacing variable parameters in the SQL statements, a parameterized SQL structure and corresponding parameter constraint information are obtained. This information is used to characterize the dependency relationship between the SQL statement and the database protocol interaction. When constructing protocol requests, the SQL-related content in the protocol requests is constrained according to the dependency relationship, ensuring that the generated protocol requests maintain a consistent association with the corresponding SQL statements. Building upon this foundation, multiple protocol interaction sequences associated with the execution process of a single SQL statement are constructed. This allows the testing process to proceed collaboratively across two dimensions: SQL generation and protocol request generation, thereby further covering the database protocol processing path associated with SQL execution. During test execution, the protocol responses returned by the database are parsed, and the expected response for each protocol interaction is determined by combining protocol specification requirements, the current session state, and the SQL semantic constraints related to the request. By verifying the consistency between the actual response and the expected response, it is determined whether the database response meets the protocol specification requirements and the current state and semantic constraints. This identifies abnormal responses or state inconsistencies during the protocol interaction process, enabling the testing process to discover potential problems that violate the protocol interaction agreement but do not lead to abnormal database termination, and improving the detection coverage of complex database protocol interaction scenarios.

[0043] The database testing apparatus provided by the present invention will be described below. The database testing apparatus described below can be referred to in correspondence with the database testing method based on protocol layer interaction described above.

[0044] Figure 6 A functional structure diagram of the database testing device provided in the embodiments of the present invention is shown below. Figure 6 As shown, the database testing apparatus provided in this embodiment of the invention includes: SQL generation module 601 is used to generate test SQL statements, perform parameterization processing on the test SQL statements to form parameter placeholder structures, and extract parameter constraint information. The protocol test case generation module 602 is used to generate protocol test cases based on the parameter placeholder structure, the parameter constraint information and the current session state. The protocol test cases are multiple protocol data packets arranged in chronological order. The update module 603 is used to send the multiple protocol data packets to the database system in sequence, receive and parse the response data packets returned by the database system, record communication error information during the response reading process, and update the current session state based on the parsing result of the response data packets. The error detection module 604 is used to determine the expected response to the protocol request based on the preset database protocol specification and the current session state, and to detect whether the database system has crashed when a communication abnormality is detected; if no database system crash is detected, the actual response is checked for consistency with the expected response; and an error report is generated when a database system crash is detected or the actual response is found to be inconsistent with the expected response.

[0045] like Figure 7 As shown, the database testing device provided in this embodiment of the invention mainly consists of an SQL statement generator, a protocol test case generator, a protocol test case executor, an error detector, a coverage collector, and a database system. The SQL statement generator generates DDL / DML and test SQL statements, performs parameterization on the SQL statements to extract constraint information such as the number and type of parameters, and uses code coverage as feedback to guide the generation and variation of test SQL statements. The protocol test case generator combines parameterized SQL, parameter constraint information, and session state to generate a time-ordered sequence of data packets, and uses code coverage as feedback to guide the generation and variation of test cases. The protocol test case executor sends data packets sequentially and receives and parses the database system response, records abnormal read events such as read timeouts and connection disconnections, and updates the session state. The error detector determines the expected response to the protocol request based on the database protocol specification and the current session state, verifies the response data packets returned by the database system, and generates an error report and saves the test cases when the response is inconsistent with the expected response or when the database system crashes. The coverage collector collects the code coverage of the current execution round and feeds it back to the SQL statement generator and the protocol test case generator to update the seed pool and guide subsequent tests.

[0046] The database testing device provided in this invention uses the data packet sequence formed during database protocol interaction as the basic unit of test cases. During execution, it parses responses and updates session states to drive the dynamic construction of subsequent protocol requests, thereby covering protocol processing paths under different execution stages and interaction sequences. By parameterizing test SQL statements to extract parameter placeholder structures and parameter constraint information, it characterizes the dependency relationship between SQL semantics and protocol interaction, and constrains the fields and timing of protocol requests accordingly. This reduces a large number of semantically invalid requests that are easily rejected early, improving the validity of test input. The testing process can be carried out collaboratively in both SQL generation and protocol request generation dimensions, further covering the database protocol processing paths associated with SQL execution. Furthermore, based on protocol specifications, session states, and SQL semantic constraints, it determines response expectations and performs consistency checks. This can detect anomalies such as crashes and timeouts, and also identify semantic problems such as missing termination packets, mismatched metadata entries, mismatched response types, and invalid preprocessing statements still returning success, thereby improving the coverage depth and defect detection capability of database protocol testing.

[0047] Figure 8 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other through the communication bus 840. The memory 830 includes a computer program, an operating system, and acquired data. The processor 810 can call logical instructions in the memory 830 to execute a database testing method based on protocol layer interaction. This method includes: generating test SQL statements, parameterizing the test SQL statements to form a parameter placeholder structure, and extracting parameter constraint information; generating protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state, wherein the protocol test cases are multiple protocol data packets arranged in chronological order; sequentially sending the multiple protocol data packets to the database system, receiving and parsing the response data packets returned by the database system, and recording communication error information during the response reading process, while updating the current session state based on the parsing result of the response data packets; determining the expected response to the protocol request according to the preset database protocol specification and the current session state; when the communication error information is detected during the response reading process, further detecting whether the database system has crashed; if no crash occurs, performing a consistency check between the actual response and the expected response; if a crash occurs or the check result is inconsistent, generating an error report.

[0048] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to related technologies, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0049] On the other hand, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements a database testing method based on protocol layer interaction provided by the above methods. The method includes: generating test SQL statements, parameterizing the test SQL statements to form a parameter placeholder structure, and extracting parameter constraint information; generating protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state, wherein the protocol test cases are multiple protocol data packets arranged in chronological order; sequentially sending the multiple protocol data packets to a database system, receiving and parsing response data packets returned by the database system, and recording communication error information during the response reading process, while updating the current session state based on the parsing result of the response data packets; determining the expected response to the protocol request according to a preset database protocol specification and the current session state; when the communication error information is detected during the response reading process, further detecting whether the database system has crashed; if no crash occurs, performing a consistency check between the actual response and the expected response; if a crash occurs or the check result is inconsistent, generating an error report.

[0050] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0051] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of software products. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0052] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A database testing method based on protocol layer interaction, characterized in that, include: Generate test SQL statements, and parameterize the test SQL statements to form parameter placeholder structures, and extract parameter constraint information; Based on the parameter placeholder structure, the parameter constraint information, and the current session state, protocol test cases are generated, which are multiple protocol data packets arranged in chronological order. The system sends the multiple protocol data packets to the database system in sequence, receives and parses the response data packets returned by the database system, records communication error information during the response reading process, and updates the current session state based on the parsing result of the response data packets. The expected response to the protocol request is determined based on the preset database protocol specification and the current session state. When the communication abnormality information is detected during the response reading process, the database system is further checked to see if it has crashed. If no crash occurs, the actual response will be checked for consistency with the expected response. If a crash occurs or the verification results are inconsistent, an error report will be generated.

2. The database testing method based on protocol layer interaction according to claim 1, characterized in that, The process of generating test SQL statements, parameterizing the test SQL statements to form parameter placeholder structures, and extracting parameter constraint information includes: Initialize the SQL seed pool and populate it with a randomized SQL seed pool. Select a seed from the SQL seed pool, mutate it, and generate a test SQL statement; Replace the variable constants, expressions, or predicate conditions in the test SQL statement with placeholders to form a parameter placeholder structure; Extract the number and type of parameters corresponding to the placeholders, and use them as the parameter constraint information.

3. The database testing method based on protocol layer interaction according to claim 2, characterized in that, The process of generating protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state includes: The parameter placeholder structure, the parameter constraint information, and the current session state are associated to construct a generation context; Based on the generation context, the type, timing relationship, and field values ​​of the protocol data packets in the protocol test cases to be generated are determined, and a sequence of protocol data packets matching the generation context is generated as the protocol test cases.

4. The database testing method based on protocol layer interaction according to claim 3, characterized in that, The generated protocol test cases also include: A protocol test case seed pool is constructed based on multiple protocol test cases. Protocol test cases are selected from the protocol test case seed pool and mutated to generate new protocol test cases. The mutations include field-level mutations and / or timing mutations, wherein the field-level mutations are used to mutate the flag field, control field, parameter type field, or parameter value field in the protocol data packet, and the timing mutations are used to perform insertion, deletion, replacement, or rearrangement operations on the protocol data packet sequence.

5. The database testing method based on protocol layer interaction according to claim 4, characterized in that, Also includes: For the same SQL statement, maintain the coverage corresponding to the SQL statement; After a single protocol test case is executed, the code coverage generated during the execution of the single protocol test case is obtained, and the code coverage is compared with the coverage corresponding to the SQL statement. If the code coverage is higher than the coverage corresponding to the SQL statement, then the single protocol test case is added to the protocol test case seed pool, and the coverage corresponding to the SQL statement is updated using the code coverage. After the batch of protocol test cases corresponding to the SQL statement are executed, the code coverage generated during the execution of the batch of protocol test cases is obtained, and the code coverage is compared with the global coverage. If the code coverage is higher than the global coverage, then update the global coverage and add the SQL seed corresponding to the SQL statement to the SQL seed pool.

6. The database testing method based on protocol layer interaction according to claim 1, characterized in that, Updating the current session state based on the parsing result of the response data packet includes: Parse the response data packet to identify its type and key field information; Based on the type and key field information of the response data packet, determine the state changes related to protocol interaction in the current session; the state changes include at least one of the following: When the response data packet indicates that the preprocessor statement was created successfully, the identifier of the newly created preprocessor statement and its corresponding parameter information are recorded; When the response packet indicates that the preprocessing statement has been executed successfully, the preprocessing statement is confirmed to be in a valid state for subsequent protocol test case generation. When a response data packet indicates that the creation or execution of a preprocessing statement has failed, the corresponding failure information is recorded to adjust the subsequent test case generation strategy. When the response data packet indicates that the preprocessed statement was released successfully, the corresponding preprocessed statement that has been recorded is marked as invalid. When the response packet indicates a change in session connection status, user identity information, or session variables, the corresponding session status change is determined based on the status indication information in the response packet. Based on the determined state changes, update the maintained current session state record.

7. The database testing method based on protocol layer interaction according to claim 6, characterized in that, If a crash or inconsistent verification results occur, an error report will be generated, including: Based on the preprocessed statement identifier and validity status maintained in the current session state, and in conjunction with the preset database protocol specification, determine the expected response type and expected response content corresponding to the currently sent protocol request. Receive the actual response data packet returned by the database system and detect whether any communication abnormalities occur during the response reading process; When the communication anomaly is detected, the system further checks whether the database system has crashed; if the database system crash is detected, the crash information is recorded and an error report is generated. When no database system crash is detected, the actual response data packet is parsed to obtain the actual response type and actual response content; The actual response type is compared with the expected response type, and the actual response content is compared with the expected response content. When the actual response type is inconsistent with the expected response type, or when the actual response content is inconsistent with the expected response content, the response is determined to be abnormal, and an error report is generated.

8. A database testing device, characterized in that, include: The SQL generation module is used to generate test SQL statements, parameterize the test SQL statements to form a parameter placeholder structure, and extract parameter constraint information. The protocol test case generation module is used to generate protocol test cases based on the parameter placeholder structure, the parameter constraint information, and the current session state. The protocol test cases are multiple protocol data packets arranged in chronological order. The update module is used to send the multiple protocol data packets to the database system in sequence, receive and parse the response data packets returned by the database system, record communication error information during the response reading process, and update the current session state based on the parsing result of the response data packets. The error detection module is used to determine the expected response to the protocol request based on the preset database protocol specifications and the current session state, and to detect whether the database system has crashed when a communication abnormality is detected. If no database system crash is detected, the actual response is checked for consistency with the expected response. If a database system crash is detected or the actual response is found to be inconsistent with the expected response, an error report is generated.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the database testing method based on protocol layer interaction as described in any one of claims 1 to 7.

10. A non-transitory readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the database testing method based on protocol layer interaction as described in any one of claims 1 to 7.