A test method and related apparatus

CN116662141BActive Publication Date: 2026-08-11TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-17
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0004]但是,上述方式依赖系统源码,仅限于白盒测试,不能适用于无法获取系统源码的场景,测试方式存在局限性

Benefits of technology

[0027]由上述技术方案可以看出,根据待测试系统与其他系统之间的通信协议生成测试种子,使得该测试种子与实际情况更加匹配,测试种子的质量被提高,从而提高代码覆盖率。获取待测试系统与其他系统在通信过程中的实际报文,将实际报文的字段值作为测试种子赋值的依据,从而避免由于测试种子的字段值为零被待测试系统判定为无效数据。该实际报文与测试种子均包括至少一个字段,为了提高赋值的有效性,根据通信协议的协议格式解析测试种子和实际报文,得到第一字段集合和第二字段集合,若第一字段集合中的第一字段与第二字段集合中的第二字段满足相似条件,说明第一字段和第二字段之间具有较强的相关性,二者之间的数据具有互通性,故可以将该第二字段的字段值作为第一字段的字段值,进而生成测试报文,利用该测试报文对待测试系统进行测试。由此,在对待测试系统进行测试时,不再获取待测试系统的系统源码,而是根据通信协议生成测试报文进行测试,使其可以扩展至无法获取系统源码的场景,尤其是实际应用中难以获取实际报文的场景。同时,测试报文在测试开始之前被赋予有效值,减少试错时间且不会被待测试系统屏蔽,能够大概率绕过待测试系统一般判断无效数据的检查,能专注于待测试系统更深层次的处理逻辑检查,进一步提高代码覆盖率,提高实用性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116662141B_ABST
    Figure CN116662141B_ABST
Patent Text Reader

Abstract

This application discloses a testing method and related apparatus. A test seed is generated based on the communication protocol between the system under test and other systems. The field values ​​of the actual message are used as the basis for assigning the test seed value. The test seed and the actual message are parsed according to the protocol format of the communication protocol to obtain a first field set and a second field set. If the first field in the first field set and the second field in the second field set satisfy a similarity condition, it indicates a strong correlation between the first and second fields, and their data is interoperable. Therefore, the field value of the second field is used as the field value of the first field, thereby generating a test message. This test message is then used to test the system under test. Thus, when testing the system under test, the system source code of the system under test is no longer obtained; instead, a test message is generated based on the communication protocol for testing. This extends the method to scenarios where the system source code cannot be obtained, improving its practicality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a testing method and related apparatus. Background Technology

[0002] Fuzz testing (or fuzzing) is a software testing technique. Its core idea is to input automatically or semi-automatically generated random data into a program and detect program anomalies, such as crashes or assertion failures, to discover potential program errors, such as memory leaks. Fuzz testing can also detect security vulnerabilities in software or computer systems.

[0003] Code coverage is a metric in software testing that describes the proportion and extent to which source code in a program is tested; the resulting proportion is called code coverage ratio. Based on code coverage, untested areas in a program can be identified. To improve code coverage, related technologies involve obtaining the system source code from the system under test, filtering out key functions that can improve execution coverage and potentially vulnerable functions that might cause program crashes, and increasing the likelihood of execution from the current execution point to the key target functions to improve code coverage.

[0004] However, the above methods rely on the system source code and are limited to white-box testing. They cannot be applied to scenarios where the system source code cannot be obtained, and the testing methods have limitations. Summary of the Invention

[0005] To address the aforementioned technical issues, this application provides a testing method and related apparatus, which not only improves code coverage but also expands the applicable scenarios and enhances practicality.

[0006] The embodiments of this application disclose the following technical solutions:

[0007] On the one hand, the embodiments of this application provide

[0008] On the other hand, embodiments of this application provide a testing method, the method comprising:

[0009] A test seed is generated based on the communication protocol between the system under test and other systems, including at least one field, wherein the field value of the test seed is zero;

[0010] Obtain the actual messages between the system under test and the other systems during the communication process, wherein the actual messages include at least one field;

[0011] The test seed is parsed according to the protocol format of the communication protocol to obtain a first set of fields; the actual message is parsed according to the protocol format of the communication protocol to obtain a second set of fields.

[0012] If the first field in the first field set and the second field in the second field set meet the similarity condition, the field value of the second field is used as the field value of the first field;

[0013] Generate a test message based on the value of the first field;

[0014] The system under test is tested according to the test message.

[0015] On the other hand, embodiments of this application provide a testing device, characterized in that the device includes: a generation unit, an acquisition unit, a parsing unit, an assignment unit, and a testing unit;

[0016] The generation unit is used to generate a test seed including at least one field according to the communication protocol between the system under test and other systems, wherein the field value of the test seed is zero;

[0017] The acquisition unit is used to acquire the actual messages between the system under test and the other systems during the communication process, and the actual messages include at least one field.

[0018] The parsing unit is used to parse the test seed according to the protocol format of the communication protocol to obtain a first set of fields, and to parse the actual message according to the protocol format of the communication protocol to obtain a second set of fields.

