[go: up one dir, main page]

CN103744782A - Method and device for acquiring program execution sequence - Google Patents

Method and device for acquiring program execution sequence Download PDF

Info

Publication number
CN103744782A
CN103744782A CN201410001275.7A CN201410001275A CN103744782A CN 103744782 A CN103744782 A CN 103744782A CN 201410001275 A CN201410001275 A CN 201410001275A CN 103744782 A CN103744782 A CN 103744782A
Authority
CN
China
Prior art keywords
execution sequence
program
function
fundamental block
information
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.)
Pending
Application number
CN201410001275.7A
Other languages
Chinese (zh)
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.)
Nanjing University
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Nanjing University
Beijing Baidu Netcom Science and Technology Co Ltd
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 Nanjing University, Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Nanjing University
Priority to CN201410001275.7A priority Critical patent/CN103744782A/en
Publication of CN103744782A publication Critical patent/CN103744782A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

本发明提出一种程序执行序列的获取方法及装置,其中,程序执行序列的获取方法包括:在编译阶段为被测程序选择插桩节点植入探针,在探针中写入保存函数、收集序列函数和还原函数;当被测程序根据当前测试用例执行分支时,输出对应的基本块信息;以及根据所述基本块信息得到基本块图级别的执行序列,根据执行序列与对应的基本块图生成包含行号信息的执行序列信息。本发明实施例,通过插桩模块在探针中写入保存函数和还原函数,可以在不修改程序源代码的情况下,实现目标代码的插桩,通过执行测试用例后可以获得程序的多个执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位等。

Figure 201410001275

The present invention proposes a method and device for obtaining a program execution sequence, wherein the method for obtaining a program execution sequence includes: selecting an instrumentation node for the program under test at the compilation stage and implanting a probe, writing a saving function in the probe, collecting Sequence function and restore function; when the program under test executes a branch according to the current test case, output the corresponding basic block information; Generate execution sequence information including line number information. In the embodiment of the present invention, by writing the save function and restore function in the probe through the instrumentation module, the instrumentation of the target code can be realized without modifying the source code of the program, and multiple test cases of the program can be obtained. Execute the sequence, which in turn can help testers to achieve software engineering tasks, such as error location.

Figure 201410001275

Description

程序执行序列的获取方法及装置Method and device for acquiring program execution sequence

技术领域technical field

本发明涉及计算机技术领域,尤其涉及一种程序执行序列的获取方法及装置。The present invention relates to the field of computer technology, in particular to a method and device for acquiring a program execution sequence.

背景技术Background technique

程序测试是指对一个完成了全部或部分功能、模块的计算机程序在正式使用前的检测,以确保该程序能按预定的方式正确地运行。目前采用的测试方法包括白盒测试和黑盒测试等。Program testing refers to the inspection of a computer program that has completed all or part of its functions and modules before it is officially used, so as to ensure that the program can run correctly according to the predetermined method. Currently used testing methods include white box testing and black box testing.

其中,白盒测试也被称作结构测试或者逻辑驱动测试,它主要测试程序内部的结构。测试人员根据程序的内部逻辑结构信息,设计测试用例并测试程序的逻辑路径,验证执行结果。与白盒测试相对的是黑盒测试,黑盒测试又称为功能测试。黑盒测试不考虑软件内部结构和内部特性,而只关注接口输入输出的正确性。Among them, white box testing is also called structural testing or logic-driven testing, which mainly tests the internal structure of the program. Testers design test cases and test the logical path of the program based on the internal logical structure information of the program, and verify the execution results. The opposite of white box testing is black box testing, which is also called functional testing. Black-box testing does not consider the internal structure and internal characteristics of the software, but only focuses on the correctness of the interface input and output.

覆盖技术是白盒测试中常用的技术之一,逻辑覆盖是一种标准,表示测试用例在程序执行时对程序逻辑的覆盖程度。代码覆盖主要关注程序运行时内部逻辑的覆盖程度,按照粒度的不同可以分为:语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、条件组合覆盖等。覆盖测试可以通过检测是否对程序的关键路径都已经覆盖完全来检查测试用例设计的合理性。程序插桩是覆盖测试所依赖的关键技术。插桩技术在不影响程序逻辑特性的前提下,使得运行时覆盖信息的收集成为可能。按照插桩时机的不同,程序插桩技术主要分为两种:(1)源代码插桩:源代码插桩就是直接对程序源文件进行修改,插入相应的桩代码。源代码插桩需要对源代码进行完整的词法分析和语法分析,从而确定插桩的位置。(2)目标代码插桩:相比源代码插桩,目标代码插桩不会影响源代码,但是会影响生成的目标代码。但是,目标代码中通常不具有相应的程序结构。基于程序插桩技术,就可以在覆盖测试中获得各个粒度级别的覆盖信息。Coverage technology is one of the commonly used techniques in white-box testing. Logic coverage is a standard that indicates the degree of coverage of program logic by test cases during program execution. Code coverage mainly focuses on the degree of coverage of the internal logic of the program at runtime. According to different granularity, it can be divided into: statement coverage, decision coverage, condition coverage, decision/condition coverage, condition combination coverage, etc. Coverage testing can check the rationality of test case design by detecting whether the critical path of the program has been completely covered. Program instrumentation is a key technology that coverage testing relies on. The instrumentation technology makes it possible to collect runtime coverage information without affecting the logic characteristics of the program. According to the timing of instrumentation, program instrumentation techniques are mainly divided into two types: (1) Source code instrumentation: source code instrumentation is to directly modify the program source file and insert the corresponding stub code. Source code instrumentation requires a complete lexical analysis and syntax analysis of the source code to determine the location of the instrumentation. (2) Object code instrumentation: Compared with source code instrumentation, object code instrumentation will not affect the source code, but will affect the generated object code. However, there is usually no corresponding program structure in the object code. Based on the program instrumentation technology, coverage information at various granularity levels can be obtained in the coverage test.

