Vehicle-mounted code fault diagnosis method and device

By extracting semantic features from the vehicle source code and constructing an interrupt priority graph and resource contention network, a fault tree is generated for fault diagnosis. This solves the problem of low coverage and accuracy in vehicle code fault diagnosis, and achieves comprehensive and accurate diagnosis of vehicle code faults, meeting the ISO 26262 standard.

CN121658340APending Publication Date: 2026-03-13CHINA AUTOMOTIVE INNOVATION CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511664716.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-13
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing technologies for vehicle-mounted code fault diagnosis suffer from insufficient fault coverage and low accuracy, especially in complex virtualization scenarios where they fail to meet the ASIL-D level requirements of the ISO 26262 standard.

Method used

By extracting semantic features of target code segments from vehicle source code, constructing interrupt priority graphs and resource contention networks, generating target fault trees, and performing fault diagnosis based on fault mode-effect analysis tables, the system integrates code semantic parsing and dynamic fault tree generation to achieve comprehensive and accurate diagnosis of vehicle code faults.

Benefits of technology

It significantly improves the comprehensiveness and accuracy of vehicle code fault identification and diagnosis, and can uncover many hidden faults that are difficult to detect, meeting the high fault coverage requirements of the ISO 26262 standard.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121658340A_ABST
    Figure CN121658340A_ABST
Patent Text Reader

Abstract

The invention discloses a vehicle-mounted code fault diagnosis method and device, and the method comprises the steps: extracting semantic features of a target code segment from a code feature sequence of a vehicle-mounted source code, and obtaining target features; performing dynamic position coding on the vehicle-mounted source code, constructing a time sequence constraint feature according to a coding result, and constructing an interrupt priority graph based on the target feature and the time sequence constraint feature; generating a target fault tree based on the interrupt priority graph and a pre-constructed resource competition relationship network; the target fault tree comprises an event node set, a gating event edge set and a node fault probability, and the node fault probability is determined by a connection weight of an interrupt priority graph and a connection weight of a resource competition network; and the fault mode-influence analysis table is generated based on the target fault tree, and fault diagnosis is performed according to the fault mode-influence analysis table, so that the comprehensiveness and accuracy of fault identification and diagnosis of the vehicle-mounted code can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of code analysis, and in particular relates to a method and apparatus for diagnosing faults in vehicle codes. Background Technology

[0002] In the digital age, code is widely used in various fields, especially in automotive control, where the reliability of code directly affects the correctness of vehicle control functions and the safety of passengers. Current technologies typically employ static analysis for fault diagnosis of in-vehicle code; however, this method can lead to missed detections. Furthermore, in automotive applications, the ISO 26262 standard requires ASIL-D level systems to have a fault coverage rate of ≥99%, while traditional methods achieve less than 85% accuracy in fault tree logic under complex virtualization scenarios, and the potential impact omission rate in Failure Mode and Effects Analysis (FMEA) tables exceeds 15%, resulting in poor comprehensiveness and accuracy in fault diagnosis.

[0003] Therefore, improving the comprehensiveness and accuracy of fault identification and diagnosis of vehicle codes is an urgent technical problem to be solved. Summary of the Invention

[0004] This application provides a method and apparatus for diagnosing vehicle codes, which can improve the comprehensiveness and accuracy of fault identification and diagnosis of vehicle codes.

[0005] On the one hand, embodiments of this application provide a method for diagnosing faults in vehicle-mounted codes, the method comprising: Semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code to obtain the target features; the target code segment is a code segment in a preset module that has security risks. The vehicle source code is dynamically position-encoded, and a temporal constraint feature is constructed based on the encoding result. The temporal constraint feature is used to characterize the temporal dependency strength between each code position in the vehicle source code. Based on the target features and the timing constraint features, an interrupt priority graph is constructed. The interrupt priority graph includes multiple interrupt nodes and multiple connection edges. Each interrupt node represents an interrupt syntax module, and each connection edge indicates that two connected interrupt nodes have an interrupt nesting relationship. Each connection edge includes a connection weight, which represents the fault propagation probability between two connected interrupt nodes. Based on the interruption priority graph and the pre-constructed resource contention network, a target fault tree is generated; the target fault tree includes a set of event nodes, a set of gated event edges, and node failure probabilities, wherein the node failure probabilities are determined by the connection weights of the interruption priority graph and the connection weights of the resource contention network. A fault mode-impact analysis table is generated based on the target fault tree, and fault diagnosis is performed based on the fault mode-impact analysis table.

[0006] In one exemplary embodiment, the step of extracting semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain target features includes: Each syntax node in the abstract syntax tree corresponding to the vehicle source code is labeled with a preset module semantic tag to obtain a set of labeled syntax nodes; the preset module semantic tag is used to characterize the category of the preset module to which the syntax node belongs; Based on the abstract syntax tree, control flow graph, and data flow graph of the vehicle source code, a hybrid representation graph is constructed; the hybrid representation graph includes a set of code nodes and a set of connecting edges, the set of code nodes includes syntax nodes of the abstract syntax tree, control code nodes of the control flow graph, and data nodes of the data flow graph; the set of connecting edges includes connecting edges in the abstract syntax tree, connecting edges in the control flow graph, and connecting edges in the data flow graph; Based on the hybrid representation diagram and the annotated set of syntax nodes, the target code segment with security risks in the preset module is determined; The semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code and enhanced to obtain the target features.

[0007] In one exemplary embodiment, the step of dynamically encoding the vehicle-mounted source code and constructing temporal constraint features based on the encoding results includes: The vehicle-mounted source code is dynamically position-encoded based on the task execution sequence and the set of temporal constraints to obtain the positional features of each code position in the vehicle-mounted source code; the task execution sequence includes the execution timestamp of each code position; The similarity between the first position feature corresponding to the first code position and the second position feature corresponding to the second code position is calculated to obtain the similarity result; the first code position and the second code position are any two code positions of the vehicle source code; The timing dependency is calculated by performing a timing dependency calculation on the first execution timestamp corresponding to the first code position and the second execution timestamp corresponding to the second code position; The temporal constraint features are determined based on the similarity results and the temporal dependency results.

[0008] In one exemplary embodiment, constructing an interruption priority graph based on the target features and the timing constraint features includes: The code module category identification process is performed from the vehicle source code to obtain the set of interrupt module nodes and the interrupt entry code location corresponding to each interrupt module node. The initial priority is adjusted based on the similarity between the semantic features of the interrupt module node and the target features to obtain an intermediate priority; The intermediate priority of each interrupt module node is normalized to obtain the associated priority of each interrupt module node. Based on the first interrupt entry code position corresponding to the first interrupt module node, the second interrupt entry code position corresponding to the second interrupt module node, and the timing constraint characteristics, the interrupt timing constraint characteristics between the first interrupt module node and the second interrupt module node are determined. Based on the first association priority of the first interrupt module node, the second association priority of the second interrupt module node, and the interrupt timing constraint characteristics, the fault propagation probability between the first interrupt module node and the second interrupt module node is determined. The interrupt priority graph is constructed using the interrupt module nodes in the interrupt module node set as nodes, the nesting relationship as connecting edges, and the fault propagation probability as the connecting edge weight.

[0009] In one exemplary embodiment, the method further includes: Acquire the system resources of the vehicle operating system and construct them as a set of resource nodes; If the resource usage time windows corresponding to the first resource node and the second resource node overlap, and the duration of the overlapping portion is greater than a preset conflict threshold, it is determined that there is a connection edge between the first resource node and the second resource node, thus obtaining an edge set; the first resource node and the second resource node are any two resource nodes in the resource node set. The competition intensity between the first resource node and the second resource node is determined based on the intersection-exchange ratio of the resource usage time windows corresponding to the first resource node and the second resource node. The resource competition relationship network is constructed by using the resource nodes in the resource node set as nodes, the edge set as connecting edges, and the competition intensity as the weight of the connecting edges.

[0010] In one exemplary embodiment, generating the target fault tree based on the interrupt priority graph and resource contention network includes: The nodes in the interruption priority graph, the nodes in the resource contention network, and the top-level failure event are identified as the event node set; Based on the semantic similarity, temporal similarity, priority score, resource conflict score, and historical co-occurrence score of the first event node and the second event node, a gated event edge is determined between the first event node and the second event node, resulting in a set of gated event edges; the first event node and the second event node are any two event nodes in the event node set. The node failure probability distribution is determined based on the connection edge weights of each connection edge in the interruption priority diagram and the connection edge weights of each connection edge in the resource competition relationship network. The target fault tree is constructed based on the set of event nodes, the set of gated event edges, and the node fault probability distribution.

[0011] In one exemplary embodiment, generating a failure mode-effects analysis table based on the target fault tree includes: A code knowledge graph is constructed based on the hybrid representation graph, the interrupt priority graph, and the resource contention relationship network; The code knowledge graph is semantically aligned with a pre-built automotive-grade security vulnerability database to generate an extended knowledge graph; Based on the temporal constraint characteristics between any two entity nodes in the extended knowledge graph, a temporal edge is added to the extended knowledge graph to obtain a temporal knowledge graph. The fault mode-impact analysis table is generated based on the time-series knowledge graph and the target fault tree.

[0012] In one exemplary embodiment, generating the fault mode-effects analysis table based on the time-series knowledge graph and the target fault tree includes: The temporal knowledge graph and the target fault tree are fused to construct an enhanced fault propagation graph. The nodes in the enhanced fault propagation graph include nodes in the temporal knowledge graph and event nodes in the target fault tree. The edges in the enhanced fault propagation graph include connection edges in the temporal knowledge graph, gated event edges in the target fault tree, and cross-structure link edges. The cross-structure link edges are used to associate code nodes in the temporal knowledge graph with event nodes in the target fault tree. Starting from the preset fault source node in the enhanced fault propagation graph and ending at the node corresponding to the top-level fault event, a graph search process is performed on the enhanced fault propagation graph to obtain a set of fault propagation paths corresponding to each preset fault source node. For any top-level failure event, a root cause candidate set corresponding to the top-level failure event is selected from the enhanced failure propagation graph according to the failure propagation path; the root cause candidate set includes at least one preset failure source node; Based on the root cause score, target root cause nodes are selected from the root cause candidate set, and failure root cause suggestions are generated. The fault mode-impact analysis table is generated based on the fault mode description of each preset fault source node, the set of fault propagation paths corresponding to each preset fault source node, and the fault root cause suggestions.

