A static analysis method and system for multi-version software evolution history based on text comparison

Through the static analysis method of multi-version software evolution history based on text comparison, using cosine similarity matching and preprocessing annotations, the problem of complex software evolution history tracking is solved, and efficient software evolution history analysis and report generation are achieved, which is suitable for complex software Evolutionary history analysis.

CN113110871BActive Publication Date: 2024-09-06SOUTHEAST UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110462336.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-27
Publication Date
2024-09-06
Estimated Expiration
2041-04-27

AI Technical Summary

Technical Problem

Existing static analysis technology is difficult to efficiently track software evolution history when faced with complex and rapidly evolving software. Moreover, traditional methods require high accuracy and efficiency of source code files, and cannot handle redundant annotations.

Method used

A multi-version software evolution history static analysis method based on text comparison is used to generate an evolution history analysis report through cosine similarity matching of file contents and preprocessing annotations, simplifying the software evolution history analysis process and improving the accuracy and efficiency of the analysis.

Benefits of technology

It realizes the automatic calculation and positioning of the evolution history of multiple versions of software, improves the efficiency of information acquisition, reduces operating costs, can handle redundantly annotated source code files, and reduces the analysis burden of developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113110871B
    Figure CN113110871B
Patent Text Reader

Abstract

The invention discloses a static analysis method of multi-version software evolution history based on text comparison, the method comprising the following steps: step 1) arranging files of multiple different versions of software in chronological order, step 2) using a method for calculating the cosine similarity of program file contents, step 3) obtaining the differences in program file contents and obtaining a method change table; step 4) obtaining a file change table, step 5) obtaining measurement data and obtaining an evolution history analysis report. The method statically analyzes program data flow and control flow structure, and utilizes software program structure hierarchical calculation; supports concurrent calculations at different levels, and has a simple process and low cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a multi-version software adaptive static analysis method based on text comparison, and belongs to the field of software maintenance and software evolution. Background Art

[0002] Program analysis refers to manual or automated analysis of computer programs to confirm or discover whether their characteristics, such as performance, correctness, and security, meet expectations. The analysis process is based on whether the program under test needs to be run. Program analysis can be divided into two categories: static analysis and dynamic testing. Generally speaking, dynamic testing obtains specific running information, so the defects reported are more accurate, but it can only check limited test cases and the conditions are relatively harsh. Static analysis can consider possible execution paths more comprehensively, can discover more defects, and the conditions are relatively simple. Lu Shenming et al. proposed in the article "Progress in the Study of Parallelization of Static Program Analysis" that in addition to defect detection, static analysis can also be used for program understanding, repair, and test case generation, and is an important research direction in the field of programming languages ​​and software engineering.

[0003] Yuan Jumao pointed out in "Research on Annotation Transfer Technology Based on Static Program Analysis" that program static analysis refers to a code analysis technology that verifies whether the code meets the standards of standardization, security, etc. by scanning the program code without running the code. Common static program analysis technologies include lexical analysis, syntax analysis, control flow analysis, data flow analysis, and taint analysis. Among them, data flow analysis is one of the commonly used analysis modes for static difference analysis. It can collect semantic information from the program and make the semantic information set stable through continuous iteration to determine the definition and use of variables. The data flow problem is to solve a set of constraints. Constraints are divided into two categories, one is semantic-based constraints, and the other is control flow-based constraints.

[0004] After years of development, static analysis has made great progress in many aspects, but it still faces many challenges. Zhang Xin pointed out in the article "Mobile Crowdsourcing Test Guidance Technology Based on the Combination of Dynamic and Static Program Analysis" that with the advancement of the information age, software has become the infrastructure of modern society. With the continuous extension of software functions and application scope, the widespread reuse of general functional software has made the software structure increasingly complex and the software scale has continued to increase, which has put forward higher or newer requirements in terms of accuracy, efficiency, scalability and versatility.