[0019] The assignment unit is used to assign the field value of the second field as the field value of the first field if the first field in the first field set and the second field in the second field set satisfy a similarity condition.

[0020] The generation unit is further configured to generate a test message based on the field value of the first field;

[0021] The testing unit is used to test the system under test according to the test message.

[0022] On the other hand, embodiments of this application provide a computer device, the device including a processor and a memory:

[0023] The memory is used to store program code and transmit the program code to the processor;

[0024] The processor is configured to execute the methods described above according to instructions in the program code.

[0025] On the other hand, embodiments of this application provide a computer-readable storage medium for storing a computer program for performing the methods described above.

[0026] On the other hand, embodiments of this application provide a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods described above.

[0027] As can be seen from the above technical solution, generating test seeds based on the communication protocol between the system under test and other systems makes the test seeds more closely match the actual situation, improving the quality of the test seeds and thus increasing code coverage. The actual messages during the communication process between the system under test and other systems are obtained, and the field values ​​of the actual messages are used as the basis for assigning test seed values, thus avoiding the system under test judging the test seed as invalid data due to a field value of zero. Both the actual messages and the test seeds include at least one field. To improve the effectiveness of the assignment, the test seeds and actual messages are parsed according to the protocol format of the communication protocol to obtain a first field set and a second field set. If the first field in the first field set and the second field in the second field set satisfy similarity conditions, it indicates a strong correlation between the first and second fields, and their data is interoperable. Therefore, the field value of the second field can be used as the field value of the first field to generate a test message, which is then used to test the system under test. Therefore, when testing the system under test, the source code is no longer obtained. Instead, test messages are generated based on the communication protocol, extending the testing scope to scenarios where the source code is unavailable, especially in real-world applications where obtaining the actual messages is difficult. Furthermore, the test messages are assigned valid values ​​before testing begins, reducing trial-and-error time and preventing them from being blocked by the system under test. This significantly bypasses the system's usual checks for invalid data, allowing the focus to be placed on deeper processing logic checks, further improving code coverage and usability. Attached Figure Description

[0028] To more clearly illustrate the technical solutions in the embodiments of this application 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 only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0029] Figure 1 This is a schematic diagram illustrating an application scenario of a testing method provided in an embodiment of this application;

[0030] Figure 2A flowchart of a testing method provided in an embodiment of this application;

[0031] Figure 3 A schematic diagram illustrating the construction of a seed set provided in an embodiment of this application;

[0032] Figure 4 A schematic diagram illustrating the generation of a mutated test message provided in an embodiment of this application;

[0033] Figure 5 This is a schematic diagram illustrating an application scenario of a testing method provided in an embodiment of this application;

[0034] Figure 6 This is a schematic diagram of the structure of a testing device provided in an embodiment of this application;

[0035] Figure 7 This is a schematic diagram of the server structure provided in an embodiment of this application;

[0036] Figure 8 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Detailed Implementation

[0037] The embodiments of this application will now be described with reference to the accompanying drawings.

[0038] Given that related technologies, in order to improve code coverage, impose relatively strict limitations and applicable scenarios on testing methods, such as white-box testing based on system source code analysis or relying on system feedback to optimize test messages, these testing methods have limitations and poor versatility. Therefore, this application provides a testing method that not only improves code coverage but also expands applicable scenarios and enhances practicality.

[0039] The testing method provided in this application can be applied to testing equipment with data processing capabilities, such as terminal devices and servers. The server involved in this application can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. Terminal devices can be smartphones, tablets, laptops, desktop computers, intelligent voice interaction devices (such as smart speakers), smart home appliances (such as smart TVs), in-vehicle terminals, etc., but are not limited to these. Terminal devices and servers can be directly or indirectly connected via wired or wireless communication, and this application does not impose any restrictions on this connection.

[0040] To facilitate understanding of the technical solution of this application, the following is combined with... Figure 1 Taking a server as an example of the aforementioned testing device, the testing method provided in this application embodiment will be described.

[0041] The system under test and other systems described in this application can be deployed on servers or terminal devices, and there are no specific restrictions on the deployment form. For example, both the system under test and other systems can be deployed on a server. Another example is that the system under test is deployed on a server, and the other systems are deployed on terminal devices as clients. The client can run on the terminal device through a browser, or it can run on the terminal device as a standalone application (APP), etc. The specific presentation form of the client is not limited here.

[0042] See Figure 1 This figure is a schematic diagram of an application scenario for a testing method provided in an embodiment of this application. As shown in the figure, the system to be tested is deployed on server 100, and other systems are deployed on terminal device 200.

[0043] Server 100 and terminal device 200 communicate via a network, and they share a communication protocol. Server 100 generates test seeds according to this protocol. Test seeds generated according to the protocol are more closely matched to actual situations, and can subsequently generate all types of test messages, covering scenarios where it is difficult to obtain actual messages in real-world applications. This improves the quality of test seeds and thus increases code coverage.