在科研工作中通常使用源代码插桩的方式获取执行序列,这样能够获得精确的结果并且易于操作,但在工业应用中,通常不允许修改程序的源代码,因此,在工业应用中不能使用源代码插桩的方式来获取执行序列。In scientific research work, source code instrumentation is usually used to obtain the execution sequence, which can obtain accurate results and is easy to operate, but in industrial applications, it is usually not allowed to modify the source code of the program, so the source code cannot be used in industrial applications. The method of code instrumentation to obtain the execution sequence.

发明内容Contents of the invention

本发明旨在至少解决上述技术问题之一。The present invention aims to solve at least one of the above-mentioned technical problems.

为此,本发明的第一个目的在于提出一种程序执行序列的获取方法。该方法,在不修改程序源代码的情况下,实现了目标代码的插桩,执行测试用例后可以获得程序的执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位。Therefore, the first object of the present invention is to propose a method for acquiring a program execution sequence. This method realizes the instrumentation of the target code without modifying the source code of the program, and the execution sequence of the program can be obtained after the test case is executed, which in turn can help the tester to realize software engineering tasks, such as error location.

为了实现上述目的,本发明第一方面实施例的程序执行序列的获取方法,包括以下步骤:In order to achieve the above object, the method for obtaining the program execution sequence of the embodiment of the first aspect of the present invention includes the following steps:

在编译阶段为被测程序选择插桩节点植入探针,在探针中写入保存函数、收集序列函数和还原函数;In the compilation stage, select the instrumentation node to implant the probe for the program under test, and write the save function, collection sequence function and restore function in the probe;

当被测程序根据当前测试用例执行分支时,输出对应的基本块信息;以及When the program under test executes a branch according to the current test case, output the corresponding basic block information; and

根据基本块信息得到基本块图级别的执行序列,根据执行序列与对应的基本块图生成包含行号信息的执行序列信息。The execution sequence at the basic block diagram level is obtained according to the basic block information, and the execution sequence information including line number information is generated according to the execution sequence and the corresponding basic block diagram.

本发明实施例的程序执行序列的获取方法,通过在探针中写入保存函数和还原函数,可以在不修改程序源代码的情况下,实现目标代码的插桩,通过执行测试用例后可以获得程序的多个执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位。In the method for obtaining the program execution sequence in the embodiment of the present invention, by writing the save function and the restore function in the probe, the instrumentation of the target code can be realized without modifying the program source code, and the test case can be obtained after executing the test case. Multiple execution sequences of a program, which in turn can help testers achieve software engineering tasks, such as fault location.

为了实现上述目的,本发明第二方面实施例的程序执行序列的获取装置,包括:插桩模块、执行模块以及生成模块。In order to achieve the above object, the apparatus for acquiring a program execution sequence according to the embodiment of the second aspect of the present invention includes: an instrumentation module, an execution module, and a generation module.

本发明实施例的程序执行序列的获取装置,通过插桩模块在探针中写入保存函数和还原函数,可以在不修改程序源代码的情况下,实现目标代码的插桩,通过执行测试用例后可以获得程序的多个执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位等。The device for obtaining the program execution sequence in the embodiment of the present invention writes the save function and the restore function in the probe through the instrumentation module, and can realize the instrumentation of the target code without modifying the source code of the program. By executing the test case After that, multiple execution sequences of the program can be obtained, which in turn can help testers to achieve software engineering tasks, such as error location.

本发明附加的方面和优点将在下面的描述中部分给出,部分将从下面的描述中变得明显,或通过本发明的实践了解到。Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention.

附图说明Description of drawings

本发明上述的和/或附加的方面和优点从下面结合附图对实施例的描述中将变得明显和容易理解,其中,The above and/or additional aspects and advantages of the present invention will become apparent and easy to understand from the following description of the embodiments in conjunction with the accompanying drawings, wherein,

图1是根据本发明一个实施例的程序执行序列的获取方法的流程图;FIG. 1 is a flowchart of a method for acquiring a program execution sequence according to an embodiment of the present invention;

图2是根据本发明另一个实施例的程序执行序列的获取方法的流程图;FIG. 2 is a flowchart of a method for obtaining a program execution sequence according to another embodiment of the present invention;

