Influence link generation method and device and storage medium
By identifying the API interface functions and dependencies of the change function, looking up the dependency functions layer by layer, and generating the influencing links of the test code, the accuracy of evaluating the scope of the test impact in the existing technology is solved, and more accurate and efficient influencing link generation is achieved.
Patent Information
- Application Number
- CN202411960768.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-27
AI Technical Summary
In an agile development environment, it is difficult for the prior art to quickly and accurately evaluate the range of test impact, and often ignore the imperceptible call links, resulting in inaccurate evaluation results of the range of test impact.
By identifying the API interface function exposed by the change function, find the target functional module that has a dependency relationship with the API interface function, start from the entry point function of the target functional module, search for the dependency function layer by layer, and generate the influencing link corresponding to the test code.
It realizes accurate link generation for test code changes, ensures that each potential impact point is fully considered and verified, reduces the risk after going online, and improves the efficiency of impact link generation.
Smart Images

Figure CN119883913A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device and storage medium for generating a topology influence link. Background Art
[0002] In an agile development environment, enterprises face the need for rapid iteration and frequent releases, and cross-project collaboration is frequent, which makes the assessment of the test impact scope particularly critical. The existing test impact scope assessment is mainly done by technicians manually combing through the scope of changes, checking each level, and finally determining the call links affected by the code modification through manual judgment. However, this method is slow and often ignores call links that are not easily detected, and cannot fully understand all call links affected by code modifications. Summary of the invention
[0003] The embodiments of the present invention provide an impact link generation method, device and storage medium, which can accurately generate an impact link corresponding to a test code.
[0004] In a first aspect, an embodiment of the present invention provides a method for generating an impact link, the method comprising:
[0005] In response to a link generation request of a test code, obtaining a development branch submission record corresponding to the test code;
[0006] Determine the changed function in the test code according to the development branch submission record;
[0007] Determine an API interface function corresponding to the change function, where the API interface function is called by other function modules other than the function module where the change function is located;
[0008] Determine a target function module having a dependency relationship with the API interface function and an entry point function corresponding to the target function module, wherein the target function module is a function module other than the function module where the change function is located;
[0009] An impact link corresponding to the test code is generated according to the change function, the API interface function and the entry point function.
[0010] In a second aspect, an embodiment of the present invention provides an impact link generation device, the device comprising:
[0011] An acquisition module, configured to, in response to a link generation request of a test code, acquire a development branch submission record corresponding to the test code;
[0012] A first determination module, configured to determine a changed function in the test code according to the development branch submission record;
[0013] A second determining module is used to determine an API interface function corresponding to the change function, where the API interface function is called by other function modules other than the function module where the change function is located;
[0014] A third determination module is used to determine a target function module having a dependency relationship with the API interface function and an entry point function corresponding to the target function module, wherein the target function module is a function module other than the function module where the change function is located;
[0015] A generation module is used to generate an impact link corresponding to the test code according to the change function, the API interface function and the entry point function.
[0016] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the method for influencing link generation as described in the first aspect.
[0017] In a fourth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of a transmission device, the processor can at least implement the method for influencing link generation as described in the first aspect.
[0018] In a fifth aspect, an embodiment of the present invention provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor can implement the method for influencing link generation as described in the first aspect above.
[0019] In the impact link generation scheme provided in the embodiment of the present invention, an impact link can be generated for the changed test code in the development stage to determine the impact of the test code on the cross-cluster functional modules. Specifically, in response to the link generation request of the test code, the development branch submission record corresponding to the test code is obtained, and the changed function in the test code is determined according to the development branch submission record. Then, the API interface function corresponding to the changed function is determined, wherein the API interface function is called by other functional modules other than the functional module where the changed function is located. Next, the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module are determined. Among them, the target functional module is a functional module other than the functional module where the changed function is located. Finally, based on the changed function, the API interface function and the entry point function, the impact link corresponding to the test code is generated.
[0020] In the above scheme, by identifying the API interface function exposed by the changed function, the target functional module that has a dependency relationship with the API interface function is found. In this way, all external call points that may be affected by the change can be known based on the API interface function, so as to comprehensively know the calling situation of the changed function across clusters, so as to find the call link that is not easy to detect. Then, according to the entry point function corresponding to the changed function, the API interface function and the target functional module, the impact link corresponding to the test code can be generated more accurately to ensure that every potential impact point of the change is fully considered and verified, reducing the risk after going online. In addition, when generating the impact link, the API interface function corresponding to the changed function in the test code can be determined first to obtain the outermost function of the functional module where the changed function is located. In this way, the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module can be quickly found, thereby speeding up the generation efficiency of the impact link. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 A flowchart of a method for influencing link generation provided by an embodiment of the present invention;
[0023] Figure 2 A flowchart of an API interface function corresponding to a change function provided by an embodiment of the present invention;
[0024] Figure 3 A flowchart of determining an entry point function corresponding to a target functional module provided by an embodiment of the present invention;
[0025] Figure 4 A flowchart of an impact link corresponding to a test code generated according to an embodiment of the present invention;
[0026] Figure 5 A flowchart of another method for influencing link generation provided by an embodiment of the present invention;
[0027] Figure 6 A schematic diagram of an application of a method for influencing link generation provided by an embodiment of the present invention;
[0028] Figure 7 A flow chart of determining an entry layer function provided by an embodiment of the present invention;
[0029] Figure 8A schematic diagram of the structure of an influencing link generation device provided by an embodiment of the present invention;
[0030] Fig. 9 For Figure 8 The illustrated embodiment is a schematic diagram of the structure of an electronic device corresponding to the impact link generation device. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.
[0033] In an agile development environment, enterprises face the need for rapid iteration and frequent launches, and cross-project collaboration is frequent, which makes the assessment of the test impact scope particularly critical. In existing solutions, technicians mainly manually sort out the scope of changes, check layer by layer, and finally determine the call links affected by code modifications through manual judgment. However, this method is slow, and for complex cluster deployment projects, the call links are complex and changeable, and there are many call links with unclear cross-cluster usage. When this method is used for viewing, these subtle call links are often ignored, which in turn affects the final generated impact link, resulting in the accuracy of the test impact scope assessment results.
[0034] In order to solve the above technical problems, an embodiment of the present invention provides a solution for automatically generating an impact link corresponding to a change code, which no longer relies on manual generation of the impact link corresponding to the change code. Specifically, by identifying the API interface function corresponding to the change code and determining the target function module that has a dependency relationship with the API function, all external call points that may be affected by the change can be known. Then, starting from the entry point function corresponding to the target function module, according to the function reference relationship, search downward layer by layer, and determine the dependent functions that have a dependency relationship with the change function in turn, so that the impact link corresponding to the change code can be generated more accurately. In addition, based on the impact link corresponding to the generated change code, the impact scope of the change code on cross-cluster projects can be accurately evaluated.
[0035] Some embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0036] Figure 1A flowchart of a method for influencing link generation provided by an embodiment of the present invention, such as Figure 1 Specifically, the method may include the following steps:
[0037] 101. In response to a link generation request of a test code, obtain a development branch submission record corresponding to the test code.
[0038] 102. Determine the changed functions in the test code based on the development branch submission records.
[0039] 103. Determine an API interface function corresponding to the changed function. The API interface function is called by other function modules other than the function module where the changed function is located.
[0040] 104. Determine a target functional module having a dependency relationship with the API interface function and an entry point function corresponding to the target functional module, wherein the target functional module is a functional module other than the functional module where the changed function is located.
[0041] 105. Generate an impact link corresponding to the test code according to the changed function, API interface function and entry point function.
[0042] During the software development process, you can use a distributed version control system to clone the code in a remote repository to generate a local code base, and modify the code of the main branch in the local code base to modify, delete, or add some specific functions based on the original online code. In order to track code changes, each time the code is changed, a series of code modifications and submission operations corresponding to the development branch will be recorded.
[0043] Then, after receiving the link generation request triggered for the test code, in response to the link generation request for the test code, the development branch submission record corresponding to the test code is obtained according to the version number corresponding to the test code carried in the link generation request. Among them, the development branch submission record records in detail the time, author, submission information and specific content of the code change for each submission. In this way, the changed code in the test code and the changed function corresponding to the changed code can be determined by analyzing the development branch submission record.
[0044] Among them, a test code may contain multiple change functions, and the generation process of the impact link corresponding to each change function is roughly the same. For the convenience of description, the following only takes one change function as an example to illustrate its specific implementation process.
[0045] Regarding the process of determining the changed functions in the test code, in an optional implementation method, you can first obtain the main branch submission record corresponding to the test code, compare the development branch submission record corresponding to the test code with the main branch submission record corresponding to the test code to determine the changes in the test code, and determine the changed functions in the test code based on the changes.
[0046] The master branch commit record records the core code change history of the project in detail. You can use the difference comparison command to compare the development branch record with the master branch commit record to determine the change file corresponding to the test code and the change content in the change file and the line number corresponding to the change content.
[0047] After obtaining the line number corresponding to the changed content, the specific function corresponding to the changed content can be determined in combination with the file structure corresponding to the changed file. For the sake of description, this function is called a changed function.
[0048] The first abstract syntax tree corresponding to the test code can be obtained, and the first abstract syntax tree can be used to parse the change file to obtain the line number corresponding to each function in the change file. The change function corresponding to the change content is determined according to the line number corresponding to each function in the change file and the line number corresponding to the change content.
[0049] For example, through git d iff, it is determined that lines 100-150 in the changed file have changed. Combined with the Java abstract syntax tree corresponding to the test code, it is identified that function A in the changed file is located at lines 99-160, so it can be determined that the changed function is function A.
[0050] In an optional embodiment, the specific implementation process of obtaining the first abstract syntax tree corresponding to the test code may include: dividing the test code into multiple lexical units; and organizing the multiple lexical units into the first abstract syntax tree according to the grammatical rules of the test code.
[0051] After determining the changed function in the test code, the API interface function corresponding to the changed function is then determined. The API interface function is called by other functional modules other than the functional module where the changed function is located. In other words, the API interface function is the outermost calling entry function of the functional module where the changed function is located, and is usually exposed to other functional modules.
[0052] In actual applications, the outermost call entry function is where the changed function is called for the first time in the program, marking the starting point of the changed function execution process. Starting the analysis from the outermost call entry function can avoid blindly searching for the impact path of the changed function in the entire program, which helps improve analysis efficiency, speed up the efficiency of generating impact links, and reduce unnecessary workload.
[0053] Next, the dependency relationship between the changed function and other functions can be sorted out through the API interface function. Specifically, the target function module with which the API interface function has a dependency relationship and the entry point function corresponding to the target function module are determined, and the target function module is a function module other than the function module where the changed function is located.
[0054] In actual applications, when a function in a development project is changed, the function may be relatively low-level and affect many links (i.e., multiple functions call the function). In the case of complex iterations, some links affected by the function are often missed, causing online risks. In order to fully understand the actual call status of the changed function across clusters, all target function modules that have dependencies on the API interface function can be searched to obtain all external call points that may be affected by the change, so that subtle call links can be found.
[0055] In an optional embodiment, the target function module that has a dependency relationship with the API interface function can be determined by analyzing the project dependency project. After determining the change function, the API interface function corresponding to the change function, and the entry point function corresponding to the target function module, the upper and lower layer functions corresponding to each function can be determined based on the function reference relationship corresponding to each function, and then the impact link corresponding to the test code can be generated.
[0056] In an embodiment of the present invention, by identifying the API interface function exposed by the change function, the target functional module that has a dependency relationship with the API interface function is searched, so that all external call points that may be affected by the change can be known based on the API interface function, so as to comprehensively know the calling situation of the change function across clusters, so as to find the call link that is not easy to detect, and then, according to the change function, API interface function and the entry point function corresponding to the target functional module, the impact link corresponding to the test code can be accurately generated to ensure that every potential impact point of the change is fully considered and verified, reducing the risk after going online. In addition, when generating the impact link, the API interface function corresponding to the change function in the test code can be determined first to obtain the outermost function of the functional module where the change function is located, so that the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module can be quickly found, thereby accelerating the generation efficiency of the impact link.
[0057] In conjunction with the following embodiments, a possible implementation method of determining the API interface function corresponding to the change function in the above embodiment is described in detail.
[0058] Figure 2 A flowchart of determining an API interface function corresponding to a change function provided by an embodiment of the present invention, such as Figure 2Specifically, the method may include the following steps:
[0059] 201. Determine the upper-level function corresponding to the changed function according to the reference relationship corresponding to the changed function.
[0060] 202. Identify whether the upper-layer function carries an external call identifier.
[0061] 203. If the upper-layer function carries the external call identifier, the upper-layer function is determined as the API interface function corresponding to the changed function.
[0062] 204. If the upper-level function does not carry the external call identifier, start from the changed function and search upward layer by layer until the upper-level function carrying the external call identifier is found.
[0063] 205. Determine the top-level function carrying the external call identifier as the API interface function corresponding to the changed function.
[0064] Among them, before determining the API interface function corresponding to the changed function, the change file to which the changed function belongs can be analyzed according to the syntax and semantics to parse out the function name, function implementation, input parameters, return value and function reference relationship corresponding to each function in the change file.
[0065] The function reference relationship includes how a function is called by other functions and how a function calls other functions. That is, the reference relationship corresponding to the modified function refers to which function references the modified function and which function the modified function references.
[0066] After determining the reference relationship of the changed function, the upper layer function corresponding to the changed function can be determined according to the reference relationship corresponding to the changed function. Then, it is identified whether the upper layer function carries an external call identifier. Among them, the external call identifier can be an RPC identifier, a message receiving entry identifier, a scheduled task identifier, a gateway identifier, a task forwarding service identifier, etc.
[0067] If it is identified that the upper-level function carries an external call identifier, it means that the upper-level function is the outermost call entry function exposed to other functional modules for calling, and then the upper-level function can be determined as the API interface function corresponding to the change function.
[0068] If it is identified that the upper-level function does not carry an external call identifier, it means that the upper-level function is not the outermost calling entry function. Then, you can start from the changed function and search upward layer by layer until you find the upper-level function that carries the external call identifier, and determine the found upper-level function as the API interface function corresponding to the changed function.
[0069] For example, assuming that the changed function is function A, the reference relationship corresponding to function A is that function A references function D, the reference relationship corresponding to function D is that function D is referenced by functions A and B, function D references function C, the reference relationship corresponding to function C is that function C is referenced by function D, function C references function E, and function C carries an RPC identifier. Then you can start from function A and search upward layer by layer to find that the upper-layer function corresponding to function A is function D. Function D does not carry an external call identifier, then start from function D and search upward to find that the upper-layer function corresponding to function D is function C, and identify that function C carries an external call identifier. Then end the search and determine function C as the API interface function corresponding to the changed function.
[0070] In an embodiment of the present invention, the upper-layer function corresponding to the changed function is determined according to the reference relationship corresponding to the changed function, and whether the upper-layer function carries an external call identifier is identified. If the upper-layer function carries the external call identifier, the upper-layer function is determined as the API interface function corresponding to the changed function. If the upper-layer function does not carry the external call identifier, the search is conducted upward layer by layer starting from the changed function until the uppermost function carrying the external call identifier is found. In this way, the API interface function corresponding to the changed function can be accurately identified, and then all target functional modules that have a dependency relationship with the changed function can be accurately found based on the API interface function.
[0071] When determining the target function module that has a dependency relationship with the API interface function, the target function module that has a dependency relationship with the API interface function can be determined based on the service call file. Alternatively, the target function module that has a dependency relationship with the API interface function can be determined based on the pom.xml file. The target function module is a function module other than the function module where the change function is located, that is, the target function module is an external call module.
[0072] In an optional embodiment, a pre-trained code similarity recognition model can also be used to determine the target function module that has a dependency relationship with the API interface function. The code similarity recognition model can be pre-trained to determine the target function module that has a dependency relationship with the API interface function. The code similarity recognition model can be generated by learning and training the neural network module.
[0073] In addition, a project knowledge base can also be built. When using the code similarity recognition model to identify the target functional modules that have dependencies on the API interface functions, the project knowledge base can be used in conjunction with the model to improve the accuracy of the recognition results.
[0074] The project knowledge base includes code files, project design documents, historical background of the project, reasons for technology selection, project change logs, detailed descriptions of each functional module, file structure of code files, function signature information of each function, and detailed descriptions of each function, etc. Code files may include source code and test code.
[0075] In addition, automated scripts can be used to collect, organize, and update information in the knowledge base. For example, the latest function reference relationships can be extracted from the code base regularly and stored in the database; or relevant documents can be automatically updated whenever there is a new submission.
[0076] Then, before inputting the API interface function corresponding to the change function and the reference relationship and function signatures corresponding to the functional modules corresponding to multiple projects into the code similarity recognition model, the keyword corresponding to the API interface function can be determined first, and the background knowledge matching the keyword can be matched from the project knowledge base according to the keyword. The background knowledge, the API interface function and the reference relationship and function signatures of the functional modules corresponding to multiple projects are input into the code similarity recognition model to output the target functional module that has a dependency relationship with the API interface function.
[0077] In another optional embodiment, the target functional module having a dependency relationship with the API interface function can also be identified by using a large language model in combination with a project knowledge base. Specifically, the keyword corresponding to the API interface function is first determined, and the background knowledge matching the keyword is matched from the project knowledge base according to the keyword. Then, the reference relationship, function signature and background knowledge of the API interface function and the functional modules corresponding to the multiple projects are converted into a language form that is suitable for the large language model to understand, so as to obtain the converted language text. Next, the task description information corresponding to the large language model is generated, and the task description information and the language text are input into the large language model to guide the large language model to screen out the target functional module having a dependency relationship with the API function from the multiple functional modules.
[0078] After determining the target function module that has a dependency relationship with the API interface function corresponding to the changed function, the entry point function corresponding to the target function module can be determined, and then the upper-level call link can be determined based on the entry point function to accurately generate a complete impact link.
[0079] The specific implementation process of determining the entry point function corresponding to the target functional module and generating the impact link is described in detail below in conjunction with the following embodiments.
[0080] Figure 3 A flowchart of determining an entry point function corresponding to a target functional module provided by an embodiment of the present invention, such as Figure 3Specifically, the method may include the following steps:
[0081] 301. Parse the source code of the target functional module to construct a second abstract syntax tree corresponding to the target functional module.
[0082] 302. Extract a code structure corresponding to the target functional module according to the second abstract syntax tree, where the code structure includes detailed information of each class, detailed information of each method, and detailed information of each attribute in the source code.
[0083] 303. Determine the entry point function corresponding to the target functional module according to the code structure and the external call identifier.
[0084] When parsing the target function module, the source code corresponding to the target function module can be first pulled, and the overall project structure corresponding to the target function module can be parsed, and the second abstract syntax tree corresponding to the target function module can be constructed according to the overall project structure.
[0085] Next, according to the second abstract syntax tree, the code structure corresponding to the target functional module is extracted, and the code structure includes detailed information of each class, detailed information of each method, and detailed information of each attribute in the source code. And according to the code structure and the external call identifier, the entry point function corresponding to the target functional module is determined.
[0086] Wherein, the target function module may include multiple code files, and the file structure corresponding to each code file in the target function module can be parsed through the second abstract syntax tree. Wherein, the file structure includes function information, class information, class attribute information, function body information, etc. of each function. Then, according to the file structure corresponding to each code file, the internal dependency and external dependency of each function in the code file are parsed. According to the internal dependency and external dependency of each function in each code file and the external call identifier, the entry point function corresponding to the target function module is determined.
[0087] The embodiment of the present invention extracts the code structure corresponding to the target function module by combining the second abstract syntax tree corresponding to the target function module, and then accurately determines the entry point function corresponding to the target function module according to the code structure and the external call identifier.
[0088] Figure 4 A flowchart of generating an impact link corresponding to a test code provided by an embodiment of the present invention, such as Figure 4 Specifically, the method may include the following steps:
[0089] 401. Determine a reference function corresponding to the entry point function.
[0090] 402. Compare the code similarity between the API interface function and the reference function to determine whether the API interface function and the reference function are the same function.
[0091] 403. If the API interface function and the referenced function are the same function, start from the entry point function and search downward layer by layer according to the function reference relationship to sequentially determine the dependent functions that have a dependency relationship with the entry point function.
[0092] 404. Generate an impact link corresponding to the test code according to the changed function, API interface function, entry point function, and dependent function.
[0093] In order to ensure that the impact link corresponding to the test code can be accurately generated, when generating the impact link corresponding to the change function, it is possible to further determine whether the reference function of the API interface function and the entry point function corresponding to the target functional module are the same function. That is, it is further determined whether the target functional module calls the API interface function in actual application.
[0094] In specific implementation, the reference function referenced by the entry point function is first determined, and then the code similarity between the API interface function and the reference function is compared to determine whether the API interface function and the reference function are the same function.
[0095] In an optional embodiment, the specific implementation process of comparing the code similarity between the API interface function and the reference entry point function to determine whether the API interface function and the reference entry point function are the same function may include: obtaining a first function signature corresponding to the API interface function and a second function signature corresponding to the reference entry point function; vectorizing the first function signature and the second function signature respectively to obtain a first vectorized representation corresponding to the first function signature and a second vectorized representation corresponding to the second function signature; comparing the similarity between the first vectorized representation and the second vectorized representation to determine whether the API interface function and the reference entry point function are the same function.
[0096] Specifically, the Jaccard similarity coefficient corresponding to the API interface function and the reference function can be determined based on the first vectorized representation and the second vectorized representation; if the Jaccard similarity coefficient meets a preset threshold, it is determined that the API interface function and the reference function are the same function.
[0097] If it is determined that the API interface function and the reference function are the same function, then you can start from the entry point function and search down layer by layer according to the function reference relationship to determine the dependent functions that have a dependency relationship with the entry point function in turn.
[0098] Next, based on the function reference relationship, change function, API interface function, entry point function and dependent function, the impact link corresponding to the test code is generated.
[0099] In an embodiment of the present invention, before generating an impact link based on the entry point function, the code similarity between the API interface function and the reference function corresponding to the entry point is first compared to determine whether the API interface function and the reference function are the same function, and then it is determined whether the target functional module actually calls the API interface function, and then the dependent function is searched according to the entry point function. In this way, the impact link corresponding to the test code can be generated more accurately. Figure 5 A flowchart of another method for influencing link generation provided by an embodiment of the present invention is as follows: Figure 5 Specifically, the method may include the following steps:
[0100] 501. In response to a link generation request of a test code, obtain a development branch submission record corresponding to the test code.
[0101] 502. According to the development branch submission record, determine multiple changed functions in the test code.
[0102] 503. Filter out a target change function from the multiple change functions, where the target change function is a core function or a risk point change function.
[0103] 504. Determine the API interface function corresponding to the target change function.
[0104] 505. Determine a target functional module having a dependency relationship with the API interface function and an entry point function corresponding to the target functional module.
[0105] 506. Generate an impact link corresponding to the test code according to the target change function, the API interface function, and the entry point function.
[0106] After receiving the link generation request of the test code, in response to the link generation request of the test code, the development branch submission record corresponding to the test code is obtained, and multiple changed functions in the test code are determined according to the development branch submission record.
[0107] In actual applications, many changed functions will not have any impact on the system or there is no risk of change in the changed functions. Therefore, when generating the impact link corresponding to the test code, some changed functions can be filtered out, and only those core functions or risk point functions that have a significant impact on the system or process can be focused on, making the analysis process more efficient.
[0108] In the specific implementation, the target change function is selected from multiple change functions, and the target change function is a core function or a change risk point function. Then, the API interface function corresponding to the target change function is determined. The target function module that has a dependency relationship with the API interface function and the entry point function corresponding to the target function module are determined. Finally, based on the target change function, the API interface function and the entry point function, the impact link corresponding to the test code is generated.
[0109] The embodiment of the present invention can quickly identify key risk points and improve the generation efficiency of the impact link by filtering out a part of the changed functions and only generating the impact link for the core functions or the modified risk point functions.
[0110] For ease of understanding, please refer to the attached Figure 6 and attached Figure 7 The generation process of the impact link corresponding to the test code in the above specific application scenario is illustrated by example. First, use git to clone the code related to the test code to generate a local code library, which includes the code files corresponding to the development branch and the main branch (master branch). After receiving the link generation request for the test code, use git diff to obtain the development branch commit record and the master branch commit record. According to the development branch commit record and the master branch commit record, compare the development branch with the master branch to determine the changed files and which lines in the changed files have changed.
[0111] Next, parse the collection classes in these change files to determine which functions are included in the change files and the calling relationships between the functions. Specifically, the change files can be parsed by testing the Java tree corresponding to the code to determine how many functions are included in the change files, the function name, function implementation, input parameters, return value, etc. corresponding to each function, and the line number information of each function. The changed functions are determined by combining the line numbers corresponding to the changed content in the change files identified by git diff and the line numbers of each function parsed through the Java tree.
[0112] Then, according to the grammatical rules, the set of changed functions in each changed file is extracted, and the file name or file identifier to which the function belongs is recorded. And according to the function description (function identifier, function introduction information, etc.), the set of changed functions to be analyzed can be determined, and the set of changed functions to be analyzed can be screened based on whether the changed function is a core function and the change risk point. Tools or machines can also be used to complete this screening operation to determine whether the changed function is a core function or a change risk point function.
[0113] Next, based on the project function and configuration information, determine whether each change function is a core function or a change risk point. For example, in the payment scenario, the payment-related function is the change risk point function. After the target change function is selected from multiple change functions, the outermost call entry function (API interface function) is automatically found based on the target change function.
[0114] Then, based on the reference relationship corresponding to the parsed change function, determine who references the change function and who the change function references, determine the upper-level function corresponding to the change function, and determine the upper-level function corresponding to the upper-level function based on the reference relationship corresponding to the upper-level function. Determine each upper-level function in turn. When the outermost function found has an RPC identifier, the outermost calling function is found, and the outermost calling function is determined as the API interface function corresponding to the change function.
[0115] Then, analyze the project dependency projects, determine the dependency projects corresponding to the changed functions according to the service call collection file or pom.xml file, pull the dependency projects corresponding to the changed functions, and parse the overall structure of the project to extract the complete code structure corresponding to the project. Specifically, the code structure corresponding to each code file in the dependent project can be parsed through the Java syntax tree, including function information, class information, class attribute information, and function body information.
[0116] According to the code structure corresponding to each code file, the overall internal dependency and external dependency in each code file in the dependent project are parsed, and the API interface function corresponding to the changed function is determined according to the parsed internal dependency, external dependency and external call identifier of each code file. In addition, the special identifier of the RPC call can be identified according to the cluster RPC identifier and the external call identifier, so as to determine the API interface function corresponding to the changed function.
[0117] In addition, you can also establish a unified project identification management. Assign a unique identification to multiple dependent cluster projects, and obtain the complete function information of each cluster (including: function name, input parameters, return value, function package path) and function call relationship based on the identification.
[0118] According to the API interface function corresponding to the target change function and the set of dependent projects, determine whether the entry layer function of the dependent project calls the API interface function. By comparing the code similarity between the reference function corresponding to the entry layer function and the API interface function, it can be determined whether the API interface function and the reference function corresponding to the entry layer function in the dependent project are the same function, so as to determine whether there is a dependency relationship between the dependent project and the API interface function in the current situation.
[0119] Among them, Figure 7As shown, for the target change function, first pull all dependent projects that have a dependency relationship with the target change function, that is, project A, project B, and project C. Parse project A, project B, and project C, and perform grammatical semantic analysis to determine the java package path, member variables, method implementation, class information, etc. corresponding to each code file in each project. Then, based on this information, the function execution link in the code file can be obtained. According to the function execution link, determine the execution entry, that is, the entry layer function corresponding to each dependent project.
[0120] Compare whether the vectorized representations corresponding to the reference functions called by the API interface function and the entry layer function are the same to determine whether the two functions are the same function. If they are the same function, there is a dependency relationship. According to the entry layer function and the function reference relationship, the top layer link is determined. And the function name, function return value, formal parameter, path and other information corresponding to each function in the link are extracted, and then the function signature corresponding to each function is determined based on this information. Then, according to each function function, the complete dependency link is determined, and the complete execution link is determined based on the dependency link, the entry layer function, and the target change function. The execution link is the impact link corresponding to the test code. In this way, the cross-cluster impact range of the change function corresponding to the change code in the test code can be evaluated based on the automatically output impact link.
[0121] The embodiments of the present invention can be applied not only to the above-mentioned application scenarios, but also to many different application scenarios. The specific implementation methods can refer to the methods in the above-mentioned application scenarios, which will not be described in detail here.
[0122] The detailed execution process can be referred to the related descriptions in other aforementioned embodiments and will not be repeated here.
[0123] After the complete impact link is obtained in the above embodiment, the obtained impact link can also be displayed on the interface so that the staff can intuitively see the impact link corresponding to the test code and then evaluate the impact range of the change on the cross-cluster call situation.
[0124] Figure 8 A schematic diagram of a structure of an influencing link generation device provided by an embodiment of the present invention, such as Figure 8 As shown, the device includes: an acquisition module 11, a first determination module 12, a second determination module 13, a third determination module 14, and a generation module 15.
[0125] The acquisition module 11 is used to obtain the development branch submission record corresponding to the test code in response to the link generation request of the test code.
[0126] The first determining module 12 is used to determine the changed function in the test code according to the development branch submission record.
[0127] The second determining module 13 is used to determine the API interface function corresponding to the change function, and the API interface function is called by other function modules other than the function module where the change function is located.
[0128] The third determination module 14 is used to determine a target functional module having a dependency relationship with the API interface function and an entry point function corresponding to the target functional module, wherein the target functional module is a functional module other than the functional module where the change function is located.
[0129] The generating module 15 is used to generate the impact link corresponding to the test code according to the change function, the API interface function and the entry point function.
[0130] Optionally, the generation module 15 is specifically used to: determine the reference function corresponding to the entry point function; compare the code similarity between the API interface function and the reference function to determine whether the API interface function and the reference function are the same function; if the API interface function and the reference function are the same function, starting from the entry point function, according to the function reference relationship, search downward layer by layer to determine the dependent functions that have a dependency relationship with the entry point function in turn; generate the impact link corresponding to the test code according to the change function, the API interface function, the entry point function and the dependent function.
[0131] Optionally, the generation module 15 is specifically used to: obtain a first function signature corresponding to the API interface function and a second function signature corresponding to the reference function; respectively vectorize the first function signature and the second function signature to obtain a first vectorized representation corresponding to the first function signature and a second vectorized representation corresponding to the second function signature; compare the similarity between the first vectorized representation and the second vectorized representation to determine whether the API interface function and the reference function are the same function.
[0132] Optionally, the generation module 15 is specifically used to: determine the Jaccard similarity coefficient corresponding to the API interface function and the reference function according to the first vectorized representation and the second vectorized representation; if the Jaccard similarity coefficient meets a preset threshold, determine that the API interface function and the reference function are the same function.
[0133] Optionally, the first determination module 12 is specifically used to: obtain the main branch submission record corresponding to the test code; compare the development branch record and the main branch submission record to determine the changes in the test code; and determine the changed function in the test code based on the changes.
[0134] Optionally, the first determination module 12 is specifically used to: use a difference comparison command to compare the development branch record and the main branch submission record to determine the change file corresponding to the test code; determine the changed content in the change file and the line number corresponding to the changed content.
[0135] Optionally, the first determination module 12 is specifically used to: obtain a first abstract syntax tree corresponding to the test code; use the first abstract syntax tree to parse the change file to obtain the line number corresponding to each function in the change file; and determine the changed function corresponding to the changed content based on the line number corresponding to each function in the change file and the line number corresponding to the changed content.
[0136] Optionally, the first determining module 12 is specifically configured to: segment the test code into a plurality of lexical units; and organize the plurality of lexical units into a first abstract syntax tree according to a grammatical rule of the test code.
[0137] Optionally, the second determination module 13 is specifically used to: determine the upper-level function corresponding to the change function according to the reference relationship corresponding to the change function; identify whether the upper-level function carries an external call identifier, and if the upper-level function carries the external call identifier, determine the upper-level function as the API interface function corresponding to the change function; if the upper-level function does not carry the external call identifier, start from the change function and search upward layer by layer until the upper-level function carrying the external call identifier is found; determine the upper-level function carrying the external call identifier as the API interface function corresponding to the change function.
[0138] Optionally, the third determination module 14 is specifically used to: determine, according to the service call file, a target function module that has a dependency relationship with the API interface function; parse the source code of the target function module to construct a second abstract syntax tree corresponding to the target function module; extract, according to the second abstract syntax tree, a code structure corresponding to the target function module, the code structure including detailed information of each class, detailed information of each method, and detailed information of each attribute in the source code; determine an entry point function corresponding to the target function module according to the code structure and an external call identifier.
[0139] Figure 8 The device shown can execute the method for influencing link generation provided in the aforementioned embodiments. The detailed execution process and technical effects can be found in the description of the aforementioned embodiments, which will not be repeated here.
[0140] In one possible design, the above Figure 8 The structure of the link generation device shown can be implemented as an electronic device, such as Fig. 9 As shown, the electronic device may include: a processor 21, a memory 22, and a communication interface 23. The memory 22 stores executable codes, and when the executable codes are executed by the processor 21, the processor 21 can at least implement the influencing link generation method provided in the above embodiments.
[0141] In addition, an embodiment of the present invention provides a non-temporary machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the influencing link generation method provided in the aforementioned embodiment.
[0142] In addition, an embodiment of the present invention provides a computer program product. The computer program product includes a computer program or an instruction. When the computer program or the instruction is executed by a processor, the processor is enabled to implement the above Figure 1-7 The steps or functions of the method shown.
[0143] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. Those of ordinary skill in the art may understand and implement the present invention without creative effort.
[0144] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a computer product, and the present invention can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for generating an influence link, characterized in that: include: In response to a link generation request of a test code, obtaining a development branch submission record corresponding to the test code; Determine the changed function in the test code according to the development branch submission record; Determine an API interface function corresponding to the change function, where the API interface function is called by other function modules other than the function module where the change function is located; Determine a target function module having a dependency relationship with the API interface function and an entry point function corresponding to the target function module, wherein the target function module is a function module other than the function module where the change function is located; An impact link corresponding to the test code is generated according to the change function, the API interface function and the entry point function.
2. The method according to claim 1, characterized in that The generating, according to the change function, the API interface function and the entry point function, an impact link corresponding to the test code comprises: Determine a reference function corresponding to the entry point function; Comparing the code similarity between the API interface function and the reference function to determine whether the API interface function and the reference function are the same function; If the API interface function and the reference function are the same function, starting from the entry point function, searching downward layer by layer according to the function reference relationship, and determining the dependent functions that have a dependency relationship with the entry point function in turn; An impact link corresponding to the test code is generated according to the change function, the API interface function, the entry point function and the dependent function.
3. The method according to claim 2, characterized in that The comparing the code similarity between the API interface function and the reference function to determine whether the API interface function and the reference function are the same function includes: Obtain a first function signature corresponding to the API interface function and a second function signature corresponding to the reference function; Performing vectorization processing on the first function signature and the second function signature respectively to obtain a first vectorized representation corresponding to the first function signature and a second vectorized representation corresponding to the second function signature; The similarity between the first vectorized representation and the second vectorized representation is compared to determine whether the API interface function and the reference function are the same function.
4. The method according to claim 3, characterized in that The comparing the similarity between the first vectorized representation and the second vectorized representation to determine whether the API interface function and the referenced function are the same function includes: Determine, according to the first vectorized representation and the second vectorized representation, a Jaccard similarity coefficient corresponding to the API interface function and the reference function; If the Jaccard similarity coefficient meets a preset threshold, it is determined that the API interface function and the reference function are the same function.
5. The method according to claim 1, characterized in that The step of determining the changed function in the test code according to the development branch submission record includes: Obtaining the main branch submission record corresponding to the test code; Comparing the development branch record with the main branch submission record to determine the changes in the test code; According to the changed content, a changed function in the test code is determined.
6. The method according to claim 5, characterized in that The comparing the development branch record with the main branch submission record to determine the changes in the test code includes: Use a difference comparison command to compare the development branch record and the main branch submission record to determine the change file corresponding to the test code; Determine the changed content in the change file and the line number corresponding to the changed content.
7. The method according to claim 6, characterized in that The step of determining the changed function in the test code according to the changed content includes: Obtain a first abstract syntax tree corresponding to the test code; Parsing the change file using the first abstract syntax tree to obtain a line number corresponding to each function in the change file; According to the line number corresponding to each function in the change file and the line number corresponding to the change content, the change function corresponding to the change content is determined.
8. The method according to claim 7, characterized in that The obtaining a first abstract syntax tree corresponding to the test code includes: Splitting the test code into a plurality of lexical units; According to the grammatical rules of the test code, the multiple lexical units are organized into a first abstract syntax tree.
9. The method according to claim 1, characterized in that: The step of determining the API interface function corresponding to the change function includes: Determine the upper layer function corresponding to the change function according to the reference relationship corresponding to the change function; Identify whether the upper-layer function carries an external call identifier, and if the upper-layer function carries the external call identifier, determine the upper-layer function as the API interface function corresponding to the change function; If the upper layer function does not carry the external call identifier, start from the changed function and search upward layer by layer until the uppermost layer function carrying the external call identifier is found; The top-level function carrying the external call identifier is determined as the API interface function corresponding to the change function.
10. The method according to claim 1, characterized in that The determining of a target function module having a dependency relationship with the API interface function and an entry point function corresponding to the target function module includes: According to the service call file, determine the target function module that has a dependency relationship with the API interface function; Parsing the source code of the target functional module to construct a second abstract syntax tree corresponding to the target functional module; Extracting a code structure corresponding to the target functional module according to the second abstract syntax tree, wherein the code structure includes detailed information of each class, detailed information of each method, and detailed information of each attribute in the source code; According to the code structure and the external call identifier, an entry point function corresponding to the target functional module is determined.
11. An electronic device, characterized in that: include: A memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the method for influencing link generation as described in any one of claims 1 to 10.
12. A non-transitory machine-readable storage medium, characterized in that: The non-transitory machine-readable storage medium stores executable code, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the influencing link generation method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Method for determining function point changing through code analysis
CN101286119A
Accurate regression testing method and device under micro-service architecture
CN111258876A
Interface influence detection method and related equipment
CN114579452A
Method and device for parsing and displaying interface function, and computer storage medium
WO2014176976A1