WO2017201853A1 - 基于切片模型的程序回归错误定位方法 - Google Patents

基于切片模型的程序回归错误定位方法 Download PDF

Info

Publication number
WO2017201853A1
WO2017201853A1 PCT/CN2016/090956 CN2016090956W WO2017201853A1 WO 2017201853 A1 WO2017201853 A1 WO 2017201853A1 CN 2016090956 W CN2016090956 W CN 2016090956W WO 2017201853 A1 WO2017201853 A1 WO 2017201853A1
Authority
WO
WIPO (PCT)
Prior art keywords
statement
program
statements
execution
slice
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2016/090956
Other languages
English (en)
French (fr)
Inventor
刘烃
王海军
郑庆华
管晓宏
陈泽华
朱海萍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xian Jiaotong University
Original Assignee
Xian Jiaotong University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xian Jiaotong University filed Critical Xian Jiaotong University
Publication of WO2017201853A1 publication Critical patent/WO2017201853A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Definitions

  • the invention relates to the field of trusted software and software testing, in particular to a method for locating regression errors in a program.
  • ADD Algmented Delta Debugging
  • AFTER Automatic Fault Explanation for Regression testing
  • the automatic isolation of ADD by combining coverage analysis and Delta debugging results in a modification of program execution failure.
  • ADD does not analyze the semantics of the program, so the misplacement of the positioning may simply avoid the failure of the program execution and not the real error.
  • AFTER uses dynamic analysis based on Delta debugging and semantic analysis based on symbol analysis to locate regression errors.
  • the main problem with AFTER is its extensibility. As we all know, symbol analysis is a huge process, so it is difficult to apply to large-scale programs.
  • a practical regression error localization technique not only requires precise positioning to cause errors, but also provides a context in which the modification causes the program to fail.
  • the object of the present invention is to propose a program regression error localization method based on a slice model.
  • the program behavior slice causing the program regression error is output, and the problem of regression error location in the program test is solved.
  • a program regression error location method based on a slice model includes the following steps:
  • the execution trajectory is organized into a tree structure, each node of the tree is a function execution sequence; the trajectory function body statement corresponding method is called, and the execution trajectory of the two versions of the program extracted in step S2) is corresponding;
  • step S6 determining whether the slice analysis queue is empty, if it is empty, then jumping to step S9), otherwise jumping to step S7);
  • step S7 take out the first end statement of the slice analysis queue, and determine whether the first end statement needs to be sliced, if not required Analysis then jumps to step S6), otherwise jumps to step S8);
  • step S8 adding the current analysis sentence to the regression error slice, and adding the dependency statement and the corresponding statement that need to be sliced according to the sentence classification in step S4) to the slice analysis queue;
  • a further improvement of the present invention is that the process of code rearrangement in the step S1) comprises the following steps:
  • each of the two versions of the program source code is divided into two categories: identical statements, modified statements;
  • a further improvement of the present invention is that the tree structure of the execution trajectory in step S3) is defined as follows: each node in the tree is an execution trajectory of a function body, and a child node of one node is called in a function body represented by the node The execution trajectory of the function body; in step S3), the trajectory function body statement is correspondingly started from the root node of the tree structure (main function body trajectory), and specifically includes the following steps:
  • step S301 determining whether the corresponding statement in the currently corresponding function body needs to be empty, if it is empty, the function body statement corresponding method execution end returns, otherwise, the process proceeds to step S302);
  • step S303 determining whether the current corresponding statement is a function call statement, if it is a function call statement, then jumping to step S304), otherwise jumping to step S306);
  • step S304 determining whether the function call has a corresponding function call in the corresponding track, if there is a corresponding function call, then jump to step S305), otherwise jump to step S301);
  • step S305 calling the function body statement corresponding method corresponding to the statement in the function body track, after the execution ends, the process proceeds to step S301);
  • step S306 determining whether the current statement has a corresponding statement in the corresponding track, if there is a corresponding statement, then jump to step S307), otherwise jump to step S301);
  • step S307 the current statement is associated with the corresponding statement in the corresponding track, and after the process ends, the process proceeds to step S301).
  • a further improvement of the present invention is that the strategy for classifying the sentences in step S4) is to classify all the statements in the track into the following four categories according to the source code sentence classification, the track correspondence result, and the variable value information contained in the statement in step S102):
  • the classification process includes the following steps:
  • step S401 determining whether the statements in the trajectory have all been classified, if all the classifications have been performed, then the process proceeds to step S407), otherwise, the process proceeds to step S402);
  • step S403 determines whether the statement is a modified statement, if the modified statement is marked as modified resulting in a different statement and jump to step S401), otherwise jump to step S404);
  • step S404 determines whether the statement has a corresponding statement, if there is no corresponding statement, the statement is marked as a different flow statement and jump to step S401), otherwise jump to step S405);
  • step S405 according to the variable value information included in the statement, determining whether the statement and the variable value included in the corresponding statement are the same, and if at least one variable value is not the same, marking the statement as a statement having a different value and jumping to step S401) Otherwise, go to step S406);
  • step S406 marking the statement as a consistent statement and jumping to step S401);
  • a further improvement of the present invention is that the criterion for determining whether the statement needs to be sliced in step S7) is that if the statement has been analyzed or belongs to the statement consistent in step S4), no slice analysis is required, otherwise the slice needs to be sliced. analysis.
  • a further improvement of the present invention is that the analysis strategy of the statement that needs to be sliced in step S8) is that, for the statement with different median value in step S4), only the data dependency statement and the corresponding statement in the corresponding track are added to the slice analysis queue; For statements with different flows, only the control dependency statement is added to the slice analysis queue; for the classification to modify to cause different statements, the control dependency and data dependency statements are added to the slice analysis queue.
  • the current statement analyzed in step S8) needs to be added to the regression error slice.
  • the present invention proposes a program regression error localization method based on a slice model, and performs slice analysis on two versions of the program to output a program behavior slice that causes a program regression error. Solve the problem of regression error location in program testing.
  • the method compares the two versions of the program source code, identifies different parts thereof, and rearranges the source code of the two versions of the program according to the recognition result, so that the two sequences are executed without affecting the execution order of the program code.
  • the original corresponding code in the version program has the same line number; in the corresponding stage of the track, the statements on the two execution tracks are performed according to the execution trajectory of the obtained two versions of the program, the dependency relationship between the statements, and the variable value information. Corresponding, and classifying the sentences according to the corresponding results of the trajectory; in the slice analysis stage, based on the control dependence of the program, the data dependency, and the classification of the statements, the slice analysis is started from the new program execution failure point as the starting point; Its dependency, backtracking the statement entity that caused the program to fail, until the dependency statement to be analyzed is empty, and the analyzed current statement does not need to continue to analyze its dependencies; finally, all the parsed statement entities in the stage of the slice analysis are Program behavior slice output that causes regression errors. Compared with the existing regression error localization method, this method clarifies the mechanism of regression error and has a guiding role in the repair of regression errors.
  • Figure 1 is a general flow chart of the method of the present invention
  • FIG. 3 is a flow chart of a method corresponding to a function body statement
  • Figure 4 is a flow chart of the sentence classification process
  • Figure 5 is a schematic diagram showing an exemplary procedure in a specific embodiment
  • Figure 6 is a comparison of the results of the source code
  • Figure 7 is a diagram of code rearrangement results
  • Figure 8 is a diagram corresponding to the trajectory
  • Figure 9 is a regression error slice diagram
  • Figure 10 is a diagram of a slice analysis process.
  • the program to be tested v1 is the original version
  • the program to be tested v2 is the modified new version.
  • Step S1 Calculate the difference between the source code of the two versions of the program according to the two versions of the program to be tested, and rearrange the source code of the two versions according to the source code, so that the same code has the same line number.
  • the different codes correspond to the blank lines.
  • the flow chart is shown in Figure 2. Specifically, the following steps are included:
  • Step S101 Calculate the difference between the source codes of the two versions according to the source code of the two versions of the program
  • Step S102 According to the calculated difference between the source code of the two versions of the program, the statements in the source code are divided into two categories, the same statement and the modified statement, and the modified statement is marked (c1-c4), as shown in FIG. 6. Shown
  • Step S103 On the basis of not changing the execution order of the program statement, the identical statements have the same line number, the modified statement corresponds to the blank line, and the code rearrangement result is as shown in FIG. 7;
  • Step S104 The two versions of the program source code to be tested after the code rearrangement are output as a new program to be tested.
  • Program v1 track Main#c 1 2 3 5 6 7 11 12 13 mian#r
  • Program v2 track Mian#c 1 2 4 8 9 11 12 13 main#r
  • Step S3 Calling the trajectory function body sentence corresponding method, corresponding to the execution trajectory of the two versions of the program extracted in step S2), the flowchart is as shown in FIG. 3, and the function body statement corresponding method:
  • step S301 determining whether the corresponding statement in the currently corresponding function body needs to be empty, if it is empty, the function body statement corresponding method execution end returns, otherwise, the process proceeds to step S302);
  • step S303 determining whether the current corresponding statement is a function call statement, if it is a function call statement, then jumping to step S304), otherwise jumping to step S306);
  • step S304 determining whether the function call has a corresponding function call in the corresponding track, if there is a corresponding function call, then jump to step S305), otherwise jump to step S301);
  • step S305 calling the function body statement corresponding method to correspond to the statement in the function body track, after the execution ends, the process proceeds to step S301);
  • step S306 determining whether the current statement has a corresponding statement in the corresponding track, if there is a corresponding statement, then jump to step S307), otherwise jump to step S301);
  • the specific process includes:
  • Step S301 the main function body needs to be corresponding to the statement is not empty, so go to S302;
  • Step S302 taking out the statement 1 in the program v1 that the main does not respond, go to step S303;
  • Step S303 statement 1 is not a function call statement, proceeds to step S306;
  • Step S306 The main function statement 1 in the path v1 track corresponds to the main function statement 1 in the program v2 track, and the process proceeds to step S307;
  • Step S307 Corresponding to the main function statement 1 in the two version program tracks, and marking the corresponding statement.
  • Step S4 According to the difference of the source code, the track corresponding result, and the variable value included in the statement, the statements in the track are divided into four categories: modifying different statements, different statements, different values, and consistent statements.
  • the classification strategy is as follows:
  • step S401 determining whether the statements in the track have been all classified, if all the categories have been classified, then the process proceeds to step S407), otherwise, the process proceeds to step S402);
  • step S403 according to the classification of the source code, determine whether the statement is a modified statement, if the modified statement is marked as modified resulting in a different statement and jump to step S401), otherwise jump to step S404);
  • step S404 determining whether the statement has a corresponding statement according to the result of the track correspondence, if there is no corresponding statement, marking the statement as a statement with a different flow and jumping to step S401), otherwise jumping to step S405);
  • step S405) determining, according to the variable value information included in the statement, whether the value of the variable included in the statement and the corresponding statement is the same, such as If at least one variable value is not the same, the statement is marked as a statement with a different value and jumps to step S401), otherwise jumps to step S406);
  • the specific classification process includes:
  • Step S401 the statements in the trajectory are not all classified, and the process proceeds to S402;
  • Step S402 Extract the unclassified statement 2 in the track
  • Step S403 statement 2 non-modified statement, go to S403;
  • Step S403 statement 2 has a corresponding statement, and proceeds to S404;
  • Step S404 the two variables in the two sentences contain the same variable value, go to step S405;
  • Step S405 Mark the statement 2 in the two tracks as a consistent statement.
  • Step S5 Begin the slice analysis by generating the failure point of the new version program as a starting point, and add the failure point statement to the slice analysis queue.
  • the new version program is program v2
  • the execution failure point statement is the output point.
  • Statement 13 in the program v2 track is added to the slice analysis queue;
  • Step S6 determining whether the slice analysis queue is empty, if it is empty, then jumping to step S9), otherwise jumping to step S7), the current queue is not empty, so the process goes to step S7);
  • Step S7 taking out the first end statement of the slice analysis queue, and determining whether the first end statement needs to perform slice analysis. If no analysis is needed, the process jumps to step S6), otherwise it jumps to step S8), whether it needs to perform slice analysis.
  • the criterion is that if the statement has been analyzed or belongs to a statement that is consistent in step S4), no slice analysis is required, otherwise a slice analysis is required. Since the statement 13 in the program v2 track belongs to a statement with a different value, it is necessary to perform slice analysis, and the process proceeds to step S8);
  • Step S8 adding the current analysis sentence to the regression error slice, and adding the dependency statement and the corresponding statement that need to be sliced according to the sentence classification in step S4) to the slice analysis queue. Therefore, the statement 13 in the program v2 is added to the regression error slice, and the statement 13 corresponding to the program v1 track is added to the slice analysis queue. Since the statement 13 in the program v2 belongs to a statement having a different value, it is necessary to add its data dependency statement 12 to the slice analysis queue as well. After the step ends, the process jumps to step S6);
  • step S6 jumps to step S9).
  • the loop process is schematically illustrated in Figure 10.
  • the solid line with an arrow in the figure indicates the dependency between the statements, and the slash fill indicates that the statement is added to the regression error slice.
  • Step S9 Output a regression error slice, and an example regression error slice is shown in FIG.
  • an example regression error slice is shown in FIG.
  • Statement 3 is deleted from program v2 relative to program v1, resulting in a different output, ie a regression error in the discussion. Therefore, the slice provides a context for the regression error, and we can accurately correct the regression error based on the slice.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)
  • Stored Programmes (AREA)

