Unit test method, device, equipment and medium

By obtaining and configuring preset files and executable code on the microcontroller, building the target running environment, the problem of inconsistency between the unit test environment and the actual running environment is solved, and accurate and reliable unit testing is achieved.

CN119440998APending Publication Date: 2025-02-14IMOTION AUTOMOTIVE TECH (SUZHOU) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411620611.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

The prior art is difficult to maintain consistency between the unit test environment and the actual operating environment in the microcontroller, resulting in the test results not being fully consistent with the actual operating conditions, and hidden code problems may not be discovered in time.

Method used

By obtaining preset configuration files and executable code files, configuring the microcontroller, building the target running environment, and running the executable code files in that environment for testing, ensuring the consistency between the test environment and the actual running environment.

Benefits of technology

It realizes monitoring the actual operation of the unit under test in the microcontroller, and displays the test process and results in real time to ensure the accuracy and reliability of the test results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440998A_ABST
    Figure CN119440998A_ABST
Patent Text Reader

Abstract

The invention discloses a unit testing method and device, equipment and a medium, and relates to the field of vehicle software and hardware testing, and the method comprises the steps: determining a to-be-tested unit, and obtaining a preset configuration file and an executable code file of the to-be-tested unit; the preset configuration file comprises a first configuration file used for configuring the unit to be tested and a second configuration file used for configuring a test environment; performing local configuration based on a preset configuration file to obtain a target operation environment, and loading the executable code file to a local target memory; the process of configuring the local comprises the steps of constructing a test case set, configuring register parameters and configuring interrupt parameters based on the load of the microcontroller; running the executable code file in a preset test period in the target running environment to test the unit to be tested; and transmitting the test process and the test result of the to-be-tested unit to a preset human-computer interaction interface in real time for display, and generating a test report based on the test result through the human-computer interaction interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of vehicle software and hardware testing, and in particular to a unit testing method, device, equipment and medium. Background Art

[0002] Unit testing refers to the inspection and verification of the smallest testable unit in the software. Unit testing is the most important activity for verifying code correctness and the most important part of system testing. It is especially critical for embedded systems with high requirements for security and reliability.

[0003] Usually, unit testing requires developers to write additional, specific code for testing, and the addition of test code will make the test code not exactly the same as the actual code. And for MCU (MicroController Unit) embedded software, due to the high correlation between its code and hardware, there is no universal unit testing framework. Usually, the solution of stripping the code to be tested for unit testing is adopted, which will lead to a large difference between the test environment of the unit under test and the actual operating environment, so that the test results are not completely consistent with the actual operating conditions, and some code problems may be hidden and cannot be discovered in time.

[0004] In summary, how to monitor the actual operation of the unit under test in the microcontroller and maintain the consistency between the test environment and the actual operation environment is a problem that needs to be solved. Summary of the invention

[0005] In view of this, the purpose of the present invention is to provide a unit testing method, device, equipment and medium, which can monitor the actual operation of the unit under test in the microcontroller and maintain the consistency between the test environment and the actual operation environment. The specific scheme is as follows:

[0006] In a first aspect, the present application discloses a unit testing method, which is applied to a microcontroller, comprising:

[0007] Determine a unit to be tested, and obtain a preset configuration file and an executable code file of the unit to be tested; wherein the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring a test environment;

[0008] The target operating environment is obtained by configuring the local system based on the preset configuration file, and the executable code file is loaded into the local target memory; wherein the process of configuring the local system includes constructing a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval;

[0009] Running the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested;

[0010] The test process and test results of the unit to be tested are transmitted in real time to a preset human-computer interaction interface for display, and a test report is generated based on the test results through the human-computer interaction interface.

[0011] Optionally, determining the unit to be tested includes:

[0012] Acquire each function symbol and corresponding executable code obtained after parsing the target file, and send each function symbol to the human-computer interaction interface for display;

[0013] Based on the selection instruction received by the human-computer interaction interface, a target function symbol is determined from all the function symbols, so as to determine the software unit corresponding to the target function symbol as the unit to be tested.

[0014] Optionally, obtaining a preset configuration file includes:

[0015] Extracting a first configuration file of the unit to be tested from the target file; wherein the first configuration file includes a function address, registers related to the function, and a memory address used by the function;

[0016] A second configuration file sent by the human-computer interaction interface is received; wherein the second configuration file includes an interrupt configuration method, data to be monitored, and a test case construction method.

[0017] Optionally, the load configuration interrupt parameter based on the microcontroller includes:

[0018] Determine the load rate of the microcontroller and the average running time of the unit to be tested without interruption, and determine a matching target interrupt frequency mode based on the average running time; wherein the target interrupt frequency mode includes a fixed interrupt frequency mode and a random interrupt frequency mode;

[0019] An interrupt generation interval is determined based on the load rate, the test period, and the average operating time in the target interrupt frequency mode.

[0020] Optionally, determining a matching target interrupt frequency pattern based on the average running time includes:

[0021] If the average running time is lower than a preset running time threshold, determining that the matched target interruption frequency mode is the fixed interruption frequency mode;

[0022] If the average running time is not less than the preset running time threshold, determining that the matched target interruption frequency pattern is the random interruption frequency pattern;

[0023] Accordingly, determining the interruption generation interval based on the load rate, the test cycle and the average running time in the target interruption frequency mode includes:

[0024] determining the interruption cumulative operation time based on the load rate, the test cycle and the average operation time;

[0025] In the fixed interrupt frequency mode, a ratio operation is performed on the interrupt cumulative running time and the preset single running time of the interrupt function to obtain a first interrupt generation frequency, and then a first interrupt period is determined based on the first interrupt generation frequency and the test period, and a difference between the first interrupt period and the preset single running time is determined as an interrupt generation interval;

[0026] In the random interrupt frequency mode, a random running time of each interrupt function is generated based on a random function; wherein the sum of all the random running times is the interrupt cumulative running time;

[0027] The total number of times the interrupt function is run is determined as the corresponding second interrupt generation frequency, and an average interrupt period is calculated based on the test period and the second interrupt generation frequency. Then, based on each random running time and the average interrupt period, a second interrupt period corresponding to each interrupt function is generated using a random function, so that the interrupt generation interval of each time is calculated using the second interrupt period and the random running time.

[0028] Optionally, the running of the executable code file within a preset test cycle to test the unit to be tested includes:

[0029] Determine the cycle start time and cycle end time based on a pre-set test cycle;

[0030] Determine a start test time based on a preset start offset value and the cycle start time, and run the executable code file at the start test time to test the unit to be tested;

[0031] During the test, an interruption is generated at a corresponding time node based on the interruption parameter, and the test is terminated when the cycle end time is reached.

[0032] Optionally, generating a test report based on the test result through the human-computer interaction interface includes:

[0033] Counting the total number of tests of the unit to be tested;

[0034] When the total number of tests reaches a preset number threshold, a test report is generated based on the test results corresponding to each test through the human-computer interaction interface.

[0035] In a second aspect, the present application discloses a unit testing device, which is applied to a microcontroller, comprising:

[0036] An information acquisition module, used to determine a unit to be tested, and to acquire a preset configuration file and an executable code file of the unit to be tested; wherein the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring a test environment;

[0037] A configuration module, configured to configure the local system based on the preset configuration file to obtain a target operating environment, and load the executable code file into the local target memory; wherein the process of configuring the local system includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval;

[0038] A test module, used to run the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested;

[0039] The display module is used to transmit the test process and test results of the unit to be tested to a preset human-computer interaction interface in real time for display, and to generate a test report based on the test results through the human-computer interaction interface.

[0040] In a third aspect, the present application discloses an electronic device, comprising:

[0041] Memory, used to store computer programs;

[0042] The processor is used to execute the computer program to implement the steps of the unit testing method disclosed above.

[0043] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed unit testing method are implemented.

[0044] It can be seen that the test process in the present application is applied to a microcontroller, and the microcontroller first determines the unit to be tested, and obtains a preset configuration file and an executable code file of the unit to be tested; wherein, the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring the test environment; based on the preset configuration file, the local is configured to obtain the target operating environment, and the executable code file is loaded into the local target memory; wherein, the process of configuring the local includes building a test case set, configuring register parameters and configuring interrupt parameters based on the load of the microcontroller, and the interrupt parameters include an interrupt frequency mode and an interrupt generation interval; the executable code file is run under the target operating environment and within a pre-set test cycle to test the unit to be tested; the test process and test results of the unit to be tested are transmitted in real time to a preset human-computer interaction interface for display, and a test report is generated based on the test results through the human-computer interaction interface.

