Test script generation method and device for vehicle-mounted intrusion detection system, equipment and medium
By converting natural language information into structured semantic representation and combining it with vehicle communication protocols to generate test scripts, the problem of vehicle scenario adaptation in existing technologies is solved, achieving efficient and executable test script generation, and supporting automated testing and script optimization in complex scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU MAITANG TECH CO LTD
- Filing Date
- 2026-02-05
- Publication Date
- 2026-05-08
AI Technical Summary
Existing test script generation technologies are ill-suited to the needs of automotive scenarios, have low coverage, long development cycles, cannot generate executable scripts that conform to automotive protocols, and lack the ability to utilize historical test results in a closed loop, thus failing to support automated testing in complex scenarios.
By acquiring natural language information and converting it into structured semantic representation, and combining it with vehicle communication protocols and abstract scenario templates, operational information suitable for vehicle communication protocols is generated, which is then filled into preset script templates for static verification and simulation sandbox simulation to ensure the executableness and security of the scripts.
It improves the accuracy of automated generation of test scripts for vehicle intrusion detection systems, enhances the ability of scripts to cover complex scenarios, supports automated execution and result write-back, and optimizes the executability and reproducibility of scripts.
Smart Images

Figure CN121996561A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of script generation technology, and in particular to a method, apparatus, equipment and medium for generating test scripts for vehicle intrusion detection systems. Background Technology
[0002] Modern automobiles rely on multiple ECUs (Electronic Control Units) and buses to build in-vehicle networks. The widespread adoption of vehicle-to-everything (V2X) and autonomous driving technologies makes vehicles vulnerable to cyberattacks such as spoofed messages. Therefore, vehicle intrusion detection systems (VIDS) have become the core of security protection. However, the effectiveness of VIDS depends on thorough testing, and existing test script generation methods are ill-suited to the needs of in-vehicle scenarios, limiting testing efficiency and quality.
[0003] Existing test script generation technologies have significant limitations. Template and rule-based tools rely on manual template maintenance and parameter filling, covering only simple, pre-defined scenarios. For undefined, complex scenarios such as cross-ECU cascading attacks and time-window replays, manual template expansion or handwritten scripts are required, resulting in low coverage and long development cycles. Natural language-based automated testing solutions are primarily GUI (Graphical User Interface) / Application-oriented, lacking support for automotive domain characteristics such as CAN message frames, ECU topology, and timing constraints in their semantic mapping and action libraries. Even when parsing requirements, they cannot generate executable scripts conforming to automotive protocols, requiring extensive manual correction. Furthermore, existing methods lack the ability to utilize historical test results in a closed loop, failing to optimize scripts based on false positives and false negatives. They also have shortcomings in supporting complex scenarios such as multi-node collaborative attacks and concurrent simulations, resulting in poor script executability and reproducibility.
[0004] Therefore, improving the accuracy of automated generation of test scripts for vehicle intrusion detection systems, based on natural language requirements, is a pressing technical problem that needs to be solved. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for generating test scripts for vehicle intrusion detection systems, which can improve the accuracy of automated generation of test scripts for vehicle intrusion detection systems, from natural language requirements. The specific solution is as follows: Firstly, this application provides a method for generating test scripts for vehicle-mounted intrusion detection systems, including: Acquire natural language information corresponding to the testing requirements of the target vehicle, and convert the natural language information into structured semantic representation information; Based on the semantic representation information, a corresponding target abstract scene template is determined, and the target parameters in the target abstract scene template are filled in based on the natural language information and the vehicle communication protocol to obtain abstract scene information. The abstract scene information is then converted into operation information applicable to the vehicle communication protocol. The abstract scene template is an executable use case template containing action and corresponding element information. The operation information is filled into a preset script template to obtain a test script, which is then used to test the vehicle intrusion detection system corresponding to the target vehicle.
[0006] Optionally, converting the natural language information into structured semantic representation information includes: If the natural language information is in text format, then the natural language information is subjected to denoising and word segmentation to obtain the first information; The first information is processed using a recognition rule based on preset keywords to obtain the second information; The second information is processed using a large language model or sequence labeling model to obtain the third information; The target value and target unit in the third information are normalized to obtain the fourth information; The fourth information is verified using preset semantic constraints, and structured semantic representation information is determined based on the verified fourth information. If the natural language information is in speech format, then the speech format natural language information is converted into the text format natural language information, and the process jumps to the step of denoising and segmenting the natural language information until the structured semantic representation information is obtained.
[0007] Optionally, determining the corresponding target abstract scene template based on the semantic representation information includes: Determine the first vector of each abstract scene template in the preset abstract scene template library, and determine the second vector of the semantic representation information; Determine the cosine similarity between the first vector and the second vector, and determine the first vector whose cosine similarity is not less than a preset similarity threshold as the target vector; In the preset abstract scene template library, the abstract scene template corresponding to the target vector is determined as the target abstract scene template.
[0008] Optionally, the step of filling the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol to obtain abstract scene information includes: The target parameters in the target abstract scene template are filled in using a preset rule engine based on the natural language information and the vehicle communication protocol; If the target abstract scene template contains missing parameters that meet preset unknown conditions, then in the historical test records, a similar scene template that has preset similar conditions to the target abstract scene template is determined, and the missing parameters are filled based on the target information corresponding to the similar scene template. The filled target abstract scene template is determined as abstract scene information.
[0009] Optionally, filling the operation information into a preset script template to obtain a test script includes: The on-board testing tools and testing environment of the target vehicle are determined, and the script execution platform is determined based on the on-board testing tools and testing environment; In the script execution platform, the operation information is filled into a preset script template to obtain a test script.
[0010] Optionally, after obtaining the test script, the process further includes: The test script is verified based on preset static syntax rules and preset protocol consistency rules, and the verified test script is simulated in a preset simulation sandbox to detect whether the test script conflicts with a preset constraint library using a preset constraint solver; wherein, the preset constraint library is a constraint library containing temporal constraints and safety constraints for the target vehicle.
[0011] Optionally, testing the vehicle intrusion detection system corresponding to the target vehicle using the test script includes: Determine the simulator or hardware-in-the-loop simulation environment corresponding to the target vehicle; wherein the simulator or hardware-in-the-loop simulation environment includes an on-board intrusion detection system; The test script is run in the simulator or the hardware-in-the-loop simulation environment to test the vehicle intrusion detection system.
[0012] Secondly, this application provides a test script generation device for vehicle-mounted intrusion detection systems, comprising: The first information conversion module is used to acquire natural language information corresponding to the test requirements of the target vehicle and convert the natural language information into structured semantic representation information. The second information conversion module is used to determine the corresponding target abstract scene template based on the semantic representation information, and to fill the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol to obtain abstract scene information, and to convert the abstract scene information into operation information applicable to the vehicle communication protocol; the abstract scene template is an executable use case template containing action and corresponding element information; The script testing module is used to fill the operation information into a preset script template to obtain a test script, which is then used to test the vehicle intrusion detection system corresponding to the target vehicle.
[0013] Thirdly, this application provides an electronic device, comprising: Memory, used to store computer programs; A processor is used to execute the computer program to implement the aforementioned test script generation method for vehicle-mounted intrusion detection systems.
[0014] Fourthly, this application provides a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned test script generation method for vehicle-mounted intrusion detection systems.
[0015] In this application, natural language information corresponding to the testing requirements of the target vehicle is obtained, and the natural language information is converted into structured semantic representation information; based on the semantic representation information, a corresponding target abstract scene template is determined, and the target parameters in the target abstract scene template are filled in based on the natural language information and the vehicle communication protocol to obtain abstract scene information, and the abstract scene information is converted into operation information applicable to the vehicle communication protocol; the abstract scene template is an executable use case template containing action and corresponding element information; the operation information is filled into a preset script template to obtain a test script, which is used to test the vehicle intrusion detection system corresponding to the target vehicle. As can be seen from the above, in this application, natural language information matching the testing requirements of the target vehicle is obtained, and this natural language information is transformed into structured semantic representation information; based on the semantic representation information, a corresponding target abstract scene template is determined; combined with the natural language information and the vehicle communication protocol, the target parameters in the target abstract scene template are filled in to generate abstract scene information; then, the abstract scene information is transformed into operation information that conforms to the requirements of the vehicle communication protocol; wherein, the abstract scene template is an executable use case template covering actions and corresponding element information; the operation information is filled into a preset script template to generate a test script, and then the vehicle intrusion detection system corresponding to the target vehicle is tested using the test script. In this way, this application can improve the accuracy of automated generation of test scripts for vehicle intrusion detection systems from natural language requirements. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0017] Figure 1 This is a flowchart of a test script generation method for an in-vehicle intrusion detection system disclosed in this application; Figure 2 This is a schematic diagram of a test script generation device for a vehicle-mounted intrusion detection system disclosed in this application. Figure 3 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Currently, existing test script generation technologies have significant limitations. Template and rule-based tools rely on manual template maintenance and parameter filling, covering only simple, preset scenarios. For undefined, complex scenarios such as cross-ECU cascading attacks and time-window replays, manual template expansion or handwritten scripts are required, resulting in low coverage and long development cycles. Natural language-based automated testing solutions are mostly geared towards GUI / APP operations, lacking support for automotive domain characteristics such as CAN message frames, ECU topology, and timing constraints in their semantic mapping and action libraries. Even when parsing requirements, they cannot generate executable scripts conforming to automotive protocols, requiring extensive manual correction. Furthermore, existing methods lack the ability to utilize historical test results in a closed loop, failing to optimize scripts based on false positives and false negatives. They also have shortcomings in supporting complex scenarios such as multi-node collaborative attacks and concurrent simulations, resulting in poor script executability and reproducibility. Therefore, this application provides a test script generation method, apparatus, device, and medium for automotive intrusion detection systems, which can improve the accuracy of automated test script generation from natural language requirements to those for automotive intrusion detection systems.
[0020] See Figure 1 As shown in the figure, an embodiment of the present invention discloses a test script generation method for vehicle intrusion detection systems, including: Step S11: Obtain natural language information corresponding to the test requirements of the target vehicle, and convert the natural language information into structured semantic representation information.
[0021] In this embodiment, to generate a script that can drive automated security testing of an in-vehicle intrusion detection system, it is first necessary to obtain an initial description of the test requirements. These natural language descriptions are direct and flexible, but contain a large amount of unstructured, potentially ambiguous, or redundant information that cannot be directly recognized and processed by the test script generation engine. Therefore, a transformation process is necessary to map this free-form natural language information into a precise, standardized, and machine-parsable structured semantic representation, thereby laying the foundation for subsequent test logic construction and script code generation.
[0022] To complete the conversion of natural language information, this embodiment provides a corresponding processing path based on the initial format of the input information. If the natural language information is in text format, it is denoised and segmented to obtain first information; the first information is processed using a recognition rule based on preset keywords to obtain second information; the second information is processed using a large language model or sequence labeling model to obtain third information; the target value and target unit in the third information are normalized to obtain fourth information; the fourth information is verified using preset semantic constraints, and structured semantic representation information is determined based on the verified fourth information.
[0023] In one specific implementation, if the natural language information is in speech format, the speech-formatted natural language information is converted into text-formatted natural language information, and the process proceeds to the steps of denoising and word segmentation of the natural language information until the structured semantic representation information is obtained. Through the above steps, this embodiment achieves a reliable conversion from fuzzy and diverse natural language requirements to accurate and unified structured semantic representation.
[0024] Step S12: Determine the corresponding target abstract scene template based on the semantic representation information, and fill the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol to obtain abstract scene information, and convert the abstract scene information into operation information applicable to the vehicle communication protocol; the abstract scene template is an executable use case template containing action and corresponding element information.
[0025] In this embodiment, after obtaining the structured semantic representation information, it is necessary to map and instantiate the semantic representation information into a specific, executable test scenario framework.
[0026] First, the template that best matches the semantics of the current test requirements needs to be selected from a pre-defined abstract scenario template library as the target abstract scenario template. Specifically, a first vector is determined for each abstract scenario template in the pre-defined abstract scenario template library, and a second vector for the semantic representation information is determined; the cosine similarity between the first vector and the second vector is determined, and the first vector with a cosine similarity not less than a pre-defined similarity threshold is determined as the target vector; in the pre-defined abstract scenario template library, the abstract scenario template corresponding to the target vector is determined as the target abstract scenario template. This method ensures that the selected template is highly consistent with the original requirements in terms of intent.
[0027] After determining the target template, it needs to be populated with parameters to make it specific. Specifically, a preset rule engine is used to populate the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol. If the target abstract scene template contains missing parameters that meet preset unknown conditions, then similar scene templates with preset similar conditions are determined from the historical test records, and the missing parameters are populated based on the target information corresponding to the similar scene templates. The populated target abstract scene template is then determined as abstract scene information, which is a complete test scene description.
[0028] Finally, the abstract scenario information needs to be converted into operation information applicable to the vehicle communication protocol. This conversion mainly solves the problem of protocol difference adaptation. For example, general actions are refined into low-level programmable instruction sequences that conform to the specific frame format, baud rate and addressing mode of the target vehicle network according to its actual protocol. This lays the foundation for generating scripts that can directly drive test equipment or simulation environment.
[0029] Step S13: Fill the operation information into the preset script template to obtain the test script, and use the test script to test the vehicle intrusion detection system corresponding to the target vehicle.
[0030] In this embodiment, the on-board testing tool and testing environment of the target vehicle are determined, and a script execution platform is determined based on the on-board testing tool and the testing environment. Subsequently, in the script execution platform, the operation information is filled into a preset script template to obtain the test script.
[0031] After obtaining the test script, to ensure its correctness and security, the test script is verified based on preset static syntax rules and preset protocol consistency rules. The verified test script is then simulated in a preset simulation sandbox to detect whether the test script conflicts with a preset constraint library using a preset constraint solver. The preset constraint library contains temporal and safety constraints for the target vehicle. The simulation aims to identify potential runtime conflicts in advance.
[0032] Finally, to practically test the vehicle-mounted intrusion detection system, a simulator or hardware-in-the-loop simulation environment corresponding to the target vehicle is determined. This simulator or hardware-in-the-loop simulation environment includes the vehicle-mounted intrusion detection system. The test script is run in this environment to test the system. In other words, it can drive a simulated or real vehicle network bus, execute predetermined attacks or abnormal traffic injections, and observe and record the detection, alarm, and response behaviors of the vehicle-mounted intrusion detection system, thereby completing automated testing and evaluation of its security performance.
[0033] As can be seen from the above, in this application, natural language information matching the testing requirements of the target vehicle is obtained, and this natural language information is transformed into structured semantic representation information; based on the semantic representation information, a corresponding target abstract scene template is determined; combined with the natural language information and the vehicle communication protocol, the target parameters in the target abstract scene template are filled in to generate abstract scene information; then, the abstract scene information is transformed into operation information that conforms to the requirements of the vehicle communication protocol; wherein, the abstract scene template is an executable use case template covering actions and corresponding element information; the operation information is filled into a preset script template to generate a test script, and then the vehicle intrusion detection system corresponding to the target vehicle is tested using the test script. In this way, this application can improve the accuracy of automated generation of test scripts for vehicle intrusion detection systems from natural language requirements.
[0034] The architecture and technical solutions of the embodiments of this application will be described in detail below.
[0035] This application aims to provide a method and system that can automatically convert natural language descriptions of testing requirements into executable test scripts for vehicle intrusion detection systems, improve script generation efficiency, cover complex attack scenarios, and support automated execution, result write-back, and script optimization.
[0036] Specifically, the system architecture of this application includes the following modules: an input module (Natural Input Module), used to receive natural language descriptions of test requirements, such as text and speech-to-text, and perform preprocessing; a semantic parsing module (NLU Module, Natural Language Understanding Module), used to convert natural language into structured semantic representations, such as intent, entities, constraints, and expected behaviors; a scenario reasoning and retrieval module (Scenario Reasoning & Retrieval), used to retrieve matched abstract scenario templates (ASTs) based on semantic representations, and perform parameter filling and scenario combination reasoning. The abstract scenario template refers to a fixed template that converts natural language into executable test cases, removing specific parameters and retaining only specific actions and elements, thus adapting to varying natural language and achieving classification effects; a rule and protocol mapping module (Protocol Mapping Module), used to map abstract scenario parameters to vehicle protocol-level operations, such as CAN (Controller Area Network) message ID, data field, verification, transmission frequency, timing constraints, and ECU targets; and a script template generation module (Script...). The TemplateEngine is used to generate a final runnable script from executable scripting languages / platforms, such as Python + CAN API (Application Programming Interface), Vector CANoe scripts (a type of script for automotive network testing), ROS (Robot Operating System) nodes, MQTT (Message Queuing Telemetry Transport) client scripts, and vehicle simulator APIs. The Validation Module performs static syntax checks, protocol consistency checks, and local sandbox simulations, automatically correcting parameters when necessary. The Execution Engine distributes the scripts to the test platform, such as HIL (Hardware-in-the-Loop) / simulator / real vehicle, for execution and result collection. The Result Analysis & Learning module analyzes detector responses, such as alarms / logs / performance, and writes valid / invalid scripts and results to a historical test case database for subsequent script optimization and recommendation.Management and user interface (UI / UX) are used to provide natural language input, script preview, manual parameter editing, execution monitoring, and report generation.
[0037] It should be noted that the databases and knowledge resources that the system in this application needs to maintain include: a protocol knowledge base (i.e., Protocol KB), which contains message formats, ID allocation, verification algorithms, and data domain resolution rules for CAN, CAN-FD (Controller Area Network - Flexible Data-Rate), LIN (Local Interconnect Network), Ethernet, OBD (On-Board Diagnostics), and UDS (Unified Diagnostic Services); and a function / topology model library (i.e., ECU Topology & Function). The Model includes vehicle ECU topology such as ECU name, function, controllable messages, and subscription relationships; key security parameters such as message IDs and value ranges for speed, braking, and steering; an Abstract Scenario Template Library (AST) containing intrusion scenarios represented by structured templates, such as CAN replay, message forgery, rate injection, fuzzing, delay injection, and cross-ECU collaborative attacks. Templates include required parameters, optional parameters, preconditions, and post-verification items; a Test Case History library containing executed scripts, such as execution results (success / failure / false positive / missed positive), detector alarm logs, and environmental parameters such as hardware / firmware version; and a Policy and Constraints KB library containing timing constraints, upper limits on transmission frequency, thresholds, and security constraints to avoid dangers to real vehicles, such as disallowing the injection of physically dangerous commands under high-speed driving conditions in real vehicles, or only running high-risk scripts in simulators.
[0038] The data structure code for the abstract scene template in JSON (JavaScript Object Notation) format can be shown below: { "template_id": "CAN_REPLAY_WINDOW", "name": "CAN Replay_Time Window", "description": "Replay the target CAN ID within the specified time window to trigger detection", "parameters": { "target_ecu": {"type":"string","required":true}, "can_id": {"type":"hex","required":true}, "replay_rate": {"type":"float","default":10.0}, / / Hz "duration": {"type":"int","default":30} / / seconds }, "preconditions": ["SUT_mode==idle"], "postchecks": ["IDS_alarm==true"] } The following is a detailed description of the process from natural language to script execution in this technical solution.
[0039] First, the system receives natural language testing requests. Users input their natural language requests into the UI, such as: "Simulate injecting abnormal speed messages with a speed value of 300 km / h continuously into the engine ECU with ID 0x201 at a vehicle speed of 50 km / h and observe whether the VIDS alarms." The system preprocesses the input text, such as denoising, sentence segmentation, and entity recognition. If it is voice input, it converts the speech to text.
[0040] Secondly, NLU semantic parsing is performed. The NLU Natural Language Understanding module uses intent classification and entity extraction, which can be achieved using a hybrid model such as rule-based + statistical methods: First, rule-based keyword recognition is applied, where keywords can include "injection," "replay," "ECU," "CAN ID," and "speed." Then, pre-trained LLM (Large Language Model) / sequence labeling models, such as BiLSTM-CRF (Bidirectional Long Short-Term Memory - Conditional Random Field) or Transformer-based NER (Named Entity Recognition), are used to accurately extract entities and intents. Numerical values and units are normalized, such as converting km / h to protocol units, and semantic constraints are checked, for example, speed values should be within the range of 0 to 1000 km / h. A structured semantic representation is then output. The code snippet for the structured semantic representation can be shown below: { "intent":"generate_test_script", "entities":{ "target_ecu":"Engine_ECU", "can_id":"0x201", "attack_type":"Abnormal velocity injection", "speed_value":"300", "vehicle_speed_condition":"50", "duration":"30s" } } Then, abstract scene retrieval and parameter inference are performed. The abstract scene template is represented by a vectorized structure, such as template text + parameter vector. The semantic representation output by NLU is also encoded as a vector, and the most suitable AST is matched through similarity retrieval, such as calculating cosine similarity. If the similarity is lower than a threshold of, for example, 0.7, the system returns a candidate template and asks the user to confirm or supplement information. For example, in the case of abnormal speed injection, the scene retrieval module retrieves the AST abstract scene template CAN_FORGED_SPEED_INJECTION based on intent and entities. The generated or filled parameters can be: can_id=0x201;speed_field=bytes[2..3];value=30000;rate=10Hz;duration=30s;precondition:vehicle_speed==50km / h. Among them, 30000 in value is 300km / h. The generated target script can be: Python + python-can, which includes environmental checks such as vehicle speed detection and execution log recording. The expected result might be: VIDS triggers a "speed anomaly" alarm within t < 5s; the alarm time and alarm code are recorded. For example, in the case of CAN replay within a time window, the received natural language could be: "Start replaying the historical frame 0x1AB 10s after startup, continue for 20s, 50 frames per second, and observe whether DoS detection is triggered." The corresponding parameterized script could be: perform cyclic transmission based on the historical frame file, control the transmission rate, and record SUT (System Under Test) packet loss, delay, and IDS (Intrusion Detection System) alarms.
[0041] During parameter inference, the rule engine prioritizes filling in known mappings, namely Protocol KB and Topology KB. If missing parameters occur, the heuristic inferencer fills in default values based on the average parameters of similar templates from historical tests, and marks the fields "recommended for manual confirmation" in the script. For multi-node collaborative attack scenarios, graph traversal based on ECU topology is used to identify message flow and dependency chains, ensuring that the generated script can be collaboratively injected among multiple nodes at the appropriate time. Furthermore, parameter inference considers context and protocol knowledge in natural language: if can_id does not specify the data field position, it retrieves "speed in data[2:3] field" from the protocol (i.e., Protocol KB). If the semantics mention "engine ECU", the target ECU is mapped to the corresponding node in the topology library, and it is checked whether the ECU has subscribed to the CANID. If it has not subscribed, the user is prompted or the nearest similar ID is automatically selected.
[0042] Next, protocol mapping is performed. The rule and protocol mapping module converts the abstract parameters into low-level message construction rules: CAN frame ID: 0x201; data field length: 8 bytes; speed field byte offset: 2, and the corresponding storage rules determine whether it is big-endian or little-endian through the vehicle protocol; speed encoding: unit 0.01km / h, 300km / h is encoded as 30000; verification: if there is CRC (i.e., Cyclic Redundancy Check) or security code, a forged value is filled in or injected, and the verification strategy is recorded.
[0043] Finally, a script template is generated and populated. The script generation module selects a suitable script execution platform, such as Python + python-can library for connecting to the CAN interface; or Vector CANoe CAPL script, and populates the pseudo-script. Simultaneously, script metadata is generated, such as environment requirements, dependent libraries, SUT configuration, and execution pre-steps, such as setting the vehicle to test_mode and simulator loading scenarios. Additionally, the system exposes RESTful API / gRPC (Google Remote Procedure Call) interfaces for CI / CD (Continuous Integration / Continuous Delivery) pipeline calls; it supports exporting scripts in multiple formats, such as Python, CAPL, and JSON streaming script files. The generated scripts can be deployed in a hybrid architecture combining cloud services (including training and template management) and local deployment on the factory network, ensuring that sensitive data such as vehicle topology and private protocols do not leave the customer's internal network. Regarding the performance metrics of the generated scripts, the target end-to-end generation latency, i.e., the latency from inputting natural language to generating an executable script, should be within the range required in common scenarios. 5s; Script generation success rate, i.e., the percentage of scripts that can be executed directly. 85%; First-time trigger rate, i.e., whether IDS can be triggered in a single execution, is linked with the historical database for continuous optimization. Specifically, the pseudo-script code snippet can be shown below: # Python + python-can example import can from canlib bus = can.interface.Bus(channel='can0', bustype='socketcan') def send_forged_speed(): data = [0x00,0x01,0x75,0x30,0x00,0x00,0x00,0x00] # 300 encoded... msg = can.Message(arbitration_id=0x201,data=data,is_extended_id=False) start_time = time.time() while time.time()-start_time < 30: bus.send(msg) time.sleep(0.1) # 10 Hz Furthermore, the final generated script can undergo static validation and sandbox simulation. Specifically, the validation module performs static checks on the script's syntax and protocol field boundaries, and uses a constraint solver to check whether timing and frequency parameters meet vehicle safety policies. If constraint conflicts are found, the system optimizes the objective, such as minimizing risk while maintaining attack effectiveness, to find parameter adjustment schemes. The script is then pre-run in a local simulation sandbox, such as a CAN simulator, to detect whether it violates the constraint library (Constraints KB), for example, whether it will send overclocking messages or high-risk commands. If a conflict occurs, the system automatically modifies the parameters or returns confirmation to the user. Further, validated scripts can be deployed for execution and monitoring. This means the validated script is transmitted to the execution engine, which runs the script on the HIL or real vehicle test platform according to safety policies, while simultaneously collecting SUT IDS alarms, ECU logs, network traffic, and power consumption data. In principle, the system prioritizes running high-risk scripts, such as injecting braking commands that endanger safety, in the simulator or HIL environment. For scripts that can run on a real vehicle, safety prerequisites must be met, such as the vehicle being parked / ignited / at low speed and under human supervision, and operator confirmation is required. This safety policy is part of the system constraint library and is enforced during static validation.
[0044] Furthermore, the execution of the script can be analyzed and learned. The result analysis module compares the execution results with the expected results, such as whether the detector is triggered, the trigger delay, the false alarm rate, and the system load, and writes the script and results to the history database. If the script performs unstablely in multiple executions, the learning module will adjust the template parameters, such as adjusting the injection frequency or the data encoding method, to improve the trigger rate or cover more detection paths.
[0045] It is evident that this application converts natural language input into a structured semantic representation using NLU and performs template matching with the AST library and protocol KB. Therefore, the system can automatically identify test case intent and locate appropriate attack scenarios, significantly reducing the time cost of manually writing scripts. This application introduces protocol mapping and topology reasoning, mapping abstract scenario parameters to CAN message fields, verification methods, and ECU targets. Consequently, the generated scripts are executable, i.e., not pseudocode, and can be directly executed in HIL / simulation / real vehicle environments, thereby improving script implementation rate and testing efficiency. Because the system performs static verification and sandbox simulation on the generated scripts and adds safety constraints, dangerous instructions are prevented from being directly executed on real vehicles, improving test safety and making the scripts usable for industrial regression testing. Since the result analysis module writes the execution results back to the historical library and learns from them, the system can automatically optimize template parameters based on historical execution feedback, improving the effectiveness and coverage of subsequent scripts and forming a closed-loop self-optimization capability. In summary, this application can achieve automated, semantic, executable, and self-learning test script generation for automotive intrusion detection systems.
[0046] Accordingly, see Figure 2 As shown in the figure, this application provides a test script generation device for vehicle intrusion detection systems, including: The first information conversion module 11 is used to acquire natural language information corresponding to the test requirements of the target vehicle and convert the natural language information into structured semantic representation information. The second information conversion module 12 is used to determine the corresponding target abstract scene template based on the semantic representation information, and to fill the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol to obtain abstract scene information, and to convert the abstract scene information into operation information applicable to the vehicle communication protocol; the abstract scene template is an executable use case template containing action and corresponding element information; The script testing module 13 is used to fill the operation information into a preset script template to obtain a test script, and to use the test script to test the vehicle intrusion detection system corresponding to the target vehicle.
[0047] In some specific embodiments, the first information conversion module 11 specifically includes: The first information processing unit is configured to perform noise reduction and word segmentation on the natural language information if the natural language information is in text format, to obtain the first information; The second information processing unit is used to process the first information using a recognition rule based on preset keywords to obtain the second information; The third information processing unit is used to process the second information using a large language model or a sequence labeling model to obtain the third information; The fourth information processing unit is used to normalize the target value and target unit in the third information to obtain the fourth information; The first information determination unit is used to verify the fourth information using preset semantic constraints, and to determine structured semantic representation information based on the verified fourth information. The second information determination unit is used to convert the natural language information in the speech format into the natural language information in the text format if the natural language information is in speech format, and then jump to the step of denoising and segmenting the natural language information until the structured semantic representation information is obtained.
[0048] In some specific embodiments, the second information conversion module 12 specifically includes: The first vector determination unit is used to determine the first vector of each abstract scene template in the preset abstract scene template library, and to determine the second vector of the semantic representation information; The second vector determination unit is used to determine the cosine similarity between the first vector and the second vector, and to determine the first vector whose cosine similarity is not less than a preset similarity threshold as the target vector. The template determination unit is used to determine the abstract scene template corresponding to the target vector as the target abstract scene template in the preset abstract scene template library.
[0049] In some specific embodiments, the second information conversion module 12 specifically includes: The first parameter filling unit is used to fill the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol using a preset rule engine; The second parameter filling unit is used to determine, in the historical test records, a similar scene template that has a preset similarity condition to the target abstract scene template if the target abstract scene template contains a missing parameter that meets a preset unknown condition, and fill the missing parameter based on the target information corresponding to the similar scene template. The scene information determination unit is used to determine the filled target abstract scene template as abstract scene information.
[0050] In some specific embodiments, the script testing module 13 specifically includes: The platform determination unit is used to determine the on-board testing tools and testing environment of the target vehicle, and to determine the script execution platform based on the on-board testing tools and testing environment; The information filling unit is used to fill the operation information into a preset script template in the script running platform to obtain a test script.
[0051] In some specific embodiments, the script testing module 13 further includes: The script detection unit is used to verify the test script based on preset static syntax rules and preset protocol consistency rules, and to perform a simulation pre-run operation on the verified test script in a preset simulation sandbox, so as to use a preset constraint solver to detect whether the test script conflicts with a preset constraint library; wherein, the preset constraint library is a constraint library containing temporal constraints and safety constraints for the target vehicle.
[0052] In some specific embodiments, the script testing module 13 specifically includes: The test environment determination unit is used to determine the simulator or hardware-in-the-loop simulation environment corresponding to the target vehicle; wherein the simulator or the hardware-in-the-loop simulation environment includes an on-board intrusion detection system; The system testing unit is used to run the test script in the simulator or the hardware-in-the-loop simulation environment to test the vehicle intrusion detection system.
[0053] Furthermore, embodiments of this application also disclose an electronic device, Figure 3 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the test script generation method for vehicle-mounted intrusion detection systems disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be a computer.
[0054] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0055] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0056] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the test script generation method for a vehicle-mounted intrusion detection system executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0057] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned method for generating test scripts for vehicle-mounted intrusion detection systems. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0058] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0059] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0060] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0061] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0062] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for generating test scripts for vehicle-mounted intrusion detection systems, characterized in that, include: Acquire natural language information corresponding to the testing requirements of the target vehicle, and convert the natural language information into structured semantic representation information; Based on the semantic representation information, a corresponding target abstract scene template is determined, and the target parameters in the target abstract scene template are filled in based on the natural language information and the vehicle communication protocol to obtain abstract scene information. The abstract scene information is then converted into operation information applicable to the vehicle communication protocol. An abstract scenario template is an executable use case template that includes action and corresponding element information. The operation information is filled into a preset script template to obtain a test script, which is then used to test the vehicle intrusion detection system corresponding to the target vehicle.
2. The test script generation method for vehicle-mounted intrusion detection systems according to claim 1, characterized in that, The process of converting the natural language information into structured semantic representation information includes: If the natural language information is in text format, then the natural language information is subjected to denoising and word segmentation to obtain the first information; The first information is processed using a recognition rule based on preset keywords to obtain the second information; The second information is processed using a large language model or sequence labeling model to obtain the third information; The target value and target unit in the third information are normalized to obtain the fourth information; The fourth information is verified using preset semantic constraints, and structured semantic representation information is determined based on the verified fourth information. If the natural language information is in speech format, then the speech format natural language information is converted into the text format natural language information, and the process jumps to the step of denoising and segmenting the natural language information until the structured semantic representation information is obtained.
3. The test script generation method for vehicle-mounted intrusion detection systems according to claim 1, characterized in that, The step of determining the corresponding target abstract scene template based on the semantic representation information includes: Determine the first vector of each abstract scene template in the preset abstract scene template library, and determine the second vector of the semantic representation information; Determine the cosine similarity between the first vector and the second vector, and determine the first vector whose cosine similarity is not less than a preset similarity threshold as the target vector; In the preset abstract scene template library, the abstract scene template corresponding to the target vector is determined as the target abstract scene template.
4. The test script generation method for vehicle-mounted intrusion detection systems according to claim 1, characterized in that, The process of filling the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol to obtain abstract scene information includes: The target parameters in the target abstract scene template are filled in using a preset rule engine based on the natural language information and the vehicle communication protocol; If the target abstract scene template contains missing parameters that meet preset unknown conditions, then in the historical test records, a similar scene template that has preset similar conditions to the target abstract scene template is determined, and the missing parameters are filled based on the target information corresponding to the similar scene template. The filled target abstract scene template is determined as abstract scene information.
5. The test script generation method for vehicle-mounted intrusion detection systems according to claim 1, characterized in that, The step of filling the operation information into a preset script template to obtain a test script includes: The on-board testing tools and testing environment of the target vehicle are determined, and the script execution platform is determined based on the on-board testing tools and testing environment; In the script execution platform, the operation information is filled into a preset script template to obtain a test script.
6. The test script generation method for a vehicle-mounted intrusion detection system according to claim 1, characterized in that, After obtaining the test script, the process also includes: The test script is verified based on preset static syntax rules and preset protocol consistency rules, and the verified test script is simulated in a preset simulation sandbox to detect whether the test script conflicts with a preset constraint library using a preset constraint solver; wherein, the preset constraint library is a constraint library containing temporal constraints and safety constraints for the target vehicle.
7. The test script generation method for a vehicle-mounted intrusion detection system according to any one of claims 1 to 6, characterized in that, The step of testing the vehicle intrusion detection system corresponding to the target vehicle using the test script includes: Determine the simulator or hardware-in-the-loop simulation environment corresponding to the target vehicle; wherein the simulator or hardware-in-the-loop simulation environment includes an on-board intrusion detection system; The test script is run in the simulator or the hardware-in-the-loop simulation environment to test the vehicle intrusion detection system.
8. A test script generation device for vehicle-mounted intrusion detection systems, characterized in that, include: The first information conversion module is used to acquire natural language information corresponding to the test requirements of the target vehicle and convert the natural language information into structured semantic representation information. The second information conversion module is used to determine the corresponding target abstract scene template based on the semantic representation information, and to fill the target parameters in the target abstract scene template based on the natural language information and the vehicle communication protocol to obtain abstract scene information, and to convert the abstract scene information into operation information applicable to the vehicle communication protocol. An abstract scenario template is an executable use case template that includes action and corresponding element information. The script testing module is used to fill the operation information into a preset script template to obtain a test script, which is then used to test the vehicle intrusion detection system corresponding to the target vehicle.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the test script generation method for a vehicle-mounted intrusion detection system as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the test script generation method for a vehicle-mounted intrusion detection system as described in any one of claims 1 to 7.