Abstract

提出一种基于切片模型的程序回归错误定位方法,在程序预处理阶段,通过对比两个版本程序源码,识别不同部分,根据识别结果对源码进行重排;在轨迹对应阶段,根据获取到的两个版本程序的执行轨迹、语句间的依赖关系和变量值信息,对两条执行轨迹上的语句进行对应、分类;在切片分析阶段,从新版本程序执行失败点为起点开始进行切片分析;根据语句实体分类及其依赖关系,回溯导致程序执行失败的语句实体,直至待分析的依赖语句为空,且被分析的当前语句不需要继续分析其依赖关系;最后,将切片分析的阶段所有被分析的语句实体作为导致回归错误的程序行为切片输出。阐明了回归错误的产生机理,对回归错误的修复具有指导作用。

Description

基于切片模型的程序回归错误定位方法 技术领域
本发明涉及可信软件及软件测试领域,特别涉及一种程序中回归错误的定位方法。
背景技术
软件测试是用来保证软件质量的基本手段,并且也是软件开发过程中最耗费人力和物力的过程。经验表明,在软件更新的过程中经常会引入回归错误,因此进行回归测试是非常有必要的。即便现在有许多技术使得回归测试的过程变得自动化,但是回归测试仅仅只是软件测试过程中的第一步。而更加重要和富有挑战性的任务是找到导致程序执行失败的程序修改,并且提供这些修改为什么会导致程序执行失败的上下文环境。然而,该过程并不简单。首先,随着程序变得越来越复杂,回归错误总是出现在特定的环境或配置之中。第二,由于时间和人力的限制,通常只能获得一个测试案例。该测试案例在旧版本程序中能够成功执行,而在新版本程序中执行失败。第三,程序执行失败的精确上下文环境是很难获得的。只有测试人员能够读懂程序执行失败的上下文环境,他们才能够依据这些信息精确的修复错误。
近年来,许多关于回归错误测试的技术被提出,例如ADD(Augmented Delta Debugging)和AFTER(Automated Fault Explanation for Regression testing)。ADD通过结合覆盖分析和Delta调试来自动化的隔离导致程序执行失败的修改。然而,ADD并不分析程序的语义,因此定位的错位可能仅仅只是避免了程序执行失败而并非真正的错误。AFTER利用基于Delta调试的动态分析以及基于符号分析的语义分析来定位回归错误。AFTER的主要问题是它的可延展性。众所周知,符号分析是一个开销巨大的过程,因此它很难被应用于大规模程序。即使这些技术能够自动化的定位导致程序执行失败的程序修改,却很少被实际应用,因为他们不能提供导致程序执行失败的上下文环境。在现有的技术当中,一个普遍接受的假设是测试者能够很容易的 理解程序为什么执行失败。事实上,对程序执行失败原因的理解并不简单,因此现有技术对修复回归错误的帮助是很少的。
因此,一个实用的回归错误定位技术不仅需要精确定位导致错误的修改,还要能提供该修改导致程序执行失败的上下文环境。
发明内容
本发明的目的在于提出一种基于切片模型的程序回归错误定位方法,通过对两个版本程序进行切片分析,输出导致程序回归错误的程序行为切片,解决程序测试中回归错误定位的问题。
为了实现上述目的,本发明采用如下技术方案:
基于切片模型的程序回归错误定位方法,包括如下步骤:
S1)、根据输入的两个版本待测程序,计算出两个版本程序源代码的不同之处,根据源代码的不同对两个版本程序的源码重排,使得相同的代码有相同的行号,不同的代码与空行对应;
S2)、用两个经过代码重排后的程序执行会导致修改版本程序执行失败的测试案例,并提取两个版本程序的执行轨迹、语句包含的变量值以及语句的依赖关系;
S3)、将执行轨迹组织成树形结构,树的每个节点是一个函数执行序列;调用轨迹函数体语句对应方法,对步骤S2)中提取到的两版本程序的执行轨迹进行对应;
S4)、根据源代码的不同、轨迹对应结果以及语句包含的变量值,将轨迹中的语句分为四类:修改导致不同的语句、流不同的语句、值不同的语句以及一致的语句;
S5)、以新版本程序执行失败点为起点开始对回归错误的产生进行切片分析,将失败点语句加入切片分析队列;
S6)、判断切片分析队列是否为空,若为空则跳转至步骤S9),否则跳转至步骤S7);
S7)、取出切片分析队列首端语句,并判断首端语句是否需要进行切片分析,若不需进行 分析则跳转至步骤S6),否则跳转至步骤S8);
S8)、将当前分析语句加入回归错误切片,并根据步骤S4)中语句分类将其需要进行切片分析的依赖语句及对应语句加入切片分析队列;
S9)、输出回归错误切片。
本发明的进一步改进在于,所述步骤S1)中代码重排的过程包括以下步骤:
S101)、根据两个版本程序的源代码,计算出两个版本程序源码的不同;
S102)、根据计算出的两个版本程序源代码的不同之处,将两个版本程序源代码中的每条语句分为两类:完全相同的语句、修改的语句;
S103)、在不改变程序语句执行顺序的基础上,使完全相同的语句具有相同的行号,修改的语句与空行对应;
S104)、输出代码重排之后的两个版本待测程序源码作为新的待测程序。
本发明的进一步改进在于,步骤S3)中执行轨迹的树形结构定义如下:树中的每一个节点为一个函数体的执行轨迹,一个节点的子节点为该节点所表述的函数体中所调用的函数体的执行轨迹;步骤S3)中从树形结构的根节点(main函数体轨迹)开始进行轨迹函数体语句对应,具体包括以下步骤:
S301)、判断当前对应的函数体中需要进行对应的语句是否为空,若为空则函数体语句对应方法执行结束返回,否则跳转至步骤S302);
S302)、迭代取出函数体中的语句作为当前进行对应的语句;
S303)、判断当前对应语句是否为函数调用语句,若为函数调用语句则跳转至步骤S304),否则跳转至步骤S306);
S304)、判断该函数调用在对应轨迹中是否有对应的函数调用,若有对应函数调用则跳转至步骤S305),否则跳转至步骤S301);
S305)、调用函数体语句对应方法对该函数体轨迹中的语句进行对应,执行结束后跳转至步骤S301);
S306)、判断当前语句在对应轨迹中是否有对应的语句,若有对应语句则跳转至步骤S307),否则跳转至步骤S301);
S307)、将当前语句与对应轨迹中的对应语句进行对应,结束后跳转至步骤S301)。
本发明的进一步改进在于:步骤S4)中语句分类的策略是,根据步骤S102)中源码语句分类、轨迹对应结果以及语句包含的变量值信息,将轨迹中的所有语句分为以下四类:
(1)修改导致不同的语句:修改的语句。
(2)流不同的语句:非修改的语句,且在对应轨迹中没有对应语句;
(3)值不同的语句:两条轨迹中有对应的语句,且语句包含的变量值至少有一个不同;
(4)一致的语句:两条轨迹中有对应的语句,且语句包含的变量值均相同;
其分类流程包括以下步骤:
S401)、判断轨迹中的语句是否已全部分类,若已全部分类则跳转至步骤S407),否则跳转至步骤S402);
S402)、迭代取出轨迹中未分类的语句,对其进行分类;
S403)、根据源代码的分类,判断该语句是否为修改的语句,若为修改的语句则标记为修改导致不同的语句并跳转至步骤S401),否则跳转至步骤S404);
S404)、根据轨迹对应结果,判断该语句是否有对应语句,若没有对应语句则将该语句标记为流不同的语句并跳转至步骤S401),否则跳转至步骤S405);
S405)、根据语句包含的变量值信息,判断该语句与对应语句中包含的变量值是否相同,如果至少包含一个变量值不相同则将该语句标记为值不同的语句并跳转至步骤S401),否则跳转至步骤S406);
S406)、将该语句标记为一致的语句并跳转至步骤S401);
S407)、轨迹中的语句分类结束,返回。
本发明的而进一步改进在于:步骤S7)中语句是否需要进行切片分析的判断标准是:如果该语句已经被分析过或属于步骤S4)中一致的语句则不需要进行切片分析,否则需要进行切片分析。
本发明的进一步改进在于:步骤S8)中需要进行切片分析的语句的分析策略是,对于步骤S4)中值不同的语句,仅将其数据依赖语句及对应轨迹中的对应语句加入切片分析队列;对于流不同的语句,仅将其控制依赖语句加入切片分析队列;对于分类为修改导致不同的语句,则将其控制依赖和数据依赖语句均加入切片分析队列。同时步骤S8)中分析的当前语句需要加入回归错误切片中。
相对于现有技术,本发明的具有以下有益效果:本发明提出了一种基于切片模型的程序回归错误定位方法,通过对两个版本程序进行切片分析,输出导致程序回归错误的程序行为切片,解决程序测试中回归错误定位的问题。在程序预处理阶段,该方法通过对比两个版本程序源码,识别其不同的部分,根据识别结果对两个版本程序的源码进行重排,在不影响程序代码执行顺序的前提下,使得两个版本程序中原来相对应的代码具有相同的行号;在轨迹对应阶段,根据获取到的两个版本程序的执行轨迹、语句间的依赖关系和变量值信息,对两条执行轨迹上的语句进行对应,并根据轨迹对应结果对语句进行分类;在切片分析阶段,以程序的控制依赖、数据依赖以及语句的分类为基础,从新版本程序执行失败点为起点开始进行切片分析;根据语句实体分类及其依赖关系,回溯导致程序执行失败的语句实体,直至待分析的依赖语句为空,且被分析的当前语句不需要继续分析其依赖关系;最后,将切片分析的阶段所有被分析的语句实体作为导致回归错误的程序行为切片输出。相比现有的回归错误定位方法,本方法阐明了回归错误的产生机理,对回归错误的修复具有指导作用。
附图说明
图1为本发明方法整体流程图;
图2为代码重排方法流程图;
图3为函数体语句对应方法流程图;
图4为语句分类过程的流程图;
图5为说明具体实施方式中示例程序示意图;
图6为源码比较结果图;
图7为代码重排结果图;
图8为轨迹对应结果图;
图9为回归错误切片图;
图10为切片分析过程图。
具体实施方式
以下结合实例详细说明本发明的实施方式。
请参阅图5所示,待测程序v1为原版本,待测程序v2为修改后的新版本。
步骤S1:根据输入的两个版本待测程序,计算出两个版本程序源代码的不同之处,根据源代码的不同对两个版本程序的源码重排,使得相同的代码有相同的行号,不同的代码与空行对应,流程图如图2所示,具体包括以下步骤:
步骤S101:根据两个版本程序的源代码,计算两个版本程序源码的不同;
步骤S102:根据计算出的两个版本程序源代码的不同之处,对源码中的语句分为两类,相同的语句和修改的语句,修改的语句进行标记(c1-c4),如图6所示;
步骤S103:在不改变程序语句执行顺序的基础上,使完全相同的语句具有相同的行号,修改的语句与空行对应,代码重排结果如图7所示;
步骤S104:输出代码重排之后的两个版本待测程序源码作为新的待测程序。
步骤S2:用两个经过代码重排后的程序执行会导致修改版本程序执行失败的测试案例<x=1,y=1,z=2>,提取两个版本程序的执行轨迹、语句包含的变量值以及语句的依赖关系;
表1程序执行轨迹
程序v1轨迹 main#c 1 2 3 5 6 7 11 12 13 mian#r
程序v2轨迹 mian#c 1 2 4 8 9 11 12 13 main#r
步骤S3:调用轨迹函数体语句对应方法,对步骤S2)中提取到的两版本程序的执行轨迹进行对应,流程图如图3所示,函数体语句对应方法:
S301)判断当前对应的函数体中需要进行对应的语句是否为空,若为空则函数体语句对应方法执行结束返回,否则跳转至步骤S302);
S302)迭代取出函数体中的语句作为当前进行对应的语句;
S303)判断当前对应语句是否为函数调用语句,若为函数调用语句则跳转至步骤S304),否则跳转至步骤S306);
S304)判断该函数调用在对应轨迹中是否有对应的函数调用,若有对应函数调用则跳转至步骤S305),否则跳转至步骤S301);
S305)调用函数体语句对应方法对该函数体轨迹中的语句进行对应,执行结束后跳转至步骤S301);
S306)判断当前语句在对应轨迹中是否有对应的语句,若有对应语句则跳转至步骤S307),否则跳转至步骤S301);
S307)将当前语句与对应轨迹中的对应语句进行对应,结束后跳转至步骤S301)。
以两条轨迹中的main函数体轨迹为例,其具体流程包括:
步骤S301:main函数体中需要对应的语句不为空,所以转S302;
步骤S302:取出程序v1中main未应的语句1,转步骤S303;
步骤S303:语句1非函数调用语句,转步骤S306;
步骤S306:程v1轨迹中main函数语句1在程序v2轨迹中有main函数语句1对应,转步骤S307;
步骤S307:将两个版本程序轨迹中main函数语句1对应,且标记为已对应语句。
重复上述步骤,直至两条轨迹中未对应的语句为空,得到轨迹对应结果如图8所示。
步骤S4:根据源代码的不同、轨迹对应结果以及语句包含的变量值,将轨迹中的语句分为四类:修改导致不同的语句、流不同的语句、值不同的语句以及一致的语句,其分类策略如下:
(1)修改导致不同的语句:修改的语句。
(2)流不同的语句:非修改的语句,且在对应轨迹中没有对应语句;
(3)值不同的语句:两条轨迹中有对应的语句,且语句包含的变量值至少有一个不同;
(4)一致的语句:两条轨迹中有对应的语句,且语句包含的变量值均相同;
其分类流程如图4所示,具体包括以下步骤:
S401)判断轨迹中的语句是否已全部分类,若已全部分类则跳转至步骤S407),否则跳转至步骤S402);
S402)迭代取出轨迹中未分类的语句,对其进行分类;
S403)根据源代码的分类,判断该语句是否为修改的语句,若为修改的语句则标记为修改导致不同的语句并跳转至步骤S401),否则跳转至步骤S404);
S404)根据轨迹对应结果,判断该语句是否有对应语句,若没有对应语句则将该语句标记为流不同的语句并跳转至步骤S401),否则跳转至步骤S405);
S405)根据语句包含的变量值信息,判断该语句与对应语句中包含的变量值是否相同,如 果至少包含一个变量值不相同则将该语句标记为值不同的语句并跳转至步骤S401),否则跳转至步骤S406);
S406)将该语句标记为一致的语句并跳转至步骤S401);
S407)轨迹中的语句分类结束,返回。
以语句2为例,其具体分类流程包括:
步骤S401:轨迹中的语句未全部分类,转S402;
步骤S402:取出轨迹中未分类的语句2;
步骤S403:语句2非修改的语句,转S403;
步骤S403:语句2有对应的语句,转S404;
步骤S404:两条轨迹中语句2包含的变量值相同,转步骤S405;
步骤S405:将两条轨迹中的语句2标记为一致的语句。
重复上述步骤,直至轨迹中所有的语句已分类,得到语句分类结果如表2所示。
表2语句分类结果
程序v1轨迹 程序v2轨迹 语句分类
1:void main(int x,int y,int z) 1:void main(int x,int y,int z) 一致的
2:int abs=x; 2:int abs=x; 一致的
3:if(x<0)   修改导致不同
  4:abs=-x; 流不同
