An operating system component concurrent defect detection method and device and storage medium
Patent Information
- Application Number
- CN202511926423.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2045-12-19
AI Technical Summary
但现有技术在检测线程交错时,通常忽视了线程交错之间的等价性,并且随机选取线程交错进行测试,这样不仅浪费测试资源,还可能漏掉潜在的缺陷
[0014]本申请提供的方法,通过在操作系统组件程序的并发操作和同步原语处插桩,收集多线程指令的执行序列,并将收集的指令建模为读操作或写操作。根据读写规则构造出线程交错的读写关系,并通过判断不同线程交错的读写关系是否相等,过滤掉等价的线程交错。进一步,评估待测试线程交错的测试优先级,优先测试风险等级最高的线程交错。通过本发明,能够实现等价线程交错的识别与过滤,并基于线程交错的读写关系差异来评估测试优先级,从而提高操作系统组件并发缺陷测试的效率,减少冗余测试,并提升缺陷检测的覆盖率。
Smart Images

Figure CN122711515B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of defect detection, and in particular to a method, apparatus and storage medium for concurrent defect detection of operating system components. Background Technology
[0002] With the development and application of computer technology, people's demand for computing performance is constantly increasing, especially in multi-core computers. To improve computing efficiency and hardware resource utilization, concurrent programs are widely used. Concurrency mechanisms are employed in many system software systems, such as operating systems, database systems, and web servers, to achieve parallel processing of tasks, thereby improving system performance and response speed. However, with the widespread adoption of multi-core processors and the increase in the number of threads, concurrency defects in programs, such as deadlock, data races, atomicity violations, and order violations, have become significant problems for developers.
[0003] In multithreaded programs, the interleaved execution order of instructions by multiple threads can lead to concurrency defects. To improve defect detection efficiency, traditional methods capture concurrency defects by testing different thread interleaving sequences. However, current technologies often ignore the equivalence between thread interleaving sequences and randomly select them for testing. This not only wastes testing resources but may also miss potential defects. Therefore, improving the efficiency of concurrency defect detection, identifying and filtering equivalent thread interleaving sequences, and selecting the most likely thread interleaving sequences to trigger concurrency defects based on testing priority have become pressing issues that need to be addressed in current technology.
[0004] To address the aforementioned issues, this invention proposes a concurrent defect detection method for operating system components based on thread interleaving priority. The aim is to improve the efficiency of concurrent defect detection, avoid redundant testing, and increase defect detection coverage by analyzing and optimizing the read-write relationship of thread interleaving. Summary of the Invention
[0005] This application provides a method, apparatus, and storage medium for detecting concurrent defects in operating system components. The technical solution is as follows.
[0006] On the one hand, a method for detecting concurrency defects in operating system components is provided, the method comprising: Instrumentation is performed at concurrent operations and synchronization primitives in operating system component programs to collect the execution sequence of multi-threaded instructions; The execution sequence of the multi-threaded instructions is modeled as a read operation or a write operation; Based on the read and write rules, a pair of read and write operations is matched to construct a thread-interleaved read and write relationship; Determine whether the read-write relationships corresponding to the execution sequences of the multi-threaded instructions are equal, and filter out equivalent thread interleaving. The equality of read-write relationships is used to determine whether the corresponding thread interleavings are equal. The test priority of thread interleaving is evaluated based on the read-write relationship, and thread interleaving with the highest risk level is tested first.
[0007] Optionally, the stake driving process includes: Traverse the source code files of operating system component programs to generate the corresponding abstract syntax tree; Traverse the abstract syntax tree, instrument multi-threaded concurrent operations and synchronization primitives in the abstract syntax tree, and collect event content, which includes the execution sequence of collected multi-threaded instructions.
[0008] Optionally, the step of evaluating the test priority of thread interleaving based on read-write relationships, and prioritizing the testing of thread interleaving with the highest risk level, includes: Calculate the difference in read / write relationships between the interleaved set of threads to be tested and the interleaved set of threads already tested; The risk level of thread interleaving under test is assessed by the differences in read-write relationships. The threads to be tested are assigned corresponding interleaved test priorities based on their risk levels. Prioritize testing thread interleaving, which has the highest risk level.
[0009] Optionally, calculating the difference in read-write relationships between the interleaved set of threads to be tested and the interleaved set of threads already tested includes: Obtain the read / write relationship between the interleaved set of threads to be tested and the interleaved set of threads already tested; Calculate the difference between the read-write relationship of the thread under test and the read-write relationship of each thread under test in the set of thread under test; For each read-write relationship where the thread to be tested and the thread already tested are interleaved, calculate the minimum difference in the read-write relationship. The differences in read / write relationships between all interleaved threads under test and the interleaved set of tested threads are merged to obtain the overall difference between the interleaved sets of tested threads and the interleaved set of tested threads.
[0010] Optionally, assessing the risk level of thread interleaving under test based on the differences in read-write relationships includes: The risk level of the interleaving of the threads under test is assessed based on the magnitude of the difference; the higher the risk level, the higher the test priority.
[0011] Optionally, the step of matching a pair of read / write operations according to read / write rules to construct a thread-interleaved read / write relationship includes: Identify each thread operation in the operating system component program, including read and write operations, and collect comprehensive information such as the corresponding thread identifier, accessed variables, and the location of the operation; Read and write rules are defined based on the nature of the operation, where a read operation refers to accessing a shared variable and reading its value, and a write operation refers to modifying the value of a shared variable. According to the read and write rules, each pair of read and write operations is matched. If a write operation occurs on a certain variable, subsequent read operations that access that variable constitute a pair of read and write operations. For each matched pair of read and write operations, record their relative order in the execution sequence to construct a thread-interleaved read and write relationship.
[0012] On the other hand, an operating system component concurrency defect detection device is provided, the device comprising: The program instrumentation module is used to instrument concurrent operations and synchronization primitives in operating system component programs and collect the execution sequence of multi-threaded instructions. An operation modeling module is used to model the execution sequence of the multi-threaded instructions as read or write operations; The read-write relationship module is used to match a pair of read-write operations according to read-write rules and construct a thread-interleaved read-write relationship. The relationship judgment module is used to determine whether the read-write relationships corresponding to the execution sequences of the multi-threaded instructions are equal, and to filter out equivalent thread interleaving. The equality of read-write relationships is used to determine whether the corresponding thread interleavings are equal. The risk assessment module is used to evaluate the test priority of thread interleaving based on read-write relationships, and prioritize testing thread interleaving with the highest risk level.
[0013] On the other hand, a computer-readable storage medium is provided, wherein a computer program is stored in the computer program, which is loaded and executed by a processor to implement the operating system component concurrent defect detection method as described above.
[0014] The method provided in this application collects the execution sequence of multi-threaded instructions by instrumenting concurrent operations and synchronization primitives in operating system component programs, and models the collected instructions as read or write operations. It constructs interleaved read-write relationships based on read-write rules, and filters out equivalent interleaved threads by determining whether the read-write relationships of different interleaved threads are equal. Furthermore, it evaluates the testing priority of the interleaved threads to be tested, prioritizing the testing of the interleaved threads with the highest risk level. Through this invention, it is possible to identify and filter equivalent interleaved threads, and evaluate test priority based on the differences in the read-write relationships of interleaved threads, thereby improving the efficiency of concurrent defect testing of operating system components, reducing redundant testing, and increasing defect detection coverage. Attached Figure Description
[0015] Figure 1 A flowchart of a method for detecting concurrency defects in operating system components is shown; Figure 2 The corresponding Figure 1 Execution flow diagram; Figure 3 This illustration shows an example of a test target. Figure 4 An example flowchart is shown. Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0017] In this article, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0018] Example 1 like Figure 1 As shown, a flowchart of a method for detecting concurrent defects in operating system components is provided, and... Figure 2 As a flowchart, the operating system component concurrency defect detection method includes the following.
[0019] Step 101: Instrument the concurrent operations and synchronization primitives of the operating system component program to collect the execution sequence of multi-threaded instructions.
[0020] In step 101, instrumentation is first performed on concurrent operations and synchronization primitives within the operating system component program. This operation, through dynamic analysis and code modification, inserts monitoring code during program execution to capture the execution information of each thread in the multithreaded program. This information includes the thread identifier, execution order, and related synchronization primitives. Instrumentation ensures that the execution path and synchronization operations of each thread are accurately recorded, providing fundamental data for subsequent analysis. The multithreaded instruction execution sequences collected through instrumentation provide a comprehensive understanding of the thread interleaving and execution details in concurrent programs, effectively reflecting the interactions between different threads in a multithreaded environment.
[0021] By instrumenting execution sequences, the system can efficiently and accurately capture the actual runtime conditions of multithreaded programs. This provides a realistic data foundation for subsequent read-write relationship modeling and thread interleaving analysis, avoiding dynamic changes that traditional static analysis methods cannot handle. Furthermore, the instrumentation process can identify hidden inter-thread interactions within concurrent programs, especially details of multithreaded synchronization, laying a solid foundation for detecting potential concurrency defects. Real-time monitoring of the program execution path ensures more comprehensive test coverage, preventing any potential thread interleaving from being overlooked.
[0022] In one example, instrumentation before and after concurrent operations and synchronization primitives gathers information about the instruction, including its thread identifier. The execution order within a thread and its instruction types These three pieces of information constitute an event. .
[0023] Step 102: Model the execution sequence of multi-threaded instructions as read or write operations.
[0024] In step 102, the collected multi-threaded instruction execution sequences are converted into read or write operations. This modeling step is crucial because it provides a higher level of abstraction for subsequent concurrency defect detection, simplifying complex execution sequences. Each instruction, by categorizing its operation type, accurately identifies each thread's access behavior to shared resources. A read operation represents a thread reading data from a shared variable, while a write operation represents a thread modifying a shared variable. By mapping all thread operations to read and write operations, the system can more clearly analyze the interactions between threads, thus laying the foundation for subsequent read-write relationship construction and concurrency defect localization.
[0025] Modeling execution sequences as read-write operations significantly simplifies the complexity of concurrency defect detection. This modeling not only improves the efficiency of concurrency operation analysis but also ensures that each thread's access to shared resources can be accurately tracked and managed. The modeled instruction sequences make subsequent analysis of thread interleaving and resource access more intuitive, aiding in the discovery of concurrency defects such as resource contention and data contention. Furthermore, by abstracting them into read-write operations, potential errors can be identified more efficiently during testing, thereby improving detection accuracy and coverage.
[0026] Step 103: Match a pair of read and write operations according to the read and write rules to construct a thread-interleaved read and write relationship.
[0027] In step 103, the system matches read and write operations according to predefined read and write rules and constructs interleaved read and write relationships. Read and write rules define the relationships between read and write operations, helping the system identify which operations have dependencies. When a write operation modifies the value of a shared variable, and a subsequent read operation accesses that variable, a read-write pair is formed. These dependencies directly affect the correctness and stability of the program. By systematically analyzing and matching these operations and constructing interleaved read and write relationships, key data can be provided for further defect detection, helping to identify the order of operations that may lead to concurrency problems such as deadlock and data races.
[0028] By matching and constructing relationships between read and write operations, the interactions between threads and their impact on shared resources can be accurately described, thereby effectively identifying potential concurrency defects. This process allows testing to focus more on thread operations with dependencies, avoiding redundant testing of irrelevant operations. By constructing interleaved read-write relationships between threads, potential resource conflicts, access sequence errors, and other problems in the program can be identified more efficiently. Implementing this step significantly improves the accuracy and efficiency of concurrency defect detection, enabling the discovery of more concurrency defects with fewer testing steps.
[0029] Step 104: Determine whether the read-write relationships corresponding to the execution sequences of multi-threaded instructions are equal, and filter out equivalent thread interleaving. The equality of read-write relationships is used to determine whether the corresponding thread interleavings are equal.
[0030] In step 104, the system determines whether the read-write relationships corresponding to the execution sequences of multi-threaded instructions are equal and filters out equivalent thread interleaving. Different thread interleavings may produce the same read-write relationships, meaning there is no difference in execution results; such interleavings are unnecessary in actual testing. Through this determination, the system can identify which thread interleavings are equivalent, thereby avoiding repeated testing of these interleavings. Determining equivalence relationships can effectively reduce the test space, thereby improving testing efficiency and allowing test resources to be focused on interleavings that may lead to different execution results. This process helps eliminate redundant testing, saving time and computing resources.
[0031] By filtering equivalent thread interleaving, the system can improve testing efficiency and reduce unnecessary test operations in large-scale concurrent testing. This optimization not only accelerates defect localization but also avoids wasting time and resources due to repeated testing of interleaving with identical results. Furthermore, filtering equivalent interleaving helps the detection system focus more on important test scenarios, enabling the testing process to discover potential concurrent defects more quickly. In this way, the testing process becomes more granular and can cover higher-risk thread interleaving.
[0032] Step 105: Evaluate the test priority of thread interleaving based on read-write relationships, and prioritize testing thread interleaving with the highest risk level.
[0033] In step 105, the testing priority of thread interleaving is evaluated based on read-write relationships, and the thread interleaving with the highest risk level is tested first. This evaluation process calculates the risk level of each thread interleaving based on the differences in read-write relationships between them. A higher risk level indicates a greater likelihood of triggering concurrency defects, and the system should prioritize testing it. This risk-priority testing strategy allows for faster triggering of potential defects, reduces testing time, and improves defect detection efficiency. The risk level is typically calculated based on the differences between thread interleavings; the greater the difference, the higher the risk level.
[0034] A risk-priority testing strategy makes the testing process more efficient, especially for thread interleaving that may cause concurrency defects. This strategy assesses risk levels based on differences in read-write relationships, ensuring that high-risk interleaving is tested first, thus improving defect discovery efficiency. Compared to traditional random testing methods, this approach can discover concurrency defects faster and more accurately, significantly reducing redundant testing steps and improving test coverage and accuracy. In this way, the system can detect the most concurrency defects in the shortest time, thereby improving the reliability and stability of operating system components.
[0035] Therefore, this application embodiment collects the execution sequence of multi-threaded instructions by instrumenting concurrent operations and synchronization primitives in operating system component programs, and models the collected instructions as read or write operations. Based on read-write rules, interleaved read-write relationships are constructed, and equivalent interleaved threads are filtered out by determining whether the read-write relationships of different interleaved threads are equal. Furthermore, the testing priority of the interleaved threads to be tested is evaluated, prioritizing the testing of the interleaved threads with the highest risk level. Through this invention, the identification and filtering of equivalent interleaved threads can be achieved, and the testing priority can be evaluated based on the differences in the read-write relationships of interleaved threads, thereby improving the efficiency of concurrent defect testing of operating system components, reducing redundant testing, and increasing defect detection coverage.
[0036] Example 2 Furthermore, the process of inserting the stake in step 101 includes the following:
[0037] S11 traverses the source code files of operating system component programs and generates the corresponding abstract syntax tree.
[0038] In step S11, the system first traverses the source code files of the operating system component programs and generates corresponding Abstract Syntax Trees (ASTs). An Abstract Syntax Tree is a tree-structured representation of the program's source code, capable of efficiently capturing the program's syntactic structure. Through this method, the system can understand the program's control flow, data flow, and the relationships between various syntactic elements. The process of generating the Abstract Syntax Tree is fundamental to instrumentation, as it allows subsequent instrumentation to precisely locate the relevant parts of the program involving multithreaded operations. By parsing the source code, comprehensive structural information of the program can be obtained, preparing for the subsequent insertion of monitoring code.
[0039] By traversing the source code and generating an abstract syntax tree (AST), the system can effectively abstract the logical structure of the program, rather than just the source code text. This makes subsequent instrumentation operations more efficient and accurate. The AST provides an intuitive view, enabling the system to identify and locate concurrent operations and synchronization primitives in the program. After generating the AST, the system can quickly identify the code locations that need instrumentation, avoiding the tedious process of manually analyzing the source code and significantly improving the automation and accuracy of the instrumentation process. Furthermore, the structured information generated by the AST ensures that the system does not miss important operations when processing complex multithreaded programs, ensuring comprehensive defect detection.
[0040] S12, traverse the abstract syntax tree, instrument multi-threaded concurrent operations and synchronization primitives in the abstract syntax tree, and collect event content, which includes the execution sequence of multi-threaded instructions.
[0041] Then, a specific thread interleaving t is taken as input. By parsing the content of all events within it, read-write relationships are matched, and finally, the read-write relationships corresponding to the thread interleaving are obtained. Step S12 involves locating the positions of multithreaded concurrent operations and synchronization primitives in the abstract syntax tree and then instrumenting them at these positions. The purpose of instrumentation is to dynamically collect information about thread operations during program runtime, especially the execution sequence of multithreaded instructions. By inserting monitoring code at concurrent operations and synchronization primitives, the system can collect event content, such as the execution order of threads and the triggering status of synchronization primitives. This process ensures that every concurrent action of the program can be accurately recorded, providing key information for subsequent read-write relationship construction. In this way, the system can capture the program's execution trajectory at runtime, ensuring that the collected thread interleaving data is completely consistent with the actual execution.
[0042] The instrumentation process ensures that the concurrent operations and synchronization behaviors of each thread can be monitored in real time and event data can be collected. This process enables testing to be conducted in a real-world environment, accurately capturing interactions and competition between threads. By precisely inserting monitoring code into the abstract syntax tree, the system can seamlessly collect the execution sequence of multi-threaded instructions and ensure the completeness of the collected data. This not only improves the accuracy of defect detection but also effectively reduces concurrent behaviors that traditional static analysis methods may miss, thereby enhancing the coverage of concurrency defect detection.
[0043] Example 3 Furthermore, step 103 includes the following:
[0044] S31 identifies each thread operation in the operating system component program, including read and write operations, and collects comprehensive information such as the corresponding thread identifier, accessed variables, and the location of the operation.
[0045] Step S31 requires identifying each thread operation within the operating system component program and collecting information such as thread identifiers, accessed variables, and operation locations. The core of this step is identifying and recording each operation performed by a thread, especially its access to shared resources. By identifying each thread's operations, the system can gain a detailed understanding of how each thread reads and writes resources, which is crucial for subsequent thread interleaving analysis. Collecting information on thread identifiers and accessed variables allows the system to track the relationships between concurrent operations, thus providing key information for subsequently constructing read-write relationships.
[0046] By identifying each thread's operation and collecting relevant information, the system can gain a comprehensive understanding of the execution of each thread in the program, especially how they access shared variables. By collecting information such as thread identifiers, accessed variables, and operation locations, the system can not only accurately analyze the behavior of each thread but also clearly display the dependencies between threads. This step helps the system better understand the interaction methods of different threads in concurrent programs, ensuring that defect detection can cover the impact of each thread on resources and providing more comprehensive concurrency defect testing.
[0047] In one example, an event An event represents a concurrent operation of a program. It is an initialization operation. or thread operations , Represents the thread identifier. These are specific concurrent operation instructions, which can be further... There are two main scenarios: (1) Read operation: , The variable accessed by this operation. This refers to the location of the operation; (2) Write operation: , The variable accessed by this operation. This refers to the location of the operation; After instrumentation is completed, during actual program testing, the actual multi-threaded instruction execution sequence will be collected according to the program's actual execution path, i.e., the exact thread interleaving. .
[0048] Representing a precise thread interleaving using a finite sequence : , where i < j exist This happened before.
[0049] S32, define read and write rules according to the nature of the operation, where a read operation refers to accessing a shared variable and reading its value, and a write operation refers to modifying the value of a shared variable.
[0050] The key to step S32 is defining read and write rules in the operating system component program based on the nature of the operations. A read operation refers to accessing a shared variable and retrieving its value into the current thread; a write operation refers to modifying the value of a shared variable. In a multithreaded environment, read and write operations on shared resources between threads can lead to concurrency issues, therefore, clearly distinguishing between read and write operations is essential. By defining clear read and write rules, the system can accurately identify which operations will cause conflicts between threads, laying the foundation for subsequent read-write relationship matching and defect detection.
[0051] By defining read / write rules, the system can more accurately identify dependencies and potential conflicts between threads. These rules help the system differentiate between different types of operations and ensure that only read / write actions involving shared variables are given priority. The introduction of these rules makes the analysis of interleaved threads more systematic and standardized, thereby reducing the risk of misjudgments and omissions. Through precise read / write rules, the testing process can more effectively locate operations that may cause concurrency defects, improving the accuracy and efficiency of defect detection.
[0052] S33, according to the read and write rules, match each pair of read and write operations. If a write operation occurs on a certain variable, the subsequent read operation that accesses that variable constitutes a pair of read and write operations.
[0053] In step S33, the system matches each pair of read-write operations according to the previously defined read-write rules. Specifically, if a thread's write operation modifies the value of a shared variable, and subsequently another thread's read operation accesses that variable, a read-write pair is formed. This matching process is crucial for discovering potential concurrency defects because many concurrency problems, especially data race problems, often occur between write operations and subsequent read operations. By accurately matching these operations, the system can identify thread interleaving that may cause errors, thus providing a basis for subsequent defect detection.
[0054] In one example, the inter-thread event read / write relationship (e W ,e R ), indicating e W →e R That is, writing events The event of reading the result of the assignment operation on the variable. access; Thread interleaving The corresponding read / write relationship : .
[0055] The rules for matching read-write relationships include: Establish lock read-write relationships. Interleave collection threads. The system maintains a global operation sequence for each lock, while also keeping track of the latest write operation for that lock using a variable. For each read operation on a lock, it is matched against the latest write operation to indicate the order in which the lock was acquired. When constructing channel read / write relationships, collect the global write sequence and global read sequence for each channel, and then match them into read / write relationships corresponding to the read / write sequences in a FIFO manner.
[0056] By matching read and write operations, the system can effectively identify resource access dependencies between threads, especially interactions that may cause concurrency defects. This step helps the system identify potential conflict points in thread operations and provides concrete evidence for subsequent defect analysis. Through this matching method, testing can focus on potentially problematic thread interleaving, thereby improving testing efficiency and accuracy and avoiding ineffective testing of irrelevant operations.
[0057] S34. For each pair of read and write operations that are matched, record their relative order in the execution sequence to construct a thread-interleaved read and write relationship.
[0058] In step S34, the system records the relative order of each matched pair of read / write operations in the execution sequence and constructs an interleaved read / write relationship. This process determines the dependencies between operations by analyzing the execution order of the threads. By recording the relative order of these operations, the system can construct a complete interleaved read / write relationship, which is crucial for revealing dependencies and potential problems between threads. Constructing read / write relationships not only helps the system clarify the dependencies between operations but also provides more detailed data support for subsequent defect detection.
[0059] By recording the relative order of read and write operations and constructing read-write relationships, the system can accurately describe the dependencies between various operations in thread interleaving, revealing the order of operations that may cause concurrency defects. This step makes concurrency defect detection more refined, enabling precise location of specific operational interactions, rather than simply relying on the execution sequence of thread interleaving. By constructing clear read-write relationships, the system can better predict and discover potential concurrency defects, thereby improving the accuracy and efficiency of defect detection.
[0060] Example 4 Furthermore, step 105 includes the following:
[0061] S51, calculate the difference in read / write relationships between the interleaved set of threads to be tested and the interleaved set of threads already tested.
[0062] The goal of step S51 is to calculate the differences in read-write relationships between the interleaved threads under test and the set of interleaved threads already tested. To effectively detect potential concurrency defects, it is essential to compare the differences between the interleaved threads under test and all the interleaved threads already tested. By calculating the differences in read-write relationships for each interleaved thread, the system can quantify the differences between the interleaved threads under test and the interleaved threads already tested. This difference calculation, based on the relationships between read and write operations, helps identify aspects of the interleaved threads that may cause concurrency issues. This process is an indispensable part of dynamic testing because it provides an intuitive measure of difference, facilitating subsequent risk assessment and prioritization.
[0063] By calculating the differences in read-write relationships between the interleaved threads under test and the set of interleaved threads already tested, the system can effectively identify interleaved threads that are significantly different from known interleaved threads. This differential calculation ensures that testing is no longer targeted at the same or similar interleaved threads, thus avoiding redundant testing. In this way, the system can focus its resources on novel or potentially dangerous interleaved threads in a shorter time, improving testing efficiency and targeting while avoiding repetitive work. This makes defect detection more efficient and enables the discovery of hidden concurrency defects in a wider variety of interleaved scenarios.
[0064] S511, obtain the read / write relationship between the interleaved set of threads to be tested and the interleaved set of threads already tested.
[0065] Step S511 first requires obtaining the read-write relationships of the interleaved sets of threads to be tested and the interleaved sets of tested threads. The read-write relationship of each thread interleaving is determined by the order of its operations and the shared resources accessed. The system constructs a set of read-write relationships by analyzing the read and write operations in each thread interleaving. These relationships not only include the matching of read and write operations, but also involve synchronization primitive operations between different threads. By obtaining these relationships, the system provides the basic data for subsequent difference calculations. Ensuring a comprehensive collection of the read-write relationships for each interleaving helps to accurately assess the concurrency issues that each interleaving may cause.
[0066] Obtaining the read-write relationships of the interleaved threads under test and the set of interleaved threads already tested is a fundamental step to ensure targeted subsequent testing. By establishing complete read-write relationships, the system can gain a deeper understanding of the operation sequence and resource access in different thread interleavings. This method effectively avoids redundant testing of similar or known interleavings, saving time and computational resources. Furthermore, by uniformly managing the read-write relationships of all thread interleavings, the system can more accurately determine which interleavings have potential concurrency defects, thereby improving the coverage and accuracy of defect detection.
[0067] S512, calculate the difference between the interleaved read-write relationship of the thread under test and the interleaved read-write relationship of each of the interleaved threads in the interleaved set of tested threads.
[0068] Step S512 requires the system to calculate the difference between the read-write relationship of the thread under test interleaving and the read-write relationship of each interleaved thread in the tested thread interleaving set. This process is one of the key steps in defect detection. The goal of calculating the difference is to reveal the differences between the interleaving under test and known interleavings, especially in terms of resource contention and access order. Through this comparison, the system can quantify the differences in the relationship between each pair of interleavings, thus providing a basis for subsequent risk assessment and prioritization. The process of calculating the difference helps to accurately determine the dependencies and potential problems between the interleaving under test and the tested interleavings.
[0069] In one example, thread interleaving t i and Differences in read-write relationships: .
[0070] However, simply calculating the difference between two thread interleavings does not reflect the difference between the thread interleaving under test and all previously tested thread interleavings. Therefore, based on the definition of difference above, the thread interleaving under test can be... Interleaved set with tested threads Difference defined as and Each element in The minimum value of the difference.
[0071] Thread interleaving t i Interleaved set with tested threads Differences between them: .
[0072] As can be seen from this definition, the above calculation formula yields a thread interleaving result. Interleaved set with a thread Each element The maximum lower bound difference. Using the above definition, we can use the tested thread interleaving read-write relationships as a benchmark, evaluate the differences between all thread interleavings to be tested and the benchmark, and use these differences as the testing priorities. Each time a thread interleaving to be tested is selected, a greedy strategy is adopted, selecting the thread interleaving with the highest priority (largest difference) for testing, assuming this will trigger concurrency defects faster.
[0073] By calculating the differences in read-write relationships between the interleaved threads under test and the already tested interleaved thread sets, the system can clearly identify which interleavings have new risk characteristics and which are similar to known interleavings, thus skipping unnecessary duplicate tests. The difference calculation provides the system with a quantitative standard, allowing for the prioritization of higher-risk thread interleavings, improving testing efficiency and effectiveness. Furthermore, the difference calculation can reveal subtle concurrency defects that are often difficult to detect in traditional testing, effectively improving the accuracy of defect detection.
[0074] S513: For each read-write relationship where the thread to be tested is interleaved with the thread already tested, calculate the minimum difference in the read-write relationship.
[0075] In step S513, the system calculates the minimum difference between the read / write relationships of each interleaved thread and the interleaved threads already tested. This process simplifies the difference measurement between each pair of interleavings by minimizing computation, avoiding lengthy and complex calculations. The minimum difference means that the system can select thread interleavings with the smallest differences but higher potential risks for testing, reducing the number of tests while ensuring that the new interleavings can adequately cover problems that the original interleavings failed to detect. Minimum difference calculation helps to extract high-priority test objectives.
[0076] By calculating the minimum difference, the system can effectively assess the minimum variation between the interleaving to be tested and the interleaving already tested, and prioritize testing interleavings with larger differences or higher potential risks. This method significantly improves testing efficiency and accuracy, ensuring that testing resources are focused on thread interleavings most likely to reveal defects. By minimizing the difference calculation, the number of redundant tests can be reduced, ensuring that tests cover more thread interleavings that may trigger concurrency defects, while also avoiding unnecessary duplicate testing.
[0077] S514, merge the differences in read / write relationships between all interleaved threads to be tested and the interleaved set of tested threads to obtain the overall difference between the interleaved threads to be tested and the interleaved set of tested threads.
[0078] In step S514, the system merges the read-write relationship differences between all interleaved threads to be tested and the set of interleaved threads already tested, obtaining an overall difference value. This merging operation comprehensively calculates the differences between different interleavings, thus obtaining a comprehensive difference metric. This overall difference metric helps to evaluate the relationship between the interleaving to be tested and known interleavings from a global perspective, thereby supporting subsequent priority allocation and defect risk assessment. By merging differences, the system can perform a more systematic analysis of the entire test space, ensuring the comprehensiveness and efficiency of the defect detection process.
[0079] By merging all discrepancies, the system obtains a comprehensive overall discrepancy value, making test priority assessment more accurate. The process of merging discrepancies effectively integrates the complexity of multi-threaded interleaving, ensuring the rationality of test priorities. By calculating the overall discrepancy, the system can optimize resource allocation, focusing efforts on testing the interleaving with the largest discrepancies and the highest potential defect risk, thereby improving testing efficiency, shortening the detection cycle, and ensuring that defects are discovered and fixed as early as possible.
[0080] S52 assesses the risk level of thread interleaving by comparing read-write relationship differences.
[0081] The risk assessment in step S52 is based on the differences in read-write relationships between the interleaved threads under test. The system calculates these differences and converts them into risk levels. This process ensures that the potential risks of each interleaved thread under test are reasonably assessed and prioritized based on the magnitude of the differences. Risk assessment is a crucial step in defect detection, providing guidance for subsequent testing strategies. Through this process, the system can prioritize testing interleaved threads with higher risks, thereby improving testing efficiency.
[0082] By assessing the risks associated with differences in read-write relationships, the system can efficiently identify thread interleaving most likely to cause concurrency defects. Risk level assessment allows for more precise testing, avoiding blind testing. By evaluating the differences between interleavings, the system can focus resources on high-risk testing targets, ensuring that limited testing time and resources are used to their maximum effectiveness. This assessment method significantly improves the efficiency of defect detection, enabling concurrency defects to be discovered and fixed more quickly.
[0083] S53 assesses the risk level of thread interleaving based on the magnitude of the difference; the higher the risk level, the higher the test priority.
[0084] In step S53, the system assesses the risk level based on the difference between the interleaved threads to be tested and the interleaved threads already tested. A larger difference indicates a greater difference in execution results between the interleaved threads to be tested and the already tested interleaved threads, thus suggesting a higher potential risk of defects. By correlating the difference with the risk level, the system can prioritize testing interleaved threads with larger differences from multiple interleaved threads to be tested. This process is performed through difference measurement, making the testing strategy more reasonable and systematic.
[0085] By assessing risk levels based on the magnitude of differences, the system can precisely focus on testing the most risky threads in an interleaved manner, thereby improving the efficiency of discovering concurrency defects. Through reasonable risk prioritization, testing becomes more focused, avoiding redundant testing of known low-risk interleaving threads and significantly saving time and resources. This risk assessment based on the magnitude of differences makes the testing process more intelligent, quickly identifying potential concurrency defects and ensuring high efficiency and quality in testing.
[0086] S54, assign corresponding test priorities to the threads to be tested based on the risk level; In step S54, the system assigns test priorities to the thread interleaving under test based on the assessed risk level. The higher the risk level of the thread interleaving, the higher the test priority. This priority allocation mechanism allows testing to focus first on interleavings most likely to cause concurrency defects, thereby improving testing efficiency and accuracy. By prioritizing based on risk level, the system can optimize the allocation of test resources according to the actual risk situation, ensuring that the most critical test objectives are addressed first.
[0087] By prioritizing tests based on risk levels, the system can efficiently detect defects, ensuring that resources are concentrated on potentially high-risk, overlapping tasks. This prioritization mechanism makes testing more intelligent and effectively addresses the challenges posed by the complexity of multithreaded programs. Through precise priority management, testing efficiency and accuracy are significantly improved, enabling the detection of concurrent defects in a shorter time.
[0088] S55 prioritizes testing thread interleaving, which has the highest risk level.
[0089] In step S55, the system prioritizes testing thread interleaving with the highest risk level based on the risk level assessed in the previous step. Through the preceding risk assessment, the system has sorted all thread interleaving to be tested by risk level; thread interleaving with higher risk levels carries a greater potential for defects. Therefore, the system will concentrate testing resources on the interleaving with the highest risk level, ensuring that the interleaving most likely to cause concurrency issues is addressed first. The goal of this strategy is to improve the effectiveness and relevance of testing, reduce unnecessary redundant testing, and expose concurrency defects as quickly as possible.
[0090] By prioritizing the testing of thread interleaving with the highest risk level, the testing process can more quickly identify and fix potential concurrency defects, especially those that could cause serious problems in real-world applications. This prioritization strategy optimizes the allocation of testing resources, avoiding wasting significant testing time on low-risk interleavings. This method ensures that high-risk interleavings are verified first, thereby improving the efficiency and accuracy of defect detection and further enhancing the overall effectiveness and coverage of the testing process.
[0091] On the other hand, an operating system component concurrency defect detection device is also provided, the device comprising: The program instrumentation module is used to instrument concurrent operations and synchronization primitives in operating system component programs and collect the execution sequence of multi-threaded instructions. The operation modeling module is used to model the execution sequence of multi-threaded instructions as read or write operations; The read-write relationship module is used to match a pair of read-write operations according to read-write rules and construct a thread-interleaved read-write relationship. The relationship judgment module is used to determine whether the read-write relationships corresponding to the execution sequences of multi-threaded instructions are equal, and to filter out equivalent thread interleaving. The equality of read-write relationships is used to determine whether the corresponding thread interleavings are equal. The risk assessment module is used to evaluate the test priority of thread interleaving based on read-write relationships, and prioritize testing thread interleaving with the highest risk level.
[0092] On the other hand, a computer-readable storage medium is also provided, in which a computer program is stored, which is loaded and executed by a processor to implement the operating system component concurrent defect detection method as described above.
[0093] On the other hand, this invention does not have specific requirements for hardware resources. Figure 3The example shown is from the Kubernetes operating system component deadlock code. This code has three threads (G1, G2, and G3) executing 10 statements. To facilitate the representation of thread interleaving, each statement is identified by a number. Figure 3 The method will be described in detail using code as an example, and the process is as follows: Figure 4 As shown, the implementation content and steps are as follows.
[0094] Read / write relationship building module.
[0095] 1) Instrument concurrent operations and synchronization primitives in multi-threaded environments to collect event content; 2) Initially test the source code, and collect the exact thread interleaving of the initial test through instrumentation. ; 3) Identify exact thread interleaving The event content is matched with the read / write relationship to obtain... ; 4) Determine if the read-write relationship exists in the set of tested read-write relationships. If it exists, there is no need to save it again; otherwise, save it. 5) Generate new test threads and interleave them. , and t3; 6) Calculate the interleaved read-write relationships of the threads under test, and filter out the interleaved read-write relationships of the threads under test that are included in the set of already tested read-write relationships. To obtain a new read-write relationship and ; Read / write relationship difference calculation module.
[0096] 1) Calculate the difference between all read-write relationships to be tested and the set of already tested read-write relationships; 2) Assign test priorities to the corresponding threads to be tested in an interleaved manner based on the magnitude of the differences; 3) The difference between t1 and t3 is greater, and its corresponding priority is also higher, so it is selected first. Thread interleaving will be used for the next test.
[0097] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0098] 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-readable storage medium, such as a read-only memory, a disk, or an optical disk. The above descriptions are merely optional embodiments of this application and are not intended to limit the application. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for detecting concurrency defects in operating system components, characterized in that, The method includes: Instrument concurrent operations and synchronization primitives in operating system component programs to collect the execution sequence of multi-threaded instructions; The execution sequence of the multi-threaded instructions is modeled as a read operation or a write operation; Based on the read and write rules, a pair of read and write operations is matched to construct a thread-interleaved read and write relationship; Determine whether the read-write relationships corresponding to the execution sequences of the multi-threaded instructions are equal, and filter out equivalent thread interleaving. The equality of read-write relationships is used to determine whether the corresponding thread interleavings are equal. The test priority of thread interleaving is evaluated based on the read-write relationship, and the thread interleaving with the highest risk level is tested first. The step of evaluating the test priority of thread interleaving under test based on read-write relationships and prioritizing the testing of thread interleaving with the highest risk level includes: calculating the difference in read-write relationships between the thread interleaving under test and the set of thread interleaving already tested; evaluating the risk level of the thread interleaving under test based on the difference in read-write relationships; assigning a corresponding test priority to the thread interleaving under test based on the risk level; and prioritizing the testing of the thread interleaving with the highest risk level. The step of matching a pair of read-write operations according to read-write rules to construct a thread-interleaved read-write relationship includes: identifying each thread operation in the operating system component program, including read operations and write operations, and collecting comprehensive information such as the corresponding thread identifier, the accessed variable, and the location of the operation; defining read-write rules according to the nature of the operation, wherein a read operation refers to accessing a shared variable and reading its value, and a write operation refers to modifying the value of a shared variable; matching each pair of read-write operations according to the read-write rules, wherein if a write operation occurs on a certain variable, a subsequent read operation accessing that variable constitutes a pair of read-write operations; and for each matched pair of read-write operations, recording their relative order in the execution sequence to construct a thread-interleaved read-write relationship.
2. The method according to claim 1, characterized in that, The process of driving the stakes includes: Traverse the source code files of operating system component programs to generate the corresponding abstract syntax tree; Traverse the abstract syntax tree, instrument multi-threaded concurrent operations and synchronization primitives in the abstract syntax tree, and collect event content, which includes the execution sequence of collected multi-threaded instructions.
3. The method according to claim 1, characterized in that, The calculation of the difference in read-write relationships between the interleaved set of threads to be tested and the interleaved set of threads already tested includes: Obtain the read / write relationship between the interleaved set of threads to be tested and the interleaved set of threads already tested; Calculate the difference between the read-write relationship of the thread under test and the read-write relationship of each thread under test in the set of thread under test; For each read-write relationship where the thread to be tested and the thread already tested are interleaved, calculate the minimum difference in the read-write relationship. The differences in read / write relationships between all interleaved threads under test and the interleaved set of tested threads are merged to obtain the overall difference between the interleaved sets of tested threads and the interleaved set of tested threads.
4. The method according to claim 3, characterized in that, The method of assessing the risk level of thread interleaving under test based on the differences in read-write relationships includes: The risk level of the interleaving of the threads under test is assessed based on the magnitude of the difference; the higher the risk level, the higher the test priority.
5. A device for detecting concurrent defects in operating system components, characterized in that, The device includes: The program instrumentation module is used to instrument concurrent operations and synchronization primitives in operating system component programs and collect the execution sequence of multi-threaded instructions. An operation modeling module is used to model the execution sequence of the multi-threaded instructions as read or write operations; The read-write relationship module is used to match a pair of read-write operations according to read-write rules to construct a thread-interleaved read-write relationship. This module is also used to: identify each thread operation in the operating system component program, including read and write operations, and collect comprehensive information such as the corresponding thread identifier, accessed variables, and the location of the operation; define read-write rules according to the nature of the operation, where a read operation refers to accessing a shared variable and reading its value, and a write operation refers to modifying the value of a shared variable; match each pair of read-write operations according to the read-write rules, where if a write operation occurs on a variable, subsequent read operations accessing that variable constitute a read-write pair; and record the relative order of each matched pair of read-write operations in the execution sequence to construct a thread-interleaved read-write relationship. The relationship judgment module is used to determine whether the read-write relationships corresponding to the execution sequences of the multi-threaded instructions are equal, and to filter out equivalent thread interleaving. The equality of read-write relationships is used to determine whether the corresponding thread interleavings are equal. The risk assessment module is used to evaluate the test priority of the thread interleaving under test based on the read-write relationship, and to prioritize testing the thread interleaving with the highest risk level. The risk assessment module is also used to: calculate the difference in read-write relationship between the thread interleaving under test and the set of thread interleavings that have been tested; evaluate the risk level of the thread interleaving under test based on the difference in read-write relationship; assign a corresponding test priority to the thread interleaving under test based on the risk level; and prioritize testing the thread interleaving with the highest risk level.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which is loaded and executed by a processor to implement the operating system component concurrency defect detection method as described in any one of claims 1 to 4.