Abstract:
A test code generation technique that replaces instructions having a machine state dependent result with special redirection instructions provides generation of test code in which state dependent execution choices are made without a state model. Redirection instructions cause execution of a handler than examines the machine state and replaces the redirection instruction with a replacement instruction having a desired result resolved in accordance with the current machine state. The instructions that are replaced may be conditional branch instructions and the result a desired execution path. The examination of the machine state permits determination of a branch condition for the replacement instruction so that the next pass of the test code executes along the desired path. Alternatively, the handler can execute a jump to the branch instruction, causing immediate execution of the desired branch path. The re-direction instructions may be illegal instructions, which cause execution of an interrupt handler that performs the replacement.

Description:
This invention was made with Government support under HR0011-07-9-0002 awarded by the Defense Advanced Research Projects Agency (DARPA). The Government has certain rights to this invention. 
    
    
     BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     The present invention is related to test program generation by functional exercisers, and more specifically to a test case generator generating code that self-modifies to replace an instruction during a first pass of a test case. 
     2. Description of Related Art 
     Functional exercisers that generate random test code streams for testing processor integrated circuits (ICs), and for verifying designs that should have the same machine behavior as other processors, generally include a test code generator of one of two types: reference model test code generators, or consistency-checking test code generators. Consistency-checking test code generators typically do not use a reference model and generate random code streams, including random branch directions, since the state of the machine is not known when the code stream is generated in order to control the direction of a branch. An exerciser having a consistency-checking test code generator compares the behavior of a processor in response to the generated program code to the results from other processors, to determine whether a processor is functionally sound. As an alternative, consistency-checking test code generators can use predesigned code and data sequences to control branch direction. However, the use of predesigned code and data sequences limits the flexibility of the exerciser compared to purely random branch direction generation and also increase complexity of the test code generator. 
     A reference model test code generator includes a model of the processor (machine model) and therefore the state of the machine is known at the time of generating a branch instruction. Therefore, the direction of the branch is known and the generated test case can be designed to more completely explore the potential machine state and execution space of the processor. 
     Each of the test program generation strategies described above has advantages and disadvantages. The consistency-checking technique requires stored data for comparison or multiple passes and there is no absolute control of the branch directions generated. Therefore, a larger number of test cases may be required compared to an exerciser that includes a reference model test case generator. The reference model test case generator is inherently more complex and requires processing resources to track the state of the machine throughout the progress of the generated code stream. Therefore, fewer test cases can be generated in the same amount of time, even though less test cases may be required to test the processor as fully as a given amount of randomly branching test cases. 
     In addition, there are other instructions besides branches that may have state dependencies that it is desirable both test exhaustively and to control to reduce the amount of test cases that must be executed. For such instructions, the same exerciser criteria, advantages and disadvantages may apply. 
     Therefore, it would be desirable to provide a test case generator for generating a code stream that provides greater control over the test case generation without greatly increasing complexity and overhead in the test code generation. 
     BRIEF SUMMARY OF THE INVENTION 
     The invention is embodied in a processor, computer system, computer program product and method that generate test code streams for testing a processor, which may be used in a functional exerciser. The method is a method of operation of the computer system and the computer program product is a set of program instructions embodied in tangible form in computer readable storage media such as optical, magnetic or electrical removable or non-removable memory. 
     The method generates an output set of program code by replacing a particular instruction, which may be a branch instruction or other state-dependent instruction, with a redirecting instruction for redirecting execution to a handling routine. When the redirection instruction is reached the handling routine is entered. The handling routine determines a state of the processor such that a desired result of the particular instruction is selected by specifying a replacement instruction having the desired result when executed and replacing the redirection instruction with the replacement instruction. For example, a branch instruction may be selected and written in place of the redirection instruction that directs execution along a desired path. The program code is then re-executed, either immediately or on a next iteration, so that the replacement instruction generates the desired result when executed. 
     The foregoing and other objectives, features, and advantages of the invention will be apparent from the following, more particular, description of the preferred embodiment of the invention, as illustrated in the accompanying drawings. 
    
    
     
       BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWING 
       The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives, and advantages thereof, will best be understood by reference to the following detailed description of the invention when read in conjunction with the accompanying Figures, wherein like reference numerals indicate like components, and: 
         FIG. 1  is a block diagram illustrating a processing system in which program code according to an embodiment of the present invention is generated and executed. 
         FIG. 2  is a memory diagram illustrating program code generated and modified in accordance with an embodiment of the present invention. 
         FIG. 3  is a flow chart depicting a method in accordance with an embodiment of the present invention. 
         FIG. 4  is a flow chart depicting a method in accordance with another embodiment of the present invention. 
     
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     The present invention relates to methods and programs for implementing functional exercisers that are used to evaluate processor designs and test processor ICs. Rather than randomly insert machine-state-dependent instructions such as conditional branch instructions and rather than simulating the machine design of a processor to track the machine state in order to selectively place the machine-state-dependent instructions, a special redirection instruction is placed in a generate test case stream of program code. During execution the redirection instruction causes execution to enter a handling routine that then overwrites the redirection instruction with the machine-state-dependent instruction selected according to the current machine state which is know during execution of the test case. The special redirection instruction may be, for example, an illegal op-code and the corresponding handling routine the interrupt handler for the illegal op-ode exception interrupt. After the test case code stream has been patched by overwriting the redirection instruction, execution is either directed to the patched location, causing immediate execution of the selected machine-state-dependent instruction, or execution is directed to the next instruction that would be executed after the selected machine-state-dependent instruction, so that the selected machine-state-dependent instruction is executed on a next iteration through the corresponding portion of the test case. 
     Referring now to  FIG. 1 , a system for generating and executing program code in accordance with an embodiment of the present invention is shown. The depicted computer system includes a workstation  10  coupled to a test platform  20 . The depicted computer system configuration is illustrative, and processing systems in accordance with other embodiments of the present invention include dedicated exerciser systems in which the processor generating the test cases is integrated in the test platform, and other systems in which the processor generating the test cases may be used to execute the test cases, for example, when evaluating conditions in legacy designs that are long in production. A processor  11  is coupled to a memory  12 , which contains program instructions implementing a test code generator for generating program code streams for execution by a processor  11 A in test platform  20 , by transferring the test cases to memory  12 A coupled to processor  11 A in test platform  20 . Processor  11  in workstation computer  10  is coupled to a storage interface  13 , which couples processor  11  and memory  12  to storage devices such as hard disc drive  15  and an optical drive  14 . Embodiments of the invention include computer program products that contain the test code generator of the present invention stored in memory  12  as well as stored on tangible media such as a CD-ROM  16  that may be inserted into optical drive  14  to transfer the test code generator and other software components of the functional exerciser to memory  12  for execution by processor  11 . The illustrated processing system also includes input/output (I/O) interfaces and devices  19  such as mice and keyboards for receiving user input and graphical displays for displaying information, such as user interfaces for controlling and examining the results of test code execution within test platform  20 . While the system of  FIG. 1  is used to provide an illustration of a system for generating program code for testing processor and execution of the test program code in accordance with the present invention, it is understood that a functional exerciser in accordance with an embodiment of the present invention may be executed by another general-purpose or special-purpose computer system that does not include the architectural features described in further detail below. Further it is understood that the target processor executing the test cases generated by the functional exerciser may be a processor within any type of system, including processors coupled to a wafer tester. 
     Workstation computer system  10  is coupled to test platform  20  by an interface  18  that couples to interface  18 A, through a wired, optical or wireless connection that may be proprietary, or take the form of a standardized serial or parallel bus such as an Ethernet connection. Interface  18 A also includes control logic responsive to commands sent from workstation computer system  10  that control the loading of test code streams into memory  12 A, and initiation and control of the execution of the test code streams by processor  11 A, which may include clock and reset control circuits among other circuits that provide for observation of the external state of processor  11 A. 
     Referring now to  FIG. 2 , details of a test case instruction stream generated by a program within workstation computer system  10  in accordance with an embodiment of the invention are shown as loaded into memory  12 A of test platform  20 , along with details of the execution of the program within test platform  20 . Within memory  12 A, an initial memory image  30 A contains the following program: 
                                             load b           sub a,b           illegal op-code           mul a, c           sto a           test a           illegal op-code                        
