Interrupt data race model detection method based on single variable access order pattern
By using model checking technology and the bounded model checking tool CBMC to verify assertions, the problem of false positives in single-variable access sequence pattern detection in interrupt programs is solved, high reliability and automated detection results are achieved, and data competition in interrupt programs is accurately identified.
Patent Information
- Application Number
- CN202210536587.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-17
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-05-17
AI Technical Summary
The existing interrupt data race detection method based on the single-variable access sequence pattern has false alarm problems in the interrupt driver, and cannot effectively identify data races in the interrupt program, especially the single-variable access sequence pattern.
Model checking technology is used to convert the interrupt program into a multi-threaded program, automatically add assertions after serialization, and use the bounded model checking tool CBMC to verify the assertions and identify single-variable access sequence patterns in the interrupt program.
It achieves high reliability and automated detection, can accurately identify data competition in interrupt programs, avoids false positives, and only needs to specify the mode and global variables to determine whether there is an access sequence pattern.
Smart Images

Figure CN114924852B
Abstract
Description
Technical Field
[0001] The invention belongs to the field of software model detection, in particular to an interrupt data competition model detection method based on a single variable access sequence mode. Background Art
[0002] Interrupt-driven software is mainly used in safety-critical fields such as aerospace, automotive electronics, and medical equipment, which have extremely high requirements for software reliability. Data race problems caused by interrupts have a great impact on the reliability and security of software.
[0003] Since there are priority relationships and interrupt enable and disable operations between interrupts in an interrupt program, the data competition detection method for ordinary multi-threaded programs is not applicable to interrupt programs. In "Interrupt Data Competition Detection Method Based on Variable Access Sequence Pattern", Chen Rui et al. divide the data competition of interrupt programs into seven defect modes, such as single variable access sequence pattern and multiple associated variable access consistency being destroyed. Among them, the most common and most difficult to solve is the single variable access sequence pattern, which is generally divided into four types: read-write-write, write-write-read, read-write-read, and write-read-write.
[0004] Read-Write-Write mode (RWW) of single variable access sequence mode: After a global variable is read in concurrent stream 1, a write operation is performed on the global variable. Under normal circumstances, the value of the variable should remain unchanged between the read and write operations. However, because concurrent stream 2 with a higher priority may interrupt concurrent stream 1 and modify the value of the global variable, the consistency of the global variable in concurrent stream 1 is destroyed.
[0005] Write-Write-Read mode (WWR) of single variable access order mode: After a global variable is written in concurrent stream 1, it is read again. The expected value read is equal to the previously written value. However, because concurrent stream 2 with a higher priority may interrupt concurrent stream 1 and modify the value of the global variable, the value of the global variable read in concurrent stream 1 is not the previously written value.
[0006] Read-Write-Read mode (RWR) of the single variable access sequence mode: In concurrent stream 1, two consecutive read operations are performed on a global variable. It is expected that the values read twice should be equal. However, because concurrent stream 2 with a higher priority may interrupt concurrent stream 1 and modify the value of the global variable, the values of the global variable read twice in concurrent stream 1 are inconsistent.
[0007] Write-Read-Write Mode (WRW) of Single Variable Access Order Mode: Two consecutive write operations are performed on a global variable in concurrent stream 1. However, because concurrent stream 2 with a higher priority may interrupt concurrent stream 1 and read the value of the global variable, the value of the global variable read in concurrent stream 2 is inconsistent with the expected value.
[0008] Most of the current detection methods based on single variable access sequence patterns use static analysis and abstract interpretation. In the "Interrupt Data Competition Detection Method Based on Variable Access Sequence Patterns", the detection tool SpaceDRC uses a static analysis method that supports inter-procedural analysis and interrupt concurrency analysis. Although static analysis methods, as mainstream software detection methods, can detect program defects, such methods can lead to false positives in the detection results. Model detection technology has great advantages in verifying the reliability of results. Therefore, it is of great significance to explore the applicability of model detection technology in interrupt driver programs. Summary of the invention
[0009] The present invention aims to use model detection technology to identify data competition in interrupt programs. The present invention focuses on the detection of single variable access sequence patterns, so the detection content of the present invention is whether there is a specific single variable access sequence pattern in the interrupt program. First, a pattern and a global variable to be detected are selected; then the source interrupt program is converted into a multi-threaded program, and then the multi-threaded program is sequenced. In the sequenced program, the tool automatically adds assertions about variables, and then the program is input into a bounded model detection tool; finally, the bounded model detection tool gives a result. If the assertion is false, it means that the single variable access sequence of this pattern exists in the program, otherwise it does not exist.
[0010] The technical solution of the present invention is:
[0011] A method for detecting an interrupt data competition model based on a single variable access sequence pattern comprises the following steps:
[0012] 1) Specify the single variable access sequence mode and global variable to be tested: Specify the single variable access sequence mode read-write-write, write-write-read, read-write-read, or write-read-write; At the same time, the name of the global variable to be tested needs to be given. If it is a cell of an array, the array name and subscript need to be given;
[0013] 2) Sequencing of source interrupt programs: First, convert the interrupt driver program into a multi-threaded program, and then sequence the multi-threaded program so that the execution of the sequenced program can simulate the thread interaction execution in the multi-threaded program; at the same time, add constraints so that the execution order of the program meets the priority requirements of the source interrupt program, and the sequenced program can support various interrupt enable and disable operations in the source interrupt program;
[0014] 3) Automatically adding assertions: In the serialized program obtained in step 2), for the detected read or write statements about the global variables, assignment statements and assertions are added according to the specified mode and read or write;
[0015] 4) Calling the bounded model checking tool: taking the sequential program obtained in step 3) as input, setting parameters, and using the bounded model checking tool CBMC to verify the assertions therein;
[0016] 5) Obtain verification results: If there is an assertion in the program that is false, visualize the specific statements in the order of execution based on the counterexample path.
[0017] In step 3), the process of automatically adding assertions includes: selecting a concurrent flow combination; traversing the concurrent flow to determine the read / write type of each statement; if the statement is a read / write statement of a specified global variable, automatically adding an assignment statement and assertion according to the specified single variable access sequence mode processing method; if the statement is not a read / write statement of a specified global variable, no processing is performed and the next statement is determined. The details are as follows:
[0018] 3-1) Select the concurrent stream combination: In the single variable access sequence mode, you need to determine the concurrent stream combination first; a concurrent stream combination includes a concurrent stream 1 and a concurrent stream 2, where concurrent stream 1 has a low priority and concurrent stream 2 has a high priority; therefore, concurrent stream 1 is selected from the set consisting of the main function and all interrupts except the highest priority, and concurrent stream 2 is selected from the set consisting of all interrupts.
[0019] 3-2) Traverse the concurrent flow and determine the read and write type of each statement: parse the sequential program code and generate an abstract syntax tree AST object to obtain the type of each statement; determine the read and write type of the statement based on the position of the specified global variable in the statement. If it is an if statement and the condition is an expression about the global variable, then the statement is a read of the global variable; if it is an assignment statement and the global variable is on the left side of the equal sign, then the statement is a write of the global variable; if it is an assignment statement and the global variable is on the right side of the equal sign, then the statement is a read of the global variable.
[0020] 3-3) Processing methods of single variable access sequence patterns in different situations
[0021] (a) Read-write mode processing method: define variables reader_i and write_i of the same type as the variables to be detected in the serialization program, as well as an integer read operation counter variable num_i, where i is the number corresponding to the selected concurrent stream 1; insert an assignment statement after the read statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable reader_i, and increase the read operation counter variable num_i by 1; insert an assignment statement before the write statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable write_i, and use an if statement to determine whether the read operation counter variable num_i is not 0. If it is satisfied, insert the assertion assert(write_i==reader_i) and set the read operation counter variable num_i to 0; do not process concurrent stream 2.
[0022] (b) Write-write-read mode processing method: define in the sequential program variables reader_i, write_i of the same type as the variables to be detected, and an integer write operation counter variable num_i, where i is the number corresponding to the selected concurrent stream 1; insert an assignment statement after the write statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable write_i, and increase the write operation counter variable num_i by 1; insert an assignment statement before the read statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable reader_i, and use an if statement to determine whether the write operation counter variable num_i is not 0. If it is satisfied, insert the assertion assert(write_i==reader_i) and set the write operation counter variable num_i to 0; do not process concurrent stream 2.
[0023] (c) Read-write-read mode processing method: define variables reader_i and tmp_i of the same type as the variables to be detected, and an integer write operation counter variable num_i in the serialized program, where i is the number corresponding to the selected concurrent stream 1; insert an assignment statement after the read statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable reader_i, and then use an if statement to determine whether the read operation counter variable num_i is not 0. If it is satisfied, add an assertion assert(reader_i == tmp_i), and finally add 1 to the read operation counter variable num_i, and assign the reader_i value to the cache variable tmp_i; set the read operation counter variable num_i to 0 after the write operation in concurrent stream 1; and do not process concurrent stream 2.
[0024] (d) Write-read-write mode processing method: define an integer variable a_i and an integer write operation counter variable num_i in the serialized program, where i is the number corresponding to the selected concurrent stream 1; use an if statement after the write statement about the global variable in concurrent stream 1 to determine whether the write operation counter variable num_i is not 0, and if so, add an assertion assert(a_i == 0); finally, add 1 to the write operation counter variable num_i and set a_i to 0; set the variable a_i to 1 after the read statement about the global variable in concurrent stream 2.
[0025] The beneficial effects of the present invention are:
[0026] The present invention designs a method for detecting interrupt data competition model based on a single variable access sequence pattern. Assignment statements and assertions are automatically added to the sequenced program, and then the bounded model detection tool CBMC is called to verify the assertions. According to the results of the assertions, it is determined whether there is a data competition of a certain access sequence pattern in the interrupt program. The method has the following characteristics: (1) High reliability. Since the model detection method does not produce false positives, the errors detected are real. (2) High degree of automation. For the interrupt program, only the mode and global variables need to be specified to determine whether there is an access sequence pattern for the variable. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is the main flow chart of the interrupt data competition model detection method based on the single variable access sequence mode of the present invention;
[0028] Figure 2 Flowchart of the algorithm for automatically adding assertions. DETAILED DESCRIPTION
[0029] The specific implementation of the present invention is further described below in conjunction with the accompanying drawings and technical solutions.
[0030] The present invention proposes an interrupt data competition model detection method based on a single variable access sequence pattern, such as Figure 1 As shown. By specifying the pattern and variable to be detected, the source program is sequenced, assertions are automatically added, and bounded model detection tools are used to detect the single variable access sequence pattern in the source program. The details are as follows:
[0031] 1) Specify the mode and variable to be detected, for the source interrupt program, assume that the priority of the interrupt is known, and the program contains operations related to interrupt enable and interrupt disable. This embodiment takes the detection of the write-read mode of variable X as an example.
[0032] 2) Serialize the source interrupt program. First, convert the interrupt program into a multi-threaded program, where the interrupts of the source interrupt program correspond to the threads of the multi-threaded program. Then specify the serialization expansion times, which are generally set to the maximum number of loops in the source interrupt program. If the number of loops is unknown, it can be set in a certain ascending sequence. Then serialize the multi-threaded program, which includes the priority information of the interrupt and the processing of interrupt enable and disable. The serialized program divides the original program into multiple statement blocks, each of which is identified by a separate label, and an indefinite number of labels are executed each time.
[0033] 3) Automatically add assertions based on Figure 2The flowchart shown automatically adds assignment statements and assertions in the sequential program. The specific process is as follows: W1(X) represents the first write of variable X, and R1(X) represents the first read of variable X. If the order of occurrence of W1(X) of concurrent stream 1, W1(X) of concurrent stream 2, and R1(X) of concurrent stream 1 is the write-write-read access sequence mode for variable X. According to the write-write-read mode processing method, add assignment statements write=x and num++ after W1(X) of concurrent stream 1, and add assignment statement reader=x and if statement before R1(X) of concurrent stream 1 to determine whether num is not 0. If the condition is met, use assertion assert(write==reader) and set num to 0, and do not process concurrent stream 2. Since the simulation execution of the sequential program is based on a label, the statements added to the sequential program should be in the same label as the detected read and write of the global variable, so as to ensure the atomic execution of the added statements and the read and write statements.
[0034] 4) Take the sequenced program as input and call the bounded model checking tool CBMC to verify the assertions in it. Specifically, the bounded model checking tool CBMC converts the program and its constraints into CNF formula C, converts the assertion properties into CNF formula P, and then calls the SAT solver to solve
[0035] 5) Based on the results and counterexample information returned by the bounded model checking tool, show its counterexample path. If the returned result is VERIFICATION FAILED, it means that there is a false assertion, that is, there is such an access sequence pattern about the variable in the source interrupt program, and give a specific counterexample path. If the returned result is VERIFICATION SUCCESSFUL, it means that there is no false assertion under the current given input parameters.
[0036] This method has been tested many times, as listed below:
[0037] 1) The benchmark test set racebench of a test interrupt concurrency defect detection tool provided by a company was tested. There are 31 programs in the test set containing 48 real single variable access sequence patterns. Since the bounded model checking tool CBMC does not work well on programs with large loop times, the loop times of 9 source programs in the test set were modified, and the single variable access sequence patterns before the modification were guaranteed to still exist. On this basis, this method can detect all 48 real single variable access sequence patterns without false positives.
[0038] 2) For a real interrupt program with about 1000 lines of code provided by a company, there are 3 real single variable access sequence patterns in the program. After adaptive processing, this method can detect all 3 single variable access sequence patterns without false positives.
Claims
1. A method for detecting interrupt data competition model based on single variable access sequence pattern, characterized in that: The following steps are involved: 1) Specify the single variable access sequence mode and global variable to be tested: Specify the single variable access sequence mode read-write-write, write-write-read, read-write-read, or write-read-write; At the same time, the name of the global variable to be tested needs to be given. If it is a cell of an array, the array name and subscript need to be given; 2) Sequencing of source interrupt programs: First, convert the interrupt driver program into a multi-threaded program, and then sequence the multi-threaded program so that the execution of the sequenced program can simulate the thread interaction execution in the multi-threaded program; at the same time, add constraints so that the execution order of the program meets the priority requirements of the source interrupt program, and the sequenced program can support various interrupt enable and disable operations in the source interrupt program; 3) Automatically adding assertions: In the serialized program obtained in step 2), for the detected read or write statements about the global variables, assignment statements and assertions are added according to the specified mode and read or write; 4) Calling the bounded model checking tool: taking the sequential program obtained in step 3) as input, setting parameters, and using the bounded model checking tool CBMC to verify the assertions therein; 5) Obtain verification results: If there is an assertion in the program that is false, visualize the specific statements in the order of execution based on the counterexample path.
2. The interrupt data competition model detection method based on a single variable access sequence pattern according to claim 1, characterized in that: In step 3), the process of automatically adding assertions includes: selecting a concurrent flow combination; traversing the concurrent flow to determine the read and write type of each statement; if the statement is a read and write statement of a specified global variable, automatically adding an assignment statement and an assertion according to a specified single variable access sequence mode processing method; if the statement is not a read and write statement of a specified global variable, no processing is performed and the next statement is determined; the details are as follows: 3-1) Select concurrent stream combination: In the single variable access sequence mode, the concurrent stream combination needs to be determined first; a concurrent stream combination includes a concurrent stream 1 and a concurrent stream 2, where concurrent stream 1 has a low priority and concurrent stream 2 has a high priority; therefore, concurrent stream 1 is selected from the set consisting of the main function and all interrupts except the highest priority, and concurrent stream 2 is selected from the set consisting of all interrupts; 3-2) Traverse the concurrent stream and determine the read and write type of each statement: parse the sequential program code and generate an abstract syntax tree AST object to obtain the type of each statement; determine the read and write type of the statement based on the position of the specified global variable in the statement; if it is an if statement and the condition is an expression about the global variable, then the statement is a read of the global variable; if it is an assignment statement and the global variable is on the left side of the equal sign, then the statement is a write of the global variable; if it is an assignment statement and the global variable is on the right side of the equal sign, then the statement is a read of the global variable; 3-3) Processing methods of single variable access sequence patterns in different situations (a) Read-write mode processing method: define variables reader_i and write_i of the same type as the variables to be detected in the sequential program, and an integer read operation counter variable num_i, where i is the number corresponding to the selected concurrent stream 1; insert an assignment statement after the read statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable reader_i, and increase the read operation counter variable num_i by 1; insert an assignment statement before the write statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable write_i, and use an if statement to determine whether the read operation counter variable num_i is not 0. If it is satisfied, insert an assertion assert(write_i == reader_i) and set the read operation counter variable num_i to 0; do not process concurrent stream 2; (b) Write-write-read mode processing method: define variables reader_i and write_i of the same type as the variables to be detected in the sequential program, as well as an integer write operation counter variable num_i, where i is the number corresponding to the selected concurrent stream 1; insert an assignment statement after the write statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable write_i, and increase the write operation counter variable num_i by 1; insert an assignment statement before the read statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable reader_i, and use an if statement to determine whether the write operation counter variable num_i is not 0. If it is satisfied, insert an assertion assert(write_i == reader_i) and set the write operation counter variable num_i to 0; do not process concurrent stream 2; (c) Read-write mode processing method: define variables reader_i and tmp_i of the same type as the variables to be detected, and an integer write operation counter variable num_i in the sequential program, where i is the number corresponding to the selected concurrent stream 1; insert an assignment statement after the read statement about the global variable in concurrent stream 1 to assign the value of the variable to the variable reader_i, and then use an if statement to determine whether the read operation counter variable num_i is not 0. If it is satisfied, add an assertion assert(reader_i == tmp_i), and finally add 1 to the read operation counter variable num_i, and assign the reader_i value to the cache variable tmp_i; set the read operation counter variable num_i to 0 after the write operation in concurrent stream 1; do not process concurrent stream 2; (d) Write-read-write mode processing method: define an integer variable a_i and an integer write operation counter variable num_i in the serialized program, where i is the number corresponding to the selected concurrent stream 1; use an if statement after the write statement about the global variable in concurrent stream 1 to determine whether the write operation counter variable num_i is not 0, and if so, add an assertion assert(a_i == 0); finally, add 1 to the write operation counter variable num_i and set a_i to 0; set the variable a_i to 1 after the read statement about the global variable in concurrent stream 2.