[0005] Based on the results of previous static analysis, this paper innovatively proposes a static analysis method for multi-version historical evolution. By statically analyzing the texts of multiple versions of a software, the differences between different versions are obtained, such as changes in variable names, addition or deletion of blank lines, etc. Summary of the Invention

[0006] The present invention provides a static analysis method for multi-version software evolution history based on text comparison, which can automatically calculate the software evolution history by using the hierarchical characteristics of the source code structure of the program, can analyze and locate the software evolution process according to the source code, and has the advantages of easy information acquisition and high operation efficiency.

[0007] In order to achieve the above object, the technical solution of the present invention is as follows: The static analysis method for multi-version software evolution history based on text comparison of the present invention includes the following steps:

[0008] Step 1) Arrange the files of multiple different versions of the software in chronological order, such as A 0 , B 0 , C 0 , …, N 0 . Starting from A 0 , B 0 , take out two adjacent files for subsequent analysis operations each time until all adjacent files are analyzed. Taking the analysis of A 0 , B 0 as an example, save the two different versions of files A 0 and B 0 locally. Obtain and scan the source codes of all program files of the software through the local absolute paths respectively, and delete the comments in the source code to obtain files A and B without comments;

[0009] Step 2) Use the method of calculating the cosine similarity of the content of the program files to match the program files to be compared in files A and B, and store the local absolute paths of the program files into two sets FA and FB respectively. For a given integer set subscript i, FA i and FB i store the local absolute paths of the program files to be compared in the i-th pair of A and B to be compared, and |FA| = |FB|. The local absolute paths of the un-matched program files in A and B are stored in sets UFA and UFB respectively;

[0010] Step 3) For sets FA and FB, traverse i (0 < i < |A|), obtain the content of the program files from FA i and FB i , use the method based on text comparison to obtain the differences in the content of the program files and obtain the method change table;

[0011] Step 4) For the set UFA, traverse j (0 < j < |UFA|) to obtain the newly added and deleted program files in A; for the set UFB, traverse k (0 < k < |UFB|) to obtain the newly added and deleted program files in B, and obtain the file change table.

[0012] Step 5) For A 0 , B 0 , C 0 , …, N 0 After analyzing adjacent files among these N files, obtain N - 1 file change tables and method change tables, acquire measurement data, and obtain the evolutionary history analysis report.

[0013] In the preferred embodiment of the method of the present invention, the specific process of matching the program files to be compared in step 2) is as follows:

[0014] 21) For the program files with the same file name in A and B, consider them as matching program files, and store their local absolute paths in the corresponding positions with the same subscript in the sets FA and FB;

[0015] 22) For the program files with different file names in A and B, record the subscripts of the integer sets as m and n respectively. According to the local absolute paths A m and B n obtain the source code CA m and CB n of the program files. Compare the cosine similarity of CA m and CB n . If the cosine similarity is greater than or equal to a threshold, consider the program files corresponding to the local absolute paths A m and B n as matching, and store them in the sets FA and FB respectively;

[0016] 23) The files that still cannot be matched after the above steps 21) and 22) are considered as mismatched files, and are respectively grouped into the sets UFA and UFB. The sets UFA and UFB are used to generate the file change table, constituting the newly added and deleted file parts.

[0017] In the method of the present invention, the specific process of obtaining the content difference of the program files by using the text comparison - based method in step 3) is as follows:

[0018] 31) For the sets FA and FB, traverse y (0 < y < |A|), and obtain the content of the program files from FA y and FB y respectively, and record them as CA y and CB y . For CA y and CB yFor functions with the same function headers, they are considered matching functions, and the function headers are stored in sets KA and KB respectively, where |KA| = |KB|;

[0019] 32) For CA i and CB i For functions with different function headers, the function bodies RA(y, r) and RB(y, d) are obtained based on the function headers CA(y, r) and CB(y, d). If the cosine similarity between RA(y, r) and RB(y, d) is greater than or equal to a threshold, the functions corresponding to the function headers CA(y, r) and CB(y, d) are considered matching, and the function headers are stored in sets KA and KB respectively, where |KA| = |KB|;