The illegal opcodes have been placed at locations where a machine-state-dependent instructions, such as conditional branches, were originally generated or indicated for generation by the test code generator, but in the present invention are replaced with an instruction that redirects execution of the test cases to a special handler routine  32 , which is also located within memory  12 A in the exemplary illustration. In the specific example above, the handler routine  32  is part of or called by an interrupt service routine that handles at least an exception interrupt caused by the illegal instructions. The handler routine writes a machine-state-dependent instruction to the locations previously occupied by the illegal instructions as each illegal instruction is executed. One advantage of using an exception, such as the illegal op-codes of the above example, is that the handler will be entered automatically in supervisor mode, which affords some protection from any instabilities introduced by execution of the test code, and further provides some information about the location and flags associated with the change from user mode. E.g., the location of the illegal instruction can be ascertained from the exception information in some architectures, without requiring additional information provided from the test code generator. However, use of an exception or entry into supervisory mode is not a requirement of the present invention. Also, other sorts of instructions or instruction/operand combinations that generate traps to supervisory mode may be used as an alternative, such as access to illegal memory locations.
 
     The reason that redirection instructions, such as the illegal instructions of the above example, are used, is that while the test case generator program executing within workstation computer system  10  is generating the test case, the state of processor  11 A when each of the illegal instructions are encountered is not known, because for speed and simplicity, a machine state model of the processor is not maintained or generated by the test code generator. However, within test platform  20 , when handler  32  is reached, the machine state of processor  11 A is known, because the state of processor  11 A at entry to handler  32 , with the exception of the interrupt condition, is the machine state that the test case generator would have needed to select the proper machine-state-dependent instruction, such as a particular branch condition. Therefore, handler  32  can determine which branch instruction is needed for execution in a particular direction, which might be specified by the particular illegal instruction or an operand supplied therewith and overwrite initial memory image  30 A to generate modified memory image  30 B. Then, handler  32  can transfer control to the location of the modified instruction, e.g., instruction ble path in memory image  30 B to follow the desired execution at location path, or handler  32  may jump directly to location path. The value of path may also be specified in some manner such as an operand supplied with the illegal instructions, or the illegal opcode itself. Alternatively, handler  22  may receive a table of replacement instructions for each of the illegal instructions that is stored elsewhere in memory  12 A and retrieve the values needed for instruction replacement from the table, or a table of general code generation directives may be used. The table(s) can be generated by the test code generator at the time the illegal instructions are placed, and will generally have a one-to-one correspondence between each illegal instruction encountered in execution order and the entries in the table. 
     As an alternative to interrupt generation, a test code stream in accordance with another embodiment of the present invention may take the following form, for the example of the program given for memory image  30 A described above: 
                                             load b           sub a,b           jmp handler           mul a, c           sto a           test a           jmp handler                        