[0045] Beneficial effects: The unit test process of the present application runs on an actual microcontroller. First, it is necessary to determine the unit to be tested, and obtain the preset configuration file and the executable code file of the unit to be tested. Among them, the preset configuration file mainly includes two types, namely a first configuration file for configuring the unit to be tested and a second configuration file for configuring the test environment. Furthermore, the present application uses the obtained preset configuration file to configure the microcontroller locally to obtain a real target operating environment, thereby maintaining the consistency between the test environment and the actual operating environment. The process of local configuration specifically includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller. By configuring the interrupt parameters, the actual operation of the target to be tested can be better simulated. The interrupt parameters specifically include the interrupt frequency mode and the interrupt generation interval. Further, the executable code file of the unit to be tested needs to be loaded into the local target memory. After the operating environment configuration is completed, the executable code file can be run in this environment and within a pre-set test cycle to test the unit to be tested, and the microcontroller will transmit the test process and test results of the unit to be tested in real time to the preset human-computer interaction interface for display, and generate a test report based on the test results through the human-computer interaction interface. In this way, the present application can monitor the actual operation of the unit to be tested in the microcontroller and display the test process and results in real time. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0047] Figure 1 A flow chart of a unit testing method disclosed in this application;

[0048] Figure 2 A timing diagram of a fixed interrupt frequency mode disclosed in the present application;

[0049] Figure 3 A timing diagram of a random interrupt frequency mode disclosed in the present application;

[0050] Figure 4 A specific unit testing method flow chart disclosed in this application;

[0051] Figure 5 A complete test process timing diagram disclosed in this application;

[0052] Figure 6 This is a schematic diagram of the structure of a unit test device disclosed in this application;

[0053] Figure 7 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0055] Normally, unit testing requires developers to write additional, specific code for testing, and the addition of test code will make the test code not exactly the same as the actual code. And for MCU embedded software, due to the high correlation between its code and hardware, there is no universal unit testing framework. Usually, the solution of stripping the code to be tested for unit testing will be adopted, which will lead to the problem that the test environment of the unit under test is quite different from the actual operating environment, so that the test results are not completely consistent with the actual operating conditions, and some code problems may be hidden and cannot be discovered in time. To this end, the embodiments of the present application disclose a unit testing method, device, equipment and medium, which can monitor the actual operation of the unit under test in a microcontroller and maintain the consistency of the test environment with the actual operating environment.

[0056] See also Figure 1 As shown, the embodiment of the present application discloses a unit testing method, which is applied to a microcontroller, and the method includes:

[0057] Step S11: determine a unit to be tested, and obtain a preset configuration file and an executable code file of the unit to be tested; wherein the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring a test environment.

[0058] The unit test process in this embodiment runs on an actual microcontroller. First, the unit to be tested needs to be determined, and a preset configuration file and an executable code file of the unit to be tested are obtained. The preset configuration file mainly includes two types, namely, a first configuration file for configuring the unit to be tested and a second configuration file for configuring the test environment.

[0059] Step S12: Based on the preset configuration file, the local configuration is performed to obtain the target operating environment, and the executable code file is loaded into the local target memory; wherein the process of configuring the local includes constructing a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval.

[0060] In this embodiment, the microcontroller is locally configured using the acquired preset configuration file to obtain a real target operating environment, thereby maintaining the consistency between the test environment and the actual operating environment, and the executable code file of the unit to be tested is loaded into the local target memory, which is ROM (Read-Only Memory) or RAM (Random Access Memory). Among them, the process of local configuration specifically includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller. The interrupt parameters specifically include the interrupt frequency mode and the interrupt generation interval. By configuring the interrupt parameters, the actual operation of the target to be tested can be better simulated.

[0061] In a specific implementation, the above-mentioned configuration of interrupt parameters based on the load of the microcontroller includes: determining the load rate of the microcontroller and the average running time of the unit to be tested without generating an interrupt, and determining a matching target interrupt frequency mode based on the average running time; wherein the target interrupt frequency mode includes a fixed interrupt frequency mode and a random interrupt frequency mode; in the target interrupt frequency mode, determining the interrupt generation interval based on the load rate, the test cycle and the average running time.

[0062] First of all, it should be pointed out that the present application can simulate the situation where the unit to be tested is interrupted by an interrupt by setting the timer interrupt of the MCU. First, the Counter register and Compare register of the timer are set to achieve the purpose of generating an interrupt at a specified interval. Specifically, the Counter register is used to record the count value of the timer, which increases or decreases over time, and the Compare register is used to set a comparison value. When the value of the Counter register is equal to the value of the Compare register, an interrupt will be generated. After the interrupt is generated, the MCU will jump to the interrupt processing function of the timer. After the specified running time is delayed, if the set number of interrupt runs is not reached, the timer will be set again. After the interrupt is processed, the MCU will return to the executable code of the unit to be tested to continue running. In addition, if the corresponding MCU hardware platform supports software-triggered interrupts, different interrupt types can be set according to requirements. Usually, the interrupt controller of the MCU can also provide priority configuration, so priority configuration can be achieved by setting relevant registers.

