WO2013161057A1 - ソースコード検査方法及び装置 - Google Patents

ソースコード検査方法及び装置 Download PDF

Info

Publication number
WO2013161057A1
WO2013161057A1 PCT/JP2012/061372 JP2012061372W WO2013161057A1 WO 2013161057 A1 WO2013161057 A1 WO 2013161057A1 JP 2012061372 W JP2012061372 W JP 2012061372W WO 2013161057 A1 WO2013161057 A1 WO 2013161057A1
Authority
WO
WIPO (PCT)
Prior art keywords
source code
conversion
conversion rule
model
inspection
Prior art date
Application number
PCT/JP2012/061372
Other languages
English (en)
French (fr)
Inventor
秀人 野口
誠 市井
Original Assignee
株式会社日立製作所
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 株式会社日立製作所 filed Critical 株式会社日立製作所
Priority to PCT/JP2012/061372 priority Critical patent/WO2013161057A1/ja
Publication of WO2013161057A1 publication Critical patent/WO2013161057A1/ja

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3624Software debugging by performing operations on the source code, e.g. via a compiler

Definitions

  • the present invention relates to a source code inspection method and apparatus, and in particular, when verifying software, in order to suppress an increase in the amount of calculation involved in inspection, a computer is used to abstract source code,
  • the present invention relates to an inspection method and apparatus for executing symbol execution and model inspection according to the present invention.
  • Model checking technology is, for example, the method disclosed in Non-Patent Document 1, which describes the behavior of software in the input language of a specific model checker and executes the specific model checker to satisfy the property that the software should have. It is a technology that comprehensively inspects possible states of the software.
  • the behavior of software is described in an input language called Promela
  • the property that software should have is a temporal logic equation called LTL (understanding problems in relation to time, A test is performed by describing in logical expressions to be expressed and inputting them in a model checker called SPIN.
  • the input of the temporal logic formula is not required.
  • Model inspection technology is a promising technology for ensuring the quality of software that is ever increasing in complexity and scale, but in order to comprehensively inspect possible states of software, the number of states that should be inspected in large-scale software Is a phenomenon called state explosion where a large amount of time occurs, and the time complexity required for processing becomes a practically unacceptable size, or a space complexity required for processing is a computer used for processing It is possible that one or both of the phenomena exceeding the mounted storage area occur and the examination can not be completed.
  • abstraction may be performed on the source code or the inspection code to reduce the number of states to the inspectable range.
  • the abstraction is, for example, simplification of the branching condition of the selective execution statement. Abstraction may cause an execution path that does not exist originally, or an existing execution path may disappear, thus causing a difference between the nature of software indicated by the inspection result for the inspection code and the nature of the original software. possible. Therefore, it is desirable to apply abstraction after considering the level of abstraction in view of the nature to be checked for software.
  • model checking technology it may be a practical problem that a large amount of effort is required to describe the software to be checked in the input language of the specific model checker.
  • Non-Patent Document 2 is a method and apparatus for performing a procedure of abstracting software to be inspected and converting it into an input language of a specific model checker using a computer.
  • FIG. 5 shows an overview of the method disclosed in US Pat.
  • the plurality of conversion rules include a conversion rule that converts source code into an intermediate format, a conversion rule that performs abstraction in the intermediate format, and a conversion rule that converts an intermediate format to a check code.
  • symbol execution technology As a source code inspection technology different from the model inspection. Symbolic execution techniques are also called symbolic simulation, symbolic execution, symbolic simulation. The symbol execution is shown in detail in, for example, Non-Patent Document 3 and the like.
  • Symbol execution is a technique for performing simulation execution using a symbol representing a numerical value and evaluating the result, instead of substituting specific values for variables included in source code for evaluation.
  • FIG. 8 an example of a target program is shown in the program shown in FIG.
  • line numbers are described to identify instructions in the source code. Other identification methods than line numbers may be used if the purpose is to identify the instruction.
  • control flow analysis for obtaining a control flow schematically shown in FIG. 9 is performed.
  • the control flow is a data structure that indicates in what order the instructions included in the program can be executed.
  • a plurality of possibilities of instruction execution order are expressed using a tree structure, for example, by a conditional statement represented by an if statement and a branch caused by an iteration statement represented by a while statement.
  • a rectangle (a node of a tree) represents an instruction included in a program.
  • the line numbers of the source code and the statements corresponding to the nodes are described.
  • Other expression forms may be used as long as the purpose of indicating the correspondence between nodes and source code can be achieved.
  • Arrows connecting nodes to nodes indicate the execution order between instructions. If there is an edge directed from one node to a plurality of nodes, this means a branch.
  • White circles indicate the start of the program shown in FIG. 9, and black circles indicate the end of the program shown in FIG.
  • the node 901 indicates the evaluation of the conditional statement “0 ⁇ x” indicated in the line number 001 of the source code 608.
  • An edge 902 indicates that the execution shifts to the node 903 when the evaluation result of the node 901 is true.
  • An edge 903 indicates that the execution shifts to the node 905 when the evaluation result of the node 901 is false.
  • FIG. 10 schematically shows the result of simulated execution of the control flow tree shown in FIG.
  • the upper part of the node of FIG. 10 shows the value of the variable.
  • the line numbers were written so that it could be understood which instruction in the source code was the result of execution.
  • Other expression forms other than line numbers may be used if the purpose is to associate the executed instruction with the simulated execution result.
  • the lower part of the node indicates a condition (path condition) which takes the corresponding value.
  • the node 1001 in FIG. 10 defines the value of the variable x as X, the value of the variable y as Y, and the value of the variable z as Z as an initial state.
  • the path condition is true, meaning that it takes the corresponding value unconditionally.
  • the edge 1002 in FIG. 10 shows the case where the path condition [0 ⁇ x] holds, and the node 1003 executes the instruction of the line number 002 of the source code 608 so that the variable x is X + 1, the variable y is Y, the variable z means that each has a value of Z.
  • the symbolic representation of the value of each variable in the final state and the condition having the relevant value can be obtained by simulating execution using symbols and accumulating path conditions.
  • JP 2000-181750 A JP, 2012-059026, A
  • the effort for obtaining the inspection code can be obtained by a method such as automatically generating the inspection code described in the input language of the model checker from the source code.
  • Reduction and specification and design of software are finished with realistic time complexity and space complexity (capacity of storage area for performing predetermined processing, and time) by exhaustive examination by model checker Need to be abstracted.
  • the source code is abstracted using the source code conversion device shown in Patent Document 2, thereby reducing the amount of time and space required for model checking by the model checker. It is possible.
  • another problem common to model inspection techniques is that it is difficult to inspect the values of variables included in source code.
  • Model checking technology treats combinations of values of multiple variables as states. Because of the possibility of possible values of each variable and exhaustive examination of their combinations, there is a high possibility of state explosion when performing a check on the value of the variables with model checking technology. Patent Document 2 does not mention the solution relating to this problem.
  • a variable included in the source code is not searched by substituting a specific value, and simulation is performed using a symbol. Therefore, the increase in the number of states due to the possible value of the variable is small.
  • the branches included in the source code also branch the control flow tree, and the edges and nodes increase. If there are multiple branches, the flow tree branches in combination. This causes an increase in time complexity and space complexity due to branching.
  • An object of the present invention is to provide a source code inspection method and a source code inspection program which terminate inspection with a realistic amount of time complexity and space complexity in view of the problems of the prior art.
  • the source code inspection method comprises the steps of: inputting a source code of software; inputting a plurality of different conversion rules; and sequentially applying the plurality of different conversion rules to the source code. And abstracting steps, In the steps of performing symbol execution on the generalization model obtained by abstracting the source code, performing further abstraction based on the result of symbol execution, and the inspection code described in the input language of the verification tool And converting.
  • Implementation-Generalization conversion rules are used to symbolize the contents of source code and convert them into an intermediate form, and abstraction conversion rules are used to perform abstraction to generate a generalization model.
  • Abstraction of source code (2) Symbolic execution of the generalization model is performed by appropriately replacing variables in the generalization model generated in the above (1) in accordance with the logic of the program (source code). At that time, in the judgment code of the source code, processing of symbol execution is performed assuming that the judgment result is "true” or "false”.
  • the generalization model generated in the above (1) is further abstracted by reflecting the result of the symbol execution of the above (2) and using the abstraction conversion rule, and the generalization model using the generalization-inspection conversion rule To generate the inspection code. (Abstraction of generalization model based on the result of symbol execution) (4) The source code is checked as a result by checking the check code generated in the above (3) with a model checker.
  • abstraction of source code reduces time complexity and space complexity associated with symbol execution, and re-abstraction based on the result of symbol execution results in time complexity and space computation associated with later examinations
  • the amount can be further reduced. Therefore, by significantly reducing the amount of calculation involved in the inspection, it is possible to realize an inspection that could not conventionally be realized with realistic time and storage capacity of a computer.
  • the source code to be inspected is converted into the inspection code described in the input language of the model checker using a plurality of different conversion rules, and the model inspection is executed by the model checker using the inspection code as an input.
  • the plurality of different conversion rules convert the source code to be inspected into the inspection code described in the input language of the model checker, and a series of processes to be abstracted are divided into fine-grained processing, and the plurality of conversion rules are converted.
  • the conversion from the source code to the inspection code is realized by using in combination.
  • symbol execution is performed on a generalization model which is an intermediate product of the conversion.
  • the series of processes for converting the source code to be inspected into the inspection code is divided into several processes including the process of abstraction, and different “conversion rules” of the series of divided conversion processes are applied.
  • the source code conversion unit used in the present invention has an interface for selecting and inputting a plurality of different conversion rules by the user when converting source code into inspection code.
  • the conversion rule is input by any one of a selection from among a plurality of conversion rules stored in advance inside the source code conversion device and a user description.
  • the source code conversion in the present invention may use, for example, the source code conversion method shown in Patent Document 2.
  • the conversion rule converts the source code into a form (generalization model) having generalized program information which does not depend on the description language of the source code. It is classified into transformation rules, abstraction transformation rules that abstract generalization models, and generalization-check transformation rules that transform abstracted generalization models into a description language of a model checker.
  • the target of symbol execution is a generalization model.
  • FIG. 1 is a system configuration diagram of a source code inspection device of the present invention.
  • the source code inspection apparatus shown in FIG. 1 is realized using a normal computer (processing apparatus).
  • FIG. 11 is an operation flow of the source code inspection device of the present invention.
  • the source code inspection apparatus of the present invention is realized as an inspection program 006 and stored in the main memory 002.
  • the source code 007 to be inspected and the conversion rule 008 used to convert the source code are recorded in advance in the file device 003 or the like. Designation of a program 007 to be inspected and designation of a conversion rule 008 to be used are performed from an input device 004 such as a keyboard or a mouse (S11001).
  • the central processing unit 001 receives the command of the inspection program 006 in the main memory 002, and reads out the source code 007 to be inspected and the conversion rule 008 from the file device 003 (S11002).
  • the central processing unit 001 performs abstraction and symbol execution and model checking based on the description of the conversion rule 008 (S11003). Further, the central processing unit 001 displays the inspection result by the symbol execution or the model inspection or both of them on the output device 005 such as a display or outputs it to a file device, a storage device or the like (S11004).
  • FIG. 2 is a schematic view of the configuration of a source code inspection program constituting the present invention.
  • the source code inspection program of the present invention comprises a source code conversion unit 201, a symbol execution unit 202, and a model inspection unit 204.
  • FIG. 12 is a schematic operation flow of the source code inspection program 006 constituting the present invention.
  • the source code conversion unit 201 reads the source code 007 and the conversion rule set 008 stored in the file device 003 (S1201).
  • the source code to be read and the conversion rule set are instructed from the input device 004 in FIG.
  • the source code conversion unit 201 converts the source code 007 according to the description of the conversion rule set 008 (S1202). It is assumed that the operation of the source code conversion unit 201 conforms to Patent Document 2.
  • the conversion result of the source code conversion unit 201 is passed to the symbol execution unit 202, and the symbol execution unit 202 executes symbol execution and returns the result to the source code conversion unit 201 (S1203).
  • the delivery of data between the source code conversion unit 201 and the symbol execution unit 202 may be delivery using the main memory 002 or delivery using the file device 003.
  • the source code conversion unit 201 receives the result of symbol execution, performs further conversion processing according to the conversion rule, and outputs the inspection code 203 which is the conversion result of the source code conversion unit 201 (S1204).
  • the output destination may be the file device 003 or the main memory 002.
  • the model inspection unit 204 reads the inspection code 203, executes model inspection, and outputs the result 205 of the model inspection (S1205).
  • FIG. 3 is a more detailed block diagram of the source code inspection program 006 constituting the present invention.
  • the source code inspection program 006 of the present invention comprises a source code conversion unit 201, a symbol execution unit 202, and a model inspection unit 204.
  • the source code conversion unit 201 includes an input unit 3101, a conversion processing unit 3102, an output unit 3103, a storage unit 3104, and a symbol execution interface unit 3015.
  • the symbol execution unit 202 includes a model interface unit 3201 and a symbol execution processing unit 3202.
  • the symbol execution interface unit 3105 and the model interface unit 3201 serve the purpose of exchanging information between the conversion processing unit 3102 and the symbol execution processing unit 3202, they are not independent parts but integral indivisible parts. It may be implemented as
  • FIG. 13 is an operation flow of the source code inspection program 006 constituting the present invention.
  • Steps S1301 and S1302 correspond to step S1201 in FIG.
  • the conversion processing unit 3102 performs source code conversion processing using the conversion rule set 008 stored in the storage unit 3104 (S1303).
  • the operations of the input unit 3101 and the conversion processing unit 3102 conform to Patent Document 2.
  • the conversion result by the conversion processing unit 3102 is transferred to the symbol execution processing unit 3202 via the symbol execution interface unit 3105 and the model interface unit 3201 (S1304). Steps S1303 and S1304 correspond to step S1202 in FIG.
  • the symbol execution processing unit 3202 executes symbol execution (S1305), and returns the result of the symbol execution to the source code conversion unit 201 via the model interface unit 3201 and the symbol execution interface unit 3105 (S1306).
  • the conversion result delivered from the conversion processing unit 3102 to the symbol execution unit 3202 may be an intermediate result obtained by performing conversion based on a part of conversion rules. That is, the generalization model shown in Patent Document 2 may be used.
  • the delivery of data between the source code conversion unit 201 and the symbol execution unit 202 may be delivery using the main memory 002 or delivery using the file device 003. Steps S1305 and S1306 correspond to step S1203 in FIG.
  • the conversion processing unit 3102 receives the result of symbol execution from the symbol execution interface unit 3105, and performs further conversion processing according to the conversion rule (S1307).
  • the output unit 3103 outputs the inspection code 203 which is the conversion result of the conversion processing unit 3102 (S1308).
  • the output destination may be the file device 003 or the main memory 002. Steps S1307 and S1308 correspond to step S1204 in FIG.
  • Step S1309 corresponds to step S1205 in FIG.
  • symbol execution is performed on a generalization model obtained by converting the source code to be inspected.
  • Patent Document 2 since the generalization model is obtained by converting the source code into an intermediate language which does not depend on a specific program language, even if the program language of the source code to be inspected is changed, the symbol The execution unit 202 can use the same one. Further, by defining conversion rules, it is possible to convert a program structure that is difficult to execute symbols depending on the programming language into a program structure that is easy to execute symbols.
  • the result of symbol execution is used to further transform the generalization model.
  • the conversion process is performed using a conversion rule that checks whether the path condition obtained by symbol execution satisfies the value of the variable and deletes branches unnecessary for the test.
  • the inspection code can be output and the model inspection can be performed in the model inspection unit 204. As a result, it is possible to reduce the amount of time and space required for model checking.
  • the symbol execution is performed on the generalization model obtained by converting the main source code in which the property to be inspected appears.
  • model testing can be performed by combining the main source code with other secondary source code having an interaction. This makes it possible to check that the symbol execution is performed for a particular input and that the corresponding result can be obtained, but not for whether the input can be present in interaction with other software or devices. For a task, it is possible to check whether there is an interaction actually by using model checking.
  • a portion of the secondary source code may be source code that simulates the operation of a device acting on primary software that is not software.
  • FIG. 4 is a view showing a configuration example of the source code conversion unit 201 and the symbol execution unit 202 in the source code inspection program 006 according to the present invention.
  • FIG. 6 is a diagram showing a data flow related to the source code conversion unit 201 and the symbol execution unit 202.
  • FIG. 7 shows the details of the configuration of the symbol execution unit 202. As shown in FIG.
  • the input unit 3101 includes a source code input unit 3110 and a conversion rule input unit 3111.
  • the conversion processing unit 3102 includes a model construction unit 3121, an implementation-generalization model conversion unit 3122, an abstraction model conversion unit 3123, and a generalization-inspection model conversion unit 3124.
  • the output unit 3103 includes an inspection code writing unit 3131.
  • the storage unit 3104 includes a conversion rule database 3141, a meta model database 3142, and a writing rule database 3143.
  • the symbol execution interface unit 3105 includes a generalization model output unit 3151 and a symbol execution result input unit 3152.
  • the input unit 3101 receives data input by the user and performs processing for supplying the input data to the conversion processing unit 3102.
  • the input unit 3101 receives information on the source code 007 and a plurality of conversion rules applied to each of the divided processes, that is, information on the “conversion rule set” 008, and supplies the information to the conversion processing unit 3102.
  • the input unit 3101 may receive an instruction by the user regarding drive and control of the conversion processing unit, drive and control of the output unit, and drive and control of the symbol execution unit.
  • the conversion processing unit 3102 may use, for example, the conversion processing unit of the source code conversion device described in Patent Document 2.
  • the conversion processing unit 3102 is supplied with the information 601 of the source code 007 and the information of the conversion rule set 008 to be applied to the source code 007 from the input unit 3101, and converts the source code information 601 by the conversion rule set 008 Processing is performed, and information on the conversion result is supplied to the output unit 3103.
  • the information on the conversion rule set 008 supplied from the input unit 3101 includes only identification information indicating the conversion rule stored in the storage unit, and the substance of the conversion rule set 008 is It may be retrieved from the storage unit 3104 using the identification information and used for conversion.
  • the conversion processing unit 3102 includes a model construction unit 3121, an implementation-generalization model conversion unit 3122, an abstraction model conversion unit 3123, and a generalization-inspection model conversion unit 3124.
  • the conversion processing unit 3102 converts source code information 601 into an inspection model 605 by model conversion using a meta model and a conversion rule.
  • the meta-mounting model 620, the meta-generalization model 621, and the meta-inspection model 622 are described, for example, by the MOF described in Non-Patent Document 3. Further, for example, in the QVT described in Non-Patent Document 4, the implementation-generalization conversion rule 602, the abstraction conversion rule 603, and the generalization-inspection conversion rule 604 are described to perform model conversion. .
  • the conversion may be another model conversion method of the method exemplified above, or a plurality of methods may be mixed.
  • the model construction unit 3121 receives the source code information 601 from the source code input unit 3110, and converts it into a mounting model 606.
  • the form of the implementation model 606 is defined by its meta model, the meta-implementation model 620.
  • the inspection code is output. Information may be omitted or added to an extent that does not deviate from the purpose of
  • the implementation-generalization model conversion unit 3122 converts the implementation model 606 into a generalization model 607 using the implementation-generalization conversion rule 602, the meta / implementation model 620, and the meta / generalization model 621.
  • a generalization model has a data structure that can represent structures and processes in multiple programming languages. For example, in the generalization model, the If statement and the Switch statement in the source code 007 are not distinguished, and are expressed as selective execution statements.
  • the implementation-generalization conversion rule 602 when converting the implementation model 606 into the generalization model 607, only the implementation-generalization conversion rule 602 may be used. In another embodiment, when the implementation-generalization conversion rule 602 includes a plurality of conversion rules, the plurality of conversion rules are integrated into one conversion rule, and the implementation model 606 is converted to the generalization model 607. There are methods available for the conversion of In one embodiment, when the implementation-generalization conversion rule 602 includes a plurality of conversion rules, the procedure of converting the implementation model 606 into the generalization model 607 by repeating the conversion process a plurality of times is possible.
  • the abstraction model conversion unit 3123 performs abstraction of the generalization model 607 using the abstraction conversion rules 603 and the meta / generalization model 621.
  • abstraction there can be a method of replacing a conditional expression in a selection statement with a constant, or a definite or non-deterministic choice.
  • the abstraction conversion rule 603 when abstracting the generalization model 607, only the abstraction conversion rule 603 may be used. In another embodiment, when the abstraction conversion rule 603 includes a plurality of conversion rules, a method of integrating the plurality of conversion rules into one conversion rule and using it for abstraction of the generalization model 607 is used. possible. In another embodiment, when the abstraction conversion rule 603 includes a plurality of conversion rules, there may be a procedure of converting the generalization model 607 by repeating the conversion process a plurality of times.
  • the generalization-inspection model conversion unit 3124 converts the generalization model 607 into the inspection model 605 using the generalization-inspection conversion rule 604, the meta-generalization model 621, and the meta-inspection model 622 Do.
  • the inspection code 203 is in Promela format
  • an element expressed as a selective executable sentence in the generalization model is expressed as an IF sentence in the inspection model.
  • the generalization-inspection conversion rule 604 when converting the generalization model 607 to the inspection model 605, only the generalization-inspection conversion rule 604 may be used.
  • the generalization-inspection conversion rule 604 when the generalization-inspection conversion rule 604 includes a plurality of conversion rules, the plurality of conversion rules are integrated into one conversion rule, and the generalization model 607 is converted to the inspection model 605. There are methods available for the conversion of
  • the generalization-inspection conversion rule 604 when the generalization-inspection conversion rule 604 includes a plurality of conversion rules, the procedure of converting the generalization model 607 into the inspection model 605 by repeating the conversion process a plurality of times. There is a possibility.
  • the symbol execution interface unit 3105 has a generalization model output unit 3151 and a symbol execution result input unit 3152.
  • the generalization model output unit 3152 is supplied with the generalization model from the conversion processing unit 3102, has a role of supplying the generalization model information 608 to the symbol execution unit 202, and is supplied with the symbol execution result information 610 in the symbol execution unit 202, It serves to supply the symbol execution result information 610 to the conversion processing unit 3102.
  • the generalization model information 608 supplied from the conversion processing unit 3102 and the generalization model 607 supplied to the symbol execution unit may have the same information or may have only information necessary for symbol execution. . Also, the implementation of the generalization model supplied from the conversion processing unit 3102 may be different from the implementation of the generalization model supplied by the symbol execution interface unit 3105.
  • the output unit 3103 outputs the inspection code 203 using the information of the conversion result supplied from the conversion processing unit 3102.
  • information such as grammar information of a description language of a model checker may be supplied from the storage unit.
  • the inspection code writing unit 3131 converts the inspection model 605 into the inspection code 203 using the meta / inspection model 622 and the inspection code writing rule 611 acquired from the writing rule database 3143 of the storage unit 3104.
  • the inspection code writing rule 611 is described by the method described in Non-Patent Document 5, and the inspection model 605 is converted into the inspection code 203.
  • the present invention is not limited to this, and any method may be used to convert the inspection model 605 into the description format of the model checker used for the inspection.
  • the inspection code 203 is described by Promela which is an input language of SPIN.
  • each of the conversion rule database 3141, the meta model database 3142, and the writing rule database 3143 is, for example, any data storage method realized on a computer, such as a relational database or a hierarchical database. Is realized by The conversion rule database 3141, the meta model database 3142, and the writing rule database 3143 do not have to be realized in the same system, and may be realized in different systems. Further, each of the conversion rule database 3141, the meta model database 3142, and the writing rule database 3143 does not have to be realized by a single method, and, for example, a part of the information to be held is a relational database. , And a part of the information to be stored may be realized by a combination of different methods, such as incorporation in a computer program for realizing the invention.
  • the storage unit 3104 supplies information necessary for the input unit 3101, the conversion processing unit 3102, and the output unit 3103 to perform their respective processes.
  • the storage unit 3104 stores information on a conversion rule, information on a meta model, and information on a grammar of a description language of a model checker.
  • the conversion rule database 3141 holds the conversion rules along with the metadata, as described above.
  • the metadata is for selecting a conversion rule, and there can be methods having different information of an implementation-generalization conversion rule 602, an abstraction conversion conversion rule 603, and a generalization-inspection conversion rule 604. .
  • the metadata of the implementation-generalization conversion rule 602 may be, for example, the type of description language of the conversion source code.
  • the metadata of the abstraction conversion rule 603 is, for example, a name that clearly represents the abstraction, a brief description, a type of abstraction such as “data abstraction” or “process abstraction”, natural language or There may be a state reduction effect by abstraction represented by alphabets and numbers, influence on nature by abstractions represented by alphabets and numbers, and software domains to which abstractions can be applied.
  • the generalization-to-check conversion rule 604 metadata may have, for example, a name indicating a model checker to use for the check.
  • the symbol execution unit 202 includes a model interface unit 3201 and a symbol execution processing unit 3202.
  • the model interface unit 3201 receives generalization model information 608 supplied by the symbol execution interface 3105 of the source code conversion unit 201 and supplies the generalization model information 701 to the symbol execution processing unit 3202, and the symbol execution processing unit
  • the processing result information 702 of 3202 is input, and the processing result 610 is supplied to the symbol execution interface unit 3105 of the source code conversion unit 201.
  • the symbol execution processing unit 3202 receives the generalization model information 701 supplied from the model interface unit 3201, executes symbol execution processing, and supplies the result of symbol execution to the model interface unit 3201.
  • the symbol execution process executes the process shown in Non-Patent Document 1, for example.
  • symbol execution refers to performing processing as if the program was executed by replacing variables in the source code as appropriate according to the logic of the program (source code), and in particular, determining the source code In the sentence, processing of this symbol execution is performed assuming that the determination result is "true" and "false".
  • the symbol execution interface unit 3105 and the model interface unit 3201 are implemented in an inseparable manner, and the generalization model 607 supplied from the conversion processing unit 3102 is supplied to the symbol execution processing unit 3202, The symbol execution result 3212 supplied from the symbol execution unit 202 may be supplied to the conversion processing unit 3102.
  • the detailed operations of the input unit 3101, the conversion processing unit 3102, the storage unit 3104, and the output unit 3103 are, for example, the symbol execution interface unit 3105, the model interface unit 3201, and the symbols according to the example of Patent Document 2. Details of the execution processing unit 3202 will be described.
  • the generalization model output unit 3151 takes as input the generalization model 607 that is the result of conversion performed by the implementation-generalization model conversion unit 3122 (S 1401). Next, the generalization model output unit 3151 reads the meta generalization model 621 that defines the generalization model from the meta model database 3142 stored in the storage unit 3104. The generalization model output unit 3151 refers to the meta-generalization model 621 of the generalization model 607, and generates model information 608 for performing the symbolization of the generalization model 607 (S1402). The order of the input of the generalization model and the reading of the meta model of the generalization model may be reversed.
  • the generalization model output unit 3151 transfers the generalization model information 608 to the generalization model input unit 3211 of the model interface unit 3201 (S1403).
  • the generalization model information 608 can be expressed using a computer-readable expression form, for example, the XML form shown in Non-Patent Document 5. Other expressions may be used.
  • the generalization model can be exchanged between the symbol execution interface unit 3105 and the generalization model input unit 3211 through the memory area, through the communication path, through the file system, or the like. It may be any method of
  • the generalization model input unit 3211 of the model interface unit 3201 passes the passed generalization model information 608 to the symbol processing unit 3202 (S1404).
  • the generalization model input unit 3211 extracts information used by the symbol execution processing unit 3202 among the information included in the generalization model information 608 (S1405).
  • the information used by the symbol execution processing unit 3202 includes at least a control flow graph. Although the details are described in Non-Patent Document 1, for example, the information on the graph shown in FIG. 9 is included.
  • the generalization model input unit 3211 transfers the extracted information to the symbol execution processing unit 3202 (S1406).
  • the extracted information can be expressed using a computer-readable expression form, for example, the XML form shown in Non-Patent Document 5. Other expressions may be used. Further, the delivery of the extracted information may be via a memory area, via a communication channel, via a file system, or any other method.
  • the symbol execution processing unit 3202 inputs the input information and performs symbol execution.
  • FIG. 9 shows an example where the control flow graph is an input.
  • the symbol execution processing unit 3202 generates a symbol execution tree schematically shown in FIG. 10 while sequentially tracing the connection relationship of the graphs, starting from the control start position of the control flow graph, that is, in the example of FIG. .
  • a symbol indicating an initial value is assigned to each variable included in the source code 007.
  • the initial value of variable x is assigned as symbol X
  • the initial value of variable y as symbol Y
  • the initial value of variable z as symbol Z (1001).
  • the symbol to be assigned may be automatically determined by the symbol execution processor 3202 randomly or by changing the variable name.
  • the user of the source code inspection device may input an initial symbol from the input unit.
  • the node 901 in FIG. 9 is a conditional statement
  • an edge 1002 and an edge 1003 corresponding to the node 901 are generated.
  • the edge 1002 indicates that the conditional expression of the node 901 is true
  • the edge 1003 indicates that the conditional expression of the node 901 is false.
  • the node 903 generates an edge 1004 following the edge 1002 in FIG. 10 to mean that the conditional expression of the node 902 is true.
  • the value of each variable when the assignment statements shown in the nodes 903 and 904 are applied to the node 1001 is calculated symbolically.
  • the upper part of the edge 1004 shows the result of the calculation.
  • the condition of the edge 1002 is added as the path condition of the node 1004.
  • the symbol execution processing unit 3202 passes the symbol execution result information 702 to the symbol execution result output unit 3212.
  • An example of the symbol execution result information is, for example, a graph schematically shown in FIG.
  • the symbol execution result output unit 3212 passes the symbol execution result information 610 to the symbol execution result input unit 3152 (S1408).
  • the symbol execution result information 610 can be expressed using a light-machine-readable expression form, for example, the XML form shown in Non-Patent Document 5. Other expressions may be used. Further, the delivery of the extracted information may be via a memory area, via a communication channel, via a file system, or any other method.
  • the symbol execution result input unit 3152 interprets the received symbol execution result information 610 and supplies it to the abstraction model conversion unit 3123 (S1409).
  • the abstraction model conversion unit 3123 receives the symbol execution result information 610, and converts the generalization model 607 according to the abstraction conversion rule 603 included in the conversion rule database 3141 (S1410).
  • the conversion method using the symbol execution result can be described as a conversion rule.
  • FIG. 10 a case where the result of performing symbol execution on the generalization model for the source code shown in FIG. 8 is FIG. 10 will be described as an example.
  • symbol execution in FIG. Referring to the end of the result tree, it can be seen that the nodes 1005 and 1006 satisfy the preconditions, and the node 1007 does not satisfy the preconditions. That is, if [0 ⁇ x] at the edge 1003 is false, the test precondition is not satisfied. Therefore, conversion of a generalization model can be considered such that one of the branches of line number 001 (condition is false) of the corresponding source code is eliminated.
  • a rule indicating the conversion described above can be described as a conversion rule.
  • the source code inspection apparatus of the present invention abstracts the source code to be inspected, executes symbol execution for the generalization model, and uses the result of the symbol execution to perform generalization.
  • the transformation model can be transformed and abstracted again.
  • the inspection unit can efficiently inspect temporally and spatially by inspecting the re-abstracted inspection model based on the model inspection technology.
  • the second embodiment is characterized in that the symbol execution result is generated using a general expression.
  • the meta model database 3142 has a meta control flow model 1501 and a meta symbol execution result model 1502.
  • the meta control flow model 1501 and the meta symbol execution result model 1502 are, for example, MOF (Model Object Facility, shown in Non-Patent Document 3) as in the meta implementation model, meta generalization model, and meta inspection model shown in Patent Document 2. It can be implemented using a technology that defines the syntax of a model. That is, the MOF is used to define the syntax and semantics of the meta control flow model 1501 and the meta symbol execution result model 1502.
  • the generalization model input unit 3211 parses the generalization model 608 with reference to the meta-generalization model 621, extracts control flow information from the generalization model 608, and performs meta control with reference to the meta control flow model 1501.
  • the generalization model information 701 according to the flow model 1501 is generated and passed to the symbol execution processing unit 3202.
  • the symbol execution processing unit 3202 can parse the received generalization model information 701 with reference to the meta control flow model 1501, and can execute symbol execution.
  • the symbol execution processing unit 3202 refers to the meta symbol execution result model 1502 and generates the symbol execution result information 702 according to the meta symbol execution result model 1502, and the symbol execution result output unit 3212 executes the generated symbol execution
  • the result information 610 is delivered to the symbol execution result input unit 3152.
  • the symbol execution result information 610 is handed over from the symbol execution result input unit 3152 to the abstraction model conversion unit 3123.
  • the abstraction model conversion unit 3123 refers to the meta symbol execution result model 1502 and outputs the symbol execution result information 610 to the syntax. It can be analyzed. Further, in the conversion rule prepared in advance, the conversion rule can be described in accordance with the syntax of the symbol execution result information 610 defined in the meta symbol execution result model 1502.
  • the syntax and semantics of data handled by the source code inspection device according to the present invention can be integratedly managed using a meta model database, and the source code inspection device can be implemented using a unified notation. It can be configured. This makes it easy and efficient to describe the data necessary to operate the source code inspection device including the implementation of the conversion rules.
  • pre-processing for symbol execution can be described as a conversion rule to facilitate symbol execution.
  • conversion rules information necessary for creating a control flow graph as shown in FIG. 15 from an implementation model or a generalization model, that is, an instruction, an order relation between instructions, and a control branch Describe conversion rules for extracting information including.
  • a conversion rule a conversion rule that expands function calls included in source code and integrates them into one function, or a conversion rule that repeatedly changes conditions so as to end repetitive processing included in source code in a limited number of times, source
  • the dynamic memory allocation included in the code for example, in the case of C language, a rule for converting the call of the malloc function to use of a fixed memory which is allocated in advance can be defined as a conversion rule.
  • a source code inspection program and a source code inspection apparatus will be described with reference to FIG.
  • a case will be described in which not only the main code which is the source code to be directly inspected but also the slave code related to the main code is to be inspected.
  • the source code included in the source code set is a main source code 1601 and a subordinate source. It is assumed that the code 1602 is specified.
  • the main source code is a source code that expresses the property to be examined.
  • the source code containing the function is called main source code, and the other source code is Call it source code.
  • the main source code does not have to be a file unit of the source code given in advance, and the range limited to the part including the function may be the main source code. In that case, portions other than the main source code included in the source code file are secondary source code.
  • another function related to the function for example, a function that calls the function and a function to be called may have a portion including the function as main source code.
  • source code that implements the software that you want to test may be included as secondary source code.
  • the designation of the main source code and the secondary source code may be distinguished when stored in the file device 003, as shown in FIG.
  • the source code is not distinguished on the file device 003, and after the source code is read by the input unit 3101, the user of the source code inspection device designates it using the input device 004. It is also good.
  • the main source code 1601 is to be processed by the source code conversion unit 201 and the symbol execution unit 202 described in the first embodiment, the second embodiment or the third embodiment.
  • the inspection code 203 is obtained.
  • the secondary source code uses the source code conversion unit 1611 to be the target of source code conversion shown in Patent Document 2, for example.
  • the inspection code 1612 can be obtained.
  • the inspection code 203 and the inspection code 1612 are passed to the model inspection unit 204 to execute model inspection.
  • the source code conversion unit 201 for the main source code 1601 and the source code conversion unit 1611 for the source code according to the main source code 1601 may be implemented as an independent part, only one source code conversion unit is mounted.
  • the single source code conversion unit may change the operation according to the type of the source code, when 1610 is input and when the secondary source code 1602 is input. That is, when the main source code is input, the symbol execution information is passed to the symbol execution unit 202, and when the secondary source code is input, the symbol execution information may not be passed to the symbol execution unit 202.
  • the source code conversion unit 201 extracts a specific part of the program included in the main source code as the inspection target by symbol execution on the main source code, and generates the inspection code 203,
  • the inspection in consideration of the interaction with the inspection code 1612 generated from the secondary source code 1602 can be inspected in the model inspection unit 204 using the model inspection.
  • the model checking unit is abstracted by the source code conversion unit 201 using the symbol execution result for the main source code. Resources related to spatial or temporal inspection of model inspection. As described above, it is possible to realize a source code inspection device for a plurality of source codes while preventing state explosion.

Landscapes

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

Abstract

 ソフトウェアのソースコード検査技術の1つにモデル検査技術があるが、ソースコードの規模や複雑さに伴い、検査に要する時間的計算量および空間的計算量が膨大となり現実的に検査不能な場合がある。ソースコードを検査コードに変換する際に、ソースコードを抽象化し、計算量を削減するアプローチがあるが、ソースコードに含まれる複数の変数の値域が広い場合には、変数値の組合せによる状態数の爆発が起こることが知られている。 ソースコードを検査コードに変換する際、複数の変換ルールにより利用者が指定した抽象化を行い、ソースコードを抽象化して得られる汎化モデルに対して記号実行を行い、記号実行の結果に基づいて汎化モデルを再抽象化する。再抽象化した汎化モデルに対してモデル検査を行う。

Description

ソースコード検査方法及び装置
本発明は、ソースコード検査方法及び装置に係り、特に、ソフトウェアを検証する際に、検査に係る計算量の増大を抑制するために、計算機を活用してソースコードを抽象化した上で、計算機による記号実行ならびにモデル検査を実行する検査方法及び装置に関する。
 近年、ソフトウェアシステムが一般社会に浸透し、ソフトウェアに求められる信頼性が非常に高くなってきている一方で、ソフトウェアは複雑化および大規模化の一途をたどっており、手作業でのレビューや、テストによる品質確保が非常に困難になってきている。
 モデル検査技術は、たとえば非特許文献1に開示される方法であって、ソフトウェアの振舞いを、特定モデルチェッカの入力言語で記述し、特定モデルチェッカを実行することで、ソフトウェアが持つべき性質を満たしているかどうかを、前記ソフトウェアの取り得る状態を網羅的に検査する技術である。非特許文献1に開示される方法によると、ソフトウェアの振る舞いを、Promelaと呼ばれる入力言語で記述し、ソフトウェアが持つべき性質をLTLと呼ばれる時相論理式(時間との関連で問題を理解し、表現する論理式)で記述し、SPINと呼ばれるモデルチェッカにそれらを入力することで、検査を実施する。もしくは、ソフトウェアが持つべき性質として、到達可能性などSPINが予め検査機能をもつ性質について検査する場合には、時相論理式の入力は必要としない。
 モデル検査技術は複雑化及び大規模化の一途をたどるソフトウェアの品質確保に有望な技術であるが、ソフトウェアの取り得る状態を網羅的に検査するため、規模の大きなソフトウェアでは、検査すべき状態数が膨大な分量となる状態爆発と呼ばれる現象が起き、処理に必要な時間計算量が現実的に許容不可能な大きさとなる現象と、もしくは、処理に必要な空間計算量が処理に用いる計算機に搭載された記憶領域を超える現象の、両方もしくは一方が起き、検査を完了することができないことがあり得る。
 状態爆発に対応するために、抽象化と呼ばれる処理を、ソースコードもしくは検査コードに対して行い、状態数を検査可能な範囲まで削減することがある。抽象化は、例えば、選択的実行文の分岐条件の簡略化がある。抽象化によって、本来存在しない実行パスが生じる、もしくは、存在する実行パスが消滅することがあり得るため、検査コードに対する検査結果が示すソフトウェアの性質と、本来のソフトウェアの性質に差異が生まれることがあり得る。そのため、ソフトウェアに対して検査すべき性質に鑑み、抽象化の水準を検討した上で、抽象化を適用することが望ましい。
 さらに、モデル検査技術は、検査対象のソフトウェアを、特定モデルチェッカの入力言語で記述する労力が大きいことが実用上の問題となることがあり得る。
 検査対象のソフトウェアを抽象化し、特定モデルチェッカの入力言語に変換する手順を計算機を用いて実施する方法および装置として、たとえば非特許文献2に開示される方法および装置がある。図5に、特許文献2に開示される方法の概観を示す。非特許文献2によると、ソースコードを検査コードに変換する際、複数の変換ルールを選択する手段を提供し、利用者が容易に抽象化の水準を変更可能としている。また、複数の変換ルールは、ソースコードを中間形式に変換する変換ルールと、中間形式において抽象化を行う変換ルールと、中間形式から検査コードに変換する変換ルールとを含んでいる。
 モデル検査とは異なるソースコードの検査技術として、記号実行技術がある。記号実行技術は、記号シミュレーション、シンボリック実行、シンボリックシミュレーションとも呼ばれる。記号実行については、たとえば非特許文献3などに詳しく示されている。
 記号実行は、ソースコードに含まれる変数に具体的な値を代入して評価するのではなく、数値を代表する記号を用いて模擬的な実行を行い、その結果を評価する技術である。例えば、図8に示すプログラムに対象とするプログラムの例を示す。図8では、ソースコード内の命令を識別するために、行番号を記載した。命令を識別する目的を果たすならば、行番号以外の識別方法を用いてもよい。図8に示すプログラムに対して記号実行を行う場合、まず図9に模式的に示すような制御フローを得るための制御フロー解析を行う。制御フローとは、プログラムに含まれる命令がどのような順番に実行されうるかを示すデータ構造である。制御フローでは、if文に代表される条件文や、while文に代表される繰り返し文によって生じる分岐による、命令の実行順序の複数の可能性をたとえばツリー構造を用いて表現する。図9では、矩形(ツリーのノード)はプログラムに含まれる命令を表す。図9では、ノードとソースコードとの対応を示すため、ノードに対応するソースコードの行番号と命令文を記載した。ノードとソースコードとの対応を示す目的が果たせれば、他の表現形式でもよい。ノードとノードをつなぐ矢印(ツリーのエッジ)は、命令間の実行順序を表す。1つのノードから複数のノードにそれぞれ向かったエッジが存在する場合は、分岐を意味している。白丸は図9に示したプログラムの開始、黒丸は図9に示したプログラムの終了を示す。たとえば、ノード901は、ソースコード608の行番号001に示された条件文「0<x」の評価を示す。エッジ902はノード901の評価結果が真の場合にノード903に実行が移ることを示す。エッジ903はノード901の評価結果が偽の場合にノード905に実行が移ることを示す。
 記号実行では、制御フローを基に記号を用いた模擬的な実行を行う。図10に、図9に示す制御フローツリーを模擬的に実行した結果を模式的に示す。図10のノードの上段は、変数の値を示す。ただし、元のソースコードとの対応づけのため、ソースコード中のどの命令を実行した結果であるかが分かるように行番号を記載した。実行した命令と模擬的な実行結果との対応づける目的を果たせば、行番号以外の他の表現形式を用いて良い。ノードの下段は該当の値を取る条件(パスコンディション)を示す。図10のノード1001では、初期状態として変数xの値をX、変数yの値をY、変数zの値をZと定義している。プログラムの開始であるので、パスコンディションはtrue、つまり無条件に該当の値をとることを意味する。図10のエッジ1002では、パスコンディション[0<x]が成り立つ場合を示し、ノード1003では、ソースコード608の行番号002の命令を実行することにより、変数xはX+1、変数yはY、変数zはZという値をそれぞれ持つことを意味する。以下同様に、記号を用いた模擬的な実行と、パスコンディションの積み上げにより、最終状態の各変数の値の記号表現と、当該の値を持つ条件を得ることができる。
特開2000-181750号公報 特開2012-059026号公報
Gerard J. Holzmann, "The SPIN Model Checker: Primer and Reference Manual", Addison-Wesley Professional, 2003, ISBN: 978-0321228628 玉井哲夫、福永光一、"記号実行システム" 情報処理、pp.18-28、1982/1/15 The Object Management Group, "Meta Object Facility (MOF) Core Specification", formal/06-01-01, January 2006, http://www.omg.org/spec/MOF/2.0/PDF The Object Management Group , "Meta Object Facility (MOF) 2.0 Query/View/Transformation Specification", formal/2008-04-03, April 2008, http://www.omg.org/spec/QVT/1.0/PDF W3C, "Extensible Markup Language (XML) 1.1 (Second Edition)", W3C Recommendation 16 August 2006, edited in place 29 September 2006, http://www.w3.org/TR/2006/REC-xml11-20060816
 モデル検査によるソフトウェアの信頼性確保を有効に実施するためには、ソースコードからモデルチェッカの入力言語で記述された検査用コードを自動生成するなどの方法により、検査用コードを得るための労力を低減させること、および、ソフトウェアの仕様および設計を、モデルチェッカによる網羅的検査が現実的な時間計算量および空間計算量(所定の処理を実行するための記憶領域の容量、及び時間)で終了するように抽象化することが必要となる。
 特許文献2に開示される方法によると、特許文献2に示すソースコード変換装置を用いて、ソースコードを抽象化することにより、モデルチェッカによるモデル検査に要する時間計算量、空間計算量の削減が可能である。しかし、特許文献2に限らず、モデル検査技術に共通する別の問題として、ソースコードに含まれる変数の値に関する検査が困難なことが挙げられる。モデル検査技術では、複数の変数の値の組合せを状態として扱う。各変数の取りうる値の可能性と、それらの組合せを網羅的に検査することから、変数の値に関する検査をモデル検査技術で実施する場合は、状態爆発を起こす可能性が高い。特許文献2には、本問題に係る解決には言及していない。
 他方、記号実行を実施する場合には、ソースコードに含まれる変数に対して、具体的な値を代入して探索することはせず、記号を用いて模擬的に実行を行う。そのため、変数が取りうる値の可能性による状態数の増加は少ない。しかし、ソースコードに含まれる分岐によって制御フローツリーも分岐し、エッジおよびノードが増加する。分岐が複数ある場合には、組合せ的にフローツリーが分岐していく。このため、分岐による時間計算量および空間計算量の増大を生じる。
 また、記号実行には、その原理を起因として、計算が難しいプログラム構造がある。たとえば(1)関数呼出し(2)動的なメモリアクセス(3)繰り返しがある。さらに、ソースコードに対する記号実行を行う場合、ソースコードの意味論を解釈する必要がある。ソースコードの意味論は、ソースコードの実装に用いているプログラム言語、たとえばC言語、たとえばJava(登録商標)などに依存するため、プログラム言語によって異なる意味論に対応した記号実行方法を開発しなければならない。
 さらに、多くのソフトウェアまたはソフトウェアにより制御される装置は、他のソフトウェアもしくは他の装置と相互作用しながら動作する。そのため、ソフトウェアに対して入力される値によってソフトウェアによる計算結果が決定するだけでなく、他のソフトウェアや装置との間の相互作用に伴う入力のタイミングによってもソフトウェアの計算結果が決定される。しかし、記号実行では、ソースコードが示す制御フローを基に模擬的な実行を行うため、特定の入力に対して対応する結果が得られることは検査できるものの、当該の入力が他のソフトウェアもしくは装置との相互作用において存在しうるかどうかについては検査できない。
 本発明は、従来の技術の課題を踏まえ、現実的な時間計算量および空間計算量で検査を終了するソースコード検査方法およびソースコード検査プログラムを提供することを目的とする。
 本発明のソースコード検査装置によるソースコード検査方法は、ソフトウェアのソースコードを入力するステップと、異なる複数の変換ルールを入力するステップと、前記ソースコードを、前記異なる複数の変換ルールをつぎつぎと適用して抽象化するステップと、           
ソースコードを抽象化して得られた汎化モデルに対して記号実行を行うステップと、記号実行の結果に基づいて更に抽象化を実施するステップと、検証ツールの入力言語で記述された検査コードに変換するステップとを有することを特徴とする。
 即ち、本発明では以下の手順を実行する。
 (1)実装―汎化変換ルールを用いて、ソースコードの内容を記号化して中間形式に変換し、と抽象化変換ルールを用いて抽象化を行って汎化モデルを生成する。(ソースコードの抽象化)
 (2)プログラム(ソースコード)のロジックに従って、上記(1)で生成した汎化モデルの中の変数を適宜置き換えることにより、汎化モデルの記号実行を行う。その際、ソースコードの判定文では、判定結果が仮に「真」の場合、及び「偽」の場合を想定して記号実行の処理を行う。
 (3)上記(2)の記号実行の結果を反映し抽象化変換ルールを用いて、上記(1)で生成した汎化モデルを更に抽象化し、汎化―検査変換ルールを用いて汎化モデルを変換して検査コードを生成する。(記号実行の結果に基づいた汎化モデルの抽象化)
 (4)上記(3)で生成した検査コードをモデルチェッカでチェックすることにより、結果的に、ソースコードの検査が行われる。
 本発明によれば、ソースコードの抽象化により記号実行に係る時間計算量および空間計算量を削減するとともに、記号実行の結果に基づく再抽象化により、後段の検査に係る時間計算量および空間計算量を更に削減できる。そのため、検査に係る計算量を大幅に削減することにより、従来、現実的な時間および計算機の記憶容量では実現不可能であった検査を実現できる。
本発明のソースコード検査装置の構成例を示す図である。 本発明のソースコード検査プログラムの構成例の概要を示す図である。 本発明のソースコード検査プログラムの構成例を示す図である。 本発明の実施例に係るソースコード検査プログラムの構成例を示す図である。 従来のソースコード変換装置の概要を示す図である。 本発明の第一の実施例に係るソースコード変換部の構成例を示す図である。 本発明の第一の実施例に係る記号実行部の構成例を示す図である。 検査対象となるソースコードの例を示す図である。 制御フローグラフの例を示す図である。 記号実行結果の例を示す図である。 本発明のソースコード検査装置の動作手順の概要を説明する図である。 本発明のソースコード検査プログラムの動作手順の概要を説明する図である。 本発明のソースコード検査プログラムの動作手順のより詳細を説明する図である。 本発明の第一の実施例に係るソースコード変換プログラムの動作手順を説明する図である。 本発明の第二の実施例に係るソースコード変換部の構成例を示す図である。 本発明の第四の実施例に係るソースコード変換部の構成例を示す図である。
 本発明では、異なる複数の変換ルールを用いて検査対象のソースコードをモデルチェッカの入力言語で記述された検査コードへと変換し、前記検査コードを入力としてモデルチェッカによるモデル検査を実行する。前記異なる複数の変換ルールは、検査対象のソースコードをモデルチェッカの入力言語で記述された検査コードへと変換し、抽象化する一連の処理を細粒度に分割したものであり、複数の変換ルールを組み合わせて用いることにより、前記ソースコードから前記検査コードへの変換が実現される。
 本発明において、前記検査対象のソースコードから、前記検査コードへの変換の過程において、変換の中間生成物である汎化モデルに対する記号実行を行う。
 検査対象のソースコードを検査コードへと変換する一連の処理を、抽象化の処理も含めて、いくつかの処理に分割し、分割された一連の変換処理のそれぞれ異なる「変換ルール」を適用する。本発明で用いるソースコード変換部は、ソースコードを検査コードへ変換する時、異なる複数の変換ルールが、利用者によって、選択され、入力されるためのインタフェースを所有する。前記変換ルールは、事前にソースコード変換装置内部に蓄積された複数の変換ルールの中からの選択と、利用者の記述と、のいずれかの手段により入力される。なお、本発明におけるソースコード変換は、たとえば前記特許文献2において示されるソースコード変換方法を用いて良い。
 また、前記特許文献2によれば、変換ルールは、ソースコードを、前記ソースコードの記述言語に依存しない、汎化されたプログラム情報をもつ形式(汎化モデル)へと変換する実装-汎化変換ルールと、汎化モデルを抽象化する抽象化変換ルールと、抽象化された汎化モデルをモデルチェッカの記述言語へと変換する汎化-検査変換ルールに分類される。本発明においては、記号実行の対象を汎化モデルとする。
 即ち、本発明では以下の手順を実行する。(処理概要の説明)
 (1)実装―汎化変換ルールを用いて、ソースコードの内容を記号化して中間形式に変換し、と抽象化変換ルールを用いて抽象化を行って汎化モデルを生成する。(ソースコードの抽象化)
 (2)プログラム(ソースコード)のロジックに従って、上記(1)で生成した汎化モデルの中の変数を適宜置き換えることにより、汎化モデルの記号実行を行う。その際、ソースコードの判定文では、判定結果が仮に「真」の場合、及び「偽」の場合を想定して記号実行の処理を行う。
 (3)上記(2)の記号実行の結果を反映し抽象化変換ルールを用いて、上記(1)で生成した汎化モデルを更に抽象化し、汎化―検査変換ルールを用いて汎化モデルを変換して検査コードを生成する。(記号実行の結果に基づいた汎化モデルの抽象化)
 以下、図面を参照して本発明の実施形態について説明する。  
 (動作の説明)
 図1は、本発明のソースコード検査装置のシステム構成図である。図1に示すソースコード検査装置は、通常の計算機(処理装置)を用いて実現される。図11は、本発明のソースコード検査装置の動作フローである。
 本発明のソースコード検査装置は、検査プログラム006として実現され、メインメモリ002に格納される。検査の対象となるソースコード007と、ソースコードを変換するために用いる変換ルール008は、あらかじめファイル装置003などに記録される。キーボードやマウスなどの入力装置004から、検査するプログラム007の指定と、用いる変換ルール008の指定を行う(S11001)。中央処理装置001は、メインメモリ002中の検査プログラム006の指令を受け、ファイル装置003から検査対象となるソースコード007と変換ルール008を読みだす(S11002)。ついで、中央処理装置001は、変換ルール008の記述に基づく抽象化および記号実行およびモデル検査を実施する(S11003)。さらに中央処理装置001は、記号実行またはモデル検査またはそれらの両方による検査結果を、ディスプレイ等の出力装置005に表示する、もしくはファイル装置や記憶装置等に出力する(S11004)。
 図2は、本発明を構成するソースコード検査プログラムの構成の概要図である。本発明のソースコード検査プログラムは、ソースコード変換部201、記号実行部202、モデル検査部204からなる。
 図12は、本発明を構成するソースコード検査プログラム006の概要動作フローである。まず、ファイル装置003に格納されたソースコード007と変換ルール集合008をソースコード変換部201が読みとる(S1201)。ここで、読みとるソースコードと変換ルール集合は、図1における入力装置004から指示するものとする。ソースコード変換部201は、変換ルール集合008の記述に従い、ソースコード007を変換する(S1202)。ソースコード変換部201の動作は、特許文献2に準ずるものとする。
 ついで、ソースコード変換部201による変換結果を記号実行部202に受け渡し、記号実行部202は記号実行を実行し結果をソースコード変換部201に返す(S1203)。ここで、ソースコード変換部201と記号実行部202との間でのデータの受け渡しは、メインメモリ002を用いた受け渡しでも、ファイル装置003を用いた受け渡しでも良い。
 ついで、ソースコード変換部201は記号実行の結果を受け取り、変換ルールに従って更に変換処理を行い、ソースコード変換部201の変換結果である検査コード203を出力する(S1204)。出力先はファイル装置003であってもメインメモリ002であってもよい。
 ついで、モデル検査部204は検査コード203を読みとり、モデル検査を実行し、モデル検査の結果205を出力する(S1205)。
 図3は、本発明を構成するソースコード検査プログラム006のより詳細な構成図である。本発明のソースコード検査プログラム006は、ソースコード変換部201、記号実行部202、モデル検査部204からなる。さらに、ソースコード変換部201は、入力部3101、変換処理部3102、出力部3103、記憶部3104、記号実行インタフェース部3015からなる。さらに、記号実行部202は、モデルインタフェース部3201と、記号実行処理部3202からなる。ここで記号実行インタフェース部3105と、モデルインタフェース部3201とは、変換処理部3102と記号実行処理部3202との間での情報の受け渡しを行う目的を果たす限り、独立した部位ではなく一体不可分な部位として実装してもよい。
 図13は、本発明を構成するソースコード検査プログラム006の動作フローである。
 まず、ファイル装置003に格納された変換ルール集合008は記憶部3104に記憶される(S1301)。つぎに入力部3101によりファイル装置003に格納された検査対象となるソースコード007が記憶部3104に読みとられる(S1302)。なお、これらの順序は逆でもよい。ステップS1301,S1302は図12のステップS1201に対応する。
 次に変換処理部3102は、記憶部3104に格納された変換ルール集合008を用いてソースコードの変換処理を行う(S1303)。ここで、入力部3101および変換処理部3102の動作は、特許文献2に準ずるものとする。ついで、変換処理部3102による変換結果は、記号実行インタフェース部3105およびモデルインタフェース部3201を介して、記号実行処理部3202に受け渡す(S1304)。ステップS1303,S1304は図12のステップS1202に対応する。
 記号実行処理部3202は、記号実行を実行し(S1305)、当該記号実行の結果をモデルインタフェース部3201と記号実行インタフェース部3105を介してソースコード変換部201に返す(S1306)。ここで、変換処理部3102から記号実行部3202に受け渡される変換結果は、一部の変換ルールによる変換を行った中間結果であってよい。すなわち、特許文献2に示すところの、汎化モデルであってよい。また、ソースコード変換部201と記号実行部202との間でのデータの受け渡しは、メインメモリ002を用いた受け渡しでも、ファイル装置003を用いた受け渡しでも良い。ステップS1305,S1306は図12のステップS1203に対応する。
 ついで、変換処理部3102は、記号実行の結果を記号実行インタフェース部3105より受け取り、変換ルールに従って更に変換処理を行う(S1307)。ついで、出力部3103は変換処理部3102の変換結果である検査コード203を出力する(S1308)。出力先はファイル装置003であってもメインメモリ002であってもよい。ステップS1307,S1308は図12のステップS1204に対応する。
 ついで、モデル検査部204は、検査コードを読みとり、モデル検査を実行し、モデル検査の結果205を出力する(S1309)。ステップS1309は図12のステップS1205に対応する。
 本発明によれば、検査対象とするソースコードを変換した汎化モデルを対象として記号実行を行う。特許文献2によれば、汎化モデルはソースコードを特定のプログラム言語に依存しない中間言語に変換したものであることから、検査対象となるソースコードのプログラム言語が変更になったとしても、記号実行部202は同一のものを使用することができる。また、変換ルールを定義することでプログラム言語に依存して記号実行が難しいプログラム構造を、記号実行しやすいプログラム構造に変換することができる。
 また、本発明によれば、記号実行の結果を用いて、汎化モデルを更に変換する。このとき、記号実行の結果として得られるパスコンディションを参照し、後段のモデル検査に必要のない部分を汎化モデルから省略することができる。換言すれば、変数の値に関する検査をしたい場合、記号実行により得られるパスコンディションが変数の値を充足するか否かをチェックして検査に不要な分岐を削除する変換ルールを用いて、変換処理部3102において汎化モデルにおける検査に不要な分岐を削除した後、検査コードを出力し、モデル検査部204においてモデル検査を実行することができる。これにより、モデル検査に係る時間計算量と空間計算量を削減することができる。
 さらに、本発明によれば、相互作用を持つ複数のプログラムからなるシステムの検査において、検査したい性質が出現する主たるソースコードを変換して得られる汎化モデルに対して記号実行を行って、検査したい性質が出現する条件を得たのち、主たるソースコードと相互作用を持つ他の従たるソースコードとを合成してモデル検査を行うことができる。これにより、記号実行が特定の入力に対して行われ、対応する結果が得られることは検査できるものの、当該の入力が他のソフトウェアもしくは装置との相互作用において存在しうるかどうかについては検査できないという課題に対して、モデル検査を用いることで実際に相互作用が存在するか否かを検査することができる。ここで、従たるソースコードは複数であってもよい。また、従たるソースコードの一部が、ソフトウェアではない主たるソフトウェアに作用する装置の動作を模擬するソースコードであってもよい。
 (処理フローの説明)
 次に、本発明の第1の実施例になるソースコード検査プログラム006を、図4と図6と図7とを参照しながら説明する。
 図4は、本発明に係るソースコード検査プログラム006のうち、ソースコード変換部201および記号実行部202の構成例を示す図である。図6は、ソースコード変換部201と記号実行部202に関するデータフローを示す図である。図7は記号実行部202の構成の詳細を示す図である。
 図4に示すように、入力部3101は、ソースコード入力部3110と、変換ルール入力部3111とを有する。変換処理部3102は、モデル構築部3121、実装-汎化モデル変換部3122、抽象化モデル変換部3123、及び、汎化-検査モデル変換部3124を備えている。出力部3103は、検査コード書出し部3131を有する。記憶部3104は、変換ルールデータベース3141、メタモデルデータベース3142、および、書出しルールデータベース3143を有する。記号実行インタフェース部3105は、汎化モデル出力部3151と記号実行結果入力部3152とを備える。
 入力部3101は、ユーザによって入力されるデータを受付け、入力されたデータを変換処理部3102へと供給する処理を行う。入力部3101は、ソースコード007に関する情報と、いくつかに分割された処理のそれぞれに適用する複数の変換ルール、すなわち「変換ルール集合」008に関する情報とを受付け、変換処理部3102へ供給する。ある実施形態においては、入力部3101は、ユーザによる、変換処理部の駆動や制御、出力部の駆動や制御、記号実行部の駆動や制御、に関する指示を受け付けてもよい。変換処理部3102は、たとえば特許文献2に記載されているソースコード変換装置の変換処理部を用いてよい。
 変換処理部3102は、入力部3101より、ソースコード007の情報601と、ソースコード007に適用すべき変換ルール集合008の情報とを供給され、ソースコード情報601を、変換ルール集合008により変換する処理を行い、変換結果の情報を、出力部3103に供給する。他の実施形態においては、入力部3101より供給される変換ルール集合008に関する情報は、記憶部に格納された変換ルールを指し示す識別情報のみが含まれていて、変換ルール集合008の実体を、前記識別情報を用いて記憶部3104より取り出し、変換に用いてもよい。変換処理部3102は、モデル構築部3121と、実装-汎化モデル変換部3122と、抽象化モデル変換部3123と、汎化-検査モデル変換部3124とを有する。
 図6に示すように、本実施形態において、変換処理部3102は、メタモデルと、変換ルールを用いたモデル変換により、ソースコード情報601を、検査モデル605へと変換する。メタ・実装モデル620と、メタ・汎化モデル621と、メタ・検査モデル622とは、例えば、非特許文献3に記載のMOFにて記述する。また、例えば、非特許文献4に記載されているQVTにて、実装-汎化変換ルール602と、抽象化変換ルール603と、汎化-検査変換ルール604とを記述し、モデルの変換を行う。前記変換は、既に例示した方法の他のモデル変換方法でも良く、また、複数の方法を混在させてもよい。
 モデル構築部3121は、ソースコード入力部3110からソースコード情報601を受け取り、実装モデル606へと変換する。実装モデル606の形式は、そのメタモデルであるメタ・実装モデル620により、定義される。実装モデル606は、本発明の効果を最大限に得るためには、ソースコード情報601と相互に変換するのに必要十分な情報を持つことが望ましいが、ある実施形態によっては、検査コードを出力するという目的を逸しない程度にて、情報の省略や、追加があってもかまわない。
 実装-汎化モデル変換部3122は、実装-汎化変換ルール602と、メタ・実装モデル620と、メタ・汎化モデル621とを用いて、実装モデル606を、汎化モデル607へと、変換する。汎化モデルは、複数のプログラミング言語における構造や処理を表現可能なデータ構造をもつ。例えば、汎化モデル中では、ソースコード007におけるIf文とSwitch文とを区別せず、選択的実行文として表現する。
 他の実施形態においては、実装モデル606を、汎化モデル607へと変換する際、実装-汎化変換ルール602のみを用いることもあり得る。また、他の実施形態において、実装-汎化変換ルール602が、複数の変換ルールを含む場合には、複数の変換ルールを統合して1つの変換ルールとし、実装モデル606から汎化モデル607への変換に利用する方法があり得る。また、ある実施形態において、実装-汎化変換ルール602が、複数の変換ルールを含む場合には、変換処理を複数回繰り返すことで、実装モデル606から汎化モデル607への変換を行う手順があり得る。
 抽象化モデル変換部3123は、抽象化変換ルール603と、メタ・汎化モデル621とを用いて、汎化モデル607の抽象化を行う。抽象化の例としては、選択文における条件式を、恒真、もしくは恒偽、もしくは非決定的な選択で置き換える方法があり得る。
 他の実施形態においては、汎化モデル607を抽象化する際、抽象化変換ルール603のみを用いることもあり得る。また、他の実施形態において、抽象化変換ルール603が、複数の変換ルールを含む場合には、複数の変換ルールを統合して1つの変換ルールとし、汎化モデル607の抽象化に用いる方法があり得る。また、他の実施形態において、抽象化変換ルール603が、複数の変換ルールを含む場合には、変換処理を複数回繰り返すことで、汎化モデル607の変換を行う手順があり得る。
 汎化-検査モデル変換部3124は、汎化-検査変換ルール604と、メタ・汎化モデル621と、メタ・検査モデル622とを用いて、汎化モデル607を、検査モデル605へと、変換する。例えば、検査コード203がPromela形式である場合、汎化モデルにおいて選択的実行文として表現された要素は、検査モデルにおいてはIF文として表現される。
 他の実施形態においては、汎化モデル607を、検査モデル605へと変換する際、汎化-検査変換ルール604のみを用いることもあり得る。また、他の実施形態において、汎化-検査変換ルール604が、複数の変換ルールを含む場合には、複数の変換ルールを統合して1つの変換ルールとし、汎化モデル607から検査モデル605への変換に利用する方法があり得る。また、他の実施形態において、汎化-検査変換ルール604が、複数の変換ルールを含む場合には、変換処理を複数回繰り返すことで、汎化モデル607から検査モデル605への変換を行う手順があり得る。
 記号実行インタフェース部3105は、汎化モデル出力部3151と、記号実行結果入力部3152を有する。汎化モデル出力部3152は、変換処理部3102から汎化モデルを供給され、汎化モデル情報608を記号実行部202に供給する役割と、記号実行部202における記号実行結果情報610を供給され、変換処理部3102に前記記号実行結果情報610を供給する役割を果たす。変換処理部3102から供給される汎化モデル情報608と、記号実行部に供給する汎化モデル607とは、同一の情報を有しても、記号実行に必要な情報のみを有してもよい。また、変換処理部3102から供給された汎化モデルの実装形態と、記号実行インタフェース部3105が供給する汎化モデルの実装形態が異なっていてもよい。
 出力部3103は、変換処理部3102より供給された、変換結果の情報を用いて、検査コード203を出力する。ある実施形態においては、検査コード203の出力に際して、例えばモデルチェッカの記述言語の文法情報などの情報を記憶部から供給されてもよい。
 検査コード書出し部3131は、メタ・検査モデル622と、記憶部3104の書出しルールデータベース3143から取得した検査コード書出しルール611とを用いて、検査モデル605を検査コード203へと変換する。たとえば、非特許文献5に記載される方法にて、検査コード書出しルール611を記述し、検査モデル605から、検査コード203への変換を行う。他の実施例においては、これに限らず、検査モデル605を、検査に利用するモデルチェッカの記述形式へと変換する任意の方法でもよい。検査コード203は、例えば、モデルチェッカとしてSPINを用いる場合には、SPINの入力言語である、Promelaにより記述される。
 記憶部3104において、変換ルールデータベース3141と、メタモデルデータベース3142と、書出しルールデータベース3143のそれぞれは、例えば、関係データベース、もしくは、階層型データベースなどの、コンピュータ上にて実現される任意のデータ格納方式で実現される。変換ルールデータベース3141と、メタモデルデータベース3142と、書出しルールデータベース3143と、は互いに同一の方式で実現されている必要性は無く、互いに異なる方式で実現されていてもよい。また、変換ルールデータベース3141と、メタモデルデータベース3142と、書出しルールデータベース3143と、のそれぞれは、単一の方式で実現されている必要性は無く、例えば、保有すべき情報の一部を関係データベースに格納し、保有すべき情報の一部を、発明を実現するコンピュータプログラム中に組込むなど、それぞれ異なる方式の組み合わせで実現されていてもよい。
 記憶部3104は、入力部3101と、変換処理部3102と、出力部3103とが、それぞれの処理を行うのに必要な情報を供給する。例えば、記憶部3104は、変換ルールに関する情報と、メタモデルに関する情報と、モデルチェッカの記述言語の文法に関する情報とを格納する。
 変換ルールデータベース3141は、既に述べたとおり、変換ルールを、メタデータとともに保有する。前記メタデータは、変換ルールを選択するためのものであり、実装-汎化変換ルール602と、抽象化変換ルール603と、汎化-検査変換ルール604の、それぞれ異なる情報を持つ方法があり得る。実装-汎化変換ルール602のメタデータは、例えば、変換元ソースコードの記述言語の種類があり得る。抽象化変換ルール603のメタデータは、例えば、抽象化を分かりやすく端的に表現した名前、簡単な説明、「データの抽象化」、「処理の抽象化」などの抽象化の種別、自然語もしくはアルファベットや数値で表現された抽象化による状態数削減効果、自然語もしくはアルファベットや数値で表現された抽象化による性質への影響、抽象化の適用できるソフトウェアのドメイン、があり得る。汎化-検査変換ルール604メタデータは、例えば、検査に使用するモデルチェッカを指し示す名前があり得る。
 図7に示すように、記号実行部202は、モデルインタフェース部3201と、記号実行処理部3202とからなる。モデルインタフェース部3201は、ソースコード変換部201の記号実行インタフェース3105が供給する汎化モデル情報608を入力とし、記号実行処理部3202に前記汎化モデル情報701を供給する役割と、記号実行処理部3202の処理結果情報702を入力とし、ソースコード変換部201の記号実行インタフェース部3105に処理結果610を供給する役割をもつ。
 記号実行処理部3202は、モデルインタフェース部3201より供給された汎化モデル情報701を入力とし、記号実行処理を実行し、記号実行の結果をモデルインタフェース部3201に供給する。記号実行処理とは、たとえば非特許文献1に示される処理を実行する。ここで、記号実行とは、プログラム(ソースコード)のロジックに従って、ソースコードの中の変数を適宜置き換えることにより、あたかもプログラムが実行されたかのような処理を行うことであり、特に、ソースコードの判定文では、判定結果が仮に「真」の場合、及び「偽」の場合を想定してこの記号実行の処理が行われる。
 他の実施例においては、記号実行インタフェース部3105とモデルインタフェース部3201とは、不可分な様態で実装され、変換処理部3102から供給された汎化モデル607を、記号実行処理部3202に供給し、記号実行部202から供給された記号実行結果3212を変換処理部3102に供給してもよい。
 以降、入力部3101、変換処理部3102、記憶部3104、出力部3103の詳細な動作は、たとえば特許文献2の実施例に準ずる場合を例として、記号実行インタフェース部3105、モデルインタフェース部3201、記号実行処理部3202の詳細について説明する。
 まず、本実施例におけるソースコード変換部201が実行するソースコード変換プログラムの処理手順を、図14を参照しながら説明する。
 汎化モデル出力部3151は、実装-汎化モデル変換部3122が変換した結果である汎化モデル607を入力とする(S1401)。次に、汎化モデル出力部3151は、記憶部3104に記憶されているメタモデルデータベース3142から、前記汎化モデルを定義するメタ汎化モデル621を読みだす。汎化モデル出力部3151は、汎化モデル607の前記メタ汎化モデル621を参照し、前記汎化モデル607を記号実行するためのモデル情報608を生成する(S1402)。なお、前記汎化モデルの入力と、汎化モデルの前記メタモデルの読みだしは、順序が逆になってもよい。
 ついで、汎化モデル出力部3151は、汎化モデル情報608をモデルインタフェース部3201の汎化モデル入力部3211に受け渡す(S1403)。汎化モデル情報608は、計算機可読な表現形式、たとえば、非特許文献5に示されるXML形式を用いて表現することができる。他の表現形式でもよい。また、記号実行インタフェース部3105と、汎化モデル入力部3211との間での、汎化モデルの受け渡しは、メモリ領域を介しても、通信路を介しても、ファイルシステムを介しても、他の任意の方法であってもよい。
 つぎに、モデルインタフェース部3201の汎化モデル入力部3211は、受け渡された汎化モデル情報608を記号処理部3202に渡す(S1404)。
 ついで、汎化モデル入力部3211は、汎化モデル情報608に含まれる情報のうち、記号実行処理部3202が利用する情報を抽出する(S1405)。記号実行処理部3202が利用する情報とは、少なくとも制御フローグラフを含む。詳しくは、非特許文献1に記載があるが、たとえば図9に示すグラフに関する情報を含む。
 つぎに、汎化モデル入力部3211は、前記抽出した情報を、記号実行処理部3202に受け渡す(S1406)。前記抽出した情報は、計算機可読な表現形式、たとえば、非特許文献5に示されるXML形式を用いて表現することができる。他の表現形式でもよい。また、前記抽出した情報の受け渡しは、メモリ領域を介しても、通信路を介しても、ファイルシステムを介しても、他の任意の方法であってもよい。
 つぎに、記号実行処理部3202は、入力された情報を入力し、記号実行をおこなう。(S1407)。たとえば、図9に制御フローグラフが入力である場合の例を示す。記号実行処理部3202は、制御フローグラフの制御開始位置、すなわち図9の例で言えば白丸900から順に、グラフの接続関係を順にたどりながら、図10に模式的に示す記号実行ツリーを生成する。たとえば、図9の例を用いて説明すると、まずソースコード007に含まれる各変数に対して、初期の値を示す記号を割り当てる。図10の例では、変数xの初期値を記号X、変数yの初期値を記号Y、変数zの初期値を記号Zとして割り当てる(1001)。割り当てる記号は、記号実行処理部3202が無作為もしくは変数名を変形して自動的に決定してもよい。ある実施の形態では、ソースコード検査装置の使用者が初期の記号を入力部から入力してもよい。
 ついで、図9のノード901は条件文であるので、ノード901に対応したエッジ1002とエッジ1003を生成する。エッジ1002はノード901の条件式が真になる場合、エッジ1003はノード901の条件式が偽になる場合を意味する。ついで、図9のノード903に対して、ノード903はノード902の条件式が真となる場合を意味するため、図10のエッジ1002に続くエッジ1004を生成する。
 さらに、ノード903とノード904とに示される代入文を、ノード1001に適用した場合の各変数の値を記号的に計算する。エッジ1004の上段が前記計算の結果を示す。同時に、ノード1004の値となるのは、エッジ1002の条件が成立する場合であるので、ノード1004のパスコンディションとして、エッジ1002の条件を加える。
 ここで、ノード903とノード904との間に分岐が存在しないため、両ノードの代入を順に行った結果を一度にノード1004に示しているが、ノード903の計算とノード904の計算とを独立して行っても構わない。
 以降、図9の制御フローグラフを順にたどりながら記号的な計算およびパスコンディションの決定を繰り返すことで、図10に模式的に示す記号実行結果を得られる。なお、図9の制御フローグラフを順にたどる際には、深さ優先探索を用いても、幅優先探索を用いても良い。記号実行処理部3202は、記号実行結果情報702を、記号実行結果出力部3212に受け渡す。記号実行結果情報の例は、たとえば図10に模式的に示すグラフである。
 記号実行結果出力部3212は、前記記号実行結果情報610を、記号実行結果入力部3152に受け渡す(S1408)。前記記号実行結果情報610は、軽算機可読な表現形式、たとえば、非特許文献5に示されるXML形式を用いて表現することができる。他の表現形式でもよい。また、前記抽出した情報の受け渡しは、メモリ領域を介しても、通信路を介しても、ファイルシステムを介しても、他の任意の方法であってもよい。
 記号実行結果入力部3152は、受け入れた記号実行結果情報610を解釈し、抽象化モデル変換部3123に供給する(S1409)。
 抽象化モデル変換部3123は、記号実行結果情報610を入力し、変換ルールデータベース3141に含まれる抽象化変換ルール603に従って、汎化モデル607を変換する(S1410)。ここで、記号実行結果を用いた変換方法は、変換ルールとして記述することができる。
 ここで、図8に示すソースコードに対する汎化モデルに対して記号実行を行った結果が図10である場合を例に説明する。たとえば、検査したい前提条件として、変数xと変数yの値が異なる入力であって、ソースコードを実行した結果変数xと変数yの値が一致する場合という条件がある場合、図10の記号実行結果ツリーの末端を参照すると、ノード1005とノード1006とが前提条件を満たし、ノード1007は前提条件を満たさないことがわかる。すなわち、エッジ1003における[0<x]が偽の場合には、検査の前提条件を満たさない。そのため、これに対応するソースコードの、行番号001の分岐の一方(条件が偽)は消去するような汎化モデルの変換を考えることができる。以上に述べた変換を示すルールを変換ルールとして記述することができる。
 本実施例によれば、本発明のソースコード検査装置は、検査の対象たるソースコードを抽象化した上で、汎化モデルを対象とした記号実行を実施し、記号実行の結果を用いて汎化モデルを再度変換し抽象化することができる。これにより、具体的な値を考えることなくソースコードの実行を模擬した上で汎化モデルを抽象化し、再抽象化された前記汎化モデルに基づく検査モデルを出力することができる。検査部は、再抽象化を経た検査モデルをモデル検査技術に基づき検査することで、時間的および空間的に効率的に検査することができる。
 次に、本発明の第2の実施例になるソースコード検査プログラムおよびソースコード検査装置を、図15を参照しながら説明する。第2の実施例は、記号実行結果を汎用的な表現を用いて生成する点に特徴がある。
 図15によれば、メタモデルデータベース3142に、メタ制御フローモデル1501と、メタ記号実行結果モデル1502を有する。メタ制御フローモデル1501と、メタ記号実行結果モデル1502は、たとえば特許文献2に示すメタ実装モデル、メタ汎化モデル、メタ検査モデルと同様に、非特許文献3に示されるMOF(Model Object Facility、モデルの構文を定義する技術)を用いて実装することができる。すなわち、MOFを用いて、メタ制御フローモデル1501と、メタ記号実行結果モデル1502の構文および意味論を定義する。
 汎化モデル入力部3211は、メタ汎化モデル621を参照して汎化モデル608を構文解析したのち、汎化モデル608から制御フロー情報を抽出し、メタ制御フローモデル1501を参照してメタ制御フローモデル1501に従った汎化モデル情報701を生成し、記号実行処理部3202に受け渡す。記号実行処理部3202は、メタ制御フローモデル1501を参照し、受け取った汎化モデル情報701を構文解析し、記号実行を実施することができる。
 また、記号実行処理部3202は、メタ記号実行結果モデル1502を参照し、前記メタ記号実行結果モデル1502に従って記号実行結果情報702を生成し、記号実行結果出力部3212は、生成された前記記号実行結果情報610を記号実行結果入力部3152に引き渡す。記号実行結果情報610は、記号実行結果入力部3152から抽象化モデル変換部3123に引き渡されるが、抽象化モデル変換部3123は、メタ記号実行結果モデル1502を参照して記号実行結果情報610を構文解析することができる。また、予め用意する変換ルールには、メタ記号実行結果モデル1502で定義された記号実行結果情報610の構文に従って、変換ルールを記述しておくことができる。
 本実施例によれば、本発明に係るソースコード検査装置が扱うデータの構文と意味論を、メタモデルデータベースを用いて統合的に管理でき、統一された記法を用いて、ソースコード検査装置を構成することができる。これにより、変換ルールの実装をはじめとするソースコード検査装置を稼働するために必要なデータの記載が容易かつ効率的になる。
 次に、本発明の第3の実施例になるソースコード検査プログラムおよびソースコード検査装置について説明する。第3の実施例では、変換ルールを具体的に説明している。
 実施例2において、変換ルールとして、記号実行のための前処理を記述し、記号実行を容易にすることができる。たとえば、変換ルールとして、実装モデもしくは汎化モデルから、図15に示したような制御フローグラフを作成するために必要な情報、すなわち、命令、命令と命令との間の順序関係、制御の分岐、分岐条件、を含む情報を抽出する変換ルールを記述する。
 また、変換ルールとして、ソースコードに含まれる関数呼び出しを展開し1つの関数に統合する変換ルール、もしくはソースコードに含まれる繰り返し処理を有限回数で終了するように繰り返し条件を変更する変換ルール、ソースコードに含まれる動的なメモリ確保、たとえばC言語であればmalloc関数の呼び出しを予め確保した固定的なメモリの利用に変換するルールを変換ルールとして定義することができる。
 これにより、記号実行が難しい、関数呼び出し、繰り返し、動的なメモリ確保について、記号実行を可能とする。また、前記変換ルールにより、検査対象ソースコードの振舞いと変換後の汎化モデルの振舞いが一致しない場合があるが、特許文献2で示されているように、使用者が意図した範囲で振舞いを変えることは、本発明における
 次に、本発明の第4の実施例になるソースコード検査プログラムおよびソースコード検査装置を、図16を参照しながら説明する。第4の実施例では、直接検査の対象となるソースコードである主コードだけでなく、主コードに関連する従コードも検査対象とする場合を説明する。
 本実施例においては、検査対象となるソースコードが複数、すなわち検査の対象となるソースコード集合があるものとし、前記ソースコード集合に含まれるソースコードには、主たるソースコード1601と、従たるソースコード1602とが指定されるものとする。主たるソースコードとは、検査したい特性が発現するソースコードである。
 たとえば、ソースコードに含まれる特定の関数の計算結果が、特定の値の範囲内であることを検査したい場合、前記関数が含まれるソースコードを主たるソースコードと呼び、それ以外のソースコードを従たるソースコードと呼ぶ。
 また、主たるソースコードは、あらかじめ与えられるソースコードのファイル単位である必要はなく、前記関数を含む部分に限定した範囲を主たるソースコードとしてもよい。その場合、当該ソースコードファイルに含まれる主たるソースコード以外の部分は、従たるソースコードとする。あるいは、当該関数と関係する他の関数、たとえば当該関数を呼び出す関数と呼び出される関数とを、当該関数を含む部分を主たるソースコードとしてもよい。
 さらに、従たるソースコードとして、検査したいソフトウェアを実装するソースコードだけでなく、当該ソフトウェアが動作するにあたり関連するハードウェアの動作を模擬するソフトウェアのソースコードが含まれていてもよい。主たるソースコードと従たるソースコードとの指定は、図16に示すように、ファイル装置003に格納する際に区別してもよい。
 ある実施の形態では、ファイル装置003上ではソースコードの区別はせず、入力部3101によるソースコードの読込みを行ったのち、入力装置004を用いて、ソースコード検査装置の使用者が指定してもよい。
 本実施例によれば、主たるソースコード1601を実施例1もしくは実施例2もしくは実施例3に示した、ソースコード変換部201および記号実行部202による処理対象とする。その結果、検査コード203が得られる。従たるソースコードは、ソースコード変換部1611を用いて、たとえば特許文献2に示されるソースコード変換の対象とする。その結果、検査コード1612を得られる。前記検査コード203と前記検査コード1612をモデル検査部204へ受け渡し、モデル検査を実行する。
 ここで、主たるソースコード1601に対するソースコード変換部201と従たるソースコードに対するソースコード変換部1611は、独立した部位として実装してもよいが、唯一のソースコード変換部を実装し、主たるソースコード1610を入力した場合と、従たるソースコード1602を入力した場合とで、前記唯一のソースコード変換部がソースコードの種別に応じて動作を変更してもよい。すなわち、主たるソースコードを入力した場合は、記号実行部202へ記号実行用情報を受け渡し、従たるソースコードを入力した場合は、記号実行部202への記号実行用情報の受け渡しをしないでもよい。
 本実施例により、主たるソースコードに対する記号実行により、ソースコード変換部201は、主たるソースコードに含まれるプログラムのうちの特定の部分を検査対象として抽出をして検査コード203を生成し、これと従たるソースコード1602から生成された検査コード1612との相互作用を考慮した検査をモデル検査部204においてモデル検査を用いて検査できる。これにより、記号実行では複数の動作主体間の相互作用を考慮できない点をモデル検査によって解決し、かつ、主たるソースコードに対する記号実行結果を用いたソースコード変換部201による抽象化により、モデル検査部におけるモデル検査の空間的または時間的な検査に係るリソースを削減することができる。以上により、状態爆発を防止しつつ、複数のソースコードに対するソースコード検査装置を実現できる。
001:中央処理装置、002:メインメモリ、003:ファイル装置、004:入力装置、005:出力装置、006:ソースコード検査プログラム、007:検査対象ソースコード、008:変換ルール、201:ソースコード変換部、202:記号実行部、203:検査コード、204:モデル検査部、205:検査結果、3101:入力部、3102:変換処理部、3103:出力部、3104:記憶部、3105:記号実行インタフェース部、3110:ソースコード入力部、3111:変換ルール入力部、3121:モデル構築部、3122:実装-汎化モデル変換部、3123:抽象化モデル変換部、3124:汎化-検査モデル変換部、3151:汎化モデル出力部、3152:記号実行結果入力部、3201:モデルインタフェース部、3202:記号実行処理部、3211:汎化モデル入力部、3212:記号時刻結果出力部、501:ソースコード、502:変換ルール集合、5000:ソースコード変換装置、5100:入力部、5200:変換処理部、5300:出力部、5400:記憶部、601:ソースコード情報、602:実装-汎化変換ルール、603:抽象化変換ルール、604:汎化-検査変換ルール、605:検査モデル、606:実装モデル、607:汎化モデル、608:汎化モデル情報、610:記号実行結果情報、620:メタ実装モデル、621:メタ汎化モデル、622:メタ検査モデル、701:汎化モデル情報、702:記号実行結果情報、801:ソースコード、900:制御フローグラフ、1001:記号実行結果グラフ、1501:メタ制御フローグラフ、1502:メタ記号実行結果モデル、1611:ソースコード変換部、1612:検査コード

Claims (11)

  1.  計算機を用いてソースコードを検査するソースコード検査方法であって、
     ソフトウェアのソースコード、第1、第2、第3及び第4の変換ルールを入力し、
     前記ソースコードを、前記第1及び第2の変換ルールにより抽象化し、
     前記抽象化されたソースコードを記号実行し、
     前記記号実行の結果、及び前記第4の変換ルールにより、前記抽象化されたソースコードを再抽象化し、前記第4の変換ルールにより、前記再抽象化されたソースコードを検証ツールの入力言語で記述された検査コードに変換する、
    ことを特徴とするソースコード検査方法。
  2.  前記抽象化のステップにおいて、
     前記第1の変換ルールは、ソースコードを特定のプログラミング言語に依存しない形式である中間形式へと変換する変換ルールであり、
     前記第2の変換ルールは、前記中間形式に対して抽象化処理を行うための変換ルールであり、
     前記第3の変換ルールは,前記抽象化された中間形式を、前記記号実行の結果に基づいて再抽象化処理を行うための変換ルールであり、
     前記第1変換ルールを用いて、前記ソフトウェアのソースコードを、前記中間形式へと変換し、
     前記第2変換ルールを用いて、前記中間形式で表現された前記ソフトウェアを抽象化し、
     前記第3変換ルールを用いて、前記抽象化された前記ソフトウェアを、前記記号実行結果に基づいて再抽象化する、
    ことを特徴とする請求項1記載のソースコード検査方法。
  3.  前記変換ステップにおいて、
     前記第4の変換ルールは、前記中間形式から前記検査コードに変換する変換ルールであり、
     前記第4変換ルールを用いて、前記再抽象化された中間形式を検証ツールの入力言語で記述された検証用コードに変換する、ことを特徴とする請求項1記載のソースコード検査方法。
  4.  前記第2変換ルールは、
     前記中間形式に含まれる動的な記憶領域確保を行う命令を、固定的な記憶領域確保を行う命令に変換する変換ルール、
     前記中間形式に含まれる繰り返しを行う命令を、固定回数の繰り返しを行う命令に変換する変換ルール、及び
     前記中間形式に含まれる関数呼び出しを行う命令を、呼び出される関数の内容に置き換える変換ルール、の少なくとも1つを含むことを特徴とする請求項2記載のソースコード検査方法。
  5.  計算機で読み取り可能な記憶媒体であって、請求項1に記載のソースコード検査方法を実行するためのプログラムを格納したことを特徴とする記憶媒体。
  6.  ソースコードを検査する装置であって、
     ソフトウェアのソースコード、第1、第2、第3及び第4の変換ルールを入力する手段、
     前記ソースコードを、前記第1及び第2の変換ルールにより抽象化する手段、
     前記抽象化されたソースコードを記号実行する手段、及び
     前記記号実行の結果、及び前記第3の変換ルールにより、前記抽象化されたソースコードを再抽象化し、前記第4の変換ルールにより、検証ツールの入力言語で記述された検査コードに変換する手段、
    を有することを特徴とするソースコード検査装置。
  7.  前記抽象化する手段において、
     前記第1の変換ルールは、ソースコードを特定のプログラミング言語に依存しない形式である中間形式へと変換する変換ルールであり、
     前記第2の変換ルールは、前記中間形式に対して抽象化処理を行うための変換ルールであり、
     前記第3の変換ルールは,前記抽象化された中間形式を、前記記号実行の結果に基づいて再抽象化処理を行うための変換ルールであり、 前記第1変換ルールを用いて、前記ソフトウェアのソースコードを、前記中間形式へと変換し、
     前記第2変換ルールを用いて、前記中間形式で表現された前記ソフトウェアを抽象化し、
     前記第3変換ルールを用いて、前記抽象化された前記ソフトウェアを、前記記号実行結果に基づいて再抽象化する、
    ことを特徴とする請求項6記載のソースコード検査装置。
  8.  前記変換する手段において、
     前記第4の変換ルールは、前記中間形式から前記検査コードに変換する変換ルールであり、
     前記第4変換ルールを用いて、前記再抽象化された中間形式を検証ツールの入力言語で記述された検証用コードに変換する、ことを特徴とする請求項6記載のソースコード検査装置。
  9.  前記第2変換ルールは、
     前記中間形式に含まれる動的な記憶領域確保を行う命令を、固定的な記憶領域確保を行う命令に変換する変換ルール、
     前記中間形式に含まれる繰り返しを行う命令を、固定回数の繰り返しを行う命令に変換する変換ルール、及び
     前記中間形式に含まれる関数呼び出しを行う命令を、呼び出される関数の内容に置き換える変換ルール、の少なくとも1つを含むことを特徴とする請求項7記載のソースコード検査装置。
  10.  計算機を用いてソースコードを検査するソースコード検査方法であって、
     ソフトウェアの検査の対象となる主たるソースコード、前記主たるソースコードと関連する従たるソースコード、第1、第2、第3及び第4の変換ルールを入力し、
     前記主たるソースコード及び前記従たるソースコードを、前記第1及び第2の変換ルールにより抽象化し、
     前記抽象化された主たるソースコードを記号実行し、
     前記記号実行の結果、及び前記第3の変換ルールにより、前記抽象化された主たるソースコードを再抽象化し、
     前記再抽象化された主たるソースコードと、前記抽象化された従たるソースコードを統合し、 前記第4の変換ルールにより、前記統合されたソースコードを検証ツールの入力言語で記述された検査コードに変換する、ことを特徴とするソースコード検査方法。
  11.  ソースコードを検査する装置であって、
     ソフトウェアの検査の対象となる主たるソースコード、前記主たるソースコードと関連する従たるソースコード、第1、第2、第3及び第4の変換ルールを入力する手段、
     前記主たるソースコード及び前記従たるソースコードを、前記第1及び第2の変換ルールにより抽象化する手段、
     前記抽象化された主たるソースコードを記号実行する手段、
     前記記号実行の結果、及び前記第3の変換ルールにより、前記抽象化された主たるソースコードを再抽象化する手段、
     前記再抽象化された主たるソースコードと、前記抽象化された従たるソースコードを統合する手段、及び
     第4の変換ルールにより、前記統合されたソースコードを検証ツールの入力言語で記述された検査コードに変換する手段、を有することを特徴とするソースコード検査装置。
PCT/JP2012/061372 2012-04-27 2012-04-27 ソースコード検査方法及び装置 WO2013161057A1 (ja)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/JP2012/061372 WO2013161057A1 (ja) 2012-04-27 2012-04-27 ソースコード検査方法及び装置

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/JP2012/061372 WO2013161057A1 (ja) 2012-04-27 2012-04-27 ソースコード検査方法及び装置

Publications (1)

Publication Number Publication Date
WO2013161057A1 true WO2013161057A1 (ja) 2013-10-31

Family

ID=49482423

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2012/061372 WO2013161057A1 (ja) 2012-04-27 2012-04-27 ソースコード検査方法及び装置

Country Status (1)

Country Link
WO (1) WO2013161057A1 (ja)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2020038521A (ja) * 2018-09-05 2020-03-12 株式会社日立製作所 ソースコード生成支援装置およびソースコード生成支援方法
CN111666206A (zh) * 2020-04-30 2020-09-15 北京百度网讯科技有限公司 变更代码的影响范围的获取方法、装置、设备及存储介质
US10915438B2 (en) 2017-02-17 2021-02-09 Mitsubishi Heavy Industries Engineering, Ltd. Software-testing device, software-testing system, software-testing method, and program

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012059026A (ja) * 2010-09-09 2012-03-22 Hitachi Ltd ソースコード変換方法およびソースコード変換プログラム

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012059026A (ja) * 2010-09-09 2012-03-22 Hitachi Ltd ソースコード変換方法およびソースコード変換プログラム

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
NAOYA HORI: "Improving Daikon's output with Automated Generation of Test Suites based on Invariant Coverage and Model Checking Techniques", LECTURE NOTE/SOFTWARE-GAKU 34 SOFTWARE KOGAKU NO KISO, vol. XV, 30 November 2008 (2008-11-30), pages 41 - 50 *
S.F. SIEGEL ET AL.: "Combining symbolic execution with model checking to verify parallel numerical programs", ACM TRANSACTIONS ON SOFTWARE ENGINEERING AND METHODOLOGY (TOSEM), vol. 17, no. ISS. 2, April 2008 (2008-04-01), pages 1 - 34 *
SHIN NAKAJIMA: "A Perspective on Model-Checking Methods from Software Engineering", DAI 22 KAI KAIRO TO SYSTEM KARUIZAWA WORKSHOP RONBUNSHU [CD-ROM], 20 April 2009 (2009-04-20), pages 252 - 257 *
SHIN NAKAJIMA: "Formal Methods as Software Engineering Tools", SOFTWARE ENGINEERING SAIZENSEN 2007, 30 September 2007 (2007-09-30), pages 27 - 48 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10915438B2 (en) 2017-02-17 2021-02-09 Mitsubishi Heavy Industries Engineering, Ltd. Software-testing device, software-testing system, software-testing method, and program
JP2020038521A (ja) * 2018-09-05 2020-03-12 株式会社日立製作所 ソースコード生成支援装置およびソースコード生成支援方法
CN111666206A (zh) * 2020-04-30 2020-09-15 北京百度网讯科技有限公司 变更代码的影响范围的获取方法、装置、设备及存储介质
CN111666206B (zh) * 2020-04-30 2023-12-22 北京百度网讯科技有限公司 变更代码的影响范围的获取方法、装置、设备及存储介质

Similar Documents

Publication Publication Date Title
JP5659238B2 (ja) ソースコード変換方法およびソースコード変換プログラム
JP6859449B2 (ja) テストケースを利用してテストを遂行する方法および装置
EP3745256B1 (en) External code integrations within a computing environment
US20130239098A1 (en) Source code conversion method and source code conversion program
US8448146B2 (en) Generation of functional tests for re-hosted applications
US8583414B1 (en) Mapping between code coverage and model coverage for a design
US6996517B1 (en) Performance technology infrastructure for modeling the performance of computer systems
US20130080993A1 (en) Embedded system performance
US9418230B2 (en) Automated tools for building secure software programs
CN109426615A (zh) 过程间的空指针解引用检测方法、系统、设备以及介质
KR20090071596A (ko) 모델 검사를 병용하기 위한 전이 시스템 생성 방법
Marko et al. Combining xtext and oslc for integrated model-based requirements engineering
CN110347588B (zh) 软件验证方法、装置、计算机设备和存储介质
WO2013161057A1 (ja) ソースコード検査方法及び装置
Silva et al. CPN simulation-based test case generation from controlled natural-language requirements
Iqbal et al. Exhaustive simulation and test generation using fuml activity diagrams
Murawski et al. A contextual equivalence checker for IMJ
Pettit et al. Modeling behavioral patterns of concurrent software architectures using Petri nets
Sani et al. Model transformation specification for automated formal verification
Nikiforova et al. Towards a Business Process Model-based Testing of Information Systems Functionality.
JP2011154568A (ja) 情報処理装置、プログラム検証方法およびプログラム
Weiß et al. Towards establishing formal verification and inductive code synthesis in the PLC domain
JP5736588B2 (ja) ソースコード変換方法及びソースコード変換プログラム
Bussenot et al. A domain specific test language for systems integration
CN118034661B (zh) 大语言模型智能任务应用系统

Legal Events

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

Ref document number: 12875482

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 12875482

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: JP