Conditional statement defect patch generation and verification method in object-oriented program

文档序号:189950 发布日期:2021-11-02 浏览:21次 中文

阅读说明:本技术 一种面向对象程序中条件语句缺陷补丁生成与验证方法 (Conditional statement defect patch generation and verification method in object-oriented program ) 是由 杨秋辉 李兴佳 伍佳 于 2021-07-09 设计创作,主要内容包括:本发明提供一种面向对象程序中条件语句缺陷补丁生成与验证方法。该方法包括修复信息收集、补丁生成和补丁验证三个步骤。首先运行测试用例,收集待修复程序位置的上下文信息,然后综合使用变异技术和程序合成技术自动化地生成候选补丁,最后运行测试用例验证候选补丁的有效性。该方法可以有效地修复条件语句错误和条件语句缺失两种缺陷,显著提高了缺陷修复率和补丁精度,缓解了补丁过度拟合问题。(The invention provides a conditional statement defect patch generation and verification method in an object-oriented program. The method comprises three steps of repair information collection, patch generation and patch verification. The method comprises the steps of firstly running a test case, collecting context information of a program position to be repaired, then generating a candidate patch automatically by comprehensively using a variation technology and a program synthesis technology, and finally running the test case to verify the effectiveness of the candidate patch. The method can effectively repair two defects of conditional statement errors and conditional statement missing, remarkably improves defect repair rate and patch precision, and relieves the problem of patch overfitting.)

1. The method for generating and verifying the conditional statement defect patch in the object-oriented program is characterized by comprising the following steps of:

step 1, collecting information required by defect repair;

acquiring context information of a program position to be repaired in a test case execution process by executing the test case;

assuming that a conditional expression to be modified or added at the program position is exp, collecting relevant information from two aspects of input and expected output of the expression exp, and converting input related data and expected output into a defect repair equation to be solved for guiding generation and verification of a program patch;

step 2, generating candidate patches for defect repair;

selecting different patch generation strategies according to statement types of the repairable program positions; if the repairable program position is an if conditional statement, which indicates that the program defect is a conditional statement error, the original conditional expression of the position is mutated, and the generated program variant is used as a candidate patch; if the repairable program position is not the if conditional statement, which indicates that the program defect is the condition statement missing, synthesizing the conditional expression by directly using a constraint solving method, and adding the synthesized conditional expression as a precondition to form a candidate patch;

step 3, verifying the validity of the candidate patch;

for candidate patches generated by a mutation technology, screening out candidate patches conforming to a defect repair equation, and running a test case to verify the effectiveness of the candidate patches; for candidate patches which are synthesized based on constraint solving, directly running the test cases to verify the validity of the candidate patches;

if the candidate patch is a valid patch, directly outputting the patch, terminating the repair process and reporting the success of repair; if the candidate patch has no valid patch, reporting the repair failure;

therefore, the condition statement missing defect and the condition statement error defect in the object-oriented program can be repaired.

2. The method of claim 1, wherein the step 2 of generating a candidate patch for defect repair comprises: when a candidate patch is generated by using a mutation technology, three types of applicable mutation operators are defined for conditional statements according to a real defect repair mode summarized in the existing research: negating the conditional expression; replacing homogeneous operators, including arithmetic operators, relational operators and logical operators; one clause in the conditional expression is removed.

Technical Field

The invention belongs to the field of software debugging in software engineering, and particularly relates to a conditional statement defect patch generation and verification method in an object-oriented program.

Background

Software bugs refer to errors in the software that result in the software failing to meet requirements or specifications and needing to be replaced or repaired. Defect repair refers to the act of repairing failed software or software components. In the software development process, debugging is an important means for determining and repairing program defects and ensuring product quality. However, in the development process of fast iteration, the traditional manual debugging faces huge time and labor cost pressure. In order to reduce the debugging pressure of developers and reduce the development cost, researchers propose the capability of computers to assist or even replace the developers to carry out debugging work, and the technology is called automatic defect repair. The technology analyzes and explains the reasons of program failure by means of the capability of a computer, provides one or more feasible repair schemes for the problem program, and therefore effectively reduces debugging cost of developers.

In the existing research results, most of the defect repair techniques use test cases to describe the correct program behavior and verify whether the program patch is valid by rerunning the test cases. If the test case is fully executed, then the program patch is considered a valid patch capable of repairing the defect. However, due to the incompleteness of the test suite, the valid patches generated by such techniques may just pass a given test case, and no real repair is achieved.

Disclosure of Invention

