A compilation level program spectrum generation method, program spectrum and fault location method

Through the compilation-level program spectrum generation method and instrumentation technology, the problem of low fault location efficiency caused by compilation optimization and macro replacement in the existing technology is solved, and efficient and accurate fault location at the compilation level is achieved, which is suitable for compiled code.

CN118626403BActive Publication Date: 2024-10-15BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411119423.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-15
Publication Date
2024-10-15
Estimated Expiration
2044-08-15

AI Technical Summary

Technical Problem

Existing fault location technology is difficult to accurately reflect the actual execution behavior of the program when faced with compilation optimization and macro replacement, resulting in reduced fault location efficiency and accuracy. Especially when multiple identical statements or structures exist, it is difficult to distinguish the differences. .

Method used

Using the compiler-level program spectrum generation method, through compiler-level instrumentation and detailed program behavior information analysis, the compiler-level program spectrum is generated, the execution times and paths of statements are calculated, and the compiler spectrum matrix and artificial intelligence learning methods are used to locate faults, directly in Analysis is performed at the compilation level and applies to compiled code.

Benefits of technology

It significantly improves the accuracy and efficiency of fault location, can effectively handle compilation optimization and macro replacement, provides finer-grained data support, and improves fault location capabilities in software testing and maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626403B_ABST
    Figure CN118626403B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of software fault location, and specifically to a compilation-level program spectrum generation method, a program spectrum and a fault location method, comprising: performing compilation-level stubs on a compilation code containing multiple compilation-level statements, executing test cases and collecting information, and for each compilation-level statement, counting and updating the number of executions of the statement during the test case execution process; finally, generating a compilation spectrum matrix according to the results of the number of executions of all compilation-level statements in all test cases. The present invention uses compiled and finer-grained program behavior information to improve the efficiency of fault location, and achieves distinction and precise location of subtle differences between identical statements by deeply analyzing and extracting program behavior information at the compilation level, thereby significantly improving the accuracy and efficiency of fault location.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software fault location, and specifically to a method for generating a compiled-level program spectrum, a program spectrum and a fault location method, and more particularly to improving the efficiency of fault location by using compiled-level program coverage information; by analyzing and inserting compiled code, collecting detailed program coverage information during execution, and then using this information to assist in quickly and accurately locating faults in the software. Background Art

[0002] As the complexity of software systems increases, efficient and accurate fault location has become one of the key challenges for software testing and maintenance. Traditional fault location techniques mainly focus on the source code level, using various static and dynamic analysis techniques, including compilation spectrum analysis, dynamic slicing, coverage analysis and other methods to identify possible fault sources. These methods are effective when the source code is available and the software scale is small, but in the face of compilation optimization, macro replacement and other situations, this information is often not enough to accurately reflect the actual execution behavior of the program. In particular, when multiple identical statements or code structures exist in different contexts, existing methods find it difficult to distinguish the differences between them in the specific execution process, resulting in greatly reduced efficiency and accuracy of fault location.

[0003] Spectrum-based Fault Localization (SFL) is a technology used for software fault localization. It helps identify code locations that may cause software failures based on information collected during program execution (such as statement execution times, execution paths, success or failure of test cases, etc.). In simple terms, spectrum-based fault localization is a method that associates software execution information with test results to narrow the search scope for potential fault sources.

[0004] Existing methods analyze source code at the statement level, method level, and class level, and collect information such as the number of statement executions, execution paths, and success or failure of test cases in the source code. Although these methods can provide a certain degree of positioning accuracy at the source code level, they lack a finer level of granularity, and their application is limited when faced with compiled code or scenarios where the source code cannot be directly accessed. At the compilation level, the code has undergone compiler optimization, macro replacement, inline functions, and other processing, which directly affects the structure and execution behavior of the code. This results in the inability of source code-level fault location methods to be directly applied to compiled code, because they cannot accurately understand the structure and semantics of the compiled code, and lack effective analysis methods, which leads to limitations in the actual software development and testing process. Summary of the invention

[0005] In order to solve the above problems in the prior art, the present invention proposes a compilation-level program spectrum generation method. In view of the element binding problem that the existing fault location technology may encounter when dealing with a large number of identical statements or structures, the present invention uses compiled and finer-grained program behavior information to improve the efficiency of fault location. By deeply analyzing and extracting program behavior information at the compilation level, it realizes the distinction and precise location of subtle differences between identical statements, thereby significantly improving the accuracy and efficiency of fault location.