where the jump instructions cause entry to the handler routine, which can then replace the jump instructions with the conditional branches or other machine-state-dependent instructions specified by the test code generator.
 
     Referring now to  FIG. 3 , a method for generating program code in accordance with an embodiment of the present invention is shown. If the next instruction being generated is a machine state-dependent instruction, resolution of which is being held until runtime (decision  40 ), a redirection instruction, such as the illegal instructions described above is inserted at the next location in the output code stream (step  42 ), otherwise the next test code instruction is generated and added to the end of the code stream (step  41 ). Until the test code generation is complete (decision  44 ), the algorithm moves on to the next instruction in the code stream (step  43 ). If test code generation is complete (decision  44 ), the generating ends. While the method illustrated in  FIG. 3  provides an example of how to generate test code in accordance with an embodiment of the present invention, other techniques may be employed as well, in accordance with other embodiments of the present invention. For example, an entire test case code stream may be generated and then parsed for certain machine-state-dependent instructions such as conditional branches. The conditional branches are then replaced with the redirection instructions. 
     Referring now to  FIG. 4 , a method of executing program code in accordance with an embodiment of the present invention is shown. Until a redirection instruction is reached (decision  51 ), or execution of the test program code is complete (decision  56 ), the next instruction in the test code stream is executed (step  50 ). When a redirection instruction is reached (decision  51 ), the handler is entered (step  52 ). In the handler, the machine state is determined and the replacement instruction is selected in accordance with the determined machine state (step  53 ). Next, the replacement instruction is written over the redirection instruction (step  54 ) and execution is resumed in the test code stream by jumping to the replacement instruction or a resulting branch path (step  55 ). Once execution of the test program code is complete (decision  56 ), the execution terminates. 
     While the invention has been particularly shown and described with reference to the preferred embodiments thereof, it will be understood by those skilled in the art that the foregoing and other changes in form, and details may be made therein without departing from the spirit and scope of the invention.