Program patch generation and verification are the core steps in automated defect repair. In order to improve the defect repair rate and the patch precision, the invention focuses on the conditional statement defect in the object-oriented program, and provides a novel conditional statement defect repair patch generation and verification method. The method comprises the steps of firstly running a test case, collecting context information of a program position to be repaired, then generating a candidate patch automatically by comprehensively using a variation technology and a program synthesis technology, and finally running the test case to verify the effectiveness of the candidate patch.

A method for generating and verifying conditional statement defect patches in an object-oriented program comprises the following steps.

Step 1, collecting information required by defect repair.

And acquiring context information of the position of the program to be repaired in the test case execution process by executing the test case. Assuming that the conditional expression to be modified or added at the program position is exp, relevant information is collected from two aspects of input and expected output of the expression exp, and input related data and expected output are converted into a defect repair equation to be solved for guiding generation and verification of a program patch.

And 2, generating a candidate patch for repairing the defect.

And selecting different patch generation strategies according to the statement type of the repairable program position. If the repairable program position is an if conditional statement, which indicates that the program defect is a conditional statement error, the original conditional expression at the position is mutated, and the generated program variant is used as a candidate patch. And if no valid patch meeting the requirement exists in the program variant, synthesizing the candidate patch by using a constraint solving method according to the defect repair equation. And if the repairable program position is not the if conditional statement, which indicates that the program defect is the condition statement missing, synthesizing the conditional expression by directly using a constraint solving method, and adding the synthesized conditional expression as a precondition to form a candidate patch.

And 3, verifying the validity of the candidate patch.

For candidate patches generated by a mutation technology, screening out candidate patches conforming to a defect repair equation, and running a test case to verify the effectiveness of the candidate patches; and for candidate patches which are synthesized based on constraint solving, directly running the test cases to verify the validity of the patches.

If the candidate patch is a valid patch, the patch is directly output, the repair process is terminated, and the success of repair is reported. Otherwise, the candidate patch is discarded and the next one is selected for verification. And if no valid patch exists in the candidate patches, reporting the repair failure.

The method focuses on two defects of conditional statement errors and conditional statement missing in an object-oriented program, and different patch generation strategies are selected according to statement types at the position of a repairable program during repair. On one hand, three applicable mutation operators are defined for the conditional statement, and the original conditional expression is simply changed by using a mutation technology to generate the candidate patch. On the other hand, by collecting program semantic information, conditional expressions satisfying constraints are synthesized as candidate patches using component-based program synthesis techniques. Finally, patch verification is performed using the test suite. The method has the advantages that two defects of conditional statement errors and conditional statement missing can be effectively repaired, the defect repair rate and the patch precision are obviously improved, and the problem of patch overfitting is solved.

Drawings

FIG. 1 is a flow chart of an embodiment of the method of the present invention.

Detailed Description

In order to more clearly show the objects and technical solutions of the present invention, the following will describe the specific embodiments and parameters of the present invention in more detail with reference to the specific implementation processes and the attached drawings.

A method for generating and verifying a conditional statement bug fixing patch in an object-oriented program is shown in FIG. 1 and comprises the following steps.

Step 1, collecting information required for defect repair, step G1 in fig. 1.

The program defect localization technique may obtain a list of suspect statements, each suspect statement comprising a setWherein, location represents the position of the program to be repaired, is used for uniquely identifying a program statement in the defect program and consists of a class name and a line number; the angelicValue refers to a value which can enable the failed test case to be successfully executed, and for the conditional statement defect, the value range is { true, false };indicating a failed test case. On the basis, context information of the position of the program to be repaired in the test case execution process is obtained by executing the test case. Assuming that the conditional expression to be modified or added at the program location is exp, relevant information is collected from both the input and output aspects of the expression, and the input data and the desired output can be converted into program semantic constraints to be solved for guiding the synthesis of the program patch.

Further, step 1 comprises the following three steps.

Step 1-1, collecting input data related to conditional expressions for useAnd (4) showing.

Wherein l is location, which represents the position of exp, and n and m respectively represent the m-th execution of the nth test case. It is assumed that in the program execution process, before the conditional expression exp to be repaired is executed, all accessible variables have u basic variables and a set of pairsLike a set of OBJ (w objects in total), and some constants, thenThe data contained are as follows:

the side-by-side u basic variables and corresponding variable values. Such as: a → 10;

the w bolean values in the positive and negative sides respectively indicate whether w objects in the OBJ are empty. If a certain object is empty, the corresponding value is false;

the status query method and its output of the respective corresponding classes of the objects in the even and odd OBJ, as obj1.size () → 2;

