Embedded software interface automatic testing method based on C language data structure

By automatically analyzing and data generation of the C-language communication protocol of embedded software, the problem of low-efficiency test case design in embedded software testing is solved, and efficient and accurate test results are achieved.

CN120386733APending Publication Date: 2025-07-29NANJING RES INST OF ELECTRONICS TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510476768.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-16
Publication Date
2025-07-29

AI Technical Summary

Technical Problem

In embedded software testing, the test case design efficiency is low, the testing human resources and time cost is high, and the testing work quality is difficult to guarantee.

Method used

The technical solution of automatic analysis of communication protocols based on the C language format of the system under test is adopted to automatically generate and parse the content of the communication message and perform automatic interface testing.

Benefits of technology

It improves the correctness of embedded software construction functions and integration, the correctness of software running timing, and the robustness of software, improves the automation and systematization of tests, and improves the testing efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120386733A_ABST
    Figure CN120386733A_ABST
Patent Text Reader

Abstract

The invention discloses an embedded software interface automatic test method based on a C language data structure, and aims to solve the technical problems that the test case design efficiency is low, the test manpower and material resource and time cost is high, and the test work quality is difficult to guarantee. The technical scheme of C language format communication protocol automatic analysis based on a tested system and communication data and test case automatic generation is adopted, communication message content is automatically generated, analyzed and judged, system software data interaction related functions and performance are tested based on automatic testing of an interface, and the test efficiency is improved. The technical effects of improving the correctness of embedded software construction function and integration, the correctness of software operation time sequence and software robustness are achieved, the test automation and systematization degree are improved, and a new way is provided for improving the efficiency, accuracy and quality of embedded software interface test.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of software testing, and particularly relates to a C language communication protocol interface testing technology. Background Art

[0002] Currently, in the fields of aviation, aerospace, industrial control, civil electronics, etc., the proportion of embedded software is increasing, and the functions and data interaction processes implemented are becoming more and more complex. Modern embedded systems contain a large number of homogeneous and heterogeneous software modules, and the program structure and business processing show a distributed and modular trend. The module scale expands, the communication and data interaction between different modules are complex, the amount of working interaction data is large, and the application scenarios are more complex and diverse. With the continuous growth of the scale and complexity of embedded software, the human, material resources and time costs of testing also increase significantly.

[0003] Software testing is an important means to ensure software design and development. For the testing of the functions and performance related to data interaction of embedded system software, it is completed by designing normal and abnormal message use cases based on the system communication interface and communication protocol. The interface communication protocol of such embedded software is often defined in a C language-based header file. The traditional testing method is to write code according to the format content of the communication protocol to generate and send messages and parse received messages, so as to judge whether the functions or performance of the embedded software are normal. Since the communication protocols of each embedded software are different, when testing personnel test the embedded system software, they need to conduct a large amount of analysis on the communication protocol and spend a lot of time writing test code in the early stage of testing. Summary of the Invention

[0004] In order to solve the technical problems of low efficiency in designing test cases, large human, material resources and time costs of testing, and difficulty in guaranteeing the quality of testing work, a technical solution of automatic analysis of the C language format communication protocol based on the system under test, automatic generation of communication data and test cases is adopted. Automatically generate, parse and judge the content of communication messages, and conduct automated testing based on the interface to test the functions and performance related to data interaction of system software, resulting in the technical effects of improving the correctness of the construction function and integration of embedded software, the correctness of software running timing, and software robustness, enhancing the degree of test automation and systematization, and providing a new way to improve the efficiency, accuracy and quality of embedded software interface testing.

[0005] Step 1: Put all the C language format header files to be imported into the same folder, read each line of information in the header file in the form of a file byte stream, parse the structure information from each line of information according to the C language specification, and classify the structure information into a sending type communication protocol set and a receiving type communication protocol set.

[0006] Further, the structure information includes macro definitions, comments, structure names, structure member variables, and arrays.