[0013] In one exemplary embodiment, the step of filtering target root cause nodes from the root cause candidate set based on root cause scores includes: Based on severity, probability of occurrence, and detectability, a risk priority coefficient is determined for the preset fault source node corresponding to each fault propagation path; the probability of occurrence is determined by the node fault probability distribution of the target fault tree; the severity is obtained by mapping from a preset strategy. The root cause score of each preset fault source node in the root cause candidate set is determined based on the risk priority coefficient, path decay coefficient, and semantic sensitivity coefficient. The preset fault source nodes are sorted according to the root cause score, and the preset number of fault source nodes at the top of the sort are determined as the target root cause nodes.

[0014] On the other hand, this application also provides a fault diagnosis device for vehicle codes, the device comprising: The target feature extraction module is used to extract the semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain the target features; the target code segment is a code segment with security risks in the preset module; The temporal constraint feature determination module is used to perform dynamic position encoding on the vehicle source code and construct temporal constraint features based on the encoding results. The temporal constraint features are used to characterize the temporal dependency strength between each code position in the vehicle source code. An interrupt priority graph construction module is used to construct an interrupt priority graph based on the target features and the timing constraint features. The interrupt priority graph includes multiple interrupt nodes and multiple connection edges. Each interrupt node represents an interrupt syntax module, and each connection edge indicates that there is an interrupt nesting relationship between two connected interrupt nodes. Each connection edge includes a connection weight, and the connection weight represents the fault propagation probability between two connected interrupt nodes. The target fault tree construction module is used to generate a target fault tree based on the interruption priority graph and the pre-built resource contention network. The target fault tree includes a set of event nodes, a set of gated event edges, and node failure probabilities. The node failure probabilities are determined by the connection weights of the interruption priority graph and the connection weights of the resource contention network. The fault diagnosis module is used to generate a fault mode-impact analysis table based on the target fault tree, and to perform fault diagnosis based on the fault mode-impact analysis table.

[0015] On the other hand, this application also provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the vehicle code fault diagnosis method as described above.

[0016] On the other hand, this application also provides a computer storage medium storing at least one instruction or at least one program, which is loaded and executed by a processor to implement the vehicle code fault diagnosis method as described above.

[0017] On the other hand, this application also provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform a fault diagnosis method for vehicle-mounted codes as described above.

[0018] The fault diagnosis method for vehicle codes provided in this application has the following technical effects: The method provided in this application extracts semantic features of target code segments from the code feature sequence of vehicle source code to obtain target features; performs dynamic position encoding on the vehicle source code and constructs temporal constraint features based on the encoding results to characterize the temporal dependency strength between code positions in the vehicle source code, thereby fully utilizing the dynamic semantic information of the vehicle source code to capture the dynamic semantic associations between codes; then, based on the target features and temporal constraint features, constructs an interrupt priority graph, where each interrupt node represents an interrupt syntax module, each connection edge indicates that two connected interrupt nodes have an interrupt nesting relationship, and each connection edge includes a connection weight, characterizing the fault propagation probability between two connected interrupt nodes. Next, based on the interrupt priority graph and the pre-built resource contention network, a target fault tree is generated. The node failure probability of the target fault tree is jointly determined by the connection weights of the interrupt priority graph and the resource contention network, thereby explicitly modeling faults such as interruptions, timing dependencies, and resource conflicts, avoiding the omission of related faults. Then, a fault mode-effect analysis table is generated based on the target fault tree, and fault diagnosis is performed based on the fault mode-effect analysis table. By integrating code semantic parsing, dynamic fault tree generation, and FMEA analysis, accurate modeling and safety extension of vehicle code fault modes are achieved, which can uncover many hidden faults that are difficult to detect, significantly improving the comprehensiveness and accuracy of fault identification and diagnosis. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of this application, 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 some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a flowchart illustrating the fault diagnosis method for vehicle-mounted codes provided in an embodiment of this application; Figure 2 This is a schematic diagram of the process for determining target features provided in an embodiment of this application; Figure 3 This is a schematic diagram of the process for constructing an interrupt priority map provided in an embodiment of this application; Figure 4 This is a flowchart illustrating the process of generating a failure mode-effect analysis table provided in an embodiment of this application. Figure 5 This is a flowchart illustrating the fault diagnosis method for vehicle-mounted codes provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of the vehicle code fault diagnosis device provided in the embodiments of this application; Figure 7 This is a hardware structure block diagram of a server for a fault diagnosis method for vehicle-mounted codes provided in an embodiment of this application. Detailed Implementation

[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0022] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0023] Figure 1 This is a flowchart illustrating the vehicle code fault diagnosis method provided in an embodiment of this application. Figure 1 As shown, the method provided in this application includes: S101: Extract the semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain the target features; The target code segment is a code segment within a preset module that poses a security risk; the preset module may include an interrupt handling module, a task scheduling module, a resource allocation module, etc. In one example, the target code segment may be a security-sensitive code segment involving privileged instruction usage, critical section protection, etc.

[0024] In one embodiment, the vehicle-mounted source code can be C code, etc., and this application does not limit the code language. The vehicle-mounted source code can be denoted as a code sequence W={w1,w2,…,w…} n}, w i Let H be the i-th code token in the code sequence. Inputting this code sequence into a pre-trained code encoding model for code feature extraction yields a context-aware semantic representation H, i.e., the code feature sequence. In one example, the code encoding model could be the CodeBERT model, which is based on the Transformer architecture and pre-trained on a large-scale code corpus through a masked language model and a next-sentence prediction task. Then, the code feature sequence can be represented as H = CodeBERT(W) = {h1, h2, ..., h...} n}, where h i This represents the semantic features of the i-th code token.

[0025] After identifying the target code segment, the corresponding semantic features can be extracted from the code feature sequence based on the code token contained in the target code segment to obtain the target features.

[0026] S103: Perform dynamic position encoding on the vehicle source code and construct temporal constraint features based on the encoding results; The temporal constraint feature is used to characterize the temporal dependency strength between different code locations in the vehicle source code. In one embodiment, through the dynamic position encoding function P dyn The temporal constraints in real-time task scheduling can be transformed into position embedding vectors, as shown in the following formula: P seq =P dyn (T exec C constraint ,τ deadline ) Among them, T exec ={t1,t2,…,t n} represents the task execution sequence, Cconstraint ={c ij} represents the set of time-series constraints, τ deadline Let P represent the set of task deadlines. seq This represents the encoding result, i.e., the positional encoding vector.

[0027] Position encoding vector P seq Each element in It can be represented as:

[0028] in, This represents the positional characteristics of code position i. For time base parameters, For model dimensions.

[0029] Then, based on the encoding results, temporal constraint features are constructed, which can be denoted as M. time [i,j] represents the temporal dependency strength between code position i and code position j.

