State machine testing method and device, electronic equipment and readable storage medium
By automatically acquiring and sending signals to test the state machine, the problems of low efficiency and poor accuracy of state machine testing in the existing technology are solved, and efficient and accurate state machine testing is achieved.
Patent Information
- Application Number
- CN202310213425.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-07
- Publication Date
- 2024-09-10
AI Technical Summary
The state machine testing efficiency in the existing technology is low and the test results are inaccurate, mainly because manual testing requires a lot of time and energy, and instability leads to incorrect results.
By obtaining the status value output by the state machine, the appropriate signal is automatically determined and sent to the state machine, and test results are generated based on the response status value to achieve automated testing, avoid manual errors and improve efficiency.
It realizes automated state machine testing, improves testing efficiency, ensures the accuracy of test results, and avoids errors and instability of manual testing.
Smart Images

Figure CN118625002A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing technology, and in particular to a state machine testing method, device, electronic equipment and readable storage medium. Background Art
[0002] The state machine can jump between multiple states. When the state machine is in different states, it will output different state values. The state machine runs by responding to the output signal. When the input signal of the state machine meets the state jump condition, it will cause the state machine to jump from one state to another. State machines are widely used in various fields, and state machines are used in many scenarios, such as autonomous driving, e-commerce and other fields. In the application process of state machines, it is often necessary to test the state machine.
[0003] In the related art, in order to test the state machine, technicians need to use manual testing methods to input appropriate test signals into the state machine to make the state machine jump, and record the state value output after the state machine jumps, and then determine whether the state value output by the state machine is correct. The tester needs to repeat the above process continuously to use as many test signals as possible to test the state machine.
[0004] However, due to the complexity of the state changes of the state machine, manual testing requires a lot of time and energy of testers, and the test efficiency is also low. In addition, due to the instability of manual testing, it is easy to cause inaccurate test results. Summary of the invention
[0005] In view of this, the present invention aims to provide a state machine testing method, device, electronic device and readable storage medium to solve the problems of low efficiency and inaccurate test results when testing a state machine in the prior art.
[0006] To achieve the above object, the technical solution of the present invention is achieved as follows:
[0007] Obtain the first state value output by the state machine;
[0008] Determine a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal;
[0009] Sending the first signal to the state machine, and obtaining a second state value output by the state machine in response to the first signal;
[0010] A test result is generated according to the second state value and the target state value.
[0011] Optionally, determining a first signal according to the first state value includes:
[0012] Obtaining a starting state value corresponding to a test case set; wherein the test cases in the test case set are composed of a starting state value, a target state value, and a test signal for adjusting the state value output by the state machine from the starting state value to the target state value;
[0013] Matching the first state value with the initial state values corresponding to all test case sets to determine a first test case set corresponding to the first state value;
[0014] A first test case is obtained from the first test case set, and a first signal is determined according to a test signal of the first test case.
[0015] Optionally, the method comprises:
[0016] Determine a state value switching mode corresponding to the state machine; wherein the state value switching mode is composed of an initial state value and a target state value;
[0017] For each of the state value switching modes, a test signal corresponding to the state value switching mode is generated; wherein the test signal is used to adjust the state value output by the state machine from the starting state value corresponding to the state value switching mode to the target state value corresponding to the state value switching mode;
[0018] For each of the state value switching modes, a test case set corresponding to the state value switching mode is generated by using a test signal, an initial state value and a target state value corresponding to the state value switching mode.
[0019] Optionally, obtaining the first test case from the first test case set includes:
[0020] Determine, according to the historical test information, the historical test cases that have been tested in the first test case set;
[0021] Removing the historical test cases from the first test case set to obtain a target test case set;
[0022] A first test case is obtained from the target test case set.
[0023] Optionally, generating a test result according to the second state value and the target state value includes:
[0024] Determine a second test case set corresponding to the second state value, and test the state machine using a second signal determined based on the test cases in the second test case set until all test cases in all test case sets are traversed;
[0025] A test result is generated according to the state value output by the state machine for each test case in all test case sets.
[0026] Optionally, determining a second test case set corresponding to the second state value includes:
[0027] In a case where the second state value matches the target state value, determining a second test case set corresponding to the second state value;
[0028] When the second state value does not match the target state value, the test process is terminated and the first test case and the second state value are output to the user.
[0029] Optionally, generating a test result according to a state value output by the state machine for each test case in all test case sets includes:
[0030] When the state value output by the state machine for each test case in all the test case sets matches the target state value of the corresponding test case, determining that the test result is a test pass;
[0031] When the state value output by the state machine for at least one test case in the set of all test cases does not match the target state value of the corresponding test case, the test result is determined to be a test failure.
[0032] A state machine testing device, the device comprising:
[0033] An acquisition module, used for acquiring a first state value output by the state machine;
[0034] A determination module, configured to determine a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal;
[0035] a sending module, configured to send the first signal to the state machine, and obtain a second state value output by the state machine in response to the first signal;
[0036] A result module is used to generate a test result according to the second state value and the target state value.
[0037] Optionally, the determining module includes:
[0038] A starting state value submodule, used to obtain a starting state value corresponding to a test case set; wherein the test case in the test case set is composed of a starting state value, a target state value, and a test signal for adjusting the state value output by the state machine from the starting state value to the target state value;
[0039] A first test case set submodule, configured to match the first state value with the starting state values corresponding to all test case sets, and determine a first test case set corresponding to the first state value;
[0040] The first signal submodule is used to obtain a first test case from the first test case set and determine a first signal according to a test signal of the first test case.
[0041] Optionally, the device comprises:
[0042] A state value switching mode submodule is used to determine the state value switching mode corresponding to the state machine; wherein the state value switching mode is composed of a starting state value and a target state value;
[0043] A test signal generation submodule, for generating a test signal corresponding to each state value switching mode; wherein the test signal is used to adjust the state value output by the state machine from the starting state value corresponding to the state value switching mode to the target state value corresponding to the state value switching mode;
[0044] The test case set generation submodule is used to generate a test case set corresponding to each state value switching mode by using the test signal, starting state value and target state value corresponding to the state value switching mode.
[0045] Optionally, the first signal submodule includes:
[0046] A historical test case module, configured to determine, based on historical test information, historical test cases that have been tested in the first test case set;
[0047] A target test case set submodule, configured to remove the historical test case from the first test case set to obtain a target test case set;
[0048] The first test case submodule is used to obtain a first test case from the target test case set.
[0049] Optionally, the result module includes:
[0050] A traversal test submodule, used to determine a second test case set corresponding to the second state value, and use a second signal determined based on the test case of the second test case set to test the state machine until all test cases in all test case sets are traversed;
[0051] The test result submodule is used to generate a test result according to the state value output by the state machine for each test case in the set of all test cases.
[0052] Optionally, the traversal test submodule includes:
[0053] A second test case set submodule, configured to determine a second test case set corresponding to the second state value when the second state value matches the target state value;
[0054] A termination submodule is used to terminate the test process and output the first test case and the second state value to the user when the second state value does not match the target state value.
[0055] Optionally, the test result submodule includes:
[0056] A first test result submodule, configured to determine that the test result is a test pass when the state value output by the state machine for each test case in all test case sets matches the target state value of the corresponding test case;
[0057] The second test result submodule is used to determine that the test result is a test failure when the state value output by the state machine for at least one test case in all test case sets does not match the target state value of the corresponding test case.
[0058] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the state machine testing method when executing the computer program.
[0059] A readable storage medium stores a program or instruction, and the program or instruction implements the state machine testing method when executed by a processor.
[0060] Compared with the prior art, the state machine testing method, device, electronic device and readable storage medium described in the present invention have the following advantages:
[0061] In summary, an embodiment of the present invention provides a state machine testing method, including: obtaining a first state value output by a state machine; determining a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal; sending the first signal to the state machine, and obtaining a second state value output by the state machine in response to the first signal; and generating a test result according to the second state value and the target state value. In an embodiment of the present invention, a suitable signal can be automatically selected to test the state machine according to the state value output by the state machine, thereby avoiding errors that may occur in manually testing the state machine. At the same time, by automatically determining the test signal and automatically generating the test result, the test efficiency of the state machine is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:
[0063] Figure 1 A flow chart of the steps of a state machine testing method provided by an embodiment of the present invention;
[0064] Figure 2 Another state machine testing method step flow chart provided by an embodiment of the present invention;
[0065] Figure 3 A schematic diagram of a test case set provided by an embodiment of the present invention;
[0066] Figure 4 A schematic diagram of another test case set provided by an embodiment of the present invention;
[0067] Figure 5 A structural block diagram of a state machine testing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0068] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0069] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0070] Reference Figure 1 , Figure 1 A flow chart of the steps of a state machine testing method provided by an embodiment of the present invention.
[0071] Step 101, obtaining a first state value output by a state machine.
[0072] A finite-state machine (FSM), also known as a finite state machine or an automatic state machine (FSA), is a mathematical model that represents a finite number of states and the transitions and actions between these states. A state machine is a type of automaton studied in automata theory and computational theory. It can jump between multiple states based on input signals and output a variety of different state values.
[0073] State machines can be widely used in different scenarios. For example, in an autonomous driving scenario, the vehicle's autonomous driving system can be connected to a state machine, and the state machine receives the vehicle sensor signal, jumps between different states according to the input sensor signal, and outputs a state value indicating the current state of the vehicle to the autonomous driving system, wherein the vehicle can be an unmanned logistics vehicle, a fuel vehicle, an electric vehicle, etc. For example, the state machine can receive the acceleration signal of the acceleration sensor mounted on the vehicle, and output a state value that can represent the current state of motion of the vehicle according to the acceleration signal. If the current acceleration of the vehicle is a positive value, the state machine can jump to the vehicle acceleration state after receiving the acceleration signal, and output a state value representing that the vehicle is in an accelerated state. At the next moment, the state machine receives a signal that the acceleration of the vehicle is 0, and the state machine outputs a state value representing that the vehicle is in a uniform linear motion. At the next moment, the state machine receives a negative value for the acceleration of the vehicle, and the state machine outputs a state value representing that the vehicle is in a deceleration state.
[0074] Generally speaking, after the state machine is started, it will continuously output the state value according to the built-in circuit or program, and the output state value will change with the change of the input signal. For example, after the state machine is started from the power-off state, it will be initialized first, and after the initialization is completed, an initial state value will be output. The initial state value can be used to notify other systems or modules that the state value has been initialized and is waiting for the input of a valid signal. The initial state value may have a certain meaning or may not have any meaning. For example, if the state machine is used to output a state value representing the motion state of the vehicle, the initial state value output after the state machine is started may indicate that the vehicle is in a waiting state, or it may not represent any vehicle state.
[0075] In an embodiment of the present invention, the first state value being output by the state machine can be obtained when the state machine is started, or the first state value output by the state machine can be obtained a period of time after the state machine is started. Therefore, in an embodiment of the present invention, the first state value can be the initial state value of the state machine, or it can be any state value that the state machine can output except the initial state value.
[0076] Specifically, the state value output by the state machine can be continuously monitored by connecting to the state output port of the state machine, so as to obtain the first state value output by the state machine from the output port of the state machine. It should be noted that in the embodiment of the present invention, the state machine can be a program running in an electronic device or an independent physical terminal, and the embodiment of the present invention does not specifically limit the specific form of the state machine.
[0077] Step 102, determining a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal.
[0078] Based on the operating principle of the state machine, each state machine can have multiple preset state values that can be output, and every two different state values among the preset state values can constitute a state value switching mode, and the state machine can switch the state between the two preset state values contained in each state value switching mode. It should be noted that two different preset state values are combined in different orders, and the state value switching modes formed are different. For example, a state value switching mode of a state machine includes preset state value A and preset state value B, then a state value switching mode can be (preset state value A, preset state value B), and the state value switching mode indicates that the state value output by the state machine can be directly switched from preset state value A to preset state value B, and another state value switching mode can be (preset state value B, preset state value A), and the state value switching mode indicates that the state value output by the state machine can be directly switched from preset state value B to preset state value A. It is easy to understand that the state machine can also include only one of the above two state value switching modes, and the above state machine cannot perform the state value switching mode indicated by the other state value switching mode.
[0079] In addition, according to the settings of the technicians, all state value switching modes corresponding to a state machine can exhaust all combinations of different preset state values, or only include some combinations of different preset state values. For example, a state machine can output three state values, namely preset state value A, preset state value B and preset state value C, then the state machine can have up to six state value switching modes: (preset state value A, preset state value B), (preset state value A, preset state value C), (preset state value B, preset state value C), (preset state value C, preset state value B), (preset state value C, preset state value B), (preset state value C, preset state value A) and (preset state value B, preset state value A). The technicians can make the state machine support the above six state value switching modes at the same time, or only support one or more of the above six state value switching modes.
[0080] Normally, in order to switch the state value output by the state machine from one preset state value to another preset state value, that is, to implement a state value switching method, it is necessary to make the state machine receive a signal corresponding to the state value switching method. For example, for a state machine used to output the motion state of a vehicle, one of its state value switching methods may be (acceleration state, uniform motion state). In the case where the state machine outputs the preset state value corresponding to the acceleration state, if the state machine receives a signal with an acceleration of 0, the state machine can jump to the uniform motion state and output a preset state value indicating the uniform motion state.
[0081] Therefore, in an embodiment of the present invention, a corresponding test signal can be set for each preset state value, and the test signal is used to switch the preset state value output by the state machine to another preset state value. For example, a state machine can output three state values, namely preset state value A, preset state value B and preset state value C. The state machine has three state value switching modes: (preset state value A, preset state value B), (preset state value B, preset state value C), (preset state value C, preset state value A). Then, for the above three state value switching modes, three test signal sets are set respectively. The test signals contained in each test signal set can be used to input the state machine and enable the state machine to implement a state value switching mode. It should be noted that each test signal set can contain only one test signal or multiple different test signals. These multiple test signals in the same test signal set can enable the state machine to implement the state value switching mode corresponding to the test signal set.
[0082] Since a preset state value may be used as the starting state value in multiple state value switching modes (i.e., the state value arranged first in the above-mentioned state value switching mode), and each state value switching mode corresponds to a test signal set, therefore, in an embodiment of the present invention, each preset state value may correspond to multiple test signal sets.
[0083] In an embodiment of the present invention, after receiving the first state value currently being output by the state machine, the first state value can be matched with all preset state values, and a set of all test signals corresponding to the preset state values that match the first state value can be determined, and then a test signal is obtained from the set of all test signals corresponding to the preset state values that match the first state value as the first signal, so that the second state value in the state value switching mode corresponding to the test signal as the first signal is the target state value corresponding to the first signal, and the first signal can be used to adjust the state value output by the state machine to the target state value.
[0084] Step 103: Send the first signal to the state machine, and obtain a second state value output by the state machine in response to the first signal.
[0085] After the first signal is determined according to the first state value, the first signal can be sent to the state machine, the state machine receives the first signal and changes the output state value, and then obtains the second state value output by the state machine. The second state value is checked in subsequent operations to test the state machine.
[0086] It should be noted that since the embodiment of the present invention tests the state machine, the state value output by the state machine may be normal or abnormal, the state machine may respond to the first signal correctly or incorrectly, and when the state machine responds to the first signal correctly, the state value output by the state machine will change, and when the state machine responds to the first signal incorrectly, the state value output by the state machine may not change. Therefore, in the embodiment of the present invention, the first state value and the second state value may be the same or different.
[0087] Generally speaking, a state machine generally has an output interface and an input interface. The input interface is used to receive input signals, and the output interface is used to output state values. In an embodiment of the present invention, a first signal can be sent to the state machine through the input interface of the state machine, and the output interface of the state machine can be monitored to obtain the second state value output by the state machine after responding to the first signal.
[0088] Step 104: Generate a test result according to the second state value and the target state value.
[0089] After obtaining the second state value, the second state value can be compared with the target state value in the state value switching mode corresponding to the first signal (i.e., the state value arranged in the second position in the above state value switching mode). If the second state value is the same as the target state value corresponding to the first signal, it means that the state machine responds normally to the first signal and can pass the test of the first signal. At this time, the result of passing the test for the first signal can be output. If the second state value is different from the target state value, it means that the state machine responds abnormally to the first signal and cannot pass the test of the first signal. The test can output the result of failing the test for the first signal.
[0090] Furthermore, all test signals may be used to test the state machine, and after determining that the state machine can correctly respond to all test signals, it is determined that the state machine has passed the test. If the state machine cannot correctly respond to at least one test signal, it can be determined that the state machine has failed the test.
[0091] In summary, an embodiment of the present invention provides a state machine testing method, including: obtaining a first state value output by a state machine; determining a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal; sending the first signal to the state machine, and obtaining a second state value output by the state machine in response to the first signal; and generating a test result according to the second state value and the target state value. In an embodiment of the present invention, a suitable signal can be automatically selected to test the state machine according to the state value output by the state machine, thereby avoiding errors that may occur in manually testing the state machine. At the same time, by automatically determining the test signal and automatically generating the test result, the test efficiency of the state machine is improved.
[0092] Reference Figure 2 , Figure 2 A flowchart of another state machine testing method provided by an embodiment of the present invention.
[0093] Step 201, determining a state value switching mode corresponding to the state machine; wherein the state value switching mode is composed of an initial state value and a target state value.
[0094] In an embodiment of the present invention, each state machine may have a plurality of preset state values that can be output, and one of every two different state values among the preset state values may be used as a starting state value, and the other may be used as a target state value, so that a pair of starting state values and a target state value constitute a state value switching mode, and the state value that the state machine can output may jump from the starting state value in the state value switching mode to the target state value. For example, the starting state value of a state value switching mode of a state machine is state value A, and the target state value is state value B, then the state value switching mode may be expressed as: (state value A, state value B), and the state value switching mode indicates that the state value output by the state machine may be directly switched from state value A to state value B, and another state value switching mode may be: (state value B, state value A), and the state value switching mode indicates that the state value output by the state machine may be directly switched from state value B to state value A. It is easy to understand that the state machine may also have one of the above two state value switching modes, and the above state machine cannot perform the other state value switching mode.
[0095] In addition, all state value switching modes corresponding to a state machine can exhaust all combinations of different preset state values, or only include some combinations of different preset state values. For example, a state machine can output three state values, namely state value A, state value B, and state value C. Then the state machine can have at most six state value switching modes: (state value A, state value B), (state value A, state value C), (state value B, state value C), (state value C, state value B), (state value C, state value B), (state value C, state value A), and (state value B, state value A). The technician can make the state machine support the above six state value switching modes at the same time, or only support one or more of the above six state value switching modes.
[0096] In an embodiment of the present invention, the state value switching mode that can actually be implemented by the state machine to be tested can be first determined. The state value switching mode of the state machine is determined by the characteristics of the state machine itself. According to the design, program, function, etc. of the state machine, different state machines correspond to different state value switching modes. It should be noted that the number of state value switching modes corresponding to each state machine can be 1 or more, and the embodiment of the present invention does not specifically limit this.
[0097] Step 202, for each of the state value switching modes, generate a test signal corresponding to the state value switching mode; wherein the test signal is used to adjust the state value output by the state machine from the starting state value corresponding to the state value switching mode to the target state value corresponding to the state value switching mode.
[0098] In the embodiment of the present invention, the technician can pre-set a corresponding test signal for each state value switching mode corresponding to the state machine, and the test signal is used to adjust the state value output by the state machine from the starting state value of the state value switching mode to the target state value of the state value switching mode. It should be noted that there can be multiple test signals corresponding to each state value switching mode.
[0099] For example, the state value switching mode of a state machine is: (state value A, state value B), where state value A is the starting state value of the state value switching mode, and state value B is the target state value of the state value switching mode. The technician can set test signal C and test signal D for the state value switching mode. If the state machine is normal, when the state machine outputs state value A, the test signal C is input into the state machine, and the state value output by the state machine can be adjusted from state value A to state value B. The test signal D is input into the state machine, and the state value output by the state machine can also be adjusted from state value A to state value B. wherein, test signal C and test signal D are different signals.
[0100] In the embodiment of the present invention, multiple test signals can be set for a state value switching mode, which is helpful to perform a more comprehensive test on the state machine.
[0101] Step 203: for each of the state value switching modes, a test case set corresponding to the state value switching mode is generated by using a test signal, an initial state value and a target state value corresponding to the state value switching mode.
[0102] In an embodiment of the present invention, the state value switching mode is composed of an initial state value and a target state value, and a corresponding test signal is also set for the state value switching mode in the above steps. Therefore, for each state value switching mode, a test signal, an initial state value and a target state value corresponding to the state value switching mode can be used to generate a test case corresponding to the state value switching mode, and obtain a test case set corresponding to the state value switching mode.
[0103] For example, the state value switching mode Z is: (state value A, state value B), where state value A is the starting state value of the state value switching mode Z, and state value B is the target state value corresponding to the state value switching mode Z, and the technician can set the test signal C and the test signal D for the state value switching mode Z. Then, the above information can be used to generate two test cases for the state value switching mode Z: test case E (state value A, test signal C, state value B), and test case F (state value A, test signal D, state value B). The set composed of the above test cases E and F is used as the test case set of the state value switching mode Z.
[0104] Each test case consists of 1 starting state value, 1 target state value and 1 test signal. Test cases with the same starting state value and the same target state value constitute a test case set. Different test case sets are used to test different state value switching methods. Figure 3 , Figure 3 A schematic diagram of a test case set provided by an embodiment of the present invention is shown. Figure 3 As shown, test case set 1 includes test case 1 and test case 2. Test case 1 consists of starting state value 1, target state value 2 and test signal 1. Test case 2 consists of starting state value 1, target state value 2 and test signal 2.
[0105] Step 204: Obtain a first state value output by the state machine.
[0106] After obtaining the test case set corresponding to the state machine, the state machine can be tested using the test case set.
[0107] Specifically, the state machine may be started first, and the first state value outputted after the state machine is started is obtained. It should be noted that the first state value may be an initial state value, or any state value that the state machine can output, and step 204 may describe any test behavior in the entire test process of the state machine, and does not necessarily refer to the first test of the state machine.
[0108] Step 205, obtaining the starting state value corresponding to the test case set; wherein the test cases in the test case set are composed of a starting state value, a target state value, and a test signal for adjusting the state value output by the state machine to the target state value.
[0109] In the embodiment of the present invention, since each test case in each test case set corresponds to the same state value switching mode, the starting state value of each test case in each test case set is the same, and the target state value is also the same. Then the starting state value corresponding to each test case set is the starting state value of each test case in the test case set.
[0110] Specifically, after obtaining the first state value output by the state machine, all test case sets corresponding to the first state value can be obtained from the database, and the starting state values corresponding to each test case set corresponding to the first state value can be obtained, so as to determine the test case set corresponding to the first state value in subsequent operations.
[0111] Step 206: Match the first state value with the initial state values corresponding to all test case sets to determine a first test case set corresponding to the first state value.
[0112] After obtaining the starting state values corresponding to each test case set corresponding to the state machine, the first state value can be matched with the starting state values corresponding to each test case set corresponding to the state machine, and the starting state value that is the same as the first state value can be determined, and then the test case set corresponding to the starting state value that is the same as the first state value can be determined as the first test case set corresponding to the first state value.
[0113] For example, refer to Figure 4 , Figure 4 FIG. 4 shows another schematic diagram of a test case set provided by an embodiment of the present invention. Figure 4 As shown, test case set 2 includes test case 3 and test case 4. Test case 3 consists of starting state value 1, target state value 3 and test signal 3. Test case 4 consists of starting state value 1, target state value 3 and test signal 4. Figure 3 and Figure 4The starting state value 1 shown matches. Since the starting state value 1 exists in both the test case set 1 and the test case set 2, the test case set 1 and the test case set 2 can be determined as the first test case set corresponding to the first state value.
[0114] Step 207: Acquire a first test case from the first test case set, and determine a first signal according to a test signal of the first test case.
[0115] After obtaining the first test case set corresponding to the first state value, a test case may be selected from the first test case set as the first test case, and the first signal may be determined according to the first test case.
[0116] In an embodiment of the present invention, a test case can be randomly selected from the first test case set as the first test case, or the first test case can be selected using the following sub-steps 2071 to 2073. The technician can also use other methods to select the first test case from the first test case set, and the embodiment of the present invention does not specifically limit this.
[0117] After the first test case is determined, a test signal of the first test case may be acquired, and the test signal of the first test case may be directly used as the first signal.
[0118] Optionally, step 207 may include:
[0119] Sub-step 2071, determining historical test cases that have been tested in the first test case set according to historical test information.
[0120] In the process of testing the state machine, a large number of test cases may be used for testing, and it may even be necessary to traverse all test cases in each test case set to obtain comprehensive test results. In order to improve the test efficiency, in an embodiment of the present invention, each time a test case is used to test the state machine, the used test case can be recorded (for example, the identification information of the test case can be recorded), thereby obtaining historical test information.
[0121] When it is necessary to determine the test signal from the first test case set, the first test case set can be screened according to the historical test information, and the tested test cases can be determined from the first test case set and used as the historical test cases.
[0122] Sub-step 2072: removing the historical test case from the first test case set to obtain a target test case set.
[0123] After the historical test cases are determined, the historical test cases can be removed from the first test case set to obtain a target test case set consisting of untested test cases.
[0124] It should be noted that since there may be multiple test case sets with the same target state value as the first state value, there may be multiple first test case sets corresponding to the first state value. In an embodiment of the present invention, for each first test case set corresponding to the first state value, the historical test cases therein can be removed to obtain the target test case sets corresponding to each first test case set.
[0125] Sub-step 2073, obtaining a first test case from the target test case set.
[0126] After obtaining the target test case set, a first test case can be determined from the target test case set. Specifically, a first test case can be randomly determined from the target test case set, or a first test case can be determined from the target test case set according to a preset rule for this test. Among them, the preset rule can be flexibly set by the technician according to actual needs, and the embodiment of the present invention does not specifically limit this. For example, the preset rule can be set to determine a test case with the smallest amount of test signal data from the target test case set as the first test case to improve the test efficiency.
[0127] Step 208: Send the first signal to the state machine, and obtain a second state value output by the state machine in response to the first signal.
[0128] This step can be referred to as step 102, and will not be described in detail in this embodiment of the present invention.
[0129] Step 209: Generate a test result according to the second state value and the target state value.
[0130] After obtaining the second state value returned by the state machine for the first signal, you can continue to determine the second signal based on the second state value and send the second signal to the state machine, and so on, until the number of test signals sent to the state machine reaches a preset number or all test signals are traversed, and then generate test results based on the state values output by the state machine for all tested test signals.
[0131] Specifically, the state machine may be completely tested using the method shown in the following sub-steps 2091 to 2092.
[0132] Optionally, step 209 may include:
[0133] Sub-step 2091, when the second state value matches the target state value, determine a second test case set corresponding to the second state value, and use a second signal determined based on the test case of the second test case set to test the state machine until all test cases in all test case sets are traversed.
[0134] After receiving the second state value, the second test case set corresponding to the second state value can be further determined, and the test signal in the test case of the second test case set is selected as the second signal, and the state machine is continuously tested using the second signal, and so on, until all the test cases in all the test case sets are traversed. It should be noted that the process of testing the state machine using the second signal is similar to the process of testing the state machine using the first signal mentioned above, and the present invention is an embodiment and will not be repeated.
[0135] If the second state value output by the state machine is different from the target state value corresponding to the first signal, it means that the state machine fails to respond to the first signal correctly, jumps to an incorrect state, and outputs an incorrect state value. At this time, the test process can be terminated and a message indicating that the test failed can be displayed to the user. At the same time, the test case that failed the test can also be output to the user. For example, when the first signal test fails, the first test case corresponding to the first signal can be output to the user.
[0136] Optionally, sub-step 2091 may include:
[0137] Sub-step A1: when the second state value matches the target state value, determine a second test case set corresponding to the second state value.
[0138] In the embodiment of the present invention, the test cases are generated based on the state values that the state machine can correctly output. If the state machine outputs an erroneous state value, the erroneous state value is likely to be unable to match the starting state value of any test case, causing the test to be unable to continue. For example, the state values that a state machine can output are only state value A and state value B. In all the test cases corresponding to the state machine, the starting state value can only be state value A or state value B. If the state machine incorrectly responds to the input first signal and the output second state value is state value C, since state value C cannot match the starting state value of any test case corresponding to the state machine, it is impossible to further determine the corresponding second test case set based on the second state value output by the state machine, causing the test to be unable to continue.
[0139] Therefore, in the embodiment of the present invention, the step of determining the second test case set corresponding to the second state value may be performed only when the second state value matches the target state value.
[0140] Sub-step A2: when the second state value does not match the target state value, terminate the test process and output the first test case and the second state value to the user.
[0141] In the embodiment of the present invention, if the state machine outputs an erroneous state value, the erroneous state value is likely to be unable to match the initial state value of any test case, causing the test to be unable to continue. In other words, if the second state value output by the state machine does not match the target state value, it means that the erroneous state value output by the state machine is likely to cause the test to be unable to continue. Therefore, the test process can be directly terminated, and the information that the test failed can be output to the user. At the same time, the first test case (including the initial state value of the first test case, the test signal and the target state value) and the second state value can also be output to the user, so that the user can accurately locate the fault of the state machine.
[0142] Sub-step 2092: Generate a test result according to the state value output by the state machine for each test case in all test case sets.
[0143] After the test is completed, a complete test result can be generated based on the state value output by the state machine for each test case in the set of all test cases.
[0144] Optionally, sub-step 2092 may include:
[0145] Sub-step B1, when the state value output by the state machine for each test case in all test case sets matches the target state value of the corresponding test case, determining that the test result is a test pass.
[0146] If the state value output by the state machine for each test case in all test case sets matches the corresponding target state value, it means that the state machine can correctly process and respond to each test case in all test case sets. At this time, a test result indicating that the test has passed can be generated to the user.
[0147] Sub-step B2, when the state value output by the state machine for at least one test case in the set of all test cases does not match the target state value of the corresponding test case, determining the test result as test failure.
[0148] If the state value output by the state machine for at least one test case in the set of all test cases does not match the corresponding target state value, it means that there are test cases in the test case set that the state machine cannot respond to and process correctly, indicating that there is a problem with the state machine. At this time, a test result of test failure can be generated to the user.
[0149] Furthermore, in the case of test failure, all test cases that fail the test can be obtained and output to the user so that the user can understand which state value switching methods and test signals the state machine cannot correctly handle, which is convenient for the user to discover and handle state machine failures.
[0150] In summary, an embodiment of the present invention provides another state machine testing method, including: obtaining a first state value output by a state machine; determining a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal; sending the first signal to the state machine, and obtaining a second state value output by the state machine in response to the first signal; and generating a test result according to the second state value and the target state value. In an embodiment of the present invention, a suitable signal can be automatically selected to test the state machine according to the state value output by the state machine, thereby avoiding errors that may occur in manually testing the state machine. At the same time, by automatically determining the test signal and automatically generating the test result, the test efficiency of the state machine is improved.
[0151] Based on the above embodiments, an embodiment of the present invention further provides a state machine testing device.
[0152] refer to Figure 5 , Figure 5 A structural block diagram of a state machine testing device provided by an embodiment of the present invention:
[0153] An acquisition module 501 is used to acquire a first state value output by a state machine;
[0154] A determination module 502 is used to determine a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal;
[0155] A sending module 503, configured to send the first signal to the state machine, and obtain a second state value output by the state machine in response to the first signal;
[0156] The result module 504 is used to generate a test result according to the second state value and the target state value.
[0157] Optionally, the determining module includes:
[0158] A starting state value submodule, used to obtain a starting state value corresponding to a test case set; wherein the test case in the test case set is composed of a starting state value, a target state value, and a test signal for adjusting the state value output by the state machine from the starting state value to the target state value;
[0159] A first test case set submodule, configured to match the first state value with the starting state values corresponding to all test case sets, and determine a first test case set corresponding to the first state value;
[0160] The first signal submodule is used to obtain a first test case from the first test case set and determine a first signal according to a test signal of the first test case.
[0161] Optionally, the device comprises:
[0162] A state value switching mode submodule is used to determine the state value switching mode corresponding to the state machine; wherein the state value switching mode is composed of a starting state value and a target state value;
[0163] A test signal generation submodule, for generating a test signal corresponding to each state value switching mode; wherein the test signal is used to adjust the state value output by the state machine from the starting state value corresponding to the state value switching mode to the target state value corresponding to the state value switching mode;
[0164] The test case set generation submodule is used to generate a test case set corresponding to each state value switching mode by using the test signal, starting state value and target state value corresponding to the state value switching mode.
[0165] Optionally, the first signal submodule includes:
[0166] A historical test case module, configured to determine, based on historical test information, historical test cases that have been tested in the first test case set;
[0167] A target test case set submodule, configured to remove the historical test case from the first test case set to obtain a target test case set;
[0168] The first test case submodule is used to obtain a first test case from the target test case set.
[0169] Optionally, the result module includes:
[0170] A traversal test submodule, used to determine a second test case set corresponding to the second state value, and use a second signal determined based on the test case of the second test case set to test the state machine until all test cases in all test case sets are traversed;
[0171] The test result submodule is used to generate a test result according to the state value output by the state machine for each test case in the set of all test cases.
[0172] Optionally, the traversal test submodule includes:
[0173] A second test case set submodule, configured to determine a second test case set corresponding to the second state value when the second state value matches the target state value;
[0174] A termination submodule is used to terminate the test process and output the first test case and the second state value to the user when the second state value does not match the target state value.
[0175] Optionally, the test result submodule includes:
[0176] A first test result submodule, configured to determine that the test result is a test pass when the state value output by the state machine for each test case in all test case sets matches the target state value of the corresponding test case;
[0177] The second test result submodule is used to determine that the test result is a test failure when the state value output by the state machine for at least one test case in all test case sets does not match the target state value of the corresponding test case.
[0178] In summary, an embodiment of the present invention provides a state machine testing device, including: an acquisition module, used to acquire a first state value output by a state machine; a determination module, used to determine a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal; a sending module, used to send the first signal to the state machine, and acquire a second state value output by the state machine in response to the first signal; and a result module, used to generate a test result according to the second state value and the target state value. In an embodiment of the present invention, a suitable signal can be automatically selected to test the state machine according to the state value output by the state machine, thereby avoiding errors that may occur in manual testing of the state machine. At the same time, by automatically determining the test signal and automatically generating the test result, the test efficiency of the state machine is improved.
[0179] An embodiment of the present invention further provides an electronic device, the electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the state machine testing method.
[0180] An embodiment of the present invention further provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the above-mentioned state machine testing method is implemented.
[0181] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned device embodiments and will not be repeated here.
[0182] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
[0183] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A state machine testing method, characterized in that: The method comprises: Obtain the first state value output by the state machine; Determine a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal; Sending the first signal to the state machine, and obtaining a second state value output by the state machine in response to the first signal; A test result is generated according to the second state value and the target state value.
2. The method according to claim 1, characterized in that The determining a first signal according to the first state value comprises: Obtaining a starting state value corresponding to a test case set; wherein the test cases in the test case set are composed of a starting state value, a target state value, and a test signal for adjusting the state value output by the state machine from the starting state value to the target state value; Matching the first state value with the initial state values corresponding to all test case sets to determine a first test case set corresponding to the first state value; A first test case is obtained from the first test case set, and a first signal is determined according to a test signal of the first test case.
3. The method according to claim 2, characterized in that The method comprises: Determine a state value switching mode corresponding to the state machine; wherein the state value switching mode is composed of an initial state value and a target state value; For each of the state value switching modes, a test signal corresponding to the state value switching mode is generated; wherein the test signal is used to adjust the state value output by the state machine from the starting state value corresponding to the state value switching mode to the target state value corresponding to the state value switching mode; For each of the state value switching modes, a test case set corresponding to the state value switching mode is generated by using a test signal, an initial state value and a target state value corresponding to the state value switching mode.
4. The method according to claim 2, characterized in that: The obtaining the first test case from the first test case set includes: Determine, according to the historical test information, the historical test cases that have been tested in the first test case set; Removing the historical test cases from the first test case set to obtain a target test case set; A first test case is obtained from the target test case set.
5. The method according to claim 2, characterized in that: The generating a test result according to the second state value and the target state value includes: Determine a second test case set corresponding to the second state value, and test the state machine using a second signal determined based on the test cases in the second test case set until all test cases in all test case sets are traversed; A test result is generated according to the state value output by the state machine for each test case in all test case sets.
6. The method according to claim 5, characterized in that The determining a second test case set corresponding to the second state value includes: In a case where the second state value matches the target state value, determining a second test case set corresponding to the second state value; When the second state value does not match the target state value, the test process is terminated and the first test case and the second state value are output to the user.
7. The method according to claim 5, characterized in that The generating a test result according to the state value output by the state machine for each test case in all test case sets includes: When the state value output by the state machine for each test case in all the test case sets matches the target state value of the corresponding test case, determining that the test result is a test pass; When the state value output by the state machine for at least one test case in the set of all test cases does not match the target state value of the corresponding test case, the test result is determined to be a test failure.
8. A state machine testing device, characterized in that: The device comprises: An acquisition module, used for acquiring a first state value output by the state machine; A determination module, configured to determine a first signal according to the first state value; wherein the first signal is used to adjust the state value output by the state machine to a target state value corresponding to the first signal; a sending module, configured to send the first signal to the state machine, and obtain a second state value output by the state machine in response to the first signal; A result module is used to generate a test result according to the second state value and the target state value.
9. An electronic device, characterized in that: The electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the state machine testing method according to any one of claims 1 to 7 when executing the computer program.
10. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by the processor, the state machine testing method according to any one of claims 1 to 7 is implemented.