[0007] Further, the sending communication protocol set represents the message sent to the device under test, and the receiving communication protocol set represents the message received from the device under test.

[0008] Step 2: Configure the byte order for each field in the communication protocol, set the increment or decrement attribute, initial value, and numerical change unit for the sequence number value field in the communication protocol, and set the check algorithm and check range field for the check value field in the communication protocol.

[0009] Further, the configured byte order is defaulted to the big-endian encoding format, and the check algorithms include CRC check, exclusive OR check, and LRC check.

[0010] Further, set the data anomaly detection information for the receiving communication protocol to automatically identify the abnormal data in the message for subsequent fault analysis and processing.

[0011] Step 3: Set the data generation method for each protocol field in the specified protocol message and generate the sending message according to the communication protocol format.

[0012] Further, the data generation methods include random numbers, normal values, boundary values, abnormal values, enumeration values, and permutations and combinations.

[0013] Specifically, the rules for generating the sending message include: in each packet of data, except for permutations and combinations, at most only one protocol field is a boundary value or an abnormal value, and the others are normal values; the boundary value and abnormal value are only valid for range values and enumeration values; the protocol field without setting the numerical generation method is defaulted to 0; generate data for all protocol fields that can generate boundary values and abnormal values in the order in the protocol format; for the same protocol field that needs to generate boundary values and abnormal values, generate the boundary value first, then the normal value, and finally the abnormal value.

[0014] Step 4: Traverse and obtain the communication protocol format in sequence in the receiving communication protocol set, determine whether the length of the current communication protocol format is equal to the length of the received communication message. If they are equal, determine whether the current communication protocol format matches the received communication message. If they match, parse the content of each protocol field in the communication protocol corresponding to the received communication message, otherwise obtain the next communication protocol format by traversing.

[0015] Further, if the content of the protocol field is an abnormal value, mark this protocol field for testers to analyze the fault. Description of the Drawings

[0016] Figure 1 is the C language data structure header file format. Figure 2It is the protocol field definition, Figure 3 It is the parsing process of converting communication protocol information into a memory data structure, Figure 4 It is the process of generating a transmission message according to the communication protocol format, Figure 5 It is the process of parsing the received communication message. Specific implementation manners

[0017] The technical solution of the present invention will be specifically described below with reference to the accompanying drawings.

[0018] Step 1: Import the C language format header file and parse the structure information set in the header file. In the development of equipment system software, the interface communication protocol of the embedded device under test based on the interface is often defined in the C language format data structure header file and is embodied in the form of a structure. Therefore, in order to realize the automatic parsing of communication messages, it is first necessary to import the C language format data structure header file and parse the specific communication protocol format of the device under test from it, which is convenient for subsequent communication message parsing. The typical C language data structure header file format is as Figure 1 shown, including message header, message identifier, message length, year, month, day, hour combined with the application, data such as mode length, reserved field, check value, end symbol, etc.

[0019] According to the characteristics of the C language format data structure header file and combined with the interface test situation of the embedded software, the communication protocol is defined as 4 objects in the object-oriented design method, namely the communication protocol set, the sending class protocol, the receiving class protocol and the protocol field; among them, the communication protocol set has two attributes, namely the sending class protocol and the receiving class protocol; the sending class and the receiving class protocols are the same, and both have an attribute, which can be defined as a sequential container, equivalent to list or vector in C++ language, and store each protocol field in the communication protocol format; the protocol field is the smallest unit object in the communication protocol format and has attributes such as name, type, length, description, number of arrays, endian flag, field content, etc., and the relevant definitions are as Figure 2 shown.

