Model and code cross validation analysis method based on UPPAAL

By combining the UPPAAL model checking and code verification tools, two-way cross-validation of the model and code is achieved, which solves the problems of limited scope and false positives in the existing technology, improves the comprehensiveness and accuracy of system verification, and is suitable for the verification of complex systems.

CN118708481AActive Publication Date: 2024-09-27BEIHANG UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410777050.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-27
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

Existing UPPAAL model and code cross-validation techniques suffer from limited scope, false positives, and lack of integration, resulting in insufficiently comprehensive and accurate system verification.

Method used

By combining the UPPAAL model checking and code verification tools, two-way cross-validation of the model and code is achieved to ensure the correctness of the system's syntax, semantics and behavior, reduce false positives, and improve the comprehensiveness and accuracy of verification.

Benefits of technology

It achieves more comprehensive system verification, improves the reliability and correctness of the system, reduces development costs, and is suitable for verification of complex systems, especially the detection of concurrency and time constraints.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708481A
    Figure CN118708481A
Patent Text Reader

Abstract

The invention provides a model and code cross validation analysis method based on UPPAAL, a valuable solution is provided for a method for applying UPPAAL and a code analysis tool to double source code verification, and the method comprises the steps of system modeling, model verification, model verification analysis, attribute verification, model-code conversion, code verification, model and code cross validation and the like. According to the method, the system can be comprehensively checked, meanwhile, the grammar and semantics of the system and the correctness of system attributes and behaviors can be ensured, the limitations (limited range, false positive and lack of integration) in the prior art are overcome, and higher-level software quality is realized. The method has the advantages of improving code quality, enhancing system reliability, improving efficiency and accuracy, reducing development cost and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention discloses a model and code cross-validation analysis method based on UPPAAL, which relates to the field of system verification, and specifically uses model checking and code verification to verify system design and implementation. Background Art

[0002] Formal methods address the inability of traditional software development methods to determine the correctness of design specifications. By abstracting and extracting key features from the top-level design, they analyze and model the system at the model level and define system properties at the requirements level, thereby simulating whether the designed system can traverse all states. UPPAAL is a tool for timed automaton verification within formal checking methods. It models a system as a collection of nondeterministic processes with a finite control structure and a real-time clock, communicating through channels or shared variables.

[0003] UPPAAL uses CTL (Computation Tree Logic) to verify the reachability, safety, and liveness of the system. The basic CTL formula for verifying reachability is: E<>P, which indicates that there exists a path that satisfies logical formula P. The basic CTL formula for verifying safety is: A[]P, which indicates that every state in the system can satisfy logical formula P. E[]P indicates that there exists a path state that always satisfies P. The basic CTL formula for verifying liveness is: A<>P, which indicates that a state in all paths ultimately satisfies logical formula P.

[0004] Currently, some extended models of the UPPAAL model have been developed based on the UPPAAL model, such as CORA, ECDAR, Tiga, and TRON. Among them, CORA is a linear pricing timed automaton based on the UPPAAL model. Given an LPTA model, UPPAAL CORA can find the optimal path to the state that meets certain target conditions. This optimal path has the lowest cumulative cost. ECDAR is a timed interface theory tool designed to check the incremental refinement between specifications. It can combine automata of different timed I / O with combination or connection operators and check whether the combined specification refines another specification. ECDAR regards timed game automata as timed I / O automata, paving the way for incremental design and combinatorial reasoning. Tiga optimizes the basic symbolic algorithm by using regions as the underlying data structure to execute each step of the algorithm to obtain the time-optimal winning strategy. TRON is a black-box conformance test for timing systems, primarily targeting embedded software commonly found in various controllers. Test primitives are generated directly from the model and executed online (dynamically) while connected to the SUT (System Under Test) to simultaneously check the system response, thus avoiding a large intermediate test suite. The specification is a UPPAAL timed automaton network.

[0005] Existing UPPAAL models and code cross-validation-related technologies can be divided into three categories:

[0006] 1. Model checking and code verification techniques

[0007] These techniques focus on verifying the correctness of the UPPAAL model and its corresponding code implementation. This process includes separate UPPAAL model checking, which verifies the model's properties based on various event logics, demonstrating that the model correctly reflects the system's expected behavior. Meanwhile, static code analysis examines the source code to identify potential errors and vulnerabilities. Another approach is model-based testing, which uses the UPPAAL model to generate test cases that are executed on the actual system to identify differences between the model and the code. However, these approaches treat the methods and processes of model checking and code verification as two independent processes. The goal of model checking is to verify whether the model can correctly reflect and verify the system's properties and expected behavior; the goal of static code analysis is to examine the code and identify potential code defects.

[0008] 2. Model and code co-simulation technology