[0044] Since the field value of the test seed is zero, in order to avoid the test seed being rejected by the system under test as invalid data, the process of assigning a value to the test seed will be explained below.

[0045] The actual messages between server 100 and terminal device 200 during communication are obtained. The field values ​​of these actual messages generally have practical meaning. These field values ​​are used as the basis for assigning test seeds, thus avoiding invalid data being judged by the system under test due to a test seed field value of zero. Both the actual message and the test seed include at least one field. To improve the effectiveness of the assignment, the test seed and the actual message are parsed according to the protocol format of the communication protocol to obtain a first set of fields and a second set of fields. For example, the first set of fields is {ActivityID, GoodsID, GoodsNum}, representing the activity identifier, reward item identifier, and reward item quantity, respectively. The second set of fields is {ActivitySeq, BeginTime, Endtime}, representing the activity identifier, activity start time, and activity end time, respectively.

[0046] The following explanation uses ActivityID as the first field. If ActivityID and ActivitySeq (the second field) in the second field set meet similarity conditions, it indicates a strong correlation between the first and second fields, and their data is interoperable. The field value of ActivitySeq can be assigned to ActivityID, and then GoodsID can be assigned as the first field until all fields included in all test seeds have been assigned, resulting in a test message. The field values ​​of this test message are not zero. By testing the system under test based on the test message, it is possible to bypass the general invalid data check of the system under test with a high probability, thereby focusing on the deeper processing logic check of the system under test and further improving code coverage.

[0047] Therefore, when testing the system under test, the source code is no longer obtained. Instead, test messages are generated based on the communication protocol, extending the testing scope to scenarios where the source code is unavailable, especially in real-world applications where obtaining the actual messages is difficult. Furthermore, the test messages are assigned valid values ​​before testing begins, reducing trial-and-error time and preventing them from being blocked by the system under test. This significantly bypasses the system's usual checks for invalid data, allowing the focus to be placed on deeper processing logic checks, further improving code coverage and usability.

[0048] The following description, with reference to the accompanying drawings, uses the example of the system under test being deployed on a server to illustrate a testing method provided in this application.

[0049] See Figure 2 This figure is a flowchart of a testing method provided in an embodiment of this application. Figure 2 As shown, the testing method includes the following steps:

[0050] S201: Generate a test seed including at least one field based on the communication protocol between the system under test and other systems.

[0051] The system under test (SUBST) is the system that needs to be tested, while other systems are those capable of communicating with it. The SUBST communicates with other systems according to a communication protocol. A communication protocol refers to the rules and agreements that must be followed by both entities to complete communication or provide services. For multiple data communication systems in different geographical locations interconnected through communication channels and devices to work collaboratively and achieve information exchange and resource sharing, they must share a common language. What is exchanged, how it is exchanged, and when it is exchanged must all follow mutually acceptable rules; these rules constitute the communication protocol.

[0052] Test seeds are generated based on the communication protocols between the system under test and other systems, enabling subsequent testing of the system under test. Therefore, this application does not require obtaining the system source code of the system under test; that is, the testing method provided in this application is not limited to scenarios where only the system source code can be obtained. Furthermore, the test seeds generated based on the communication protocols can generate all types of test seeds, covering many scenarios where the system under test interacts with other systems, especially in scenarios where it is difficult to obtain actual messages in practical applications, thus expanding the applicability of the testing method provided in this application. Moreover, the test seeds are more closely matched to actual situations, improving their quality and ensuring that the subsequently generated test messages conform to reality, increasing the pass rate of test messages, and consequently improving the testing efficiency and code coverage of the system under test when testing the test messages.

[0053] The test seed is the foundational data for generating test messages. Subsequent test cases are constructed and modified based on this seed. It includes at least one field, such as a field representing an activity identifier or a field representing a reward item identifier. Furthermore, each field in the test seed has a value of zero, meaning no values ​​have been assigned, resulting in low-quality test seeds. If an unassigned test seed is input into the system under test, it is meaningless data. Generally, the system will reject unassigned test seeds, causing the test to fail from the outset and resulting in minimal improvement in code coverage. Without a clear direction, aimless fuzzy testing cannot effectively discover system vulnerabilities.

[0054] Based on this, the process of assigning values ​​to the test seed will be explained below.

[0055] S202: Obtain the actual messages during the communication process between the system under test and other systems.

[0056] Obtain the actual messages of the system under test during communication with other systems. Since the actual messages generally have practical meaning and are more likely not invalid data, the field values ​​of the actual messages are used as the basis for assigning test seeds. This allows the test seeds to be assigned relatively meaningful values, thereby avoiding the test seeds being judged as invalid data by the system under test due to a field value of zero. This has a significant benefit on code coverage.

[0057] Understandably, a typical message usually includes one or more fields, and different fields may have different field types, such as numeric, string, byte, and array types.

[0058] The embodiments of this application do not specifically limit the order of S201 and S202; they can be executed simultaneously or sequentially.