[0020] 33) Functions that are still not matched after the above steps 31) and 32) are considered mismatched functions, and they form sets UKA and UKB respectively;

[0021] 34) For set UKA, traverse q (0 < q < |UKA|) to obtain the newly added and deleted function headers in A; for set UKB, traverse t (0 < t < |UKB|) to obtain the newly added and deleted function headers in B. The information of the newly added and deleted function headers in A and B is used to generate a method change table.

[0022] In the method of the present invention, in step 5), the specific process of obtaining the measurement data from the file change table and the method change table to obtain the evolution history analysis report is as follows.

[0023] 51) The following measurement data can be obtained:

[0024] NI: The number of software iterations;

[0025] CN: The number of file changes;

[0026] CL: The number of lines of code that have been modified in the source code entities;

[0027] TCL: The total number of lines of code that have been modified in the source code entities.

[0028] The calculation methods of each measurement index are as follows:

[0029] (1) The change frequency CF is the number of file changes divided by the total number of software iterations.

[0030] CF = CN / NI;

[0031] (2) The change weight CW reflects the proportion of file changes in the total changes during the software iteration process, and can be obtained by dividing the file code change scale by the total change scale.

[0032] CW = CL / TCL;

[0033] 52) Analyze frequently changed files based on change frequency and change weight sorting, and generate an evolution history analysis report.

[0034] The method of the present invention pre-processes the source code files under the path, classifies them according to features, and outputs them according to class names and method names. Compared with the prior art, the method of the present invention has the following advantages:

[0035] (1) Allowing redundant comments to exist in the source code files that need to be compared. After searching for information, it is found that the coverage-based fault location technology has high requirements for source code files, and redundant comments are not allowed in source code files. However, the present invention allows the source code files to be in the original state of comments, and automatically deletes the comments by preprocessing the redundant parts of the comments, eliminating the problem of inefficient manual deletion of comments.

[0036] (2) Innovative file matching method. When judging whether two files are similar and can be matched, the present invention innovatively uses the cosine similarity method to judge whether the similarity of the file content or function content is greater than 0.94. If it is greater than this value, the two files are considered to be matchable and further matched. Compared with the traditional method, this approach increases the tolerance of different versions of files and avoids the problem of mismatch caused by minor deletions and modifications of files as much as possible.

[0037] (3) The evolution history analysis of multiple versions of software is realized, and it does not rely on other technologies such as version controllers, making the process simple and low-cost. The evolution history analysis report proposed by the present invention is in chronological order, clearly indicating the similarities and differences between different versions of the software, as well as the program files and methods that are frequently modified. It is convenient for developers to track the modification history of program files and methods, reducing the analysis burden. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 is a flow chart of the method of the present invention.

[0039] Figure 2 It is a diagram of an embodiment of the present invention, showing relevant contents in the embodiment. DETAILED DESCRIPTION

[0040] The technical solution of the invention is described in detail below with reference to the accompanying drawings:

[0041] The present invention statically analyzes the program data flow and control flow structure and utilizes the software program structure for hierarchical calculation; it supports concurrent calculations at different levels, has a simple process and is low in cost.

[0042] Example 1: See Figure 1 ,A static analysis method for multi-version software evolution history based on text comparison for designing architecture,

[0043] 1. Architecture

[0044] Figure 1 The paper presents a design architecture of a static analysis method for multi-version software evolution history based on text comparison. The following is a detailed description of several main parts.

[0045] 1 Pre-processing components

[0046] The function of this component is: take two adjacent files from the file queue each time, obtain and scan the source code of all program files of the software through the local absolute path, delete the comments and blank lines in the source code, and get the file without comments by deleting the comments in the file. The main purpose of preprocessing is to eliminate interference during file comparison and improve the correctness of static analysis.

[0047] 2. File matching and comparison components

[0048] The main function of this component is to match the preprocessed files, obtain the matching program files and mismatched program files, and generate a file change table; the matching program files serve as the input of the method matching and comparison components, and the file change table serves as the input of the metric acquisition and evolution history analysis components.