5:int max=y;   修改导致不同
6:if(y<z)   修改导致不同
7:max=z;   修改导致不同
  8:int max=z; 修改导致不同
  9:if(y>z) 修改导致不同
11:int out=max; 11:int out=max; 一致的
12:out=abs+out; 12:out=abs+out; 值不同
13:printf(“%d”,out); 13:printf(“%d”,out); 值不同
步骤S5:以新版本程序执行失败点为起点开始对回归错误的产生进行切片分析,将失败点语句加入切片分析队列,在该示例中新版本程序即程序v2,其执行失败点语句即输出点语句13,所以将程序v2轨迹中的语句13加入切片分析队列;
步骤S6:判断切片分析队列是否为空,若为空则跳转至步骤S9),否则跳转至步骤S7),当前队列不为空,所以跳转至步骤S7);
步骤S7:取出切片分析队列首端语句,并判断首端语句是否需要进行切片分析,若不需进行分析则跳转至步骤S6),否则跳转至步骤S8),是否需要进行切片分析的判断标准是:如果该语句已经被分析过或属于步骤S4)中一致的语句则不需要进行切片分析,否则需要进行切片分析。由于程序v2轨迹中的语句13属于值不同的语句,所以需要进行切片分析,跳转至步骤S8);
步骤S8:将当前分析语句加入回归错误切片,并根据步骤S4)中语句分类将其需要进行切片分析的依赖语句及对应语句加入切片分析队列。所以将程序v2中的语句13加入回归错误切片,并将程序v1轨迹中与之对应的语句13加入切片分析队列。因为程序v2中的语句13属于值不同的语句,所以需要将其数据依赖语句12也加入切片分析队列。该步骤结束后跳转至步骤S6);
重复上述步骤,直至步骤S6)跳转至步骤S9)。该循环过程示意如图10所示,图中带箭头的实线表示语句间的依赖关系,斜杠填充表示该语句被加入到回归错误切片中。
步骤S9:输出回归错误切片,示例的回归错误切片如图9所示。从该切片可以看出,由 于程序v2相对程序v1删除了语句3,从而导致了输出的不同,即讨论的回归错误。因此,该切片提供了回归错误产生的上下文环境,同时我们可以根据该切片精确的修复回归错误。

