Hardware-in-the-loop test case generation method and device, equipment, medium and product
By inputting test requirements into a reinforcement learning model, generating and iteratively training test cases, the problem of incomplete test case scenario coverage in existing technologies is solved, and comprehensive test coverage of intelligent driving technology is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-25
- Publication Date
- 2026-03-27
AI Technical Summary
Existing hardware-in-the-loop test case generation schemes cannot fully cover multiple scenarios, resulting in poor scenario coverage of test cases, which cannot meet the multi-dimensional testing needs of intelligent driving technology as it develops towards Level 4.
By inputting test requirements into a pre-trained reinforcement learning model, an initial set of test cases is generated, and a reward value is calculated based on the test cases and responses. When the reward value is less than a preset threshold, the reinforcement learning model is iteratively trained until effective test cases are generated, ensuring comprehensive scenario coverage.
It improves the comprehensiveness of test case scenario coverage, ensures the effectiveness of generated test cases, adapts to the multi-dimensional testing needs of intelligent driving technology, and is compatible with different vehicle models and test objects.
Smart Images

Figure CN121742433A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automotive technology, and in particular to a method, apparatus, device, medium, and product for generating hardware-in-the-loop test cases. Background Technology
[0002] In the automotive technology field, Hardware-in-the-Loop (HIL) testing is a core component for verifying the security and reliability of domain controllers. This test simulates complex scenarios in real-world road environments to verify the controller's decision-making logic and execution capabilities under different operating conditions. To verify the controller's performance, there is an urgent need for a solution that can generate test cases adaptable to multiple test objects to comprehensively verify the domain controller.
[0003] Current hardware-in-the-loop test case generation methods rely on manual writing and custom parameter settings to generate test cases. However, this method fails to generate test cases that cover multiple scenarios, resulting in poor scenario comprehensiveness of the generated test cases. Summary of the Invention
[0004] This application provides a hardware-in-the-loop test case generation method, apparatus, device, medium, and product, which improves the comprehensiveness of the scenario coverage of the generated test cases.
[0005] In a first aspect, embodiments of this application provide a hardware-in-the-loop test case generation method, including:
[0006] Obtain test requirements;
[0007] The test requirements are input into a reinforcement learning model to obtain a test case set; the test case set is used to represent the set of test scenarios corresponding to the test requirements.
[0008] For each test case in the test case set, run the test case and generate a test response;
[0009] A reward value is calculated based on the test cases and the test responses. If the reward value is less than a preset threshold, the reinforcement learning model is iteratively trained based on the reward value until the reward value is not less than the preset threshold, and a test case set corresponding to the reward value not being less than the preset threshold is output.
[0010] In one possible implementation, calculating the reward value based on the test cases and the test responses includes:
[0011] The reward value is calculated based on the test cases and the test responses, using preset weights.
[0012] In one possible implementation, calculating the reward value based on the test cases and the test responses, using preset weights, includes:
[0013] The target priority score, exploration priority score, and timeout priority score are determined based on the test cases and the test responses. The target priority score indicates whether the current test case meets the test requirements. The target priority score indicates whether the current test case is a new scenario. The timeout priority score indicates whether the test response generated based on the current test case times out.
[0014] The target priority score, the exploration priority score, and the timeout priority score are weighted and summed based on their respective preset weights to obtain the reward value.
[0015] In one possible implementation, determining the target priority score, exploration priority score, and timeout priority score based on the test cases and the test responses includes:
[0016] Determine whether the test case meets the test requirements. If it does, determine the target priority score as the first value; otherwise, determine the target priority score as 0.
[0017] Determine whether the test case is a new scenario. If it is a new scenario, determine the exploration priority score as the second value; otherwise, determine the exploration priority score as 0.
[0018] Determine whether the delay time of the test case has timed out. If it has timed out, determine the timeout priority score as the third value; otherwise, determine the timeout priority score as 0.
[0019] In one possible implementation, the method further includes:
[0020] For test case sets whose reward value is not less than the preset threshold, a clustering algorithm is used to remove test case sets with a similarity greater than the similarity threshold.
[0021] In one possible implementation, the method further includes: iteratively training the reinforcement learning model based on the reward value, comprising:
[0022] The reward value is input into the reinforcement learning model. Based on the reward value, the policy network of the reinforcement learning model is updated, and corresponding test cases are output until the reward value obtained based on the test cases is not less than the threshold.
[0023] Secondly, embodiments of this application provide a hardware-in-the-loop test case generation apparatus, comprising:
[0024] The acquisition module is used to acquire test requirements;
[0025] The first processing module is used to input the test requirements into the reinforcement learning model to obtain a test case set; the test case set is used to represent the set of test scenarios corresponding to the test requirements.
[0026] The execution module is used to run each test case in the test case set and generate a test response;
[0027] The second processing module is used to calculate a reward value based on the test cases and the test response; if the reward value is less than a preset threshold, the reinforcement learning model is iteratively trained based on the reward value until the reward value is not less than the preset threshold, and the test case set corresponding to the reward value not being less than the preset threshold is output.
[0028] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor;
[0029] The memory stores computer-executed instructions;
[0030] The processor executes computer execution instructions stored in the memory, causing the processor to perform the first aspect and / or various possible implementations of the first aspect as described above.
[0031] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible implementations of the first aspect.
[0032] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the first aspect and / or various possible implementations of the first aspect.
[0033] The hardware-in-the-loop test case generation method, apparatus, device, medium, and product provided in this application's embodiments involve: acquiring test requirements; inputting the test requirements into a reinforcement learning model to obtain a test case set; the test case set representing the set of test scenarios corresponding to the test requirements; running the test case for each test case in the test case set to generate a test response; calculating a reward value based on the test case and the test response; and if the reward value is less than a preset threshold, iteratively training the reinforcement learning model based on the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The solution in this application obtains an initial test case set by inputting test requirements into a pre-trained reinforcement learning model, and generates test responses based on the test cases; calculating a reward value based on the environmental parameters, traffic parameters, and response parameters included in the generated test cases. When the reward value is less than the preset threshold, it means that the generated test case is not a valid test case. Therefore, it is necessary to iteratively train the reinforcement learning model based on the reward value, and then output a new round of test cases based on the trained reinforcement learning model. Then, run the test case to generate a new test response. This process continues until the calculated reward value is not less than the preset threshold, at which point the corresponding test case is output. This ensures that the generated test cases are valid test cases and improves the comprehensiveness of the scenario coverage of the generated test cases. Attached Figure Description
[0034] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0035] Figure 1 A flowchart illustrating a hardware-in-the-loop test case generation method provided for an exemplary embodiment;
[0036] Figure 2 A flowchart illustrating the test case generation process for example;
[0037] Figure 3 A system architecture diagram for example domain controller hardware-in-the-loop testing;
[0038] Figure 4 A diagram illustrating the interaction logic of a reinforced logic intelligent agent, serving as an example.
[0039] Figure 5 A schematic diagram of the hardware-in-the-loop test case generation device provided in the embodiments of this application;
[0040] Figure 6 A schematic diagram of the structure of the electronic device provided in this application.
[0041] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0042] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0043] In the automotive technology field, such as intelligent driving, hardware-in-the-loop (HIL) testing of autonomous driving domain controllers is a core step in verifying their safety and reliability. This test verifies the controller's decision-making logic and execution capabilities under different operating conditions by simulating complex scenarios in real-world road environments (such as extreme weather, sudden obstacles, sensor anomalies, etc.). Specifically, the test scenarios need to cover multi-dimensional coupling conditions: environmental parameters (temperature, illumination, precipitation, etc.), traffic scenarios (obstacle types, trajectories, lane distribution, etc.), and controller states (sensor fusion confidence, decision delay, braking commands, etc.). For example, in an extreme scenario of heavy rain + backlight + pedestrian crossing, the controller needs to complete target detection, trajectory prediction, and braking response within 1.2 seconds, and the deceleration needs to reach more than 8 m / s².
[0044] However, current technologies struggle to generate test cases that cover these complex coupling conditions, leading to safety vulnerabilities after deployment in real vehicles. Furthermore, as intelligent driving technology evolves towards Level 4 (Level 4 of the autonomous driving standards: highly automated driving), testing requirements are expanding in multiple dimensions: not only do they need to cover more edge scenarios (such as rain and fog recognition failure at tunnel entrances and exits, and radar signal obstruction), but they also need to adapt to the testing needs of different vehicle models (such as the VCU, BMS, and other ECUs in new energy vehicles). Current methods of manually writing test cases and simple AI-assisted solutions both have significant shortcomings, failing to meet the requirements of high coverage, high efficiency, and high versatility in testing. There is an urgent need for a solution that can autonomously explore extreme scenarios, automatically generate test cases, and adapt to multiple test objects.
[0045] The hardware-in-the-loop test case generation method, apparatus, device, medium, and product provided in this application embodiment obtain an initial test case set by inputting test requirements into a pre-trained reinforcement learning model, and generate test responses based on the test cases. A reward value is calculated based on the test cases and test responses, using environmental parameters, traffic parameters, and response parameters included in the generated test cases. When the reward value is less than a preset threshold, it indicates that the generated test cases are not valid. Therefore, the reinforcement learning model needs to be iteratively trained based on the reward value. Then, a new round of test cases is output based on the trained reinforcement learning model, and these test cases are run again to generate new test responses. This process continues until the calculated reward value is not less than the preset threshold, at which point the corresponding test cases are output. This ensures that the generated test cases are valid and improves the comprehensiveness of the scenario coverage of the generated test cases.
[0046] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0047] Figure 1 A flowchart illustrating a hardware-in-the-loop test case generation method provided for an exemplary embodiment; as shown. Figure 1 As shown, the method includes:
[0048] Step 101: Obtain test requirements.
[0049] In this embodiment, the test requirement indicates the scenario in which the test should be conducted and the target response of the domain controller in that scenario. For example, the test requirement could be: "The L4 domain controller must trigger emergency braking for a pedestrian crossing within 1.2 seconds under heavy rain and backlight conditions, with a deceleration ≥ 8 m / s²." Here, "The L4 domain controller must be under heavy rain and backlight conditions" is the test scenario; "Trigger emergency braking for a pedestrian crossing within 1.2 seconds, with a deceleration ≥ 8 m / s²" is the controller's target response.
[0050] Step 102: Input the test requirements into the reinforcement learning model to obtain the test case set; the test case set is used to represent the set of test scenarios corresponding to the test requirements.
[0051] In this embodiment, the acquired test requirements are input into the reinforcement learning model to obtain the initial test scenario output by the model. For example, the reinforcement learning agent loads the pre-trained model and outputs the corresponding instructions. The pre-trained model is the reinforcement learning model, which can be trained based on 100,000 data points of normal operating conditions, covering following / lane-changing scenarios under normal temperature and lighting conditions. In one example, the output action instructions could be "Temperature 3 degrees Celsius (°C) + Precipitation 45 mm / h + Illumination 95,000 lux + Pedestrian crossing on the left 5 km / h (km / h)". Based on the corresponding instructions, a corresponding scenario can be generated, which may include conditions such as rain, fog, noise in the LiDAR point cloud, and overexposed camera images, and is sent to the domain controller.
[0052] The commands can include environmental parameters, traffic parameters, and controller parameters. For example, the range of environmental parameters can be: temperature (-40~85℃), precipitation (0~50mm / h), illumination (0~100000 lux), and road surface friction (0.1~1.0). The range of traffic parameters can be: obstacle type (pedestrian / vehicle / guardrail), speed (0~60km / h), lane markings (1~4), and vehicle distance (5~50m). The range of controller parameters can be: sensor fusion confidence (0~1), decision delay (0~100ms), braking command (0~100%), etc. Control commands can vary within these ranges and can be combined in any form; therefore, the output control commands can include tens of thousands of commands, and the corresponding test case set can contain tens of thousands of test cases.
[0053] Step 103: For each test case in the test case set, run the test case and generate a test response.
[0054] In this embodiment, for each test case in the aforementioned test case set, the test case is sent to the corresponding domain controller, generating a test response for each test case. This test response is the actual response of the current domain controller under that test case, which is to say, it simulates the response of the domain controller in a real environment. For example, "triggering emergency braking for a pedestrian crossing within 1.5s, with deceleration ≥7m / s²" is an example predicted response of the domain controller.
[0055] Step 104: Calculate the reward value based on the test cases and test responses; if the reward value is less than the preset threshold, iteratively train the reinforcement learning model based on the reward value until the reward value is not less than the preset threshold, and output the test case set corresponding to the reward value not less than the preset threshold.
[0056] Based on the obtained test cases and test responses, the reward value corresponding to each test case and test response is calculated. This reward value serves as the basis for subsequent optimization and reinforcement model training. When the calculated reward value is less than a preset threshold, the reinforcement model is iteratively trained based on the reward value. For example, the RL Agent updates the policy network of the reinforcement learning model based on the reward value, and regenerates new test cases; for example, increasing precipitation to 48 mm / h and increasing illumination to 98,000 lux to enhance the extreme nature of the scenario; at the same time, the newly generated test cases are sent to the domain controller to regenerate new test responses; the reward value is calculated again until the reward value is not less than the preset threshold. For example, until R ≥ 5; 5 is the preset threshold, and R represents the reward value.
[0057] In this embodiment, an initial set of test cases is obtained by inputting test requirements into a pre-trained reinforcement learning model, and test responses are generated based on these test cases. A reward value is calculated based on the environmental parameters, traffic parameters, and response parameters included in the generated test cases. When the reward value is less than a preset threshold, it indicates that the generated test cases are not valid. Therefore, the reinforcement learning model needs to be iteratively trained based on the reward value. Then, a new round of test cases is output based on the trained reinforcement learning model, and these test cases are run again to generate new test responses. This process continues until the calculated reward value is not less than the preset threshold, at which point the corresponding test cases are output. This ensures that the generated test cases are valid and improves the comprehensiveness of the scenario coverage of the generated test cases.
[0058] Optionally, the reward value is calculated based on the test cases and test responses, including:
[0059] The reward value is calculated based on the test cases and test responses, using preset weights.
[0060] In this embodiment, test cases are input into the domain controller for testing, and the domain controller response (such as braking delay of 1.3s and deceleration of 7.8m / s²) is collected. Based on the test cases and test responses, and according to preset weights, the reward value can be obtained.
[0061] Optionally, based on test cases and test responses, and using preset weights, a reward value is calculated, including:
[0062] The target priority score, exploration priority score, and timeout priority score are determined based on the test cases and test responses. The target priority score indicates whether the current test case meets the test requirements. The target priority score indicates whether the current test case is a new scenario. The timeout priority score indicates whether the test response generated based on the current test case has timed out.
[0063] In this embodiment, test cases can consist of scenario environment parameters, alternation parameters, and predicted response parameters. For example, in the test case of temperature 3℃ + precipitation 45mm / h + illumination 95000 lux + pedestrian crossing from the left (5km / h) + predicted response of 1.1s, temperature 3℃ + precipitation 45mm / h + illumination 95000 lux represent the scenario environment parameters, and pedestrian crossing from the left (5km / h) represents the traffic parameters. The predicted response time is the predicted value of the domain controller's response time in this scenario. Based on the scenario environment parameters and traffic parameters, it can be determined whether the currently generated test case conforms to the current test scenario, i.e., whether the test point has been triggered; it can also be determined whether the current test case is a new scenario different from the previously generated test cases. Based on the predicted domain controller response time and the actual response time when the test case is input to the domain controller, it can be determined whether the response time is delayed. Based on the above, the target priority score, exploration priority score, and timeout priority score can be determined.
[0064] The target priority score, exploration priority score, and timeout priority score are weighted and summed based on their respective preset weights to obtain the reward value.
[0065] In this embodiment, a corresponding preset weight is first assigned to the target priority score, the exploration priority score, and the timeout priority score. The scores are then multiplied by their respective weights and added together to obtain the final reward value.
[0066] In this embodiment, the accuracy of obtaining the reward value is improved by calculating the scores of each part corresponding to the test cases and test responses, and then obtaining the reward value based on the scores and weights.
[0067] Optionally, target priority score, exploration priority score, and timeout priority score are determined based on test cases and test responses, including:
[0068] Determine whether the test case meets the test requirements. If it does, set the target priority score to the first value; otherwise, set the target priority score to 0.
[0069] Determine whether the test case is a new scenario. If it is a new scenario, set the exploration priority score to the second value; otherwise, set the exploration priority score to 0.
[0070] Determine whether the delay time of the test case has exceeded the time limit. If it has, determine the timeout priority score as the third value; otherwise, determine the timeout priority score as 0.
[0071] In this embodiment, it is determined whether the current test case meets the test requirements. If a test point is triggered, the target priority score is the first value; if it does not meet the test requirements, the corresponding target priority score is 0. It is then determined whether the current test case is a new scenario different from the already generated test cases. If it is, the exploration priority score is determined to be the second value; otherwise, the exploration priority score is determined to be 0. If the delay time of the test case shows a delay when the predicted response is actually generated, the timeout priority is determined to be the third value; otherwise, it is 0.
[0072] For example, the first value can be 10, the second value can be 5, and the third value can be -1.
[0073] The formula for calculating reward value is:
[0074]
[0075] in, Indicates the reward value. This indicates the weight corresponding to the target priority score. Indicates the target priority score. This indicates the weight corresponding to the exploration priority score. This indicates the exploration priority score. This indicates the weight corresponding to the timeout priority score. This indicates the timeout priority score.
[0076] For example, the weight corresponding to the target priority score needs to be set relatively large, for example: This ensures that test case generation prioritizes matching test requirements. If... Set it to 0.3, Setting it to 0.6 (increasing exploration priority) will cause test cases to explore new scenarios first but not match the test objectives; the target test point trigger rate will drop from 90% to 45%, generating a large number of invalid new scenarios (such as the "high temperature + no obstacles" scenario that is irrelevant to the test requirements).
[0077] In this embodiment, the accuracy of generating each priority score is improved by analyzing test cases to generate corresponding priority scores.
[0078] Optionally, the method also includes:
[0079] For test case sets with reward values not less than a preset threshold, a clustering algorithm is used to remove test case sets with similarity values greater than the similarity threshold.
[0080] In this embodiment, redundant test cases are removed and output. For example, a clustering algorithm can be used to cluster the generated N test cases (e.g., N=100), and redundant test cases with similarity >80% (e.g., 72 cases) are removed; standardized test cases (including scenario parameters, test steps, and expected results) are output, which can be imported into automated testing software for execution.
[0081] In this embodiment, a clustering algorithm is used to eliminate test cases, which further improves the effectiveness of test case generation.
[0082] Based on the reward value, the reinforcement learning model is iteratively trained, including:
[0083] The reward value is input into the reinforcement learning model. Based on the reward value, the policy network of the reinforcement learning model is updated, and the corresponding test cases are output until the reward value obtained based on the test cases is not less than the threshold.
[0084] In this embodiment, the reinforcement learning model is iteratively trained by using the reward value obtained from each calculation as feedback, so that the test cases it outputs are more in line with the testing requirements, thereby improving the reliability of the test cases generated by the reinforcement learning model.
[0085] Figure 2 A flowchart illustrating the test case generation process for example; Figure 2 As shown, after initialization, test requirements are imported, and the RL Agent loads the pre-trained model to explore scenarios and obtain test case scenario descriptions. The test case scenario descriptions are then input into the HIL testing platform, and the scenario test results are output. Feedback calculations are performed based on the scenario test results to calculate the reward value R. It is determined whether the R value is greater than 5. If it is not greater than 5, scenario exploration is performed again to generate test cases. If the R value is greater than 5, test case clustering is performed, and redundancy is removed to output standardized test cases with a similarity of less than 80%. The process then ends.
[0086] Figure 3 A system architecture diagram for example domain controller hardware-in-the-loop testing; such as Figure 3 As shown, after obtaining the reward value based on the initially generated test cases and test responses, the RL algorithm in the AI decision layer outputs action instructions based on the reward value. The simulated test cases are sent through the controller LAN / Ethernet (CAN / Etherent) and then to the domain controller through the domain controller's multi-channel sensor simulation module. The domain controller sends a decision response to the simulation interaction layer through CAN / Etherent. The response is stored in the test data storage server and the reward value is calculated by the reward calculation unit. The newly calculated reward value is then output to the AI decision layer, and this process is repeated in a loop.
[0087] For example, the HIL hardware layer includes the HIL real-time simulator, which supports microsecond-level response and generates simulation scenario data (such as sensor signals and bus commands). This data is then connected to the AI decision layer and the domain controller via a CAN / Ethernet bus.
[0088] The multi-channel sensor simulation module simulates camera images (including backlight / rain and fog noise), LiDAR point clouds (including 30% point cloud loss), and millimeter-wave radar echoes. It is embedded in the HIL simulator and outputs signals to the domain controller.
[0089] The AI decision-making layer is equipped with an industrial computer with a graphics processing unit (GPU) accelerator card. It runs a lightweight RL algorithm to generate action instructions and update strategies, receives feedback data from the simulation interaction layer, and outputs instructions to the HIL hardware layer.
[0090] The simulation interaction layer test data storage server (including a MySQL database) stores domain controller output data (decision delay, braking commands, etc.) in real time, enabling bidirectional communication: receiving domain controller data and feeding it back to the AI decision layer.
[0091] The reward calculation unit (embedded software module) calculates the reward value R based on the domain controller response, is integrated into the storage server, and outputs the R value to the AI decision layer.
[0092] Figure 4 A diagram illustrating the interaction logic of a reinforced logic intelligent agent; such as... Figure 4 As shown, the parameters input to the RL Agent (PPO2 framework) include environmental and traffic parameters from the environment module (HIL simulation), as well as control parameters output by the domain controller. The RL Agent (PPO2 framework) updates its reward value by calculating the reward based on the decision data output by the domain controller. After the update, it outputs an adjusted action space A, including adjusting the environment / switching obstacles / triggering sensor anomalies, etc., which is then re-inputted to the environment module to generate new environmental parameters, forming a closed-loop interaction.
[0093] The following example illustrates the process of generating test cases.
[0094] 1. Initialization: Set the state space range (temperature 0~5℃, precipitation 30~50mm / h, light intensity 80000~100000lux), and load the reinforcement learning pre-trained model;
[0095] 2. First round of exploration: Agent output "Temperature 3℃ + Precipitation 45mm / h + Illumination 95000lux + Pedestrian crossing from the left", Domain controller braking delay 1.3s (not meeting the standard), R=0.7;
[0096] 3. 15th iteration: The agent outputs "temperature 2℃ + precipitation 48mm / h + light 98000 lux + pedestrian crossing the middle of two lanes (6km / h)", the domain controller triggers braking in 1.1s (deceleration 8.5m / s²), R=6.9 (marked as core use case);
[0097] 4. Redundancy Removal: Cluster 100 test cases, remove 72 similar scenarios (such as precipitation of 45~47mm / h + illumination of 95000~97000lux), and output 28 core test cases;
[0098] 5. Execution: Import into automated testing software, HIL will execute automatically and generate a report containing "response curve and compliance results".
[0099] The hardware-in-the-loop test case generation method provided in this embodiment obtains an initial test case set by inputting test requirements into a pre-trained reinforcement learning model, and generates test responses based on the test cases. A reward value is calculated based on the environmental parameters, traffic parameters, and response parameters included in the generated test cases. When the reward value is less than a preset threshold, it indicates that the generated test cases are not valid. Therefore, the reinforcement learning model needs to be iteratively trained based on the reward value. Then, a new round of test cases is output based on the trained reinforcement learning model, and these test cases are run again to generate new test responses. This process continues until the calculated reward value is not less than the preset threshold, at which point the corresponding test cases are output. This ensures that the generated test cases are valid and improves the comprehensiveness of the scenario coverage of the generated test cases.
[0100] Figure 5 This is a schematic diagram of the hardware-in-the-loop test case generation device provided in the embodiments of this application; as shown below. Figure 5 As shown, the hardware-in-the-loop test case generation device provided in this embodiment includes:
[0101] Module 501 is used to obtain test requirements.
[0102] The first processing module 502 is used to input the test requirements into the reinforcement learning model to obtain a test case set; the test case set is used to represent the set of test scenarios corresponding to the test requirements.
[0103] The Run module 503 is used to run test cases and generate test responses for each test case in the test case set.
[0104] The second processing module 504 is used to calculate the reward value based on the test cases and test responses; if the reward value is less than the preset threshold, the reinforcement learning model is iteratively trained based on the reward value until the reward value is not less than the preset threshold, and the test case set corresponding to the reward value not less than the preset threshold is output.
[0105] The hardware-in-the-loop test case generation device provided in this embodiment can execute the hardware-in-the-loop test case generation method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.
[0106] Figure 6 A schematic diagram of the structure of the electronic device provided in this application. Figure 6 As shown, the electronic device 60 provided in this embodiment includes at least one processor 601 and a memory 602. Optionally, the device 60 further includes a communication component 603. The processor 601, memory 602, and communication component 603 are connected via a bus 604.
[0107] In a specific implementation, at least one processor 601 executes computer execution instructions stored in memory 602, causing at least one processor 601 to perform the above-described method.
[0108] The specific implementation process of processor 601 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0109] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0110] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0111] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0112] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0113] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.
[0114] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0115] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0116] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0117] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0118] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0119] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0120] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0121] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A hardware-in-the-loop test case generation method, characterized by, The method comprises the following steps: acquiring a test requirement; inputting the test requirement into a reinforcement learning model to obtain a test case set; the test case set is used to represent a test scenario set corresponding to the test requirement; running each test case in the test case set to generate a test response; calculating a reward value according to the test case and the test response; if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold.
2. The method of claim 1, wherein, The method further comprises the following steps: if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold.
3. The method of claim 2, wherein, The method further comprises the following steps: acquiring a test requirement; inputting the test requirement into a reinforcement learning model to obtain a test case set; 4. The method of claim 3, wherein, the test case set is used to represent a test scenario set corresponding to the test requirement; running each test case in the test case set to generate a test response; calculating a reward value according to the test case and the test response; if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold.
5. The method of claim 4, wherein, The method further comprises the following steps: if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold.
6. The method according to any one of claims 1 to 5, characterized in that, The method further comprises the following steps: acquiring a test requirement; 7. A hardware-in-the-loop test case generation apparatus, characterized by, inputting the test requirement into a reinforcement learning model to obtain a test case set; the test case set is used to represent a test scenario set corresponding to the test requirement; running each test case in the test case set to generate a test response; calculating a reward value according to the test case and the test response; if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The method further comprises the following steps: if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The method further comprises the following steps: acquiring a test requirement; inputting the test requirement into a reinforcement learning model to obtain a test case set; the test case set is used to represent a test scenario set corresponding to the test requirement; running each test case in the test case set to generate a test response; calculating a reward value according to the test case and the test response; if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The method further comprises the following steps: if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The method further comprises the following steps: acquiring a test requirement; inputting the test requirement into a reinforcement learning model to obtain a test case set; the test case set is used to represent a test scenario set corresponding to the test requirement; running each test case in the test case set to generate a test response; calculating a reward value according to the test case and the test response; if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The method further comprises the following steps: if the reward value is less than a preset threshold, iteratively training the reinforcement learning model according to the reward value until the reward value is not less than the preset threshold, and outputting the test case set corresponding to the reward value not less than the preset threshold. The second processing module is configured to calculate a reward value according to the test case and the test response; If the reward value is less than a preset threshold, the reinforcement learning model is iteratively trained according to the reward value until the reward value is not less than the preset threshold, and a test case set corresponding to the reward value not less than the preset threshold is output.
8. An electronic device, comprising: Comprising: a memory, a processor; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory, so that the processor executes the method of any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by the processor to implement the method of any one of claims 1-6.
10. A computer program product, characterised in that, The computer program is executed by the processor to implement the method of any one of claims 1-6.