and can be constant, e.g., -1, 0, 1.

And 1-2, collecting an expected output result of the conditional expression.

In the process of using the test case to run the program, after the conditional expression exp to be repaired is executed, the value which can be passed by the test case and is output by the expression is called expected outputAnd expressing the value range as true, false.And n and m respectively represent the mth execution of the nth test case.

If it is notThe position is a conditional statement, the expression is a conditional statement error defect,is the expected output of the conditional expression exp for this positional error. For a failed test case, the test case,equal to a value that enables the test case to pass; with respect to the successful test cases,equal to the actual output.

If it is notThe position is a non-conditional statement, the expression is that the conditional statement has a missing defect,is the expected output of the conditional expression exp for the position missing. For a failed test case, the test case,are all false; with respect to the successful test cases,are both true.

And 1-3, forming a defect repair equation.

Based onAnda repair equation F (equation 1) to be solved may be formed.

(equation 1).

And step 2, generating a candidate patch for defect repair, wherein the step G2 in the step 1 is carried out.

And selecting different patch generation strategies according to the statement type of the repairable program position. And when the statement of the position to be repaired is the if conditional statement, using the strategy one, otherwise, using the strategy two.

Strategy one: program patches are generated based on mutation operators.

When the program position to be repaired is an if conditional statement, introducing small code change in the conditional expression of the position based on a predefined mutation operator, and generating all possible first-order program variants as candidate patches. And if no valid patch exists after verification, generating a candidate patch by using the strategy two. There are three types of variants in this strategy: (1) negating the conditional expression; (2) replacing homogeneous operators, including arithmetic operators, relational operators and logical operators; (3) one clause in the conditional expression is removed. For example, a conditional statement if (a >0| | b <0) is mutated, based on a candidate patch generated by a mutation operator (1) such as if (| (a >0| | b <0)), based on a candidate patch generated by a mutation operator (2) such as if (a <0| | b <0), based on a candidate patch generated by a mutation operator (3) such as if (a > 0).

And (2) strategy two: the composite program patch is solved based on the constraints.

Obtained by running test cases in step 1<>And after the constraint is generated with the comparison operator, the arithmetic operator and the logic operator, inputting the generated constraint into the SMT solver, and if the constraint has a solution, outputting a conditional expression exp-patch meeting the program constraint. If the constraint is not solved, the next statement in the list of suspect statements continues to be analyzed. And if all the statements are analyzed and no valid patch is generated, reporting that the repair is failed. For example, assuming a conditional expression to be repaired is obtained<>To is formed by<{x=1, y=1, 0}, true>、<{x=2, y=1, 0}, false>The arithmetic operator is { +, - }, and the logical operator is<,>And then the conditional expression exp-patch synthesized after constraint solving is' x-y<0”。

And for the condition statement missing defect, adding the condition expression exp-patch synthesized by constraint solving as a precondition to a repairable program position to form a candidate patch.

And for the conditional statement error defect, replacing the original wrong conditional expression exp by using a constraint solving synthesized conditional expression exp-patch to form a candidate program patch.

And step 3, verifying the validity of the candidate patch, and step G3 in FIG. 1.

When the candidate patches are generated by the mutation technology, for each candidate patch, the solution of the defect repair equation (formula 1) in the step 1 is firstly satisfied, otherwise, the candidate patch is discarded; a test case is then run to verify the validity of the candidate patch. If the candidate patch is a valid patch, the patch information is directly output, and the repair process is terminated. Otherwise, the candidate patch is discarded, and the next candidate patch is selected for inspection and verification. And if all candidate patches generated by the mutation are not valid patches, solving the synthesized candidate patches by using the constraint.

And for candidate patches which are synthesized based on constraint solving, directly running the test cases to verify the validity of the patches. If a valid patch exists which allows all test cases to be executed, the patch is directly output, and the repair process is terminated. Otherwise, the candidate patch is discarded and the next one is selected for verification. If no valid patch is found that meets the requirements, the next statement in the list of suspect statements continues to be analyzed. And if all the sentences in the suspicious sentence list are analyzed and no valid patch is generated, reporting that the repair is failed.

Aiming at the conditional statement defects, two methods of generating patches based on mutation operators and solving synthetic patches based on constraints are provided. According to the statement type of the program position to be repaired, different patch generation and verification strategies can be selected, and the defect repair rate of the repair method is improved. When the conditional statement defect is repaired, the method is feasible and has a good effect.

7页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:嵌入式设备升级方法、装置、设备、介质及程序产品

网友询问留言

已有0条留言

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

精彩留言,会给你点赞!