Code change influence range analysis method and system based on calling relationship

文档序号:168451 发布日期:2021-10-29 浏览:34次 中文

阅读说明:本技术 一种基于调用关系的代码变更影响范围分析方法及系统 (Code change influence range analysis method and system based on calling relationship ) 是由 刘勤意 于 2021-07-23 设计创作,主要内容包括:本发明涉及一种基于调用关系的代码变更影响范围分析方法及系统,使用所述条件分支代码行号范围、代码调用关系、变更代码影响模型和输入输出变量名行号关系分析获得所述变更代码行号所对应的全部影响范围代码行号,可以很准确的定位分析出代码变更行对于其他代码的影响范围,尤其是对于存在调用关系以及多条件分支情况下的代码影响范围分析更加准确,可以有效的减少传统方法进行代码变更影响范围分析的冗余数据,以及改善存在调用关系以及多条件分支情况下影响范围的数据的准确性。(The invention relates to a code change influence range analysis method and system based on a calling relation, which are used for analyzing and obtaining all influence range code line numbers corresponding to a change code line number by using a conditional branch code line number range, a code calling relation, a change code influence model and an input/output variable name line number relation, can accurately position and analyze the influence range of the code change line on other codes, and particularly can more accurately analyze the code influence range under the condition of calling relation and multi-condition branch, thereby effectively reducing redundant data of code change influence range analysis performed by a traditional method and improving the accuracy of the data of the influence range under the condition of calling relation and multi-condition branch.)

1. A code change influence range analysis method based on calling relationship is characterized by comprising the following steps:

comparing the change code file with the current version code file, and analyzing to obtain a change code line number and a conditional branch code line number range under different branches;

establishing a code calling relation based on a conditional branch function;

establishing a change code influence model;

establishing a name line number relationship of input and output variables;

and analyzing the relationship among the line number range of the conditional branch code, the code calling relationship, the change code influence model and the line number of the input/output variable name to obtain the code line number of all influence ranges corresponding to the change code line number.

2. The method of claim 1, wherein obtaining all impact range code line numbers corresponding to the change code line number using the conditional branch code line number range, code call relationship, change code impact model, and input output variable name line number relationship analysis comprises:

inquiring change code influence range data under the change code influence model;

judging whether the data of the influence range of the change code influences the input and output variable values;

when the influence range data of the change codes do not influence the input and output variable values, assembling the influence range data of the change codes to obtain the line numbers of all the influence range codes;

when the changed code influence range data influences the input and output variable values, inquiring subsequent line range data with the input and output variable values in the line number range of the current conditional branch code through the name line number relationship and the code calling relationship of the input and output variable;

and assembling the change code influence range data and the subsequent line range data to obtain the code line number of the whole influence range.

3. The method of claim 2, wherein the establishing a conditional branch function based code call relationship comprises:

compiling the line number of the change code and the line number range of the conditional branch code under different branches by using java source codes to generate a class file;

and analyzing by using java byte codes to obtain a code calling relation based on a conditional branch function, wherein child node information related to the function comprises a code branch condition line, a code line of the function, a file name of the function, all code lines in the function, whether input parameters are influenced and called function information.

4. The method of claim 2, wherein the establishing a change code impact model comprises:

analyzing whether the code line under the code line number of the change affects the value of the input and output variables;

when the code line has a function call relation under the change code line number, inquiring whether the function call relation influences the input and output variable value;

and assembling the affected input and output variable values into a change code influence model, wherein the parameters related to the change code influence model comprise whether the change code changes the input parameters, the line number of the change code and the name of the input and output variable.

5. The method of claim 2, wherein establishing an input-output variable name row number relationship comprises:

inquiring all related code lines affected by the change under the function calling relation according to the change code effect model;

judging whether the related code line belongs to different branches, if so, removing codes under other branches from the related code line;

further judging whether the relevant code line is influenced by the input and output variable value, and acquiring a part containing the input and output variable name in the relevant code line;

and comparing the line number of the change code containing the input and output variable name with the line number of the subsequent line containing the input and output variable name and establishing a line number relationship.

6. A code change influence scope analysis system based on call relations, comprising:

the system comprises a change code preprocessing module, a condition branch code preprocessing module and a condition branch code preprocessing module, wherein the change code preprocessing module is used for analyzing and obtaining a change code line number and a conditional branch code line number range under different branches;

the code calling relation generating module is used for establishing a code calling relation based on the conditional branch function;

the change code influence model generation module is used for establishing a change code influence model;

the input and output variable name row number relation generating module is used for establishing an input and output variable name row number relation;

