Program testing method and device, computer equipment and readable storage medium
By automatically simulating the operation of the program to be tested and comparing hash values with the operation results of the benchmark program, the inefficient testing problems caused by frequent compilation and burning in the existing technology are solved, and efficient and accurate program testing is achieved.
Patent Information
- Application Number
- CN202411421437.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-06-03
AI Technical Summary
In the prior art, frequent compilation and burning are required during program development and testing, resulting in low efficiency in the test process.
The pre-built automated simulation program simulates the input data of the program to be tested, obtains the simulation operation results, and hash the results. Compare the hash value of the simulation run result with the hash value of the benchmark run result obtained by the input data of the benchmark program to be processed to determine that the running test result of the program to be tested is passed.
This method does not require compilation and burning on the hardware side, and can quickly simulate the operation of the program to be tested, ensure the accuracy of the test results, and greatly improve the efficiency of program testing.
Smart Images

Figure CN120086124A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technologies, and in particular, to a program testing method, apparatus, computer device, and computer-readable storage medium. Background Art
[0002] With the development of computer technologies, a technology of burning a program written in C language or C++ to a hardware side has emerged. After a user completes program writing, the written program can be burned to the hardware side through a compiler, and the above program can be run through the hardware side to complete the development and testing of the hardware program.
[0003] In traditional technologies, during the development and testing of a hardware program, if it is necessary to modify data or logic of the written program, in this case, it is necessary to recompile the modified program and re-burn it to the hardware side to complete the testing of the modified program.
[0004] Therefore, during the program development process, it is usually necessary to perform compilation and burning multiple times. However, the compilation and burning processes usually take a lot of time, resulting in blocking of the testing process. Therefore, in existing program testing, the program testing efficiency is low. Summary of the Invention
[0005] Based on this, in view of the above technical problems, it is necessary to provide a program testing method, apparatus, computer device, computer-readable storage medium, and computer program product that can improve the program testing efficiency.
[0006] In a first aspect, the present application provides a program testing method, including:
[0007] In response to a program testing request for a program to be tested, obtaining input data for testing the program to be tested;
[0008] Simulating, through a pre-constructed automated simulation program, the program to be tested processing the input data to obtain a simulation operation result for this time;
[0009] Performing a hash process on the simulation operation result for this time to obtain a running hash value for this time corresponding to the simulation operation result for this time;
[0010] Obtaining a reference hash value, and determining that the running test result of the program to be tested passes when the running hash value for this time matches the reference hash value; the reference hash value is obtained by performing a hash process on a reference operation result, and the reference operation result is obtained by the reference program processing the input data.
[0011] In one embodiment, the reference program is pre-burned into the hardware side; the program to be tested corresponds to the same target program as the reference program; the obtaining of the reference hash value includes: when the current simulation operation result is the simulation operation result of the automated simulation program for the first time simulating the target program to process the input data, sending the input data to the hardware side; the hardware side is used to run the input data through the pre-burned reference program to obtain an actual operation result; obtaining the hash value corresponding to the actual operation result, and using the hash value corresponding to the actual operation result as the reference hash value.
[0012] In one embodiment, after using the hash value corresponding to the actual operation result as the reference hash value, it further includes: when the current operation hash value matches the reference hash value, storing the current operation hash value as the first operation hash value of the target program; the obtaining of the reference hash value includes: when the current simulation operation result is not the simulation operation result of the automated simulation program for the first time simulating the target program to process the input data, using the stored first operation hash value as the reference hash value.
[0013] In one embodiment, after performing hash processing on the current simulation operation result to obtain the current operation hash value corresponding to the current simulation operation result, it further includes: storing the current operation hash value into a pre-constructed doubly linked list; wherein, the structure of the doubly linked list is that the head node points to the head node and the tail node points to the tail node.
[0014] In one embodiment, performing hash processing on the current simulation operation result to obtain the current operation hash value corresponding to the current simulation operation result includes: obtaining the first data format corresponding to the input data and the second data format corresponding to the current simulation operation result; when the second data format is different from the first data format, converting the data format of the current simulation operation result into the first data format to obtain the current simulation operation result after data format conversion; performing hash processing on the current simulation operation result after data format conversion to obtain the current operation hash value.
[0015] In one embodiment, obtaining input data for testing the program to be tested in response to a program test request for the program to be tested includes: obtaining the current time, and triggering a plurality of program test requests when the current time meets the triggering time of a preset scheduled task; when the number of the program test requests is greater than a preset number threshold, obtaining a target program test request with a quantity matching the preset number threshold from the plurality of program test requests; and in response to the target program test request with a quantity matching the preset number threshold, obtaining input data for testing the program to be tested.
[0016] In one embodiment, after determining that the running test result of the program to be tested for running the input data passes, it further includes: after the program to be tested is burned to the hardware side, sending a program running instruction for the program to be tested to the hardware side; the program running instruction is used to instruct the hardware side to run the program to be tested to generate a binary running result file for the program to be tested; and displaying the binary running result file; the displayed binary running result file is used to obtain the true running test result of the program to be tested.
[0017] In a second aspect, the present application further provides a program testing device, including:
[0018] An input data acquisition module, configured to obtain input data for testing the program to be tested in response to a program test request for the program to be tested;
[0019] A simulation result acquisition module, configured to simulate the program to be tested processing the input data through a pre-constructed automated simulation program to obtain the current simulation running result;
[0020] A hash value acquisition module, configured to perform hash processing on the current simulation running result to obtain the current running hash value corresponding to the current simulation running result;
[0021] A test result acquisition module, configured to obtain a reference hash value, and determine that the running test result of the program to be tested passes when the current running hash value matches the reference hash value; the reference hash value is obtained by performing hash processing on a reference running result, and the reference running result is obtained by the reference program processing the input data.
[0022] In a third aspect, the present application further provides a computer device, including a memory and a processor, where the memory stores a computer program, and when the processor executes the computer program, it implements the steps of the method according to any one of the embodiments in the first aspect.
[0023] Fourthly, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method according to any embodiment of the first aspect are implemented.
[0024] Fifthly, the present application also provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the method according to any embodiment of the first aspect are implemented.
[0025] For the above program testing method, device, computer device, computer-readable storage medium and computer program product, in response to a program testing request for a program to be tested, input data for testing the program to be tested is obtained; the input data is processed by the program to be tested through a pre-constructed automated simulation program to obtain the simulation running result of the current time; the simulation running result of the current time is subjected to hash processing to obtain the running hash value of the current time corresponding to the simulation running result of the current time; a reference hash value is obtained. When the running hash value of the current time matches the reference hash value, it is determined that the running test result of the program to be tested passes; the reference hash value is obtained by performing hash processing on the reference running result, and the reference running result is obtained by the reference program processing the input data. In the present application, when a program testing request for a program to be tested is received, input data can be obtained, and then the pre-constructed automated simulation program can be used to simulate the program to be tested to process the input data to obtain the simulation running result of the current time. Then, the running hash value of the current time corresponding to the simulation running result of the current time can be calculated, and the running hash value of the current time is compared with the reference hash value of the reference running result obtained by the reference program processing the input data. If they match, it is confirmed that the running logic of the program to be tested is the same as that of the reference program, and the running test result passes. In this way, only in the automated simulation program can the running of the program to be tested in the hardware end be simulated, and it is not necessary to perform compilation and burning in the hardware end for testing to ensure the accuracy of the running test result. Moreover, the way to obtain the running test result is to compare the hash value of the simulation running result with the reference hash value corresponding to the running result obtained by the reference program, without the need for manual comparison. Therefore, on the premise of ensuring the accuracy of the running test result, the efficiency of program testing can be further improved. Description of the Drawings
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following will briefly introduce the drawings required for describing the embodiments of the present application or related technologies. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0027] Figure 1Schematic flowchart of a program testing method in an embodiment;
[0028] Figure 2 Schematic flowchart of obtaining a reference hash value in an embodiment;
[0029] Figure 3 Schematic flowchart of obtaining the hash value of the current run in an embodiment;
[0030] Figure 4 Schematic flowchart of obtaining input data in an embodiment;
[0031] Figure 5 Schematic diagram of the structure of a doubly linked list in an embodiment;
[0032] Figure 6 Block diagram of the structure of a program testing device in an embodiment;
[0033] Figure 7 Internal structure diagram of a computer device in an embodiment. Detailed implementation manners
[0034] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0035] In one embodiment, as Figure 1 shown, a program testing method is provided. In this embodiment, the method is exemplified by being applied to a terminal. It can be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0036] Step S101, in response to a program testing request for a program to be tested, obtain input data for testing the program to be tested.
[0037] The program to be tested refers to a running program written in a certain C language or C++ that needs to be tested. This running program is used to be burned into the hardware terminal so that the hardware terminal can run the above program to complete a certain specific function, and the program testing request is a request for testing the running logic of the program to be tested. The input data is the input parameter data used to test the running logic of the program to be tested, and this input data can be written by the user in the terminal.
[0038] Specifically, when the user initiates a program test request for the program to be tested through the terminal, input parameter data for testing the operation of the program to be tested can be input into the terminal. Subsequently, the terminal can respond to this request to obtain the input parameter data input by the user.
[0039] Step S102: Simulate the program to be tested processing the input data through a pre-constructed automated simulation program to obtain the simulation operation result for this time.
[0040] The automated simulation program is a pre-written simulation program for simulating the operation of the program to be tested. This simulation program can be used to simulate the operation of the program to be tested on the hardware side, thereby completing the program test for the program to be tested. The simulation operation result for this time refers to the operation result of the automated simulation program simulating the program to be tested for this time.
[0041] Specifically, after the terminal obtains the input data, it can acquire the program to be tested that needs to be tested. For example, it can obtain the program to be tested from the server side by means of calling the interface of the automated simulation program. Subsequently, by importing the input data into the program to be tested, the automated simulation program can simulate the process of the program to be tested processing the input data, thereby outputting the simulation operation result for this time.
[0042] Step S103: Perform a hash process on the simulation operation result for this time to obtain the running hash value for this time corresponding to the simulation operation result for this time;
[0043] Step S104: Obtain the reference hash value. When the running hash value for this time matches the reference hash value, it is determined that the running test result of the program to be tested passes; the reference hash value is obtained by performing a hash process on the reference operation result, and the reference operation result is obtained by the reference program processing the input data.
[0044] The running hash value for this time refers to the hash value obtained after performing a hash process on the above-mentioned simulation operation result, while the reference hash value refers to the hash value corresponding to the reference operation result obtained by the reference program processing the input data. The reference program refers to a program used to compare the running results with the program to be tested. The running result of the program to be tested needs to be the same as the running result of the reference program to ensure that the running test of the program to be tested passes.
[0045] For example, the reference program can be the original version of a C language program that implements a certain function, and the program to be tested can be an updated version of this C language program. To ensure that the updated C language program can also implement this function, it is necessary to ensure that the running result of the program to be tested matches the running result of the reference program, so that the running test result of the program to be tested can be determined to pass the test.
[0046] Specifically, after the terminal obtains the simulation operation result of the current time, it can perform hash processing on the simulation operation result of the current time to obtain the hash value of the current operation. Then, the hash value of the current operation can be compared with the reference hash value, where the reference hash value refers to the hash value of the reference operation result obtained by running the input data through the reference program. If the hash value of the current operation matches the reference hash value, it indicates that the operation logic of the program to be tested is the same as that of the reference program and the same functions can be achieved. Therefore, the operation test result of the program to be tested is passed.
[0047] In the above program testing method, in response to a program testing request for the program to be tested, input data for testing the program to be tested is obtained; the input data is processed by a pre-built automated simulation program to simulate the program to be tested, and the simulation operation result of the current time is obtained; hash processing is performed on the simulation operation result of the current time to obtain the hash value of the current operation corresponding to the simulation operation result of the current time; the reference hash value is obtained, and when the hash value of the current operation matches the reference hash value, it is determined that the operation test result of the program to be tested passes; the reference hash value is obtained by performing hash processing on the reference operation result, and the reference operation result is obtained by the reference program processing the input data. In this application, when a program testing request for the program to be tested is received, input data can be obtained, and then the pre-built automated simulation program can be used to simulate the program to be tested to process the input data to obtain the simulation operation result of the current time. Then, the hash value of the current operation corresponding to the simulation operation result of the current time can be calculated, and the hash value of the current operation is compared with the reference hash value of the reference operation result obtained by the reference program processing the input data. If they match, it is confirmed that the operation logic of the program to be tested is the same as that of the reference program and the operation test result passes. By this method, the operation of the program to be tested in the hardware end can be simulated only in the automated simulation program, and it is not necessary to perform compilation and burning in the hardware end for testing, which can also ensure the accuracy of the operation test result. Moreover, the way to obtain the operation test result is to compare the hash value of the simulation operation result with the reference hash value corresponding to the operation result obtained by the reference program, without manual comparison. Therefore, on the premise of ensuring the accuracy of the operation test result, the efficiency of program testing can be further improved.
[0048] In one embodiment, the reference program is pre-burned in the hardware end; the reference program is the program to be tested that processes the input data for the first time; the program to be tested and the reference program correspond to the same target program; as Figure 2 shown, step S104 may further include:
[0049] Step S201, when the simulation result of the current run is the simulation result of the automated simulation program's first simulation of the program under test processing the input data, send the input data to the hardware side; the hardware side is used to run the input data through a pre-burned reference program to obtain the actual running result.
[0050] In this embodiment, the reference program can be the same as the target program first simulated by the automated simulation program. For example, it can be the original version program of the target program, and the reference program can be pre-recorded into the hardware side, while the target program can refer to the program code that implements the preset function. Specifically, if the simulation result of the current run is the simulation result of the automated simulation program's first simulation of the target program processing the input data, that is, when the current program under test is the same as the reference program, after obtaining the simulation result of the current run through simulation, the input data can also be sent to the hardware side, and the program under test burned in the hardware side runs the input data in the real environment to obtain the running result in the real environment, that is, the actual running result.
[0051] Step S202, obtain the hash value corresponding to the actual running result, and use the hash value corresponding to the actual running result as the reference hash value.
[0052] After obtaining the actual running result of the reference program in the hardware side, the hash value corresponding to the actual running result can be calculated, and the hash value corresponding to the actual running result is used as the reference hash value to compare with the hash value of the current run. Since the current program under test is the first target program simulated by the automated simulation program, that is, the current program under test is the reference program itself, therefore, by using the hash value corresponding to the actual running result as the reference hash value and comparing it with the running result simulated by the automated simulation program, it can be verified whether the automated simulation program can accurately simulate the real running of the program under test on the hardware side. If the hash value of the current run matches the reference hash value, it indicates that the automated simulation program can accurately simulate the real running of the program under test on the hardware side, so the running test result passes.
[0053] In this embodiment, when the simulation result of the current run is the simulation result of the automated simulation program's first simulation of the program under test processing the input data, the terminal can use the hash value corresponding to the running result of the actual running of the reference program on the hardware side as the reference hash value to match with the hash value of the current run. If the hash value of the current run matches the reference hash value, it indicates that the automated simulation program can accurately simulate the real running of the program under test on the hardware side, so the running test result passes. By this method, it can be ensured that the automated simulation program can accurately simulate the real running of the program under test on the hardware side and improve the reliability of the test result.
[0054] Further, after step S202, it may further include: when the hash value of the current run matches the reference hash value, storing the hash value of the current run as the first run hash value of the target program; step S104 may further include: when the simulation result of the current simulation run is not the simulation result of the first simulation of the target program processing the input data by the automated simulation program, using the stored first run hash value as the reference hash value.
[0055] After the automated simulation program obtains the hash value of the current run of the first simulation of the program under test processing the input data, the hash value can be matched with the hash value corresponding to the actual run result, that is, the reference hash value. If the match is successful, the terminal can store the hash value of the current run as the first run hash value of the target program. When the automated simulation program simulates the target program processing the input data again, for example, when the program under test is the second version of the target program and the second version of the target program is tested, the terminal can use the stored first run hash value as the reference hash value for comparison, instead of having to run the benchmark program burned on the hardware side again to obtain the hash value corresponding to the actual run result as the reference hash value for comparison.
[0056] For example, taking the target program as Program A, when simulating Program A processing the input data for the first time, the version of Program A is Version 1. The Program A of Version 1 can be burned on the hardware side as the benchmark program. Then, when the automated simulation program first simulates Program A processing the input data, the input data can also be input to the hardware side, and the benchmark program burned on the hardware side processes the input data to obtain the actual run result. Then, the hash value of the current simulation run result obtained by the automated simulation program and the hash value of the actual run result can be calculated respectively, and the above hash values can be compared. If the comparison passes, the hash value of the current simulation run result can be stored as the first run hash value of Program A. If Program A is tested again later, for example, when testing Version 2 of Program A, Version 2 of Program A can be used as the program under test. At this time, it is no longer the first simulation run of the target program, that is, Program A. Therefore, the terminal can compare the hash value of the run result of Version 2 of Program A with the first run hash value of Program A. If they match, it means that the test of Version 2 of Program A passes. In this way, it can be ensured that Version 1 and Version 2 of Program A are used to implement the same basic running logic, thus ensuring that Version 2 of Program A can achieve the same functions as Version 1.
[0057] In this embodiment, if the hash value of the simulation running result of the target program processing the input data for the first time matches the hash value corresponding to the actual running result in the hardware side, the hash value can also be stored as the first running hash value of the target program. When the target program is simulated and run again later, only the stored first running hash value can be directly used as the reference hash value, without obtaining the hash value corresponding to the actual running result through the hardware side again. In this way, the test efficiency can be further improved.
[0058] In one embodiment, after step S103, it may further include: storing the current running hash value into a pre-constructed doubly linked list; wherein, the structure of the doubly linked list is that the head node points to the head node, and the tail node points to the tail node.
[0059] In this embodiment, after calculating the current running hash value, the current running hash value can also be stored into a pre-constructed doubly linked list, where the structure of the doubly linked list is a gene spiral structure. The characteristic of this gene spiral structure is that the head node points to the head node, and the tail node points to the tail node. Part of the code for constructing the doubly linked list is as follows:
[0060] this.head = new Node(0, 0); / / Create the head node
[0061] this.tail = new Node(0, 0); / / Create the tail node
[0062] this.tail.head = this.head; / / The head node points to the head node
[0063] this.tail.next = this.tail; / / The tail node points to the tail node
[0064] In this embodiment, the current running hash value can also be stored into a pre-constructed doubly linked list for saving, and the structure of the doubly linked list is a gene spiral structure in which the head node points to the head node and the tail node points to the tail node. Compared with the doubly linked list with the head and tail connected to form an inner loop, the doubly linked list provided in this embodiment can directly compare according to the subscripts corresponding to the two files when comparing data in a loop, without having to distinguish between the head and tail of the linked list, so the comparison efficiency can be improved.
[0065] In one embodiment, as Figure 3 shown, step S103 may further include:
[0066] Step S301, obtaining the first data format corresponding to the input data, and the second data format corresponding to the current simulation running result.
[0067] Among them, the first data format refers to the data format corresponding to the input data, and the second data format is the data format of the result of the simulation run obtained by the program under test processing the input data. In this embodiment, after the terminal obtains the result of the current simulation run, it can also obtain the data format corresponding to the input data as the first data format, and use the data format corresponding to the result of the current simulation run as the second data format.
[0068] Step S302, when the second data format is different from the first data format, convert the data format of the result of the current simulation run to the first data format to obtain the result of the current simulation run after data format conversion;
[0069] Step S303, perform a hash process on the result of the current simulation run after data format conversion to obtain the hash value of the current run.
[0070] If the second data format is different from the first data format, that is, when the data format corresponding to the result of the current simulation run is different from the data format corresponding to the input data, it is necessary to convert the data format corresponding to the result of the current simulation run to the first data format. After obtaining the result of the current simulation run after data format conversion, perform a hash process to obtain the hash value of the current run.
[0071] For example, if the first data format corresponding to the input data is hexadecimal and the second data format corresponding to the result of the current simulation run is binary, the terminal needs to perform a data format conversion on the result of the current simulation run to convert the result of the current simulation run to hexadecimal. It can be to first convert the result of the current simulation run to decimal and then to hexadecimal to obtain the result of the current simulation run after data format conversion. Finally, perform a hash process on the result of the current simulation run after data format conversion to obtain the hash value of the current run.
[0072] In this embodiment, if the data format corresponding to the input data is inconsistent with the data format corresponding to the result of the current simulation run, the data format of the result of the current simulation run can also be converted to be the same as the data format of the input data, and then a hash operation is performed. By this method, the accuracy of obtaining the hash value of the current run can be improved.
[0073] In one embodiment, as Figure 4 shown, step S101 may further include:
[0074] Step S401, obtain the current time, and when the current time meets the trigger time of a preset timing task, trigger multiple program test requests.
[0075] A scheduled task refers to a task that is triggered at a preset time. In this embodiment, a program test request for the program to be tested can be triggered by a scheduled task. If the current time meets the trigger time of the scheduled task, the program test request for the program to be tested can be actively triggered, and the number of such program test requests can be multiple, which is used to simulate the situation of processing multiple tasks simultaneously in a real environment.
[0076] Step S402, when the number of program test requests is greater than a preset quantity threshold, obtain a target program test request with a quantity matching the preset quantity threshold from multiple program test requests;
[0077] Step S403, in response to the target program test request with a quantity matching the preset quantity threshold, obtain the input data for testing the program to be tested.
[0078] If the number of program test requests is greater than the preset quantity threshold, for example, the number of program test requests is greater than the preset quantity threshold of 5, then a target program test request with a quantity matching the preset quantity threshold can be obtained from multiple program test requests, that is, 5 target program test requests are screened out for response processing to execute the process of obtaining input data, and the remaining program test requests are not processed. In this way, the situation of the message channel in a real environment being full or empty can be simulated.
[0079] Specifically, during testing, a scheduled task can be set to passively trigger a program test task, and this test task can be stored in an array or a list, which is equivalent to the message channel in a test bench. Then, the method of sleeping and waking up can be used to execute the tasks of the message channel, and the length of the message channel can be limited. For example, the length set in the C language program package in the test bench is 5, and other tasks will not be processed if there are more than 5 tasks. In this way, the situation of the message channel in a real environment being full or empty can be simulated.
[0080] In this embodiment, the test request can be triggered by a preset scheduled task, and when the number of program test requests is greater than the preset quantity threshold, only the target program test request with a quantity matching the preset quantity threshold is responded to, so as to simulate the situation of the message channel in a real environment being full or empty. In this way, the integrity and intelligence of program testing can be further improved.
[0081] In one embodiment, after step S104, it may further include: after the program to be tested is burned into the hardware end, sending a program running instruction for the program to be tested to the hardware end; the program running instruction is used to instruct the hardware end to run the program to be tested to generate a binary running result file for the program to be tested; displaying the binary running result file; the displayed binary running result file is used to obtain the real running test result of the program to be tested.
[0082] In this embodiment, after the running test result of the program to be tested passes, the user can also open the programming platform through the terminal to burn the program to be tested to the hardware side. After that, the user can also initiate a program running instruction for the program to be tested through the terminal to instruct the hardware side to run the program to be tested and generate a binary running result file for the program to be tested. After the user initiates the program running instruction, the binary running result file generated by the hardware side can be further displayed through the terminal, so that the user can judge whether the binary running result file is generated and whether there is data in the binary running result file. In this way, the user can perform a real running test of the program to be tested on the hardware side, so as to obtain the real running test result of the program to be tested.
[0083] In this embodiment, after the simulation running test is completed, the program to be tested can also be burned to the hardware side. By initiating a program running instruction, the hardware side is instructed to run the program to be tested and generate a binary running result file for the program to be tested. After that, the terminal can also display the generated binary running result file to obtain the real running test result of the program to be tested. In this way, the integrity of program testing can be improved.
[0084] In one embodiment, an automated test method for implementing programmatic hash collision is also provided. According to the compiled program package, it can be executed with one key and the result can be output with one key, and the process of burning a C language or C++ program to the board can be realized. The specific steps are as follows:
[0085] (1) Write a program using a programming language and execute the written test data using the programming language, such as the following msg. Define a method in the code, with parameters being msg and the output data format, and the return result being the input data format (the data format can be binary, decimal, and hexadecimal). The specific processing logic can be based on the programming language used.
[0086] For example:
[0087] uint8 msg[5] = {0x01,0x02,0x03,0x04,0x05};
[0088] data testData = {.msgId = 0x53000c0500010001,
[0089] .length = 0x09,
[0090] .sigle = 0x0005
[0091] .resv = 0x0560
[0092] .data = &msg[0]}
[0093] The binary file parsed by this format through Python, when converting to hexadecimal, or through the Python program code: "{:#06X}".format("the binary data to be parsed"), directly parses and returns the output in binary computer language. If the test data requires binary, according to the input parameters, the binary result can be directly returned. If the input parameter is hexadecimal, the parsed binary data needs to be converted to hexadecimal. The parsing logic is: first convert the binary to decimal, and then to hexadecimal (code: int(binary_str, 2), hex(num)[2:]). The parsed hexadecimal data is as follows,
[0094] 01 00 01 00 05 0c 00 53
[0095] 08 00 21 00 00 00 00 00 02 33 d0 9f 8f 01 00 00 01 02 03 04 05 00 00
[0097] Among them, the first line is the parsing result of msgId, the second line is the timestamp, and the third line is the parsing data result of msg. The parsing format can be specified according to the specific scenario, or a binary data packet header can be added for distinction to facilitate the retrieval of data uploaded to the application end.
[0098] (2)Hash the binary, decimal, or hexadecimal data parsed in (1). Taking hexadecimal as an example:
[0099] def md5_hash(text):
[0100] hash_object = hashlib.md5(text.encode())
[0101] return hash_object.hexdigest(),
[0102] Hash the data to be tested as well, and then perform a hash collision between the programmatically generated hash data and the hash result to be tested (a hash collision can be simply understood as determining whether the hash values are equal, and this patent mainly focuses on determining whether the hash values are equal). If the hash values are equal, the test data is correct, and the hash data of this time is retained. Based on this data, there is no need to generate hash data again during subsequent tests and retests. Just collide the latest test data with the benchmark hash data. If the hash values are not equal, an error report is output.
[0103] (3)Improve the hash here. Through an encoding form, transform it into a gene helix double-linked list, as Figure 5 , similar to a gene helix structure. Different from a doubly linked list where the head and tail are connected and an inner loop is done, the gene helix linked list used this time has the head against the head and the tail against the tail, and the loop is exited when the last pointer index is null. It is a structure that accurately compares the value according to the subscript value - key without having to do repeated loop processing, and only needs to compare according to the subscript index. Some of the code is as follows:
[0104] this.head = new Node(0, 0); / / Create the head node
[0105] this.tail = new Node(0, 0); / / Create the tail node
[0106] this.tail.head = this.head; / / The head node points to the head node
[0107] this.tail.next = this.tail; / / The tail node points to the tail node
[0108] (4)Regarding the above problems, the solutions proposed in this patent are as follows:
[0109] (1)Write a program using a programming language and execute the completed test data using the programming language, such as the following msg. Define a method in the encoding, with the parameters being msg and the output data format, and the return result being the input data format (the data format can be binary, decimal, and hexadecimal). The specific processing logic can be based on the programming language used.
[0110] For example:
[0111] uint8 msg[5] = {0x01,0x02,0x03,0x04,0x05};
[0112] data testData = {.msgId = 0x53000c0500010001,
[0113] .length = 0x09,
[0114] .sigle = 0x0005
[0115] .resv = 0x0560
[0116] .data = &msg[0]}
[0117] The binary file parsed from this format by Python, when converting to hexadecimal, or, through the Python program code:
[0118] "{:#06X}".format("the binary data to be parsed") directly parses and returns the output in the computer language of binary. If the test data requires binary, according to the input parameters, the binary result can be directly returned. If the input parameter is hexadecimal, the parsed binary data needs to be converted to hexadecimal. The parsing logic is: first convert the binary to decimal, and then to hexadecimal (code: int(binary_str, 2), hex(num)[2:]). The parsed hexadecimal data is as follows,
[0119] 01 00 01 00 05 0c 00 53
[0120] 08 00 21 00 00 00 00 00 02 33 d0 9f 8f 01 00 00 01 02 03 04 05 00 00
[0122] Among them, the first line is the parsing result of msgId, the second line is the timestamp, and the third line is the parsing data result of msg. The parsing format can be specified according to the specific scenario, or a binary data packet header can be added for differentiation to facilitate the retrieval of data uploaded to the application side.
[0123] (2)Hash the binary, decimal, or hexadecimal data parsed in (1). Taking hexadecimal as an example:
[0124] def md5_hash(text):
[0125] hash_object = hashlib.md5(text.encode())
[0126] return hash_object.hexdigest(),
[0127] Hash the data to be tested as well, and then perform a hash collision between the programmed hash data and the hash result to be tested (a hash collision can be simply understood as determining whether the hash values are equal, and this patent mainly focuses on determining whether the hash values are equal). If the hash values are equal, the test data is correct, and the hash data of this time is retained. Based on this data, there is no need to generate hash data again in subsequent tests and retests. Just collide the latest test data with the benchmark hash data. If the hash values are not equal, an error report is output.
[0128] (3)Improve the hash here. Through an encoding form, transform it into a gene spiral doubly linked list, as Figure 1 , similar to a gene spiral structure. Different from a doubly linked list where the head and tail are connected and an inner loop is done, the gene spiral linked list used this time has the head against the head and the tail against the tail, and the loop is exited when the last pointer index is null. It is a structure that accurately compares values according to the subscript value - key without having to do repeated loop processing, and only needs to compare according to the subscript index. Part of the code is as follows:
[0129] this.head = new Node(0, 0); / / Create the head node
[0130] this.tail = new Node(0, 0); / / Create the tail node
[0131] this.tail.head = this.head; / / The head node points to the head node
[0132] this.tail.next = this.tail; / / The tail node points to the tail node
[0133] (4)During the execution of the program, active writing and passive writing can be performed by simulating the signals of the hardware board through simulation, and at the same time, signals are sent as confirmation. For example, a timed task can be created to passively trigger, or a Python input pop-up window can also be created to actively trigger by inputting corresponding parameters or data. The triggered tasks can be put into an array or a list, which is equivalent to a message channel in a test bench. The tasks in the message channel are executed by the method of sleeping and waking up. The length of the message channel can be restricted. Just like the length set in the C language program package in a test bench test is 5, and no processing is done for more than 5 tasks. This method simulates the situation of queue full and queue empty in a real environment message channel.
[0134] (5) The above is for those that can use program simulation design but require real data and need to be saved to disk, which cannot be simulated by automated testing. In this case, the mouse event and screenshot third-party libraries of Python need to be used for operation and implementation. First, operate the screen to open the client, open the flashing program platform, open the flashing menu, and execute the flashing program step by step according to the mouse events and screen operations of Python. Then, check whether the.bin file is generated by taking a screenshot. And confirm whether the saved file has data. This method only verifies whether the disk saving operation is successful, and the data on the server side is verified in the above program package.
[0135] Through this embodiment, since the automated test program package can be reused after one-time development, the greatest benefit is that in multi-phase tests, the initial hash reference data can be recycled and reused in retesting. Secondly, it can save the time for pre-operation such as setting up the test bench, wiring, and debugging. When testing each test case, modifying the code requires repeated burning. However, through the automated simulation program, the same result data after the flashing program can be simulated, saving manpower and a large amount of time. Through the automated simulation program, it is possible to avoid the need to re-burn and compile every time the embedded code is modified. During the compilation process, compilation errors may also occur (such as type definition errors, array out-of-bounds, undefined parameters, etc.). Only the business logic to be tested needs to be preset in advance when writing test cases. The automated simulation program can implement automatic hash collision between the hash data results after the execution of the program and the test data, and output the error data, saving the labor of manually checking the data. Moreover, the hash value itself has an encryption function, which can prevent the leakage and tampering of important test data. The hash data structure itself is a chained structure, so in terms of execution query and collision, it is more efficient and faster than the general program data comparison.
[0136] It should be understood that although the steps in the flowcharts of the above-described embodiments are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, there is no strict order limit for the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts of the above-described embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0137] Based on the same inventive concept, an embodiment of the present application further provides a program testing device for implementing the program testing method involved above. The implementation solution provided by this device for solving problems is similar to the implementation solution described in the above method. Therefore, the specific limitations in one or more embodiments of the program testing device provided below can refer to the limitations on the program testing method in the above text, and will not be elaborated here.
[0138] In one embodiment, as Figure 6 shown, a program testing device is provided, including: an input data acquisition module 601, a simulation result acquisition module 602, a hash value acquisition module 603, and a test result acquisition module 604, where:
[0139] The input data acquisition module 601 is configured to obtain input data for testing the program to be tested in response to a program testing request for the program to be tested;
[0140] The simulation result acquisition module 602 is configured to simulate the program to be tested processing the input data through a pre-constructed automated simulation program to obtain the simulation operation result of the current simulation run;
[0141] The hash value acquisition module 603 is configured to perform hash processing on the simulation operation result of the current simulation run to obtain the current run hash value corresponding to the simulation operation result of the current simulation run;
[0142] The test result acquisition module 604 is configured to obtain a reference hash value, and determine that the run test result of the program to be tested passes when the current run hash value matches the reference hash value; the reference hash value is obtained by performing hash processing on the reference operation result, and the reference operation result is obtained by the reference program processing the input data.
[0143] In one embodiment, the reference program is pre-burned in the hardware side; the program to be tested and the reference program correspond to the same target program; the test result acquisition module 604 is further configured to send the input data to the hardware side when the simulation operation result of the current simulation run is the simulation operation result of the automated simulation program for the first time to simulate the target program processing the input data; the hardware side is configured to run the input data through the pre-burned reference program to obtain the actual operation result; obtain the hash value corresponding to the actual operation result, and use the hash value corresponding to the actual operation result as the reference hash value.
[0144] In one embodiment, the test result acquisition module 604 is further configured to store the current run hash value as the first run hash value of the target program when the current run hash value matches the reference hash value; when the simulation operation result of the current simulation run is not the simulation operation result of the automated simulation program for the first time to simulate the target program processing the input data, use the stored first run hash value as the reference hash value.
[0145] In one embodiment, the hash value acquisition module 603 is further configured to store the current run hash value into a pre-constructed doubly linked list; wherein, the structure of the doubly linked list is that the head node points to the head node, and the tail node points to the tail node.
[0146] In one embodiment, the hash value acquisition module 603 is further configured to obtain a first data format corresponding to the input data and a second data format corresponding to the current simulation run result; in the case where the second data format is different from the first data format, convert the data format of the current simulation run result into the first data format to obtain the current simulation run result after data format conversion; perform hash processing on the current simulation run result after data format conversion to obtain the current run hash value.
[0147] In one embodiment, the input data acquisition module 601 is further configured to obtain the current time, and trigger a plurality of program test requests when the current time meets the trigger time of a pre-set timing task; in the case where the number of program test requests is greater than a preset number threshold, obtain a target program test request with a number matching the preset number threshold from the plurality of program test requests; in response to the target program test request with a number matching the preset number threshold, obtain input data for testing the program to be tested.
[0148] In one embodiment, the test result acquisition module 604 is further configured to, after the program to be tested is burned into the hardware side, send a program running instruction for the program to be tested to the hardware side; the program running instruction is used to instruct the hardware side to run the program to be tested to generate a binary running result file for the program to be tested; display the binary running result file; the displayed binary running result file is used to obtain the real running test result of the program to be tested.
[0149] Each module in the above program test device can be implemented in whole or in part by software, hardware, and their combination. Each of the above modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in a computer device in software form, so that the processor can call and execute the operations corresponding to each of the above modules.
[0150] In one embodiment, a computer device is provided. The computer device can be a terminal, and its internal structure diagram can be as Figure 7As shown in the figure. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface, the display unit, and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a program testing method. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0151] Those skilled in the art can understand that Figure 7 the structure shown in the figure is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0152] In one embodiment, a computer device is further provided, including a memory and a processor. A computer program is stored in the memory, and when the processor executes the computer program, the steps in the above method embodiments are implemented.
[0153] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by the processor, the steps in the above method embodiments are implemented.
[0154] In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by the processor, the steps in the above method embodiments are implemented.
[0155] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with relevant regulations.
[0156] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in this application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., and are not limited thereto. The processors involved in the embodiments provided in this application can be general-purpose processors, central processors, graphics processors, digital signal processors, programmable logic devices, data processing logics based on quantum computing, artificial intelligence (AI) processors, etc., and are not limited thereto.
[0157] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this application.
[0158] The above-described embodiments merely represent several implementation manners of this application. The description is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of this application. It should be noted that for those of ordinary skill in the art, without departing from the concept of this application, several modifications and improvements can still be made, and these all belong to the protection scope of this application. Therefore, the protection scope of this application shall be subject to the appended claims.
Claims
1. A program testing method, characterized in that: The method comprises: In response to a program test request for a program to be tested, obtaining input data for testing the program to be tested; The pre-built automated simulation program is used to simulate the program to be tested to process the input data, and the simulation operation result is obtained; Performing hash processing on the simulation running result of the current time to obtain the current running hash value corresponding to the simulation running result of the current time; Obtain a benchmark hash value, and determine that the running test result of the program to be tested passes when the current running hash value matches the benchmark hash value; the benchmark hash value is obtained by hashing the benchmark running result, and the benchmark running result is obtained by the benchmark program processing the input data.
2. The method according to claim 1, characterized in that The benchmark program is pre-burned in the hardware end; The program to be tested and the benchmark program correspond to the same target program; The obtaining of the reference hash value comprises: In the case where the simulation running result is the simulation running result of the automatic simulation program simulating the target program processing the input data for the first time, the input data is sent to the hardware end; the hardware end is used to run the input data through the pre-burned benchmark program to obtain an actual running result; Obtain a hash value corresponding to the actual operation result, and use the hash value corresponding to the actual operation result as the reference hash value.
3. The method according to claim 2, characterized in that After the hash value corresponding to the actual operation result is used as the reference hash value, the method further includes: When the hash value of the current operation matches the reference hash value, storing the hash value of the current operation as the first operation hash value of the target program; The obtaining of the reference hash value comprises: In the case that the simulation running result at the time is not the simulation running result of the first simulation of the target program processing the input data by the automated simulation program, the first running hash value stored is used as the reference hash value.
4. The method according to claim 1, characterized in that After performing hash processing on the simulation running result of the current time to obtain the current running hash value corresponding to the simulation running result of the current time, the method further includes: The hash value of the current operation is stored in a pre-constructed bidirectional linked list; wherein the structure of the bidirectional linked list is that the head node points to the head node, and the tail node points to the tail node.
5. The method according to claim 1, characterized in that The performing hash processing on the simulation running result of the current time to obtain the current running hash value corresponding to the simulation running result of the current time includes: Acquire a first data format corresponding to the input data and a second data format corresponding to the simulation running result; In the case where the second data format is different from the first data format, converting the data format of the simulation running result of the current time into the first data format to obtain the simulation running result of the current time after the data format conversion; The simulation running result of the current time after the data format conversion is hashed to obtain the hash value of the current time.
6. The method according to claim 1, characterized in that The step of obtaining input data for testing the program to be tested in response to a program test request for the program to be tested includes: Acquire the current time, and trigger multiple program test requests when the current time meets the preset trigger time of the scheduled task; When the number of the program test requests is greater than a preset number threshold, obtaining target program test requests whose number matches the preset number threshold from the plurality of program test requests; In response to target program test requests of a number matching the preset number threshold, input data for testing the program to be tested is acquired.
7. The method according to claim 1, characterized in that After determining that the running test result of the input data of the program to be tested passes, the method further includes: After the program to be tested is burned into the hardware end, a program running instruction for the program to be tested is initiated to the hardware end; the program running instruction is used to instruct the hardware end to run the program to be tested to generate a binary running result file for the program to be tested; The binary operation result file is displayed; the displayed binary operation result file is used to obtain the actual operation test result of the program to be tested.
8. A program testing device, characterized in that: The device comprises: An input data acquisition module, used for acquiring input data for testing the program to be tested in response to a program test request for the program to be tested; A simulation result acquisition module is used to simulate the program to be tested to process the input data through a pre-built automated simulation program to obtain the simulation operation result of the current time; A hash value acquisition module is used to perform hash processing on the simulation running result of the current time to obtain the current running hash value obtained by the simulation running result of the current time; A test result acquisition module is used to obtain a benchmark hash value, and determine that the running test result of the program to be tested passes when the current running hash value matches the benchmark hash value; the benchmark hash value is obtained by hashing the benchmark running result, and the benchmark running result is obtained by the benchmark program processing the input data.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.