[0049] 3 Method Matching and Comparison Components

[0050] The main function of this component is to match the methods in the source code of the matching program files to obtain the matching methods and mismatching methods, as well as the changes in the matching methods accurate to the source code line, and thus generate a method change table as a prerequisite for obtaining measurement indicators and evolution history analysis.

[0051] 4. Metrics Acquisition Components

[0052] The main function of this component is to use the file change table and method change table to automatically count the measurement data: the number of software iterations, the number of file changes, the number of code lines changed in the source code entity, and the total number of code lines changed in the source code entity, so as to calculate the measurement indicators: change frequency and change weight as the input of the evolution history analysis component.

[0053] 5 Evolutionary History Analysis Components

[0054] The main function of this component is to automatically analyze frequently changed files based on the acquired file change table, method change table and metrics; focus the analysis on frequently changed files, generate an evolution history analysis report, and provide assistance for other software maintenance and software evolution technologies.

[0055] Embodiment 2: A static analysis method of multi-version software evolution history based on text comparison, the specific process is as follows:

[0056] Suppose we need to use the method in this article to statically analyze the differences between two versions of a software. We put all the files of the two versions of the software in two corresponding folders, and then perform the following steps to analyze and get the results:

[0057] Step 1) Preprocess all the files to be compared in the two folders: Taking C++ as an example, there are two types of comments in C++: a line of comments starts with / / and ends with a newline; a multi-line comment starts with / * and ends with * / . We use all the files in the two folders as input files. During the input process, we determine whether / / appears continuously in the characters of the input stream. Once / / appears, we ignore the string starting from / / to the end of the newline, that is, we do not add them to the result string; similarly, if / * appears continuously in the characters of the input stream, we ignore the string starting from / * to the end of * / , that is, we do not put the content in the result string. After processing all the input strings, we can get the result string, and output the result string to get the preprocessed file.

[0058] Step 2) Find the "corresponding files" in the two folders: After a file in the previous version of the software is added, deleted or modified, it is obtained as a file in the next version. We define these two files as "corresponding files" to each other. First, we find the two folders that store the files to be matched according to the absolute path of the folder, and then get the file names of all the files therein and store them in two containers respectively, and then determine which file names in the two containers are the same. Two files with the same file name are directly considered as "corresponding files". If the file names are different, calculate the cosine similarity between the content of a file in the previous version and the content of all files in the next version. After many experiments, the best effect is achieved when the cosine similarity threshold is 0.94, that is, when the cosine similarity between two files exceeds 0.94, we consider the two files to be "corresponding files". Record each pair of "corresponding files" and uncorresponding files in the file change table.

[0059] Step 3) Compare the differences between each group of corresponding files. After the above steps, we have obtained each group of "corresponding files" of the two versions. For a group of corresponding files in the file change table, we locate the function header in the file, and for the matching function header, we solve the longest common subsequence in the function body based on the dynamic programming method to obtain the corresponding matching words in the two files, that is, the words that have not been changed in the two versions. For words that cannot be found with matching objects, we think that these words have been deleted or added, record the deletion and addition information of these words, and obtain the static analysis results of the two corresponding files. After obtaining the static analysis results of all groups of "corresponding files", record the deletion and modification information of all "corresponding files" in the method change table.

[0060] Step 4) According to the file change table and method change table obtained in step 2 and step 3, automatically count the measurement data: the number of software iterations, the number of file changes, the number of lines of code changed in the source code entity, and the total number of lines of code changed in the source code entity, so as to calculate the measurement indicators: change frequency and change weight. After obtaining the measurement indicators, the frequently changed files are automatically analyzed and an evolution history analysis report is generated to provide assistance for other software maintenance and software evolution technologies.

[0061] Application examples:

[0062] For the convenience of description, we assume the following simplified application example: the target folder structure is as follows Figure 2 As shown, the target program source codes of the two files to be compared are shown in the following table. Assume that two versions of the software are stored in the paths D:\testfiles1 and D:\testfiles2, respectively, and the folders are marked as A and B, respectively, and the contents are shown in the following table.

