DIFFERENT BETWEEN UVM_TOP.PRINT_TOPOLOGY AND SPRINT() METHODS - NISHUNISARGA/UVM_notes GitHub Wiki

uvm_info("TB hierarchy(sprint)", this.sprint(), UVM_NONE); and uvm_top.print_topology() serve different purposes and provide different kinds of information. Here's how they differ:

1. `uvm_info("tb_...",this.sprint(), UVM_NONE);

Purpose:

This statement prints information about the current UVM component's hierarchy (from the component's context where the code is called).

Key Features:

  • this.sprint():
    • This method returns a string representation of the component's hierarchy, including its configuration and settings.
    • It shows only the component calling sprint() and its immediate subcomponents. It doesn't provide the entire testbench hierarchy unless used from the top-level component.
  • uvm_info:
    • Logs the string representation (returned by sprint()) to the simulation output, depending on the verbosity level (e.g., UVM_NONE, UVM_LOW, etc.).

When to Use:

  • If you want to debug or log details about a specific component (e.g., sequencer, driver, monitor) and its immediate hierarchy.

    Example:
             class my_driver extends uvm_driver;
                 function void build_phase(uvm_phase phase);
                    `uvm_info("TB hierarchy(sprint)", this.sprint(), UVM_NONE);
                 endfunction
             endclass
    
    Output Example:
           UVM_INFO @ 0: uvm_test_top.env.driver: TB hierarchy(sprint):
             Name        Type           Size  Value
             my_driver   uvm_driver     -     -
    

2. uvm_top.print_topology()

Purpose:

  • This method prints the entire testbench hierarchy from the root component (uvm_top).

Key Features:

  • print_topology() is a built-in method of the uvm_root class (uvm_top is its singleton instance).
  • It shows all components instantiated in the testbench, along with their types and configuration fields.
  • Provides a global view of the testbench hierarchy, making it useful for debugging and verifying the overall testbench structure.

When to Use:

  • During testbench development or debugging to confirm that all components are instantiated as expected and to understand their relationships.

         Example:
    
                initial begin
                     uvm_top.print_topology();
                end
          
          Output Example:
               
              Name                             Type              Size  Value
              --------------------------------------------------------------
              uvm_test_top                     uvm_test           -    -
                env                            my_env             -    -
                  agent                        my_agent           -    -
                    driver                     my_driver          -    -
                    monitor                    my_monitor         -    -
                    sequencer                  my_sequencer       -    -
    

Key Differences:

     Feature    |   this.sprint()	      |      uvm_top.print_topology()
    ------------|-----------------------------|--------------------------------------
       Scope    |   Specific component and    |      Entire testbench hierarchy from              
                |   its immediate hierarchy.  |	 uvm_top.
    ------------|-----------------------------|--------------------------------------
      Usage     |   Logs information about a  |      Prints all instantiated
      Context   |   particular component.     |      components in the testbench.
    ------------|-----------------------------|--------------------------------------
      Level of  |   Detailed view of the      |      High-level view of all 
      Detail    |   calling component.        |      components.
    ------------|-----------------------------|--------------------------------------
      Output    |   Returns a string (can be  |      Directly prints to the
      Format    |   logged with uvm_info).    |      simulation output.
    ----------------------------------------------------------------------------------

When to Use Which:

  1. Use this.sprint() when:
    • You want detailed information about a specific component.
    • Debugging or logging localized configurations or attributes.
  2. Use uvm_top.print_topology() when:
    • You need a complete overview of the testbench structure.
    • Verifying if all components are properly instantiated.

When Can uvm_top.print_topology() Be Called?

Anywhere in Code:

  • You can call uvm_top.print_topology() from any part of your testbench, such as the test, environment, agent, or even sequences.
  • It is a method of the uvm_root class, which is always accessible as uvm_top.

Dependency on Phases:

Before the Build Phase:

  • If called before the build_phase, the testbench hierarchy may not be fully constructed yet, so it won't display the complete hierarchy.

After the Build Phase:

  • This is the ideal time to call uvm_top.print_topology() since the testbench components are fully instantiated by this point.

After the Run Phase:

  • The hierarchy remains intact, so it can still print the full topology, but by this point, you usually won't need it for debugging purposes.

Typical Locations to Call:

  1. In the Test class - can be called in build_phase or start_of_simulation_phase but better to use in end_of_elaboration_phase since at this time hierarchy is completed and this phase happens before the simulation runs so good for debugging.
  2. In the tb top module - should call before the run_test() is called, uvm env and other components are typically built and elaborated during the BP, CP, EoEP. run_test() will trigger those phases and simulation might already be running and the output could be too late for debugging testbench setup issues. if we call it after run_test() hierarchy is still valid and less useful.
  3. In the env or agent