[0009] There are two main types of model-code co-simulation techniques: one links the UPPAAL model with an external simulator and code implementation, such as UPPAAL-SMC; the other integrates the UPPAAL model with a real-time operating system, performing model and code verification on a single platform. Tools such as CORA, ECDAR, and TRON are examples. However, in general, model-code system simulation approaches still treat model verification and code verification as separate entities, lacking information sharing and collaboration between the two.

[0010] 3. Model and code refactoring techniques

[0011] The model and code refactoring techniques are designed to improve the quality and maintainability of the UPPAAL model and its corresponding code implementation. These techniques include model refactoring that restructures the UPPAAL model and code refactoring that involves reorganizing the code.

[0012] In summary, there is currently no specific technology for directly cross-validating the UPPAAL model and code. Therefore, the present invention is aimed at the UPPAAL model and code cross-validation technology. By combining model checking and code verification technologies, a two-way cross-validation technology of the model and code based on UPPAA is implemented. While verifying the correctness of object attributes, the consistency and correctness of the model and code are achieved.

[0013] Existing model checking and code checking technologies are primarily distributed, independent processes. Modeling a system and using model checking tools to verify its properties and behavior; then checking the system's code to verify variable ranges and values. There's a lack of an effective bridge between model checking and code checking to integrate their results. This leads to the following problems:

[0014] 1. Limited Scope: Traditional code analysis tools primarily focus on syntactic and semantic correctness, often overlooking subtle behavioral issues or potential runtime errors. UPPAAL, on the other hand, is suitable for verifying temporal properties and system behavior, but has limitations and scope for variable analysis, resulting in limited variable coverage. Furthermore, individual tools may be limited in their coverage of specific aspects of the code. UPPAAL's exclusive model-level verification also limits the scope of variables.

[0015] False positives: Model checking and code checking have tool-specific limitations: Code checking tools (e.g., static analysis tools) may not catch all types of errors or may produce false positives / negatives. Similarly, model checking tools (e.g., UPPAAL) may not be able to handle complex systems or may require extensive expertise.

[0016] ③ Lack of integration: Code checking tools and model checking tools are often used separately, which makes it difficult to correlate results and identify inconsistencies.

[0017] In summary, single model checking and code detection technologies have problems such as limited scope, false positives, and lack of integration, which restrict the further development of current model checking and code detection technologies. Summary of the Invention

[0018] This invention addresses the current challenges of model checking and code validation, such as limited scope, false positives, and a lack of integration. By combining code checking tools with the UPPAAL model verification tool, this invention leverages the strengths of both approaches to achieve a more comprehensive verification process. This invention provides a UPPAAL-based model and code cross-validation analysis method to improve the reliability of system verification. This is achieved through a structured process that ensures that both the model and its corresponding code implementation meet specified properties and requirements. This achieves the following goals:

[0019] ① Comprehensive coverage: UPPAAL can effectively detect concurrency issues such as deadlocks. Combined with traditional code analysis tools, it can not only identify the system's behavioral and temporal properties, but also address syntactic and semantic correctness (such as syntax errors, type errors, or security vulnerabilities) or potential runtime errors, solving the problem of variable scope limitations.

[0020] ② Mutual Verification: Combining the results of model checking and code checking for cross-validation can reduce the possibility of false positives / negatives and catch problems such as deadlocks and limited variable detection. By specifying time attributes in UPPAAL, it is possible to verify that the system follows the desired behavior pattern over time, thereby preventing unexpected results (such as memory leaks, deadlocks, or inefficient resource allocation). Code checking tools can check variables and semantics within the code, cross-verifying with model checking techniques to address false positives.

[0021] Integration and cross-validation: Integrating model checking and code checking methods and cross-validating them can identify inconsistencies and potential errors. This not only makes the detection results more comprehensive, but also facilitates debugging and fixing these errors, forming a more robust and efficient verification process.

[0022] ④ Improve efficiency and accuracy: Combining model checking and code testing processes not only reduces the time and effort required for manual code review and testing, but also yields more accurate experimental results. This can provide a higher level of assurance for the correctness and reliability of the system, which is crucial in safety-critical and mission-critical applications.

[0023] The purpose of this invention is to solve the above problems and provide a model and code cross-validation analysis method based on UPPAAL, which can ensure a comprehensive inspection of the system and at the same time ensure the correctness of the system's syntax and semantics as well as the correctness of the system's properties and behaviors. It has the advantages of improving code quality, enhancing system reliability, improving efficiency and accuracy, and reducing development costs. The overall process is as follows: Figure 1 shown.

[0024] To achieve the above object, the present invention adopts the following technical solutions:

[0025] A model and code cross-validation analysis method based on UPPAAL, the specific steps are as follows:

[0026] Step (1), system modeling: describe the system as a timed automaton UPPAAL model, and the system described by UPPAAL is denoted as M.