[0063]

[0064] According to the calculation steps we mentioned above, implement them one by one:

[0065] In the first step, the preprocessing component obtains all files in folders A and B through the local path and deletes the comments in the files.

[0066] The second step is to match all file names and corresponding file types under the component acquisition path, and store the local absolute path of the file with the C++ source code type into the collection A and B.

[0067] Set A={“D:\testfiles1\test1.cpp”,“D:\testfiles1\taskone.cpp”},

[0068] Set B = {"D:\testfiles2\test2.cpp", "D:\testfiles2\other.cpp"}.

[0069] In the third step, the file matching component compares the file names of the program files stored in sets A and B, calculates the cosine similarity of the program file contents stored in sets A and B, and considers program files with the same file name or file content cosine similarity > 0.94 as matches and stores them in sets FA and FB one by one. Unmatched files are stored in sets UFA and UFB respectively. The cosine similarity calculation results are shown in the following table.

[0070]

[0071] The contents of each collection are as follows:

[0072] FA={“D:\testfiles1\test1.cpp”}

[0073] FB={“D:\testfiles2\test2.cpp”}

[0074] UFA={“D:\testfiles1\taskone.cpp”}

[0075] UFB={“D:\testfiles2\test2.cpp”}

[0076] Step 4: The function matching component extracts the corresponding local absolute paths in FA and FB to obtain the file content CA y and CB y . Get CA y and CB y Function headers with the same function heads or function body cosine similarity greater than 0.94 are stored in sets KA and KB respectively, and unmatched function headers are stored in sets UKA and UKB respectively.

[0077]

[0078] The contents of each collection are as follows:

[0079] KA={“void findmax()”} KB={“int findmax()”}

[0080] UKA={} UKB={}

[0081] In the fifth step, the function comparison component obtains the function corresponding to the function header in the sets KA and KB, reads the function body and compares it line by line, and stores the additions, deletions and modifications inside the function body into the method change table, as shown below.

[0082]

[0083] The above embodiments are only preferred implementation modes of the present invention. It should be pointed out that ordinary technicians in this technical field can make several improvements and equivalent substitutions without departing from the principles of the present invention. These technical solutions after improvements and equivalent substitutions to the claims of the present invention all fall within the protection scope of the present invention.

Claims