[0063] In addition to allowing users to configure interrupt parameters according to actual conditions, this application can also automatically configure interrupt parameters based on the load of the microcontroller. First, it is necessary to determine the load rate of the microcontroller and the average running time of the unit to be tested without interruption, so as to determine the target interrupt frequency mode that matches the average running time. The target interrupt frequency mode includes a fixed interrupt frequency mode and a random interrupt frequency mode. In this way, the interrupt generation interval can be determined based on the load rate, the pre-set test cycle and the average running time in the target interrupt frequency mode. Among them, the timing diagram of the fixed interrupt frequency mode is as follows Figure 2 As shown, the timing diagram of the random interrupt frequency mode is as follows Figure 3 shown.

[0064] Specifically, the above-mentioned determination of the matching target interrupt frequency mode based on the average running time includes: if the average running time is lower than the preset running time threshold, determining the matching target interrupt frequency mode to be the fixed interrupt frequency mode; if the average running time is not lower than the preset running time threshold, determining the matching target interrupt frequency mode to be the random interrupt frequency mode; accordingly, determining the interrupt generation interval based on the load rate, the test cycle and the average running time in the target interrupt frequency mode includes: determining the interrupt cumulative running time based on the load rate, the test cycle and the average running time; in the fixed interrupt frequency mode, performing a ratio operation on the interrupt cumulative running time and the preset single running time of the interrupt function to obtain the first interrupt generation interval. frequency, and then determine the first interruption period based on the first interruption generation frequency and the test period, and determine the difference between the first interruption period and the preset single running time as the interruption generation interval; in the random interruption frequency mode, generate the random running time of the interruption function each time based on the random function; wherein the sum of all the random running times is the interruption cumulative running time; determine the total number of running times of the interruption function as the corresponding second interruption generation frequency, and calculate the average interruption period based on the test period and the second interruption generation frequency, and then generate the second interruption period corresponding to each interruption function based on each random running time and the average interruption period and using the random function, so as to calculate the interruption generation interval each time using the second interruption period and the random running time.

[0065] That is, in this application, for the unit to be tested with a short average running time when there is no interruption, a fixed interrupt frequency mode is specifically adopted, and for the unit to be tested with a long average running time when there is no interruption, a random interrupt frequency mode is specifically adopted. First, from the perspective of test accuracy, for the unit to be tested with a short average running time when there is no interruption, the fixed interrupt frequency can ensure stable and predictable interrupt testing within a limited running time, which helps to accurately obtain the response characteristics of the software unit in this specific case. It is equivalent to extending its running time in disguise, which helps to reflect whether the unit can be executed correctly when the MCU is highly loaded, and for the unit to be tested with a long running time when there is no interruption, the random interrupt frequency is closer to the actual complex and changeable operating environment, and the adaptability and stability of the software unit under different random interrupt conditions can be tested, so as to more comprehensively detect the performance of the software unit. Secondly, from the perspective of efficiency, the fixed interrupt frequency is suitable for the unit to be tested with a short average running time when there is no interruption, and a relatively complete test process can be completed in a short time, saving test time. Although the random interrupt frequency seems complicated, for the unit to be tested with a long running time when there is no interruption, it can avoid special situations that may be missed in the overly long fixed cycle test, and improve the test efficiency in general. Finally, in terms of effect, this setting method can make the MCU software unit testing method more flexible and comprehensive, better adapt to the units under test in different operating conditions, improve the overall test quality, and ensure that the software units can work normally under various actual possible interruption scenarios.

[0066] When calculating the interruption generation interval, whether it is a fixed interruption frequency mode or a random interruption frequency mode, it is necessary to first determine the interruption cumulative running time based on the load rate, the test cycle and the average running time, and then in the fixed interruption frequency mode, perform a ratio operation on the interruption cumulative running time and the preset single running time of the interruption function, so as to use the ratio operation result as the corresponding first interruption generation frequency, and then determine the corresponding first interruption cycle based on the first interruption generation frequency and the test cycle, and determine the difference between the first interruption cycle and the preset single running time as the interruption generation interval in the fixed interruption frequency mode. In the random interruption frequency mode, firstly, it is necessary to generate the random running time of the interruption function each time based on the random function, and the sum of all random running times needs to be the same as the value of the interruption cumulative running time. Further, the total number of operations of the interruption function is determined as the corresponding second interruption generation frequency, and the average interruption cycle is first calculated based on the test cycle and the second interruption generation frequency, and then the second interruption cycle corresponding to each interruption function is generated based on each random running time and the average interruption cycle and using the random function, so as to use the second interruption cycle and the corresponding random running time to perform a difference calculation to obtain each interruption generation interval.