图3是根据本发明一个实施例的基本块图的示意图;3 is a schematic diagram of a basic block diagram according to an embodiment of the present invention;

图4是根据本发明一个实施例的程序执行序列的获取装置的结构示意图;FIG. 4 is a schematic structural diagram of an acquisition device for a program execution sequence according to an embodiment of the present invention;

图5是根据本发明另一个实施例的程序执行序列的获取装置的结构示意图。Fig. 5 is a schematic structural diagram of an apparatus for acquiring a program execution sequence according to another embodiment of the present invention.

具体实施方式Detailed ways

下面详细描述本发明的实施例,实施例的示例在附图中示出,其中自始至终相同或类似的标号表示相同或类似的元件或具有相同或类似功能的元件。下面通过参考附图描述的实施例是示例性的,仅用于解释本发明,而不能理解为对本发明的限制。相反,本发明的实施例包括落入所附加权利要求书的精神和内涵范围内的所有变化、修改和等同物。Embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below by referring to the figures are exemplary only for explaining the present invention and should not be construed as limiting the present invention. On the contrary, the embodiments of the present invention include all changes, modifications and equivalents coming within the spirit and scope of the appended claims.

在本发明的描述中,术语“第一”、“第二”等仅用于描述目的,而不能理解为指示或暗示相对重要性。在本发明的描述中,除非另有明确的规定和限定,术语“相连”、“连接”应做广义理解,例如,可以是固定连接,也可以是可拆卸连接,或一体地连接;可以是机械连接,也可以是电连接;可以是直接相连,也可以通过中间媒介间接相连。对于本领域的普通技术人员而言,可以具体情况理解上述术语在本发明中的具体含义。此外,在本发明的描述中,除非另有说明,“多个”的含义是两个或两个以上。In the description of the present invention, the terms "first", "second", etc. are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance. In the description of the present invention, unless otherwise specified and limited, the terms "connected" and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be A mechanical connection can also be an electrical connection; it can be a direct connection or an indirect connection through an intermediary. Those of ordinary skill in the art can understand the specific meanings of the above terms in the present invention in specific situations. In addition, in the description of the present invention, unless otherwise specified, "plurality" means two or more.

流程图中或在此以其他方式描述的任何过程或方法描述可以被理解为,表示包括一个或更多个用于实现特定逻辑功能或过程的步骤的可执行指令的代码的模块、片段或部分,并且本发明的优选实施方式的范围包括另外的实现,其中可以不按所示出或讨论的顺序,包括根据所涉及的功能按基本同时的方式或按相反的顺序,来执行功能,这应被本发明的实施例所属技术领域的技术人员所理解。Any process or method descriptions in flowcharts or otherwise described herein may be understood to represent modules, segments or portions of code comprising one or more executable instructions for implementing specific logical functions or steps of the process , and the scope of preferred embodiments of the invention includes alternative implementations in which functions may be performed out of the order shown or discussed, including substantially concurrently or in reverse order depending on the functions involved, which shall It is understood by those skilled in the art to which the embodiments of the present invention pertain.

下面参考附图描述本发明实施例的程序执行序列的获取方法及装置。The method and device for acquiring a program execution sequence in the embodiments of the present invention will be described below with reference to the accompanying drawings.

图1是根据本发明一个实施例的程序执行序列的获取方法的流程图。FIG. 1 is a flow chart of a method for acquiring a program execution sequence according to an embodiment of the present invention.

如图1所示,程序执行序列的获取方法包括以下步骤:As shown in Figure 1, the method for obtaining the program execution sequence includes the following steps:

S101,在编译阶段为被测程序选择插桩节点植入探针,在探针中写入保存函数、收集序列函数和还原函数。S101 , selecting an instrumentation node for the program under test at the compilation stage to implant a probe, and writing a save function, a collection sequence function and a restore function into the probe.

其中,保存函数用于在调用收集序列函数之前,将寄存器数据保存到内存中;还原函数用于在调用收集序列函数之后,将保存在内存中的寄存器数据进行还原。Among them, the save function is used to save the register data in the memory before calling the collection sequence function; the restore function is used to restore the register data saved in the memory after calling the collection sequence function.

在探针中写入保存函数的目的是保存收集序列函数的上下文场景;在探针中写入还原函数的目的是恢复收集序列函数上下文场景;在探针中写入收集序列函数的目的是收集程序执行序列。The purpose of writing the save function in the probe is to save the context scene of the collection sequence function; the purpose of writing the restore function in the probe is to restore the context scene of the collection sequence function; the purpose of writing the collection sequence function in the probe is to collect sequence of program execution.

另外,在为被测程序选择插桩节点植入探针之前,该方法还可以包括:预处理被测程序的源文件,对源文件划分基本块和分支,并绘制基本块图。In addition, before selecting a stub node for the program under test to implant probes, the method may further include: preprocessing the source file of the program under test, dividing the source file into basic blocks and branches, and drawing a basic block diagram.