[0030] S105: Construct an interrupt priority map based on target features and timing constraint features; The interrupt priority graph includes multiple interrupt nodes and multiple connection edges. Each interrupt node represents an interrupt syntax module, and each connection edge indicates that there is an interrupt nesting relationship between two connected interrupt nodes. Each connection edge includes a connection weight, which represents the fault propagation probability between two connected interrupt nodes. Interrupt priority map can be denoted as G int =(V int E int W int ), where the node set V int ={v1,v2,…,v n} represents the interrupt handling module, and the edge set E int ={(v i ,v j | There is an interruption nesting relationship}, weight matrix W int [i,j] represents the interrupted node v i to v j The probability of fault propagation is determined based on target characteristics and temporal constraint characteristics.

[0031] S107: Generate a target fault tree based on the interrupt priority graph and the pre-built resource contention network; the target fault tree includes a set of event nodes, a set of gated event edges, and node failure probabilities, wherein the node failure probabilities are determined by the connection weights of the interrupt priority graph and the connection weights of the resource contention network. Resource competition networks are graph structures, which can be denoted as G.res =(V res E res C res ), where the node set V res ={r1,r2,…,r m} represents system resources, and the edge set Eres = {(r i ,r j There is a resource competition relationship. The weight matrix C res [i,j] represents resource r i and r j The intensity of competition.

[0032] Based on interrupt priority map G int Resource competition relationship network G res It can generate the target fault tree T=(V T E T ,P T V T E represents the set of nodes. T Let P represent the set of edges. T Representing a probability distribution, a fault tree quantifies the probability of a fault propagating between different nodes using a probability propagation algorithm. Fault trees reveal the logical relationships between faults, facilitating comprehensive fault analysis.

[0033] S109: Generate a fault mode-effect analysis table based on the target fault tree, and perform fault diagnosis based on the fault mode-effect analysis table.

[0034] Failure Mode and Effects Analysis (FMEA) tables, in a structured tabular format, can identify all potential failures in a product, design, or process in advance, and analyze the causes and consequences of these failures. Specifically, a target fault tree can be used to identify failure propagation paths, and an FMEA table can be created based on these paths to achieve failure diagnosis. This table can include multiple records, each containing the failure source, propagation path, risk indicators, mitigation recommendations, and verification methods. It also supports exporting to a safety engineering management system for manual review and closed-loop tracking.

[0035] In this embodiment, semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code to obtain target features; dynamic position encoding is performed on the vehicle source code, and temporal constraint features are constructed based on the encoding results to characterize the temporal dependency strength between various code positions in the vehicle source code, thereby making full use of the dynamic semantic information of the vehicle source code to capture the dynamic semantic association between codes; then, based on the target features and temporal constraint features, an interrupt priority graph is constructed, where each interrupt node represents an interrupt syntax module, each connection edge represents that there is an interrupt nesting relationship between two connected interrupt nodes, and each connection edge includes a connection weight, which characterizes the fault propagation probability between two connected interrupt nodes; Next, based on the interrupt priority graph and the pre-built resource contention network, a target fault tree is generated. The node failure probability of the target fault tree is jointly determined by the connection weights of the interrupt priority graph and the resource contention network, thereby explicitly modeling faults such as interruptions, timing dependencies, and resource conflicts, avoiding the omission of related faults. Then, a fault mode-effect analysis table is generated based on the target fault tree, and fault diagnosis is performed based on the fault mode-effect analysis table. By integrating code semantic parsing, dynamic fault tree generation, and FMEA analysis, accurate modeling and safety extension of vehicle code fault modes are achieved, which can uncover many hidden faults that are difficult to detect, significantly improving the comprehensiveness and accuracy of fault identification and diagnosis.

[0036] Figure 2 This is a schematic diagram of the process for determining target features provided in an embodiment of this application. For example... Figure 2 As shown, the step of extracting semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain target features may include: S201: Label each syntax node in the abstract syntax tree corresponding to the vehicle source code with preset module semantic tags to obtain the labeled syntax node set; The preset module semantic tag is used to characterize the category of the preset module to which the syntax node belongs.

[0037] First, the LLVM compiler front-end can be used to perform multi-stage parsing of the vehicle source code, generating an abstract syntax tree (AST) = (V ast E ast Based on this, semantic tags, such as task_sched, interrupt_handle, and resource_alloc, are attached to the nodes of the abstract syntax tree, thereby semantically annotating the task scheduling module, interrupt handling module, and resource allocation module, resulting in the annotated set of syntax nodes N. annoThis provides functional semantic anchors for subsequent security testing, indicating which syntax nodes in the code structure belong to specific preset modules (including task scheduling modules, interrupt handling modules, and resource allocation modules), thus avoiding indiscriminate scanning of all code by security testing. The formula is: N anno =F label (AST,M rules ) Where AST represents the constructed abstract syntax tree, M rules N represents the module's identification rule set. anno This represents a set of annotated syntax nodes, where each syntax node contains a predefined module semantic label T, which can be represented as follows: ; S203: Construct a hybrid representation graph based on the abstract syntax tree, control flow graph, and data flow graph of the vehicle source code; A control flow graph CFG=(V) can be generated through data flow analysis and control flow analysis. cfg E cfg ) and data flow graph DFG=(V dfg E dfg Based on this, a hybrid representation graph is constructed, which includes a set of code nodes and a set of connecting edges, and can be represented as G. hybrid =(V hybrid E hybrid The code node set can include syntax nodes from the abstract syntax tree, control code nodes from the control flow graph, and data nodes from the data flow graph, represented as follows: The set of connection edges includes connection edges in the abstract syntax tree, connection edges in the control flow graph, and connection edges in the data flow graph. It may also include cross-graph connection edges E. cross Specifically, the set of connecting edges can be represented as E cross Used to associate different types of nodes, in one embodiment, V ast and V cfg Cross-graph connections can be established through the execution process; for V cfg and V dfg If a basic block in the CFG contains a definition or reference to the variable v, then the corresponding control code node can establish a cross-graph connection edge with the corresponding variable node in the DFG; for V ast and V dfg In the AST, each variable node can establish a cross-graph connection edge with the corresponding definition or reference node in the DFG.

[0038] S205: Based on the hybrid representation diagram and the annotated set of syntax nodes, identify target code segments in the preset module that pose security risks; Since the nodes in the annotated syntax node set already have metadata tags for "task scheduling / interrupt handling / resource allocation", the annotated syntax node set N can be used as the reference. anno Based on this, combined with the hybrid graph G hybrid The structural relationships of nodes and edges are analyzed, and the syntactic features of each task scheduling module, interrupt handling module, and resource allocation module are aggregated from the code feature sequence of the vehicle source code. Specifically, the module syntactic features can be determined by the following formula: M features =A module (G hybrid ,H,T rules ) Among them, M features This is a module syntax feature, which includes multiple module syntax sub-features, corresponding to each task scheduling module, interrupt handling module, and resource allocation module, respectively. hybrid The diagram is a hybrid representation, where H represents the code feature sequence of the vehicle source code, and T... rules The module identification strategy set includes strategies such as task scheduling mode, interrupt handler function signature, and resource allocation API mode.

[0039] Next, retrieve and call the predefined security mode library L. sec The security mode library includes multiple security modes, each containing a set of mode conditions related to module characteristics, used to characterize features or patterns related to security-sensitive code segments; these conditions are related to M features The feature dimensions correspond one-to-one. Then, M is compared one by one. features The comparison process involves determining whether the module syntax sub-features satisfy the pattern conditions. Specifically, during the comparison, the satisfaction level of each module syntax sub-feature can be determined, and based on the satisfaction level, it can be determined whether the corresponding code node is a target code segment. For example, if the module syntax sub-features corresponding to a code node satisfy all the conditions of a certain pattern (such as a node marked with interrupt handling simultaneously satisfying "containing the __interrupt keyword" and "modifying global flags"), then it is preliminarily determined that the code node can be a security-sensitive code segment, i.e., a target code segment, denoted as S. sec The target code segment indicates that the code involves sensitive data processing or security controls, posing a security risk and potentially causing security issues.

[0040] S207: Extract the semantic features of the target code segment from the code feature sequence of the vehicle source code, and perform enhanced representation to obtain the target features.

[0041] After identifying the target code segment S sec Then, through the hybrid graph G hybridThe mapping relationship between "nodes and source code locations" carried by the AST can determine the code sequence W={w1,w2,…,w...} in the onboard source code for the target code segment. n The starting and ending indices [s,e] in} are S sec Corresponding subsequence {w s ,w s+1 ,…,w e}. Due to the code feature sequence H={h1,h2,…,h} of the vehicle source code. n In}, each h i With code w i Strict alignment is required; therefore, in one implementation, the subvector corresponding to index [s, e] in H can be directly extracted to obtain S. sec The semantic features are represented as H sec ={h s ,h s+1 ,…,h e}

[0042] In one implementation, a hybrid representation graph G can be combined with the aforementioned semantic features. hybrid The semantic features of nodes strongly associated with the target code segment are extracted from the cross-graph edge Ecross, and then weighted and fused with the aforementioned semantic features. The fusion result is used as S. sec semantic features H sec It should be noted that weights can be determined based on the strength of the association (e.g., data flow dependency, control flow branch probability).

[0043] Next, attention mechanisms are used to apply the following formula to H. sec Perform semantic enhancement representation: H enhanced =Attention(W q H,W k H sec W v H sec ) Among them, H enhanced H represents the semantic features enhanced by the attention mechanism, i.e., the target features. sec W represents the semantic features of the target code segment. q W k W v This represents a learnable linear transformation matrix used to map the input feature vector to the Query, Key, and Value in the attention mechanism.

[0044] Existing technologies largely rely on static code scanning or single-dimensional fault analysis, which lacks sufficient understanding of code semantics and struggles to capture the complex relationships between modules such as task scheduling and interrupt handling, thus limiting their ability to identify hidden faults. The embodiments in this application deeply analyze the unique syntax and semantics of in-vehicle code, significantly improving the accuracy of identifying safety-sensitive code segments (target code segments) and providing an accurate basis for subsequently determining the probability of fault propagation.

[0045] In one embodiment, the step of dynamically encoding the vehicle-mounted source code and constructing temporal constraint features based on the encoding result may include: First, dynamic position encoding is performed on the vehicle-mounted source code based on the task execution sequence and the set of temporal constraints to obtain the positional features of each code position in the vehicle-mounted source code; in this embodiment, a dynamic position encoding function P is designed. dyn The temporal constraints in real-time task scheduling are transformed into position embedding vectors, and the mathematical expression is as follows: P seq =P dyn (T exec C constraint ,τ deadline ) Among them, T exec ={t1,t2,…,t n} represents the task execution sequence, C constraint ={c ij} represents the set of time-series constraints, τ deadline Let P represent the set of task deadlines. seq This represents the encoding result, i.e., the positional encoding vector.

[0046] Position encoding vector P seq Each element in It can be represented as:

[0047] in, This represents the positional characteristics of code position i. For time base parameters, For model dimensions.

[0048] Next, the similarity of the first position feature corresponding to the first code position and the second position feature corresponding to the second code position is calculated to obtain a similarity result; the first code position and the second code position are any two code positions of the vehicle source code; the temporal dependency of the first execution timestamp corresponding to the first code position and the second execution timestamp corresponding to the second code position is calculated to obtain a temporal dependency result; the temporal constraint feature is determined based on the similarity result and the temporal dependency result.

[0049] Specifically, for any first code position i and second code position j, construct temporal constraint features. The timing constraint feature can be in matrix form, where, Indicates the first positional feature. Indicates the second positional feature. Indicates the similarity results. Indicates the first execution timestamp. Indicates the second execution timestamp. This indicates a time-dependent result.

[0050] in,

[0051] In t i Earlier than t j In this case, the time-series dependency result is Output a positive number between 0 and 1, reflecting t i For t j Positive dependencies, and the smaller the interval, the stronger the dependency; in t i Later than t j In this case, the time-dependent result outputs a negative number between -1 and 0, reflecting t i For t j Negative dependency; when they are equal, the temporal dependency result is 0, indicating that the codes corresponding to code positions i and j belong to simultaneous events. ΔT is the time scale parameter.

[0052] In this embodiment of the application, dynamic position coding is used to quantify timing constraints, which provides a basis for introducing timing constraints into fault modeling. This helps to improve the comprehensiveness of subsequent quantitative analysis of fault propagation paths and avoids missing faults such as timing conflicts.

[0053] Figure 3 This is a schematic diagram illustrating the process of constructing an interrupt priority map provided in an embodiment of this application. For example... Figure 3 As shown, constructing an interrupt priority graph based on the target features and the timing constraint features may include: S301: Perform code module category identification processing from the vehicle source code to obtain the set of interrupt module nodes and the location of the interrupt entry code corresponding to each interrupt module node; By using a code module category identification model, the code module categories in the source code can be automatically identified and analyzed to obtain the interrupt handling module node set V. int ={v1,v2,…,v n}, and the main entry point f of the code corresponding to the interrupt module node. int ={f1,f2,…,f nThe code module category recognition model can be CodeBERT, which learns large-scale semantic features of "code-text" through a Transformer-based pre-trained model and connects to a classifier to achieve the downstream code module category recognition task.

[0054] S303: The initial priority is adjusted based on the similarity between the semantic features of the interrupt module nodes and the target features to obtain the intermediate priority; the intermediate priority of each interrupt module node can be determined according to the following formula: s i =λ1 P sem (v i )+λ2 P conf (v i ) Among them, P sem (v i ) indicates the degree of semantic similarity between the interrupt module node and the target features; P conf (v i This indicates the configuration priority of the interrupt module node; Specifically, P sem (v i )=map 01 (Sim(H int [i],H sec H int [i] represents the semantic features obtained by extracting semantic features from the i-th interrupt module node using the CodeBERT model, H sec Represents target features; map 01 This indicates that the cosine similarity (ranging from [-1, 1]) is mapped to [0, 1]. This mapping can be either a linear or nonlinear mapping.

[0055] Specifically, H int [i] represents the semantic features obtained by extracting semantic features from the i-th interrupt module node using the CodeBERT model. For hardware identifier library H lib Any one of the elements in {h1,h2,…,hm}, each Feature templates corresponding to specific hardware To match the weights (including peripheral address weight 0.4, driver API weight 0.3, and register operation weight 0.3), satisfying... The semantic features of the interrupt module node are matched with the feature templates of each specific hardware, according to the matching weights for each hardware-specific feature. The configuration priority of the interrupt module node is obtained by weighting the values.

[0056] S305: Normalize the intermediate priorities of each interrupt module node to obtain the associated priorities of each interrupt module node; specifically, the associated priorities can be determined according to the following formula:

[0057] This represents the minimum priority among the intermediate priorities of all interrupt module nodes. This represents the maximum value among the intermediate priorities of each interrupt module node.

[0058] S307: Determine the interrupt timing constraint characteristics between the first interrupt module node and the second interrupt module node based on the first interrupt entry code position corresponding to the first interrupt module node, the second interrupt entry code position corresponding to the second interrupt module node, and the timing constraint characteristics. Specifically, the interrupt timing constraint characteristics can be represented as M time [f i ,f j ], where M time f represents the pre-constructed temporal constraint features. i Indicates the location of the first interrupt entry code, f j This indicates the location of the second interrupt entry code.

[0059] S309: Determine the fault propagation probability between the first interrupt module node and the second interrupt module node based on the first association priority of the first interrupt module node, the second association priority of the second interrupt module node, and the interrupt timing constraint characteristics; Specifically, the probability of fault propagation can be determined by the following formula:

[0060] Where σ is the sigmoid function, used to map real numbers to the interval (0,1). As the first priority association, It is the second priority of association. For interrupt timing constraint characteristics, The fault propagation probability represents the probability that a fault will propagate from the first interrupt module node to the second interrupt module node.

[0061] S311: An interrupt priority graph is constructed using interrupt module nodes in the interrupt module node set as nodes, nesting relationships as connecting edges, and fault propagation probabilities as connecting edge weights.

[0062] Interrupt priority graph can be represented as G int =(V int E int W int Vint That is, the set of interrupt handling module nodes in step S301 above, E int Let E be the set of edges. int ={(v i ,v j | There is an interrupt nesting relationship}, W int That is, the edge weight matrix, where each element is the fault propagation probability determined in step S309 above.

[0063] In this embodiment of the application, by introducing timing constraints into the construction of the interrupt priority map, the interrupt priority map can comprehensively represent the dynamic relationship between each interrupt handling module, which is beneficial to the accuracy and comprehensiveness of subsequent fault tree generation.

[0064] In addition to the interruption priority graph described above, embodiments of this application also construct a resource contention relationship network to introduce resource conflict fault analysis. In one embodiment, the process of constructing the resource contention relationship network may include: Acquire the system resources of the vehicle operating system and construct them as a set of resource nodes; If the resource usage time windows corresponding to the first resource node and the second resource node overlap, and the duration of the overlapping portion is greater than a preset conflict threshold, it is determined that there is a connection edge between the first resource node and the second resource node, thus obtaining an edge set; the first resource node and the second resource node are any two resource nodes in the resource node set. The competition intensity between the first resource node and the second resource node is determined based on the intersection-exchange ratio of the resource usage time windows corresponding to the first resource node and the second resource node. The resource competition relationship network is constructed by using the resource nodes in the resource node set as nodes, the edge set as connecting edges, and the competition intensity as the weight of the connecting edges.

[0065] The resource competition network can be represented as Gres = (V res E res C res ), where the resource node set V res ={r1,r2,…,r m} represents system resources; edge set E res ={(r i ,r j There exists a resource contention relationship. In one embodiment, a resource usage conflict detection algorithm can be used to identify whether there is a resource contention relationship in the system. Specifically, , Represents resource node r i The usage time window Represents resource node rj The usage time window This represents the preset conflict threshold. Weight matrix C res [i,j] represents resource r i and r j The intensity of competition is calculated using the following formula: .

[0066] In this embodiment of the application, by constructing a resource competition relationship network and introducing it into the subsequent fault tree generation process, the fault analysis can focus on resource conflict faults, thereby improving the comprehensiveness and accuracy of fault diagnosis.

[0067] In one embodiment, generating the target fault tree based on the interruption priority map and resource contention network may include: First, the nodes in the interrupt priority graph, the nodes in the resource contention network, and the top-level fault events are determined as the event node set; based on the interrupt priority graph G... int Resource competition relationship network G res Generate the target fault tree T=(V T E T ,P T ), where: event node set v top These are top-level failure events. In the automotive field, top-level failure events include, but are not limited to: user-mode applications (such as in-vehicle entertainment apps) illegally accessing kernel-mode resources (such as interrupt controller registers and memory management tables), leading to OS kernel crashes or data tampering; user-mode process interrupt requests being incorrectly assigned kernel-mode priorities, breaching permission isolation; shared memory buffers between kernel and user modes lacking mutual exclusion mechanisms, allowing user-mode processes to preemptively write to them; OS real-time tasks (such as braking control tasks and sensor data processing tasks) not executing according to preset cycles, resulting in scheduling delays exceeding automotive safety standards; high-priority non-real-time tasks (such as in-vehicle log backup tasks) having excessively high interrupt priorities, preempting the scheduler's CPU resources; and timer resources on which the scheduler depends being contested by multiple tasks, leading to abnormal clock tick generation.

[0068] Then, based on the semantic similarity, temporal similarity, priority score, resource conflict score, and historical co-occurrence score of the first event node and the second event node, the gated event edge between the first event node and the second event node is determined, resulting in a set of gated event edges; the first event node and the second event node are any two event nodes in the set of event nodes; Edge set E T Through the fault propagation strategy R prop The formula for generation is as follows: The specific fault propagation strategy is as follows: It determines whether an edge exists between two event nodes based on five aspects: semantic association, temporal dependency, priority / configuration, resource contention, and historical evidence. Simultaneously, in the gating logic... In terms of decision-making, one implementation can use a rule-based (interpretable) scheme for fault tree gating logic decision-making; another implementation can combine a learning-based (trainable) model for fault tree gating logic decision-making.

[0069] Specifically, in one implementation, when semantic similarity <0.5, and temporal similarity >0.7, and resource conflict score A similarity score >0.6 indicates that multiple different tasks will only trigger failures under strict temporal coupling conditions, which is a typical type of concurrency or resource conflict, corresponding to the AND gate; if semantic similarity is... >0.7 or historical co-occurrence score A similarity score >0.6 indicates that these tasks are very similar in function and semantics, or have historically occurred simultaneously, and the triggering of any one of these conditions could lead to failure, corresponding to an OR gate; if the semantic similarity score is higher... >0.7, but historical co-occurrence score <0.3 indicates that they are functionally similar but almost never appear simultaneously, representing a typical mutually exclusive branching relationship, corresponding to the XOR gate; when order similarity >0.8 and priority score 0.4< A score <0.7 indicates a clear temporal order between tasks, influenced by a moderate level of priority, representing a sequential dependency, corresponding to the functional sequence gate (SEQ). Conversely, a priority score of <0.7 indicates a higher priority. >0.8 and historical co-occurrence score When the value is greater than 0.5, it indicates that the propagation of the fault is mainly driven by high-priority events, which is a typical scenario for interrupt priority gates, corresponding to the interrupt priority gate PRI.

[0070] It should be noted that if multiple conditions are met simultaneously, the gating logic is selected according to the following priority: PRI>SEQ>XOR>AND>OR.

[0071] In another implementation, for each event node, the five features (semantic similarity, temporal similarity, priority score, resource conflict score, and historical co-occurrence score) corresponding to the connecting edges associated with that event node can be aggregated with the set of parent nodes of that event node to form a node-level feature vector for that event node. This node-level feature vector can be represented as:

[0072] Where k is the number of parent nodes of the event node. Then, a lightweight classification network or tree model is used to determine the gating logic corresponding to the event node:

[0073] Where: the input is The output dimension is 6 (five features + number of parent nodes), and the output dimension is 5 (AND, OR, XOR, SEQ, PRI) representing the gating logic corresponding to the event node. The activation function is ReLU, and the output layer is Softmax. It should be noted that the loss function of a lightweight classification network or tree model can be defined as:

[0074] The optimization objective is to minimize L gate The Adam optimizer can be used with a learning rate of 0.001, and the model can be trained based on an early stopping strategy. The training samples are sourced from historical fault trees or gate-type samples annotated by experts. K-fold (K=5) validation strategy can then be used for cross-validation to determine the performance of the classification model.

[0075] Next, based on the connection edge weights of each connection edge in the interruption priority graph and the connection edge weights of each connection edge in the resource contention network, the node failure probability distribution is determined. In one embodiment, the node failure probability distribution P T Calculated using the following formula: P T (v j │v i )=γ W int [i,j]+(1-γ) C res [i,j]+μ Sim(H sec V res ), where the node failure probability distribution P T (v j │v i ) indicates that at node v i Under fault conditions, node v j The probability of a malfunction occurring. W int [i,j] represents the edge weights of each connection in the interrupt priority graph, C res [i,j] represents the edge weights of each connection edge in the resource competition network, Sim(H sec V res) represents the similarity between the semantic features of the target feature and the resource node. It should be noted that γ is used to balance the impact of interruption factors and resource contention factors on fault propagation; the optimal weights can be found using cross-entropy loss and gradient descent methods through fault samples from the vehicle operating system. Therefore, based on the determined set of event nodes, the set of gated event edges, and the node fault probability distribution, the target fault tree T=(V) can be constructed. T E T ,P T ).

[0076] In this embodiment of the application, by combining the interrupt priority table and the resource contention relationship network to construct the target fault tree, the ability of the target fault tree to discover faults such as interrupt faults and resource conflict faults can be improved, thereby improving the comprehensiveness of subsequent fault analysis and diagnosis.

[0077] In one embodiment, generating a failure mode-effects analysis table based on the target fault tree may include: A code knowledge graph is constructed based on the hybrid representation graph, the interrupt priority graph, and the resource contention network; specifically, the code knowledge graph can be represented as G. code =(V code, E code A code ), where the set of nodes It contains code elements, interrupt modules, and resource nodes; edge collection Semantic relation edge E semantic Generated by semantic similarity calculation: Where h i and h j They are nodes v i and v j semantic features The semantic similarity threshold; attribute mapping A code Assign attributes to each node and edge, including code location, execution order, resource type, etc.

[0078] The code knowledge graph is semantically aligned with a pre-built automotive-grade security vulnerability database to generate an extended knowledge graph; Through alignment function A align Implementing the code knowledge graph G code With pre-built automotive-grade security vulnerability library L vuln Semantic alignment is performed to obtain an expanded knowledge graph. Specifically, the security vulnerability database can be represented as L. vuln =(V vuln E vuln A vuln ),in: Represents vulnerability type nodes, with each vulnerability type associated with a feature vector. E vuln Let A represent the set of vulnerability relationship edges. vuln This represents the set of attributes for nodes and edges. An extended knowledge graph can be represented as... Compared to the code knowledge graph, the extended knowledge graph adds cross-graph edges, which connect the code knowledge graph with matching nodes in the security vulnerability database. Specifically, the Match function calculates the matching degree using multimodal similarity, as shown in the following formula: , Indicates semantic similarity. Indicates structural similarity. and Here, represents the weighting parameter. In one embodiment, structural similarity can be calculated based on Jaccard similarity, specifically the ratio of the intersection to the union of the neighbors of two nodes, as shown in the following formula:

[0079] in: and These are nodes v in the code knowledge graph. i Vulnerability nodes in automotive-grade security vulnerability databases The set of neighbors. Represents node v i and vulnerable nodes The number of neighbors you share. Represents node v i and vulnerable nodes The number of all neighbors.

[0080] Based on the temporal constraint characteristics between any two entity nodes in the extended knowledge graph, a temporal edge is added to the extended knowledge graph to obtain a temporal knowledge graph. Expanding knowledge graphs Building upon this foundation, by further incorporating temporal constraint information, a temporal knowledge graph can be constructed, which can be represented as G. time =(V time E time ,T time ), where the node set V time = ;exist Add a time-series relation edge E based on the existing one time The newly added temporal relation edge is constrained by the temporal constraint matrix M. time generate: ,in This is a time-dependent threshold. Timestamp mapping T time Assign a time attribute to each node and edge, and record the execution order and duration.

[0081] Then, the fault mode-effect analysis table is generated based on the time-series knowledge graph and the target fault tree.

[0082] In this embodiment of the application, semantic alignment enables entity nodes in the code knowledge graph to automatically identify parts that are semantically similar or structurally related to known security vulnerability patterns or defect mechanisms, thereby improving the accuracy of subsequent fault analysis.

[0083] Figure 4 This is a flowchart illustrating the process of generating a failure mode-effect analysis table provided in an embodiment of this application. For example... Figure 4 As shown, generating the fault mode-effect analysis table based on the time-series knowledge graph and the target fault tree may include: S401: The temporal knowledge graph and the target fault tree are fused to construct an enhanced fault propagation graph; The nodes in the enhanced fault propagation graph include nodes in the temporal knowledge graph and event nodes in the target fault tree; the edges in the enhanced fault propagation graph include connection edges in the temporal knowledge graph, gated event edges in the target fault tree, and cross-structure link edges; the cross-structure link edges are used to associate code nodes in the temporal knowledge graph with event nodes in the target fault tree. Time series knowledge graph G time =(V time E time ,T time ) and the target fault tree T=(V T E T ,P T The fusion process is used to construct the enhanced fault propagation graph G. fmea =(V fmea E fmea A fmea ).

[0084] Node set This includes all code elements, interrupt modules, resource nodes, and logic and event nodes in the target fault tree. It should be noted that event nodes in the fault tree... For a specific interrupt function or resource access point, then in V time Find nodes in the same source code location or with the same semantic vector h (cosine similarity > 0.95). Treat them as the same entity, merge them into a single node, and retain the attributes of both.

[0085] edge set The newly added cross-structure link edge E linkUsed to connect concrete code nodes in a time-series knowledge graph with abstract fault event nodes in a target fault tree, it is defined as follows: The specific implementation process is as follows: For each faulty leaf node (Representing a potential source of failure, such as "unprotected critical section"): If v leaf Corresponding source code location Then in V time Find all Related nodes (such as AST nodes, CFG basic blocks, DFG variable nodes) are denoted as a set. For each Add a bidirectional link edge: In practice, it can be set to be directed, from code node u to fault node v. leaf This indicates that the code behavior can trigger this failure mode; If a precise match cannot be achieved using the location information described above, semantic vector matching is used: first, calculate v leaf semantic features h leaf (This can be found in its description template or associated H) sec Extracted from V), then V time The semantic vector h of each code node u in u Determine the similarity between the node and the faulty leaf node. If the similarity is greater than a preset connection threshold, then... Then add a link edge. .

[0086] Attribute Mapping A fmea Assign multi-dimensional attributes to each node, including: fault mode identifier. Severity score Occurrence frequency O(v) = P T (v) (Node failure probability distribution from the target fault tree). By fusing the time-series knowledge graph and fault tree as described above, the complex relationships between modules such as task scheduling and interrupt handling can be effectively captured, which is beneficial to improving the ability to identify hidden faults and providing a comprehensive and accurate analytical foundation for subsequent FMEA analysis.

[0087] S403: Starting from the preset fault source node in the enhanced fault propagation graph and ending at the node corresponding to the top-level fault event, perform graph search processing on the enhanced fault propagation graph to obtain the set of fault propagation paths corresponding to each preset fault source node. Traversing G fmea All possible starting points (i.e., the bottom-level fault source nodes) are identified. A depth-first search is used to trace from each fault source node back to the top-level fault event v. top All paths. For each fault source node v srcThis yields a set of fault propagation paths {π1,π2,…,π k}, where each πi = (v src ,v1,…,v top ).

[0088] S405: For any top-level fault event, select the root cause candidate set corresponding to the top-level fault event from the enhanced fault propagation graph according to the fault propagation path; the root cause candidate set includes at least one preset fault source node; The root cause of a fault is located using a root cause analyzer. For any high-risk fault event v... top The root cause candidate set is defined as follows: In this context, the gating logic constraints are determined by the gating logic Gate(u) defined in the above embodiments. For example, if the gate of an intermediate node u is AND, then all its child nodes must be activated simultaneously for it to be considered a valid propagation; if it is PRI, then only the activation of the highest priority child node is valid. Based on the backpropagation strategy, in G... fmea Perform path backtracking with gated logic constraints to determine the root cause candidate set.

[0089] S407: Based on the root cause score, select the target root cause node from the root cause candidate set and generate failure root cause suggestions; This step may specifically include: Based on severity, probability of occurrence, and detectability, a risk priority coefficient is determined for each fault propagation path corresponding to a preset fault source node; the probability of occurrence is determined by the node fault probability distribution of the target fault tree; the severity is obtained by mapping a preset strategy; in one embodiment, the risk priority coefficient can be determined by the following formula: RPN i =S i ×O i ×D i Among them, RPN i S represents the risk priority coefficient of fault source node i. i Indicates the severity of the fault source node i, O i D represents the probability of fault source node i occurring. i This indicates the detectability of the fault source node i.

[0090] In one embodiment, severity S i It can be obtained by mapping from a predefined strategy (e.g., modifying the global flag + lock-free protection → S=9). The probability of occurrence is O. i The calculation is based on the probability product of the edges in the target fault tree, reflecting the joint probability of fault propagation along the path, and can be determined according to the following formula:

[0091] in, This represents the probability distribution of fault nodes in the target fault tree.

[0092] Detectability D i It can be quantified by the following formula: D(v) = 10 - (λ) cov C cover (v)+λ log L log (v)+λ assert A assert (v)); where: C cover (v), L log (v) and A assert (v) are all static analysis indicators. The coverage of node v for unit testing / fuzz testing; Check if there is log output near the node (by checking if the log output function log() or printf() is called in the AST); To check for the presence of assertion protection (such as assert() or custom validation macros); λ cov , λ log , λ assert The normalized weights are those that sum to 1, i.e., λ. cov +λ log +λ assert =1.

[0093] For the same v src Multiple fault propagation paths can be probabilistically aggregated to obtain the risk priority coefficient of the fault source node; the root cause score of each preset fault source node in the root cause candidate set is determined based on the risk priority coefficient, path attenuation coefficient, and semantic sensitivity coefficient. In one embodiment, the root cause score is used to quantify the likelihood of a root cause and can be determined as follows:

[0094] Where, d cfg (v,v top ) represents the shortest number of hops from node v to the top-level fault event in the control flow graph; δ is the attenuation coefficient (typically 3); if Then the semantic sensitivity coefficient Otherwise, the value is 0.5, indicating that semantically sensitive nodes are more likely to be the root cause.

[0095] The preset fault source nodes are sorted according to the root cause score, and a preset number of fault source nodes at the top of the sort are determined as the target root cause nodes. Finally, the results are sorted by Score. root (v) Sort in descending order, select the Top-K nodes as target root cause nodes and generate root cause suggestions.

[0096] S409: Generate the fault mode-impact analysis table based on the fault mode description of each preset fault source node, the set of fault propagation paths corresponding to each preset fault source node, and the fault root cause suggestion.

[0097] Fault mode description desc i =Template(f mode (v src ),context(v src Specifically, firstly, a mapping table or rule base is predefined to associate specific fault modes with description templates, based on the fault source node v. src Failure mode f mode (v src ) and context information context(v src It uses a template mechanism to generate descriptive text.

[0098] Furthermore, mitigation measures can be generated through the failure mode-remediation strategy mapping function. i =M(f mode (v src Add it to the Failure Mode-Impact Analysis table.

[0099] The output of this step is a structured failure mode-effects analysis table F={R1,R2,…,R...} k}, each record R i This includes, but is not limited to, a fault mode description for each preset fault source node, a set of fault propagation paths corresponding to each preset fault source node, and the fault root cause suggestions and mitigation measures. Based on the fault mode-impact analysis table obtained from the analysis, fault diagnosis is performed on the vehicle source code.

[0100] Compared to traditional FMEA analysis that relies on human experience, the embodiments of this application automatically generate FMEA tables based on temporal knowledge graphs and target fault trees, reducing human error and providing strong support for subsequent code optimization and security hardening. The prediction accuracy is at a high level, reliably predicting potential faults, effectively meeting the stringent safety requirements of ASIL-D level, and effectively adapting to automotive-grade safety standards. This provides a more efficient and reliable technical means for the security verification of automotive software, promoting the transformation of automotive code fault analysis from experience-driven to data-driven and intelligent-driven approaches.

[0101] Figure 5 This is a flowchart illustrating the vehicle code fault diagnosis method provided in an embodiment of this application. Figure 5 As shown, this application extracts semantic features from the vehicle source code to obtain the semantic representation of security-sensitive code segments, i.e., the target features in the above embodiments. Through dynamic position coding technology, the temporal constraints in real-time task scheduling are captured. Combined with the semantic representation, an interrupt priority graph and resource contention network supporting fault propagation analysis are constructed, generating a fault tree structure and quantifying the probability of fault propagation between nodes. The knowledge graph corresponding to the code is semantically aligned with a pre-built automotive-grade security vulnerability database, and combined with temporal constraints, a temporal knowledge graph is constructed. Based on the temporal knowledge graph and fault tree structure, an FMEA analysis table is generated and fault cause identification is performed. This effectively captures the complex relationships between modules such as task scheduling and interrupt handling, improving the comprehensiveness and accuracy of fault identification in vehicle code in the intelligent vehicle field. Furthermore, the automatically generated FMEA table can reliably predict potential faults, making fault identification and diagnosis more systematic and accurate.

[0102] The fault diagnosis method for vehicle codes provided in this application may specifically include: Each syntax node in the abstract syntax tree corresponding to the vehicle source code is labeled with a preset module semantic tag to obtain a set of labeled syntax nodes; the preset module semantic tag is used to characterize the category of the preset module to which the syntax node belongs; Based on the abstract syntax tree, control flow graph, and data flow graph of the vehicle source code, a hybrid representation graph is constructed; the hybrid representation graph includes a set of code nodes and a set of connecting edges, the set of code nodes includes syntax nodes of the abstract syntax tree, control code nodes of the control flow graph, and data nodes of the data flow graph; the set of connecting edges includes connecting edges in the abstract syntax tree, connecting edges in the control flow graph, and connecting edges in the data flow graph; Based on the hybrid representation diagram and the annotated set of syntax nodes, the target code segment with security risks in the preset module is determined; The semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code and enhanced representation is performed to obtain the target features; the target code segment is a code segment in a preset module that has security risks; The vehicle-mounted source code is dynamically position-encoded based on the task execution sequence and the set of temporal constraints to obtain the positional features of each code position in the vehicle-mounted source code; the task execution sequence includes the execution timestamp of each code position; The similarity between the first position feature corresponding to the first code position and the second position feature corresponding to the second code position is calculated to obtain the similarity result; the first code position and the second code position are any two code positions of the vehicle source code; The timing dependency is calculated by performing a timing dependency calculation on the first execution timestamp corresponding to the first code position and the second execution timestamp corresponding to the second code position; Based on the similarity results and the temporal dependency results, the temporal constraint features are determined; the temporal constraint features are used to characterize the temporal dependency strength between each code location in the vehicle source code. The code module category identification process is performed from the vehicle source code to obtain the set of interrupt module nodes and the interrupt entry code location corresponding to each interrupt module node. The initial priority is adjusted based on the similarity between the semantic features of the interrupt module node and the target features to obtain an intermediate priority; The intermediate priority of each interrupt module node is normalized to obtain the associated priority of each interrupt module node. Based on the first interrupt entry code position corresponding to the first interrupt module node, the second interrupt entry code position corresponding to the second interrupt module node, and the timing constraint characteristics, the interrupt timing constraint characteristics between the first interrupt module node and the second interrupt module node are determined. Based on the first association priority of the first interrupt module node, the second association priority of the second interrupt module node, and the interrupt timing constraint characteristics, the fault propagation probability between the first interrupt module node and the second interrupt module node is determined. The interrupt priority graph is constructed using the interrupt module nodes in the interrupt module node set as nodes, the nesting relationship as connecting edges, and the fault propagation probability as the connecting edge weight. The interrupt priority graph includes multiple interrupt nodes and multiple connecting edges. Each interrupt node represents an interrupt syntax module, and each connecting edge indicates that two connected interrupt nodes have an interrupt nesting relationship. Each connecting edge includes a connecting weight, which represents the fault propagation probability between two connected interrupt nodes. Acquire the system resources of the vehicle operating system and construct them as a set of resource nodes; If the resource usage time windows corresponding to the first resource node and the second resource node overlap, and the duration of the overlapping portion is greater than a preset conflict threshold, it is determined that there is a connection edge between the first resource node and the second resource node, thus obtaining an edge set; the first resource node and the second resource node are any two resource nodes in the resource node set. The competition intensity between the first resource node and the second resource node is determined based on the intersection-exchange ratio of the resource usage time windows corresponding to the first resource node and the second resource node. The resource competition relationship network is constructed by using the resource nodes in the resource node set as nodes, the edge set as connecting edges, and the competition intensity as the weight of the connecting edges.

[0103] The nodes in the interruption priority graph, the nodes in the resource contention network, and the top-level failure event are identified as the event node set; Based on the semantic similarity, temporal similarity, priority score, resource conflict score, and historical co-occurrence score of the first event node and the second event node, a gated event edge is determined between the first event node and the second event node, resulting in a set of gated event edges; the first event node and the second event node are any two event nodes in the event node set. The node failure probability distribution is determined based on the connection edge weights of each connection edge in the interruption priority diagram and the connection edge weights of each connection edge in the resource competition relationship network. The target fault tree is constructed based on the event node set, the gated event edge set, and the node failure probability distribution; the target fault tree includes the event node set, the gated event edge set, and the node failure probability, and the node failure probability is determined by the connection weight of the interrupt priority graph and the connection weight of the resource contention network; A code knowledge graph is constructed based on the hybrid representation graph, the interrupt priority graph, and the resource contention relationship network; The code knowledge graph is semantically aligned with a pre-built automotive-grade security vulnerability database to generate an extended knowledge graph; Based on the temporal constraint characteristics between any two entity nodes in the extended knowledge graph, a temporal edge is added to the extended knowledge graph to obtain a temporal knowledge graph. The temporal knowledge graph and the target fault tree are fused to construct an enhanced fault propagation graph. The nodes in the enhanced fault propagation graph include nodes in the temporal knowledge graph and event nodes in the target fault tree. The edges in the enhanced fault propagation graph include connection edges in the temporal knowledge graph, gated event edges in the target fault tree, and cross-structure link edges. The cross-structure link edges are used to associate code nodes in the temporal knowledge graph with event nodes in the target fault tree. Starting from the preset fault source node in the enhanced fault propagation graph and ending at the node corresponding to the top-level fault event, a graph search process is performed on the enhanced fault propagation graph to obtain a set of fault propagation paths corresponding to each preset fault source node. For any top-level failure event, a root cause candidate set corresponding to the top-level failure event is selected from the enhanced failure propagation graph according to the failure propagation path; the root cause candidate set includes at least one preset failure source node; Based on severity, probability of occurrence, and detectability, a risk priority coefficient is determined for the preset fault source node corresponding to each fault propagation path; the probability of occurrence is determined by the node fault probability distribution of the target fault tree; the severity is obtained by mapping from a preset strategy. The root cause score of each preset fault source node in the root cause candidate set is determined based on the risk priority coefficient, path decay coefficient, and semantic sensitivity coefficient. The preset fault source nodes are sorted according to the root cause score, and the preset number of fault source nodes at the top of the sort are determined as the target root cause nodes, and a fault root cause suggestion is generated. Based on the fault mode description of each preset fault source node, the set of fault propagation paths corresponding to each preset fault source node, and the fault root cause suggestions, the fault mode-impact analysis table is generated, and fault diagnosis is performed based on the fault mode-impact analysis table.

[0104] Figure 6 This is a schematic diagram of the vehicle code fault diagnosis device provided in the embodiments of this application.

[0105] like Figure 6 As shown, the device 600 includes: The target feature extraction module 601 is used to extract the semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain the target features; the target code segment is a code segment with security risks in a preset module. The timing constraint feature determination module 602 is used to perform dynamic position encoding on the vehicle source code and construct timing constraint features based on the encoding results. The timing constraint features are used to characterize the temporal dependency strength between each code position in the vehicle source code. Interrupt priority graph construction module 603 is used to construct an interrupt priority graph based on the target features and the timing constraint features; the interrupt priority graph includes multiple interrupt nodes and multiple connection edges, each interrupt node represents an interrupt syntax module, each connection edge represents that two connected interrupt nodes have an interrupt nesting relationship, and each connection edge includes a connection weight, the connection weight representing the fault propagation probability between two connected interrupt nodes; The target fault tree construction module 604 is used to generate a target fault tree based on the interruption priority graph and the pre-built resource contention relationship network; the target fault tree includes a set of event nodes, a set of gated event edges, and node failure probabilities, wherein the node failure probabilities are determined by the connection weights of the interruption priority graph and the connection weights of the resource contention network. The fault diagnosis module 605 is used to generate a fault mode-impact analysis table based on the target fault tree, and to perform fault diagnosis based on the fault mode-impact analysis table.

[0106] In some embodiments, the target feature extraction module may include: The tag annotation submodule is used to annotate each syntax node in the abstract syntax tree corresponding to the vehicle source code with preset module semantic tags to obtain an annotated set of syntax nodes; the preset module semantic tags are used to characterize the category of the preset module to which the syntax node belongs; A hybrid representation graph construction submodule is used to construct a hybrid representation graph based on the abstract syntax tree, control flow graph, and data flow graph of the vehicle source code. The hybrid representation graph includes a set of code nodes and a set of connecting edges. The set of code nodes includes syntax nodes of the abstract syntax tree, control code nodes of the control flow graph, and data nodes of the data flow graph. The set of connecting edges includes connecting edges in the abstract syntax tree, connecting edges in the control flow graph, and connecting edges in the data flow graph. The target code segment determination submodule is used to determine the target code segments with security risks in the preset module based on the hybrid representation graph and the annotated set of syntax nodes. The target feature determination submodule is used to extract the semantic features of the target code segment from the code feature sequence of the vehicle source code, and perform enhanced representation to obtain the target features.

[0107] In some embodiments, the timing constraint feature determination module may include: The dynamic position encoding submodule is used to perform dynamic position encoding on the vehicle source code according to the task execution sequence and the set of temporal constraints to obtain the position feature of each code position in the vehicle source code; the task execution sequence includes the execution timestamp of each code position; The similarity result determination submodule is used to calculate the similarity between the first position feature corresponding to the first code position and the second position feature corresponding to the second code position to obtain the similarity result; the first code position and the second code position are any two code positions of the vehicle source code; The timing dependency result determination submodule is used to calculate the timing dependency between the first execution timestamp corresponding to the first code position and the second execution timestamp corresponding to the second code position, and obtain the timing dependency result. The temporal constraint feature determination submodule is used to determine the temporal constraint features based on the similarity results and the temporal dependency results.

[0108] In some embodiments, the interrupt priority graph construction module may include: The code module category identification submodule is used to perform code module category identification processing from the vehicle source code to obtain the set of interrupt module nodes and the interrupt entry code position corresponding to each interrupt module node. The intermediate priority determination submodule is used to adjust the initial priority based on the similarity between the semantic features of the interrupt module node and the target feature to obtain the intermediate priority; The associated priority determination submodule is used to normalize the intermediate priority of each interrupt module node to obtain the associated priority of each interrupt module node. The interrupt timing constraint feature determination submodule is used to determine the interrupt timing constraint features between the first interrupt module node and the second interrupt module node based on the first interrupt entry code position corresponding to the first interrupt module node, the second interrupt entry code position corresponding to the second interrupt module node, and the timing constraint features. The fault propagation probability determination submodule is used to determine the fault propagation probability between the first interrupt module node and the second interrupt module node based on the first association priority of the first interrupt module node, the second association priority of the second interrupt module node, and the interrupt timing constraint characteristics. An interrupt priority graph construction submodule is used to construct the interrupt priority graph using interrupt module nodes in the interrupt module node set as nodes, nesting relationships as connecting edges, and the fault propagation probability as the connecting edge weight.

[0109] In some embodiments, the device 600 further includes a resource competition network construction module, specifically, the resource competition network construction module may include: The resource node set acquisition submodule is used to acquire the system resources of the vehicle operating system and construct them into a resource node set; The edge set determination submodule is used to determine that there is a connecting edge between the first resource node and the second resource node if the resource usage time windows corresponding to the first resource node and the second resource node overlap, and the duration of the overlapping part is greater than a preset conflict threshold, thereby obtaining an edge set; the first resource node and the second resource node are any two resource nodes in the resource node set; The competition intensity determination submodule is used to determine the competition intensity between the first resource node and the second resource node based on the intersection-exchange ratio of the resource usage time windows corresponding to the first resource node and the second resource node. The resource competition network construction submodule is used to construct the resource competition relationship network using the resource nodes in the resource node set as nodes, the edge set as connecting edges, and the competition intensity as the connecting edge weight.

[0110] In some embodiments, the target fault tree construction module may include: The event node set determination submodule is used to determine the nodes in the interrupt priority graph, the nodes in the resource contention network, and the top-level fault events as the event node set; The gated event edge set determination submodule is used to determine the gated event edge between the first event node and the second event node based on the semantic similarity, temporal similarity, priority score, resource conflict score, and historical co-occurrence score of the first event node and the second event node, thereby obtaining the gated event edge set; the first event node and the second event node are any two event nodes in the event node set; The node probability distribution determination submodule is used to determine the node failure probability distribution based on the connection edge weights of each connection edge in the interruption priority graph and the connection edge weights of each connection edge in the resource contention relationship network. The target fault tree construction submodule is used to construct the target fault tree based on the event node set, the gated event edge set, and the node fault probability distribution.

[0111] In some embodiments, the fault diagnosis module may include: The code knowledge graph construction submodule is used to construct a code knowledge graph based on the hybrid representation graph, the interrupt priority graph, and the resource contention relationship network. An extended knowledge graph generation submodule is used to semantically align the code knowledge graph with a pre-built automotive-grade security vulnerability database to generate an extended knowledge graph. The temporal knowledge graph determination submodule is used to add temporal edges to the extended knowledge graph based on the temporal constraint features between any two entity nodes in the extended knowledge graph, thereby obtaining the temporal knowledge graph. The table generation submodule is used to generate the fault mode-impact analysis table based on the time-series knowledge graph and the target fault tree.

[0112] In some embodiments, the table generation submodule may include: A data fusion unit is used to fuse the temporal knowledge graph and the target fault tree to construct an enhanced fault propagation graph. The nodes in the enhanced fault propagation graph include nodes in the temporal knowledge graph and event nodes in the target fault tree. The edges in the enhanced fault propagation graph include connection edges in the temporal knowledge graph, gated event edges in the target fault tree, and cross-structure link edges. The cross-structure link edges are used to associate code nodes in the temporal knowledge graph with event nodes in the target fault tree. The graph search unit is used to perform graph search processing on the enhanced fault propagation graph, starting from the preset fault source node in the enhanced fault propagation graph and ending at the node corresponding to the top-level fault event, to obtain a set of fault propagation paths corresponding to each preset fault source node. The root cause candidate set filtering unit is used to filter the root cause candidate set corresponding to any top-level fault event from the enhanced fault propagation graph according to the fault propagation path; the root cause candidate set includes at least one preset fault source node. The target root cause node filtering unit is used to filter target root cause nodes from the root cause candidate set based on the root cause score and generate fault root cause suggestions. The fault mode-impact analysis table generation unit is used to generate the fault mode-impact analysis table based on the fault mode description of each preset fault source node, the set of fault propagation paths corresponding to each preset fault source node, and the fault root cause suggestions.

[0113] In some embodiments, the target root cause node screening unit may include: The risk priority coefficient determination subunit is used to determine the risk priority coefficient of the preset fault source node corresponding to each fault propagation path based on severity, probability of occurrence, and detectability; the probability of occurrence is determined by the node fault probability distribution of the target fault tree; the severity is obtained by mapping from a preset strategy. The root cause score determination subunit is used to determine the root cause score of each preset fault source node in the root cause candidate set based on the risk priority coefficient, path decay coefficient and semantic sensitivity coefficient. The sorting and filtering subunit is used to sort the preset fault source nodes according to the root cause score, and determine the preset number of fault source nodes at the top of the sort as the target root cause nodes.

[0114] The apparatus and method embodiments described herein are based on the same inventive concept.

[0115] This application provides an electronic device including a processor and a memory. The memory stores at least one instruction or at least one program, which is loaded and executed by the processor to implement the method provided in the above method embodiments.

[0116] Embodiments of this application also provide a computer storage medium, which can be disposed in a terminal to store at least one instruction or at least one program related to implementing a method as provided in the above method embodiments, wherein the at least one instruction or at least one program is loaded and executed by the processor to implement the method provided in the above method embodiments.

[0117] Embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method provided in the above-described method embodiments.

[0118] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0119] The memory described in this application embodiment can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for the functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.

[0120] The methods provided in this application can be executed on mobile terminals, computer terminals, servers, or similar computing devices. Taking running on a server as an example... Figure 7 This is a hardware structure block diagram of a server for a vehicle-mounted code fault diagnosis method provided in an embodiment of this application. For example... Figure 7As shown, the server 700 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 710 (CPUs 710 may include, but are not limited to, microprocessors (MCUs) or programmable logic devices (FPGAs), a memory 730 for storing data, and one or more storage media 720 (e.g., one or more mass storage devices) for storing application programs 723 or data 722. The memory 730 and storage media 720 may be temporary or persistent storage. The program stored in the storage media 720 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 710 may be configured to communicate with the storage media 720 and execute the series of instruction operations stored in the storage media 720 on the server 700. Server 700 may also include one or more power supplies 760, one or more wired or wireless network interfaces 750, one or more input / output interfaces 740, and / or one or more operating systems 721, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0121] The input / output interface 740 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 700. In one example, the input / output interface 740 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the input / output interface 740 may be a radio frequency (RF) module used for wireless communication with the Internet.

[0122] Those skilled in the art will understand that Figure 7 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 700 may also include... Figure 7 The more or fewer components shown, or having the same Figure 7 The different configurations shown.

[0123] As can be seen from the embodiments of the vehicle code fault diagnosis method, device, electronic device, and storage medium provided above, this application extracts the semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain the target features; performs dynamic position encoding on the vehicle source code, and constructs temporal constraint features based on the encoding results to characterize the temporal dependency strength between each code position in the vehicle source code, thereby fully utilizing the dynamic semantic information of the vehicle source code to capture the dynamic semantic association between codes; then, based on the target features and temporal constraint features, constructs an interrupt priority graph, where each interrupt node represents an interrupt syntax module, each connection edge indicates that two connected interrupt nodes have an interrupt nesting relationship, and each connection edge includes a connection weight to characterize the connection. The algorithm first measures the probability of fault propagation between two interrupted nodes. Then, based on the interruption priority graph and the pre-built resource contention network, a target fault tree is generated. The node failure probability of the target fault tree is jointly determined by the connection weights of the interruption priority graph and the resource contention network, thereby explicitly modeling faults such as interruptions, timing dependencies, and resource conflicts to avoid missing related faults. Next, a fault mode-effect analysis table is generated based on the target fault tree, and fault diagnosis is performed based on the fault mode-effect analysis table. By integrating code semantic parsing, dynamic fault tree generation, and FMEA analysis, accurate modeling and safety extension of vehicle code fault modes are achieved, which can uncover many hidden faults that are difficult to detect, significantly improving the comprehensiveness and accuracy of fault identification and diagnosis.

[0124] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0125] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, devices, and storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0126] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer storage medium, such as a read-only memory, a disk, or an optical disk.

[0127] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for diagnosing vehicle-mounted codes, characterized in that, The method includes: Semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code to obtain the target features; the target code segment is a code segment in a preset module that has security risks. The vehicle source code is dynamically position-encoded, and a temporal constraint feature is constructed based on the encoding result. The temporal constraint feature is used to characterize the temporal dependency strength between each code position in the vehicle source code. Based on the target features and the timing constraint features, an interrupt priority graph is constructed. The interrupt priority graph includes multiple interrupt nodes and multiple connection edges. Each interrupt node represents an interrupt syntax module, and each connection edge indicates that two connected interrupt nodes have an interrupt nesting relationship. Each connection edge includes a connection weight, which represents the fault propagation probability between two connected interrupt nodes. Based on the interruption priority graph and the pre-constructed resource contention network, a target fault tree is generated; the target fault tree includes a set of event nodes, a set of gated event edges, and node failure probabilities, wherein the node failure probabilities are determined by the connection weights of the interruption priority graph and the connection weights of the resource contention network. A fault mode-impact analysis table is generated based on the target fault tree, and fault diagnosis is performed based on the fault mode-impact analysis table.

2. The method according to claim 1, characterized in that, The semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code to obtain the target features, including: Each syntax node in the abstract syntax tree corresponding to the vehicle source code is labeled with a preset module semantic tag to obtain a set of labeled syntax nodes; the preset module semantic tag is used to characterize the category of the preset module to which the syntax node belongs; Based on the abstract syntax tree, control flow graph, and data flow graph of the vehicle source code, a hybrid representation graph is constructed; the hybrid representation graph includes a set of code nodes and a set of connecting edges, the set of code nodes includes syntax nodes of the abstract syntax tree, control code nodes of the control flow graph, and data nodes of the data flow graph; the set of connecting edges includes connecting edges in the abstract syntax tree, connecting edges in the control flow graph, and connecting edges in the data flow graph; Based on the hybrid representation diagram and the annotated set of syntax nodes, the target code segment with security risks in the preset module is determined; The semantic features of the target code segment are extracted from the code feature sequence of the vehicle source code and enhanced to obtain the target features.

3. The method according to claim 1, characterized in that, The step of dynamically encoding the vehicle-mounted source code and constructing temporal constraint features based on the encoding results includes: The vehicle-mounted source code is dynamically position-encoded based on the task execution sequence and the set of temporal constraints to obtain the positional features of each code position in the vehicle-mounted source code; the task execution sequence includes the execution timestamp of each code position; The similarity between the first position feature corresponding to the first code position and the second position feature corresponding to the second code position is calculated to obtain the similarity result; the first code position and the second code position are any two code positions of the vehicle source code; The timing dependency is calculated by performing a timing dependency calculation on the first execution timestamp corresponding to the first code position and the second execution timestamp corresponding to the second code position; The temporal constraint features are determined based on the similarity results and the temporal dependency results.

4. The method according to claim 1, characterized in that, The step of constructing an interrupt priority graph based on the target features and the timing constraint features includes: The code module category identification process is performed from the vehicle source code to obtain the set of interrupt module nodes and the interrupt entry code location corresponding to each interrupt module node. The initial priority is adjusted based on the similarity between the semantic features of the interrupt module node and the target features to obtain an intermediate priority; The intermediate priority of each interrupt module node is normalized to obtain the associated priority of each interrupt module node. Based on the first interrupt entry code position corresponding to the first interrupt module node, the second interrupt entry code position corresponding to the second interrupt module node, and the timing constraint characteristics, the interrupt timing constraint characteristics between the first interrupt module node and the second interrupt module node are determined. Based on the first association priority of the first interrupt module node, the second association priority of the second interrupt module node, and the interrupt timing constraint characteristics, the fault propagation probability between the first interrupt module node and the second interrupt module node is determined. The interrupt priority graph is constructed using the interrupt module nodes in the interrupt module node set as nodes, the nesting relationship as connecting edges, and the fault propagation probability as the connecting edge weight.

5. The method according to claim 1, characterized in that, The method further includes: Acquire the system resources of the vehicle operating system and construct them as a set of resource nodes; If the resource usage time windows corresponding to the first resource node and the second resource node overlap, and the duration of the overlapping portion is greater than a preset conflict threshold, it is determined that there is a connection edge between the first resource node and the second resource node, thus obtaining an edge set; the first resource node and the second resource node are any two resource nodes in the resource node set. The competition intensity between the first resource node and the second resource node is determined based on the intersection-exchange ratio of the resource usage time windows corresponding to the first resource node and the second resource node. The resource competition relationship network is constructed by using the resource nodes in the resource node set as nodes, the edge set as connecting edges, and the competition intensity as the weight of the connecting edges.

6. The method according to claim 1, characterized in that, The step of generating a target fault tree based on the interrupt priority map and resource contention network includes: The nodes in the interruption priority graph, the nodes in the resource contention network, and the top-level failure event are identified as the event node set; Based on the semantic similarity, temporal similarity, priority score, resource conflict score, and historical co-occurrence score of the first event node and the second event node, a gated event edge is determined between the first event node and the second event node, resulting in a set of gated event edges; the first event node and the second event node are any two event nodes in the event node set. The node failure probability distribution is determined based on the connection edge weights of each connection edge in the interruption priority diagram and the connection edge weights of each connection edge in the resource competition relationship network. The target fault tree is constructed based on the set of event nodes, the set of gated event edges, and the node fault probability distribution.

7. The method according to claim 2, characterized in that, The generation of the failure mode-impact analysis table based on the target fault tree includes: A code knowledge graph is constructed based on the hybrid representation graph, the interrupt priority graph, and the resource contention relationship network; The code knowledge graph is semantically aligned with a pre-built automotive-grade security vulnerability database to generate an extended knowledge graph; Based on the temporal constraint characteristics between any two entity nodes in the extended knowledge graph, a temporal edge is added to the extended knowledge graph to obtain a temporal knowledge graph. The fault mode-impact analysis table is generated based on the time-series knowledge graph and the target fault tree.

8. The method according to claim 7, characterized in that, The generation of the fault mode-effect analysis table based on the time-series knowledge graph and the target fault tree includes: The temporal knowledge graph and the target fault tree are fused to construct an enhanced fault propagation graph. The nodes in the enhanced fault propagation graph include nodes in the temporal knowledge graph and event nodes in the target fault tree. The edges in the enhanced fault propagation graph include connection edges in the temporal knowledge graph, gated event edges in the target fault tree, and cross-structure link edges. The cross-structure link edges are used to associate code nodes in the temporal knowledge graph with event nodes in the target fault tree. Starting from the preset fault source node in the enhanced fault propagation graph and ending at the node corresponding to the top-level fault event, a graph search process is performed on the enhanced fault propagation graph to obtain a set of fault propagation paths corresponding to each preset fault source node. For any top-level failure event, a root cause candidate set corresponding to the top-level failure event is selected from the enhanced failure propagation graph according to the failure propagation path; the root cause candidate set includes at least one preset failure source node; Based on the root cause score, target root cause nodes are selected from the root cause candidate set, and failure root cause suggestions are generated. The fault mode-impact analysis table is generated based on the fault mode description of each preset fault source node, the set of fault propagation paths corresponding to each preset fault source node, and the fault root cause suggestions.

9. The method according to claim 1, characterized in that, The step of selecting target root cause nodes from the root cause candidate set based on root cause scores includes: Based on severity, probability of occurrence, and detectability, a risk priority coefficient is determined for the preset fault source node corresponding to each fault propagation path; the probability of occurrence is determined by the node fault probability distribution of the target fault tree; the severity is obtained by mapping from a preset strategy. The root cause score of each preset fault source node in the root cause candidate set is determined based on the risk priority coefficient, path decay coefficient, and semantic sensitivity coefficient. The preset fault source nodes are sorted according to the root cause score, and the preset number of fault source nodes at the top of the sort are determined as the target root cause nodes.

10. A fault diagnosis device for vehicle-mounted codes, characterized in that, The device includes: The target feature extraction module is used to extract the semantic features of the target code segment from the code feature sequence of the vehicle source code to obtain the target features; the target code segment is a code segment with security risks in the preset module; The temporal constraint feature determination module is used to perform dynamic position encoding on the vehicle source code and construct temporal constraint features based on the encoding results. The temporal constraint features are used to characterize the temporal dependency strength between each code position in the vehicle source code. An interrupt priority graph construction module is used to construct an interrupt priority graph based on the target features and the timing constraint features. The interrupt priority graph includes multiple interrupt nodes and multiple connection edges. Each interrupt node represents an interrupt syntax module, and each connection edge indicates that there is an interrupt nesting relationship between two connected interrupt nodes. Each connection edge includes a connection weight, and the connection weight represents the fault propagation probability between two connected interrupt nodes. The target fault tree construction module is used to generate a target fault tree based on the interruption priority graph and the pre-built resource contention network. The target fault tree includes a set of event nodes, a set of gated event edges, and node failure probabilities. The node failure probabilities are determined by the connection weights of the interruption priority graph and the connection weights of the resource contention network. The fault diagnosis module is used to generate a fault mode-impact analysis table based on the target fault tree, and to perform fault diagnosis based on the fault mode-impact analysis table.