[0020] Step 1 is actually to convert the communication protocol information defined in the C language format header file into a data structure in the computer memory, which is convenient for subsequent automatic parsing of the program. The flow chart of the parsing process is as Figure 3As shown. Put all relevant C-language format header files in the same folder. Through file path scanning, automatically identify and load all header files. Read the content of the header files line by line in the form of file byte stream to ensure that each line of information is completely captured. Parse each line of text according to the C-language specification to identify key information such as macro definitions, comments, structure names, structure member variables, arrays, etc. During the parsing process, ignore comments and irrelevant macro definitions and focus on extracting structure information related to the communication protocol. Classify the parsed structure information into a set of communication protocols for sending and a set of communication protocols for receiving. The set of communication protocols for sending is used to generate messages sent to the device under test, and the set of communication protocols for receiving is used to parse the messages received from the device under test.

[0021] Step 2: Configure the communication protocol to ensure the accuracy of communication protocol parsing or message generation. In traditional communication protocols, each message generally has a sequence number field and a checksum field. If there is no sequence number field and checksum field, no corresponding configuration is required; if there are sequence number field and checksum field, they need to be set separately.

[0022] For the sequence number field, it is generally used to identify the sequence number of a message in the total messages. This sequence number may increase continuously, may decrease continuously, and the increase or decrease amplitude can also be customized. Therefore, it is necessary to set the sequence number field to an increasing or decreasing mode and the amplitude value.

[0023] For the checksum field, it is generally used to ensure the integrity of communication message data. It is a checksum calculated by a specified algorithm for the original data. The communication parties calculate the checksum once with the same algorithm. If it is the same as the checksum in the message content, it means the data is complete and trustworthy. Therefore, for the checksum field, it is necessary to set the currently adopted checksum algorithm and the checksum content.

[0024] The following are several commonly used checksum algorithms, as shown in the following table. Configure the byte order of each field of the communication protocol to ensure the accuracy of communication messages. In a computer, whether the byte encoding order is LittleEndian or BigEndian is related to both the operating system and the chip type. Therefore, in a processor system, there may be a phenomenon where both big-endian and little-endian modes exist simultaneously. This requires testers to confirm and configure the byte code of each field in the communication protocol before testing to ensure that the messages in the communication process are accurate.

[0025] Step 2 configures the communication protocol to refine the characteristics of the communication protocol for embedded software interface testing and perform corresponding configurations in advance for subsequent processing.

[0026] Step 3, generate a transmission message in accordance with the communication protocol format, as Figure 4 shown. Traverse all fields in a loop, generate data according to the permutation and combination method. If not, determine whether it is a check value field and whether an abnormal value needs to be generated, set the value of the check value field to 0, generate an abnormal value according to the abnormal conditions, otherwise generate the normal value of this field, including value taking within the range, boundary values, and enumerated values. Then determine the field byte order and save it to the buffer defined for the entire packet message according to the LittleEndian or BigEndian saving method, thus completing one loop.

[0027] Step 4, parse the content of the received communication message, as Figure 5 shown. Traverse in sequence in the received communication protocol set to obtain the communication protocol format traversed in sequence currently. Determine whether the length of the currently traversed communication protocol format is equal to the length of the received communication message. If the lengths match, proceed to the next step; otherwise, jump to the aforementioned traversal step and continue to traverse the next communication protocol. Determine whether the content of the received message matches the currently traversed communication protocol format. If it matches, proceed to the next step; otherwise, jump to the aforementioned traversal step and continue to traverse the next communication protocol.

[0028] Parse the content of each protocol field in the communication protocol corresponding to the received message to ensure that the data of each field is correctly extracted and parsed. Determine whether the content of the protocol field is an abnormal value and compare it with the abnormal information set in the previous step. If it is an abnormal value, mark this protocol field to facilitate fault analysis by testers. Generate test cases automatically to ensure that the test covers all possible communication protocol scenarios. The test cases include various situations such as normal values, boundary values, and abnormal values to ensure that the system under test can work properly in all situations.

[0029] The automated test tool automatically executes the test and records the test results according to the generated test cases. By automatically parsing the received message, identifying abnormal data and conducting fault analysis, ensure the comprehensiveness and accuracy of the test.