Claims (7)

  1. 基于切片模型的程序回归错误定位方法,其特征在于,包括以下步骤:
    S1)、根据输入的两个版本待测程序,计算出两个版本程序源代码的不同之处,根据源代码的不同对两个版本程序的源码重排,使得相同的代码有相同的行号,不同的代码与空行对应;
    S2)、用两个经过代码重排后的程序执行会导致修改版本程序执行失败的测试案例,并提取两个版本程序的执行轨迹、语句包含的变量值以及语句的依赖关系;
    S3)、将执行轨迹组织成树形结构,树的每个节点是一个函数执行序列;调用轨迹函数体语句对应方法,对步骤S2)中提取到的两版本程序的执行轨迹进行对应;
    S4)、根据源代码的不同、轨迹对应结果以及语句包含的变量值,将轨迹中的语句分为四类:修改导致不同的语句、流不同的语句、值不同的语句以及一致的语句;
    S5)、以新版本程序执行失败点为起点开始对回归错误的产生进行切片分析,将失败点语句加入切片分析队列;
    S6)、判断切片分析队列是否为空,若为空则跳转至步骤S9),否则跳转至步骤S7);
    S7)、取出切片分析队列首端语句,并判断首端语句是否需要进行切片分析,若不需进行分析则跳转至步骤S6),否则跳转至步骤S8);
    S8)、将当前分析语句加入回归错误切片,并根据步骤S4)中语句分类将其需要进行切片分析的依赖语句及对应语句加入切片分析队列,结束后跳转至步骤S6);
    S9)、输出回归错误切片。
  2. 根据权利要求1所述的基于切片模型的程序回归错误定位方法,其特征在于,步骤S1)中代码重排的过程包括以下步骤:
    S101)、根据两个版本程序的源代码,计算出两个版本程序源码的不同;
    S102)、根据计算出的两个版本程序源代码的不同之处,将两个版本程序源代码中的每条语句分为两类:完全相同的语句、修改的语句;
    S103)、在不改变程序语句执行顺序的基础上,对两个版本程序的源码进行重排,使完全相同的语句具有相同的行号,修改的语句与空行对应;
    S104)、输出代码重排之后的两个版本待测程序源码作为新的待测程序。
  3. 根据权利要求1所述的基于切片模型的程序回归错误定位方法,其特征在于,步骤S3)中执行轨迹的树形结构定义如下:树中的每一个节点为一个函数体的执行轨迹,一个节点的子节点为该节点所表述的函数体中所调用的函数体的执行轨迹;步骤S3)中从树形结构的根节点开始进行轨迹函数体语句对应,具体包括以下步骤:
    S301)、判断当前对应的函数体中需要进行对应的语句是否为空,若为空则函数体语句对应方法执行结束返回,否则跳转至步骤S302);
    S302)、迭代取出函数体中的语句作为当前进行对应的语句;
    S303)、判断当前对应语句是否为函数调用语句,若为函数调用语句则跳转至步骤S304),否则跳转至步骤S306);
    S304)、判断该函数调用在对应轨迹中是否有对应的函数调用,若有对应函数调用则跳转至步骤S305),否则跳转至步骤S301);
    S305)、调用函数体语句对应方法对该函数体轨迹中的语句进行对应,执行结束后跳转至步骤S301);
    S306)、判断当前语句在对应轨迹中是否有对应的语句,若有对应语句则跳转至步骤S307),否则跳转至步骤S301);
    S307)、将当前语句与对应轨迹中的对应语句进行对应,结束后跳转至步骤S301)。
  4. 根据权利要求1所述的基于切片模型的程序回归错误定位方法,其特征在于,步骤S4)中语句分类的方法为:根据步骤S102)中源码语句分类、轨迹对应结果以及语句包含的变量值信息,将轨迹中的所有语句分为以下四类:
    (1)修改导致不同的语句:修改的语句;
    (2)流不同的语句:非修改的语句,且在对应轨迹中没有对应语句;
    (3)值不同的语句:两条轨迹中有对应的语句,且语句包含的变量值至少有一个不同;
    (4)一致的语句:两条轨迹中有对应的语句,且语句包含的变量值均相同。
  5. 根据权利要求1或4所述的基于切片模型的程序回归错误定位方法,其特征在于,步骤S4)中分类流程包括以下步骤:
    S401)、判断轨迹中的语句是否已全部分类,若已全部分类则跳转至步骤S407),否则跳转至步骤S402);
    S402)、迭代取出轨迹中未分类的语句,对其进行分类;
    S403)、根据源代码的分类,判断该语句是否为修改的语句,若为修改的语句则标记为修改导致不同的语句并跳转至步骤S401),否则跳转至步骤S404);
    S404)、根据轨迹对应结果,判断该语句是否有对应语句,若没有对应语句则将该语句标记为流不同的语句并跳转至步骤S401),否则跳转至步骤S405);
    S405)、根据语句包含的变量值信息,判断该语句与对应语句中包含的变量值是否相同,如果至少包含一个变量值不相同则将该语句标记为值不同的语句并跳转至步骤S401),否则跳转至步骤S406);
    S406)、将该语句标记为一致的语句并跳转至步骤S401);
    S407)、轨迹中的语句分类结束,返回。
  6. 根据权利要求1所述的基于切片模型的程序回归错误定位方法,其特征在于,步骤S7)中语句是否需要进行切片分析的判断标准是:如果该语句已经被分析过或属于步骤S4)中一致的语句则不需要进行切片分析,否则需要进行切片分析。
  7. 根据权利要求1所述的基于切片模型的程序回归错误定位方法,其特征在于,步骤S8) 中需要进行切片分析的语句的分析策略是:对于步骤S4)中值不同的语句,仅将其数据依赖语句及对应轨迹中的对应语句加入切片分析队列;对于流不同的语句,仅将其控制依赖语句加入切片分析队列;对于分类为修改导致不同的语句,则将其控制依赖和数据依赖语句均加入切片分析队列。