[0059] S203: Parse the test seed according to the protocol format of the communication protocol to obtain the first set of fields, and parse the actual message according to the protocol format of the communication protocol to obtain the second set of fields.

[0060] Since both the actual message and the test seed include at least one field, the field values ​​corresponding to different field types may differ. For example, the field value for a numeric type is purely numeric, while the field value for a string type is a mixture of numbers and letters. To improve the effectiveness of the assignment, the test seed and the actual message are parsed according to the protocol format of the communication protocol. The protocol format of the communication protocol clearly defines the composition of the test seed and the actual message, thus dividing the test seed and the actual message into multiple fields, ensuring that all fields within a field are of the same type, resulting in a first field set and a second field set.

[0061] For example, a test seed can be parsed into one or more basic fields, where each basic field is the smallest unit of a field and cannot be further subdivided. For instance, a test seed for obtaining rewards in a game system is parsed according to the communication protocol format, resulting in the first set of fields: {ActivityID, GoodsID, GoodsNum}, representing the activity identifier, reward item identifier, and reward item quantity, respectively. Similarly, the actual message is parsed into one or more basic fields according to the communication protocol format. For example, parsing the actual message obtained when a player purchases goods in the store yields the second set of fields: {Price, BuyGoodsID, BuyGoodsNum}, representing the price, store item identifier, and store item quantity, respectively. As another example, parsing the actual message corresponding to activity date information yields the second set of fields: {ActivitySeq, BeginTime, Endtime}, representing the activity identifier, activity start time, and activity end time, respectively.

[0062] It should be noted that since there can be many actual messages, one or more fields obtained from parsing each actual message can be put into the second field set, so that the second field set includes as many fields as possible, so as to provide strong support for assigning values ​​to more test seed fields later.

[0063] S204: If the first field in the first field set and the second field in the second field set satisfy the similarity condition, the field value of the second field shall be used as the field value of the first field.

[0064] The first set of fields includes one or more fields, such as the first field, and the second set of fields includes one or more fields, such as the second field.

[0065] If the first field and the second field meet the similarity condition, it means that there is a strong correlation between the first field and the second field, and the data between the two is interoperable. Therefore, the field value of the second field can be assigned to the first field to generate a test message.

[0066] One possible implementation is to use field type and field name similarity as similarity criteria. Specifically, if the field type of the first field is the same as that of the second field, and the matching degree between the field names of the first field and the second field is greater than a preset threshold, then the first field and the second field meet the similarity criteria. Thus, under the premise that the field types are the same, the field value corresponding to the string type will not be used as the field value corresponding to the numeric type, further improving the effectiveness of field assignment. Moreover, fields with more similar names are more likely to represent the same content. For test seeds generated according to communication protocols, if it is difficult to obtain the corresponding actual message in real-world applications, assigning values ​​based on similar messages covers more test scenarios.

[0067] Those skilled in the art can set a preset threshold according to the actual situation, such as 70%, and this application does not make a specific limitation in this regard. It should be noted that, through experiments, it has been found that setting the preset threshold to 70% can ensure code coverage while expanding the applicable scenarios.

[0068] Continuing with the example described in S203, by comparison, ActivityID and ActivitySeq, GoodsID and BuyGoodsID, and GoodsNum and BuyGoodsNum meet the similarity condition. Therefore, the field value of ActivitySeq can be assigned to ActivityID, the field value of BuyGoodsID can be assigned to GoodsID, and the field value of BuyGoodsNum can be assigned to GoodsNum.

[0069] As one possible approach, when calculating the similarity of field names, the FuzzyWuzzy fuzzy string matching toolkit can be used. This toolkit is based on the Levenshtein distance algorithm and can effectively calculate the differences between strings.

[0070] S205: Generate a test message based on the field value of the first field.

[0071] If the test seed only includes the first field, then the assignment of the test seed is complete, generating a test message for that test seed. If the test seed includes multiple fields, each field can be used as the first field to obtain a field value. Values ​​are then assigned to each field in the set of first fields. Once all fields included in the test seed have corresponding field values, the assignment of the test seed is complete, generating a test message corresponding to that test seed. As one possible implementation, multiple test messages corresponding to the test seed can also be generated when one field corresponds to multiple field values. This will be explained later through S2051 and S2052, and will not be elaborated upon here.

[0072] S206: Test the system under test according to the test message.

[0073] Therefore, by generating test seeds through communication protocols, black-box fuzzing testing can be achieved without obtaining the system source code of the system under test. By assigning valid values ​​to the test seeds and generating test messages, the test messages can be driven to process the relevant logic of the system under test with a high probability, thereby improving code coverage and reducing the risk of exposing vulnerabilities.