1. A static analysis method for the evolution history of multi-version software based on text comparison, characterized in that, this method includes the following steps: Step 1) Arrange the files of different versions of the software in chronological order, such as A 0 ,B 0 ,C 0 ,…,N 0 , from A 0 ,B 0 At the beginning, two adjacent files are taken out each time for subsequent analysis operations until all adjacent files are analyzed. Step 2) Use the method of calculating the cosine similarity of the program file content to match the program files to be compared in files A and B, and store the local absolute paths of the program files in two sets FA and FB respectively. For a given integer set index i, FA i With FB i The local absolute paths of the program files in the i-th pair A and B to be compared are stored, |FA|=|FB|, and the local absolute paths of the program files in A and B that do not match are stored in the sets UFA and UFB respectively; Step 3) For sets FA and FB, traverse i (0 < i < |A|), from FA i and FB i obtain the content of the program file, and use the method based on text comparison to obtain the method change table; Step 4) For the set UFA, traverse j (0 < j < |UFA|) to obtain the newly added and deleted program files in A; for the set UFB, traverse k (0 < k < |UFB|) to obtain the newly added and deleted program files in B, and obtain the file change table; Step 5) A 0 ,B 0 ,C 0 ,…,N 0 After the adjacent files in these N files are analyzed, N-1 file change tables and method change tables are obtained, measurement data is obtained, and an evolution history analysis report is obtained. The specific process of matching the program files to be compared in the said step 2) is as follows: 21) For the program files with the same file name in A and B, they are considered as matching program files, and their local absolute paths are stored in the corresponding positions with the same subscript in the sets FA and FB; 22) For program files with different file names in A and B, the integer set subscripts are m and n respectively, according to the local absolute path A m and B n Get the program file source code CA m and CB n , compared with CA m and CB n If the cosine similarity is greater than or equal to a threshold, the local absolute path A is considered m and B n The corresponding program files are matched and stored in the sets FA and FB respectively; 23) The files that still cannot be matched after the above steps 21) and 22) are considered as mismatched files, and they are respectively grouped into the sets UFA and UFB; In the said step 3), the specific process of obtaining the differences in the contents of program files by using the text comparison method is as follows, 31) For sets FA and FB, traverse y (0 < y < |A|), and from FA y and FB y obtain the content of the program files, denoted as CA y and CB y respectively. For the functions with the same function headers in CA y and CB y , consider them as matching functions, and store the function headers in sets KA and KB respectively, where |KA| = |KB|; 32) Targeting CA i With CB i For functions with different function heads, the function bodies RA(y,r) and RB(y,d) are obtained according to the function heads CA(y,r) and CB(y,d). If the cosine similarity between RA(y,r) and RB(y,d) is greater than or equal to a threshold, the functions corresponding to the function heads CA(y,r) and CB(y,d) are considered to be matched, and the function heads are stored in the sets KA and KB respectively, |KA|=|KB|; 33) The functions that still cannot be matched after the above steps 31) and 32) are considered as mismatched functions, and they are respectively grouped into the sets UKA and UKB; 34) For the set UKA, traverse q (0 < q < |UKA|) to obtain the number of newly added and deleted functions and the function headers in A; for the set UKB, traverse t (0 < t < |UKB|) to obtain the number of newly added and deleted functions and the function headers in B; In the said step 5), the specific process of obtaining the measurement data from the file change table and the method change table and obtaining the evolution history analysis report is as follows, 51) The following measurement data can be obtained: NI: The number of software iterations; CN: The number of file changes; CL: The number of code lines modified in the source code entities; TCL: The total number of code lines modified in the source code entities; The calculation methods of each measurement index are as follows: (1) The change frequency CF is the number of file changes divided by the total number of software iterations; CF = CN / NI; (2) The change weight CW reflects the proportion of file changes in the total changes during the software iteration process, and can be obtained by dividing the file code change scale by the total change scale; CW = CL / TCL; 52) Conduct frequent change file analysis based on the sorting of change frequency and change weight, and generate an evolution history analysis report.

2. A static analysis system for the evolution history of multi-version software based on text comparison, characterized in that, it is used to implement the static analysis method for the evolution history of multi-version software based on text comparison described in claim 1, the said system includes a preprocessing component, a file matching and comparison component, a method matching and comparison component, a measurement index acquisition component, and an evolution history analysis component, where The preprocessing component takes out two adjacent files from the file queue each time, obtains and scans the source codes of all program files of the software through the local absolute paths, deletes the comments and blank lines in the source code, and obtains the file without comments by deleting the comments in the file, The file matching and comparison component matches the preprocessed files, obtains the matching program files and the mismatched program files, and generates a file change table therefrom; the matching program files are used as the input of the method matching and comparison component, and the file change table is used as the input of the measurement index acquisition and evolution history analysis components; Method matching and comparison component, for matching program files, matches the methods in the file source code to obtain matching methods and mismatching methods, as well as changes in matching methods accurate to the source code line, and generates a method change table as a prerequisite for obtaining measurement indicators and evolution history analysis; The metric acquisition component uses the file change table and the method change table to automatically collect statistics on metric data: the number of software iterations, the number of file changes, the number of lines of code changed in the source code entity, and the total number of lines of code changed in the source code entity, so as to calculate the metric indicators: change frequency and change weight, which are used as inputs of the evolution history analysis component. The evolution history analysis component automatically analyzes frequently changed files based on the acquired file change table, method change table, and metrics. The analysis is focused on frequently changed files, and an evolution history analysis report is generated to provide assistance for other software maintenance and software evolution technologies.