[0006] Compared with the traditional fault location method that relies on source code level analysis, the present invention can more effectively handle special situations generated during the compilation process such as compilation optimization and macro expansion, and describe the running process from a finer granularity, solve the problem of multiple statements with the same suspicion, and improve the location efficiency, thereby significantly improving the efficiency and accuracy of fault location during software testing and maintenance.

[0007] The complete technical solution of the present invention includes:

[0008] A method for generating a compilation-level program spectrum comprises the following steps:

[0009] Step 1: Compile-level instrumentation

[0010] For a compiled code containing multiple compiled-level statements, a corresponding statement identifier is generated for each compiled-level statement in the code, and a code is inserted before the compiled-level statement, wherein the code enables the compiled-level statement to output the statement identifier of the compiled-level statement passed by the test case when the test case is run, and form a path formed by the compiled-level statements passed by the test case during its execution;

[0011] Step 2: Test case execution and information collection

[0012] Execute the compile-level instrumentation in step 1 for all test cases in the test case set, obtain the logs generated by the compile-level instrumentation, and collect the corresponding paths formed by the compile-level statements passed by each test case during execution;

[0013] Step 3: Compile-level program spectrum generation

[0014] Initialization: For each compilation-level statement, first set its execution count during the test case execution to 0;

[0015] Execution information update: When the test case is executed, the path corresponding to each test case is traversed, and the execution count of each compile-level statement is updated according to the log generated by the compile-level instrumentation;

[0016] Output the corresponding compilation spectrum: After all test cases traverse all compilation-level statements, a compilation spectrum matrix is ​​generated according to the execution times of all compilation-level statements in all test cases.

[0017] Furthermore, the compiled spectrum matrix is where N is the number of test cases and M is the number of compile-level statements.

[0018] Furthermore, the components of the compiled spectrum matrix are Indicates During the execution of a test case, The number of times a compiled-level statement is executed.

[0019] Furthermore, the rule for outputting the number of executions is: During the execution of a test case, When the number of executions of a compiled-level statement is zero, =0; when During the execution of a test case, When the execution count of a compiled-level statement is not zero, =1.

[0020] Furthermore, the compiled-level program spectrum is obtained using the method.

[0021] Furthermore, based on the compilation-level program spectrum, the statement suspicion of each compilation-level statement in the software is calculated.

[0022] The calculation method may adopt the fault location algorithm in the prior art, such as Jaccard, Tarantula, Ochiai, etc. The calculation method is as follows:

[0023]

[0024] In the formula, is the statement suspicion of the Jaccard algorithm, is the statement suspicion of the Tarantula algorithm, is the statement suspicion of the ochiai algorithm, c is the statement, is a failed test case, is a passed test case.

[0025] Furthermore, based on the compiled-level program spectrum, training and learning are performed through an artificial intelligence learning method, and software fault location is performed. For example, training and learning can be performed through an artificial intelligence learning method such as GNN in combination with code structure information.

[0026] The advantages of the present invention over the prior art are:

[0027] Compared with the prior art, the present invention can directly perform fault location analysis on the code at the compilation level without relying on source code, and is applicable to a wider range of scenarios. By accurately tracking and analyzing compilation-level statements, the present invention can effectively improve the accuracy and efficiency of fault location, especially showing better adaptability when dealing with compilation optimization and macro replacement. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 This is a flow chart of the compilation-level program spectrum generation method described in the present invention.

[0029] Figure 2 Schematic diagram of the compilation spectrum matrix generation process.

[0030] Figure 3 Flow chart of the generation process of the compilation-level program spectrum in an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The present invention is described in detail below in conjunction with the embodiments and drawings, but it should be understood that the embodiments and drawings are only used to exemplify the present invention and do not constitute any limitation on the protection scope of the present invention. All reasonable changes and combinations within the scope of the inventive concept of the present invention fall within the protection scope of the present invention.

[0032] Figure 1 This is a flow chart of an embodiment of the method of the present invention. As shown in the figure, the present invention provides a compilation-level program spectrum generation method, a program spectrum and a fault location method. First, the basic component units required for the compilation-level program (compilation spectrum for short) generation are defined, including statement identifiers, execution times, execution path tags, etc. Then, by applying specific formulas and algorithms to these units, a compilation-level program spectrum that can accurately describe the execution characteristics of the test case is generated.

[0033] Take an existing program as an example, its compilation level statement set is {s 1 …s M}, test case set {t 1 …t N}.