[0074] As can be seen from the above technical solution, generating test seeds based on the communication protocol between the system under test and other systems makes the test seeds more closely match the actual situation, improving the quality of the test seeds and thus increasing code coverage. The actual messages during the communication process between the system under test and other systems are obtained, and the field values ​​of the actual messages are used as the basis for assigning test seed values, thus avoiding the system under test judging the test seed as invalid data due to a field value of zero. Both the actual messages and the test seeds include at least one field. To improve the effectiveness of the assignment, the test seeds and actual messages are parsed according to the protocol format of the communication protocol to obtain a first field set and a second field set. If the first field in the first field set and the second field in the second field set satisfy similarity conditions, it indicates a strong correlation between the first and second fields, and their data is interoperable. Therefore, the field value of the second field can be used as the field value of the first field to generate a test message, which is then used to test the system under test. Therefore, when testing the system under test, the source code is no longer obtained. Instead, test messages are generated based on the communication protocol, extending the testing scope to scenarios where the source code is unavailable, especially in real-world applications where obtaining the actual messages is difficult. Furthermore, the test messages are assigned valid values ​​before testing begins, reducing trial-and-error time and preventing them from being blocked by the system under test. This significantly bypasses the system's usual checks for invalid data, allowing the focus to be placed on deeper processing logic checks, further improving code coverage and usability.

[0075] As one possible implementation, if the second field set includes multiple fields, the second field set can be iterated through, and each field in the second field set can be compared with the first field to obtain multiple similar fields that satisfy the similarity condition with the first field. A set of field values ​​for the first field can then be constructed, and the field values ​​of the similar fields can be added to this set. It should be noted that the second field can be a similar field to the first field, and the field value of the second field can be one of the field values ​​in the first field's set.

[0076] Furthermore, if the test seed includes multiple fields, such as m fields, where m is an integer greater than 1, for example, the test seed includes 3 fields. This application embodiment provides a specific implementation method for S205, which is generating a test message based on the field value of the first field, specifically including S2051-S2052.

[0077] S2051: Obtain a field value from the set of m field values ​​corresponding to each of the m fields, and get the m field values ​​corresponding to the m fields.

[0078] By constructing the set of field values ​​for the first field, we can construct the set of field values ​​for each of the m fields. Thus, each field included in the test seed has a corresponding value. By permuting and combining these values, we can obtain multiple test messages and generate a seed set for that test seed.

[0079] S2052: Arrange the m field values ​​corresponding to the m fields according to the order of the m fields to generate a test message.

[0080] It should be noted that the m fields included in the test seed have an order relationship, that is, the order in which the m fields are arranged. In order to generate a test message that meets the test requirements, the m field values ​​can be arranged according to the order in which the m fields are arranged. At this time, all m fields included in the test seed have corresponding field values, and a test message that meets the test requirements is generated.

[0081] Since the set of m field values ​​corresponding to each of the m fields can include multiple field values—for example, the field value corresponding to the ActivityID field can be {1002, 1003, 1004}, etc.—the set of field values ​​corresponding to the ActivityID field can include {1002, 1003, 1004}, etc., according to S2051, obtaining one field value from each of the m field value sets corresponding to the m fields yields multiple different combinations. Each combination includes m field values. Then, according to S2052, the m field values ​​are arranged according to the order of the multiple sets of m fields to generate multiple test messages, thus obtaining the seed set for this test seed. The following section combines... Figure 3 Please provide an explanation.

[0082] See Figure 3 This figure is a schematic diagram of constructing a seed set according to an embodiment of this application. The test seed includes m fields, each of which has a corresponding set of field values. If the set of field values ​​corresponding to field 1 includes P1 values, the set of field values ​​corresponding to field 2 includes P2 values, ..., and the set of field values ​​corresponding to field m includes Pm values, by obtaining a field value from the set of field values ​​corresponding to each of the m fields, and arranging and combining the obtained m field values ​​according to the order of the m fields included in the test seed, a seed set for the test seed is obtained. The seed set includes P1*P2*...*Pm test messages.

[0083] In related technologies, fuzzing involves counting the number of times each program block is executed. In each fuzzing test, the dynamic weight of each program block is obtained based on the count. Seeds in a seed bank are then scored based on both static and dynamic weights, and selected seeds are mutated; the higher the seed score, the higher the probability of selection. However, this method requires the testing system to provide feedback on the number of times each program block is executed, using this data to score the test seeds and adjust the probability of selecting them. This method only saves testing time and does not improve system code coverage, thus its effectiveness is limited.

[0084] Based on this, the present application provides an S206, which is a specific implementation method for testing the system under test according to the test message, specifically including S2061-S2063.

[0085] S2061: Obtain multiple test messages corresponding to the test seed.

[0086] For example, you can obtain the seed set corresponding to the test seed, which includes multiple test messages.

[0087] S2062: Mutate multiple test messages.

[0088] The mutation process involves altering the field values ​​of a known message (such as the test message in this application) to generate a new test message, thereby increasing code coverage by enhancing the diversity of the test messages. This application does not specifically limit the mutation process; for example, one or more methods such as adding, deleting, inserting, byte replacement, and byte reversal can be used to mutate the field values ​​of the obtained test message to obtain a mutated test message.

[0089] S2063: Test the system under test based on the test message and the modified test message.