and the influence range code line number analysis module is used for analyzing and obtaining all influence range code line numbers corresponding to the change code line numbers.

7. The system of claim 6, wherein the scope of influence code line number analysis module comprises:

and the change code influence range data judgment submodule is used for judging whether the change code influence range data influences the input and output variable values.

8. A computer-readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when being executed by a processor, carries out the method of any one of claims 1 to 5.

9. An electronic device comprising a processor and a memory;

the memory is used for storing a change code file and a current version code file;

the processor is used for executing the method of any one of claims 1 to 5 by calling the change code file and the current version code file.

Technical Field

The invention relates to the technical field of software testing, in particular to a code change influence range analysis method and system based on a calling relationship.

Background

The current software functions are increasing and the complexity is increasing, and the amount of code of the software is increasing. In order to upgrade software services and repair vulnerabilities, in many scenarios, developers need to change existing code. However, as the software itself is more and more complex, and the relationship between calling and called is hidden in many codes, the research and development personnel cannot determine whether the modified content will affect other parts of the software after modifying the codes, and the testing personnel needs to fully consider the influence range of code change and perform testing, and if the testing is not complete, problems may occur after the software is on-line.

In the prior art, the influence of analyzing code change by testers generally depends on manual analysis, analysis through grammar and lexical method or a target symbol searching method. The manual analysis method needs a tester to manually analyze and search the code change influence range so as to design a comprehensive test case to ensure the comprehensiveness and the quality of the test. However, because the amount of code is iterated continuously, researchers have to understand the logic and structure of the code more and more complicated, it is difficult to analyze the influence range of the changed code when the complexity of the code is high, manual analysis is time-consuming and labor-consuming, and omission occurs, so that the efficiency is very low; the method is carried out by a grammar and lexical analysis method, or by searching a range file influenced by a target symbol (function, method, variable and the like), the searched structure possibly comprises redundant data, the realization difficulty is high, accurate influence range analysis can not be carried out under the condition that a code has a conditional branch relation, and omission exists when a call relation exists.

Disclosure of Invention

In order to overcome the defects of the prior art, the invention provides a code change influence range analysis method and system based on a calling relationship, which can accurately position and analyze the influence range of a code change line on other codes, especially more accurately analyze the code influence range under the condition of the existence of the calling relationship and multiple condition branches, effectively reduce redundant data of code change influence range analysis performed by a traditional method, and improve the accuracy of the data of the influence range under the condition of the existence of the calling relationship and the multiple condition branches.

In order to achieve the above purpose, the technical scheme adopted by the invention comprises the following steps:

a code change influence range analysis method based on calling relationship is characterized by comprising the following steps:

comparing the change code file with the current version code file, and analyzing to obtain a change code line number and a conditional branch code line number range under different branches;

establishing a code calling relation based on a conditional branch function;

establishing a change code influence model;

establishing a name line number relationship of input and output variables;

and analyzing the relationship among the line number range of the conditional branch code, the code calling relationship, the change code influence model and the line number of the input/output variable name to obtain the code line number of all influence ranges corresponding to the change code line number.

Further, the obtaining of all influence range code line numbers corresponding to the change code line number by using the conditional branch code line number range, the code call relationship, the change code influence model and the input/output variable name line number relationship analysis includes:

inquiring change code influence range data under the change code influence model;

judging whether the data of the influence range of the change code influences the input and output variable values;

when the influence range data of the change codes do not influence the input and output variable values, assembling the influence range data of the change codes to obtain the line numbers of all the influence range codes;

when the changed code influence range data influences the input and output variable values, inquiring subsequent line range data with the input and output variable values in the line number range of the current conditional branch code through the name line number relationship and the code calling relationship of the input and output variable;

and assembling the change code influence range data and the subsequent line range data to obtain the code line number of the whole influence range.

Further, the establishing a code calling relation based on the conditional branch function includes:

compiling the line number of the change code and the line number range of the conditional branch code under different branches by using java source codes to generate a class file;

and analyzing by using java byte codes to obtain a code calling relation based on a conditional branch function, wherein child node information related to the function comprises a code branch condition line, a code line of the function, a file name of the function, all code lines in the function, whether input parameters are influenced and called function information.

Further, the establishing a change code impact model comprises:

analyzing whether the code line under the code line number of the change affects the value of the input and output variables;

when the code line has a function call relation under the change code line number, inquiring whether the function call relation influences the input and output variable value;

and assembling the affected input and output variable values into a change code influence model, wherein the parameters related to the change code influence model comprise whether the change code changes the input parameters, the line number of the change code and the name of the input and output variable.