[0034] The basic building blocks required for compiling spectrum generation include:

[0035] s j : The jth compilation level statement;

[0036] t i : the i-th test case;

[0037] e i : Test case t i The execution result, e i When it is +, it means the test case passed.i When it is -, it means the test case execution failed;

[0038] S j : Statement identifier, for compiled-level statements j The corresponding unique identifier.

[0039] C ij : Statements j In the test case t i The number of executions during execution.

[0040] P i : represents test case t i The path formed by the statements passed during execution.

[0041] A: Compile the spectrum matrix

[0042] This method mainly includes the following four steps:

[0043] 1. Compile-level instrumentation

[0044] 2. Test case execution and information collection

[0045] 3. Compiler-level program spectrum generation

[0046] 4. Application of fault location algorithm

[0047] Step 1: Compile-level instrumentation

[0048] After obtaining the compiled code, the compiled-level statement s j Generate the corresponding statement identifier S j , and at the compile-level statement s j Insert the code before running the test case i Output the test case t i Compiled-level statements j The statement identifier S j , thus forming the corresponding path P i .

[0049] Step 2: Test case execution and information collection

[0050] Execute all test cases in the test case set and collect test case logs generated by instrumentation i The corresponding path P i .

[0051] Step 3: Compile-level program spectrum generation

[0052] Initialization: For each compile-level statement, set its execution count to 0.

[0053] Execution information update: When the test is executed, the path corresponding to the test case is traversed and the execution count of each statement is updated according to the instrumentation log.

[0054] Output corresponding compilation spectrum: for test case t i Traverse the compiled-level statements s in order 1 …s M , output the compilation spectrum matrix A corresponding to the statement according to the number of executions.

[0055]

[0056] The process is as Figure 2 As shown in the figure, the elements in the compiled spectrum matrix are all binary results, with a value range of {0,1}. The element a in the compiled spectrum A is ij The value selection rules are as follows.

[0057]

[0058] Each row of the coverage matrix indicates which statements have been covered by the corresponding test case, and each column provides the coverage vector of the corresponding statement.

[0059] Example 1

[0060] This embodiment performs fault location analysis on the code at the compilation level for a specific program. The process is as follows: Figure 3 shown.

[0061] The example code of the program is:

[0062]

[0063] Step 1: Bytecode Instrumentation

[0064] First, compile it into bytecode, and then use the written stub program to perform stub. The stub program will traverse the bytecode of the target program, assign a unique identifier to each compilation-level statement (including method calls, conditional judgments, etc.) and insert it into the program. In addition, the stub program will record statement-related information (line number, compilation-level statement identifier, class name, compilation-level statement) into a txt file (stmt.txt), which will serve as the basis for subsequent analysis.

[0065] Compile-level statement information and unique identifier corresponding files:

[0066]

[0067]

[0068] Step 2: Runtime Logging

[0069] By modifying the configuration file of Defects4j, the instrumentation program is integrated into its automated test process. During the test execution, the instrumented compile-level statement will output its unique identifier to the log file (jimple_log_simple.txt) before execution. This step ensures that the execution status of each statement during the test execution is accurately recorded, providing raw data for generating the compile-level program spectrum.

[0070] Instrumentation results:

[0071] For example, enter the following test case:

[0072]

[0073] The path information obtained:

[0074]

[0075] Step 3: Generate a compiled program spectrum

[0076] The compilation-level program spectrum generation program reads the log file in step 2 and generates a compilation-level program spectrum based on the statement execution status recorded in the log file and the statement information in stmt.csv. The compilation spectrum contains information such as the number of executions and execution paths of each compilation-level statement, providing a detailed data basis for subsequent fault location analysis.

[0077] Compiled spectrum results:

[0078]

[0079] The corresponding statement-level program spectrum (statement spectrum) results are:

[0080]

[0081] Corresponding to the source code, we can find that test cases 1 and 2 cover different compilation-level statements, but the actual statements they pass through are all int small = (a>b) ? b : a;. Therefore, the compilation spectra corresponding to test cases 1 and 2 are different, but the statement spectra are the same, indicating that the compilation spectrum does describe a more detailed range than the statement spectrum.

[0082] Based on the compile-level program spectrum, the statement suspicion of each compile-level statement in the software is calculated.

[0083] The calculation method may adopt the fault location algorithm in the prior art, such as Jaccard, Tarantula, Ochiai, etc. The calculation method is as follows:

[0084]

[0085] In the formula, is the statement suspicion of the Jaccard algorithm, is the statement suspicion of the Tarantula algorithm, is the statement suspicion of the ochiai algorithm, c is the statement, is a failed test case, is a passed test case.

[0086] On this basis, this implementation uses the existing classic suspicion calculation method ochiai fault location algorithm to calculate the statement suspicion. The calculation results are compared as follows. It can be seen that the ranking of the erroneous statements is consistent in the two, but the compilation level result has one less statement under the same ranking, which means that compared with the statement level, the compilation level result is easier to distinguish the erroneous statements.

[0087] Table 1 Comparison of calculation results of fault location algorithms

[0088] Source code statement line number Source code statements Sentence-level suspicion ranking Compilation-level suspicion ranking (ranked by taking the average) 3 public class JavaFile { 15 15 8 Boolean calValid = Boolean.parseBoolean(args[0]); 9 9 9 int a = Integer.parseInt(args[1]); 9 9 10 int b = Integer.parseInt(args[2]); 9 9 11 String method = default method";" 9 9 12 if (calValid) { 9 9 13 int small = (a>b) ? b : a; 4 8 14 if(small<8) { / / trigger wrong 4 4 15 if (small<5) { 1 1 16 method = method 1";" 1 1 17 if (small<2) { 1 1 18 method = method 2";" 8 7 22 System.out.println(method); 4 4 23 } else { 4 4 24 System.out.println(Do not want to cal!");" 15 15 26 } 9 9

[0089] This embodiment effectively supports high-precision fault location through precise compilation-level instrumentation and detailed compilation spectrum generation methods. Compared with the prior art, the present invention does not need to modify the compiler or rely on specific compiler features, and has better versatility and flexibility. In addition, it can be seen from the above examples that the compilation level can dig out finer-grained differences than the statement level, and the positioning is more precise. Through runtime logging and the generation of compilation-level program spectra, the present invention can provide more detailed and accurate data support for fault location than the statement level without affecting the complexity of the program algorithm.

[0090] The above applications are only some implementation methods of the present application. For those skilled in the art, several modifications and improvements can be made without departing from the creative concept of the present application, and these all belong to the protection scope of the present application.

Claims

1. A method for generating a compilation-level program spectrum, characterized in that: The steps include: Step 1: Compile-level instrumentation For a compiled code containing multiple compiled-level statements, a corresponding statement identifier is generated for each compiled-level statement in the code, and a code is inserted before the compiled-level statement, wherein the code enables the compiled-level statement to output the statement identifier of the compiled-level statement passed by the test case when the test case is run, and form a path formed by the compiled-level statements passed by the test case during its execution; Step 2: Test case execution and information collection Execute the compile-level instrumentation in step 1 for all test cases in the test case set, obtain the logs generated by the compile-level instrumentation, and collect the corresponding paths formed by the compile-level statements passed by each test case during execution; Step 3: Compile-level program spectrum generation Initialization: For each compilation-level statement, first set its execution count during the test case execution to 0; Execution information update: When the test case is executed, the path corresponding to each test case is traversed, and the execution count of each compile-level statement is updated according to the log generated by the compile-level instrumentation; Output the corresponding compilation spectrum: After all test cases traverse all compilation-level statements, a compilation spectrum matrix is ​​generated according to the number of executions of all compilation-level statements in all test cases.

2. The method for generating a compiled program spectrum according to claim 1, characterized in that: The compiled spectrum matrix is where N is the number of test cases and M is the number of compile-level statements.

3. The method for generating a compiled program spectrum according to claim 2, characterized in that: Compile the components of the spectrum matrix Indicates During the execution of a test case, The number of times a compiled-level statement is executed.

4. The method for generating a compiled program spectrum according to claim 3, characterized in that: The rule for outputting the number of executions is: During the execution of a test case, When the number of executions of a compiled-level statement is zero, =0; when During the execution of a test case, When the execution count of a compiled-level statement is not zero, =1.

5. A compiled-level program spectrum obtained by the method according to any one of claims 1 to 4.

6. The method for locating software faults using the compiled-level program spectrum of claim 5, characterized in that: Based on the compile-level program spectrum, the statement suspicion of each compile-level statement in the software is calculated.

7. The method for locating software faults using the compiled-level program spectrum of claim 5, characterized in that: Based on the compiled-level program spectrum, training and learning are performed through artificial intelligence learning methods, and software faults are located.