(1) Field of the Invention
The present invention relates to a program generation apparatus for generating programs automatically, and particularly to a program generation apparatus for generating source programs, as test programs, for verifying operation of a language processor such as a compiler.
(2) Description of the Related Art
A conventional program generation apparatus is disclosed in Japanese Laid-Open Patent Application No. 05-342054 Publication, for example. This is a program generation apparatus for generating test programs for verifying operation of a language processor such as a compiler. To be more specific, this program generation apparatus previously holds a plurality of templates of structure data indicating control structures in programs, and generates test programs according to scripts that respectively specify one or more of the templates.
As described above, the automatic program generation apparatus as disclosed in the conventional art generates test programs having control structures that correspond to structure data defined by scripts. Since all that a programmer has to do is write simple scripts that define structure data, man-hours for writing the details of the test programs are reduced.
However, this conventional automatic program generation apparatus has a problem of requiring an enormous number of man-hours for script writing in order to generate a lot of test programs having a variety of program structures. That is why only one test program is generated from a single script, and in order to generate a plurality of test programs having a variety of program structures, a programmer has to create the same number of scripts corresponding to the test programs. In addition, a lot of structure data must be previously prepared.
For example, in the case where, in order to verify operation of a compiler, a random test is carried out using a plurality of test programs having a variety of program structures, or a test program consisting of complex combinations of specific control structures such as loop structures and if structures, an enormous number of man-hours is needed to tailor the scripts for specific test programs. Therefore, the above-mentioned conventional art is not practical for generation of a variety of test programs.
An object of the present invention is to provide a program generation apparatus that realizes generation of a plurality of test programs having a variety of program structures with a smaller number of man-hours.
Another object of the present invention is to provide a program generation apparatus that allows programmers to easily check the execution results of test programs.
In order to achieve the above objects, the program generation apparatus according to the present invention includes: an accepting unit operable to accept a first script that defines a plurality of program structures for programs to be generated; and a script generating unit operable to generate a plurality of second scripts, each of which describes one of the plurality of program structures defined by the first script, said one of the plurality of program structures being different from each other.
According to this configuration, the program generation apparatus generates a plurality of second scripts from a single first script. Therefore, all that a programmer has to do is create only one first script, and thus a plurality of programs having a variety of program structures can be realized with a small number of man-hours.
Here, the program generation apparatus may be configured so that the first script defines the plurality of program structures by indicating a plurality of arrangements of control structures in the programs to be generated, each of the second scripts describes a program structure that indicates a unique arrangement of one or more of the control structures, and the script generating unit generates the plurality of second scripts by arranging the control structures based on the plurality of arrangements indicated in the first scrip.
According to this configuration, the first script indicates a plurality of various arrangements of control structures. Therefore, a programmer can create the first script easily.
Here, the control structure may be at least one of a loop structure, an if-then branch structure and an if-then-else branch structure.
Also, the first script may include an indication of paralleling and nesting of the control structures.
In addition, the program generation apparatus may be configured so that the first script includes an indication of the number of programs to be generated, and the script generating unit generates the plurality of second scripts, the number of said generated second scripts being indicated in the first script, and said second scripts describing the program structures selected, on a random basis, from among the plurality of program structures defined by the first script.
According to this configuration, the program generation apparatus generates the specified number of programs. Therefore, a programmer can cause the program generation apparatus to generate his/her desired number of programs.
Here, the program generation apparatus may further include a program generating unit operable to generate programs that respectively correspond to the plurality of second scripts generated by the script generating unit.
According to this configuration, the accepting unit, the script generating unit and the program generating unit work with each other in a chain. Therefore, upon accepting a single first script, a plurality of second scripts and a plurality of test programs can be generated one after another.
Here, the program generation apparatus may be configured so that the first script further includes a parameter indicating that a specific program statement should be set at a plurality of points in each of the programs, the script generating unit puts a mark that represents the parameter at a plurality of points in each of the second scripts, and the program generating unit sets the specific program statement at the points in each of the programs that correspond to the points of marks put in each of the second scripts.
Also, the program generation apparatus may be configured so that the specific program statement is one of the following: an output statement indicating that one of a character string and a variable should be outputted; and a pair of assignment statements that have data dependency.
According to this configuration, the program generation apparatus inserts a specific program statement into a program to be generated. Therefore, by executing the specific program statement (data dependency or output statement) during execution of the compiled program, a programmer can verify the operation of the compiler more easily and securely.
In addition, the method, program and script for program generation of the present invention have the same structures, functions and effects as those of the program generation apparatus described above.
As further information about technical background to this application, the disclosure of Chinese Patent Application No. 03147238.9 filed on Jul. 9, 2003 including specification, drawings and claims is incorporated herein by reference in its entirety.
These and other objects, advantages and features of the invention will become apparent from the following description thereof taken in conjunction with the accompanying drawings that illustrate a specific embodiment of the invention. In the Drawings:
A program generation apparatus in the embodiment of the present invention will be explained below.
(External View)
(Configuration Overview)
The translation unit 2 generates a plurality of files written in a middle level scripting language from a single file written in a high level scripting language.
The generation unit 3 generates one test program from each of the plurality of files written in a middle level scripting language.
According to this configuration, all that a programmer has to do is create a single file written in a high level scripting language, and thus the test program generation apparatus 1 can generate a plurality of test programs having a variety of program structures from that single file.
A high level scripting language and a middle level scripting language will be hereinafter referred to as HLSL and MLSL respectively. Similarly, a file written in HLSL and a file written in MLSL will be referred to as an HLSL script and an MLSL script respectively.
In addition,
Here, an HLSL script is a file that defines a variety of arrangements (or combinations) of control structures in a program, and represents, in a comprehensive manner, a variety of program structures defined by the variety of arrangements (or combinations) of control structures. In other words, an HLSL script defines control structures to be arranged and indicates a variety of arrangements of the defined control structures at a plurality of locations in a program. On the other hand, an MLSL script is a file that represents one program structure, like a script 2a or 3a as shown in
The test program generation apparatus 1 can generate a plurality of MLSL scripts and a plurality of test programs from a single HLSL Script.
(Example of Program Generation)
The HLSL script h1 in this diagram indicates an example where parameters and the like define a control structure type as LOOP and how to arrange the loop structures. The HLSL script h1 defines, in this case, that the nesting depth of the loop structures is 1 to 2 and the number of parallel loop structures is 1 to 2.
Each of the MLSL scripts m1 to mn is a file that describes one arrangement among a variety of arrangements defined by the HLSL script h1. For example, it corresponds to the script 2a or 3a as mentioned in the conventional art using
The test programs t1 to tn are test programs that correspond to the MLSL scripts m1 to mn one to one. In
As described above, the test program generation apparatus 1 generates “n” MLSL scripts from a single HLSL script, and further generates “n” test programs from the “n” MLSL scripts.
Each of the generated test programs is converted into a machine language program through compilation by a compiler 10 as shown in
(HLSL Syntax)
The parameter 1 specifies a control structure which should be set in the program structure. Here, a control structure generally means an element for controlling an execution flow of a program. There are various control structures such as a sequential structure, an iteration structure and a selection structure (or a branch structure). An execution flow of a program (that is, a program structure) is determined by an arrangement (a combination) of these control structures. As shown in
To be more specific, the parameter 2 includes “pattern”, “nest”, “parallel”, “number” “depend”, “compare” and the like.
“pattern” specifies an “if-then” structure or an “if-then-else” structure, in the case where the control structure specified by the parameter 1 is the “if” structure. If the parameter 3 that follows the parameter 2 is “then”, it indicates the “if-then” pattern, whereas the parameter 3 is “then-else”, it indicates the “if-then-else” pattern. In the case where the parameter 1 specifies the “if” structure and “pattern” is omitted, it indicates the “if-then” pattern.
“nest” specifies an arrangement of the control structures specified by the parameter 1 to be nested. The nesting depth is specified by the parameter 3 that follows the “nest”.
“parallel” specifies a parallel arrangement of the control structures specified by the parameter 1. The number of parallel structures is specified by the parameter 3 that follows the “parallel”.
“number” specifies the number of MLSL scripts (that is equal to the number of test programs) which should be generated. That number is specified by the parameter 3 that follows the “number”. If the parameter 3 indicates a character string “all”, not a numeric value, it means that all of the MLSL scripts that can be generated should be generated.
“depend” specifies, in a program, setting of a dependency between program statements. The number of points at which the dependency should be set is specified by the parameter 3 that follows “depend”.
“compare” specifies setting of an output statement for outputting a predetermined character string or the like. When the test program which has been finally generated by the present test program generation apparatus 1 is compiled by the compiler 10 and further executed by the target computer 11, a programmer can compare the output by the output statement with the point marked in the MLSL script so as to verify the operation.
The parameter 3 specifies a pattern of an “if” structure in the case where the parameter 2 is “pattern”, or a numerical range of the parameter 2. As shown in
“L-M” (where L and M are integers) specifies a combination (or an arrangement) of control structures within a range of values L to M, in the case where “L-M” follows the parameter 1 “nest” or “parallel”. In the case where “L-M” follows “depend” or “compare”, it specifies setting of data dependencies or output statements within a range of values L to M.
“N” (where N is an integer) specifies placement of control structures at locations of up to the value N inclusive, in the case where it follows the parameter 1 “nest” or “parallel”. In the case where it follows “depend” or “compare”, it specifies setting of dependencies or output statements at N points. Note that, in this case, it may specify setting of dependencies or output statements in every N blocks or every (N+1) blocks.
“All” can be specified as a parameter 3 that follows the parameter 2 “number”, and means that all the MLSL scripts that can be generated should be generated.
For example, “nest: 1-2” means the nesting depth of the specified control structures is in a range of 1 (no nest) to 2 (one nest). “parallel: 1-2” means the number of the specified parallel control structures is in a range of 1 (no parallel) to 2. In the case where the parameter 3 is omitted, it is considered to be a default value which is previously set by a user. This default value is set for each type of the parameter 2.
As for the parameters 2 and 3, a plurality of them can be written in the brackets { } following the parameter 1, and each of them specifies one of the following: (1) a pattern of an “if” structure; (2) a combination or an arrangement of control structures specified by the parameter 1 in a program (“nest” or “parallel”); (3) the number of test programs to be generated (“number”); and (4) the number of information to be added to a test program (“depend” or “compare”). The above-mentioned (1) and (2) allow specification of a variety of arrangements of control structures in a single HLSL script, namely, specification of a plurality of program structures which are to be arranged in different ways. The above-mentioned (3) allows specification of the number of test programs to be generated, as a programmer desires. The above-mentioned (4) allows a programmer to verify the data dependency and the execution flow easily in the case where he/she causes a compiler to compile a test program into a machine language program and a target computer to execute the machine language program.
(MLSL Syntax)
An MLSL script is, for example, the script 2b in
As shown in these examples, an MLSL script is written as a combination of a plurality of parameters indicating control structures, and indicates an arrangement of the control structures uniquely. The parameters in the MLSL script are LOOP, if (if-then or if-then-else) and the like.
(Detailed Configuration of Translation Unit 2)
The parameter reading unit 21 reads the parameters 1 to 3 written in an HLSL script and outputs them to the control structure generation unit 22. However, it outputs, to the additional information generation unit 23, only the specification of information to be added to a test program (“depend” or “compare”) in the parameter 1.
As for the parameters 1 to 3 read by the parameter reading unit 21, the control structure generation unit 22 performs the processing for generating a plurality of MLSL scripts by arranging the control structures specified by the parameters 1 in accordance with the arrangements specified by the parameters 2. See, for example, the MLSL scripts m1, m2 and mn, as shown in
The additional information generation unit 23 puts marks at the points at which the additional information should be set, in each of the plurality of MLSL scripts generated by the control structure generation unit 22, in accordance with the information to be added to the test programs which is specified in the parameters read by the parameter reading unit 21. There are two types of marks: a mark corresponding to “depend”; and a mark corresponding to “compare”. The plurality of MLSL scripts on which these marks are put are converted into a plurality of test programs respectively by the generation unit 3. At that time, the generation unit 3 sets program statements having data dependencies at the respective points in the test program that correspond to the “depend”-marked points in the MLSL script. The generation unit 3 also sets output statements at the respective points in the test program that correspond to the “compare”-marked points in the MLSL script.
A programmer can verify the execution flow using these program statements or the output statements.
(Parameter Reading Processing)
In
(Control Structure Generation Processing)
The control structure generation unit 22 judges whether the parameter 1 outputted from the parameter reading unit 21 is “if” or “LOOP” (S205), and performs the loop control structure generation processing when the parameter 1 is “LOOP” as a result of the judgment. In this loop control structure generation processing, the control structure generation unit 22 generates a variety of arrangements of the loop control structures within a range of values specified by the parameter, and generates a plurality of MLSL scripts having the program structures that correspond to the respective arrangements (S209).
When the parameter 1 is “if” as a result of the judgment and “pattern” and “then” are specified by the parameter 2 and the parameter 3 respectively (or “pattern” is omitted, or “then” or “then-else” is omitted although “pattern” is specified), the control structure generation unit 22 performs the if control structure generation processing. In this if control structure generation processing, the control structure generation unit 22 generates a variety of arrangements of the if-then control structures within a range of values specified by the parameter, and generates a plurality of MLSL scripts having the program structures that correspond to the respective arrangements (S207).
When the parameter 1 is “if” as a result of the judgment and “pattern” and “then-else” are specified by the parameter 2 and the parameter 3 respectively, the control structure generation unit 22 performs the if-then-else control structure generation processing. In this if-then-else control structure generation processing, the control structure generation unit 22 generates a variety of arrangements of the if-then-else control structures within a range of values specified by the parameter, and generates a plurality of MLSL scripts having the program structures that correspond to the respective arrangements (S208).
(Details of If-then Control Structure Generation Processing)
First, the control structure generation unit 22 generates a complete tree, in accordance with the value of the parameter 3 for “parallel” (the maximum value thereof will be hereinafter referred to as “the number of parallel control structures”) and the value of the parameter 3 for “nest” (the maximum value thereof will be hereinafter referred to as “the nesting depth”) which are outputted from the parameter reading unit 21 (S210). To be more specific, the control structure generation unit 22 determines the height of the tree (the node depth) to be the value of the nesting depth plus one (S210a), determines the number of child nodes (the number of branches) of each node to be the value of the number of parallel control structures (S210b), and then generates the data representing the complete tree in accordance with the determined height and number of branches (S210c).
Next, the control structure generation unit 22 generates a plurality of subtrees from the complete tree (Loop 1 in S212 to S217). The number of generated subtrees is the number specified by “number”. Each subtree represents a program structure in which one or more of the control structures defined in the HLSL script are arranged within the number of control structures included in the complete tree. Note that the subtrees which are generated here include the complete tree itself.
To be more specific, the control structure generation unit 22 generates one subtree S from the complete tree on a random basis (S212), and returns to the generation of a subtree unless the height of the subtree S is the nesting depth plus 1 (S213), and returns to the generation of a subtree unless the maximum number of child nodes is the number of parallel control structures (S214). The control structure generation unit 22 returns to the generation of a subtree because the generated subtree S does not have the control structures (nodes) of the number specified by the parameters (“nest” and “parallel”).
Furthermore, the control structure generation unit 22 judges whether the MLSL script corresponding to the generated subtree has already been generated or not (S215), and generates the MLSL script corresponding to the subtree if the script has not yet been generated (S216).
As a result of the above processing, one subtree is generated. The control structure generation unit 22 repeats the above processing (Loop 1) until the subtrees of the number specified by the parameter “number” are generated.
(Details of If-then-else Control Structure Generation Processing)
The flow of
In Step S210a, the control structure generation unit 22 generates a complete tree having nodes corresponding to “if” statements of if-then-else pattern. For that purpose, after determining the height of the tree and the number of child nodes, the control structure generation unit 22 generates the root node and its branches (5210d), and further generates twin nodes and their branches in accordance with the determined height and number of child nodes, considering that all the child nodes under the root node are twin nodes (S210e).
Step S216a is different from Step S216 in that the control structure generation unit 22 generates MLSL scripts in which the control structures of if-then-else pattern, not if-then pattern, are arranged.
The control structure generation unit 22 generates the MLSL scripts that correspond to the subtrees as shown in
(Details of Loop Control Structure Generation Processing)
In Step S216b, the control structure generation unit 22 generates loop control structures, instead of if-then control structures in Step S216. To be more specific, the control structure generation unit 22 generates a plurality of MLSL scripts representing “LOOP{ }”, instead of “if( ){ }” in the MLSL scripts in
Note that the control structure generation processing for the control structures of if-then pattern, if-then-else pattern and loop pattern has been described separately, but these patterns may be mixed. For example, in the case where a mixture of if-then control structures and if-then-else control structures are defined, the control structure generation unit 22 once generates a complete tree by considering the if-then structures as the if-then-else structures and then adds the processing of replacing some of the twin nodes with ordinary nodes within a range of values specified by the parameters “parallel” and “nest”. The same processing can also be performed in the case where loop control structures and if-then-else control structures or if-then control structures are mixed.
(Additional Information Generation Processing)
In the case where the parameters outputted from the parameter reading unit 21 include “compare” and the following parameter 3 (S220), the additional information generation unit 23 puts the marks of the number specified by the parameter 3 (hereinafter referred to compare marks) in each of a plurality of MLSL scripts generated by the control structure generation unit 22 (S221). Here, a compare mark is a mark that specifies the point at which an output statement for indicating the program execution point and status should be set. To be more specific, the compare marks are put in every specified number of blocks. Here, a block (also called a basic block) denotes a sequence of instructions, as a unit in a program, which is always executed in succession without being branched in the middle of the sequence. In other words, in a single block, no branch occurs from any instructions except for the last one in the program. In an MLSL script, a block corresponds to each region of a program separated by an “if” or “loop” control structure. The blocks in which the compare marks are put are selected from all the blocks at random.
In addition, in the case where the parameters outputted from the parameter reading unit 21 include “depend” and the following parameter 3 (S222), the additional information generation unit 23 puts the marks of the number specified by the parameter 3 (hereinafter referred to as depend marks) to each of a plurality of MLSL scripts generated by the control structure generation unit 22 (S223). Here, one depend mark is a pair of marks that specifies the points at which two program statements which have data dependency should be set.
(Detailed Structure of Generation Unit)
The generation unit 3 generates a source program having control structures that correspond to “LOOP”s and “if”s written as control structures in an MLSL script. For example, it generates a “for” statement for iteration processing in accordance with “LOOP” in an MLSL script, generates an “if” statement in accordance with “if” in an MLSL script, and generates an “if( ){ }else{ }” statement in accordance with an if-then-else in an MLSL script, respectively. This kind of generation of a test program from an MLSL script may be done using the same technique as the conventional art for converting the script in
The data dependency setting unit 31 puts program statements having data dependency at the depend-marked point, for generating a test program.
The comparison point setting unit 32 puts an output statement at the compare-marked point, for generating a test program.
(Data Dependency Setting Processing Flow)
As shown in
The data dependency setting unit 31 judges whether or not a data dependency mark (one of a pair of depend marks) is set in a current block in an MLSL script (S311). When judging that the mark is not set, the data dependency setting unit 31 generates, at random, an assignment statement as a program statement for describing the current block in the test program (S312). When judging that the mark is set, the data dependency setting unit 31 searches the MLSL script for a block in which the other of the pair of depend marks is put, and generates two assignment statements having data dependency for the pair of blocks in the test program (S313). In the case where the assignment statement having data dependency has already been set, the processing in Step S313 may be omitted.
The test program p10 as shown in
Note that the data dependency setting unit 31 may assign a pair of marks to a basic block corresponding to “then” and a basic block corresponding to “else”, like a pair of A marks. Furthermore, the data dependency setting unit 31 may assign a pair of marks to the following: (a) adjacent two basic blocks; (b) a basic block corresponding to “if” and a basic block corresponding to “then”; and (c) a basic block corresponding to “if” and a basic block corresponding to “else”.
(Comparison Point Setting Processing Flow)
As shown in
The test program p11 in
The present invention is not limited to the above-mentioned embodiment, and various changes or modifications are possible without departing from the scope of the present invention.
In the above embodiment, generation of a C language source program as a test program has been explained as an example, but a test program written in any of other high level languages than C language may be generated. In that case, LOOP and if as the parameters 1 have to be corresponded to the control structures which can be written in that high-level language (such as if structures, for structures, and while structures).
In addition, the above embodiment has been explained, as an example, on the assumption that one control structure is specified by one parameter 1 in one HLSL script, but a plurality of parameters 1 may be specified in a single HLSL script, or various control structures may be specified by a plurality of parameters 1. For example, a parameter 1 specifying an if-then structure and a parameter 1 specifying an if-then-else structure may be mixed, or a parameter 1 specifying a loop structure and a parameter 1 specifying an if-then-else structure may be mixed.
Furthermore, in the above embodiment, a test program for a compiler is generated. However, a test program for an interpreter or an assembler, instead of a compiler, may be generated, or a test program may be targeted for a virtual machine for interpreting and executing a script language such as JAVA® and VisualBasic®.
In the above embodiment, LOOP and if have been explained as parameters 1 specifying control structures, but the parameters specifying other control structures may be included. For example, parameters indicating sequence structures, recursive structures, n-branch structures indicating a 1-to-n branch and the like may be included.
Note that in the above embodiment, the program generated by the test program generation apparatus 1 is a test program used for verifying operation of a compiler under development. However, it goes without saying that the program can be used for verifying operation of the target machine 11 under development.
Although the present invention has been fully described by way of examples with reference to the accompanying drawings, it is to be noted that various changes and modifications will be apparent to those skilled in the art. Therefore, unless otherwise such changes and modifications depart from the scope of the present invention, they should be construed as being included therein.
Number | Date | Country | Kind |
---|---|---|---|
03147238.9 | Jul 2003 | CN | national |