Further, the establishing of the input/output variable name line number relationship includes:

inquiring all related code lines affected by the change under the function calling relation according to the change code effect model;

judging whether the related code line belongs to different branches, if so, removing codes under other branches from the related code line;

further judging whether the relevant code line is influenced by the input and output variable value, and acquiring a part containing the input and output variable name in the relevant code line;

and comparing the line number of the change code containing the input and output variable name with the line number of the subsequent line containing the input and output variable name and establishing a line number relationship.

The invention also relates to a code change influence range analysis system based on the calling relationship, which is characterized by comprising the following steps:

the system comprises a change code preprocessing module, a condition branch code preprocessing module and a condition branch code preprocessing module, wherein the change code preprocessing module is used for analyzing and obtaining a change code line number and a conditional branch code line number range under different branches;

the code calling relation generating module is used for establishing a code calling relation based on the conditional branch function;

the change code influence model generation module is used for establishing a change code influence model;

the input and output variable name row number relation generating module is used for establishing an input and output variable name row number relation;

and the influence range code line number analysis module is used for analyzing and obtaining all influence range code line numbers corresponding to the change code line numbers.

Further, the influence range code line number analysis module comprises:

and the change code influence range data judgment submodule is used for judging whether the change code influence range data influences the input and output variable values.

The invention also relates to a computer-readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when being executed by a processor, carries out the above-mentioned method.

The invention also relates to an electronic device, characterized in that it comprises a processor and a memory;

the memory is used for storing a change code file and a current version code file;

the processor is used for executing the method by calling the change code file and the current version code file.

The invention has the beneficial effects that:

by adopting the code change influence range analysis method and system based on the calling relation, the influence range of a code change line on other codes can be accurately positioned and analyzed, the code influence range under the condition of calling relation and multi-condition branch is more accurately analyzed, redundant data of code change influence range analysis by other traditional methods and the accuracy of data of the influence range under the condition of calling relation and multi-condition branch can be effectively reduced, the accuracy and the efficiency of analyzing data of the influence range are improved, and the problem that the calculation of the influence range is inaccurate when the redundant data of the influence range and the code call function relation exist is solved.

Drawings

FIG. 1 is a schematic flow chart of a code change influence range analysis method based on a call relation according to the present invention.

FIG. 2 is a schematic diagram of a system for analyzing the influence range of code change based on call relations.

Detailed Description

For a clearer understanding of the contents of the present invention, reference will be made to the accompanying drawings and examples.

The first aspect of the present invention relates to a code change influence scope analysis method based on call relation as shown in fig. 1, including:

comparing the change code file with the current version code file, and analyzing to obtain a change code line number and a conditional branch code line number range under different branches;

establishing a code calling relation based on a conditional branch function, particularly compiling a change code line number and a range of the conditional branch code line number under different branches by using java source codes to generate a class file; using java byte code analysis to obtain a code calling relation based on a conditional branch function, wherein child node information related to the function comprises a code branch condition line, a function code line, a file name, all code lines in the function, whether input parameters are influenced and called function information;

establishing a change code influence model, particularly analyzing whether a code line under a change code line number influences an input and output variable value; when the code line has a function call relation under the change code line number, inquiring whether the function call relation influences the input and output variable value; assembling the affected input and output variable values into a change code influence model, wherein parameters related to the change code influence model comprise whether the change code changes the input parameters, a change code line number and an input and output variable name;

establishing a line number relationship of input and output variable names, particularly judging whether related code lines belong to different branches, and if the related code lines belong to different branches, removing codes under other branches from the related code lines; further judging whether the relevant code line is influenced by the input and output variable value, and acquiring a part containing the input and output variable name in the relevant code line; comparing the line number of the change code containing the input and output variable name with the line number of the subsequent line containing the input and output variable name and establishing a line number relationship;

inquiring change code influence range data under the change code influence model;

judging whether the data of the influence range of the change code influences the input and output variable values;

when the influence range data of the change codes do not influence the input and output variable values, assembling the influence range data of the change codes to obtain the line numbers of all the influence range codes;

when the changed code influence range data influences the input and output variable values, inquiring subsequent line range data with the input and output variable values in the line number range of the current conditional branch code through the name line number relationship and the code calling relationship of the input and output variable;

and assembling the change code influence range data and the subsequent line range data to obtain the code line number of the whole influence range.

The invention also relates to a code change influence range analysis system based on the calling relationship and having the structure shown in FIG. 2, which comprises:

the system comprises a change code preprocessing module, a condition branch code preprocessing module and a condition branch code preprocessing module, wherein the change code preprocessing module is used for analyzing and obtaining a change code line number and a conditional branch code line number range under different branches;