绘制完基本块图之后,根据基本块图确定需要插桩的分支,然后根据需要插桩的分支确定插桩节点。After drawing the basic block diagram, determine the branch that needs to be inserted according to the basic block diagram, and then determine the insertion node according to the branch that needs to be inserted.

S102,当被测程序根据当前测试用例执行分支时,输出对应的基本块信息。S102, when the program under test executes a branch according to the current test case, output corresponding basic block information.

测试用例是由测试数据和预期结果构成的,在本发明实施例中可以采用多个测试用例,这些测试用例包括执行成功的测试用例和执行失败的测试用例。执行不同测试用例可以获得不同的分支信息。A test case is composed of test data and expected results. Multiple test cases may be used in the embodiment of the present invention, and these test cases include test cases that are successfully executed and test cases that fail to execute. Different branch information can be obtained by executing different test cases.

当被测程序根据当前测试用例执行分支时,会执行分支中的基本块。When the program under test executes a branch according to the current test case, the basic blocks in the branch are executed.

S103,根据基本块信息得到基本块图级别的执行序列,根据执行序列与对应的基本块图生成包含行号信息的执行序列信息。S103. Obtain an execution sequence at the basic block diagram level according to the basic block information, and generate execution sequence information including line number information according to the execution sequence and the corresponding basic block diagram.

在本实施例中,在执行分支中的基本块时会触发收集序列函数收集基本块的执行序列;然后可以通过面向对象、直译式计算机程序设计语言处理包含执行序列的执行文件以及存放程序的覆盖信息和基本块图信息的文件,得到易读的执行序列信息即包含行号信息的执行序列信息。In this embodiment, when the basic block in the branch is executed, the collection sequence function will be triggered to collect the execution sequence of the basic block; then the execution file containing the execution sequence and the coverage of the stored program can be processed by an object-oriented, literal translation computer programming language information and basic block diagram information files to obtain easy-to-read execution sequence information, that is, execution sequence information including line number information.

上述程序执行序列的获取方法,在不修改程序源代码的情况下,实现了目标代码的插桩,执行测试用例后可以获得程序的执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位。The method for obtaining the execution sequence of the above program realizes the instrumentation of the target code without modifying the source code of the program. After executing the test case, the execution sequence of the program can be obtained, which in turn can help testers realize software engineering tasks, such as error location .

图2是根据本发明另一个实施例的程序执行序列的获取方法的流程图。Fig. 2 is a flow chart of a method for obtaining a program execution sequence according to another embodiment of the present invention.

如图2所示,程序执行序列的获取方法包括以下步骤:As shown in Figure 2, the method for obtaining the program execution sequence includes the following steps:

S200,预处理被测程序的源文件,对源文件划分基本块和分支,并绘制基本块图。S200, preprocessing the source file of the program under test, dividing the source file into basic blocks and branches, and drawing a basic block diagram.

假定,本实施例中的待测程序的源文件如下:Assume that the source file of the program to be tested in this embodiment is as follows:

Figure BDA0000452422590000041
Figure BDA0000452422590000041

Figure BDA0000452422590000051
Figure BDA0000452422590000051

通过代码覆盖工具绘制得到的基本块(BB)图如图3所示,从图3可以看出该程序被划分成为9个基本块,即BB0-BB8。其中BB0、BB2、BB7、BB8没有对应的源代码信息,这些是编译工具插入的辅助基本块,相应的分支(arc)也是虚拟的分支。根据有向图的基本概念,每一个顶点的出度和等于其入度和。其中,BB0是虚拟的开始入口节点,BB8是虚拟的出口节点,BB0的入度和为0,且BB8的出度和为0。The basic block (BB) diagram drawn by the code coverage tool is shown in Figure 3. From Figure 3, it can be seen that the program is divided into 9 basic blocks, namely BB0-BB8. Among them, BB0, BB2, BB7, and BB8 have no corresponding source code information. These are auxiliary basic blocks inserted by the compilation tool, and the corresponding branches (arc) are also virtual branches. According to the basic concept of a directed graph, the out-degree sum of each vertex is equal to its in-degree sum. Among them, BB0 is the virtual start entry node, BB8 is the virtual exit node, the in-degree sum of BB0 is 0, and the out-degree sum of BB8 is 0.

S201,在编译阶段为被测程序选择插桩节点植入探针,在探针中写入保存函数、收集序列函数和还原函数。S201, selecting an instrumentation node for the program under test at the compilation stage to implant a probe, and writing a save function, a collection sequence function and a restore function into the probe.

在本实施例中,通过步骤S200绘制完如图3所示的基本块图之后,可以根据基本块图确定需要插桩的分支,然后根据需要插桩的分支确定插桩节点。In this embodiment, after drawing the basic block diagram as shown in FIG. 3 through step S200, the branches to be inserted can be determined according to the basic block diagram, and then the nodes to be inserted can be determined according to the branches to be inserted.