PCT/CN2016/090956 2016-05-26 2016-07-22 基于切片模型的程序回归错误定位方法 Ceased WO2017201853A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610368555.0 2016-05-26
CN201610368555.0A CN106095663B (zh) 2016-05-26 2016-05-26 基于切片模型的程序回归错误定位方法

Publications (1)

Publication Number Publication Date
WO2017201853A1 true WO2017201853A1 (zh) 2017-11-30

Family

ID=57230282

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/090956 Ceased WO2017201853A1 (zh) 2016-05-26 2016-07-22 基于切片模型的程序回归错误定位方法

Country Status (2)

Country Link
CN (1) CN106095663B (zh)
WO (1) WO2017201853A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115203041A (zh) * 2022-07-20 2022-10-18 北京信息科技大学 一种面向持续集成过程的模糊测试方法
CN121052178A (zh) * 2025-10-31 2025-12-02 上海合见工业软件集团有限公司 一种基于多文件跳转的导航方法、电子设备及存储介质

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107643905B (zh) * 2017-09-13 2021-01-12 扬州大学 一种面向软件版本一致性缺陷的自动修复方法
CN110851353B (zh) * 2019-10-22 2023-03-31 天津大学 一种基于Delta Debugging与约束求解的并发程序缺陷定位方法
CN114092288B (zh) * 2020-11-24 2024-07-30 北京航空航天大学 一种面向编程初学者的个性化智能辅导方法
CN115858335A (zh) * 2022-10-25 2023-03-28 上海丰蕾信息科技有限公司 一种针对plc程序的回归测试方法、装置及计算机设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101859276A (zh) * 2010-05-14 2010-10-13 东南大学 一种基于层次切片的回归测试用例选择方法
CN101916222A (zh) * 2010-08-09 2010-12-15 哈尔滨工程大学 基于控制流图遍历和切片前向遍历相结合的软件测试方法
US20110239204A1 (en) * 2010-03-29 2011-09-29 Gm Global Technology Operations, Inc. Method and apparatus for analyzing software
CN103970845A (zh) * 2014-04-28 2014-08-06 南京邮电大学 基于程序切片技术的网页过滤方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7926036B2 (en) * 2007-04-26 2011-04-12 Microsoft Corporation Technologies for code failure proneness estimation
CN102902619B (zh) * 2011-07-29 2015-09-09 阿里巴巴集团控股有限公司 Web应用程序的回归测试方法和装置
CN103678097A (zh) * 2012-09-05 2014-03-26 百度在线网络技术(北京)有限公司 一种选择回归测试用例的方法和装置
CN105446723B (zh) * 2014-09-02 2018-11-23 国际商业机器公司 用于标识源代码版本之间的语义区别的方法和装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110239204A1 (en) * 2010-03-29 2011-09-29 Gm Global Technology Operations, Inc. Method and apparatus for analyzing software
CN101859276A (zh) * 2010-05-14 2010-10-13 东南大学 一种基于层次切片的回归测试用例选择方法
CN101916222A (zh) * 2010-08-09 2010-12-15 哈尔滨工程大学 基于控制流图遍历和切片前向遍历相结合的软件测试方法
CN103970845A (zh) * 2014-04-28 2014-08-06 南京邮电大学 基于程序切片技术的网页过滤方法

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115203041A (zh) * 2022-07-20 2022-10-18 北京信息科技大学 一种面向持续集成过程的模糊测试方法
CN121052178A (zh) * 2025-10-31 2025-12-02 上海合见工业软件集团有限公司 一种基于多文件跳转的导航方法、电子设备及存储介质