[0067] The following are specific examples of two interrupt frequency modes given in this application:

[0068] Example 1: Set the MCU load rate to 80%, the test cycle to 10ms, the average running time of the unit under test without interruption to 2ms, and use the fixed interrupt frequency mode;

[0069] The calculation process of the interrupt cumulative running time is: Trun = 10ms × 80% - 2ms = 6ms;

[0070] Let the single running time of the interrupt processing function be Tisr=0.2ms;

[0071] The calculation process of the initial / final interrupt generation frequency is: fisr=Trun / Tisr=6ms / 0.2ms=30;

[0072] The calculation process of the interruption period is: Pisr=10ms / fisr=10ms / 30=0.33ms;

[0073] The calculation process of the interrupt generation interval is: Tinv = Pisr-Tisr = 0.33ms–0.2ms = 0.13ms;

[0074] It is calculated that in this mode, the interrupt function will be generated 30 times at an interval of 0.13ms, and each execution time is 0.2ms.

[0075] Example 2: Set the MCU load rate to 60%, the test cycle to 20ms, the average running time of the unit under test without interruption to 8ms, and use the random interrupt frequency mode;

[0076] The calculation process of the interrupt cumulative running time is: Trun=20ms*60%-8ms=4ms;

[0077] Randomly generate the running time of each interrupt processing function to obtain a random running time, assuming that the random range is 0.2ms~0.8ms:

[0078] Tisr_1=Rand(0.2,0.8)=0.5ms;

[0079] Tisr_2=Rand(0.2, 0.8)=0.3ms;

[0080] Repeat the above steps to obtain Tisr_1~Tisr_N, where N is the total number of times the interrupt function is run. The following conditions must be met during calculation:

[0081] ;

[0082] The total number of times the interrupt function is run is the corresponding interrupt generation frequency. Assuming N=12, the average interrupt cycle can be calculated based on the test cycle and the interrupt generation frequency.

[0083] =20ms / N=20ms / 12=1.66ms;

[0084] Then, based on each random running time and the average interruption period, a random function is used to generate the second interruption period corresponding to each interruption function, where the period of the first interruption is:

[0085] Pisr_1=Rand(Tisr_1, )=Rand(0.5,1.66)=0.9ms;

[0086] Calculate the interruption period of Pisr_2~Pisr_N:

[0087] Pisr_n=Rand(Tisr_n, +( - Pisr_(n-1))), n=2, 3,…N;

[0088] For example: Pisr_2=Rand(Tisr_2, +( -Pisr_1))= Rand(0.5, 2.42)=1.7ms;

[0089] Finally, the difference between the second interrupt cycle and the corresponding random running time is calculated to obtain the interval between each interrupt:

[0090] Tinv_n= Pisr_n-Tisr_n, n=1, 2,...N;

[0091] For example: Tinv_1=Pisr_1-Tisr_1=0.9ms–0.5ms=0.4ms;

[0092] For example: Tinv_2 = Pisr_2 - Tisr_2 = 1.7ms – 0.3ms = 1.4ms;

[0093] Through the above calculation, a complete interrupt configuration can be obtained:

[0094] Interrupt 1 is generated at time T0 and runs for 0.5ms (Tisr_1), then interrupt 2 is generated after an interval of 0.4ms (Tinv_1);

[0095] After interrupt 2 runs for 0.3ms (Tisr_2), interrupt 3 is generated after an interval of 1.4ms (Tinv_2);

[0096] And so on, until interrupt N is generated.

[0097] Step S13: running the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested.

[0098] In this embodiment, after the running environment configuration is completed, the executable code file can be run in the environment and within a preset test cycle to test the unit to be tested.

[0099] Step S14: transmitting the test process and test results of the unit to be tested to a preset human-computer interaction interface in real time for display, and generating a test report based on the test results through the human-computer interaction interface.

[0100] In this embodiment, the microcontroller will transmit the test process and test results of the unit to be tested in real time to a preset human-computer interaction interface for display, and generate a test report based on the test results through the human-computer interaction interface. In this way, through the above scheme, the present application can monitor the actual operation of the unit to be tested in the microcontroller, and display the test process and results in real time.