在程序编译阶段在所确定的插桩节点植入探针,在该实施例中要为arc0-arc9的所有边都插桩。在探针中写入保存函数的目的是保存收集序列函数的上下文场景;在探针中写入还原函数的目的是恢复收集序列函数上下文场景。In the program compilation stage, probes are implanted at the determined insertion nodes, and in this embodiment, all edges of arc0-arc9 are to be inserted. The purpose of writing the save function in the probe is to save the context scene of the collection sequence function; the purpose of writing the restore function in the probe is to restore the context scene of the collection sequence function.

另外,在本实施例中,保存函数和还原函数采用内联汇编(即在高级语言例如C语言中插入汇编语言),可以直接访问寄存器,提高效率。In addition, in this embodiment, the save function and the restore function use inline assembly (that is, insert assembly language into a high-level language such as C language), which can directly access registers and improve efficiency.

S202,当被测程序根据当前测试用例执行分支时,输出对应的基本块信息。S202, when the program under test executes a branch according to the current test case, output corresponding basic block information.

测试用例是由测试数据和预期结果构成的,在本发明实施例中可以采用多个测试用例,这些测试用例包括执行成功的测试用例和执行失败的测试用例。执行不同测试用例可以获得不同的分支信息。A test case is composed of test data and expected results. Multiple test cases may be used in the embodiment of the present invention, and these test cases include test cases that are successfully executed and test cases that fail to execute. Different branch information can be obtained by executing different test cases.

S203,根据基本块信息得到基本块图级别的执行序列,根据执行序列与对应的基本块图生成包含行号信息的执行序列信息。S203. Obtain an execution sequence at the basic block diagram level according to the basic block information, and generate execution sequence information including line number information according to the execution sequence and the corresponding basic block diagram.

执行编译后的程序,输出的包含基本块图级别的执行序列的执行文件为:Execute the compiled program, and the output execution file containing the execution sequence at the basic block diagram level is:

demo.gcda0demo.gcda0

demo.gcda1demo.gcda1

demo.gcda2demo.gcda2

demo.gcda4demo.gcda4

demo.gcda2demo.gcda2

demo.gcda4demo.gcda4

demo.gcda2demo.gcda2

demo.gcda4demo.gcda4

demo.gcda3demo.gcda3

demo.gcda5demo.gcda5

demo.gcda7demo.gcda7

demo.gcda9demo.gcda9

其中,上述执行文件的第一列和第二列用空格隔开,第一列为分支所属的文件,第二列为分支对应于基本块图中的arc号,即0表示图3中的arc0,1表示图3中的arc1,2表示图3中的arc2,以此类推。Among them, the first column and the second column of the above execution file are separated by spaces, the first column is the file to which the branch belongs, and the second column is the branch corresponding to the arc number in the basic block diagram, that is, 0 means arc0 in Figure 3 , 1 means arc1 in Figure 3, 2 means arc2 in Figure 3, and so on.

在本实施例中,可以通过面向对象、直译式计算机程序设计语言例如Python语言处理执行文件以及存放程序的覆盖信息和基本块图信息的文件,得到易读的执行序列信息即包含行号信息的执行序列信息为:In this embodiment, an object-oriented, literal translation computer programming language such as Python language can be used to process the execution file and the file storing the coverage information and basic block diagram information of the program to obtain easy-to-read execution sequence information that includes line number information. The execution sequence information is:

[2,3,4,5][2,3,4,5]

[5,7][5,7]

[5,7][5,7]

[5,7][5,7]

[10,11][10,11]

[13][19][13][19]

其中,该执行序列信息按照序列的执行顺序记录,中括号表示一个块(block),内部数字表示该block所包含的语句。Wherein, the execution sequence information is recorded according to the execution order of the sequence, the square brackets represent a block, and the internal numbers represent the statements contained in the block.

S204,获得多个执行序列信息,根据执行序列信息进行被测程序的错误定位。S204, obtaining a plurality of execution sequence information, and locating the error of the program under test according to the execution sequence information.

通过步骤S201-203可以获得多个测试用例对应的执行序列信息,根据上述执行序列信息生成多个图,使用子图挖掘算法对生成的图进行挖掘,进而根据挖掘结果对被测程序进行错误定位。Through steps S201-203, the execution sequence information corresponding to multiple test cases can be obtained, multiple graphs are generated according to the above execution sequence information, and the generated graphs are mined using the subgraph mining algorithm, and then the error location of the tested program is performed according to the mining results .

上述程序执行序列的获取方法,通过在探针中写入保存函数和还原函数,可以在不修改程序源代码的情况下,实现目标代码的插桩,通过执行测试用例后可以获得程序的多个执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位。The method for obtaining the above program execution sequence, by writing the save function and the restore function in the probe, can realize the instrumentation of the target code without modifying the program source code, and can obtain multiple programs by executing the test case. Execution sequences, which in turn can help testers achieve software engineering tasks, such as bug localization.

图4是根据本发明一个实施例的程序执行序列的获取装置的结构示意图。如图4所示,程序执行序列的获取装置包括:插桩模块410、执行模块420和生成模块430。Fig. 4 is a schematic structural diagram of a device for acquiring a program execution sequence according to an embodiment of the present invention. As shown in FIG. 4 , the device for obtaining the program execution sequence includes: an instrumentation module 410 , an execution module 420 and a generation module 430 .