Also Published As

Publication number Publication date
CN106095663B (zh) 2017-06-27
CN106095663A (zh) 2016-11-09

Similar Documents

Publication Publication Date Title
WO2017201853A1 (zh) 基于切片模型的程序回归错误定位方法
CN108509336B (zh) 一种操作系统规范形式化验证与测试方法
US9032371B2 (en) Method and apparatus for automatic diagnosis of software failures
EP3032425A1 (en) Integrated automated test case generation for safety-critical software
US20150370685A1 (en) Defect localization in software integration tests
US9384117B2 (en) Machine and methods for evaluating failing software programs
US20060107121A1 (en) Method of speeding up regression testing using prior known failures to filter current new failures when compared to known good results
US20160342720A1 (en) Method, system, and computer program for identifying design revisions in hardware design debugging
CN103092748A (zh) 一种确定需要进行回归测试的测试用例的方法及系统
CN106484605A (zh) 一种实现软件自动化测试的方法和系统
CN103198016B (zh) 基于联合依赖概率建模的软件错误定位方法
WO2025246269A1 (zh) 一种测试代码修复方法及相关设备
US11256612B2 (en) Automated testing of program code under development
US10481969B2 (en) Configurable system wide tests
Petrulio et al. SZZ in the time of pull requests
CN111831541B (zh) 一种基于风险轨迹的软件缺陷定位方法
CN107643905A (zh) 一种面向软件版本一致性缺陷的自动修复方法
CN118860848A (zh) 一种实时嵌入式软件自动化闭环测试的方法
CN109634842B (zh) 基于qt应用程序的测试方法和系统
Ulewicz et al. System regression test prioritization in factory automation: Relating functional system tests to the tested code using field data
CN118672925A (zh) 单元测试代码的生成方法、装置、电子设备和存储介质
US11740895B2 (en) Generation of software program repair explanations
Ignarra et al. A Workflow for Automated Testing of a Safety-Critical Embedded Subsystem
CN105677996B (zh) 一种芯片验证中确定回归测试版本异常源头的方法
CN103150254B (zh) 基于状态依赖概率建模的软件错误定位方法

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16902840

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 23.05.2019)

122 Ep: pct application non-entry in european phase

Ref document number: 16902840

Country of ref document: EP

Kind code of ref document: A1