[0090] See Figure 4This figure is a schematic diagram illustrating the generation of mutated test messages provided in an embodiment of this application. Based on the actual messages exchanged between the system under test and other systems during communication, a seed set for test seeds is generated using the aforementioned method. This seed set is then used as input to a black-box fuzzing tool to generate multiple mutated test messages, which serve as the basis for testing the system under test. The quality of the mutated test messages generated by the black-box fuzzing tool's algorithm is highly dependent on the quality of the seed set. Compared to related technologies that assign a value of zero to the test seed, the seed set provided in this embodiment is of higher quality, significantly improving code coverage.

[0091] Therefore, the testing method provided in this application directly generates test messages from the system under test for testing, eliminating the need for manual intervention to correct content and saving labor costs. Furthermore, by using a relatively effective seed set as input to the black-box fuzzing tool, the resulting mutated test messages are of high quality, ensuring their basic validity at the start of testing, reducing trial-and-error time, and preventing them from being simply masked by the system under test, effectively improving code coverage.

[0092] Next, let's combine the following... Figure 5 Taking a real-world application scenario as an example, the testing method provided in the embodiments of this application will be explained.

[0093] S501: Generate test seeds based on the communication protocols between the system under test and other systems.

[0094] S502: Obtain the actual messages during communication between the system under test and other systems.

[0095] Both the test seed and the actual message include multiple fields.

[0096] S503: Parse the test seed according to the protocol format of the communication protocol to obtain the first set of fields, and parse the actual message according to the protocol format of the communication protocol to obtain the second set of fields.

[0097] S504: Take a field from the first field set as the first field.

[0098] S505: Compare the first field with each field in the second field set.

[0099] S506: Determine whether the first field and the second field meet the similarity condition. If yes, execute S507; otherwise, execute S509.

[0100] The similarity criteria are that the field type of the first field is the same as that of the second field, and the matching degree between the field name of the first field and the field name of the second field is greater than 70%.

[0101] S507: Add the field value of the second field to the set of field values ​​of the first field.

[0102] S508: After traversing the second field set, obtain the field value set for the first field, and execute S504 until all fields in the first field set are retrieved.

[0103] S509: Discard the first field.

[0104] S510: Obtain a field value from each of the multiple field value sets, arrange the m field values ​​corresponding to the m fields according to the order of the m fields, and generate a test message.

[0105] Repeating steps S504-S509 above, we can obtain the set of field values ​​corresponding to each field in the first set of fields, and then proceed to step S510. We will obtain a field value from each of the multiple set of field values, arrange the m field values ​​according to the order of the m fields, and generate a test message. For related details, please refer to steps S2051 and S2052, which will not be repeated here.

[0106] S511: Perform mutation processing on multiple test messages.

[0107] S512: Test the system under test based on the test message and the modified test message.

[0108] In addition to the data processing methods provided in the above embodiments, this application also provides a data processing apparatus.

[0109] See Figure 6 This figure is a schematic diagram of the structure of a testing device provided in an embodiment of this application. Figure 6 As shown, the testing device 600 includes a generation unit 601, an acquisition unit 602, a parsing unit 603, an assignment unit 604, and a testing unit 605;

[0110] The generation unit 601 is used to generate a test seed including at least one field according to the communication protocol between the system under test and other systems, wherein the field value of the test seed is zero.

[0111] The acquisition unit 602 is used to acquire the actual message during the communication process between the system under test and the other system, and the actual message includes at least one field.

[0112] The parsing unit 603 is used to parse the test seed according to the protocol format of the communication protocol to obtain a first set of fields, and to parse the actual message according to the protocol format of the communication protocol to obtain a second set of fields.

[0113] The assignment unit 604 is used to assign the field value of the second field as the field value of the first field if the first field in the first field set and the second field in the second field set satisfy a similarity condition.

[0114] The generation unit 601 is further configured to generate a test message based on the field value of the first field;

[0115] The test unit 605 is used to test the system under test according to the test message.

[0116] As one possible implementation, if the second field set includes multiple fields, the testing device 600 further includes a field value set construction unit, used for:

[0117] The first field is compared with each field in the second field set to obtain multiple similar fields that satisfy the similarity condition with the first field;

[0118] Construct a set of field values ​​for the first field based on the field values ​​of the multiple similar fields.

[0119] As one possible implementation, if the test seed includes m fields, the generation unit 601 is used to:

[0120] Each of the m fields is represented by a field value, and one field value is obtained from the set of m field values ​​corresponding to each of the m fields.

[0121] According to the order of the m fields, the values ​​of the m fields corresponding to the m fields are arranged to generate a test message.

[0122] As one possible implementation, the test unit 605 is used for:

[0123] Obtain multiple test messages corresponding to the test seed;

[0124] The multiple test messages are mutated;

[0125] The system under test is tested based on the test message and the modified test message.

[0126] As one possible implementation, the testing device 600 further includes a judgment unit, used for:

[0127] If the field type of the first field is the same as that of the second field, and the matching degree between the field name of the first field and the field name of the second field is greater than a preset threshold, then the first field and the second field meet the similarity condition.