插桩模块410用于在编译阶段为被测程序选择插桩节点植入探针,在上述探针中写入保存函数、收集序列函数和还原函数;执行模块420用于当上述被测程序根据当前测试用例执行分支时,输出对应的基本块信息;生成模块430用于根据基本块信息得到基本块图级别的执行序列,根据上述执行序列与对应的上述基本块图生成包含行号信息的执行序列信息。The instrumentation module 410 is used to select the instrumentation node implantation probe for the program under test at the compilation stage, and writes the preservation function, collection sequence function and restoration function in the above-mentioned probe; the execution module 420 is used for when the above-mentioned program under test according to When the current test case executes a branch, output the corresponding basic block information; the generation module 430 is used to obtain the execution sequence of the basic block diagram level according to the basic block information, and generate the execution sequence containing the line number information according to the above execution sequence and the corresponding basic block diagram sequence information.

其中,保存函数用于在调用上述收集序列函数之前,将寄存器数据保存到内存中;上述还原函数用于在调用上述收集序列函数之后,将保存在内存中的寄存器数据进行还原。Wherein, the save function is used to save the register data in the memory before calling the above collection sequence function; the above restore function is used to restore the register data saved in the memory after calling the above collection sequence function.

在探针中写入保存函数的目的是保存收集序列函数的上下文场景;在探针中写入还原函数的目的是恢复收集序列函数上下文场景;在探针中写入收集序列函数的目的是记录程序执行序列。The purpose of writing the save function in the probe is to save the context scene of the collection sequence function; the purpose of writing the restore function in the probe is to restore the context scene of the collection sequence function; the purpose of writing the collection sequence function in the probe is to record sequence of program execution.

另外,该装置还可以包括:绘制模块400,该绘制模块400用于在插桩模块410为被测程序选择插桩节点植入探针之前,预处理被测程序的源文件,对上述源文件划分基本块和分支,并绘制基本块图。在绘制模块400绘制完基本块图之后,插桩模块410可以根据绘制的基本块图确定需要插桩的分支,然后根据需要插桩的分支确定上述插桩节点。In addition, the device may further include: a drawing module 400, which is used to preprocess the source file of the program under test before the instrumentation module 410 selects the instrumentation node for the program under test to implant the probe, and the above source file Divide basic blocks and branches, and draw basic block diagrams. After the basic block diagram is drawn by the drawing module 400, the posting module 410 may determine the branches that need to be inserted according to the drawn basic block diagram, and then determine the above-mentioned posting nodes according to the branches that need to be inserted.

进一步地,该装置还可以包括:定位模块440,如图5所示,该定位模块440用于在上述生成模块430生成包含行号信息的执行序列信息之后,获得多个执行序列信息,根据上述执行序列信息进行上述被测程序的错误定位。Further, the device may further include: a positioning module 440, as shown in FIG. 5, the positioning module 440 is used to obtain a plurality of execution sequence information after the above generation module 430 generates the execution sequence information including line number information, according to the above Execute the sequence information to locate the error of the above-mentioned program under test.

上述程序执行序列的获取装置,通过绘制模块400、插桩模块410、执行模块420和生成模块430之间的配合,可以获得被测程序的执行序列,具体实现过程可参见图1,此处不赘述;通过绘制模块400、插桩模块410、执行模块420、生成模块430和定位模块440之间的配合,可以根据获得的被测程序的执行序列对被测程序进行错误定位,具体实现过程可参见图2,此处不赘述。The above-mentioned device for obtaining the execution sequence of the program can obtain the execution sequence of the program under test through cooperation between the drawing module 400, the instrumentation module 410, the execution module 420, and the generation module 430. The specific implementation process can be seen in FIG. 1, which is not shown here. Repeat; through the cooperation between the drawing module 400, the instrumentation module 410, the execution module 420, the generation module 430 and the positioning module 440, the error location of the program under test can be performed according to the obtained execution sequence of the program under test. The specific implementation process can be Refer to FIG. 2 , which will not be repeated here.

上述程序执行序列的获取装置,通过插桩模块在探针中写入保存函数和还原函数,可以在不修改程序源代码的情况下,实现目标代码的插桩,通过执行测试用例后可以获得程序的多个执行序列,进而可以帮助测试人员实现软件工程任务,比如错误定位等。The acquisition device of the above-mentioned program execution sequence writes the save function and restore function in the probe through the instrumentation module, which can realize the instrumentation of the target code without modifying the source code of the program, and the program can be obtained after executing the test case Multiple execution sequences, which in turn can help testers to achieve software engineering tasks, such as error location.