the code calling relation generating module is used for establishing a code calling relation based on the conditional branch function;

the change code influence model generation module is used for establishing a change code influence model;

the input and output variable name row number relation generating module is used for establishing an input and output variable name row number relation;

and the influence range code line number analysis module is used for analyzing and obtaining all influence range code line numbers corresponding to the change code line numbers.

The method may be performed by using the system, and for example, analyzing a single line of code, the method may specifically include the following steps:

and S1, acquiring a code change file submitted by a user through a code platform, and calculating a change code line number through a gitdiff file.

S2, resolving the conditional branch code line number range under different branches through a java byte code technology, and establishing a relation according to different file names, such as ("/com/base/application.

S3, establishing a code calling relation based on the conditional branch function by using the asm byte code analysis technology based on java, wherein the child node information of each function comprises a code branch condition line, a function code line, a file name, all code lines in the function, whether input parameters are influenced and called function information. Each function call relationship may be a tree type data structure.

S4, searching the code line of the function in the code calling relation in S3 according to the code changing line code line, and if the function calling is not inquired, directly analyzing whether the current code line influences the input and output variable value. And if the function call exists, further inquiring whether the function call relation data influences the input variable value.

And S5, establishing a change code influence model, wherein the parameters of the model comprise whether the change code changes the input parameters, the line number of the change code and the input and output variable name.

S6, establishing the line number relationship between the internal change line number of the method and the subsequent line of the change line which refers to the input and output variable name. According to the change code influence model obtained in S5, the intra-function code line number in the code call relation obtained in S3 queries all codes under the current function change influence line (related code line). And judging whether the current change code is in the branch code range or not according to the range of the conditional branch code line number under different branches acquired in the step S2, acquiring the range lines of other branches if the current change code is in the branch code range, and removing the codes under other branches from the related code lines. It should be noted that the file name of the changed code needs to be found first, and then the branch range is queried according to the file name, such as ("com/pop/mh/kk. java", { [1,2.3], [6, 8,11]), and if the current code changes behavior 2, the change affects all behaviors below the row [2,6,8,9,18], then all code rows below the current change affects the row are [2,9,18 ].

And S7, judging whether the input and output variable names in the change code influence model have influence, if the input and output variable names have influence, inquiring codes of all lines below the acquired change influence line, and acquiring the code line containing the input and output variable names. If the input/output variable value has no influence, the calculation of the influence range of the current code line is completed, and the process goes to S13.

S8, establishing a line number relation between the change line number inside the method and the code line with the input and output variable name in the subsequent line of the change line, wherein the relation comprises a file name and a method name, such as (com/push/m. java "," func "," 2 ", [9,10,11 ]).

And S9, sequentially inquiring the function based on the conditional branch function code calling relation acquired in S3 according to the line number and the file name according to the line number relation of the input and output variable names acquired in S8, and acquiring the function if the inquired function affects the input and output variable values.

S10, according to the entry of the function in S9, all internal code lines of the function are queried, all code lines (code lines inside the function) referring to the parameter are obtained, if the current change code is in the branch code range, the range lines of other branches are obtained, and all code lines referring to the parameter need to remove the range lines of other branches.

S11, establishing the line number relationship between the internal change line number of the method and the code line containing the input/output variable name in the subsequent line of the change line, especially establishing the relationship according to the file name.

S12, repeating S9 until no function call or the function does not influence the input and output variables is finished, and the final result is the relation map data of a plurality of file names and code change influence lines.

And S13, assembling all code change influence range data, establishing a relation according to the file name and the influence range row, and removing duplication. Here, the method internal change line number of S6 needs to be merged with the line number relationship of the change line subsequent to the change line referring to the input/output variable name for deduplication. The final structure is, for example, ("com/push/m.java", [1,5,6,8]), ("com/pk/k.java", [2,6,8,9 ]).

By the method, the change influence range of java codes of code changes submitted by branches on the gitlab can be obtained, the code range lines of all affected files are included, and the influence ranges of corresponding different lines of codes can be respectively obtained by repeating the process for each line of codes.

Further, the present invention relates to a readable storage medium storing a program for executing the code change influence range analysis method based on call relations, the program being executable by using the readable storage medium to implement the code change influence range analysis method based on call relations.

Further, the present invention relates to an electronic device comprising a memory for storing data necessary for executing the above-mentioned call relation-based code change influence range analysis method and a processor for executing the call relation-based code change influence range analysis method.

The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

10页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:代码预取指令

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!