[0128] As one possible implementation, the preset threshold is 70%, and the field types include numeric, string, byte, and array types.

[0129] As can be seen from the above technical solution, generating test seeds based on the communication protocol between the system under test and other systems makes the test seeds more closely match the actual situation, improving the quality of the test seeds and thus increasing code coverage. The actual messages during the communication process between the system under test and other systems are obtained, and the field values ​​of the actual messages are used as the basis for assigning test seed values, thus avoiding the system under test judging the test seed as invalid data due to a field value of zero. Both the actual messages and the test seeds include at least one field. To improve the effectiveness of the assignment, the test seeds and actual messages are parsed according to the protocol format of the communication protocol to obtain a first field set and a second field set. If the first field in the first field set and the second field in the second field set satisfy similarity conditions, it indicates a strong correlation between the first and second fields, and their data is interoperable. Therefore, the field value of the second field can be used as the field value of the first field to generate a test message, which is then used to test the system under test. Therefore, when testing the system under test, the source code is no longer obtained. Instead, test messages are generated based on the communication protocol, extending the testing scope to scenarios where the source code is unavailable, especially in real-world applications where obtaining the actual messages is difficult. Furthermore, the test messages are assigned valid values ​​before testing begins, reducing trial-and-error time and preventing them from being blocked by the system under test. This significantly bypasses the system's usual checks for invalid data, allowing the focus to be placed on deeper processing logic checks, further improving code coverage and usability.

[0130] This application also provides a computer device, which is the computer device described above. This computer device can be a server or a terminal device, and the aforementioned test can be built into the server or terminal device. The computer device provided in this application will be described below from a hardware implementation perspective. Among them, Figure 7 The diagram shown is a structural schematic of the server. Figure 8 The diagram shown is a structural schematic of the terminal device.

[0131] See Figure 7 , Figure 7This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1400 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 1422 and memory 1432, and one or more application programs 1442 or data storage media 1430 (e.g., one or more mass storage devices). The memory 1432 and storage media 1430 can be temporary or persistent storage. The program stored in the storage media 1430 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the server. Furthermore, the CPU 1422 may be configured to communicate with the storage media 1430 and execute the series of instruction operations in the storage media 1430 on the server 1400.

[0132] Server 1400 may also include one or more power supplies 1426, one or more wired or wireless network interfaces 1450, one or more input / output interfaces 1458, and / or one or more operating systems 1441, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.

[0133] The steps performed by the server in the above embodiments can be based on this Figure 7 The server structure shown.

[0134] CPU 1422 is used to perform the following steps:

[0135] A test seed is generated based on the communication protocol between the system under test and other systems, including at least one field, wherein the field value of the test seed is zero;

[0136] Obtain the actual messages between the system under test and the other systems during the communication process, wherein the actual messages include at least one field;

[0137] The test seed is parsed according to the protocol format of the communication protocol to obtain a first set of fields; the actual message is parsed according to the protocol format of the communication protocol to obtain a second set of fields.

[0138] If the first field in the first field set and the second field in the second field set meet the similarity condition, the field value of the second field is used as the field value of the first field;

[0139] Generate a test message based on the value of the first field;

[0140] The system under test is tested according to the test message.

[0141] Optionally, the CPU 1422 may also execute method steps of any specific implementation of the test method in the embodiments of this application.

[0142] See Figure 8 , Figure 8 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Figure 8 This diagram illustrates a partial structure of a smartphone related to the terminal device provided in this embodiment. The smartphone includes components such as a radio frequency (RF) circuit 1510, a memory 1520, an input unit 1530, a display unit 1540, a sensor 1550, an audio circuit 1560, a Wi-Fi module 1570, a processor 1580, and a power supply 1590. Those skilled in the art will understand that... Figure 8 The smartphone structure shown does not constitute a limitation on smartphones and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0143] The following is combined Figure 8 A detailed introduction to the various components of a smartphone:

[0144] The RF circuit 1510 can be used to receive and transmit signals during information transmission or calls. In particular, it receives downlink information from the base station and processes it with the processor 1580; in addition, it transmits uplink data to the base station.

[0145] The memory 1520 can be used to store software programs and modules, and the processor 1580 runs the software programs and modules stored in the memory 1520 to realize various functions and data processing of the smartphone.

[0146] Input unit 1530 can be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the smartphone. Specifically, input unit 1530 may include touch panel 1531 and other input devices 1532. Touch panel 1531, also known as a touch screen, can collect touch operations on or near the user and drive corresponding connected devices according to a pre-set program. In addition to touch panel 1531, input unit 1530 may also include other input devices 1532. Specifically, other input devices 1532 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.

[0147] The display unit 1540 can be used to display information input by the user or information provided to the user, as well as various menus of the smartphone. The display unit 1540 may include a display panel 1541, which may optionally be configured as a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.

[0148] Smartphones may also include at least one sensor 1550, such as a light sensor, a motion sensor, and other sensors. Other sensors that smartphones may also be equipped with, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be detailed here.

