WO2023207973A1 - Compiler test method and apparatus, case generation method and apparatus, and instruction storage structure - Google Patents

Compiler test method and apparatus, case generation method and apparatus, and instruction storage structure Download PDF

Info

Publication number
WO2023207973A1
WO2023207973A1 PCT/CN2023/090577 CN2023090577W WO2023207973A1 WO 2023207973 A1 WO2023207973 A1 WO 2023207973A1 CN 2023090577 W CN2023090577 W CN 2023090577W WO 2023207973 A1 WO2023207973 A1 WO 2023207973A1
Authority
WO
WIPO (PCT)
Prior art keywords
test
instruction
data
compilation
instructions
Prior art date
Application number
PCT/CN2023/090577
Other languages
French (fr)
Chinese (zh)
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 上海商汤智能科技有限公司
Publication of WO2023207973A1 publication Critical patent/WO2023207973A1/en

Links

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/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis

Definitions

  • the present disclosure relates to the field of computer technology, and in particular, to a compiler testing method, a use case generation method, a device, a device, a storage medium, and a storage structure of test instructions.
  • Compilers are usually used to compile programs from one language into another language.
  • the accuracy of the compiler results is a prerequisite for ensuring the normal operation of the program. If the compiler function is abnormal, it will not only cause the program to not obtain the originally intended running results, but may even mislead the debugging (troubleshooting) of subsequent programs. Therefore, after developing a compiler, it is necessary to provide a solution that can test the compiler to detect abnormalities in the compiler in a timely manner.
  • the present disclosure provides a compiler testing method, use case generation method, device, equipment, storage medium and storage structure of test instructions.
  • a method for testing a compiler includes: constructing a test case based on data related to test instructions stored in an instruction database, and a reference compilation instruction corresponding to the test case. ;Use the compiler to be tested to compile the test case to obtain the target compilation instruction; based on the comparison result of the reference compilation instruction and the target compilation instruction, determine whether there is an exception in the compiler.
  • the test cases include functional test cases and/or stability test cases.
  • the functional test cases include a single test instruction for testing the function of the compiler; the stability test case It is spliced together from multiple test instructions and used to test the stability of the compiler.
  • the stability test case meets one or more of the following conditions: the compiler compiles the stability test case for longer than a preset time; the test instructions included in the stability test case The quantity is greater than the preset quantity; the data volume of the stability test case is greater than the preset data volume.
  • the test cases include functional test cases and stability test cases. Based on the comparison results of the reference compilation instructions corresponding to the test cases and the target compilation instructions, it is determined whether there is an abnormality in the compiler. , including: determining whether there is an abnormality in the function of the compiler based on the comparison result of the reference compilation instruction corresponding to the functional test case and the target compilation instruction corresponding to the functional test case; There is no abnormal situation. Based on the reference compilation instructions corresponding to the stability test case and the stability test case, the The comparison results of the target compilation instructions corresponding to the qualitative test cases are used to determine whether there are abnormalities in the stability of the compiler.
  • the test instruction includes multiple components, and the data related to the test instruction includes for one component among the multiple components, the characteristic data corresponding to the component and the characteristic data corresponding to The reference compiled data, the characteristic data corresponding to this component is stored in association with the characteristic data corresponding to the remaining components among the plurality of components except this component.
  • the component includes one or more of the following: instruction type, control domain, and instruction address, where the control domain is used to represent the control operations included in the test instruction.
  • the test cases include a plurality of functional test cases for testing the compiler function, the test cases are constructed based on the data related to the test instructions stored in the instruction database, and the test cases correspond to
  • the reference compilation instructions include: for one component among the plurality of components, a piece of target characteristic data corresponding to the component is determined from the remaining components among the plurality of components except the component.
  • Associated feature data stored in association with the target feature data; generating test instructions based on the target feature data and the associated feature data, and obtaining the test based on the reference compiled data corresponding to the target feature data and the reference compiled data corresponding to the associated feature data
  • the reference compilation instruction corresponding to the instruction; the test instruction is used as a functional test case, and the reference compilation instruction corresponding to the test instruction is used as the reference compilation instruction corresponding to the functional test case.
  • the test cases include stability test cases for testing the stability of the compiler.
  • the test cases are constructed based on the data related to the test instructions stored in the instruction database and the reference compilation corresponding to the test cases.
  • Instructions include: for one of the plurality of components, for a piece of target characteristic data in the component, respectively determine the relationship with the component from the remaining components of the plurality of components except the component.
  • the target feature data is associated with the stored associated feature data; a test instruction is generated based on the target feature data and the associated feature data, and the test instruction correspondence is obtained based on the reference compiled data corresponding to the target feature data and the reference compiled data corresponding to the associated feature data.
  • the reference compilation instructions are used to splice the generated test instructions to obtain the stability test case, and the reference compilation instructions corresponding to the multiple test instructions are used to splice the reference compilation instructions corresponding to the stability test case.
  • the data related to the test instructions is stored in a tree structure
  • the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compiled data corresponding to the target feature data.
  • the child nodes of the tree structure are used to store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, and the leaves of the tree structure The node is used to store the second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data in the instruction address.
  • constructing a test case and a reference compilation instruction corresponding to the test case based on the data related to the test instruction stored in the instruction database includes: obtaining the data from the root node to the leaf node in the tree structure. The characteristic data stored in each node in any path, and the reference compiled data corresponding to the characteristic data; a test instruction is obtained by splicing the characteristic data stored in each node, and the reference compiled data corresponding to the characteristic data stored in each node is spliced to obtain The reference compilation instruction corresponding to the test instruction; constructing a test case based on the obtained test instruction, and constructing the reference compilation instruction corresponding to the test case based on the reference compilation instruction corresponding to the test instruction.
  • the method further includes: outputting a test report, and the test The report includes one or more of the following information: the type of exception, the test instruction in which the exception occurs, and the component in which the exception occurs in the test instruction; wherein the type of exception includes functional abnormality or stability abnormality, and the component Including instruction type, control domain, and instruction address.
  • a storage structure of a test instruction includes: a tree structure; the tree structure is used to store data related to the test instruction; the data related to the test instruction The data includes the characteristic data corresponding to each component of the multiple components of the test instruction and the reference compiled data corresponding to the characteristic data; the multiple components include instruction type, control domain and instruction address, and the control domain represents The control operations included in the test instructions; wherein, the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compilation data corresponding to the target feature data, and the sub-tree of the tree structure The node is used to store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data.
  • the leaf nodes of the tree structure are used to store the instruction address.
  • a method for generating test cases is provided.
  • the test cases are used to test the compiler.
  • the test instructions for constructing the test cases are stored through the storage structure described in the second aspect, so The method includes: obtaining the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure, and the reference compiled data corresponding to the characteristic data; splicing the characteristic data stored in each node to obtain A test instruction, splicing the reference compilation data corresponding to each characteristic data to obtain the reference compilation instruction corresponding to the test instruction; generating a test case based on the obtained test instruction, and generating the test case corresponding to the reference compilation instruction corresponding to the test instruction Reference compilation directives.
  • a test device for a compiler including: a building module for constructing test cases based on data related to test instructions stored in an instruction database and the The reference compilation instructions corresponding to the test cases; the compilation module is used to compile the test cases using the compiler to be tested to obtain the target compilation instructions; the determination module is used to compare the reference compilation instructions and the target compilation instructions As a result, it is determined whether there is an exception in the compiler.
  • an electronic device includes a processor, a memory, and computer instructions stored in the memory for execution by the processor.
  • the processor executes the computer instructions.
  • the instruction is issued, the method mentioned in the first aspect and/or the third aspect may be implemented.
  • a computer-readable storage medium is provided.
  • Computer instructions are stored on the storage medium.
  • the above mentioned first and/or third aspects are implemented. method.
  • an instruction database when testing the compiler, can be set in advance. Data related to test instructions can be stored in the instruction database, and then test cases can be automatically constructed based on the data related to test instructions stored in the instruction database. , and the reference compiler instructions corresponding to the test case, and then use the compiler to be tested to compile the test case to obtain the target compilation instructions. Based on the comparison results of the target compilation instructions and the reference compilation instructions corresponding to the test case, determine whether there is an exception in the compiler. . In this way, test cases can be automatically constructed based on the data stored in the instruction database, and the compiler can be automatically tested. This can automate the entire testing process, improve testing efficiency, and improve the accuracy of test results.
  • Figure 1(a) is a flow chart of a compiler testing method according to an embodiment of the present disclosure.
  • Figure 1(b) is a schematic structural diagram of a test instruction according to an embodiment of the present disclosure.
  • Figure 1(c) is a tree structure diagram for storing test instruction related data according to an embodiment of the present disclosure.
  • FIG. 1(d) is a schematic path diagram in a tree structure diagram for storing test instruction related data according to an embodiment of the present disclosure.
  • Figure 2 is a schematic diagram of an instruction database according to an embodiment of the present disclosure.
  • Figure 3 is a schematic diagram of a test instruction storage method according to an embodiment of the present disclosure.
  • FIG. 4 is a schematic diagram of the logical structure of a compiler testing device according to an embodiment of the present disclosure.
  • Figure 5 is a schematic diagram of the logical structure of a device according to an embodiment of the present disclosure.
  • first, second, third, etc. may be used in this disclosure to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other.
  • first information may also be called second information, and similarly, the second information may also be called first information.
  • word “if” as used herein may be interpreted as "when” or “when” or “in response to determining.”
  • Compilers are usually used to compile programs from one language into another language.
  • the accuracy of the compiler results is a prerequisite for ensuring the normal operation of the program. If the function of the compiler is abnormal, not only will the program not be able to obtain the originally intended running results, but it will even be misleading for subsequent debugging of the program.
  • the assembler is usually used to convert assembly language into machine language. If the function of the assembler is abnormal, the final machine language may have errors, resulting in errors in the final program running results.
  • embodiments of the present disclosure provide a compiler testing method that can pre-set instruction data Library, the instruction database can store data related to test instructions, and then can automatically build test cases based on the data related to test instructions stored in the instruction database, as well as the reference compilation instructions corresponding to the test cases, and then use the compiler to be tested to compile
  • This test case obtains the target compilation instruction, and determines whether there is an exception in the compiler based on the comparison result between the target compilation instruction and the reference compilation instruction corresponding to the test case.
  • test cases can be automatically constructed based on the data stored in the instruction database, and the compiler can be automatically tested. This can automate the entire testing process, improve testing efficiency, and improve the accuracy of test results.
  • the compiler testing method in the embodiment of the present disclosure can be executed by various electronic devices, such as mobile phones, computers, cloud servers, etc.
  • the compiler in the embodiment of the present disclosure can be software or hardware with the function of converting one language of the program into another language.
  • the compiler can be a software program with the compilation function, or it can also have the compilation function. hardware equipment.
  • the compiler may be an assembler that converts assembly language into machine language, or a compiler with other types of language conversion capabilities.
  • the correctly compiled data corresponding to the characteristic data corresponding to each component in the test instruction is called reference compilation data
  • the correctly compiled data corresponding to the test instruction or test case to be compiled is called reference compilation instruction.
  • the compiler testing method may include the following steps:
  • test cases and reference compilation instructions corresponding to the test cases based on the data related to the test instructions stored in the instruction database;
  • a test case and a reference compilation instruction corresponding to the test case may be constructed based on the data related to the test instruction stored in the instruction database.
  • a test case can be a single test instruction or a test document constructed from a large number of test instructions.
  • the data related to the test instruction may be various data that can determine the test instruction, and various data that can determine the reference compilation instruction corresponding to the test instruction.
  • the data related to the test instruction can be a complete test instruction and the reference compilation instruction corresponding to the test instruction.
  • multiple test instructions and the corresponding code of each test instruction can be directly stored in the instruction data. Refer to the compilation instructions and then build the test cases directly based on the test instructions.
  • the test instruction can include multiple components, such as instruction type, control domain, instruction address, etc., where the control domain is the control operation included in the instruction.
  • addition instructions usually include rounding operations and saturation processing operations.
  • the data related to the test instruction can be the characteristic data corresponding to each component of the test instruction, that is, the specific content of each component (for example, if the component is an instruction type, the characteristic data can be an addition instruction, a subtraction instruction, etc.) , and the reference compiled data corresponding to the feature data.
  • the instruction database can also store the characteristic data corresponding to each component and the reference compiled data corresponding to the characteristic data, and then construct the test instructions based on these characteristic data, and then based on Build test cases based on the built test instructions, and the reference compilation instructions corresponding to the test cases.
  • step S104 after obtaining the test case, the test case can be compiled using the compiler to be tested to obtain the target compilation instruction.
  • step S106 the target compilation instruction compiled by the compiler can be compared with the reference compilation instruction corresponding to the test case. If the two are consistent, it means that the compilation result of the compiler is correct. If the two are inconsistent, the compilation result is correct. The compiler result of the compiler is wrong and there is an exception in the compiler.
  • the test case may be a test case for testing the functionality of the compiler, hereinafter referred to as a functional test case.
  • Each functional test case can include a single test instruction.
  • the compiler can be tested separately through multiple functional test cases to detect whether there are abnormalities in the compiler's compilation function, for example, to detect whether the compiler will incorrectly compile certain types of instructions, or to detect certain control operations in the instructions. Incorrect compilation, or incorrect compilation of certain addresses in instructions.
  • multiple functional test cases can be constructed.
  • Each functional test case includes a test instruction. These test instructions can cover various instruction types, control operations and instruction addresses. , to ensure the comprehensiveness and completeness of test data.
  • the test case may be a test case used to test the stability of the compiler, hereinafter referred to as a stability test case, and each stability test case may be spliced by multiple test instructions.
  • a stability test case used to test the stability of the compiler
  • each stability test case may be spliced by multiple test instructions.
  • the stability of the compiler can also be tested to detect compilation Will there be any exceptions when the compiler compiles a large number of instructions at one time?
  • a large number of test instructions can be used to splice together to obtain one or more stability test cases with a large amount of data, which can be used to test the stability of the compiler.
  • the test cases may include both functional test cases and stability test cases, that is, testing the above two properties of the compiler.
  • the stability test case may meet one or more of the following conditions: for example, the condition may be that the time it takes for the compiler to compile the stability test case is longer than the preset time, thus ensuring that the compiler runs for a longer time. Afterwards, no exception will occur.
  • the preset duration can be flexibly set based on actual conditions.
  • the condition can also be that the number of test instructions included in the stability test case can be greater than the preset number.
  • stability test cases need to be spliced together with at least 1,000 test instructions.
  • the condition may also be that the data amount of the stability test case is greater than the preset data amount, for example, the data amount of the stability test case is greater than 1GB, etc.
  • the evaluation criteria can also be set to other standards, as long as it can ensure that the stability test case data is large and complex, and can accurately consider the stability of the compiler. Just sex.
  • the built test cases include functional test cases and stability test cases, that is, the compiler can be tested for functionality and stability.
  • the compiler can be tested for functionality and stability.
  • the target compilation instruction corresponding to the functional test case is obtained, and then the target compilation instruction is compared with the reference compilation instruction corresponding to the functional test case, and based on the comparison result, it is determined whether there is an abnormality in the function of the compiler.
  • multiple functional test cases are used to cover various instruction types, various control operations, and instruction addresses. Therefore, each functional test case can be traversed and the above test steps can be repeated to comprehensively test the functionality of the compiler.
  • the compiler can be used to compile each stability test case one by one to obtain the target compilation instruction corresponding to the stability test case, and compare the target compilation instruction with the reference compilation instruction corresponding to the stability test case, based on The comparison results determine whether there are any abnormalities in the stability of the compiler.
  • each test instruction can be composed of multiple components.
  • these components can be one or more of the instruction type, control domain, and instruction address.
  • the instruction address includes the source address of the test instruction and the target address of the test instruction.
  • the test instruction can include three components (components 1-3), which respectively correspond to the instruction type, control domain, and instruction address (source address and target address).
  • the instruction type can be an addition instruction, a subtraction instruction, a data transfer instruction, an OR operation instruction, an AND operation instruction, etc.
  • the control domain represents the control operations included in the test instruction. Taking the arithmetic processing type as an example, the control operations it contains It can be rounding operations, saturation processing, etc.
  • the source address of the test instruction may be an address where the data to be processed by the instruction is stored, and the target address of the test instruction may be an address where the data processed by the instruction is stored.
  • the data related to the test instructions stored in the instruction database may be one or more pieces of characteristic data corresponding to one or more components that constitute the test instruction and the reference compiled data corresponding to these characteristic data, such as , the component can be an instruction type, and the characteristic data can be an addition instruction, a subtraction instruction, etc.
  • the characteristic data corresponding to each component is stored in association with the characteristic data corresponding to the remaining components in the plurality of components.
  • the addition instruction has its corresponding control operation
  • the data transfer instruction also has its corresponding control operation. Therefore, the associated characteristic data in each component can be associated, which can be used when constructing test instructions. Construct test instructions by associating stored feature data.
  • the components of the test instruction include instruction type, control domain, and instruction address.
  • the type of test instruction corresponds to multiple pieces of characteristic data.
  • Each piece of characteristic data represents an instruction type.
  • the characteristic data can be addition instructions, subtraction instructions, etc. instructions etc.
  • the control domain of the test instruction can also correspond to multiple pieces of feature data.
  • Each piece of feature data represents a control operation.
  • the feature data can be rounding processing, saturation processing, etc.
  • the instruction address includes the source address of the test instruction and the target address of the test instruction.
  • the instruction address can also correspond to multiple pieces of feature data, and each feature data represents a set of addresses.
  • an instruction type list including multiple instruction types and reference compiled data corresponding to each instruction type; a control domain list including multiple control operations, and Reference compilation data corresponding to each control operation; and an instruction address list, which includes multiple sets of addresses, and reference compilation data corresponding to each set of addresses, where each set of addresses includes a source address and a target address.
  • the type of control operations involved is certain, for example, it can only be control operations related to addition processing.
  • the type of data it can process is also certain, that is, the data it can process is data within a certain address range, and its corresponding instruction address can also be determined.
  • the instruction type when storing the above data in the instruction database, for each instruction type, the instruction type can be stored in association with its various control operations, source addresses, and target addresses, so that when constructing instructions based on these characteristic data, it can be based on The correlation relationship of the characteristic data selects the associated instruction type, control operation, source address and target address, and constructs the correct test instruction.
  • the amount of data can be reduced, and it is also possible to add, delete, or modify test instructions stored in the instruction data later when it is necessary to add, delete, or modify them. More convenient.
  • the instruction database may store characteristic data corresponding to each component of the test instruction and reference compilation data corresponding to the characteristic data.
  • multiple components can be traversed. Each piece of characteristic data corresponding to each component. For any piece of characteristic data corresponding to any component, this piece of characteristic data is referred to as the target characteristic data in the following.
  • the target characteristic data can be determined from the remaining components among the multiple components. Associate the stored associated feature data, then generate a test instruction based on the target feature data and the associated feature data, and obtain the reference compilation corresponding to the test instruction based on the reference compilation data corresponding to the target feature data and the reference compilation data corresponding to the associated feature data.
  • each generated test instruction can be used as a functional test case, and the reference compilation instructions corresponding to each test instruction can be used as the reference compilation instructions corresponding to the functional test case, so that the compilation instructions can be obtained.
  • Multiple functional test cases to test the functionality of the processor can be used as a functional test case, and the reference compilation instructions corresponding to each test instruction can be used as the reference compilation instructions corresponding to the functional test case, so that the compilation instructions can be obtained.
  • multiple "controls” stored in association with the "addition instruction” can be determined from the two components of the control domain and instruction address stored in the instruction database. Operation” and multiple “addresses”, and then a "control operation” and a set of “addresses” can be randomly selected from the multiple "control operations" and multiple "addresses", and the target characteristic data of the above-mentioned "addition instruction” Build a test directive.
  • test instructions By traversing each feature data of each component in the instruction database, multiple test instructions covering various instruction types, control operations and instruction addresses can be constructed, so that the functional test cases constructed are more comprehensive and more accurate. test results. In some embodiments, it is not necessary to traverse each feature data of each component in the instruction database, but only obtain a specified number of test cases according to requirements, which is not limited in this disclosure.
  • the instruction database may store characteristic data corresponding to each component of the test instruction and reference compiled data corresponding to the characteristic data. Stability test cases and stability test cases are constructed based on the test instruction-related data stored in the instruction database.
  • the reference compilation instruction corresponding to the test case is used, for any piece of target feature data in any component, the associated feature data stored in association with the target feature data can be determined from the remaining components in multiple components, and then based on The target characteristic data and associated characteristic data generate test instructions. And based on the reference compilation data corresponding to the target characteristic data and the reference compilation data corresponding to the associated characteristic data, the reference compilation instruction corresponding to the test instruction is obtained. Then the multiple generated test instructions can be used to splice to obtain a stability test case, and the reference compilation instructions corresponding to the multiple test instructions can be used to splice to obtain the reference compilation instructions corresponding to the stability test case.
  • test instructions can be randomly constructed based on the interrelated feature data stored in the instruction database, and these test instructions can be used to splice together to obtain stability test cases with a large amount of data.
  • the instructions corresponding to the test instructions are stored in the instruction database.
  • these data can be stored in a tree structure.
  • the number of layers can be consistent with the number of components of the test instruction.
  • the test instruction includes three components: instruction type, control domain, and instruction address
  • the tree structure can include three layers, that is, tree structure. The structure includes a root node, child nodes branched from the root node, and leaf nodes branched from each child node.
  • the root node of the tree structure can be used to store any target feature data in the instruction type and the corresponding target feature data.
  • Reference compiled data The child nodes of the tree structure to the leaf nodes of the tree structure are used to sequentially store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, as well as the instruction address and The second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data.
  • FIG. 1(c) it is a schematic diagram of using a tree structure to store test instructions.
  • the root node of the tree structure can be used to store a feature data in the instruction type and its corresponding reference compiled data.
  • the characteristic data may be an "addition instruction”
  • the reference compiled data may be the machine code corresponding to the "addition instruction”.
  • multiple child nodes can be branched from the root node.
  • Each child node is used to store the control operation associated with the "addition instruction” and the reference compiled data corresponding to the control operation.
  • there can be three child nodes each child node Store "rounding mode” and its machine code, "immediate mode” and its machine code, "register mode” and its machine code, etc.
  • each leaf node It is used to store the instruction address and its machine code associated with the characteristic data stored in the root node and the child nodes branching out of the leaf node, for example, multiple sets of instructions associated with "addition instructions” and "rounding mode” Address, "source address 1, destination address 1", “source address 2, destination address 2", “source address 3, destination address 3”, etc.
  • the feature data stored in each node in any path from the root node to the leaf node in the tree structure can be obtained , and the reference compilation data corresponding to each of these feature data, and then splicing the feature data stored in each node to obtain a test instruction, splicing the reference compilation data corresponding to the feature data stored in each node to obtain the reference compilation instruction corresponding to the test instruction, and then A test case may be constructed based on the obtained test instruction and a reference compilation instruction corresponding to the test case may be constructed based on the reference compilation instruction corresponding to the test instruction. For example, each obtained test instruction can be used as a test case, or multiple test instructions can be spliced into one test case.
  • the "root node-child node-leaf node” selected in the black box is a path from the root node to the leaf node in the tree structure, and the information stored in each node in the path can be obtained.
  • the characteristic data namely "addition instruction”, “rounding mode”, "source address 1, target address 1”, is spliced to obtain a test instruction, and the machine code corresponding to these characteristic data is obtained and spliced to obtain the reference corresponding to the test instruction. Compilation directives.
  • a test report can be further output.
  • the test report It can include one or more of the following information: the type of exception, the test instruction in which the exception occurs, and the component where the exception occurs.
  • the type of exception includes functional abnormality or stability abnormality.
  • the components can include instruction type, control domain, and instruction. address.
  • this embodiment provides an assembler testing method.
  • An instruction database can be set up in advance.
  • the architecture of the instruction database is shown in Figure 2. Since assembly instructions can usually be divided into three components: instruction type, control domain, and instruction address, the instruction type can correspond to an instruction type list.
  • the list includes various instruction types of assembly instructions, and the machine codes corresponding to various instruction types.
  • the control domain can also correspond to a control domain list. This list includes various control operations of assembly instructions, as well as various control operations.
  • the instruction address can also correspond to an address list, which includes the source address and destination address of the data involved in the instruction, as well as the machine code corresponding to each address.
  • Each piece of feature data in each of the above three lists is stored in association with one or more pieces of feature data in the other lists.
  • the instruction type "addition instruction” in Figure 2 is associated with the control operations “rounding” and “saturation processing”, and is associated with the "source address 1, target address 1" and “source address” in the instruction address. Address 2, target address 2" and “source address 3, target address 3" are stored in association. Therefore, when building a test instruction, you can randomly select a control operation "saturation processing" and a set of instruction addresses "source address 1, target address 1" Build a test instruction.
  • each feature data in this component For any of the three components: instruction type, instruction control domain, and instruction address. For each piece of characteristic data, you can select from the remaining two components. Determine the associated feature data of the feature data from the feature data of each component, and then select one piece of associated feature data corresponding to the other two components to construct a test instruction. Then you can traverse each feature data of each component and repeat the above steps to get multiple test instructions and the reference machine code corresponding to each test instruction.
  • test document can be obtained by splicing multiple test instructions, wherein the number of test instructions in the test document is greater than the preset number. This test document can then be used to test the stability of the assembler and determine whether there are abnormalities in the assembler.
  • an exception test report can be output.
  • the report can indicate the following information: what type of exception is the exception, the test instruction in which the exception occurred, and which component of the test instruction caused the exception, which facilitates developers to locate the exception. and solved.
  • Test instructions generally consist of multiple components.
  • test instructions can be composed of three parts: instruction type, control domain, and instruction address.
  • the characteristic data corresponding to each component of the test instruction and the reference compiled data corresponding to the characteristic data can be stored separately, and different components can be stored in
  • the associated feature data is stored in an associated manner, so that when generating a test instruction, the associated feature data in each component can be obtained, spliced together to obtain the test instruction, and the reference compilation instruction corresponding to the test instruction. In this way, it is also possible to generate more Comprehensive, covering various types of test instructions.
  • test instructions Since the various components of the test instructions are interrelated, for example, the instruction type will affect the selection of the control operation, and the instruction type and control operation will further affect the selection of the instruction address.
  • the following provides a storage method for test instructions, as shown in Figure 3, which can include Following steps:
  • Step 1 Obtain the data related to the test instruction to be stored.
  • the data related to the test instruction includes multiple feature data corresponding to each component of the multiple components of the test instruction, and the reference compilation corresponding to each feature data.
  • Data; the plurality of components include an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
  • the test instruction includes three components: instruction type, control domain, and instruction address.
  • Each component can include multiple pieces of feature data, and each piece of feature data has corresponding reference compiled data.
  • instruction types may include addition instructions, subtraction instructions, data transfer instructions, and other types.
  • Step 2 Store the data related to the test instructions through a tree structure, where the root node of any tree structure is used to store a piece of target feature data in the instruction type and the reference compiled data corresponding to the target feature data.
  • the child nodes of the tree structure to the leaf nodes of the tree structure are used to store the control domain in sequence
  • the tree structure can include three levels: root node - child node - leaf node.
  • Any target feature data A1 (for example, addition instruction) in the instruction type and its reference compiled data can be stored in a In the root node of the tree structure, then determine the first associated feature data B1, B2, B3 in the control domain that are associated with the target feature data A1 (for example, rounding, saturation processing, immediate mode, etc.), and their respective Reference compiled data is then stored in each child node branched from the root node.
  • the second association associated with the target feature data A1 stored in the root node and the first feature data stored in the child node that branches out from the leaf node can be determined from the instruction address.
  • Feature data such as second associated feature data C1, C2, C3 (for example, three sets of addresses) associated with target feature data A1, first associated feature data B1, and their respective reference compiled data are then stored in the slave In each leaf node branched from the child node where the first associated feature data B1 is located. That is, the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure can constitute a test instruction.
  • test instruction storage method For specific implementation details of the test instruction storage method, please refer to the description of the embodiment in the above compilation method, and will not be repeated here.
  • the present disclosure also provides a storage structure of test instructions, where the storage structure includes: a tree structure;
  • the tree structure is used to store data related to test instructions;
  • the data related to test instructions includes multiple pieces of characteristic data corresponding to each component of the multiple components of the test instruction, and a reference corresponding to each piece of characteristic data.
  • Compile data includes an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
  • the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compilation data corresponding to the target feature data, and the child nodes of the tree structure to the leaves of the tree structure
  • the node is used to sequentially store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, as well as the target feature data and the reference compilation data corresponding to the first associated feature data in the instruction address.
  • the second associated feature data associated with the first associated feature data and the reference compiled data corresponding to the second associated feature data.
  • test instruction storage structure For specific implementation details of the test instruction storage structure, reference can be made to the description of the embodiment in the above compilation method, and the details will not be repeated here.
  • test case generation method for generating test cases for testing the compiler, in which the test instructions for constructing the test cases can be stored using the above-mentioned storage structure.
  • Specific generation of test cases The process can include the following steps:
  • the embodiment of the present disclosure also provides a compiler testing device, as shown in Figure 4, the device includes:
  • the construction module 41 is used to construct test cases based on the data related to the test instructions stored in the instruction database, and the reference compilation instructions corresponding to the test cases;
  • the compilation module 42 is used to compile the test case using the compiler to be tested to obtain the target compilation instructions
  • the determination module 43 is configured to determine whether there is an exception in the compiler based on the comparison result between the reference compilation instruction and the target compilation instruction.
  • embodiments of the present disclosure also provide a storage device for test instructions, where the device includes:
  • An acquisition module used to acquire data related to the test instructions to be stored.
  • the data related to the test instructions include characteristic data corresponding to each component of the multiple components of the test instruction and reference compiled data corresponding to the characteristic data.
  • the plurality of components include an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
  • a storage module configured to store the data related to the test instructions through a tree structure, where the root node of any tree structure is used to store a piece of target feature data in the instruction type and a reference corresponding to the target feature data. Compiled data, the child nodes of the tree structure are used to store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, the tree structure The leaf node is used to store the second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data in the instruction address.
  • embodiments of the present disclosure also provide a device for generating test cases.
  • the test cases are used to test the compiler.
  • the test instructions for constructing the test cases are stored through the storage method described in the above embodiments.
  • the device include:
  • An acquisition module used to acquire the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure, and the reference compiled data corresponding to the characteristic data;
  • the splicing module is used to splice the characteristic data stored in each node to obtain a test instruction, and splice the reference compilation data corresponding to each characteristic data to obtain the reference compilation instruction corresponding to the test instruction;
  • a generation module configured to generate test cases based on the obtained test instructions, and generate reference compilation instructions corresponding to the test cases based on reference compilation instructions corresponding to the test instructions.
  • an embodiment of the present disclosure also provides an electronic device.
  • the electronic device includes a processor 51, a memory 52, and computer instructions stored in the memory 52 for execution by the processor 51.
  • the processor 51 executes the computer instructions, the method described in any one of the above embodiments is implemented.
  • An embodiment of the present disclosure also provides a computer-readable storage medium on which a computer program is stored.
  • the program is executed by a processor, the method described in any of the foregoing embodiments is implemented.
  • Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information.
  • Information may be computer-readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • read-only memory read-only memory
  • ROM read-only memory
  • EEPROM electrically erasable programmable read-only memory
  • flash memory or other memory technology
  • compact disc read-only memory CD-ROM
  • DVD digital versatile disc
  • Magnetic tape cassettes tape magnetic disk storage or other magnetic storage devices or any other non-transmission medium can be used to store information that can be accessed by a computing device.
  • computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • the embodiments of the present disclosure can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions of the embodiments of the present disclosure are essentially or the parts that contribute to the existing technology can be embodied in the form of software products.
  • the computer software products can be stored in storage media, such as ROM/RAM, A magnetic disk, optical disk, etc., includes a number of instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments or certain parts of the embodiments of the present disclosure.
  • a typical implementation device is a computer, which may be in the form of a personal computer, a laptop, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, or a game controller. desktop, tablet, wearable device, or a combination of any of these devices.
  • each embodiment in this specification is described in a progressive manner.
  • the same and similar parts between the various embodiments can be referred to each other.
  • Each embodiment focuses on its differences from other embodiments.
  • the description is relatively simple.
  • the device embodiments described above are only illustrative.
  • the modules described as separate components may or may not be physically separated.
  • the functions of each module may be integrated into the same device. or implemented in multiple software and/or hardware. Some or all of the modules can also be selected according to actual needs to achieve the purpose of the solution of this embodiment. Persons of ordinary skill in the art can understand and implement the method without any creative effort.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Test And Diagnosis Of Digital Computers (AREA)
  • Debugging And Monitoring (AREA)