[0101] It can be seen that the unit test process of the present application runs on an actual microcontroller. First, it is necessary to determine the unit to be tested, and obtain the preset configuration file and the executable code file of the unit to be tested. Among them, the preset configuration file mainly includes two types, namely a first configuration file for configuring the unit to be tested and a second configuration file for configuring the test environment. Further, the present application uses the obtained preset configuration file to configure the microcontroller locally to obtain a real target operating environment, thereby maintaining the consistency between the test environment and the actual operating environment. The process of local configuration specifically includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller. By configuring the interrupt parameters, the actual operation of the target to be tested can be better simulated. The interrupt parameters specifically include the interrupt frequency mode and the interrupt generation interval. Further, the executable code file of the unit to be tested needs to be loaded into the local target memory. After the operating environment configuration is completed, the executable code file can be run in this environment and within a pre-set test cycle to test the unit to be tested, and the microcontroller will transmit the test process and test results of the unit to be tested in real time to the preset human-computer interaction interface for display, and generate a test report based on the test results through the human-computer interaction interface. In this way, the present application can monitor the actual operation of the unit to be tested in the microcontroller and display the test process and results in real time.

[0102] See also Figure 4 As shown, the embodiment of the present application discloses a specific unit testing method. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, it includes:

[0103] Step S21: Obtain each function symbol and the corresponding executable code obtained after parsing the target file, and send each function symbol to the human-computer interaction interface for display, and determine the target function symbol from all the function symbols based on the selection instruction received by the human-computer interaction interface to determine the software unit corresponding to the target function symbol as the unit to be tested.

[0104] In this embodiment, after the MCU embedded software is integrated, target files such as bin and elf are usually obtained. The function symbols and corresponding executable codes in the program can be obtained by parsing these two files. The parsed function symbols are sent to the human-computer interaction interface for display. The user can select the function symbols to be tested through the human-computer interaction interface and issue corresponding selection instructions. In this way, the target function symbol that the user needs to test can be determined from all function symbols based on the selection instructions received by the human-computer interaction interface, and the software unit corresponding to the target function symbol is determined as the unit to be tested.

[0105] Step S22: extract a first configuration file for configuring the unit to be tested from the target file, and receive a second configuration file for configuring the test environment sent by the human-computer interaction interface; the first configuration file includes a function address, registers related to the function, and a memory address used by the function, and the second configuration file includes an interrupt configuration method, data to be monitored, and a test case construction method.

[0106] In this embodiment, a first configuration file for configuring the unit to be tested is extracted from the target file, and the first configuration file specifically includes information such as function addresses, registers related to the function, and memory addresses used by the content function, i.e., content. The user can configure the test operation environment of the MCU through the human-computer interaction interface, such as whether to allow MCU interrupts, interruption generation intervals, interruption time, data to be monitored, custom test cases, etc. Through these configurations, the operating environment in the actual product can be more realistically simulated, and a second configuration file for configuring the test environment is generated after the configuration is completed. After the first configuration file and the second configuration file are configured, they are sent to the microcontroller through the communication cable.

[0107] Step S23: Based on the preset configuration file, the local configuration is performed to obtain the target operating environment, and the executable code file is loaded into the local target memory; wherein the process of configuring the local includes constructing a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval.

[0108] In this embodiment, the microcontroller loads the executable code at a specified location according to the received configuration file, prepares a test case data set, configures related MCU registers, configures MCU interrupts, etc.

[0109] Step S24: running the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested.

[0110] In this embodiment, the above-mentioned running the executable code file within a preset test cycle to test the unit to be tested includes: determining the cycle start time and the cycle end time based on the preset test cycle; determining the start test time based on a preset start offset value and the cycle start time, and running the executable code file at the start test time to test the unit to be tested; generating an interrupt at a corresponding time node based on the interrupt parameter during the test, and terminating the test when the cycle end time is reached.

[0111] like Figure 5 As shown, Figure 5 This is a complete test process timing diagram disclosed in this application. First, the configuration of the operating environment is completed at time T0, and the executable code file is loaded into the specified location (ROM or RAM). T1 to T3 is a test cycle, T1 is the start time of the cycle, and T3 is the end time of the cycle, that is, this cycle test starts at time T1. This application also sets a preset starting offset value T offset , through the starting offset value T offset The start test time T2 is determined by the cycle start time T1 to simulate the actual position of the function in the actual running process. At the start test time T2, the executable code file is started to test the unit to be tested (i.e., the unit under test in the figure). During the test, an interrupt is generated at the corresponding time node based on the interrupt parameter, and the test is terminated when the cycle end time is reached. If the unit to be tested is not executed, it is forced to terminate and the running timeout is recorded.