[0027] Step (2), model verification: Use UPPAAL's validator to perform initial grammatical correctness verification to check the basic correctness of the model; if M meets the initial grammatical correctness standard, Verify(M) returns true and the next step of verification is performed; if M does not meet the initial grammatical correctness standard, Verify(M) returns false and gives the specific error location and error cause, further modifies the model grammatical structure, and repeats step (2) until M meets the initial grammatical correctness standard, that is, Verify(M) returns true.

[0028] Step (3), Model Verification Analysis: If Verify(M) is true, the model can be dynamically verified. Starting from the initial state, the dynamic changes of the state can be simulated, and the changes in variable values ​​during dynamic changes can be checked at any time. Here, it can be detected whether the model has problems such as deadlock. Assume that the deadlock problem is represented by Deadlock(M). If the system is deadlocked, Deadlock(M) returns true, the deadlock problem is recorded in the "Model Verification Problem Description", the system structure is modified, and the return to step (2) is made until the system no longer has deadlock problems, that is, Deadlock(M) returns false, and the subsequent attribute verification step can be entered.

[0029] Step (4), property verification: Assuming that the system model M must satisfy the property P, perform verification Verify(M,P); if Verify(M,P) returns true, the model is considered correct; if Verify(M,P) returns false, record these problems in the "Model Verification Problem Description".

[0030] Step (5), model-code conversion: convert the UPPAAL model M into an XML representation M X, use the model conversion tool to convert M X Convert to C language file M C .

[0031] Step (6), code verification: Use a code verification tool (such as CBMC, ESBMC, SPIN) to verify the C language file converted in step (5); if the verification process VerifyCode(C) returns true, it proves that the code is correct; if the verification process VerifyCode(C) returns false, it proves that a problem has been detected in the code verification and is recorded in the "Code Detection Problem Description".

[0032] Step (7), model and code cross-validation: integrate the problems verified or detected from the "model verification problem description" and the "code detection problem description" to form a "model and code cross-validation problem set"; and perform system modeling correction based on the "model and code cross-validation problem set".

[0033] In step (1), the UPPAAL model is as follows: Assuming S represents a set of states (locations), δ represents a set of transitions (transitions), s0 represents an initial state, and C represents a set of clocks (clocks), the system is represented by the UPPAAL automaton as a quaternion A = (S, δ, s0, C). Its behavior can be expressed as:

[0034] δ: S × Guards × S → Synchronization, where Guards and Synchronization describe the state transition rules and communication mechanisms. Furthermore, the state evolution of the system can be expressed as Path(G) = ∑ e∈E w(e), where G represents the system state graph, e belongs to an edge in the edge set E, and each edge e in the edge set E has a weight function w(e) representing the time or resource consumption of state transition.

[0035] In step (2), it is assumed that ∑X is the set of UPPAAL model grammar rules, and any model M should belong to the legal model set ∑ valid X, that is, M∈∑ validX. Define a validator function Verifier_Syntax(M) to check the correctness of the model syntax. If the model M meets all the syntax rules, Verifier_Syntax(M) returns true; if Verifier_Syntax(M) does not meet the syntax rules, Verifier_Syntax(M) returns (false, error_loc, error_reason), where false indicates that the syntax check fails, error_loc indicates the location of the error, and error_reason indicates the reason for the error. The initial syntax correctness verification can be expressed as:

[0036] If Verifier_Syntax(M) returns true, continue with the subsequent verification steps; if Verifier_Syntax(M) returns false, further modify the model syntax structure according to the error location and error cause, and repeat step (2) until Verifier_Syntax(M) returns true, that is, Among them, M (k) Denotes the model after the kth revision. Assuming F represents the set for which Verifier_Syntax(M) returns false, then F can be expressed as F = {M|Verifier_Syntax(M) = false}. The revision process of model M is equivalent to finding the complement of F. The elements of

[0037] Among them, in step (4), the specific process of verifying Verify(M,P) is as follows: Assuming that p represents a property and P represents the set of properties to be verified, then p∈P represents a condition that the model must meet. Define a verifier function Verifier_Property(M,p) to check whether the model M meets the property p. Assuming that property_reason represents the specific reason why the property is not met, the process of the verifier function checking whether the model M meets the property p can be expressed as:

[0038]

[0039] Furthermore, P = {p1, p2, ..., p m}, the attribute verification process can be expressed as:

[0040]

[0041] Assume that the problem record set is ε, and record the information of Verifier_Property(M,p)=(false,property_reason) in ε, that is,

[0042] ε={(p,property_reason)|Verifier_Property(M,p)=false}.

[0043] In step (5), the UPPAAL model M is converted into an XML representation M X , use the model conversion tool to convert M X Convert to C language file M C The specific operation process is as follows:

[0044] The first step is to convert the UPPAAL model M into XML representation. The basic conversion steps include: converting templates into XML tags and their attributes; converting system definitions into XML tags and their attributes. Assume that the UPPAAL model M contains n templates T1, T2, ..., T n , the system is defined as S. Then the XML representation of model M can be expressed as M XML , which includes the template part and the system definition part S XML . Further, M XML ={T XML ,S XML}.