[0030] Identify the communication protocol information in the data structure header file in C language format through the import and parsing method, and convert it into a transmission communication protocol set and a received communication protocol set that are convenient for automated processing. Then configure the communication protocol information appropriately to improve the communication protocol information, facilitate generating messages and parsing messages according to the communication protocol format, and efficiently parse and configure the communication protocol.

[0031] In view of the differences in different embedded communication protocols, it can avoid the defects of the traditional method of conducting a large amount of analysis on the communication protocol and writing test codes in the early stage of testing. It can automatically analyze the communication protocol and automatically generate communication data, greatly improving the test efficiency and accuracy. It is applicable to all scenarios where the communication protocol is defined in a C-language formatted data structure file, effectively assisting testers in conducting embedded software interface testing.

[0032] The above are embodiments of the present invention and do not limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention are all included in the protection scope of the present invention.

Claims

1. An automated testing method for an embedded software interface based on C language data structures, characterized in that, Including: Step 1: Put all the C-language format header files to be imported into the same folder, read each line of information in the header file in the form of a file byte stream, parse the structure information from each line of information according to the C-language specification, and classify the structure information into a set of sending communication protocols and a set of receiving communication protocols; Step 2: Configure the byte order for each field in the communication protocol, set the increment or decrement attribute, initial value, and numerical change unit for the sequence number value field in the communication protocol, and set the check algorithm and check range field for the check value field in the communication protocol; Step 3: Set the data generation method for each protocol field in the specified protocol message, and generate a sending message according to the communication protocol format; Step 4: Traverse and obtain the communication protocol format in sequence in the set of receiving communication protocols, and judge whether the length of the current communication protocol format is equal to the length of the received communication message. If they are equal, judge whether the current communication protocol format matches the received communication message. If they match, parse the content of each protocol field in the communication protocol corresponding to the received communication message. Otherwise, conveniently obtain the next communication protocol format.

2. The automated test method for the embedded software interface based on the C language data structure according to claim 1, wherein The structure information in Step 1 includes: macro definitions, comments, structure names, structure member variables, and arrays.

3. The automated test method for the embedded software interface based on the C language data structure according to claim 1, characterized in that, Step 1 includes: The set of sending communication protocols represents the message sent to the device under test, and the set of receiving communication protocols represents the message received from the device under test.

4. The automated test method for the embedded software interface based on the C language data structure according to claim 1, characterized in that Step 2 includes: The configured byte order is defaulted to the big-endian and little-endian encoding format, and the check algorithms include CRC check, exclusive-or check, and LRC check.

5. The automated test method for an embedded software interface based on a C language data structure according to claim 1, wherein Step 2 includes: Set the data anomaly detection information for the set of receiving communication protocols, automatically identify the abnormal data in the message, and use it for subsequent fault analysis and processing.

6. The automated test method for an embedded software interface based on a C language data structure according to claim 1, characterized in that The data generation method in Step 3 includes random numbers, normal values, boundary values, abnormal values, enumeration values, and permutations and combinations.

7. The automated testing method for embedded software interfaces based on C language data structures according to claim 1, characterized in that, The rule for generating the sending message in Step 3 includes: In each packet of data, except for permutations and combinations, at most only one protocol field is a boundary value or an abnormal value, and the others are normal values; The boundary value and abnormal value are only valid for the range value and the enumeration value; The protocol field without setting the numerical generation method is defaulted to 0; According to the order in the protocol format, generate data for all protocol fields that can generate boundary values and abnormal values; For the same protocol field that needs to generate a boundary value and an abnormal value, generate the boundary value first, then the normal value, and finally the abnormal value.

8. The automated test method for an embedded software interface based on a C language data structure according to claim 1, characterized in that Step 4 includes: If the content of the protocol field is an abnormal value, mark this protocol field for the tester to analyze the fault.