[0112] Step S25: The test process and test results of the unit to be tested are transmitted in real time to a preset human-computer interaction interface for display, and the total number of tests of the unit to be tested is counted. When the total number of tests reaches a preset threshold, a test report is generated through the human-computer interaction interface based on the test results corresponding to each test.

[0113] In this embodiment, the operation status will be monitored in real time during the test process, and the test process and results will be transmitted in real time to the human-computer interaction interface through the communication cable for display. After a cycle of testing is completed, the test results and the operation status of the unit to be tested will be checked and counted, and the total number of tests of the unit to be tested will be counted. When the total number of tests reaches the preset number threshold, a test report is generated based on the test results corresponding to each test through the human-computer interaction interface, including code coverage, branch coverage and other information.

[0114] For more specific processing procedures of the above steps S23 and S24, reference may be made to the corresponding contents disclosed in the above embodiments, which will not be described in detail here.

[0115] It can be seen that this application uses the MCU embedded software integrated by the normal process, without adding additional code, thus ensuring consistency with the actual running code. In addition, this application performs unit testing on real hardware, which is more in line with the actual product operation, making it easier to find software bugs related to hardware, and finally displays the test process and results in real time through the human-computer interaction module interface.

[0116] See also Figure 6 As shown, the embodiment of the present application discloses a unit testing device, which is applied to a microcontroller, and the device includes:

[0117] The information acquisition module 11 is used to determine the unit to be tested and obtain a preset configuration file and an executable code file of the unit to be tested; wherein the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring a test environment;

[0118] A configuration module 12 is used to configure the local system based on the preset configuration file to obtain a target operating environment, and load the executable code file into the local target memory; wherein the process of configuring the local system includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval;

[0119] A testing module 13, configured to run the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested;

[0120] The display module 14 is used to transmit the test process and test results of the unit to be tested to a preset human-computer interaction interface in real time for display, and to generate a test report based on the test results through the human-computer interaction interface.

[0121] It can be seen that the unit test process of the present application runs on an actual microcontroller. First, it is necessary to determine the unit to be tested, and obtain the preset configuration file and the executable code file of the unit to be tested. Among them, the preset configuration file mainly includes two types, namely a first configuration file for configuring the unit to be tested and a second configuration file for configuring the test environment. Further, the present application uses the obtained preset configuration file to configure the microcontroller locally to obtain a real target operating environment, thereby maintaining the consistency between the test environment and the actual operating environment. The process of local configuration specifically includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller. By configuring the interrupt parameters, the actual operation of the target to be tested can be better simulated. The interrupt parameters specifically include the interrupt frequency mode and the interrupt generation interval. Further, the executable code file of the unit to be tested needs to be loaded into the local target memory. After the operating environment configuration is completed, the executable code file can be run in this environment and within a pre-set test cycle to test the unit to be tested, and the microcontroller will transmit the test process and test results of the unit to be tested in real time to the preset human-computer interaction interface for display, and generate a test report based on the test results through the human-computer interaction interface. In this way, the present application can monitor the actual operation of the unit to be tested in the microcontroller and display the test process and results in real time.

[0122] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the unit test method performed by the electronic device disclosed in any of the aforementioned embodiments.

[0123] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0124] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0125] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222 and data 223, etc. The storage method can be temporary storage or permanent storage.

[0126] Among them, the operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21, which can be Windows, Unix, Linux, etc. In addition to including a computer program that can be used to complete the unit test method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks. In addition to data transmitted from an external device received by the electronic device, the data 223 can also include data collected by its own input and output interface 25, etc.

[0127] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the unit testing method steps disclosed in any of the aforementioned embodiments are implemented.

[0128] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0129] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0130] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a compact disc read-only memory (CD-ROM), or any other form of storage medium known in the art.

[0131] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0132] The above is a detailed introduction to a unit testing method, device, equipment and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A unit testing method, characterized in that: Applications in microcontrollers, including: Determine a unit to be tested, and obtain a preset configuration file and an executable code file of the unit to be tested; wherein the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring a test environment; The target operating environment is obtained by configuring the local system based on the preset configuration file, and the executable code file is loaded into the local target memory; wherein the process of configuring the local system includes constructing a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval; Running the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested; The test process and test results of the unit to be tested are transmitted in real time to a preset human-computer interaction interface for display, and a test report is generated based on the test results through the human-computer interaction interface.

