One initiates a simulation in Specman Elite by clicking on the Test button in the GUI or by issuing the test command at the Specman Elite command prompt. To understand how e code is executed, it is necessary to understand the phases of execution. This section discusses these execution phases.
Upon issuance of the test command, Specman Elite goes through five distinct execution phases. Each test phase is called in a specific order. Each phase is represented by a predefined method in Specman Elite. Each phase is normally empty. User e code is executed by extension of some of these phase methods. Figure 11-7 shows these test phases.
The test phases that are executed by the test command are described as follows:
Initialization: In this phase, Specman Elite does general preparations and configuration. In addition to other methods, the initialization phase calls the sys.setup() method. Any e simulator configuration options are specified by extension of sys.setup() in this phase.
Pre-run Generation: In this phase, Specman Elite performs memory allocation, instantiation, and generation of the data elements before simulation. In addition to other methods, the pre-run generation phase calls the predefined init() and pre_generate() methods for every struct instance under sys. Then the generation of the data elements occurs. After the generation is complete, the pre-run generation phase calls the post_generate() methods for every struct instance under sys. Each of these methods can be extended to include method calls. Any computations that are done after Specman Elite has generated the data elements must be done by extension of the post_generate() method. Each method call is executed for all instantiated structs before moving to the next method call.
Simulation Run: The actual simulation occurs in this phase. Any TCMs are executed in this phase. If Specman Elite is working with an HDL simulator, the start of the simulation run is time 0 of the HDL simulator. The predefined run() method is called for every struct and unit in the sys hierarchy. One can initiate simulation time activity by starting (with the start keyword) a TCM from the run() method of a struct or unit. For any simulation, at least one main TCM must be started from the run() method of a top-level unit. Otherwise, no simulation activity will occur. This main TCM then starts or calls other TCMs to control execution. Figure 11-8 shows two ways to launch TCMs from the main TCM. Simulation time elapses only in this phase.
Post-Run Check: This phase performs preparation for checking and then performs the checking.
Finalization: This phase does simulation cleanup, coverage, and reporting.
Figure 11-9 shows a detailed flow of the method calls invoked by Specman Elite during each of the five test phases.
Although there are many extensible methods, the most commonly extended methods are described below.
This method initializes configuration and test parameters for running a test. For example, the seed value for generation is set during this method. The coverage mode is set by extension of this method call. Example 11-1 shows the usage of this method.
Extend the sys.setup() method <' extend sys { setup() is also { set_config(cover, mode, normal); }; }; '>
This method is called for every struct or unit instance in the sys hierarchy. The post_generate() method is run automatically after an instance of the enclosing struct is allocated and both pre-generation and generation have been performed. You can extend the predefined post_generate() method for any struct to manipulate values produced during generation. The post_generate() method allows you to derive more complex expressions or values from the generated values.
The order of generation is recursively as follows:
Example 11-2 shows the usage of the post_generate() method.
Example shows usage of post_generate() method <' struct a { !m: int; //Do not create m in generate() m1: int; //Create a value for m1 in generate() post_generate() is also { //Extend the post_generate() method m = m1 + 1; //Compute value of m based on generated value of //m1. This method will be called for an instance //of this struct just after the generation is //complete. }; }; extend sys { A: a; //Instantiate struct a in the sys hierarchy }; '>
The run() method is extended to start user-defined TCMs. The method is initially empty. The run() methods of all structs under sys are called, starting from sys, in depth-first search order when you execute a test or a run command. To run the simulation at least one main TCM should be started from the run() method of the main unit. Note that run() itself is not a TCM. Therefore, you can only start TCMs, not call them, from the run() method.
Example 11-3 shows the usage of the run() method.
Example shows usage of run() method <' struct packet { id : int; event clk is rise('~/top/clk') @sim; //Define clk monitor() @clk is { while (TRUE) { wait [2] * cycle; out("cycle ", sys.time, " Packet id ", id, " is still running"); }; }; run() is also { //Extend the run() method of the struct start monitor(); //Start the monitor() TCM from the run() //method of the struct. This TCM will //start at simulation time 0 when the //e simulator hits the simulation run phase. }; }; '>