This application is based upon and claims the benefit of priority of the prior Japanese Patent Application No. 2013-022950, filed on Feb. 8, 2013, the entire contents of which are incorporated herein by reference.
Embodiment discussed herein is related to a technique for generating test data.
A test case set including test input, expected results, and the like is prepared so that all the points to be checked are covered in a comprehensive manner when a program test is executed. In an operation for preparing test cases, test input generation is often manually performed.
Related technologies are disclosed in Japanese Laid-open Patent Publication Nos. 2009-87355 and 2012-068869, TAMAI, Tetsuo, FUKUNAGA, Koichi, “Symbolic Execution System (Kigou Jikkou Sisutemu)”, Information Processing, Information Processing Society of Japan, Vol. 23 No. 1, p. 18-28, January 1982, and MUNAKATA, Kazuki, et al., “Test Case Selection based on Path Conditions of Symbolic Execution”, 19th Asia-Pacific Software Engineering Conference, IEEE computer society, p. 318-321, 2012.
According to one aspect of the embodiments, a computer-readable recording medium storing therein a test data generating program to be executed by a computer, the program causing the computer to: generate, for each of a plurality of path conditions obtained by repeatedly performing symbolic execution, a simplified path condition by substituting a fixed value for a first symbolic variable included in the path condition; calculate, for each the simplified path condition, a value of the symbolic variable that satisfies the simplified path condition; generate test data including the values of the symbolic variable, the fixed values, and path conditions not subjected to simplification; and remove duplicative data from the test data that corresponds to a same path condition.
The object and advantages of the invention will be realized and attained by means of the elements and combinations particularly pointed out in the claims.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory and are not restrictive of the invention, as claimed.
In order to reduce labor, test input generation is performed by symbolic execution. In symbolic execution, a program is executed while holding specific values called symbolic values, without embodying variables in the program. A variable holding a symbolic value is referred to as a symbolic variable. In symbolic execution, in the case where a symbolic variable is used in a determination condition for branching or the like, paths in the case where the determination condition is satisfied and paths in the case where the determination condition is not satisfied are covered in a comprehensive manner. For execution of a path, for example, a condition to be satisfied by a symbolic variable is held in order that a determination condition is satisfied or in order that the determination condition is not satisfied. The condition is called a path condition and is held for each path performed in the symbolic execution. In the case where no value satisfying a specific path condition (hereinafter, referred to as a satisfying value) exists, a path for the path condition is not performed. Thus, the path is excluded from the target of a test. In the case where a satisfying value for the path condition exists, satisfying solution is set for test input.
In symbolic execution, for example, due to the occurrence of path explosion, the symbolic execution might not be able to be performed with practical time and calculation amount.
In order to suppress occurrence of path explosion, symbolic execution is repeatedly performed while switching a variable to be symbolized.
For example, symbolic execution is performed for a program having a control structure illustrated in
Referring to
Referring to
As illustrated in
The execution control part 106 extracts candidates for symbolic variables based on data stored in the driver storing unit 102, and stores the extracted candidates into the variable storing unit 103. The execution control part 106 outputs a program stored in the program storing unit 101 and information on a symbolic variable to the execution engine 113. The fixed data calculating part 105 generates data of a fixed symbolic variable and stores the generated data into the fixed data storing unit 107.
The substituting part 109 substitutes a fixed value stored in the fixed data storing unit 107 into a path condition received from the path condition calculating part 114. The simplifying part 110 generates a simplified path condition by simplifying the path condition received from the substituting part 109, and stores the generated simplified path condition into the simplified data storing unit 111.
In response to a request from the execution control part 106, the execution engine 113 performs symbolic execution. The execution engine 113 may be a module which performs symbolic execution, and may be, for example, a Java® PathFinder. The path condition calculating part 114 generates a path condition and outputs the generated path condition to the converting unit 108. The test input generating part 115 calculates a satisfying value which satisfies the simplified path condition stored in the simplified data storing unit 111, and outputs test input including the satisfying value and a fixed value to the test case generating part 116. The test case generating part 116 generates a test case including the test input and the path condition, and stores the generated test case into the first test case storing unit 117.
The removing unit 118 performs processing using the data stored in the first test case storing unit 117, and stores a result of the processing into the second test case storing unit 119.
Two types of symbolic variables including a free symbolic variable and a fixed symbolic variable may be introduced. Free symbolic variables may be normal symbolic variables. Fixed symbolic variables may be symbolic variables having a fixed value.
When a path condition is obtained by symbolic execution, a free symbolic variable and a fixed symbolic variable may be handled in a similar manner as normal symbolic variables. When test input is calculated using an obtained path condition, only a free symbolic variable is handled as in a similar manner as normal symbolic variables. A fixed value is substituted for a fixed symbolic variable, and a simplified path condition is generated. By obtaining a satisfying value of the simplified path condition, test input is generated.
Referring to
Referring to
At this point in time, the test case 2 and the test case 4 are redundant. However, the redundancy is removed by comparing path conditions before simplification. The path condition for the test case 1 is “x*(y+1)>10”. The path condition for the test case 2 is “x*(y+1)<10&&y<=5”. The path condition for the test case 3 is “x*(y+1)<=10&&y>5”. The path condition for the test case 4 is “x*(y+1)=<10&&y<=5”. Since the path condition for the test case 2 and the path condition for the test case 4 are the same, it may be determined that the test case 2 and the test case 4 are redundant. Thus, redundant test data may be removed by removing the test case 2 or the test case 4.
The execution control part 106 determines whether or not an unprocessed declaration statement exists (operation S23). In the case where no unprocessed declaration statement exists (operation S23: No route), the process returns to the process illustrated in
The execution control part 106 determines whether or not an initial value is declared (operation S27). In the case where an initial value is declared (operation S27: Yes route), the execution control part 106 sets the initial value for the fixed value of a symbolic variable in the declaration statement (operation S29). The initial value may be, for example, a value subsequent to “param1=” in
With the execution of the process described above, an appropriate value may be extracted as a fixed value of a fixed symbolic variable.
Referring back to
The execution control part 106 acquires, from the variable storing unit 103, data of candidates for a symbolic variable, such as variable names and variable types (
The execution control part 106 generates a combination of a free symbolic variable and a fixed symbolic variable (operation S43), and outputs, to the fixed data calculating part 105, the data acquired in operation S41 and the fixed values set in operations S29 and S31.
The fixed data calculating part 105 generates data of fixed symbolic variables including the data received from the execution control part 106 (operation S45), and stores the generated data into the fixed data storing unit 107. The process is terminated.
By performing symbolic execution for the generated combinations, symbolic execution may be performed repeatedly.
Referring back to
The execution control part 106 issues a request to the symbolic execution unit 112 to perform symbolic execution on the combination identified in operation S7. In response to this request, the execution engine 113 performs symbolic execution (operation S9).
The execution engine 113 performs initialization of symbolic execution (
The execution engine 113 determines whether or not the next instruction exists in the program (operation S53). In the case where the next instruction exists (operation S53: Yes route), the execution engine 113 analyzes the instruction (hereinafter, called an instruction to be processed) (operation S57). For example, analysis may be performed on the details of the instruction, a related variable, and the like.
The execution engine 113 determines whether or not the instruction to be processed is a branch instruction (operation S59). In the case where the instruction to be processed is a branch instruction (operation S59: Yes route), the execution engine 113 selects an unselected branch for the branch instruction (operation S61). The process proceeds to processing of operation S63.
In the case where the instruction to be processed is not a branch instruction (operation S59: No route), the execution engine 113 issues a request to the path condition calculating part 114 to perform processing. In response to the request, the path condition calculating part 114 calculates a path condition (operation S63). The path condition calculating part 114 outputs the calculated path condition to the converting unit 108.
In accordance with this, the converting unit 108 performs a simplifying process (operation S65).
The substituting part 109 generates a simplified path condition by generating copy of the path condition received from the path condition calculating part 114 (
The substituting part 109 extracts, from the fixed data storing unit 107, a fixed value corresponding to a symbolic variable included in the simplified path condition generated in operation S81, and substitutes the extracted fixed value for the symbolic variable (operation S83). The substituting part 109 outputs the processed simplified path condition to the simplifying part 110. By the processing of operation S83, for example, a simplified path condition “(“ZZ0100”.startsWith(“ZZ01”))^(“ZZ0100”.subString(4).equals(“00”))^((param1−100+100)>0)” may be generated.
Since data of fixed symbolic variables for individual combinations are stored in the fixed data storing unit 107, the substituting part 109 extracts a fixed value from data of the combination on which the processing is currently being performed.
The simplifying part 110 determines whether or not an unprocessed atomic formula, or atomic formula exists in the simplified path condition (operation S85). The atomic formula may be an element coupled using “and”. For example, in the case where a simplified path condition is “(“ZZ0100”.startsWith(“ZZ01”))^(“ZZ0100”.subString(4).equals(“00”))^((param1−100+100)>0)”, atomic formulae are ““ZZ0100”.startsWith(“ZZ01”)”, ““ZZ0100”.subString(4).equals(“00”)”, and “(param1−100+100)>0”.
In the case where no unprocessed atomic formula exists (operation S85: No route), since the simplifying processing is completed, the simplifying part 110 stores the path condition that has not been subjected to the simplifying processing and the simplified path condition in association with each other into the simplified data storing unit 111. The process returns to the process illustrated in
In the case where an unprocessed atomic formula exists (operation S85: Yes route), the simplifying part 110 identifies the formula (operation S87). The atomic formula identified in operation S87 may be referred to as an “atomic formula to be processed”.
The simplifying part 110 performs calculation of a subexpression included in the atomic formula to be processed (operation S89). A subexpression that is capable of being calculated may be a subexpression that is independent of a free symbolic value or a subexpression to which a specific simplifying rule is applied. For example, the result of the calculation of a subexpression “100−100” in an atomic formula “param1−100+100” is obtained as 0.
The simplifying part 110 determines whether or not the atomic formula to be processed differs between before and after the calculation (operation S91). In the case where a difference occurs in the atomic formula to be processed (operation S91: Yes route), the process returns to operation S89. In the case where no difference occurs in the atomic formula to be processed (operation S91: No route), the simplifying part 110 determines whether or not the atomic formula to be processed is “false”, for example, whether or not the atomic formula to be processed is an unsatisfied atomic formula (operation S93). In the case where the atomic formula to be processed is “false” (operation S93: Yes route), since the atomic formula to be processed is not satisfied, the simplifying part 110 sets “false” for the simplified path condition (operation S95). The simplifying part 110 stores the path condition that has not been subjected to simplification and the simplified path condition (false) in association with each other into the simplified data storing unit 111. The process returns to the process illustrated in
In the case where the atomic formula to be processed is not “false” (operation S93: No route), the simplifying part 110 determines whether or not the atomic formula to be processed is “true” for example, whether or not the atomic formula to be processed is a satisfied atomic formula (operation S97). In the case where the atomic formula to be processed is “true” (operation S97: Yes route), the simplifying part 110 removes the atomic formula to be processed from the simplified path condition (operation S99). In the case where the atomic formula to be processed is not “true” (operation S97: No route), the simplifying part 110 replaces the atomic formula identified in operation S87 with the calculated atomic formula (operation S101). After the processing of operations S99 and S101, the process returns to operation S85.
With the execution of the process described above, a simplified path condition including a free symbolic variable may be generated by simplifying a path condition including a free symbolic variable and a fixed symbolic variable.
For example, in a path condition 2001 illustrated in
A simplifying procedure after a fixed value is substituted will be described later.
(1) A conversion rule (1a) is applied to each atomic formula until there is no portion to which the conversion rule (1a) is to be applied.
(1a) The value of a subexpression that is free from symbolic variables is converted into a result obtained by calculation of the subexpression.
(2) If there is any atomic formula converted into false after (1) is performed, a simplified path condition is defined as false.
(3) For a simplified path condition that is not converted into false after (1) and (2) are performed, a condition obtained by removing an atomic formula converted into true is set as a simplified path condition.
Referring to
Referring to
Referring back to
In the case where it is determined in operation S53 that no next instruction exists (operation S53: No route), the execution engine 113 issues a request to the test input generating part 115 to perform a test case generating process. In response to the request, the test input generating part 115 and the test case generating part 116 perform the test case generating process (operation S71).
The test input generating part 115 generates test input relating to a free symbolic variable by calculating a satisfying value for the simplified path condition stored in the simplified data storing unit 111, and stores the generated test input into a storing device such as a main memory (
The test input generating part 115 generates test input including a fixed value of a fixed symbolic variable, and stores the generated test input into a storing device such as a main memory (operation S113). For example, in the case where fixed symbolic variables are SDriver.param2 and SDriver.param3, the test input generating part 115 reads from the fixed data storing unit 107 fixed values for the SDriver.param2 and the SDriver.param3. The test input generating part 115 generates, for example, test input “param1=100” and “param3=“ZZ0100””.
The test input generating part 115 outputs the test input generated in operation S111 and the test input generated in operation S113 to the test case generating part 116. Upon receiving the test inputs, the test case generating part 116 generates a test case including the test input received from the test input generating part 115 and a path condition that has not been subjected to simplification (operation S115), and stores the generated test case into the first test case storing unit 117. The path condition that has not been subjected to simplification may be a path condition that is associated with a simplified path condition in the simplified data storing unit 111. The process is terminated.
With the execution of the process described above, a path condition that has not been subjected to simplification is associated with test input including a satisfying value satisfying a simplified path condition and a fixed value.
Referring back to
The execution engine 113 determines whether or not an unselected branch exists for the last branch instruction, for example, whether or not an unexecuted path exists (operation S77). In the case where no unselected branch exists (operation S77: No route), the process returns to operation S73 in order to search for a different branch instruction. In the case where an unselected branch exists (operation S77: Yes route), the execution engine 113 selects an unselected branch (operation S79). The process proceeds to operation S63.
By the time of completing generation of a path generation, any variable is symbolized without distinction between a free symbolic variable and a fixed symbolic variable. Thus, a path condition related to all the symbolic variables may be generated.
For example, in the case where symbolic execution is repeatedly performed in a different method, a path condition that is only related to a symbolic variable for which a default value is not substituted may be generated, and different path conditions may be obtained for test cases passing through the same path. Thus, it might not be determined whether or not test cases are redundant. With the method mentioned above, for the same symbolic variable, path conditions generated for test cases passing through the same path may be substantially the same. Thus, when symbolic execution is repeatedly performed while switching between a free symbolic variable and a fixed symbolic variable, it may be determined, based on a path condition that has not been subjected to simplification, that test cases are redundant.
By using a simplified path condition which is a path condition that is only related to a free symbolic variable for determination of satisfiability and generation of test input, occurrence of path explosion may be reduced.
Referring back to
The removing unit 118 determines whether or not an unprocessed test case exists among test cases stored in the first test case storing unit 117 (
The removing unit 118 determines whether or not a test case including the same path condition as a path condition included in the test case identified in operation S123 is stored in the second test case storing unit 119 (operation S125). In the case where a test case including the same path condition is stored in the second test case storing unit 119 (operation S125: Yes route), since redundant test cases exist, the process returns to operation S121.
In the case where no test case including the same path condition is stored in the second test case storing unit 119 (operation S125: No route), the removing unit 118 adds the test case identified in operation S123 to the second test case storing unit 119 (operation S127). The process returns to the processing of operation S121.
With the execution of the process described above, a redundant test case stored in the first test case storing unit 117 may be removed.
In the processing flows, the order of processing operations may be changed or may be performed concurrently as long as the same processing result is obtained.
The number of free symbolic variables may be one, two, or more.
The second test case storing unit 119 might not be provided. For example, the removing unit 118 may remove one or more of test cases stored in the first test case storing unit 117.
In a test data generating method, (A) for each of a plurality of path conditions generated by repeatedly performing symbolic execution, a simplified path condition obtained by simplifying a path condition is generated by substituting a fixed value for one or more of symbolic variables included in the path condition; (B) for each of the generated plurality of simplified path conditions, the value of a symbolic variable that satisfies the simplified path condition is calculated, and test data including the calculated value, a fixed value, and a path condition that has not been subjected to simplification is generated and is stored into a data storing unit; and (C) part of test data stored in the data storing unit is removed so that redundancy of test data including the same path condition does not occur in the data storing unit.
For test data generated for the same path, even if the combination of the value of a symbolic variable that satisfies a simplified path condition and a fixed value differs between the test data, the path conditions that have not been subjected to simplification are substantially the same. Thus, redundant test data may be removed. Since processing for obtaining the value of a symbolic variable that satisfies a simplified path condition is performed, the amount of calculation may be reduced.
In the test data generating method, (D) a plurality of combinations of a first symbolic variable for which a fixed value is not substituted and a second symbolic variable for which a fixed value is substituted may be generated. For example, in the processing for generating a simplified path condition, (a1) for each of the plurality of combinations, symbolic execution may be performed. Symbolic execution may be repeatedly performed so that paths of a program are covered in a comprehensive manner.
In the processing for generating a simplified path condition, (a2) a fixed value may be substituted for the second symbolic variable included in a path condition, and it may be determined whether at least one of formulae included in the path condition is not satisfied; (a3) in the case where it is determined that at least one of the formulae included in the path condition is not satisfied, a simplified path condition in which no satisfying value exists may be generated; and (a4) in the case where it is determined that all the formulae included in the path condition are satisfied, a simplified path condition may be generated by substituting a fixed value for the second symbolic variable included in the path condition. Test data may be generated only for a reachable path.
The fixed value mentioned above may be a value complying with a symbolic variable declared in a program on which symbolic execution is to be performed. Symbolic execution may be performed without any problem.
A program for causing a computer to execute the processes described above may be generated. The program may be stored, for example, in a computer-readable storing medium, such as a flexible disk, a CD-ROM, a magneto-optical disk, a semiconductor memory, a hard disk, or the like, or a storing device. An intermediate processing result may be temporarily stored in a storing device, such as a main memory.
All examples and conditional language recited herein are intended for pedagogical purposes to aid the reader in understanding the invention and the concepts contributed by the inventor to furthering the art, and are to be construed as being without limitation to such specifically recited examples and conditions, nor does the organization of such examples in the specification relate to a showing of the superiority and inferiority of the invention. Although the embodiments of the present invention have been described in detail, it should be understood that the various changes, substitutions, and alterations could be made hereto without departing from the spirit and scope of the invention.
Number | Date | Country | Kind |
---|---|---|---|
2013-022950 | Feb 2013 | JP | national |
Number | Name | Date | Kind |
---|---|---|---|
6442732 | Abramovici | Aug 2002 | B1 |
8347271 | Nallasivam | Jan 2013 | B1 |
8533680 | Tillmann | Sep 2013 | B2 |
20030108107 | Kim | Jun 2003 | A1 |
20040019546 | Ta | Jan 2004 | A1 |
20070033440 | Tillmann | Feb 2007 | A1 |
20070033443 | Tillmann | Feb 2007 | A1 |
20070033576 | Tillmann | Feb 2007 | A1 |
20070157169 | Chen | Jul 2007 | A1 |
20080010620 | Moeller | Jan 2008 | A1 |
20090089759 | Rajan et al. | Apr 2009 | A1 |
20090089769 | GRcevski et al. | Apr 2009 | A1 |
20090265692 | Godefroid | Oct 2009 | A1 |
20090281999 | Sinha | Nov 2009 | A1 |
20110072417 | Dhurjati | Mar 2011 | A1 |
20110219359 | Gupta | Sep 2011 | A1 |
20110289488 | Ghosh | Nov 2011 | A1 |
20120304157 | Kawashima | Nov 2012 | A1 |
20130085720 | Xie | Apr 2013 | A1 |
20130283236 | Kuznetsov | Oct 2013 | A1 |
Number | Date | Country |
---|---|---|
2007-011477 | Jan 2007 | JP |
2009-087355 | Apr 2009 | JP |
2011-039718 | Feb 2011 | JP |
2012-068869 | Apr 2012 | JP |
Entry |
---|
Tetsuo Tamai et al., “Symbolic Execution Systems”, Jan. 1982, Information Processing Society of Japan, p. 18, right column, line 15 to p. 21, left column, line 32 with English translation. |
James C. King, “Symbolic Execution and Program Testing”, IBM Thomas J. Watson Research Center, Communication of the ACM, Jul. 1976, vol. 19, No. 7, pp. 385-394. |
Kazuki Munakata, et al., “Test Case Selection based on Path Conditions of Symbolic Execution”, 2012 19th Asia-Pacific Software Engineering Conference, 2012 IEEE Computer Society, pp. 318-321. |
Tetsuo Tami et al., “Symbolic Execution Systems”, Jan. 1982, Information Processing Society of Japan, with English translation, 18 pages. |
Number | Date | Country | |
---|---|---|---|
20140229918 A1 | Aug 2014 | US |