How can we modify the default uvm_printer behavior?

In most cases, we all use the default uvm_printer behavior. However, from time to time, we may need to tweak it. Consider the following example:

We have a sequence item class, that here has only one dynamic array field, to illustrate this:

If we randomize this object and use the built-in macro to print it, we will get something like this:

Suppose that you want to print all items in this array because, for example, someone who is recreating the scenario from the lab needs you to provide them with a text file of all items printed.

While you can provide a custom print function, here’s how you can do it using a built-in uvm_printer instead.

Inside the test, for example, define a custom function to configure the printer as needed:

The above configuration tells the printer to print all items in the respected field in the relevant object. You can invoke this function during the build_phase:

Now your output will look like this:

The drawback of this approach is that it will affect all the prints in your test. You can change this solution by defining your own custom printer, and using it only for prints you need. Here’s how to do it.

Declare, construct and configure your printer in the test:

Note that here we are using a table printer; there are two other options (line printer and tree printer).

Now pass this object as an argument in the print() function as shown below:

Now you can control how and what to print using the built-in uvm_printer.

Note that there are many other options with which you can play with the uvm_printer configuration. We only showed one possibility here. Refer to UVM documentation for more information.

Contact Us

Please, enter your details below. We will get back to you as fast as we can.

This website uses cookies to ensure you get the best experience on our website.

Get Cogita

Please, enter your details below. We will get back to you as fast as we can.

Thank you!

We will get in touch soon.

Get a Quote

Please, enter your details below. We will get back to you as fast as we can.