[0045] The second step is to convert the XML file into a C language file. The basic conversion steps include: parsing the XML representation and generating C code. First, parse the XML representation. Assume that the conversion tool for XML to C language is defined as T c , use the Transform Tool T c The conversion function Second, use T c Parsing M XML , generate the intermediate structure Ψ: Ψ=parse(M XML ). Then, the corresponding C language file M is generated through the parsed intermediate structure Ψ C :M C =generate_C_code(Ψ).

[0046] The specific process of code verification in step (6) is as follows: First, input the verification model: the C language file M generated in step (5) CAs input, use code checking tools (CBMC, ESBMC, SPIN) to verify the input C language file. Assume that the verification function of the code checking tool is Y and the code checking result set is R verify , then the code detection tool verification process can be expressed as: Υ:M C →{true,false}, while R verify =Y{M C}. Among them, R verify =true, indicating that the code verification is correct, R verify = false, it means that the code detection method detects an error. Finally, R verify =false is stored in the "Code Detection Problem Description".

[0047] Among them, in step (7), the specific process of cross-validation of model and code is as follows: First, problem induction is performed. Assume that the set of model detection problems is P model-check , the set of code detection problems is P code-verify , the set of models and code cross validation problems is P cross-validation , then P cross-validation =P model-check ∪P code-verify Among them, P model-check ={p1,p2,...,p m}, P code-verify ={q1,q2,...,q n},

[0048] P cross-validation ={r1,r2,...,r k}(k≤m+n), r i is the merge p i and q i The problem items are obtained. Secondly, according to P cross-validation The system model is corrected based on the problem in the paper. Let the correction function be Its input is the current system and the problem set, and its output is the revised new system model, which can be expressed as: (M,P cross-validation )→M ′ ,Right now Modified model M ′ And the corresponding C code file M C 'Re-enter the model detection and code detection cycle and return to step (1) until the verification result is true, that is, no new problem description is generated, that is, |P cross-validation |=0.

[0049] In summary, the UPPAAL-based bidirectional cross-validation method for models and code includes system modeling, model verification, code conversion, and problem integration. Model verification involves checking the correctness of structure and behavior, while code verification uses a variety of tools to ensure robustness to different types of errors.

[0050] The present invention provides a model and code cross-validation analysis method based on UPPAAL by ensuring that the model and its implementation comply with predefined specifications, thereby improving the reliability and correctness of system development.

[0051] Compared with the prior art, the present invention has the following beneficial effects:

[0052] This paper proposes a UPPAAL-based model and code cross-validation analysis method. This method, which combines UPPAAL and code analysis tools for dual source code verification, provides a valuable solution to overcome the limitations of existing technologies (limited scope, false positives, and lack of integration) and achieve higher levels of software quality. Compared with existing technologies, this UPPAAL-based model and code bidirectional cross-validation technique has the following advantages:

[0053] ① Enhanced consistency verification

[0054] In traditional approaches, model verification and code verification are usually separated, which may lead to inconsistencies between the model and its implementation. By integrating the model and code verification processes, this invention ensures that each step from model to code meets the predetermined properties and requirements, thereby enhancing the consistency of the final system.

[0055] ② Improve system reliability:

[0056] By performing bidirectional cross-validation on the model and generated code, potential errors and issues can be more comprehensively detected. This invention combines model checking and code verification techniques to comprehensively verify and validate the system. Model checking verifies the system design and specifications, while code verification ensures that the implementation complies with the design and specifications. This bidirectional cross-validation approach can significantly improve the reliability and correctness of the system.

[0057] ③ Reduce rework and costs:

[0058] Through model checking and code verification, errors and defects in the system can be precisely located. Model checking can identify problems at the design and specification levels, while code verification can identify problems at the implementation level. Combining the results of these two methods allows for comprehensive and accurate identification of system problems. By identifying problems early in the development process, this method reduces the need for rework later, saving time and costs. Furthermore, once the system is deployed, the complexity and cost of maintaining and upgrading it are reduced accordingly.

[0059] ④ Improve verification efficiency:

[0060] The present invention enables rapid model and code verification through automated tools and processes (such as UPPAAL and code verification tools like CBMC, ESBMC, and SPIN). This increased automation significantly accelerates the verification process, enabling development teams to iterate and improve products more quickly. Furthermore, the present invention can seamlessly integrate with existing verification tools (such as UPPAAL, CBMC, ESBMC, and SPIN), fully leveraging their capabilities and advantages. This compatibility reduces development costs and improves verification efficiency.

[0061] ⑤ Enhanced error tracking and analysis capabilities:

[0062] By carefully documenting issues discovered during model and code validation and integrating them into a "model and code cross-validation problem set," this paper provides a clear framework for error tracking and analysis. Based on the information in this problem set, targeted bug fixes can be implemented, designs optimized, and system performance and reliability improved. This not only facilitates continuous system improvement but also provides valuable experience and data support for future projects.

[0063] ⑥Support verification of complex systems:

[0064] UPPAAL, a powerful real-time system modeling and verification tool, combined with code verification tools, makes the present invention particularly well-suited for handling complex system verification challenges, such as concurrency, communication, and timing constraints, which are often difficult to accurately handle with traditional verification tools. Furthermore, the present invention can be applied to various types of systems, such as embedded systems, real-time systems, and safety-critical systems. As long as a system can be modeled using UPPAAL and C code can be generated, the present invention can be used for verification and validation.

[0065] Through these beneficial effects, this invention not only improves the quality and efficiency of system development, but also provides a more scientific and systematic verification method for the design and implementation of high-reliability systems. The application of this method can significantly improve system performance and user trust, which is of great significance for improving product competitiveness.

[0066] The present invention can play an important role in many fields, especially those related to concurrent systems, real-time systems, embedded systems, and communication protocols. Specific application areas include, but are not limited to, embedded systems, communication protocols, autonomous driving systems, aerospace and aviation systems, medical equipment, power systems, and intelligent transportation systems. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] Figure 1 This is a flowchart of the model and code bidirectional cross-validation based on UPPAAL.

[0068] Figure 2 It is the first process POne.

[0069] Figure 3 It is the second process PTwo.

[0070] Figure 4 It is the UPPAAL process simulation.

[0071] Figure 5 This is the modified POne process.

[0072] Figure 6 This is the modified PTwo process.

[0073] Figure 7 The model simulator simulates after the changes. DETAILED DESCRIPTION

[0074] The effectiveness of the proposed "bidirectional cross-validation of model code based on UPPAAL and C code" implementation scheme will now be demonstrated using a specific aviation application. On an aircraft, multiple sensors may execute programs simultaneously. These sensors may read and modify shared data simultaneously. If data consistency and security are not properly ensured in the design, serious safety issues could arise.

[0075] Specifically, aircraft have numerous and functionally coupled sensors, each executing distinct control programs. Flight data sensors such as accelerometers, gyroscopes, and altimeters monitor the aircraft's attitude, position, and speed in real time; environmental sensors such as temperature, air pressure, and engine speed monitor changes in the flight environment; and engine sensors such as oil pressure, temperature, and engine speed monitor the engine's operating status. These sensors generate hundreds or even more data points, simultaneously reading and modifying shared data, such as the aircraft's real-time status parameters. Multiple sensors simultaneously reading and modifying shared data can lead to several issues: 1) Data contention: Multiple sensors accessing the same shared data area simultaneously can lead to inconsistent data; 2) Synchronization: Data synchronization between sensors is cumbersome and error-prone under high real-time requirements; and 3) Difficult code verification: Traditional code verification methods are insufficient for detecting code that involves complex interactions between multiple systems. Ensuring error-free operation across thousands or even more lines of sensor control code is challenging.

[0076] Therefore, the above problems can be solved by using a two-way cross-model and code approach. Specifically:

[0077] 1) Model establishment

[0078] UPPAAL is used to build a timed automaton model of the aircraft sensor control program. This model describes the process of sensor reading data, processing data, and modifying shared data, and extracts the core logic and timing characteristics from the control program code.

[0079] 2) Code conversion

[0080] The sensor control program is converted into C code through rule conversion and optimized to ensure that the converted C code can accurately reflect the operation logic in the model, especially the logical and timing relationships in the reading and writing of shared data and sensor synchronization.

[0081] 3) Model-code two-way cross validation

[0082] The consistency and correctness of the detection results on the model side and the detection results on the code side are compared and verified to obtain the verification results of the model-code two-way cross-validation, and improvements are made to the problems detected.

[0083] (1) System Modeling

[0084] Based on the practical application context described above, we present an abstract aircraft sensor control program modeling the aircraft's accelerometer and gyroscope as two independent timed automata. Each time step reads the aircraft attitude from a shared data area and updates this data after the sensor measurement. This process can be modeled as a multithreaded program with two concurrent processes—accelerometer process P1 and gyroscope process P2—operating simultaneously. They simultaneously manipulate the aircraft attitude variable (global variable x) in the shared data area, performing a subtraction operation and checking whether the result is greater than or equal to 0 in each iteration. UPPAAL is used to formally model and verify concurrent operations, assessing whether they lead to data races or inconsistencies and verifying that the program satisfies specific properties such as safety, consistency, and integrity.

[0085] The specific modeling process is as follows:

[0086] First, set up global variable declarations: an int variable x, initialized to 0, and a channel variable reset. x represents a global variable shared by all processes, and reset is a channel type. This allows for inter-process synchronization and communication within the model, enabling data transfer and synchronization between concurrent processes, thus enabling interaction and coordination between concurrent programs. Through channels, different processes can send and receive messages, enabling coordination and synchronization within the system.

[0087] Secondly, establish the aircraft accelerometer process POne (such as Figure 2 As shown): Set its local variable to int y1 and initialize it to 0; establish the gyroscope process PTwo (as shown Figure 3 (as shown): Set the local int variable y2 to 0. Combine the aircraft accelerometer and gyroscope processes into a local aircraft sensor system and simulate it using UPPAAL. The idle state is the initial state; want is the state after variable initialization; wait is the waiting state; cs is the state after the y1 or y2 variable is updated; and ct is the state after the aircraft attitude angle x variable is updated, with x being required to be non-zero.

[0088] (2) Model Verification

[0089] like Figure 4 As shown, the UPPAAL simulator results show that a process deadlocks when transitioning from the wait state to the cs state. This issue is documented in the "Model Verification Problem Description." Analysis of the deadlock revealed that no specific operations were performed during the transition from the ct state to the wait state, and that a resource conflict occurred at some point, leading to the deadlock. (For example, if process P2 had received the channel reset command, while process P1 remained in the wait state, a deadlock would occur during the transition from the wait state to the cs state.)

[0090] (3) Model verification and analysis

[0091] Analyze its modeling process and change its modeling process such as Figure 5 、 Figure 6 shown.

[0092] First, declare the global int variable z and the channel type variable reset; declare the aircraft accelerometer process POne, which contains the local int type variable y1 and initializes it to 0; declare the gyroscope process PTwo, which contains the local int type variable y2 and initializes it to 0. At the same time, in the model declaration part, the POne process and PTwo are two system processes P1 and P2.

[0093] The system simulates two processes, POne and PTwo, under a shared variable (the aircraft attitude variable z). Each time the POne process loops, it adds 1 to the global variable z, and each time the PTwo process loops, it subtracts 1 from the global variable z. At the same time, the system requires that x in the system cannot be less than 0. UPPAAL is used to verify the path in this instance.

[0094] (4) Attribute Verification

[0095] Based on the constructed model, simulation was performed using a simulator and verification was performed in a verifier. The results are as follows.

[0096] ①Simulator simulation

[0097] When using the simulator to simulate, it was found that when the number of simulated interactions reached 32766, a type out-of-bounds problem occurred. The model cannot handle values ​​greater than 32767, such as Figure 7 shown.

[0098] ② Validator verification

[0099] To verify that the system satisfies the condition "For all conditions, as long as the system is in the P1.wait state, the aircraft attitude variable z always remains greater than 0," we provide the constraint: A[]P1.wait imply z>0 and verify this in the verifier. The verifier displays "The property is not satisfied," indicating that the value of z is not always greater than 0 in the wait state of the P1 process.

[0100] To verify the condition that "there exists a path in the system such that the aircraft attitude variable z is equal to 0 in the P1.wait state," we provide the constraints: E <> P1.wait and z == 0 and verify this in the verifier. The verification result shows "The property is satisfied." This indicates that in the P1 process's wait state, the value of z is equal to 0.

[0101] Verify that there exists an execution path in the system that satisfies the aircraft attitude variable z less than 0 during the P1.wait state. Given the constraints E<>P1.wait and z<0, this is verified in the verification process. The verification result shows: "Assignment of value '32768' to variable 'P2.y2' is out of range on line 1ofProject / PTwo / wait→wait / assignment," indicating that the model cannot verify that the wait state in P1 is less than 0; the value is out of range.

[0102] Similarly, we verify whether for any state space, when in the P1.wait state, the condition that the aircraft attitude variable z is greater than or equal to 0 is satisfied. We give the constraint condition: A[]P1.wait imply z>=0. Verify it in the validator, and the verification result shows "Assignment of value'32768'to variable'P2.y2'is out of range on line 1 of Project / PTwo / wait→wait / assignment", indicating that the model cannot verify whether the wait state in the P1 process is always greater than or equal to 0, and the value is out of range.

[0103] In the "Model Verification Problem Description", record the problem that occurred during the model verification process: "The number range exceeds [-32768, 32767], and the UPPAAL model cannot verify its related situations."

[0104] (5) Model-Code Conversion

[0105] To address the aforementioned issues with UPPAAL, we'll retest the UPPAAL-generated C code using a C code checking tool. First, convert the UPPAAL model to XML format by clicking "File / Save Model As." Next, convert the XML model to the corresponding C code, primarily converting model elements like location, transition, variables, and clocks into C variables and functions.

[0106] (6) Code Verification

[0107] Apply code verification tools (such as CMBM, ESBMC) to verify the C language file converted from the model in step (5). The specific process is as follows.

[0108] ①CBMC detection C code

[0109] Use CBMC to detect C language files. Use CBMC version 5.88 and run it on Linux. The configuration parameters are as follows:

[0110] --trace: Print out the specific variables that do not meet the assertion;

[0111] --unwind: Unwind the loop 3 times.

[0112] The test result displays "Violated property: file / src / test.c function P2line21thread 2assertion x>=0," indicating that the CBMC tool discovered that the variable x might be 0 on line 21 of the code. Record the CBMC test result for the C language file in the "Code Verification Problem Description" section.

[0113] ②ESBMC detection C code

[0114] Use ESBMC version 7.2.0 and run it on a 64-bit Windows platform. The configuration parameters are as follows:

[0115] --context_bound 2: context switch twice;

[0116] --no-unwinding-assertions: disable assertions about reaching the number of loop unwindings;

[0117] --unwind 3: Unwind the loop 3 times.

[0118] After the test, the display shows "Violated property: file / src / test.c function P2line 21thread 2assertion x>=0", indicating that at line 21 of the code, the aircraft attitude variable x may be 0. Record the results of the ESBMC test of the C language file in "Code Verification Problem Description".

[0119] (7) Model code two-way cross validation

[0120] The "Model Verification Problem Description" and "Code Verification Problem Description" are combined to form a "Model and Code Cross-Validation Problem Set." In this example, the "Model and Code Cross-Validation Problem Set" includes three issues generated by the original model: deadlock, type out-of-bounds, and the possibility that the aircraft attitude variable x could be 0. Based on this "Model and Code Cross-Validation Problem Set," the system model is modified until no related issues are reported.

[0121] In summary, this case study, through the modification of shared variables (aircraft attitude variables) using the aircraft's accelerometer and gyroscope, illustrates the significance and value of model-code cross-validation. This not only enables more comprehensive problem detection from both the model and code sides, but also improves the accuracy and completeness of these two sides by integrating the results of model and code validation. Finally, the test results can be fed back to the system side, enabling continuous correction to achieve the goal of detecting problems and correcting the system.

Claims

1. A model and code cross-validation analysis method based on UPPAAL, characterized in that: The specific steps are as follows: Step (1), system modeling: describe the system as a timed automaton UPPAAL model, and the system described by UPPAAL is denoted as M; Step (2), model verification: Use UPPAAL's validator to perform initial grammatical correctness verification to check the basic correctness of the model; if M meets the initial grammatical correctness standard, Verify(M) returns true and the next step of verification is performed; if M does not meet the initial grammatical correctness standard, Verify(M) returns false and gives the specific error location and error cause, further modifies the model grammatical structure, and repeats step (2) until M meets the initial grammatical correctness standard, that is, Verify(M) returns true; Step (3), model verification analysis: if Verify(M) is true, then the model is dynamically verified, starting from the initial state, simulating the dynamic changes of the state, and checking the changes in variable values ​​during dynamic changes at any time to detect whether the model has a deadlock problem; let the deadlock problem be represented as Deadlock(M). If the system has a deadlock, Deadlock(M) returns true, and the deadlock problem is recorded in the model verification problem description. The system structure is modified and the process returns to step (2) until the system has no deadlock problem, that is, Deadlock(M) returns false, and the subsequent attribute verification step is entered; Step (4), attribute verification: Assume that the system model M must satisfy the attribute P, then execute Verify(M, P); if Verify(M, P) returns true, the model is considered correct; if Verify(M, P) returns false, then record these problems in the model verification problem description; Step (5), model-code conversion: convert the UPPAAL model M into an XML representation M X , use the model conversion tool to convert M X Convert to C language file M C ; Step (6), code verification: Use a code verification tool to verify the C language file converted in step (5); if the verification process VerifyCode(C) returns true, it proves that the code is correct; If the verification process VerifyCode(C) returns false, it means that there is a problem with the code verification detection, and it is recorded in the code detection problem description; Step (7), model and code cross-validation: The problems verified or detected from the model verification problem description and the code detection problem description are integrated to form a model and code cross-validation problem set; and the system modeling is corrected according to the model and code cross-validation problem set.

2. The model and code cross-validation analysis method based on UPPAAL according to claim 1, characterized in that: In step (1), the timed automaton UPPAAL model is as follows: let S represent the state location set, δ represent the transition set, s0 represent the initial state, and C represent the clock set. Then the system is represented by the timed automaton UPPAAL as a four-tuple A = (S, δ, s0, C); its behavior is expressed as: δ: S×Guards×S→Synchronization, where Guards and Synchronization describe the state transition rules and communication mechanisms; the state evolution of the system is expressed as Path(G)=∑ e∈E w(e), where G represents the system state graph, e belongs to an edge in the edge set E, and each edge e in the edge set E has a weight function w(e) representing the time or resource consumption of state transition.

3. A UPPAAL-based model and code cross-validation analysis method according to claim 1 or 2, characterized in that: In step (2), let ∑X be the set of UPPAAL model grammar rules. For any model M, it should belong to the legal model set ∑ valid X, that is, M∈∑ valid X; define a validator function Verifier_Syntax(M) to check the correctness of the model syntax. If the model M meets all the syntax rules, Verifier_Syntax(M) returns true; if Verifier_Syntax(M) does not meet the syntax rules, Verifier_Syntax(M) returns (false, error_loc, error_reason); where false means the syntax check fails, error_loc indicates the location of the error, and error_reason indicates the cause of the error.

4. The model and code cross-validation analysis method based on UPPAAL according to claim 3, characterized in that: The initial syntax correctness verification is expressed as: If Verifier_Syntax(M) returns true, continue with the subsequent verification steps; if Verifier_Syntax(M) returns false, further modify the model syntax structure according to the error location and error cause, and repeat step (2) until Verifier_Syntax(M) returns true. Among them, M (k) represents the model after the kth revision; let F represent the set for which Verifier_Syntax(M) returns false, then F is expressed as F = {M|Verifier_Syntax(M) = false}, and the revision process of model M is equivalent to finding the complement of F The elements of 5. The model and code cross-validation analysis method based on UPPAAL according to claim 1, characterized in that: In step (4), the specific process of verifying Verify(M, P) is as follows: let p represent the attribute, P represent the set of attributes to be verified, then p∈P, representing a condition that the model must satisfy; define a verifier function Verifier_Property(M, p) to check whether the model M satisfies the attribute p, let property_reason represent the specific reason why the attribute is not satisfied.

6. The model and code cross-validation analysis method based on UPPAAL according to claim 5, characterized in that: The process of the Verifier function checking whether the model M satisfies the property p is expressed as: Furthermore, P = {p1, p2, ..., p m }, the attribute verification process is expressed as: Suppose the problem record set is ε, and record the information of Verifier_Property(M, p) = (false, property_reason) in ε, that is, ε={(p, property_reason)|Verifier_Property(M, p)=false}.

7. The UPPAAL-based model and code cross-validation analysis method according to claim 1, characterized in that: In step (5), the specific operation process is as follows: The first step is to convert the UPPAAL model M into XML representation; including: converting the template into XML tags and their attributes; converting the system definition into XML tags and their attributes; assuming that the UPPAAL model M contains n templates T1, T2, ..., T n , the system is defined as S; then the XM representation of model M is M XML , including the template part and the system definition part S XML ; Further, M XML ={T XML , S XML }; The second step is to convert the XML file into a C language file; this includes: parsing the XML representation and generating C code. First, parse the XML representation, and define the conversion tool from XML to C language as T c , using the conversion function of the conversion tool Tc Second, use T c Parsing M XML , generate the intermediate structure ψ: ψ=parse(M XML ); Finally, the corresponding C language file M is generated through the parsed intermediate structure ψ C :M C =generate_C_code(ψ).

8. The UPPAAL-based model and code cross-validation analysis method according to claim 7, characterized in that: The specific process of code verification in step (6) is as follows: First, input the verification model: convert the C language file M generated in step (5) into C As input, use the code detection tools CBMC, ESBMC, and SPIN to verify the input C language file; let the verification function of the code detection tool be Y, and the code detection result set be R verify , then the code detection tool verification process is expressed as: Y:M C →{true, false}, at the same time, R verify =Y{M C }; where R verify = true, indicating that the code verification is correct, R verify = false, it means that the code detection method detects an error; finally, R verify = false is stored in the code detection problem description.

9. The UPPAAL-based model and code cross-validation analysis method according to claim 1, characterized in that: In step (7), the specific process of model and code cross-validation is as follows: First, the problem is summarized; let the set of model detection problems be P model-check , the set of code detection problems is P code-verify , the set of models and code cross validation problems is P cross-validation , then P cross-validation =P model-check ∪P code-verify ; Among them, P model-check ={p1, p2, ..., p m }, P code-verify ={q1, q2, ..., q n }, P cross-validation ={r1, r2, ..., r k }; k≤m+n;, r i is the merge p i and q i The obtained question items; secondly, according to P cross-validation The system model is corrected according to the problem in the paper; let the correction function be The input is the current system and the problem set, and the output is the revised new system model, which can be expressed as: Right now The modified model M′ and the corresponding C code file M′ C Re-enter the model checking and code checking loop and return to step (1) until the verification result is true, that is, no new problem description is generated, that is, |P cross-validation |=0.

Citation Information

Patent Citations

  • ROS code generator and code generation method based on formal model

    CN110109658A

  • Digital twin manufacturing unit behavior modeling method based on time automaton

    CN111722539A

  • Source code formal verification method and system

    CN117687924A

  • An interoperable extensible system for the generation of verified software code

    WO2018007822A1