应当理解,本发明的各部分可以用硬件、软件、固件或它们的组合来实现。在上述实施方式中,多个步骤或方法可以用存储在存储器中且由合适的指令执行系统执行的软件或固件来实现。例如,如果用硬件来实现,和在另一实施方式中一样,可用本领域公知的下列技术中的任一项或他们的组合来实现:具有用于对数据信号实现逻辑功能的逻辑门电路的离散逻辑电路,具有合适的组合逻辑门电路的专用集成电路,可编程门阵列(PGA),现场可编程门阵列(FPGA)等。It should be understood that various parts of the present invention can be realized by hardware, software, firmware or their combination. In the embodiments described above, various steps or methods may be implemented by software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented by any one or combination of the following techniques known in the art: Discrete logic circuits, ASICs with suitable combinational logic gates, Programmable Gate Arrays (PGAs), Field Programmable Gate Arrays (FPGAs), etc.

在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不一定指的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任何的一个或多个实施例或示例中以合适的方式结合。In the description of this specification, descriptions referring to the terms "one embodiment", "some embodiments", "example", "specific examples", or "some examples" mean that specific features described in connection with the embodiment or example , structure, material or characteristic is included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.

尽管已经示出和描述了本发明的实施例,本领域的普通技术人员可以理解:在不脱离本发明的原理和宗旨的情况下可以对这些实施例进行多种变化、修改、替换和变型,本发明的范围由权利要求及其等同物限定。Although the embodiments of the present invention have been shown and described, those skilled in the art can understand that various changes, modifications, substitutions and modifications can be made to these embodiments without departing from the principle and spirit of the present invention. The scope of the invention is defined by the claims and their equivalents.

Claims (10)

1. program is carried out an acquisition methods for sequence, it is characterized in that, comprising:
In the compilation phase, be that tested program is selected pitching pile node implantable probe, in described probe, write and preserve function, collect ordinal function and go back original function;
When described tested program is carried out branch according to current test case, export corresponding fundamental block information; And
According to described fundamental block information, obtain the execution sequence of fundamental block figure rank, according to described execution sequence, generate with corresponding fundamental block figure the execution sequence information that comprises line number information.
2. the method for claim 1, is characterized in that, described preservation function, for before calling described collection ordinal function, is saved in register data in internal memory; The described original function of going back, for after calling described collection ordinal function, reduces the register data being kept in internal memory.
3. the method for claim 1, is characterized in that, described, before the compilation phase is tested program selection pitching pile node implantable probe, described method also comprises:
The source file of tested program described in pre-service, divides fundamental block and branch to described source file, and draws fundamental block figure.
4. method as claimed in claim 3, is characterized in that, describedly for tested program, selects pitching pile node implantable probe and comprises:
According to described fundamental block figure, determine the branch that needs pitching pile, according to the described branch that needs pitching pile, determine described pitching pile node.
5. the method as described in claim as arbitrary in claim 1-4, is characterized in that, described according to described execution sequence, generate with corresponding fundamental block figure the execution sequence information that comprises line number information after, described method also comprises:
Obtain multiple execution sequence informations, according to described execution sequence information, carry out the location of mistake of described tested program.
6. program is carried out an acquisition device for sequence, it is characterized in that, comprising:
Pitching pile module for being that tested program is selected pitching pile node implantable probe in the compilation phase, writes and preserves function, collects ordinal function and go back original function in described probe;
Execution module, for when described tested program is carried out branch according to current test case, exports corresponding fundamental block information; And
Generation module, for obtain the execution sequence of fundamental block figure rank according to described fundamental block information, generates with corresponding fundamental block figure the execution sequence information that comprises line number information according to described execution sequence.
7. device as claimed in claim 6, is characterized in that, described preservation function, for before calling described collection ordinal function, is saved in register data in internal memory; The described original function of going back, for after calling described collection ordinal function, reduces the register data being kept in internal memory.
8. device as claimed in claim 6, is characterized in that, described device also comprises:
Drafting module, for being before tested program is selected pitching pile node implantable probe in described pitching pile module, the source file of tested program, divides fundamental block and branch to described source file, and draws fundamental block figure described in pre-service.
9. device as claimed in claim 8, is characterized in that, described pitching pile module, specifically for:
The fundamental block figure drawing according to described drafting module determines the branch that needs pitching pile, according to the described branch that needs pitching pile, determines described pitching pile node.
10. the device as described in claim as arbitrary in claim 6-9, is characterized in that, described device also comprises:
Locating module, for after described generation module generates the execution sequence information that comprises line number information, obtains multiple execution sequence informations, according to described execution sequence information, carries out the location of mistake of described tested program.
CN201410001275.7A 2014-01-02 2014-01-02 Method and device for acquiring program execution sequence Pending CN103744782A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410001275.7A CN103744782A (en) 2014-01-02 2014-01-02 Method and device for acquiring program execution sequence

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410001275.7A CN103744782A (en) 2014-01-02 2014-01-02 Method and device for acquiring program execution sequence

Publications (1)

Publication Number Publication Date
CN103744782A true CN103744782A (en) 2014-04-23

Family

ID=50501801

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410001275.7A Pending CN103744782A (en) 2014-01-02 2014-01-02 Method and device for acquiring program execution sequence

Country Status (1)