Abstract

A compiler test method and apparatus, a device, a storage medium, and a storage structure for a test instruction. The method comprises: on the basis of data which is stored in an instruction database and is related to a test instruction, constructing a test case, and a reference compiling instruction corresponding to the test case; compiling the test case by using a compiler to be tested, so as to obtain a target compiling instruction; and on the basis of a comparison result between the reference compiling instruction corresponding to the test case and the target compiling instruction, determining whether the compiler is abnormal. In the embodiments of the present disclosure, automatic testing of a compiler can be realized, thereby improving the test efficiency and the accuracy of a test result.

Description

编译器测试方法、用例生成方法、装置及指令存储结构Compiler testing methods, use case generation methods, devices and instruction storage structures
相关申请的交叉引用Cross-references to related applications
本申请要求于2022年04月29日提交的、申请号为2022104743224的中国专利申请的优先权,该申请以引用的方式并入本文中。This application claims priority from the Chinese patent application with application number 2022104743224, submitted on April 29, 2022, which is incorporated herein by reference.
技术领域Technical field
本公开涉及计算机技术领域,尤其涉及一种编译器的测试方法、用例生成方法、装置、设备、存储介质及测试指令的存储结构。The present disclosure relates to the field of computer technology, and in particular, to a compiler testing method, a use case generation method, a device, a device, a storage medium, and a storage structure of test instructions.
背景技术Background technique
编译器通常用于将程序由一种语言编译成另外一种语言,编译器编译结果的准确性是保证程序正常运行的前提。如果编译器的功能出现异常,不仅会使得程序得不到原本想要的运行结果,甚至还会对后续程序的debug(排除故障)产生误导。因而,在研发一种编译器后,有必要提供一种可以对该编译器进行测试的方案,以及时发现编译器存在的异常。Compilers are usually used to compile programs from one language into another language. The accuracy of the compiler results is a prerequisite for ensuring the normal operation of the program. If the compiler function is abnormal, it will not only cause the program to not obtain the originally intended running results, but may even mislead the debugging (troubleshooting) of subsequent programs. Therefore, after developing a compiler, it is necessary to provide a solution that can test the compiler to detect abnormalities in the compiler in a timely manner.
发明内容Contents of the invention
本公开提供一种编译器的测试方法、用例生成方法、装置、设备、存储介质及测试指令的存储结构。The present disclosure provides a compiler testing method, use case generation method, device, equipment, storage medium and storage structure of test instructions.
根据本公开实施例的第一方面,提供一种编译器的测试方法,所述方法包括:基于指令数据库中存储的与测试指令相关的数据构建测试用例,以及所述测试用例对应的参考编译指令;利用待测试的编译器编译所述测试用例,得到目标编译指令;基于所述参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常。According to a first aspect of an embodiment of the present disclosure, a method for testing a compiler is provided. The method includes: constructing a test case based on data related to test instructions stored in an instruction database, and a reference compilation instruction corresponding to the test case. ;Use the compiler to be tested to compile the test case to obtain the target compilation instruction; based on the comparison result of the reference compilation instruction and the target compilation instruction, determine whether there is an exception in the compiler.
在一些实施例中,所述测试用例包括功能性测试用例和/或稳定性测试用例,所述功能性测试用例包括单条测试指令,用于测试所述编译器的功能;所述稳定性测试用例由多条测试指令拼接得到,用于测试所述编译器的稳定性。In some embodiments, the test cases include functional test cases and/or stability test cases. The functional test cases include a single test instruction for testing the function of the compiler; the stability test case It is spliced together from multiple test instructions and used to test the stability of the compiler.
在一些实施例中,所述稳定性测试用例符合以下一种或多种条件:所述编译器编译所述稳定性测试用例的时长大于预设时长;所述稳定性测试用例中包括的测试指令数量大于预设数量;所述稳定性测试用例的数据量大于预设数据量。In some embodiments, the stability test case meets one or more of the following conditions: the compiler compiles the stability test case for longer than a preset time; the test instructions included in the stability test case The quantity is greater than the preset quantity; the data volume of the stability test case is greater than the preset data volume.
在一些实施例中,所述测试用例包括功能性测试用例以及稳定性测试用例,基于所述测试用例对应的参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常,包括:基于所述功能性测试用例对应的参考编译指令与所述功能性测试用例对应的目标编译指令的比对结果,判定所述编译器的功能是否存在异常;在所述编译器的功能不存在异常的情况,基于所述稳定性测试用例对应的参考编译指令与所述稳 定性测试用例对应的目标编译指令的比对结果,判定所述编译器的稳定性是否存在异常。In some embodiments, the test cases include functional test cases and stability test cases. Based on the comparison results of the reference compilation instructions corresponding to the test cases and the target compilation instructions, it is determined whether there is an abnormality in the compiler. , including: determining whether there is an abnormality in the function of the compiler based on the comparison result of the reference compilation instruction corresponding to the functional test case and the target compilation instruction corresponding to the functional test case; There is no abnormal situation. Based on the reference compilation instructions corresponding to the stability test case and the stability test case, the The comparison results of the target compilation instructions corresponding to the qualitative test cases are used to determine whether there are abnormalities in the stability of the compiler.
在一些实施例中,所述测试指令包括多个组成部分,所述与测试指令相关的数据包括针对所述多个组成部分中的一个组成部分,该组成部分对应的特征数据以及该特征数据对应的参考编译数据,该组成部分对应的特征数据与所述多个组成部分中除该组成部分之外的其余组成部分对应的特征数据关联存储。In some embodiments, the test instruction includes multiple components, and the data related to the test instruction includes for one component among the multiple components, the characteristic data corresponding to the component and the characteristic data corresponding to The reference compiled data, the characteristic data corresponding to this component is stored in association with the characteristic data corresponding to the remaining components among the plurality of components except this component.
在一些实施例中,所述组成部分包括以下一种或多种:指令类型、控制域、指令地址,其中,所述控制域用于表示所述测试指令包括的控制操作。In some embodiments, the component includes one or more of the following: instruction type, control domain, and instruction address, where the control domain is used to represent the control operations included in the test instruction.
在一些实施例中,所述测试用例包括用于测试所述编译器功能的多个功能性测试用例,基于指令数据库中存储的与测试指令相关的数据构建测试用例,以及所述测试用例对应的参考编译指令,包括:针对所述多个组成部分中的一个组成部分,针对该组成部分对应的一条目标特征数据,分别从所述多个组成部分中除该组成部分以外的其余组成部分中确定与该目标特征数据关联存储的关联特征数据;基于该目标特征数据和该关联特征数据生成测试指令,基于该目标特征数据对应的参考编译数据以及该关联特征数据对应的参考编译数据得到所述测试指令对应的参考编译指令;将所述测试指令作为一个功能性测试用例,将所述测试指令对应的参考编译指令作为该功能性测试用例对应的参考编译指令。In some embodiments, the test cases include a plurality of functional test cases for testing the compiler function, the test cases are constructed based on the data related to the test instructions stored in the instruction database, and the test cases correspond to The reference compilation instructions include: for one component among the plurality of components, a piece of target characteristic data corresponding to the component is determined from the remaining components among the plurality of components except the component. Associated feature data stored in association with the target feature data; generating test instructions based on the target feature data and the associated feature data, and obtaining the test based on the reference compiled data corresponding to the target feature data and the reference compiled data corresponding to the associated feature data The reference compilation instruction corresponding to the instruction; the test instruction is used as a functional test case, and the reference compilation instruction corresponding to the test instruction is used as the reference compilation instruction corresponding to the functional test case.
在一些实施例中,所述测试用例包括用于测试所述编译器稳定性的稳定性测试用例,基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令,包括:针对所述多个组成部分中的一个组成部分,针对该组成部分中的一条目标特征数据,分别从所述多个组成部分中除该组成部分以外的其余组成部分中确定与该目标特征数据关联存储的关联特征数据;基于该目标特征数据和该关联特征数据生成测试指令,基于该目标特征数据对应的参考编译数据以及该关联特征数据对应的参考编译数据得到所述测试指令对应的参考编译指令;利用生成的多个测试指令拼接得到所述稳定性测试用例,利用所述多个测试指令对应的参考编译指令拼接得到所述稳定性测试用例对应的参考编译指令。In some embodiments, the test cases include stability test cases for testing the stability of the compiler. The test cases are constructed based on the data related to the test instructions stored in the instruction database and the reference compilation corresponding to the test cases. Instructions include: for one of the plurality of components, for a piece of target characteristic data in the component, respectively determine the relationship with the component from the remaining components of the plurality of components except the component. The target feature data is associated with the stored associated feature data; a test instruction is generated based on the target feature data and the associated feature data, and the test instruction correspondence is obtained based on the reference compiled data corresponding to the target feature data and the reference compiled data corresponding to the associated feature data. The reference compilation instructions are used to splice the generated test instructions to obtain the stability test case, and the reference compilation instructions corresponding to the multiple test instructions are used to splice the reference compilation instructions corresponding to the stability test case.
在一些实施例中,所述测试指令相关的数据通过树型结构存储,所述树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点用于存储所述控制域中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,所述树型结构的叶子节点用于存储所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。 In some embodiments, the data related to the test instructions is stored in a tree structure, and the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compiled data corresponding to the target feature data. , the child nodes of the tree structure are used to store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, and the leaves of the tree structure The node is used to store the second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data in the instruction address.
在一些实施例中,所述基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令,包括:获取所述树型结构中从根节点到叶子节点的任一路径中的各节点存储的特征数据,以及所述特征数据对应的参考编译数据;将各节点存储的特征数据拼接得到一条测试指令,将各节点存储的特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令;基于得到的测试指令构建测试用例,以及基于所述测试指令对应的参考编译指令构建所述测试用例对应的参考编译指令。In some embodiments, constructing a test case and a reference compilation instruction corresponding to the test case based on the data related to the test instruction stored in the instruction database includes: obtaining the data from the root node to the leaf node in the tree structure. The characteristic data stored in each node in any path, and the reference compiled data corresponding to the characteristic data; a test instruction is obtained by splicing the characteristic data stored in each node, and the reference compiled data corresponding to the characteristic data stored in each node is spliced to obtain The reference compilation instruction corresponding to the test instruction; constructing a test case based on the obtained test instruction, and constructing the reference compilation instruction corresponding to the test case based on the reference compilation instruction corresponding to the test instruction.
在一些实施例中,在基于所述测试用例对应的参考编译指令与所述目标编译指令的比对结果,判定所述编译器存在异常之后,所述方法还包括:输出测试报告,所述测试报告包括以下一种或多种信息:异常的类型、出现异常的测试指令、所述测试指令中出现异常的组成部分;其中,所述异常的类型包括功能异常或稳定性异常,所述组成部分包括指令类型、控制域、指令地址。In some embodiments, after determining that there is an exception in the compiler based on a comparison result between the reference compilation instructions corresponding to the test case and the target compilation instructions, the method further includes: outputting a test report, and the test The report includes one or more of the following information: the type of exception, the test instruction in which the exception occurs, and the component in which the exception occurs in the test instruction; wherein the type of exception includes functional abnormality or stability abnormality, and the component Including instruction type, control domain, and instruction address.
根据本公开实施例的第二方面,提供一种测试指令的存储结构,所述存储结构包括:树型结构;所述树型结构用于存储与测试指令相关的数据;所述与测试指令相关的数据包括测试指令的多个组成部分中各组成部分对应的特征数据以及所述特征数据对应的参考编译数据;所述多个组成部分包括指令类型、控制域以及指令地址,所述控制域表示所述测试指令包括的控制操作;其中,所述树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点用于存储所述控制域中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,所述树型结构的叶子节点用于存储所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。According to a second aspect of the embodiment of the present disclosure, a storage structure of a test instruction is provided. The storage structure includes: a tree structure; the tree structure is used to store data related to the test instruction; the data related to the test instruction The data includes the characteristic data corresponding to each component of the multiple components of the test instruction and the reference compiled data corresponding to the characteristic data; the multiple components include instruction type, control domain and instruction address, and the control domain represents The control operations included in the test instructions; wherein, the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compilation data corresponding to the target feature data, and the sub-tree of the tree structure The node is used to store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data. The leaf nodes of the tree structure are used to store the instruction address. The second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data.
根据本公开实施例的第三方面,提供一种测试用例的生成方法,所述测试用例用于测试编译器,构建所述测试用例的测试指令通过上述第二方面所述的存储结构存储,所述方法包括:获取所述树型结构中从根节点到叶子节点的任一路径中的各节点存储的特征数据,以及所述特征数据对应的参考编译数据;将各节点存储的特征数据拼接得到一条测试指令,将各特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令;基于得到的测试指令生成测试用例,以及基于所述测试指令对应的参考编译指令生成所述测试用例对应的参考编译指令。According to the third aspect of the embodiment of the present disclosure, a method for generating test cases is provided. The test cases are used to test the compiler. The test instructions for constructing the test cases are stored through the storage structure described in the second aspect, so The method includes: obtaining the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure, and the reference compiled data corresponding to the characteristic data; splicing the characteristic data stored in each node to obtain A test instruction, splicing the reference compilation data corresponding to each characteristic data to obtain the reference compilation instruction corresponding to the test instruction; generating a test case based on the obtained test instruction, and generating the test case corresponding to the reference compilation instruction corresponding to the test instruction Reference compilation directives.
根据本公开实施例的第四方面,提供一种编译器的测试装置,所述装置包括:构建模块,用于基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述 测试用例对应的参考编译指令;编译模块,用于利用待测试的编译器编译所述测试用例,得到目标编译指令;判定模块,用于基于所述参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常。According to a fourth aspect of an embodiment of the present disclosure, a test device for a compiler is provided, the device including: a building module for constructing test cases based on data related to test instructions stored in an instruction database and the The reference compilation instructions corresponding to the test cases; the compilation module is used to compile the test cases using the compiler to be tested to obtain the target compilation instructions; the determination module is used to compare the reference compilation instructions and the target compilation instructions As a result, it is determined whether there is an exception in the compiler.
根据本公开实施例的第五方面,提供一种电子设备,所述电子设备包括处理器、存储器、存储在所述存储器可供所述处理器执行的计算机指令,所述处理器执行所述计算机指令时,可实现上述第一方面和/或第三方面提及的方法。According to a fifth aspect of an embodiment of the present disclosure, an electronic device is provided. The electronic device includes a processor, a memory, and computer instructions stored in the memory for execution by the processor. The processor executes the computer instructions. When the instruction is issued, the method mentioned in the first aspect and/or the third aspect may be implemented.
根据本公开实施例的第六方面,提供一种计算机可读存储介质,所述存储介质上存储有计算机指令,所述计算机指令被执行时实现上述第一方面和/或第三方面提及的方法。According to a sixth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided. Computer instructions are stored on the storage medium. When the computer instructions are executed, the above mentioned first and/or third aspects are implemented. method.
本公开实施例中,在对编译器进行测试时,可以预先设置指令数据库,指令数据库中可以存储与测试指令相关的数据,然后可以基于指令数据库中存储的与测试指令相关的数据自动构建测试用例,以及测试用例对应的参考编译器指令,再利用待测试的编译器编译该测试用例,得到目标编译指令,基于目标编译指令和测试用例对应的参考编译指令的比对结果判定编译器是否存在异常。通过这种方式,可以基于指令数据库存储的数据自动构建测试用例,并自动对编译器进行测试,可以实现整个测试过程自动化,提高测试效率以及测试结果的准确性。In the embodiment of the present disclosure, when testing the compiler, an instruction database can be set in advance. Data related to test instructions can be stored in the instruction database, and then test cases can be automatically constructed based on the data related to test instructions stored in the instruction database. , and the reference compiler instructions corresponding to the test case, and then use the compiler to be tested to compile the test case to obtain the target compilation instructions. Based on the comparison results of the target compilation instructions and the reference compilation instructions corresponding to the test case, determine whether there is an exception in the compiler. . In this way, test cases can be automatically constructed based on the data stored in the instruction database, and the compiler can be automatically tested. This can automate the entire testing process, improve testing efficiency, and improve the accuracy of test results.
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,而非限制本公开。It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only, and are not restrictive of the disclosure.
附图说明Description of the drawings
此处的附图被并入说明书中并构成本说明书的一部分,这些附图示出了符合本公开的实施例,并与说明书一起用于说明本公开的技术方案。The accompanying drawings herein are incorporated into and constitute a part of this specification. They illustrate embodiments consistent with the disclosure and, together with the description, serve to explain the technical solutions of the disclosure.
图1(a)是本公开实施例的一种编译器的测试方法的流程图。Figure 1(a) is a flow chart of a compiler testing method according to an embodiment of the present disclosure.
图1(b)是本公开实施例的一种测试指令的结构示意图。Figure 1(b) is a schematic structural diagram of a test instruction according to an embodiment of the present disclosure.
图1(c)是本公开实施例的一种存储测试指令相关数据的树型结构图。Figure 1(c) is a tree structure diagram for storing test instruction related data according to an embodiment of the present disclosure.
图1(d)是本公开实施例的一种存储测试指令相关数据的树型结构图中的路径示意图。FIG. 1(d) is a schematic path diagram in a tree structure diagram for storing test instruction related data according to an embodiment of the present disclosure.
图2是本公开实施例的一种指令数据库的示意图。Figure 2 is a schematic diagram of an instruction database according to an embodiment of the present disclosure.
图3是本公开实施例的一种测试指令存储方法的示意图。Figure 3 is a schematic diagram of a test instruction storage method according to an embodiment of the present disclosure.
图4是本公开实施例的一种编译器的测试装置的逻辑结构示意图。FIG. 4 is a schematic diagram of the logical structure of a compiler testing device according to an embodiment of the present disclosure.
图5是本公开实施例的一种设备的逻辑结构示意图。 Figure 5 is a schematic diagram of the logical structure of a device according to an embodiment of the present disclosure.
具体实施方式Detailed ways
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本公开相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本公开的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with aspects of the disclosure as detailed in the appended claims.
在本公开使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本公开。在本公开和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。另外,本文中术语“至少一种”表示多种中的任意一种或多种中的至少两种的任意组合。The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in this disclosure and the appended claims, the singular forms "a," "the" and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It will also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality.
应当理解,尽管在本公开可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本公开范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It should be understood that although the terms first, second, third, etc. may be used in this disclosure to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of the present disclosure, the first information may also be called second information, and similarly, the second information may also be called first information. Depending on the context, the word "if" as used herein may be interpreted as "when" or "when" or "in response to determining."
为了使本技术领域的人员更好的理解本公开实施例中的技术方案,并使本公开实施例的上述目的、特征和优点能够更加明显易懂,下面结合附图对本公开实施例中的技术方案作进一步详细的说明。In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present disclosure, and to make the above objects, features and advantages of the embodiments of the present disclosure more obvious and easy to understand, the technical solutions in the embodiments of the present disclosure are described below in conjunction with the accompanying drawings. The plan is explained in further detail.
编译器通常用于将程序由一种语言编译成另外一种语言,编译器编译结果的准确性是保证程序正常运行的前提。如果编译器的功能出现异常,不仅会使得程序得不到原本想要的运行结果,甚至还会对后续程序的debug产生误导。以汇编器为例,汇编器通常用于将汇编语言转换为机器语言,如果汇编器的功能出现异常,则最后得到的机器语言可能出现错误,导致最终程序的运行结果出错。Compilers are usually used to compile programs from one language into another language. The accuracy of the compiler results is a prerequisite for ensuring the normal operation of the program. If the function of the compiler is abnormal, not only will the program not be able to obtain the originally intended running results, but it will even be misleading for subsequent debugging of the program. Take the assembler as an example. The assembler is usually used to convert assembly language into machine language. If the function of the assembler is abnormal, the final machine language may have errors, resulting in errors in the final program running results.
针对一些自研的编译器,通常需要先对其功能进行测试后,再投入到产品中使用。相关技术中,比较少专门针对编译器单独进行测试的方案,大多是针对运行程序的整个系统进行测试,即通过对整个系统进行测试,由程序最终的运行结果和预期结果进行比对,来确定整个系统是否出现异常,如果出现异常,再来排查是否是编译环节出现异常。这种方式无法单独的对编译器的功能进行测试。也有的技术是直接通过人工对编译器进行测试,比如,通过人工来比对编译器的编译结果与正确结果,这种方式比较繁琐,耗时耗力,且容易出错。For some self-developed compilers, it is usually necessary to test their functions before putting them into use in products. In related technologies, there are relatively few solutions that specifically test the compiler alone. Most of them test the entire system that runs the program, that is, by testing the entire system and comparing the final running results of the program with the expected results to determine Check whether there is an abnormality in the entire system. If there is an abnormality, check whether there is an abnormality in the compilation process. This method cannot independently test the functionality of the compiler. There are also technologies that directly test the compiler manually. For example, manually compare the compiler's compilation results with the correct results. This method is cumbersome, time-consuming, and error-prone.
基于此,本公开实施例提供了一种编译器的测试方法,可以预先设置指令数据 库,指令数据库中可以存储与测试指令相关的数据,然后可以基于指令数据库中存储的与测试指令相关的数据自动构建测试用例,以及测试用例对应的参考编译指令,再利用待测试的编译器编译该测试用例,得到目标编译指令,基于目标编译指令和测试用例对应的参考编译指令的比对结果判定编译器是否存在异常。通过这种方式,可以基于指令数据库存储的数据自动构建测试用例,并自动对编译器进行测试,可以实现整个测试过程自动化,提高测试效率以及测试结果的准确性。Based on this, embodiments of the present disclosure provide a compiler testing method that can pre-set instruction data Library, the instruction database can store data related to test instructions, and then can automatically build test cases based on the data related to test instructions stored in the instruction database, as well as the reference compilation instructions corresponding to the test cases, and then use the compiler to be tested to compile This test case obtains the target compilation instruction, and determines whether there is an exception in the compiler based on the comparison result between the target compilation instruction and the reference compilation instruction corresponding to the test case. In this way, test cases can be automatically constructed based on the data stored in the instruction database, and the compiler can be automatically tested. This can automate the entire testing process, improve testing efficiency, and improve the accuracy of test results.
本公开实施例中的编译器的测试方法可以由各种电子设备执行,比如,手机、电脑、云端服务器等。The compiler testing method in the embodiment of the present disclosure can be executed by various electronic devices, such as mobile phones, computers, cloud servers, etc.
本公开实施例中的编译器可以是具备将程序的一种语言转换成另一种语言的功能的软件或硬件,比如,该编译器可以是具备编译功能的软件程序、也是可以具备编译功能的硬件设备。该编译器可以是将汇编语言转换成机器语言的汇编器,或者是具备其他类型的语言转换功能的编译器。The compiler in the embodiment of the present disclosure can be software or hardware with the function of converting one language of the program into another language. For example, the compiler can be a software program with the compilation function, or it can also have the compilation function. hardware equipment. The compiler may be an assembler that converts assembly language into machine language, or a compiler with other types of language conversion capabilities.
其中,为了便于区分,以下将测试指令中各组成部分对应的特征数据对应的正确编译的数据称为参考编译数据,将待编译的测试指令或测试用例对应的正确编译的数据称为参考编译指令。Among them, in order to facilitate distinction, the correctly compiled data corresponding to the characteristic data corresponding to each component in the test instruction is called reference compilation data, and the correctly compiled data corresponding to the test instruction or test case to be compiled is called reference compilation instruction. .
如图1(a)所示,所述编译器的测试方式可以包括以下步骤:As shown in Figure 1(a), the compiler testing method may include the following steps:
S102、基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令;S102. Construct test cases and reference compilation instructions corresponding to the test cases based on the data related to the test instructions stored in the instruction database;
在步骤S102中,可以基于指令数据库中存储的与测试指令相关的数据构建测试用例以及测试用例对应的参考编译指令。其中,测试用例可以是单独的一条测试指令,也可以是由大量测试指令构建的测试文档。与测试指令有关的数据可以是各种可以确定测试指令的数据,以及各种可以确定测试指令对应的参考编译指令的数据。比如,在一些场景,该与测试指令有关的数据可以是完整的测试指令,以及该测试指令对应的参考编译指令,比如,可以直接在指令数据中存储多条测试指令以及每条测试指令对应的参考编译指令,然后直接根据测试指令构建测试用例。在一些场景,测试指令可以包括多个组成部分,比如,指令类型、控制域、指令地址等,其中,控制域为指令中包括的控制操作,比如,加法指令中通常包括四舍五入操作、饱和处理操作等,该与测试指令有关的数据可以是测试指令的各组成部分对应的特征数据,即各组成部分的具体内容(比如,组成部分为指令类型,则特征数据可以是加法指令、减法指令等),以及该特征数据对应的参考编译数据。比如,指令数据库中也可以存储各组成部分对应的特征数据以及该特征数据对应的参考编译数据,然后基于这些特征数据构建得到测试指令,进而基 于构建的测试指令构建测试用例,以及测试用例对应的参考编译指令。In step S102, a test case and a reference compilation instruction corresponding to the test case may be constructed based on the data related to the test instruction stored in the instruction database. Among them, a test case can be a single test instruction or a test document constructed from a large number of test instructions. The data related to the test instruction may be various data that can determine the test instruction, and various data that can determine the reference compilation instruction corresponding to the test instruction. For example, in some scenarios, the data related to the test instruction can be a complete test instruction and the reference compilation instruction corresponding to the test instruction. For example, multiple test instructions and the corresponding code of each test instruction can be directly stored in the instruction data. Refer to the compilation instructions and then build the test cases directly based on the test instructions. In some scenarios, the test instruction can include multiple components, such as instruction type, control domain, instruction address, etc., where the control domain is the control operation included in the instruction. For example, addition instructions usually include rounding operations and saturation processing operations. etc., the data related to the test instruction can be the characteristic data corresponding to each component of the test instruction, that is, the specific content of each component (for example, if the component is an instruction type, the characteristic data can be an addition instruction, a subtraction instruction, etc.) , and the reference compiled data corresponding to the feature data. For example, the instruction database can also store the characteristic data corresponding to each component and the reference compiled data corresponding to the characteristic data, and then construct the test instructions based on these characteristic data, and then based on Build test cases based on the built test instructions, and the reference compilation instructions corresponding to the test cases.
S104、利用待测试的编译器编译所述测试用例,得到目标编译指令;S104. Use the compiler to be tested to compile the test case and obtain the target compilation instruction;
在步骤S104中,在得到测试用例后,可以利用待测试的编译器对该测试用例进行编译,得到目标编译指令。In step S104, after obtaining the test case, the test case can be compiled using the compiler to be tested to obtain the target compilation instruction.
S106、基于所述测试用例对应的参考编译指令与所述目标编译指令的比对结果判定所述编译器是否存在异常。S106. Determine whether there is an exception in the compiler based on the comparison result between the reference compilation instruction corresponding to the test case and the target compilation instruction.
在步骤S106中,可以将编译器编译得到的目标编译指令与该测试用例对应的参考编译指令进行比对,如果两者一致,则说明编译器的编译结果正确,如果两者不一致,则说明编译器的编译器结果出错,编译器存在异常。In step S106, the target compilation instruction compiled by the compiler can be compared with the reference compilation instruction corresponding to the test case. If the two are consistent, it means that the compilation result of the compiler is correct. If the two are inconsistent, the compilation result is correct. The compiler result of the compiler is wrong and there is an exception in the compiler.
在一些实施例中,该测试用例可以是用于测试编译器的功能的测试用例,以下称为功能性测试用例。其中,每个功能性测试用例可以包括单条测试指令。一般可以通过多条功能性测试用例分别对编译器进行测试,以检测编译器的编译功能是否存在异常,比如,检测编译器是否会对某类指令错误编译,或者对指令中的某个控制操作错误编译,或者对指令中的某类地址错误编译。通常,为了对编译器的功能进行更加全面的测试,一般可以构建多个功能性测试用例,每个功能性测试用例包括一条测试指令,这些测试指令可以覆盖各种指令类型、控制操作和指令地址,以确保测试数据的全面性和完整性。In some embodiments, the test case may be a test case for testing the functionality of the compiler, hereinafter referred to as a functional test case. Each functional test case can include a single test instruction. Generally, the compiler can be tested separately through multiple functional test cases to detect whether there are abnormalities in the compiler's compilation function, for example, to detect whether the compiler will incorrectly compile certain types of instructions, or to detect certain control operations in the instructions. Incorrect compilation, or incorrect compilation of certain addresses in instructions. Usually, in order to conduct a more comprehensive test on the functionality of the compiler, multiple functional test cases can be constructed. Each functional test case includes a test instruction. These test instructions can cover various instruction types, control operations and instruction addresses. , to ensure the comprehensiveness and completeness of test data.
在一些实施例中,该测试用例可以是用于测试编译器的稳定性的测试用例,以下称稳定性测试用例,每个稳定性测试用例可以由多条测试指令拼接得到。目前,在对编译器进行测试时,通常只测试编译器的功能。但是即便在编译器的功能正常的情况下,也会存在待编译的数据量较大,导致编译器崩溃,无法正常工作的场景,因而,还可以对编译器的稳定性进行测试,以检测编译器在一次性编译大量的指令的情况下,是否会存在异常。在对编译器的稳定性进行测试时,可以利用大量的测试指令拼接得到一个或多个数据量较大的稳定性测试用例,用于测试编译器的稳定性。In some embodiments, the test case may be a test case used to test the stability of the compiler, hereinafter referred to as a stability test case, and each stability test case may be spliced by multiple test instructions. Currently, when testing a compiler, it is common to only test the functionality of the compiler. However, even when the compiler functions normally, there will be scenarios where the amount of data to be compiled is large, causing the compiler to crash and not work properly. Therefore, the stability of the compiler can also be tested to detect compilation Will there be any exceptions when the compiler compiles a large number of instructions at one time? When testing the stability of the compiler, a large number of test instructions can be used to splice together to obtain one or more stability test cases with a large amount of data, which can be used to test the stability of the compiler.
在一些实施例中,测试用例可以同时包括功能性测试用例和稳定性测试用例,即对编译器的上述两种性能进行测试。In some embodiments, the test cases may include both functional test cases and stability test cases, that is, testing the above two properties of the compiler.
由于稳定性测试用例是用于测试编译器的稳定性,即编译器在一次性处理大量数据量的情况,是否会出现程序崩溃的现象。因而,稳定性测试用例的数据量需要尽可能大,以得到准确的测试结果。在一些实施例中,稳定性测试用例可以符合以下一种或多种条件:比如,该条件可以是编译器编译该稳定性测试用例的时长大于预设时长,从而可以保证编译器运行较长时间后,仍不会出现异常。其中,预设时长可以基于实际情况灵活设置。该条件也可以是稳定性测试用例中包括的测试指令的数量可以大于预设数 量,比如,稳定性测试用例需通过至少1000条测试指令拼接得到。该条件也可以是稳定性测试用例的数据量大于预设数据量,比如,该稳定性测试用例的数据量大于1GB等。当然,以上只是示例性例子,实际在构建稳定性测试用例时,其评判标准也可以设置成其他标准,只要能够保证稳定性测试用例数据量较大,较复杂,能够准确的考量编译器的稳定性即可。Since the stability test case is used to test the stability of the compiler, that is, whether the program will crash when the compiler processes a large amount of data at one time. Therefore, the data volume of stability test cases needs to be as large as possible to obtain accurate test results. In some embodiments, the stability test case may meet one or more of the following conditions: for example, the condition may be that the time it takes for the compiler to compile the stability test case is longer than the preset time, thus ensuring that the compiler runs for a longer time. Afterwards, no exception will occur. Among them, the preset duration can be flexibly set based on actual conditions. The condition can also be that the number of test instructions included in the stability test case can be greater than the preset number. For example, stability test cases need to be spliced together with at least 1,000 test instructions. The condition may also be that the data amount of the stability test case is greater than the preset data amount, for example, the data amount of the stability test case is greater than 1GB, etc. Of course, the above are just illustrative examples. In fact, when constructing stability test cases, the evaluation criteria can also be set to other standards, as long as it can ensure that the stability test case data is large and complex, and can accurately consider the stability of the compiler. Just sex.
在一些实施例中,构建的测试用例包括功能性测试用例以及稳定性测试用例,即可以对编译器进行功能性测试和稳定性测试。在对编译器进行上述两种类型的测试时,可以先对编译器进行功能性测试,在确保编译器的功能不存在异常后,再进一步对编译器的稳定性进行测试。比如,在基于测试用例对应的参考编译指令与目标编译指令的比对结果判定编译器是否存在异常时,可以逐一获取每个功能性测试用例,利用编译器对该功能性测试用例进行编译后,得到该功能性测试用例对应的目标编译指令,然后将该目标编译指令与该功能性测试用例对应的参考编译指令进行比对,基于比对结果判定编译器的功能是否存在异常。通常,对编译器进行功能测试时,会采用多个功能性测试用例,以覆盖各种指令类型、各种控制操作和指令地址。因而可以遍历每个功能性测试用例,重复上面的测试步骤,以对编译器的功能进行全面的测试。In some embodiments, the built test cases include functional test cases and stability test cases, that is, the compiler can be tested for functionality and stability. When conducting the above two types of tests on the compiler, you can first conduct a functional test on the compiler, and then further test the stability of the compiler after ensuring that there are no abnormalities in the function of the compiler. For example, when determining whether there is an exception in the compiler based on the comparison results between the reference compilation instructions corresponding to the test cases and the target compilation instructions, you can obtain each functional test case one by one, and use the compiler to compile the functional test case. The target compilation instruction corresponding to the functional test case is obtained, and then the target compilation instruction is compared with the reference compilation instruction corresponding to the functional test case, and based on the comparison result, it is determined whether there is an abnormality in the function of the compiler. Typically, when functionally testing a compiler, multiple functional test cases are used to cover various instruction types, various control operations, and instruction addresses. Therefore, each functional test case can be traversed and the above test steps can be repeated to comprehensively test the functionality of the compiler.
在利用所有功能性测试对编译器进行测试后,如果未发现编译器存在异常,则进一步对编译器的稳定性进行测试。比如,可以利用编译器逐一对各稳定性测试用例进行编译,得到该稳定性测试用例对应的目标编译指令,并将该目标编译指令与该稳定性测试用例对应的参考编译指令进行比对,基于比对结果判定该编译器的稳定性是否存在异常。After testing the compiler using all functional tests, if no exceptions are found in the compiler, the stability of the compiler will be further tested. For example, the compiler can be used to compile each stability test case one by one to obtain the target compilation instruction corresponding to the stability test case, and compare the target compilation instruction with the reference compilation instruction corresponding to the stability test case, based on The comparison results determine whether there are any abnormalities in the stability of the compiler.
通常,每条测试指令都可以有多个组成部分构成,在一些实施例中,这些组成部分可以是指令类型、控制域、指令地址中的一种或多种。其中,指令地址包括测试指令的源地址以及测试指令的目标地址。比如,如图1(b)所示,测试指令可以包括3个组成部分(组成部分1-3),这3个组成部分分别对应指令类型、控制域、指令地址(源地址以及目标地址)。其中,指令类型可以是加法指令、减法指令、数据传输指令、或运算指令、与运算指令等等,控制域表示测试指令包括的控制操作,以算数类的处理类型为例,其包含的控制操作可以是四舍五入操作、饱和处理等等。测试指令的源地址可以是存储该指令待处理的数据的地址,测试指令的目标地址可以是存储该指令处理后的数据的地址。Generally, each test instruction can be composed of multiple components. In some embodiments, these components can be one or more of the instruction type, control domain, and instruction address. Among them, the instruction address includes the source address of the test instruction and the target address of the test instruction. For example, as shown in Figure 1(b), the test instruction can include three components (components 1-3), which respectively correspond to the instruction type, control domain, and instruction address (source address and target address). Among them, the instruction type can be an addition instruction, a subtraction instruction, a data transfer instruction, an OR operation instruction, an AND operation instruction, etc. The control domain represents the control operations included in the test instruction. Taking the arithmetic processing type as an example, the control operations it contains It can be rounding operations, saturation processing, etc. The source address of the test instruction may be an address where the data to be processed by the instruction is stored, and the target address of the test instruction may be an address where the data processed by the instruction is stored.
在指令数据库中存储测试指令时,可以直接存储多条完整的测试指令,在对编译器进行测试时,可以直接获取每条测试指令。但是此种存储方式会占用较大的存储内 存,且后续对指令数据库中的测试指令进行扩展或修改时比较繁琐。所以,在一些实施例中,指令数据库中存储的与测试指令相关的数据可以是构成测试指令的一个或多个组成部分对应的一条或多条特征数据以及这些特征数据对应的参考编译数据,比如,组成部分可以是指令类型,特征数据可以是加法指令、减法指令等。其中,每个组成部分对应的特征数据与该多个组成部分中的其余组成部分对应的特征数据关联存储。比如,以指令类型为例,加法指令有其对应的控制操作,数据传输指令也有其对应的控制操作,因而可以将各组成部分中存在关联的特征数据关联起来,方便在构建测试指令时可以利用关联存储的特征数据构建测试指令。When storing test instructions in the instruction database, multiple complete test instructions can be directly stored. When testing the compiler, each test instruction can be directly obtained. However, this storage method will occupy a large amount of storage space. storage, and subsequent expansion or modification of the test instructions in the instruction database is more cumbersome. Therefore, in some embodiments, the data related to the test instructions stored in the instruction database may be one or more pieces of characteristic data corresponding to one or more components that constitute the test instruction and the reference compiled data corresponding to these characteristic data, such as , the component can be an instruction type, and the characteristic data can be an addition instruction, a subtraction instruction, etc. Wherein, the characteristic data corresponding to each component is stored in association with the characteristic data corresponding to the remaining components in the plurality of components. For example, taking the instruction type as an example, the addition instruction has its corresponding control operation, and the data transfer instruction also has its corresponding control operation. Therefore, the associated characteristic data in each component can be associated, which can be used when constructing test instructions. Construct test instructions by associating stored feature data.
例如,假设测试指令的组成部分包括指令类型、控制域、指令地址,其中,测试指令的类型对应多条特征数据,每条特征数据表示一种指令类型,比如,特征数据可以是加法指令、减法指令等。测试指令的控制域也可以对应多条特征数据,每条特征数据表示一种控制操作,比如,特征数据可以是四舍五入处理、饱和处理等。指令地址包括测试指令的源地址以及测试指令的目标地址,指令地址也可以对应多条特征数据,每个特征数据表示一组地址。因而,可以在指令数据库中分别存储指令类型列表,该指令类型列表中包括多种指令类型,以及每种指令类型对应参考编译数据;控制域列表,该控制域列表中包括多种控制操作,以及每种控制操作对应的参考编译数据;以及指令地址列表,该指令地址列表包括多组地址,以及每组地址对应的参考编译数据,其中,每组地址中包括一个源地址和一个目标地址。在一些实施例中,针对每种指令类型,比如,加法指令,其涉及的控制操作的种类是一定的,比如,只能是和加法处理有关的控制操作。并且在指令类型和控制操作确定后,其能够处理的数据的类型也是一定的,即其能够处理的数据为某个地址范围内的数据,进而其对应的指令地址也可以确定。因而,在指令数据库中存储上述数据时,针对每个指令类型,可以将该指令类型与其相关的多种控制操作、源地址、目标地址关联存储,以便在基于这些特征数据构建指令时,可以基于特征数据的关联关系选取存在关联的指令类型、控制操作、源地址以及目标地址,构建得到正确的测试指令。For example, assume that the components of the test instruction include instruction type, control domain, and instruction address. The type of test instruction corresponds to multiple pieces of characteristic data. Each piece of characteristic data represents an instruction type. For example, the characteristic data can be addition instructions, subtraction instructions, etc. instructions etc. The control domain of the test instruction can also correspond to multiple pieces of feature data. Each piece of feature data represents a control operation. For example, the feature data can be rounding processing, saturation processing, etc. The instruction address includes the source address of the test instruction and the target address of the test instruction. The instruction address can also correspond to multiple pieces of feature data, and each feature data represents a set of addresses. Therefore, an instruction type list including multiple instruction types and reference compiled data corresponding to each instruction type; a control domain list including multiple control operations, and Reference compilation data corresponding to each control operation; and an instruction address list, which includes multiple sets of addresses, and reference compilation data corresponding to each set of addresses, where each set of addresses includes a source address and a target address. In some embodiments, for each instruction type, such as an addition instruction, the type of control operations involved is certain, for example, it can only be control operations related to addition processing. And after the instruction type and control operation are determined, the type of data it can process is also certain, that is, the data it can process is data within a certain address range, and its corresponding instruction address can also be determined. Therefore, when storing the above data in the instruction database, for each instruction type, the instruction type can be stored in association with its various control operations, source addresses, and target addresses, so that when constructing instructions based on these characteristic data, it can be based on The correlation relationship of the characteristic data selects the associated instruction type, control operation, source address and target address, and constructs the correct test instruction.
此外,通过采用上述方法在指令数据库中存储测试指令,相比于直接存储完整的测试指令,可以减小数据量,并且,在后续需要对指令数据中存储的测试指令进行增删改等变动时也更加便捷。In addition, by using the above method to store test instructions in the instruction database, compared with directly storing complete test instructions, the amount of data can be reduced, and it is also possible to add, delete, or modify test instructions stored in the instruction data later when it is necessary to add, delete, or modify them. More convenient.
在一些实施例中,指令数据库存储的可以是测试指令各组成部分对应的特征数据以及特征数据对应的参考编译数据。在基于指令数据库中存储的测试指令相关的数据构建功能性测试用例以及功能性测试用例对应的参考编译指令时,可以遍历多个组成部 分对应的每条特征数据,针对任一组成部分对应的任一条特征数据,以下将该条特征数据称为目标特征数据,可以分别从多个组成部分中的其余组成部分中确定与目标特征数据关联存储的关联特征数据,然后基于该目标特征数据和该关联特征数据生成测试指令,并基于该目标特征数据对应的参考编译数据以及该关联特征数据对应的参考编译数据得到测试指令对应的参考编译指令。在生成测试指令后,可以将生成的每个测试指令作为一个功能性测试用例,将每个测试指令对应的参考编译指令作为该功能性测试用例对应的参考编译指令,从而可以得到用于对编译器的功能进行测试的多个功能性测试用例。In some embodiments, the instruction database may store characteristic data corresponding to each component of the test instruction and reference compilation data corresponding to the characteristic data. When constructing functional test cases and reference compilation instructions corresponding to functional test cases based on test instruction-related data stored in the instruction database, multiple components can be traversed. Each piece of characteristic data corresponding to each component. For any piece of characteristic data corresponding to any component, this piece of characteristic data is referred to as the target characteristic data in the following. The target characteristic data can be determined from the remaining components among the multiple components. Associate the stored associated feature data, then generate a test instruction based on the target feature data and the associated feature data, and obtain the reference compilation corresponding to the test instruction based on the reference compilation data corresponding to the target feature data and the reference compilation data corresponding to the associated feature data. instruction. After generating test instructions, each generated test instruction can be used as a functional test case, and the reference compilation instructions corresponding to each test instruction can be used as the reference compilation instructions corresponding to the functional test case, so that the compilation instructions can be obtained. Multiple functional test cases to test the functionality of the processor.
例如,针对指令类型中的一条目标特征数据(例如为“加法指令”),可以从指令数据库中存储的控制域和指令地址两个组成部分中确定和“加法指令”关联存储的多个“控制操作”和多个“地址”,然后可以从该多个“控制操作”和多个“地址”中随机选取一个“控制操作”和一组“地址”,与上述“加法指令”的目标特征数据构建一条测试指令。For example, for a piece of target characteristic data in an instruction type (for example, an "addition instruction"), multiple "controls" stored in association with the "addition instruction" can be determined from the two components of the control domain and instruction address stored in the instruction database. Operation" and multiple "addresses", and then a "control operation" and a set of "addresses" can be randomly selected from the multiple "control operations" and multiple "addresses", and the target characteristic data of the above-mentioned "addition instruction" Build a test directive.
通过遍历指令数据库中的每个组成部分的每条特征数据,可以构建得到覆盖各种指令类型、控制操作和指令地址的多条测试指令,从而构建的功能性测试用例也更加全面,得到更加准确的测试结果。在一些实施例中,也可以不遍历指令数据库中的每个组成部分的每条特征数据,只根据需求获取指定数量的测试用例,在本公开中对此不做限定。By traversing each feature data of each component in the instruction database, multiple test instructions covering various instruction types, control operations and instruction addresses can be constructed, so that the functional test cases constructed are more comprehensive and more accurate. test results. In some embodiments, it is not necessary to traverse each feature data of each component in the instruction database, but only obtain a specified number of test cases according to requirements, which is not limited in this disclosure.
在一些实施例中,指令数据库存储的可以是测试指令各组成部分对应的特征数据以及特征数据对应的参考编译数据,在基于指令数据库中存储的测试指令相关的数据构建稳定性测试用例以及稳定性测试用例对应的参考编译指令时,可以针对任一组成部分中的任一条目标特征数据,分别从多个组成部分中的其余组成部分中确定与该目标特征数据关联存储的关联特征数据,然后基于目标特征数据和关联特征数据生成测试指令。并基于目标特征数据对应的参考编译数据以及关联特征数据对应的参考编译数据得到测试指令对应的参考编译指令。然后可以利用生成的多个测试指令拼接得到稳定性测试用例,利用多个测试指令对应的参考编译指令,拼接得到该稳定性测试用例对应的参考编译指令。In some embodiments, the instruction database may store characteristic data corresponding to each component of the test instruction and reference compiled data corresponding to the characteristic data. Stability test cases and stability test cases are constructed based on the test instruction-related data stored in the instruction database. When the reference compilation instruction corresponding to the test case is used, for any piece of target feature data in any component, the associated feature data stored in association with the target feature data can be determined from the remaining components in multiple components, and then based on The target characteristic data and associated characteristic data generate test instructions. And based on the reference compilation data corresponding to the target characteristic data and the reference compilation data corresponding to the associated characteristic data, the reference compilation instruction corresponding to the test instruction is obtained. Then the multiple generated test instructions can be used to splice to obtain a stability test case, and the reference compilation instructions corresponding to the multiple test instructions can be used to splice to obtain the reference compilation instructions corresponding to the stability test case.
由此,可以基于指令数据库中存储的相互关联的特征数据随机构建多条测试指令,并利用这些测试指令拼接得到数据量较大的稳定性测试用例。As a result, multiple test instructions can be randomly constructed based on the interrelated feature data stored in the instruction database, and these test instructions can be used to splice together to obtain stability test cases with a large amount of data.
在一些实施例中,由于测试指令的各个组成部分之间是相互关联的,比如,指令类型会影响控制操作的选择,而指令类型和控制操作又会进一步影响指令地址的选择。即这多个组成部分之间的关系是相互关联的。所以,在指令数据库中存储与测试指令相 关的数据时,可以采用树型结构对这些数据进行存储。针对任一树型结构,其层数可以和测试指令组成部分的数量一致,比如,测试指令包括指令类型、控制域、指令地址三个组成部分,则树型结构可以包括三层,即树型结构包括根节点、根节点分支出来的子节点、以及各子节点分支出来的叶子节点,其中,树型结构的根节点可以用于存储指令类型中的任一条目标特征数据以及该目标特征数据对应的参考编译数据。树型结构的子节点至树型结构的叶子节点用于顺次存储控制域中与目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,以及指令地址中与目标特征数据及第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。In some embodiments, since various components of the test instructions are interrelated, for example, the instruction type will affect the selection of the control operation, and the instruction type and the control operation will further affect the selection of the instruction address. That is, the relationship between these multiple components is interrelated. Therefore, the instructions corresponding to the test instructions are stored in the instruction database. When it comes to related data, these data can be stored in a tree structure. For any tree structure, the number of layers can be consistent with the number of components of the test instruction. For example, if the test instruction includes three components: instruction type, control domain, and instruction address, then the tree structure can include three layers, that is, tree structure. The structure includes a root node, child nodes branched from the root node, and leaf nodes branched from each child node. The root node of the tree structure can be used to store any target feature data in the instruction type and the corresponding target feature data. Reference compiled data. The child nodes of the tree structure to the leaf nodes of the tree structure are used to sequentially store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, as well as the instruction address and The second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data.
如图1(c)所示,为一种采用树型结构存储测试指令的示意图,其中,树型结构的根节点可以用于存储指令类型中的一条特征数据,及其对应的参考编译数据。比如,该特征数据可以是“加法指令”,该参考编译数据可以是“加法指令”对应的机器码。其中,从该根节点又可以分支出来多个子节点,每个子节点用于存储和“加法指令”关联的控制操作,以及该控制操作对应的参考编译数据,比如,可以有三个子节点,每个子节点分别存储“四舍五入模式”及其机器码、“立即数模式”及其机器码、“寄存器模式”及其机器码等,然后针对每个子节点,又可以分支出来多个叶子节点,每个叶子节点则用于存储与该根节点、分支出来该叶子节点的子节点中存储的特征数据相关联的指令地址及其机器码,比如,与“加法指令”、“四舍五入模式”相关联的多组指令地址,“源地址1、目标地址1”、“源地址2、目标地址2”、“源地址3、目标地址3”等。在一些实施例中,如果与测试指令相关的数据采用树型结构存储,在构建测试用例时,可以获取树型结构中从根节点到叶子节点的任一路径中的各节点中存储的特征数据,以及这些特征数据各自对应的参考编译数据,然后将各节点存储的特征数据拼接得到一条测试指令,将各节点存储的特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令,然后可以基于得到的测试指令构建测试用例以及基于该测试指令对应的参考编译指令构建测试用例对应的参考编译指令。比如,可以将得到的每一条测试指令分别作为一个测试用例,也可以将多条测试指令拼接成一个测试用例。As shown in Figure 1(c), it is a schematic diagram of using a tree structure to store test instructions. The root node of the tree structure can be used to store a feature data in the instruction type and its corresponding reference compiled data. For example, the characteristic data may be an "addition instruction", and the reference compiled data may be the machine code corresponding to the "addition instruction". Among them, multiple child nodes can be branched from the root node. Each child node is used to store the control operation associated with the "addition instruction" and the reference compiled data corresponding to the control operation. For example, there can be three child nodes, each child node Store "rounding mode" and its machine code, "immediate mode" and its machine code, "register mode" and its machine code, etc. separately, and then for each child node, multiple leaf nodes can be branched out, each leaf node It is used to store the instruction address and its machine code associated with the characteristic data stored in the root node and the child nodes branching out of the leaf node, for example, multiple sets of instructions associated with "addition instructions" and "rounding mode" Address, "source address 1, destination address 1", "source address 2, destination address 2", "source address 3, destination address 3", etc. In some embodiments, if the data related to the test instructions is stored in a tree structure, when building the test case, the feature data stored in each node in any path from the root node to the leaf node in the tree structure can be obtained , and the reference compilation data corresponding to each of these feature data, and then splicing the feature data stored in each node to obtain a test instruction, splicing the reference compilation data corresponding to the feature data stored in each node to obtain the reference compilation instruction corresponding to the test instruction, and then A test case may be constructed based on the obtained test instruction and a reference compilation instruction corresponding to the test case may be constructed based on the reference compilation instruction corresponding to the test instruction. For example, each obtained test instruction can be used as a test case, or multiple test instructions can be spliced into one test case.
比如,如图1(d)所示,黑色框框选的“根节点-子节点-叶子节点”即为树型结构中从根节点到叶子节点的一条路径,可以获取该路径中各个节点存储的特征数据,即“加法指令”、“四舍五入模式”、“源地址1,目标地址1”,拼接得到一条测试指令,以及获取这些特征数据对应的机器码并将其拼接得到该测试指令对应的参考编译指令。 For example, as shown in Figure 1(d), the "root node-child node-leaf node" selected in the black box is a path from the root node to the leaf node in the tree structure, and the information stored in each node in the path can be obtained. The characteristic data, namely "addition instruction", "rounding mode", "source address 1, target address 1", is spliced to obtain a test instruction, and the machine code corresponding to these characteristic data is obtained and spliced to obtain the reference corresponding to the test instruction. Compilation directives.
在一些实施例中,在基于测试用例对应的参考编译指令与目标编译指令的比对结果,判定编译器存在异常之后,还可以进一步输出测试报告,其中,为了方便研发人员定位异常,测试报告中可以包括以下一种或多种信息:异常的类型、出现异常的测试指令、出现异常的组成部分,其中,异常的类型包括功能异常或稳定性异常,组成部分可以包括指令类型、控制域、指令地址。In some embodiments, after determining that there is an exception in the compiler based on the comparison results between the reference compilation instructions corresponding to the test cases and the target compilation instructions, a test report can be further output. In order to facilitate the developer to locate the exception, the test report It can include one or more of the following information: the type of exception, the test instruction in which the exception occurs, and the component where the exception occurs. The type of exception includes functional abnormality or stability abnormality. The components can include instruction type, control domain, and instruction. address.
为了进一步介绍本公开提供的编译器的测试方法,以下结合一个具体的实施例加以解释。In order to further introduce the compiler testing method provided by the present disclosure, it will be explained below in conjunction with a specific embodiment.
程序运行过程中,需要将对应的高级语言编译成成汇编语言,进而通过汇编器将对应的汇编语言转换成机器码,然后将机器码给到底层芯片进行执行。如果编译器的编译结果出错,会导致程序运行异常。汇编器的编译结果对整个程序运行至关重要,因而,本实施例中提供了一种汇编器的测试方法。During the running of the program, the corresponding high-level language needs to be compiled into assembly language, and then the corresponding assembly language is converted into machine code through the assembler, and then the machine code is given to the underlying chip for execution. If the compiler's compilation result is wrong, it will cause the program to run abnormally. The compilation result of the assembler is crucial to the operation of the entire program. Therefore, this embodiment provides an assembler testing method.
对于汇编器而言,其涉及的指令类型十分复杂,为了可以实现自动化的对汇编器进行更为准确和全面的测试。可以预先设置一个指令数据库,该指令数据库的架构如图2所示,由于汇编指令通常可以分割成指令类型、控制域、指令地址三个组成部分,其中,指令类型可以对应一个指令类型列表,该列表包括了汇编指令的各种指令类型,以及各种指令类型对应机器码,同理,控制域也可以对应一个控制域列表,该列表包括了汇编指令的各种控制操作,以及各种控制操作对应机器码,指令地址也可以对应一个地址列表,该列表中包括指令涉及的数据的源地址和目标地址,以及各地址对应的机器码。其中,上述三个列表中的每个列表中的每条特征数据与其他的列表中的一条或多条特征数据关联存储。比如,如图2中的“加法指令”这一指令类型,该指令类型与控制操作“四舍五入”、“饱和处理”关联,且与指令地址中的“源地址1,目标地址1”、“源地址2,目标地址2”、“源地址3,目标地址3”关联存储,因而,在构建测试指令时,可以随机选取一个控制操作“饱和处理”、一组指令地址“源地址1,目标地址1”构建一条测试指令。For the assembler, the instruction types involved are very complex. In order to achieve more accurate and comprehensive testing of the assembler, it is possible to achieve automation. An instruction database can be set up in advance. The architecture of the instruction database is shown in Figure 2. Since assembly instructions can usually be divided into three components: instruction type, control domain, and instruction address, the instruction type can correspond to an instruction type list. The list includes various instruction types of assembly instructions, and the machine codes corresponding to various instruction types. In the same way, the control domain can also correspond to a control domain list. This list includes various control operations of assembly instructions, as well as various control operations. Corresponding to the machine code, the instruction address can also correspond to an address list, which includes the source address and destination address of the data involved in the instruction, as well as the machine code corresponding to each address. Each piece of feature data in each of the above three lists is stored in association with one or more pieces of feature data in the other lists. For example, the instruction type "addition instruction" in Figure 2 is associated with the control operations "rounding" and "saturation processing", and is associated with the "source address 1, target address 1" and "source address" in the instruction address. Address 2, target address 2" and "source address 3, target address 3" are stored in association. Therefore, when building a test instruction, you can randomly select a control operation "saturation processing" and a set of instruction addresses "source address 1, target address 1" Build a test instruction.
在对汇编器进行测试时,可以针对指令类型、指令控制域、指令地址三个组成部分中的任一组成部分,遍历该组成部分中的各特征数据,针对每条特征数据,可以从其余两个组成部分的特征数据中确定该特征数据的关联特征数据,然后从其余两个组成部分各自对应的关联特征数据中各选取一条,以构建一个测试指令。然后可以遍历各组成部分的各条特征数据,重复上述步骤,即可以得到多条测试指令,以及每条测试指令对应参考机器码。When testing the assembler, you can traverse each feature data in this component for any of the three components: instruction type, instruction control domain, and instruction address. For each piece of characteristic data, you can select from the remaining two components. Determine the associated feature data of the feature data from the feature data of each component, and then select one piece of associated feature data corresponding to the other two components to construct a test instruction. Then you can traverse each feature data of each component and repeat the above steps to get multiple test instructions and the reference machine code corresponding to each test instruction.
然后可以利用待测的汇编器逐一对每条测试指令进行编译,得到目标编译指令, 并对参考编译指令和目标编译指令进行比对,基于比对结果确定汇编器的功能是否出现异常。Then you can use the assembler to be tested to compile each test instruction one by one to obtain the target compilation instruction. And compare the reference compilation instructions and the target compilation instructions, and determine whether there is an abnormality in the function of the assembler based on the comparison results.
如果汇编器功能未出现异常,则可以利用多个测试指令拼接得到测试文档,其中,该测试文档中测试指令的数量大于预设数量。然后可以利用该测试文档对汇编器的稳定性进行测试,判定汇编器是否存在异常。If there is no abnormality in the assembler function, a test document can be obtained by splicing multiple test instructions, wherein the number of test instructions in the test document is greater than the preset number. This test document can then be used to test the stability of the assembler and determine whether there are abnormalities in the assembler.
如果汇编器出现异常,则可以输出异常测试报告,报告中可以指示以下信息:异常为哪种类型的异常、出现异常的测试指令、以及是测试指令的哪个组成部分出现异常,方便研发人员定位异常并解决。If an exception occurs in the assembler, an exception test report can be output. The report can indicate the following information: what type of exception is the exception, the test instruction in which the exception occurred, and which component of the test instruction caused the exception, which facilitates developers to locate the exception. and solved.
其中,不难理解,上述各实施例中的描述的方案在不存在冲突的情况,可以进行组合,本公开实施例中不一一例举。Among them, it is not difficult to understand that the solutions described in the above embodiments can be combined if there is no conflict, and are not listed one by one in the embodiments of this disclosure.
通常在对编译器进行测试时,需要用到大量的测试指令。测试指令一般由多个组成部分构成,比如,通常测试指令可以由指令类型、控制域、指令地址三个部分组成。在存储的过程中,为了可以减少存储的数据量,且方便对存储的测试指令进行改动,可以单独存储测试指令各组成部分对应的特征数据以及特征数据对应参考编译数据,并将不同组成部分中存在关联的特征数据关联存储,从而在生成测试指令时,可以获取各组成部分中存在关联的特征数据,拼接得到测试指令,以及测试指令对应的参考编译指令,通过这种方式也可以生成可以更加全面、覆盖各种类型的测试指令。Usually when testing a compiler, a large number of test instructions are needed. Test instructions generally consist of multiple components. For example, usually test instructions can be composed of three parts: instruction type, control domain, and instruction address. During the storage process, in order to reduce the amount of stored data and facilitate changes to the stored test instructions, the characteristic data corresponding to each component of the test instruction and the reference compiled data corresponding to the characteristic data can be stored separately, and different components can be stored in The associated feature data is stored in an associated manner, so that when generating a test instruction, the associated feature data in each component can be obtained, spliced together to obtain the test instruction, and the reference compilation instruction corresponding to the test instruction. In this way, it is also possible to generate more Comprehensive, covering various types of test instructions.
由于测试指令的各个组成部分之间是相互关联的,比如,指令类型会影响控制操作的选择,而指令类型和控制操作又会进一步影响指令地址的选择。为了在基于存储的各组成部分生成测试指令时,不会出现将没有联系的组成部分拼接,得到错误的测试指令,以下提供了一种测试指令的存储方法,具体如图3所示,可以包括以下步骤:Since the various components of the test instructions are interrelated, for example, the instruction type will affect the selection of the control operation, and the instruction type and control operation will further affect the selection of the instruction address. In order to avoid splicing unrelated components and obtaining wrong test instructions when generating test instructions based on each stored component, the following provides a storage method for test instructions, as shown in Figure 3, which can include Following steps:
步骤1:获取待存储的与测试指令相关的数据,所述与测试指令相关的数据包括测试指令的多个组成部分中各组成部分对应的多条特征数据,以及每条特征数据对应的参考编译数据;所述多个组成部分包括指令类型、控制域以及指令地址,所述控制域表示所述测试指令包括的控制操作;Step 1: Obtain the data related to the test instruction to be stored. The data related to the test instruction includes multiple feature data corresponding to each component of the multiple components of the test instruction, and the reference compilation corresponding to each feature data. Data; the plurality of components include an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
比如,如图3所示,测试指令包括指令类型、控制域以及指令地址三个组成部分,每个组成部分可以包括多条特征数据,每条特征数据有对应的参考编译数据。比如,指令类型可以包括加法指令、减法指令、数据传输指令等多种类型。For example, as shown in Figure 3, the test instruction includes three components: instruction type, control domain, and instruction address. Each component can include multiple pieces of feature data, and each piece of feature data has corresponding reference compiled data. For example, instruction types may include addition instructions, subtraction instructions, data transfer instructions, and other types.
步骤2:通过树型结构存储所述与测试指令相关的数据,其中,任一树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点至所述树型结构的叶子节点用于顺次存储所述控制域 中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,以及所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。Step 2: Store the data related to the test instructions through a tree structure, where the root node of any tree structure is used to store a piece of target feature data in the instruction type and the reference compiled data corresponding to the target feature data. , the child nodes of the tree structure to the leaf nodes of the tree structure are used to store the control domain in sequence The first associated feature data associated with the target feature data and the reference compiled data corresponding to the first associated feature data, and the third associated feature data associated with the target feature data and the first associated feature data in the instruction address Two associated feature data and reference compiled data corresponding to the second associated feature data.
比如,如图3中,树型结构可以包括根节点-子节点-叶子结点三层,针对指令类型中任一条目标特征数据A1(比如,加法指令)及其参考编译数据,可以存储于一个树型结构的根节点中,然后确定控制域中和该目标特征数据A1存在关联的第一关联特征数据B1、B2、B3(比如,四舍五入、饱和处理、立即数模式等),及其各自的参考编译数据,然后存储在根节点分支出来的各子节点中。然后针对每个子节点分支出来的叶子节点,可以从指令地址中确定与该根节点存储的目标特征数据A1,以及分支出该叶子节点的子节点中存储的第一特征数据相关联的第二关联特征数据,比如,与目标特征数据A1、第一关联特征数据B1相关联的第二关联特征数据C1、C2、C3(比如,三组地址),及其各自的参考编译数据,然后存储在从第一关联特征数据B1所在的子节点分支出来的各叶子节点中。即树型结构中从根节点至叶子节点中任一路径中的各节点存储的特征数据即可构成一条测试指令。For example, as shown in Figure 3, the tree structure can include three levels: root node - child node - leaf node. Any target feature data A1 (for example, addition instruction) in the instruction type and its reference compiled data can be stored in a In the root node of the tree structure, then determine the first associated feature data B1, B2, B3 in the control domain that are associated with the target feature data A1 (for example, rounding, saturation processing, immediate mode, etc.), and their respective Reference compiled data is then stored in each child node branched from the root node. Then for each leaf node that branches out from the child node, the second association associated with the target feature data A1 stored in the root node and the first feature data stored in the child node that branches out from the leaf node can be determined from the instruction address. Feature data, such as second associated feature data C1, C2, C3 (for example, three sets of addresses) associated with target feature data A1, first associated feature data B1, and their respective reference compiled data are then stored in the slave In each leaf node branched from the child node where the first associated feature data B1 is located. That is, the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure can constitute a test instruction.
其中,该测试指令存储方法的具体实施细节可参考上述编译方法中实施例的描述,在此不再重复赘述。For specific implementation details of the test instruction storage method, please refer to the description of the embodiment in the above compilation method, and will not be repeated here.
本公开还提供一种测试指令的存储结构,所述存储结构包括:树型结构;The present disclosure also provides a storage structure of test instructions, where the storage structure includes: a tree structure;
所述树型结构用于存储与测试指令相关的数据;所述与测试指令相关的数据包括测试指令的多个组成部分中各组成部分对应的多条特征数据,以及每条特征数据对应的参考编译数据;所述多个组成部分包括指令类型、控制域以及指令地址,所述控制域表示所述测试指令包括的控制操作;The tree structure is used to store data related to test instructions; the data related to test instructions includes multiple pieces of characteristic data corresponding to each component of the multiple components of the test instruction, and a reference corresponding to each piece of characteristic data. Compile data; the plurality of components include an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
其中,所述树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点至所述树型结构的叶子节点用于顺次存储所述控制域中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,以及所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。Wherein, the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compilation data corresponding to the target feature data, and the child nodes of the tree structure to the leaves of the tree structure The node is used to sequentially store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, as well as the target feature data and the reference compilation data corresponding to the first associated feature data in the instruction address. The second associated feature data associated with the first associated feature data and the reference compiled data corresponding to the second associated feature data.
其中,该测试指令存储结构的具体实施细节可参考上述编译方法中实施例的描述,在此不再重复赘述。For specific implementation details of the test instruction storage structure, reference can be made to the description of the embodiment in the above compilation method, and the details will not be repeated here.
此外,本公开还提供了一种测试用例的生成方法,用于生成测试编译器的测试用例,其中构建测试用例的测试指令可以采用上述存储结构存储。测试用例的具体生成 过程可以包括以下步骤:In addition, the present disclosure also provides a test case generation method for generating test cases for testing the compiler, in which the test instructions for constructing the test cases can be stored using the above-mentioned storage structure. Specific generation of test cases The process can include the following steps:
获取树型结构中从根节点至叶子节点的任一路径中各节点存储的特征数据,以及所述特征数据对应的参考编译数据;Obtain the feature data stored in each node in any path from the root node to the leaf node in the tree structure, and the reference compiled data corresponding to the feature data;
将各节点存储的特征数据拼接得到一条测试指令,将各特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令;Splice the characteristic data stored in each node to obtain a test instruction, and splice the reference compilation data corresponding to each characteristic data to obtain the reference compilation instruction corresponding to the test instruction;
基于得到的测试指令生成测试用例,以及基于所述测试指令对应的参考编译指令生成所述测试用例对应的参考编译指令。Generate test cases based on the obtained test instructions, and generate reference compilation instructions corresponding to the test cases based on reference compilation instructions corresponding to the test instructions.
其中,具体生成测试用例的过程可参考上述编译方法中各实施例中的描述,在此不再赘述。For the specific process of generating test cases, reference may be made to the descriptions in the above embodiments of the compilation method, which will not be described again here.
通过这种方式,可以自动生成用于对编译器进行测试的测试用例,且可以避免测试用例中的测试指令出现错误,提高对编译器进行测试的效率和准确度。相应的,本公开实施例还提供了一种编译器的测试装置,如图4所示,所述装置包括:In this way, test cases for testing the compiler can be automatically generated, errors in the test instructions in the test cases can be avoided, and the efficiency and accuracy of testing the compiler can be improved. Correspondingly, the embodiment of the present disclosure also provides a compiler testing device, as shown in Figure 4, the device includes:
构建模块41,用于基于指令数据库中存储的与测试指令相关的数据构建测试用例,以及所述测试用例对应的参考编译指令;The construction module 41 is used to construct test cases based on the data related to the test instructions stored in the instruction database, and the reference compilation instructions corresponding to the test cases;
编译模块42,用于利用待测试的编译器编译所述测试用例,得到目标编译指令;The compilation module 42 is used to compile the test case using the compiler to be tested to obtain the target compilation instructions;
判定模块43,用于基于所述参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常。其中,上述装置执行编译器的测试方法的具体步骤可以参考上述方法实施例中的描述,在此不再赘述。The determination module 43 is configured to determine whether there is an exception in the compiler based on the comparison result between the reference compilation instruction and the target compilation instruction. For the specific steps of the above device to execute the compiler testing method, reference can be made to the description in the above method embodiments, which will not be described again here.
相应的,本公开实施例还提供了一种测试指令的存储装置,所述装置包括:Correspondingly, embodiments of the present disclosure also provide a storage device for test instructions, where the device includes:
获取模块,用于获取待存储的与测试指令相关的数据,所述与测试指令相关的数据包括测试指令的多个组成部分中各组成部分对应的特征数据以及所述特征数据对应的参考编译数据;所述多个组成部分包括指令类型、控制域以及指令地址,所述控制域表示所述测试指令包括的控制操作;An acquisition module, used to acquire data related to the test instructions to be stored. The data related to the test instructions include characteristic data corresponding to each component of the multiple components of the test instruction and reference compiled data corresponding to the characteristic data. ; The plurality of components include an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
存储模块,用于通过树型结构存储所述与测试指令相关的数据,其中,任一树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点用于存储所述控制域中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,所述树型结构的叶子节点用于存储所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。A storage module configured to store the data related to the test instructions through a tree structure, where the root node of any tree structure is used to store a piece of target feature data in the instruction type and a reference corresponding to the target feature data. Compiled data, the child nodes of the tree structure are used to store the first associated feature data associated with the target feature data in the control domain and the reference compiled data corresponding to the first associated feature data, the tree structure The leaf node is used to store the second associated feature data associated with the target feature data and the first associated feature data and the reference compiled data corresponding to the second associated feature data in the instruction address.
其中,上述装置执行测试指令的存储方法的具体步骤可以参考上述方法实施例中的描述,在此不再赘述。 For the specific steps of the method for storing test instructions executed by the above device, reference may be made to the description in the above method embodiments, which will not be described again here.
相应的,本公开实施例还提供了一种测试用例的生成装置,所述测试用例用于测试编译器,构建所述测试用例的测试指令通过上述实施例中描述的存储方法存储,所述装置包括:Correspondingly, embodiments of the present disclosure also provide a device for generating test cases. The test cases are used to test the compiler. The test instructions for constructing the test cases are stored through the storage method described in the above embodiments. The device include:
获取模块,用于获取所述树型结构中从根节点到叶子节点的任一路径中的各节点存储的特征数据,以及所述特征数据对应的参考编译数据;An acquisition module, used to acquire the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure, and the reference compiled data corresponding to the characteristic data;
拼接模块,用于将各节点存储的特征数据拼接得到一条测试指令,将各特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令;The splicing module is used to splice the characteristic data stored in each node to obtain a test instruction, and splice the reference compilation data corresponding to each characteristic data to obtain the reference compilation instruction corresponding to the test instruction;
生成模块,用于基于得到的测试指令生成测试用例,以及基于所述测试指令对应的参考编译指令生成所述测试用例对应的参考编译指令。A generation module, configured to generate test cases based on the obtained test instructions, and generate reference compilation instructions corresponding to the test cases based on reference compilation instructions corresponding to the test instructions.
其中,上述装置执行测试用例的生成方法的具体步骤可以参考上述方法实施例中的描述,在此不再赘述。For the specific steps of the method for generating test cases performed by the above device, reference may be made to the description in the above method embodiments, which will not be described again here.
进一步的,本公开实施例还提供一种电子设备,如图5所示,所述电子设备包括处理器51、存储器52、存储于所述存储器52可供所述处理器51执行的计算机指令,所述处理器51执行所述计算机指令时实现上述实施例中任一项所述的方法。Further, an embodiment of the present disclosure also provides an electronic device. As shown in Figure 5, the electronic device includes a processor 51, a memory 52, and computer instructions stored in the memory 52 for execution by the processor 51. When the processor 51 executes the computer instructions, the method described in any one of the above embodiments is implemented.
本公开实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现前述任一实施例所述的方法。An embodiment of the present disclosure also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described in any of the foregoing embodiments is implemented.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information. Information may be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory. (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, Magnetic tape cassettes, tape magnetic disk storage or other magnetic storage devices or any other non-transmission medium can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本公开实施例可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本公开实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开实施例各个实施例或者实施例的某些部分所述的方法。 From the above description of the embodiments, those skilled in the art can clearly understand that the embodiments of the present disclosure can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions of the embodiments of the present disclosure are essentially or the parts that contribute to the existing technology can be embodied in the form of software products. The computer software products can be stored in storage media, such as ROM/RAM, A magnetic disk, optical disk, etc., includes a number of instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments or certain parts of the embodiments of the present disclosure.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, or a game controller. desktop, tablet, wearable device, or a combination of any of these devices.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于装置实施例而言,由于其基本相似于方法实施例,所以描述得比较简单,相关之处参见方法实施例的部分说明即可。以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,在实施本公开实施例方案时可以把各模块的功能在同一个或多个软件和/或硬件中实现。也可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。Each embodiment in this specification is described in a progressive manner. The same and similar parts between the various embodiments can be referred to each other. Each embodiment focuses on its differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For relevant details, please refer to the partial description of the method embodiment. The device embodiments described above are only illustrative. The modules described as separate components may or may not be physically separated. When implementing the embodiments of the present disclosure, the functions of each module may be integrated into the same device. or implemented in multiple software and/or hardware. Some or all of the modules can also be selected according to actual needs to achieve the purpose of the solution of this embodiment. Persons of ordinary skill in the art can understand and implement the method without any creative effort.
以上所述仅是本公开实施例的具体实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本公开实施例原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本公开实施例的保护范围。 The above are only specific implementations of the embodiments of the present disclosure. It should be noted that those of ordinary skill in the art can make several improvements and modifications without departing from the principles of the embodiments of the present disclosure. Improvements and modifications should also be considered as the protection scope of the embodiments of the present disclosure.

Claims (16)

  1. 一种编译器的测试方法,其特征在于,所述方法包括:A compiler testing method, characterized in that the method includes:
    基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令;Construct test cases and reference compilation instructions corresponding to the test cases based on the data related to the test instructions stored in the instruction database;
    利用待测试的编译器编译所述测试用例,得到目标编译指令;Compile the test case using the compiler to be tested to obtain the target compilation instructions;
    基于所述参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常。Based on the comparison result between the reference compilation instruction and the target compilation instruction, it is determined whether there is an exception in the compiler.
  2. 根据权利要求1所述的方法,其特征在于,所述测试用例包括功能性测试用例和/或稳定性测试用例,所述功能性测试用例包括单条测试指令,用于测试所述编译器的功能;所述稳定性测试用例由多条测试指令拼接得到,用于测试所述编译器的稳定性。The method of claim 1, wherein the test cases include functional test cases and/or stability test cases, and the functional test cases include a single test instruction for testing the function of the compiler. ; The stability test case is obtained by splicing multiple test instructions and is used to test the stability of the compiler.
  3. 根据权利要求2所述的方法,其特征在于,所述稳定性测试用例符合以下一种或多种条件:The method according to claim 2, characterized in that the stability test case meets one or more of the following conditions:
    所述编译器编译所述稳定性测试用例的时长大于预设时长;The time it takes for the compiler to compile the stability test case is longer than the preset time;
    所述稳定性测试用例中包括的测试指令数量大于预设数量;The number of test instructions included in the stability test case is greater than the preset number;
    所述稳定性测试用例的数据量大于预设数据量。The data volume of the stability test case is greater than the preset data volume.
  4. 根据权利要求2或3所述的方法,其特征在于,所述测试用例包括功能性测试用例以及稳定性测试用例,基于所述测试用例对应的参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常,包括:The method according to claim 2 or 3, characterized in that the test cases include functional test cases and stability test cases, based on the comparison results of the reference compilation instructions corresponding to the test cases and the target compilation instructions. , determine whether there is an exception in the compiler, including:
    基于所述功能性测试用例对应的参考编译指令与所述功能性测试用例对应的目标编译指令的比对结果,判定所述编译器的功能是否存在异常;Based on the comparison results of the reference compilation instructions corresponding to the functional test case and the target compilation instructions corresponding to the functional test case, determine whether there is an abnormality in the function of the compiler;
    在所述编译器的功能不存在异常的情况,基于所述稳定性测试用例对应的参考编译指令与所述稳定性测试用例对应的目标编译指令的比对结果,判定所述编译器的稳定性是否存在异常。When there is no abnormality in the function of the compiler, the stability of the compiler is determined based on the comparison results of the reference compilation instructions corresponding to the stability test case and the target compilation instructions corresponding to the stability test case. Is there any exception?
  5. 根据权利要求1-4任一项所述的方法,其特征在于,所述测试指令包括多个组成部分,所述与测试指令相关的数据包括针对所述多个组成部分中的一个组成部分,该组成部分对应的特征数据以及该特征数据对应的参考编译数据,该组成部分对应的特征数据与所述多个组成部分中除该组成部分之外的其余组成部分对应的特征数据关联存储。The method according to any one of claims 1 to 4, characterized in that the test instruction includes multiple components, and the data related to the test instruction includes one component among the multiple components, The characteristic data corresponding to the component and the reference compiled data corresponding to the characteristic data are stored in association with the characteristic data corresponding to the remaining components among the plurality of components except the component.
  6. 根据权利要求5所述的方法,其特征在于,所述组成部分包括以下一种或多种:指令类型、控制域、指令地址,其中,所述控制域用于表示所述测试指令包括的控制操作。 The method according to claim 5, characterized in that the components include one or more of the following: instruction type, control domain, and instruction address, wherein the control domain is used to represent the control included in the test instruction. operate.
  7. 根据权利要求5或6所述的方法,其特征在于,所述测试用例包括用于测试所述编译器功能的多个功能性测试用例,基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令,包括:The method according to claim 5 or 6, characterized in that the test cases include a plurality of functional test cases for testing the compiler function, and the test is constructed based on the data related to the test instructions stored in the instruction database. Use cases and reference compilation instructions corresponding to the test cases include:
    针对所述多个组成部分中的一个组成部分,针对该组成部分对应的一条目标特征数据,分别从所述多个组成部分中除该组成部分以外的其余组成部分中确定与该目标特征数据关联存储的关联特征数据;For one component among the plurality of components, for a piece of target characteristic data corresponding to the component, determine the association with the target characteristic data from the remaining components among the plurality of components except the component. Stored associated feature data;
    基于该目标特征数据和该关联特征数据生成测试指令,基于该目标特征数据对应的参考编译数据以及该关联特征数据对应的参考编译数据得到所述测试指令对应的参考编译指令;Generate a test instruction based on the target characteristic data and the associated characteristic data, and obtain the reference compilation instruction corresponding to the test instruction based on the reference compilation data corresponding to the target characteristic data and the reference compilation data corresponding to the associated characteristic data;
    将所述测试指令作为一个功能性测试用例,将所述测试指令对应的参考编译指令作为该功能性测试用例对应的参考编译指令。The test instruction is used as a functional test case, and the reference compilation instruction corresponding to the test instruction is used as the reference compilation instruction corresponding to the functional test case.
  8. 根据权利要求5或6所述的方法,其特征在于,所述测试用例包括用于测试所述编译器稳定性的稳定性测试用例,基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令,包括:The method according to claim 5 or 6, characterized in that the test case includes a stability test case for testing the stability of the compiler, and the test case is constructed based on the data related to the test instructions stored in the instruction database. And the reference compilation instructions corresponding to the test cases, including:
    针对所述多个组成部分中的一个组成部分,针对该组成部分中的一条目标特征数据,分别从所述多个组成部分中除该组成部分以外的其余组成部分中确定与该目标特征数据关联存储的关联特征数据;For one component among the plurality of components, for a piece of target characteristic data in the component, determine the association with the target characteristic data from the remaining components among the plurality of components except the component. Stored associated feature data;
    基于该目标特征数据和该关联特征数据生成测试指令,基于该目标特征数据对应的参考编译数据以及该关联特征数据对应的参考编译数据得到所述测试指令对应的参考编译指令;Generate a test instruction based on the target characteristic data and the associated characteristic data, and obtain the reference compilation instruction corresponding to the test instruction based on the reference compilation data corresponding to the target characteristic data and the reference compilation data corresponding to the associated characteristic data;
    利用生成的多个测试指令拼接得到所述稳定性测试用例,利用所述多个测试指令对应的参考编译指令拼接得到所述稳定性测试用例对应的参考编译指令。The stability test case is obtained by splicing the plurality of generated test instructions, and the reference compilation instructions corresponding to the stability test case are obtained by splicing the reference compilation instructions corresponding to the plurality of test instructions.
  9. 根据权利要求6-8任一项所述的方法,其特征在于,所述测试指令相关的数据通过树型结构存储,所述树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点用于存储所述控制域中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,所述树型结构的叶子节点用于存储所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。The method according to any one of claims 6 to 8, characterized in that the data related to the test instruction is stored in a tree structure, and the root node of the tree structure is used to store a target in the instruction type. Feature data and reference compiled data corresponding to the target feature data. The child nodes of the tree structure are used to store the first associated feature data associated with the target feature data in the control domain and the corresponding first associated feature data. The reference compiled data, the leaf nodes of the tree structure are used to store the second associated feature data associated with the target feature data and the first associated feature data in the instruction address and the corresponding second associated feature data Reference compiled data.
  10. 根据权利要求9所述的方法,其特征在于,所述基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令,包括: The method according to claim 9, characterized in that said constructing a test case based on the data related to the test instruction stored in the instruction database and the reference compilation instruction corresponding to the test case includes:
    获取所述树型结构中从根节点到叶子节点的任一路径中的各节点存储的特征数据以及所述特征数据对应的参考编译数据;Obtain the feature data stored in each node in any path from the root node to the leaf node in the tree structure and the reference compiled data corresponding to the feature data;
    将各节点存储的特征数据拼接得到一条测试指令,将各节点存储的特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令;Splice the characteristic data stored in each node to obtain a test instruction, and splice the reference compilation data corresponding to the characteristic data stored in each node to obtain the reference compilation instruction corresponding to the test instruction;
    基于得到的测试指令构建测试用例,以及基于所述测试指令对应的参考编译指令构建所述测试用例对应的参考编译指令。Construct a test case based on the obtained test instruction, and construct a reference compilation instruction corresponding to the test case based on the reference compilation instruction corresponding to the test instruction.
  11. 根据权利要求1-10任一项所述的方法,其特征在于,在基于所述测试用例对应的参考编译指令与所述目标编译指令的比对结果,判定所述编译器存在异常之后,所述方法还包括:The method according to any one of claims 1 to 10, characterized in that, after determining that there is an abnormality in the compiler based on a comparison result between the reference compilation instruction corresponding to the test case and the target compilation instruction, The above methods also include:
    输出测试报告,所述测试报告包括以下一种或多种信息:异常的类型、出现异常的测试指令、所述测试指令中出现异常的组成部分;Output a test report, which includes one or more of the following information: the type of exception, the test instruction in which the exception occurred, and the component in the test instruction in which the exception occurred;
    其中,所述异常的类型包括功能异常或稳定性异常,所述组成部分包括指令类型、控制域、指令地址。The type of abnormality includes functional abnormality or stability abnormality, and the components include instruction type, control domain, and instruction address.
  12. 一种测试指令的存储结构,其特征在于,所述存储结构包括:树型结构;A storage structure of test instructions, characterized in that the storage structure includes: a tree structure;
    所述树型结构用于存储与测试指令相关的数据;所述与测试指令相关的数据包括测试指令的多个组成部分中各组成部分对应的特征数据以及所述特征数据对应的参考编译数据;所述多个组成部分包括指令类型、控制域以及指令地址,所述控制域表示所述测试指令包括的控制操作;The tree structure is used to store data related to test instructions; the data related to test instructions includes characteristic data corresponding to each component of the multiple components of the test instruction and reference compiled data corresponding to the characteristic data; The plurality of components include an instruction type, a control domain and an instruction address, and the control domain represents the control operations included in the test instruction;
    其中,所述树型结构的根节点用于存储所述指令类型中的一条目标特征数据以及该目标特征数据对应的参考编译数据,所述树型结构的子节点用于存储所述控制域中与所述目标特征数据关联的第一关联特征数据和该第一关联特征数据对应的参考编译数据,所述树型结构的叶子节点用于存储所述指令地址中与所述目标特征数据及所述第一关联特征数据关联的第二关联特征数据和该第二关联特征数据对应的参考编译数据。Wherein, the root node of the tree structure is used to store a piece of target feature data in the instruction type and the reference compiled data corresponding to the target feature data, and the child nodes of the tree structure are used to store the control domain. The first associated feature data associated with the target feature data and the reference compiled data corresponding to the first associated feature data. The leaf nodes of the tree structure are used to store the target feature data and the reference data in the instruction address. The second associated feature data associated with the first associated feature data and the reference compiled data corresponding to the second associated feature data.
  13. 一种测试用例的生成方法,其特征在于,所述测试用例用于测试编译器,构建所述测试用例的测试指令通过如权利要求12所述的存储结构存储,所述方法包括:A method for generating test cases, characterized in that the test cases are used to test a compiler, and the test instructions for constructing the test cases are stored through the storage structure as claimed in claim 12, and the method includes:
    获取所述树型结构中从根节点到叶子节点的任一路径中的各节点存储的特征数据,以及所述特征数据对应的参考编译数据;Obtain the characteristic data stored in each node in any path from the root node to the leaf node in the tree structure, and the reference compiled data corresponding to the characteristic data;
    将各节点存储的特征数据拼接得到一条测试指令,将各特征数据对应的参考编译数据拼接得到该测试指令对应的参考编译指令;Splice the characteristic data stored in each node to obtain a test instruction, and splice the reference compilation data corresponding to each characteristic data to obtain the reference compilation instruction corresponding to the test instruction;
    基于得到的测试指令生成测试用例,以及基于所述测试指令对应的参考编译指令生成所述测试用例对应的参考编译指令。 Generate test cases based on the obtained test instructions, and generate reference compilation instructions corresponding to the test cases based on reference compilation instructions corresponding to the test instructions.
  14. 一种编译器的测试装置,其特征在于,所述装置包括:A compiler testing device, characterized in that the device includes:
    构建模块,用于基于指令数据库中存储的与测试指令相关的数据构建测试用例以及所述测试用例对应的参考编译指令;A building module for constructing test cases and reference compilation instructions corresponding to the test cases based on the data related to the test instructions stored in the instruction database;
    编译模块,用于利用待测试的编译器编译所述测试用例,得到目标编译指令;A compilation module, used to compile the test case using the compiler to be tested and obtain the target compilation instructions;
    判定模块,用于基于所述参考编译指令与所述目标编译指令的比对结果,判定所述编译器是否存在异常。A determination module, configured to determine whether there is an exception in the compiler based on a comparison result between the reference compilation instruction and the target compilation instruction.
  15. 一种电子设备,其特征在于,所述电子设备包括处理器、存储器、存储于所述存储器可供所述处理器执行的计算机指令,所述处理器执行所述计算机指令时实现如权利要求1-11或13任一项所述的方法。An electronic device, characterized in that the electronic device includes a processor, a memory, and computer instructions stored in the memory and executable by the processor. When the processor executes the computer instructions, the implementation as claimed in claim 1 -The method described in any one of 11 or 13.
  16. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机指令,所述计算机指令被执行时实现如权利要求1-11或13任一项所述的方法。 A computer-readable storage medium, characterized in that computer instructions are stored on the computer-readable storage medium, and when the computer instructions are executed, the method according to any one of claims 1-11 or 13 is implemented.
PCT/CN2023/090577 2022-04-29 2023-04-25 Compiler test method and apparatus, case generation method and apparatus, and instruction storage structure WO2023207973A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210474322.4 2022-04-29
CN202210474322.4A CN114817047A (en) 2022-04-29 2022-04-29 Compiler test method, case generation method and device and instruction storage structure

Publications (1)

Publication Number Publication Date
WO2023207973A1 true WO2023207973A1 (en) 2023-11-02

Family

ID=82512174

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/090577 WO2023207973A1 (en) 2022-04-29 2023-04-25 Compiler test method and apparatus, case generation method and apparatus, and instruction storage structure

Country Status (2)

Country Link
CN (1) CN114817047A (en)
WO (1) WO2023207973A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114817047A (en) * 2022-04-29 2022-07-29 上海阵量智能科技有限公司 Compiler test method, case generation method and device and instruction storage structure

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140040872A1 (en) * 2012-07-31 2014-02-06 Oracle International Corporation Systems and methods for testing a compiler through compile-time decision feedback
CN104516818A (en) * 2014-12-29 2015-04-15 北京四方继保自动化股份有限公司 Automatic testing system and method both applicable to compiler in logical configuration software
CN110704065A (en) * 2019-10-09 2020-01-17 大连理工大学 Compiler front-end differential test method based on illegal program input
CN114817047A (en) * 2022-04-29 2022-07-29 上海阵量智能科技有限公司 Compiler test method, case generation method and device and instruction storage structure

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140040872A1 (en) * 2012-07-31 2014-02-06 Oracle International Corporation Systems and methods for testing a compiler through compile-time decision feedback
CN104516818A (en) * 2014-12-29 2015-04-15 北京四方继保自动化股份有限公司 Automatic testing system and method both applicable to compiler in logical configuration software
CN110704065A (en) * 2019-10-09 2020-01-17 大连理工大学 Compiler front-end differential test method based on illegal program input
CN114817047A (en) * 2022-04-29 2022-07-29 上海阵量智能科技有限公司 Compiler test method, case generation method and device and instruction storage structure

Also Published As

Publication number Publication date
CN114817047A (en) 2022-07-29

Similar Documents

Publication Publication Date Title
US10552301B2 (en) Completing functional testing
WO2021098148A1 (en) Software compiling method and apparatus, and electronic device and storage medium
JP7172435B2 (en) Representation of software using abstract code graphs
US9026998B2 (en) Selecting relevant tests to quickly assess code stability
US11675575B2 (en) Checking source code validity at time of code update
US20130014093A1 (en) Code inspection executing system for performing a code inspection of abap source codes
CN111104335B (en) C language defect detection method and device based on multi-level analysis
US10354031B2 (en) Information processing by interpenetrating signal transmission channel in design for testability of chip
CN106095501B (en) A kind of application dispositions method and device
US10514898B2 (en) Method and system to develop, deploy, test, and manage platform-independent software
US20210103514A1 (en) Reusable test cases for identifiable patterns
US10572371B2 (en) Generating valid use cases from a parsed configuration file describing use case options
WO2020237508A1 (en) Assertion validation code binding method and apparatus
WO2023207973A1 (en) Compiler test method and apparatus, case generation method and apparatus, and instruction storage structure
US7908596B2 (en) Automatic inspection of compiled code
US20210263837A1 (en) Real time fault localization using combinatorial test design techniques and test case priority selection
CN113094252B (en) Test case generation method and device, computer equipment and storage medium
CN109284222B (en) Software unit, project testing method, device and equipment in data processing system
CN111240987B (en) Method and device for detecting migration program, electronic equipment and computer readable storage medium
US20150020056A1 (en) Methods and systems for file processing
CN111858290A (en) Method and apparatus for detecting memory leak path of target code
CN108959103A (en) Method for testing software based on BWDSP library function
CN117273171A (en) Deep learning framework adaptation method, deep learning framework adaptation device, computer equipment and storage medium
US11947966B2 (en) Identifying computer instructions enclosed by macros and conflicting macros at build time
CN112506806B (en) Method for debugging program, electronic device and storage medium

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: 23795405

Country of ref document: EP

Kind code of ref document: A1