Code influence domain analysis method and device based on variable propagation
By generating an abstract syntax tree, compiling it into LLVM bytecode, and generating fine-grained control flow graphs and alias graphs, combined with variable propagation derivation, the problems of poor analysis accuracy and low efficiency in existing technologies are solved, and high-precision regression testing is achieved.
Patent Information
- Application Number
- CN202611324180.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies lack in-depth analysis of the actual semantics of code modifications in regression testing, and cannot distinguish between non-substantial formatting adjustments and substantial underlying logic modifications, resulting in poor analysis accuracy and low efficiency.
By generating abstract syntax trees before and after the target software update, performing normalization reduction operations to identify substantially changed nodes, compiling them into LLVM intermediate layer bytecode, generating fine-grained control flow graphs and alias graphs, and combining variable propagation derivation operations to generate statement-level influence domain networks.
It improves the accuracy of influence domain analysis, avoids the path explosion problem, and significantly enhances regression testing efficiency and defect detection speed.
Smart Images

Figure CN123178264A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of regression testing technology, and in particular to a code influence domain analysis method and apparatus based on variable propagation. Background Technology
[0002] In the software development and maintenance lifecycle, regression testing is a crucial step in ensuring that code modifications do not introduce new defects. Currently, targeted testing and impact domain analysis are primarily implemented using the following methods: Existing technology 1: Chianti (coarse-grained code change impact analysis tool) This technology identifies the changed methods by comparing two versions of the program and infers other methods that may be affected by these changes based on a coarse-grained call graph. Disadvantages: This tool's analysis granularity remains at the "function / method level," lacking a detailed depiction of the underlying data flow. When dealing with complex software, the inability to delve into the instruction or statement level to track the actual propagation of variables leads to an extreme amplification of the influence domain, resulting in numerous false positives in subsequent testing and poor analysis accuracy.
[0003] Existing technology 2: Influence domain analysis based on static slices This technical solution utilizes traditional data dependency graphs and control dependency graphs to identify the set of statements that may be affected by code changes through forward or backward static program slicing.
[0004] Disadvantages: When dealing with large-scale, complex software containing numerous multi-level pointers, references, and complex nested structures, traditional static slicing techniques lack rigorous, flow-sensitive, and context-sensitive underlying extensions for alias analysis. This results in tools being unable to accurately trace complex indirect pointer calls, easily leading to path explosion problems due to over-generalization of aliases, and slow analysis speed.
[0005] Existing technology 3: Jripples (a text comparison-based change propagation tracking tool) This tool uses text comparison to track code dependencies in order to analyze the propagation effect of changes.
[0006] Disadvantages: When identifying changes, these tools typically rely on basic text or structural comparisons without performing deep reduction of the Abstract Syntax Tree (AST). Therefore, they cannot distinguish between "non-substantive changes" such as variable renaming for readability improvements, statement reordering for performance enhancements, and injected redundant dead code. This sensitivity to pseudo-changes leads to numerous false positives, incorrectly including irrelevant logic in the affected domain. Summary of the Invention This application provides a code influence domain analysis method and apparatus based on variable propagation to solve the problems of existing technologies that focus on using distance calculation to find the shortest path, which is extremely time-consuming to discover target defects, lacks in-depth analysis of the actual semantics of code modifications, and cannot distinguish between non-substantial format adjustments and substantial underlying logic modifications.
[0007] The first aspect of this application provides a code influence domain analysis method based on variable propagation, comprising the following steps: generating an abstract syntax tree corresponding to the source code before and after the target software update, and performing a preset normalization reduction operation on the abstract syntax tree to obtain the corresponding reduction result, and identifying substantial change nodes in the local logic of the code based on the reduction result; compiling the target code repository into LLVM intermediate layer bytecode, and traversing all modules in the target code repository to extract the corresponding complete instruction flow, and generating a fine-grained inter-process control flow graph covering the target code repository according to the complete instruction flow and preset function call relationships, and performing a preset alias analysis operation on the LLVM intermediate layer bytecode based on the control flow graph to generate a corresponding target alias graph; determining the corresponding seed diffusion point according to the substantial change node, and performing inter-process and inter-module variable propagation derivation operation based on the seed diffusion point, the control flow graph, and the target alias graph, and in combination with multiple core rules, to generate a corresponding statement-level influence domain network.
[0008] Optionally, in one embodiment of this application, generating an abstract syntax tree (AST) corresponding to the source code before and after the target software update, performing a preset normalization reduction operation on the AST to obtain a corresponding reduction result, and identifying substantial change nodes in the local logic of the code based on the reduction result, includes: generating an AST that satisfies preset hierarchical relationship requirements for the source code before and after the target software update using a preset compiler front-end, performing active variable analysis on the AST using a preset depth-first traversal strategy, and deleting the at least one first target subtree if the assignment in at least one first target subtree is not referenced in subsequent paths and does not involve modification of the global state or side effects of function calls. The tree is used to obtain a reduced abstract syntax tree (API). The API is traversed from bottom to top, and at least one second target subtree of the operation nodes and control flow that satisfy the commutative law is obtained. Based on a preset operator-specific order relationship and variable lexicographical order, the positions of the at least one second target subtree are swapped to obtain a standard abstract syntax tree. The API corresponding to the source code before and after the target software update is compared to obtain the corresponding comparison results. Based on the comparison results and a preset dynamic heuristic variable mapping table, the renamed variables in the standard abstract syntax tree that do not change the context structure are normalized to obtain differentiated subtrees that cannot be matched with each other. The substantial change nodes are determined according to the differentiated subtrees.
[0009] Optionally, in one embodiment of this application, generating a fine-grained interprocedural control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships includes: when directly calling a function in the complete instruction flow, adding a direct call edge between the caller and the callee node; and when indirectly calling a function in the complete instruction flow, inferring all possible targets of the function pointer based on a preset pointer pointing analysis algorithm, and supplementing the call graph and the control flow graph with indirect call edges and return edges to generate the control flow graph.
[0010] Optionally, in one embodiment of this application, the step of performing a preset alias analysis operation on the LLVM intermediate layer bytecode based on the control flow graph to generate a corresponding target alias graph includes: performing flow-sensitive and context-sensitive alias analysis on the LLVM intermediate layer bytecode based on the control flow graph, and dynamically updating the topology of the alias graph through multiple types of core low-level instructions during the alias analysis execution to generate the target alias graph. The multiple types of core low-level instructions include assignment instructions, memory write instructions, read instructions, and structure offset calculation instructions, and the variables represented by all access paths reaching the same node in the target alias graph are aliases to each other.
[0011] Optionally, in one embodiment of this application, the step of determining the corresponding seed diffusion point based on the substantial change node, and performing inter-process and inter-module variable propagation derivation operations based on the seed diffusion point, the control flow graph, and the target alias graph, and in combination with multiple core rules, to generate the corresponding statement-level influence domain network, includes: performing variable propagation derivation operations based on the seed diffusion point, the control flow graph, and the target alias graph to obtain at least one target variable of all the multiple core rules and the underlying instruction corresponding to the at least one target variable, and packaging the at least one target variable and the underlying instruction to generate the statement-level influence domain network, and performing regression test redundant test case elimination and priority scheduling operations based on the statement-level influence domain network.
[0012] A second aspect of this application provides a code influence domain analysis device based on variable propagation, comprising: a reduction module, used to generate an abstract syntax tree corresponding to the source code before and after the target software update, and perform a preset normalization reduction operation on the abstract syntax tree to obtain a corresponding reduction result, and based on the reduction result, identify substantial change nodes of local logic in the code; an alias analysis module, used to compile the target code repository into LLVM intermediate layer bytecode, and traverse all modules in the target code repository to extract the corresponding complete instruction flow, and generate a fine-grained inter-process control flow graph covering the target code repository according to the complete instruction flow and a preset function call relationship, and perform a preset alias analysis operation on the LLVM intermediate layer bytecode based on the control flow graph to generate a corresponding target alias graph; and a propagation derivation module, used to determine the corresponding seed diffusion point according to the substantial change node, and perform inter-process and inter-module variable propagation derivation operation based on the seed diffusion point, the control flow graph, and the target alias graph, and in combination with multiple core rules, to generate a corresponding statement-level influence domain network.
[0013] Optionally, in one embodiment of this application, the reduction module includes: an active variable analysis unit, used to generate an abstract syntax tree (AST) that satisfies a preset hierarchical relationship requirement for the source code before and after the target software update using a preset compiler front-end, and to perform active variable analysis on the AST using a preset depth-first traversal strategy, and to delete the at least one first target subtree if the assignment in at least one first target subtree of the AST is not referenced in subsequent paths and does not contain any modification to the global state or side effects of function calls, thereby obtaining a reduced AST; and a traversal unit, used to traverse the reduced AST from bottom to top and obtain the... The abstract syntax tree (API) is modified by exchanging the positions of the at least one second target subtree of the control flow and the commutative operation nodes in the reduced API. A comparison unit is used to compare the APIs of the source code before and after the target software update, obtain the comparison results, and normalize the renamed variables in the API that do not change the context structure based on the comparison results and a preset dynamic heuristic variable mapping table, to obtain differentiated subtrees that cannot be matched. The substantially changed nodes are then determined based on these differentiated subtrees.
[0014] Optionally, in one embodiment of this application, the alias analysis module includes: a calling unit, configured to add a direct calling edge between the caller and the callee node when directly calling a function in the complete instruction flow, and to infer all possible targets of the function pointer based on a preset pointer pointing analysis algorithm when indirectly calling a function in the complete instruction flow, and to supplement the call graph and the control flow graph with indirect calling edges and return edges to generate the control flow graph.
[0015] Optionally, in one embodiment of this application, the alias analysis module further includes: a generation unit, configured to perform flow-sensitive and context-sensitive alias analysis on the LLVM intermediate layer bytecode based on the control flow graph, and during the alias analysis execution process, dynamically update the topology of the alias graph through multiple types of core low-level instructions to generate the target alias graph, wherein the multiple types of core low-level instructions include assignment instructions, memory write instructions, read instructions, and structure offset calculation instructions, and the variables represented by all access paths reaching the same node of the target alias graph are aliases to each other.
[0016] Optionally, in one embodiment of this application, the propagation derivation module includes: a packaging unit, used to perform variable propagation derivation operations based on the seed diffusion point, the control flow graph, and the target alias graph to obtain at least one target variable of all the plurality of core rules and the underlying instruction corresponding to the at least one target variable, and to package the at least one target variable and the underlying instruction to generate the statement-level influence domain network, and to perform regression test redundant test case elimination and priority scheduling operations according to the statement-level influence domain network.
[0017] A third aspect of this application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the code influence domain analysis method based on variable propagation as described in the above embodiments.
[0018] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described code influence domain analysis method based on variable propagation.
[0019] A fifth aspect of this application provides a computer program product, including a computer program that is executed to implement the above-described code influence domain analysis method based on variable propagation.
[0020] Therefore, the embodiments of this application have the following beneficial effects: The embodiments of this application can generate an abstract syntax tree corresponding to the source code before and after the target software update, and perform a preset normalization reduction operation on the abstract syntax tree to obtain the corresponding reduction result. Based on the reduction result, the application identifies the substantive change nodes of the local logic of the code. The application compiles the target code repository into LLVM (Low Level Virtual Machine) intermediate layer bytecode, traverses all modules in the target code repository to extract the corresponding complete instruction flow, and generates a fine-grained inter-process control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships. Based on the control flow graph, the application performs a preset alias analysis operation on the LLVM intermediate layer bytecode to generate the corresponding target alias graph. The application determines the corresponding seed diffusion points based on the substantive change nodes, and performs variable propagation derivation operations between processes and modules based on the seed diffusion points, control flow graph, and target alias graph, combined with multiple core rules, to generate the corresponding statement-level influence domain network. This application can effectively improve the accuracy of influence domain analysis, avoid the path explosion problem of complex low-level analysis, and significantly improve regression testing efficiency and defect detection speed. This solves the problems of existing technologies that focus on using distance calculations to find the shortest path, which is extremely time-consuming to discover target defects, and lack in-depth analysis of the actual semantics of code modifications, making it impossible to distinguish between non-substantial format adjustments and substantial underlying logic modifications.
[0021] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0022] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 This is a flowchart of a code influence domain analysis method based on variable propagation provided in an embodiment of this application; Figure 2 A schematic diagram of a code local logic substantive change identification and reduction process based on an abstract syntax tree is provided as an embodiment of this application; Figure 3 A schematic diagram of a cross-process control flow graph analysis architecture is provided for one embodiment of this application; Figure 4 A schematic diagram of a flow-sensitive alias graph update process based on four types of core instructions is provided as an embodiment of this application; Figure 5 This is an example diagram of a code influence domain analysis apparatus based on variable propagation according to an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0023] Among them, 10-code influence domain analysis device based on variable propagation; 100-protocol module, 200-alias analysis module, 300-propagation derivation module; 601-memory, 602-processor, 603-communication interface. Detailed Implementation
[0024] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0025] The following describes a code influence domain analysis method and apparatus based on variable propagation according to embodiments of this application, with reference to the accompanying drawings. Addressing the problems mentioned in the background section, this application provides a code influence domain analysis method based on variable propagation. In this method, an abstract syntax tree (AST) is generated corresponding to the source code before and after the target software update. A preset normalization reduction operation is performed on the AST to obtain the corresponding reduction result. Based on the reduction result, substantial change nodes in the local logic of the code are identified. The target code repository is compiled into LLVM intermediate layer bytecode, and all modules in the target code repository are traversed to extract the corresponding complete instruction flow. A fine-grained inter-process control flow graph covering the target code repository is generated based on the complete instruction flow and preset function call relationships. Based on the control flow graph, a preset alias analysis operation is performed on the LLVM intermediate layer bytecode to generate a corresponding target alias graph. Seed diffusion points are determined based on the substantial change nodes. Based on the seed diffusion points, the control flow graph, and the target alias graph, and in conjunction with multiple core rules, variable propagation derivation operations between processes and modules are performed to generate a corresponding statement-level influence domain network. This application effectively improves the accuracy of influence domain analysis, avoids the path explosion problem in complex low-level analysis, and significantly improves regression testing efficiency and defect detection speed. Therefore, it solves the problems of existing technologies that focus on finding the shortest path using distance calculations, resulting in extremely long detection times for target defects, a lack of in-depth analysis of the actual semantics of code modifications, and an inability to distinguish between non-substantial formatting adjustments and substantial low-level logic modifications.
[0026] Specifically, Figure 1 This is a flowchart illustrating a code influence domain analysis method based on variable propagation, provided as an embodiment of this application.
[0027] like Figure 1 As shown, this code influence domain analysis method based on variable propagation includes the following steps: In step S101, an abstract syntax tree corresponding to the source code before and after the target software update is generated, and a preset normalization reduction operation is performed on the abstract syntax tree to obtain the corresponding reduction result. Based on the reduction result, the substantive change nodes of the local logic of the code are identified. The embodiments of this application can first generate an abstract syntax tree (AST) corresponding to the source code before and after the target software update, perform normalization reduction on the generated AST, and identify the substantive change nodes of the local logic of the code based on the reduction result.
[0028] Therefore, the embodiments of this application can filter out non-substantial changes such as variable renaming, structural rearrangement, and format adjustment when the code is changed, and accurately extract the substantive changes in the local logic of the code.
[0029] Optionally, in one embodiment of this application, an abstract syntax tree (AST) is generated corresponding to the source code before and after the target software update, and a preset normalization reduction operation is performed on the AST to obtain the corresponding reduction result. Based on the reduction result, the nodes of substantial changes in the local logic of the code are identified, including: generating an AST that satisfies the preset hierarchical relationship requirements corresponding to the source code before and after the target software update using a preset compiler front-end, performing active variable analysis on the AST using a preset depth-first traversal strategy, and deleting at least one first target subtree if the assignment in at least one first target subtree of the AST is not referenced in subsequent paths and does not contain modifications to the global state or side effects of function calls. The subtrees are used to obtain the reduced abstract syntax tree; the reduced abstract syntax tree is traversed from bottom to top, and at least one second target subtree of the operation nodes and control flow that satisfy the commutative law is obtained. Based on the preset operator-specific order relationship and variable lexicographical order, the positions of at least one second target subtree are swapped to obtain the standard abstract syntax tree; the abstract syntax trees corresponding to the source code before and after the target software update are compared to obtain the corresponding comparison results. Based on the comparison results and the preset dynamic heuristic variable mapping table, the renamed variables in the standard abstract syntax tree that do not change the context structure are normalized to obtain the differential subtrees that cannot be matched with each other, and the nodes of substantial change are determined according to the differential subtrees.
[0030] It should be noted that, for the source code before and after the target software update, the embodiments of this application can use the compiler front-end to generate an abstract syntax tree with a strict hierarchical relationship in the source code, and perform normalization and reduction operations on the generated abstract syntax tree. Figure 2 This is a schematic diagram illustrating the process of identifying and reducing substantial changes in local logic of code based on an abstract syntax tree. (Example:) Figure 2As shown, it illustrates the process of generating the AST, deleting redundant subtrees, rearranging the subtrees based on the commutative law, and extracting substantially changed nodes by comparing differences before and after code modification. The specific process is as follows: 1. Dead code deletion: Active variable analysis is performed through depth-first traversal. If the assignment in a subtree (i.e., at least one first target subtree) is not referenced in subsequent paths and does not contain any modification to the global state or side effects of function calls, it is deleted as a deletable subtree, thus obtaining the reduction abstract syntax tree.
[0031] 2. Node Swapping and Sorting: Traverse the AST from bottom to top. For commutative nodes and control flow subtrees (i.e., at least one second target subtree), sort the nodes according to the specific order of the operators (e.g., ...). The positions of the variables and their lexicographical order are swapped, and logically equivalent but differently arranged codes are unified into the "standard type", thus obtaining the standard type abstract syntax tree.
[0032] After the specification is completed, the embodiments of this application can perform a deep comparison of the old and new ASTs (i.e., the abstract syntax trees corresponding to the source code before and after the target software update), and introduce a dynamic heuristic variable mapping table to normalize the renamed variables that do not change the context structure. Finally, the differentiated subtrees that cannot be matched with each other are anchored as nodes with substantial changes in local logic.
[0033] It should be noted that in actual implementation, those skilled in the art may also abandon the AST generation of the compiler front end and instead use the intermediate representation in the back end of the compiler (such as LLVM IR) for text or graph structure comparison (such as isomorphic subgraph matching based on the Program Dependence Graph (PDG)). Although this method can also partially achieve semantic comparison, the intermediate representation often loses high-level semantic information such as macro definitions and type systems at the source code level, and may require greater computational cost when matching across versions.
[0034] Therefore, the embodiments of this application, through innovative abstract syntax tree reduction technology, can effectively shield the code from interference caused by adding comments, adjusting format, renaming variables, commutative operations, or injecting redundant defense code, thereby ensuring that the system can accurately locate the real "logically substantial change point" and improve the accuracy of influence domain analysis to over 85%.
[0035] In step S102, the target code repository is compiled into LLVM intermediate layer bytecode, and all modules in the target code repository are traversed to extract the corresponding complete instruction flow. A fine-grained inter-process control flow graph covering the target code repository is generated based on the complete instruction flow and the preset function call relationship. Based on the control flow graph, a preset alias analysis operation is performed on the LLVM intermediate layer bytecode to generate the corresponding target alias graph. Furthermore, embodiments of this application can also compile the target code repository into LLVM intermediate layer bytecode and traverse all modules in the target code repository to extract the corresponding complete instruction flow; secondly, embodiments of this application can also generate a fine-grained inter-process control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships, and then perform preset alias analysis operations on the LLVM intermediate layer bytecode to generate the final alias graph (i.e., the target alias graph).
[0036] Therefore, the embodiments of this application can accurately track the alias relationships of variables when faced with low-level code containing complex multi-level pointers, nested structures, and cross-module calls, so as to avoid path explosion and false positives during the data flow analysis process.
[0037] Optionally, in one embodiment of this application, generating a fine-grained interprocedural control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships includes: when directly calling a function in the complete instruction flow, adding a direct call edge between the caller and the callee node; and when indirectly calling a function in the complete instruction flow, inferring all possible targets of the function pointer based on a preset pointer pointing analysis algorithm, and supplementing the call graph and the control flow graph with indirect call edges and return edges to generate the control flow graph.
[0038] Figure 3 This is a schematic diagram of a cross-process control flow graph analysis architecture. (Example:) Figure 3 As shown, it illustrates the process of performing control flow graph analysis on a target code repository. In a specific implementation, embodiments of this application can compile the target code repository into LLVM intermediate layer bytecode, traverse all modules in the target code repository to extract the corresponding complete instruction flow, and combine the corresponding function call relationships to generate a fine-grained interprocedural control flow graph (ICFG) covering the entire code repository.
[0039] The function call relationships include: for direct function calls, this embodiment can add a direct call edge between the caller and the callee nodes. For indirect calls via function pointers, this embodiment can employ a field-sensitive pointer analysis algorithm to infer all possible targets of the function pointer and supplement the call graph and control flow graph with indirect call edges and return edges.
[0040] Optionally, in one embodiment of this application, a preset alias analysis operation is performed on the LLVM intermediate layer bytecode based on the control flow graph to generate a corresponding target alias graph. This includes: performing flow-sensitive and context-sensitive alias analysis on the LLVM intermediate layer bytecode based on the control flow graph, and dynamically updating the topology of the alias graph through multiple types of core low-level instructions during the alias analysis execution to generate the target alias graph. The multiple types of core low-level instructions include assignment instructions, memory write instructions, read instructions, and structure offset calculation instructions, and the variables represented by all access paths reaching the same node in the target alias graph are aliases to each other.
[0041] Specifically, based on the constructed control flow graph, embodiments of this application can perform flow-sensitive and context-sensitive alias analysis on the code, i.e., LLVM intermediate layer bytecode. During the flow-sensitive and context-sensitive alias analysis process, embodiments of this application can update the topology of the alias graph by capturing and processing four types of core low-level instructions to dynamically maintain an alias graph, thereby obtaining the final alias graph (i.e., the target alias graph), where, for example... Figure 4 As shown, the four categories of core low-level instructions (i.e., multiple categories of core low-level instructions) include: 1. The move instruction (i.e., the assignment instruction): moves the variable to the target node. If the two share the same node, it is considered an alias.
[0042] 2. Store instruction (i.e., memory write instruction): Deletes old outgoing edges, adds new outgoing edges marked with an asterisk, and reconstructs the underlying memory mapping.
[0043] 3. Load command (i.e., read command): Moves the variable to the destination node pointed to by the asterisk outgoing edge.
[0044] 4. gep instruction (i.e., structure offset calculation instruction): Moves the variable to the destination node with the edge marked by a specific structure field. It should be noted that, in the embodiments of this application, all access paths leading to the same node in the alias graph are strictly determined to be aliases of each other.
[0045] It should be noted that in actual implementation, in order to pursue faster analysis speed, those skilled in the art can also use flow-insensitive or context-insensitive lightweight pointer analysis algorithms (such as the Stensgaard or Andersen algorithms) to replace the dynamic alias graph update mechanism of the embodiments of this application. The advantage of the alternative is that the analysis is extremely fast, but the cost is that it will generate a large number of pseudo-positive alias associations (that is, variables that are considered to have no alias relationship are considered to be aliases of each other), which will lead to the "over-expansion" of the final calculated influence domain.
[0046] Therefore, the embodiments of this application dynamically update the alias graph through four types of fine-grained core instructions (move, store, load, gep) and combine them with context-sensitive indirect call resolution, thereby achieving extremely low time and space overhead while taking into account cross-module globality, and solving the problem that existing data flow analysis is prone to paralysis when facing multi-level pointers in large C / C++ projects.
[0047] In step S103, the corresponding seed diffusion point is determined based on the substantial change node, and variable propagation derivation operations between processes and modules are performed based on the seed diffusion point, control flow graph, and target alias graph, combined with multiple core rules, to generate the corresponding statement-level influence domain network. Subsequently, embodiments of this application can determine the corresponding seed diffusion point based on the substantially changed node, and combine the seed diffusion point, control flow graph, target alias graph, and multiple core rules to perform variable propagation derivation operations between processes and modules, thereby generating a high-precision statement-level influence domain network.
[0048] Therefore, the embodiments of this application can achieve global influence domain tracking from coarse-grained (function level / module level) to fine-grained (instruction / statement level), thereby deeply integrating the influence domain analysis results with regression testing and providing high-precision targeted guidance for test case selection and priority ranking.
[0049] Optionally, in one embodiment of this application, a corresponding seed diffusion point is determined based on the substantial change node, and variable propagation derivation operations are performed between processes and modules based on the seed diffusion point, control flow graph, and target alias graph, and in combination with multiple core rules, to generate a corresponding statement-level influence domain network. This includes: performing variable propagation derivation operations based on the seed diffusion point, control flow graph, and target alias graph to obtain at least one target variable and at least one underlying instruction corresponding to the multiple core rules, and packaging at least one target variable and underlying instruction to generate a statement-level influence domain network, and performing regression test redundant test case elimination and priority scheduling operations based on the statement-level influence domain network.
[0050] Specifically, in the embodiments of this application, the aforementioned anchored "substantial change node" is used as the seed diffusion point. Combining the obtained control flow graph and alias graph (i.e., the target alias graph), variable propagation between processes and modules is deduced according to the following four core rules: Rule 1: If a variable is an alias of a variable that has undergone substantial change, then mark the variable as affected.
[0051] Rule 2: If an expression contains an affected variable and that expression is used to assign a value to a new variable, the new variable being assigned a value is marked as affected.
[0052] Rule 3 (Control Dependency Propagation): Based on dominance boundary analysis, if the condition of a branch statement (such as if / while) is affected, then all variables assigned values within the code block controlled by that branch are marked as affected.
[0053] Rule 4 (Cross-process propagation): If the return value of the called function is marked as affected, then the instruction that called the function and the variable that received the return value are marked as affected.
[0054] This application embodiment can extract and package all variables (i.e., at least one target variable) that conform to the above diffusion rules and their corresponding underlying instructions, and output a high-precision statement-level influence domain network, which serves as the basis for eliminating redundant regression test cases and performing priority scheduling.
[0055] Therefore, unlike traditional tools that rely on rough statistics or simple distances for blind exploration, the embodiments of this application output an absolute target "influence domain" at the statement level. By using this influence domain to guide the screening of fuzzy testing or regression testing cases, the speed of defect discovery for damaged logic regions can be increased by an average of more than 50%, which greatly shortens the development and iteration cycle of industrial software and other scenarios.
[0056] The code influence domain analysis method based on variable propagation proposed in this application generates an abstract syntax tree (AST) corresponding to the source code before and after the target software update, performs a preset normalization reduction operation on the AST to obtain the corresponding reduction result, and identifies the substantive change nodes of the local logic of the code based on the reduction result. The target code repository is compiled into LLVM intermediate layer bytecode, and all modules in the target code repository are traversed to extract the corresponding complete instruction flow. A fine-grained inter-process control flow graph covering the target code repository is generated based on the complete instruction flow and preset function call relationships. Based on the control flow graph, a preset alias analysis operation is performed on the LLVM intermediate layer bytecode to generate the corresponding target alias graph. Seed diffusion points are determined based on the substantive change nodes, and variable propagation derivation operations between processes and modules are performed based on the seed diffusion points, control flow graph, and target alias graph, combined with multiple core rules, to generate the corresponding statement-level influence domain network. This application can effectively improve the accuracy of influence domain analysis, avoid the path explosion problem of complex low-level analysis, and significantly improve regression testing efficiency and defect detection speed.
[0057] Secondly, the code influence domain analysis apparatus based on variable propagation proposed according to the embodiments of this application is described with reference to the accompanying drawings.
[0058] Figure 5 This is a block diagram of a code influence domain analysis device based on variable propagation according to an embodiment of this application.
[0059] like Figure 5As shown, the code influence domain analysis device 10 based on variable propagation includes: a specification module 100, an alias analysis module 200, and a propagation derivation module 300.
[0060] The specification module 100 is used to generate an abstract syntax tree corresponding to the source code before and after the target software update, and to perform a preset normalization specification operation on the abstract syntax tree to obtain the corresponding specification result. Based on the specification result, it identifies the substantive change nodes of the local logic of the code.
[0061] The alias analysis module 200 is used to compile the target code repository into LLVM intermediate layer bytecode, traverse all modules in the target code repository to extract the corresponding complete instruction flow, generate a fine-grained inter-process control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships, and perform preset alias analysis operations on the LLVM intermediate layer bytecode based on the control flow graph to generate the corresponding target alias graph.
[0062] The propagation derivation module 300 is used to determine the corresponding seed diffusion point based on the substantial change node, and based on the seed diffusion point, control flow graph and target alias graph, and in combination with multiple core rules, to perform variable propagation derivation operations between processes and modules to generate the corresponding statement-level influence domain network.
[0063] Optionally, in one embodiment of this application, the specification module 100 includes: an active variable analysis unit, a traversal unit, and a comparison unit.
[0064] The active variable analysis unit is used to generate an abstract syntax tree (AST) that satisfies the preset hierarchical relationship requirements for the source code before and after the target software update using a preset compiler front-end. It performs active variable analysis on the AST using a preset depth-first traversal strategy. If the assignment in at least one first target subtree of the AST is not referenced in subsequent paths and does not involve modification of the global state or side effects of function calls, at least one first target subtree is deleted to obtain the reduced AST.
[0065] The traversal unit is used to traverse the reduced abstract syntax tree from bottom to top, and to obtain at least one second target subtree of the reduced abstract syntax tree that satisfies the commutative law and the control flow. Based on the preset operator-specific order relationship and variable lexicographical order, the unit swaps the positions of at least one second target subtree to obtain the standard abstract syntax tree.
[0066] The comparison unit is used to compare the abstract syntax trees corresponding to the source code before and after the target software update, obtain the corresponding comparison results, and based on the comparison results and the preset dynamic heuristic variable mapping table, normalize the renamed variables in the standard abstract syntax tree that do not change the context structure, so as to obtain the differential subtrees that cannot be matched with each other, and determine the substantive change nodes based on the differential subtrees.
[0067] Optionally, in one embodiment of this application, the alias analysis module 200 includes: a calling unit, used to add a direct call edge between the caller and the callee node when directly calling a function in the complete instruction flow, and to infer all possible targets of the function pointer based on a preset pointer pointing analysis algorithm when indirectly calling a function in the complete instruction flow, and to supplement the call graph and the control flow graph with indirect call edges and return edges to generate a control flow graph.
[0068] Optionally, in one embodiment of this application, the alias analysis module 200 further includes: a generation unit, used to perform flow-sensitive and context-sensitive alias analysis on the LLVM intermediate layer bytecode based on the control flow graph, and during the alias analysis execution process, dynamically update the topology of the alias graph through multiple types of core low-level instructions to generate a target alias graph, wherein the multiple types of core low-level instructions include assignment instructions, memory write instructions, read instructions and structure offset calculation instructions, and the variables represented by all access paths reaching the same node of the target alias graph are aliases to each other.
[0069] Optionally, in one embodiment of this application, the propagation derivation module 300 includes: a packaging unit, used to perform variable propagation derivation operations based on seed diffusion points, control flow graphs, and target alias graphs to obtain at least one target variable and at least one underlying instruction corresponding to the target variable of all multiple core rules, and to package at least one target variable and underlying instruction to generate a statement-level influence domain network, and to perform regression test redundant test case elimination and priority scheduling operations according to the statement-level influence domain network.
[0070] It should be noted that the foregoing explanation of the code influence domain analysis method embodiment based on variable propagation also applies to the code influence domain analysis device based on variable propagation in this embodiment, and will not be repeated here.
[0071] The code influence domain analysis device based on variable propagation proposed in this application includes a reduction module 100, which generates an abstract syntax tree corresponding to the source code before and after the target software update, performs a preset normalization reduction operation on the abstract syntax tree to obtain the corresponding reduction result, and identifies the substantive change nodes of the local logic of the code based on the reduction result; an alias analysis module 200, which compiles the target code repository into LLVM intermediate layer bytecode, traverses all modules in the target code repository to extract the corresponding complete instruction flow, generates a fine-grained inter-process control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships, and performs a preset alias analysis operation on the LLVM intermediate layer bytecode based on the control flow graph to generate the corresponding target alias graph; and a propagation derivation module 300, which determines the corresponding seed diffusion point based on the substantive change node, and performs inter-process and inter-module variable propagation derivation operation based on the seed diffusion point, control flow graph, and target alias graph, and in combination with multiple core rules, to generate the corresponding statement-level influence domain network. This application can effectively improve the accuracy of influence domain analysis, avoid the path explosion problem of complex underlying analysis, and significantly improve the efficiency of regression testing and the speed of defect detection.
[0072] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device may include: The memory 601, the processor 602, and the computer program stored on the memory 601 and capable of running on the processor 602.
[0073] When the processor 602 executes the program, it implements the code influence domain analysis method based on variable propagation provided in the above embodiments.
[0074] Furthermore, electronic devices also include: Communication interface 603 is used for communication between memory 601 and processor 602.
[0075] The memory 601 is used to store computer programs that can run on the processor 602.
[0076] The memory 601 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0077] If the memory 601, processor 602, and communication interface 603 are implemented independently, then the communication interface 603, memory 601, and processor 602 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0078] Optionally, in a specific implementation, if the memory 601, processor 602, and communication interface 603 are integrated on a single chip, then the memory 601, processor 602, and communication interface 603 can communicate with each other through an internal interface.
[0079] The processor 602 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0080] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described code influence domain analysis method based on variable propagation.
[0081] This application also provides a computer program product, including a computer program, which, when executed, is used to implement the above-described code influence domain analysis method based on variable propagation.
[0082] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0083] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0084] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0085] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0086] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. If implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0087] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0088] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0089] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.
Claims
1. A code influence domain analysis method based on variable propagation, characterized in that, Includes the following steps: Generate abstract syntax trees corresponding to the source code before and after the target software update, and perform a preset normalization reduction operation on the abstract syntax trees to obtain the corresponding reduction results. Based on the reduction results, identify the substantive change nodes of the local logic of the code. The target code repository is compiled into LLVM intermediate layer bytecode, and all modules in the target code repository are traversed to extract the corresponding complete instruction flow. A fine-grained inter-process control flow graph covering the target code repository is generated based on the complete instruction flow and the preset function call relationship. Based on the control flow graph, a preset alias analysis operation is performed on the LLVM intermediate layer bytecode to generate the corresponding target alias graph. Based on the substantial change nodes, the corresponding seed diffusion points are determined, and based on the seed diffusion points, the control flow graph, and the target alias graph, and in conjunction with multiple core rules, variable propagation derivation operations are performed between processes and modules to generate the corresponding statement-level influence domain network.
2. The code influence domain analysis method based on variable propagation according to claim 1, characterized in that, The process involves generating abstract syntax trees (ASTs) corresponding to the source code before and after the target software update, performing a preset normalization and reduction operation on the ASTs to obtain the corresponding reduction results, and identifying substantive changes in local code logic based on the reduction results, including: An abstract syntax tree (AST) that satisfies the preset hierarchical relationship requirements is generated from the source code of the target software before and after the update using a preset compiler front-end. An active variable analysis is performed on the AST using a preset depth-first traversal strategy. If the assignment in at least one first target subtree of the AST is not referenced in subsequent paths and does not involve modification of the global state or side effects of function calls, the at least one first target subtree is deleted to obtain the reduced AST. Traverse the reduction abstract syntax tree from bottom to top, and obtain at least one second target subtree of the operation node that satisfies the commutative law and the control flow in the reduction abstract syntax tree. Based on the preset operator-specific order relationship and variable lexicographical order, swap the positions of the at least one second target subtree to obtain the standard abstract syntax tree. The abstract syntax trees corresponding to the source code before and after the target software update are compared to obtain the corresponding comparison results. Based on the comparison results and a preset dynamic heuristic variable mapping table, the renamed variables in the standard abstract syntax tree that do not change the context structure are normalized to obtain differentiated subtrees that cannot be matched with each other. The substantial change nodes are determined according to the differentiated subtrees.
3. The code influence domain analysis method based on variable propagation according to claim 2, characterized in that, The step of generating a fine-grained inter-procedural control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships includes: When directly calling a function in the complete instruction flow, a direct call edge is added between the caller and the callee node. When indirectly calling a function in the complete instruction flow, based on a preset pointer pointing analysis algorithm, all possible targets of the function pointer are inferred, and indirect call edges and return edges are added to the call graph and the control flow graph to generate the control flow graph.
4. The code influence domain analysis method based on variable propagation according to claim 3, characterized in that, The step of performing a preset alias analysis operation on the LLVM intermediate layer bytecode based on the control flow graph to generate a corresponding target alias graph includes: Based on the control flow graph, flow-sensitive and context-sensitive aliasing analysis is performed on the LLVM intermediate layer bytecode. During the aliasing analysis, the topology of the aliasing graph is dynamically updated through multiple types of core low-level instructions to generate the target aliasing graph. The multiple types of core low-level instructions include assignment instructions, memory write instructions, read instructions, and structure offset calculation instructions. The variables represented by all access paths reaching the same node in the target aliasing graph are aliases to each other.
5. The code influence domain analysis method based on variable propagation according to claim 4, characterized in that, The step of determining the corresponding seed diffusion point based on the substantial change node, and performing variable propagation derivation operations between processes and modules based on the seed diffusion point, the control flow graph, and the target alias graph, and in conjunction with multiple core rules, to generate the corresponding statement-level influence domain network, includes: Based on the seed diffusion point, the control flow graph, and the target alias graph, variable propagation derivation is performed to obtain at least one target variable of all the multiple core rules and the underlying instruction corresponding to the at least one target variable. The at least one target variable and the underlying instruction are then packaged to generate the statement-level influence domain network. Regression test redundant test case elimination and priority scheduling operations are performed based on the statement-level influence domain network.
6. A code influence domain analysis device based on variable propagation, characterized in that, include: The specification module is used to generate an abstract syntax tree corresponding to the source code before and after the target software update, and to perform a preset normalization specification operation on the abstract syntax tree to obtain the corresponding specification result. Based on the specification result, it identifies the substantive change nodes of the local logic of the code. The alias analysis module is used to compile the target code repository into LLVM intermediate layer bytecode, traverse all modules in the target code repository to extract the corresponding complete instruction flow, generate a fine-grained inter-process control flow graph covering the target code repository based on the complete instruction flow and preset function call relationships, and perform preset alias analysis operations on the LLVM intermediate layer bytecode based on the control flow graph to generate the corresponding target alias graph. The propagation derivation module is used to determine the corresponding seed diffusion point based on the substantial change node, and based on the seed diffusion point, the control flow graph, and the target alias graph, and in combination with multiple core rules, to perform variable propagation derivation operations between processes and modules to generate the corresponding statement-level influence domain network.
7. The code influence domain analysis device based on variable propagation according to claim 6, characterized in that, The specification module includes: An active variable analysis unit is used to generate an abstract syntax tree that satisfies the preset hierarchical relationship requirements of the source code before and after the target software update using a preset compiler front-end, and to perform active variable analysis on the abstract syntax tree using a preset depth-first traversal strategy. If the assignment in at least one first target subtree of the abstract syntax tree is not referenced in subsequent paths and does not contain any modification to the global state or side effects of function calls, the at least one first target subtree is deleted to obtain a reduced abstract syntax tree. The traversal unit is used to traverse the reduced abstract syntax tree from bottom to top, and obtain at least one second target subtree of the operation node that satisfies the commutative law and the control flow in the reduced abstract syntax tree. Based on the preset operator-specific order relationship and variable lexicographical order, the unit swaps the positions of the at least one second target subtree to obtain the standard abstract syntax tree. The comparison unit is used to compare the abstract syntax trees corresponding to the source code before and after the target software update, obtain the corresponding comparison results, and based on the comparison results and a preset dynamic heuristic variable mapping table, normalize the renamed variables in the standard abstract syntax tree that do not change the context structure to obtain differentiated subtrees that cannot be matched with each other, and determine the substantial change nodes according to the differentiated subtrees.
8. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the program to implement the code influence domain analysis method based on variable propagation as described in any one of claims 1-5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, The program is executed by the processor to implement the code influence domain analysis method based on variable propagation as described in any one of claims 1-5.
10. A computer program product, comprising a computer program, characterized in that, The computer program is executed to implement the code influence domain analysis method based on variable propagation as described in any one of claims 1-5.