2. The unit testing method according to claim 1, characterized in that: The step of determining the unit to be tested includes: Acquire each function symbol and corresponding executable code obtained after parsing the target file, and send each function symbol to the human-computer interaction interface for display; Based on the selection instruction received by the human-computer interaction interface, a target function symbol is determined from all the function symbols, so as to determine the software unit corresponding to the target function symbol as the unit to be tested.

3. The unit testing method according to claim 2, characterized in that: The obtaining of the preset configuration file comprises: Extracting a first configuration file of the unit to be tested from the target file; wherein the first configuration file includes a function address, registers related to the function, and a memory address used by the function; A second configuration file sent by the human-computer interaction interface is received; wherein the second configuration file includes an interrupt configuration method, data to be monitored, and a test case construction method.

4. The unit testing method according to claim 1, characterized in that: The load configuration interruption parameter based on the microcontroller includes: Determine the load rate of the microcontroller and the average running time of the unit to be tested without interruption, and determine a matching target interrupt frequency mode based on the average running time; wherein the target interrupt frequency mode includes a fixed interrupt frequency mode and a random interrupt frequency mode; An interrupt generation interval is determined based on the load rate, the test period, and the average operating time in the target interrupt frequency mode.

5. The unit testing method according to claim 4, characterized in that: The determining of a matching target interruption frequency pattern based on the average running time comprises: If the average running time is lower than a preset running time threshold, determining that the matched target interruption frequency mode is the fixed interruption frequency mode; If the average running time is not less than the preset running time threshold, determining that the matched target interruption frequency pattern is the random interruption frequency pattern; Accordingly, determining the interruption generation interval based on the load rate, the test cycle and the average running time in the target interruption frequency mode includes: determining the interruption cumulative operation time based on the load rate, the test cycle and the average operation time; In the fixed interrupt frequency mode, a ratio operation is performed on the interrupt cumulative running time and the preset single running time of the interrupt function to obtain a first interrupt generation frequency, and then a first interrupt period is determined based on the first interrupt generation frequency and the test period, and a difference between the first interrupt period and the preset single running time is determined as an interrupt generation interval; In the random interrupt frequency mode, a random running time of each interrupt function is generated based on a random function; wherein the sum of all the random running times is the interrupt cumulative running time; The total number of times the interrupt function is run is determined as the corresponding second interrupt generation frequency, and an average interrupt period is calculated based on the test period and the second interrupt generation frequency. Then, based on each random running time and the average interrupt period, a second interrupt period corresponding to each interrupt function is generated using a random function, so that the interrupt generation interval of each time is calculated using the second interrupt period and the random running time.

6. The unit testing method according to claim 1, characterized in that: The step of running the executable code file within a preset test cycle to test the unit to be tested includes: Determine the cycle start time and cycle end time based on a pre-set test cycle; Determine a start test time based on a preset start offset value and the cycle start time, and run the executable code file at the start test time to test the unit to be tested; During the test, an interruption is generated at a corresponding time node based on the interruption parameter, and the test is terminated when the cycle end time is reached.

7. The unit testing method according to any one of claims 1 to 6, characterized in that: Generating a test report based on the test result through the human-computer interaction interface includes: Counting the total number of tests of the unit to be tested; When the total number of tests reaches a preset number threshold, a test report is generated based on the test results corresponding to each test through the human-computer interaction interface.

8. A unit testing device, characterized in that: Applications in microcontrollers, including: An information acquisition module, used to determine a unit to be tested, and to acquire a preset configuration file and an executable code file of the unit to be tested; wherein the preset configuration file includes a first configuration file for configuring the unit to be tested and a second configuration file for configuring a test environment; A configuration module, configured to configure the local system based on the preset configuration file to obtain a target operating environment, and load the executable code file into the local target memory; wherein the process of configuring the local system includes building a test case set, configuring register parameters, and configuring interrupt parameters based on the load of the microcontroller, wherein the interrupt parameters include an interrupt frequency mode and an interrupt generation interval; A test module, used to run the executable code file in the target operating environment and within a preset test cycle to test the unit to be tested; The display module is used to transmit the test process and test results of the unit to be tested to a preset human-computer interaction interface in real time for display, and to generate a test report based on the test results through the human-computer interaction interface.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the unit testing method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the steps of the unit testing method according to any one of claims 1 to 7 are implemented.