[0149] Audio circuit 1560, speaker 1561, and microphone 1562 provide an audio interface between the user and the smartphone. Audio circuit 1560 converts received audio data into electrical signals and transmits them to speaker 1561, where speaker 1561 converts them into sound signals for output. On the other hand, microphone 1562 converts collected sound signals into electrical signals, which are received by audio circuit 1560, converted into audio data, and then processed by processor 1580 before being transmitted via RF circuit 1510 to, for example, another smartphone, or the audio data can be output to memory 1520 for further processing.

[0150] The processor 1580 is the control center of the smartphone, connecting various parts of the smartphone through various interfaces and lines. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 1520, and by calling data stored in the memory 1520. Optionally, the processor 1580 may include one or more processing units.

[0151] The smartphone also includes a power supply 1590 (such as a battery) that supplies power to various components. Preferably, the power supply can be logically connected to the processor 1580 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.

[0152] Although not shown, smartphones may also include a camera, Bluetooth module, etc., which will not be described in detail here.

[0153] In this embodiment of the application, the memory 1520 included in the smartphone can store program code and transmit the program code to the processor.

[0154] The processor 1580 included in the smartphone can execute the test methods provided in the above embodiments according to the instructions in the program code.

[0155] This application also provides a computer-readable storage medium for storing a computer program that performs the testing method provided in the above embodiments.

[0156] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the test methods provided in the various optional implementations of the above aspects.

[0157] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium can be at least one of the following media: read-only memory (ROM), RAM, magnetic disk, or optical disk, etc., and other media capable of storing program code.

[0158] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and 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 the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0159] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Based on the implementation methods provided in the above aspects, this application can also be further combined to provide more implementation methods. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A testing method, characterized in that, The method includes: A test seed is generated based on the communication protocol between the system under test and other systems, including at least one field, wherein the field value of the test seed is zero; Obtain the actual messages between the system under test and the other systems during the communication process, wherein the actual messages include at least one field; The test seed is parsed according to the protocol format of the communication protocol to obtain a first set of fields; the actual message is parsed according to the protocol format of the communication protocol to obtain a second set of fields. If the first field in the first field set and the second field in the second field set meet the similarity condition, the field value of the second field is used as the field value of the first field; Generate a test message based on the value of the first field; The system under test is tested according to the test message.

2. The method according to claim 1, characterized in that, If the second field set includes multiple fields, the method further includes: The first field is compared with each field in the second field set to obtain multiple similar fields that satisfy the similarity condition with the first field; Construct a set of field values ​​for the first field based on the field values ​​of the multiple similar fields.

3. The method according to claim 2, characterized in that, If the test seed includes m fields, where m is an integer greater than 1, generating the test message based on the field value of the first field includes: Each of the m fields is represented by a field value, and one field value is obtained from the set of m field values ​​corresponding to each of the m fields. According to the order of the m fields, the values ​​of the m fields corresponding to the m fields are arranged to generate multiple test messages.

4. The method according to claim 3, characterized in that, The step of testing the system under test according to the test message includes: Obtain multiple test messages corresponding to the test seed; The multiple test messages are mutated; The system under test is tested based on the test message and the modified test message.

5. The method according to any one of claims 1-4, characterized in that, The method further includes: If the field type of the first field is the same as that of the second field, and the matching degree between the field name of the first field and the field name of the second field is greater than a preset threshold, then the first field and the second field meet the similarity condition.

6. A testing apparatus, characterized in that, The device includes: a generation unit, an acquisition unit, a parsing unit, an assignment unit, and a testing unit; The generation unit is used to generate a test seed including at least one field according to the communication protocol between the system under test and other systems, wherein the field value of the test seed is zero; The acquisition unit is used to acquire the actual messages between the system under test and the other systems during the communication process, and the actual messages include at least one field. The parsing unit is used to parse the test seed according to the protocol format of the communication protocol to obtain a first set of fields, and to parse the actual message according to the protocol format of the communication protocol to obtain a second set of fields. The assignment unit is used to assign the field value of the second field as the field value of the first field if the first field in the first field set and the second field in the second field set satisfy a similarity condition. The generation unit is further configured to generate a test message based on the field value of the first field; The testing unit is used to test the system under test according to the test message.

7. The apparatus according to claim 6, characterized in that, If the second field set includes multiple fields, the device further includes a field value set construction unit, used for: The first field is compared with each field in the second field set to obtain multiple similar fields that satisfy the similarity condition with the first field; Construct a set of field values ​​for the first field based on the field values ​​of the multiple similar fields.

8. A computer device, characterized in that, The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the method described in any one of claims 1-5 according to the instructions in the program code.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program for performing the method according to any one of claims 1-5.

10. A computer program product comprising instructions that, when run on a computer, cause the computer to perform the method of any one of claims 1-5.

Citation Information

Patent Citations

  • Method and device for producing test case

    CN101902367A

  • Method of malformed data filtering in Modbus TCP protocol fuzzy testing

    CN109639624A