Country Link
CN (1) CN103744782A (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970659A (en) * 2014-05-16 2014-08-06 刘玉光 Android application software automation testing method based on pile pitching technology
CN104536882A (en) * 2014-11-28 2015-04-22 南京大学 Error locating method based on frequent sub-graph mining
CN106383781A (en) * 2016-09-05 2017-02-08 中国银行股份有限公司 Code analysis realization method and device
CN108205495A (en) * 2016-12-19 2018-06-26 联发科技股份有限公司 Code coverage rate processing method
CN110109816A (en) * 2018-02-01 2019-08-09 华为技术有限公司 Test cases selection method and apparatus
CN110135165A (en) * 2019-04-12 2019-08-16 江苏大学 A Dynamic Hierarchical and Multi-granularity Fuzzing Vulnerability Mining Method
CN111104267A (en) * 2018-10-26 2020-05-05 长鑫存储技术有限公司 Debugging processing method and debugging processing system of memory
CN115221051A (en) * 2022-07-12 2022-10-21 北京大学 Program instrumentation method and device for verifying data API execution process

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020099872A1 (en) * 2001-01-19 2002-07-25 Vinodha Ramasamy Allocating registers for use in programming code modification
CN101067798A (en) * 2007-06-14 2007-11-07 华南理工大学 A Dynamic Probe Method and Its Application in Embedded System
CN102521123A (en) * 2011-11-24 2012-06-27 西安邮电学院 Embedded software testing pile inserting method based on logic execution block

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020099872A1 (en) * 2001-01-19 2002-07-25 Vinodha Ramasamy Allocating registers for use in programming code modification
CN101067798A (en) * 2007-06-14 2007-11-07 华南理工大学 A Dynamic Probe Method and Its Application in Embedded System
CN102521123A (en) * 2011-11-24 2012-06-27 西安邮电学院 Embedded software testing pile inserting method based on logic execution block

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
沈毅: "基于软件行为分析的测试服务系统的设计与实现", 《中国优秀硕士学位论文全文数据库信息科技辑》, no. 8, 15 August 2013 (2013-08-15) *

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970659A (en) * 2014-05-16 2014-08-06 刘玉光 Android application software automation testing method based on pile pitching technology
CN103970659B (en) * 2014-05-16 2017-01-18 刘玉光 Android application software automation testing method based on pile pitching technology
CN104536882A (en) * 2014-11-28 2015-04-22 南京大学 Error locating method based on frequent sub-graph mining
CN106383781A (en) * 2016-09-05 2017-02-08 中国银行股份有限公司 Code analysis realization method and device
CN108205495A (en) * 2016-12-19 2018-06-26 联发科技股份有限公司 Code coverage rate processing method
CN110109816A (en) * 2018-02-01 2019-08-09 华为技术有限公司 Test cases selection method and apparatus
CN111104267A (en) * 2018-10-26 2020-05-05 长鑫存储技术有限公司 Debugging processing method and debugging processing system of memory
CN111104267B (en) * 2018-10-26 2022-05-13 长鑫存储技术有限公司 Debugging processing method and debugging processing system of memory
CN110135165A (en) * 2019-04-12 2019-08-16 江苏大学 A Dynamic Hierarchical and Multi-granularity Fuzzing Vulnerability Mining Method
CN110135165B (en) * 2019-04-12 2023-06-09 江苏大学 A Dynamic Hierarchical and Multi-granularity Fuzzing Vulnerability Mining Method
CN115221051A (en) * 2022-07-12 2022-10-21 北京大学 Program instrumentation method and device for verifying data API execution process

Similar Documents

Publication Publication Date Title
CN103744782A (en) Method and device for acquiring program execution sequence
US10296447B2 (en) Automated software program repair
US10152406B2 (en) Software program repair
US8756460B2 (en) Test selection based on an N-wise combinations coverage
CN103294594B (en) A kind of wrong report of the static analysis based on test removing method
US8291399B2 (en) Off-line program analysis and run-time instrumentation
US20090249309A1 (en) Efficient Program Instrumentation
US20090249305A1 (en) Super Nested Block Method to Minimize Coverage Testing Overhead
CN103218297B (en) The screening technique and device of test data
US8752007B2 (en) Automatic generation of run-time instrumenter
US20100162217A1 (en) Debugging System Using Static Analysis
US10936474B2 (en) Software test program generation
US10592703B1 (en) Method and system for processing verification tests for testing a design under test
US20200065226A1 (en) Automated software program repair of similar code snippets
CN105468797A (en) Information processing method and apparatus
CN110109816A (en) Test cases selection method and apparatus
JP2019096292A (en) Automated selection of software program repair candidate
US10761962B1 (en) Automated software program repair
CN109979520A (en) Chip functions automated testing method, device and computer equipment
CN110419031B (en) Code coverage tracking for microcontroller programs
CN103136103A (en) Test case reduction method for error locating demand
US9529963B1 (en) Method and system for partitioning a verification testbench
US10642716B1 (en) Automated software program repair
CN102521135B (en) The method of testing of linear system and device
CN104536880B (en) Gui program test case amplification method based on semiology analysis

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20140423