英文原版_自动化UVM验证平台生成和代码管理
英文原版_自动化UVM验证平台生成和代码管理
英文原版_自动化UVM验证平台生成和代码管理
Management
www.ulkasemi.com
ABSTRACT
It is well established that functional verification takes up a hefty portion of electronic design
process. Standard verification methodologies such as UVM is commonly used in the build
process of testbenches and Verification IP to increase productivity and reusability. We propose a
script based methodology for reducing verification process time by expediting creation of UVM
and System Verilog class based testbench code. Our proposed method involves systematic and
user controlled generation of code templates to build up an entire UVM testbench framework.
This script based utility can be used for automatically creating testbench files, writing
appropriate codes in corresponding files and adding any components to the existing testbench
during the whole process of verification. A graphical user interface has also been developed for
easier control of the utility. Users can create entire testbench hierarchy from scratch and add
individual components to existing testbench environment.
Table of Contents
1. Introduction ........................................................................................................................... 6
2. UVM Testbench Structure .................................................................................................... 6
3. Testbench Code Generation and Management ..................................................................... 7
3.1. Creating Whole Testbench Structure .................................................................................... 7
3.2. Adding New Components .................................................................................................. 8
3.3. Managing Testbench............................................................................................................ 8
3.4. Generate Testbench from Graphical User Interface ........................................................... 8
4. Scripts used for Testbench Automation and Management ................................................... 8
5. Testbench Generation from Terminal ................................................................................. 11
5.1. Terminal Commands .......................................................................................................... 11
5.1.1. Creating New Class/es ................................................................................................. 11
5.1.2. Creating Instances of Existing Classes......................................................................... 13
5.1.3. Creating Port Connections ........................................................................................... 14
5.2. Creating Initial Testbench Structure from Terminal ......................................................... 15
5.2.1. Top File ........................................................................................................................ 15
5.2.2. Base Test File ............................................................................................................... 16
5.2.3. Environment File .......................................................................................................... 16
5.2.4. Other Generated Files................................................................................................... 18
5.3. Adding New Agent Class from Terminal ........................................................................... 22
5.3.1. Created Files ................................................................................................................. 22
5.3.2. Changes inside Existing Environment ......................................................................... 24
5.4. Adding New Environment Class to Existing Testbench from Terminal ............................ 26
5.4.1. Created Files ................................................................................................................. 26
5.4.2. Updated Files................................................................................................................ 27
6. Testbench Generation from GUI ........................................................................................ 28
6.1 Creating Whole Testbench .................................................................................................. 28
6.2 Adding an Environment....................................................................................................... 30
6.3 Adding an Agent .................................................................................................................. 31
7. Simulation Results .............................................................................................................. 33
8. Future Aspects .................................................................................................................... 35
8.1. Include More UVM Features .............................................................................................. 35
8.2. Different Structure Creation ............................................................................................... 35
8.3. Easier Management Tool .................................................................................................... 35
9. Conclusion .......................................................................................................................... 35
10. References ........................................................................................................................... 36
Verification process must be time efficient hence the right methodology must be followed for
verifying a particular design. Universal Verification Methodology is a much improved and
universal tool than its predecessors and has become the most widely used among verification
engineers since its advent. UVM based testbenches have robust, easily reusable structure and as a
result, improves the quality of verification. It has a base class library from which typical
components of a self-checking testbench can be extended. Developing a UVM testbench with
various class components and interconnections requires a significant amount of coding time,
especially for engineers unaccustomed to UVM and System Verilog. In this paper we propose an
automation methodology which will help accelerate development process of UVM testbenches.
To implement this we have developed a script based utility that can be used to generate code
templates for developing and managing any testbench in System Verilog using UVM. In the next
sections we will elaborate on generic UVM testbench structure, working methodology and
implemented features of the tool, the graphical user interface developed and simulation test
results.
uvm_top
test1 Env1
UVM agent - master
Env2
subscriber sequencer monitor driver
Design
testcases scoreboard Under
UVM agent - slave Test
virtual sequencer monitor driver
sequencer
In the setup in Figure 1 there are multiple tests and each test contains one or more environments.
One particular test is shown in detail. It contains two different environments. ‘Env1’ contains a
‘Master’ and a ‘Slave’ agent component. The agents are built up of sub-classes such as driver,
monitor etc. The environment also contains components such as scoreboard, subscribers and
virtual sequencers. During testbench code compilation all UVM components are built following
a certain hierarchy.
Using our proposed methodology, one can develop such a testbench structure easily. The
structure contains a top level, base test, interface, environment and sub-components. The base
test contains an instance of the environment, and sub-components such as virtual sequencer,
scoreboard, agents etc. are instantiated inside that environment. Necessary interconnections
between sub-components are automatically made inside environment. The agents contain
instances of classes such as driver, monitor and sequencer. Virtual sequencer contains instances
of the local agent sequencers and connects to a virtual sequence which contains sequences. Test
instantiates and starts this virtual sequence. Scoreboard, subscriber and monitor contain
necessary ports for data transaction.
Using scripts, users can add any class component to the existing structure. In this way multiple
testcases, environments, agents, sequencers, monitors, etc. can be implemented in the testbench.
The tool options are discussed in detail in the following sections.
The proposed script based utility can generate any UVM testbench structure automatically based
on provided user inputs. Also, there are options to add components and manage overall
testbench.
This script based utility makes it possible for users to create the whole testbench structure by
passing inputs through the terminal. User has to run a command “rtg tb $arg1 $arg2
....” to generate whole testbench structure code.The important arguments for executing this
command are: prefix for the generated files, top level file name, base test file name and base test
class name. Prefix will be added to all generated file names and it will also be used for naming
different class and instances throughout the testbench. Other three arguments are just for
generating top level and base test files. After executing this command 16 files will be generated
in the current working directory. Generated files include: top level, base test, virtual sequencer,
virtual sequence, environment, scoreboard, subscriber, agent and other sub-classes. A script is
generated along with the testbench so that the testbench can be simulated just after generation.
After creating the initial testbench structure, user can add as many components as needed to the
existing testbench. It is useful for developing testbenches for verifying large SoCs. In such cases
user can just create individual environment for each block and connect them together from top
level. Currently there are 26 options available for adding, instantiating and connecting new
classes and instances to the existing testbench.
Testbench management can become complicated for large SoCs. Testbenches developed for
SoCs may have multiple environments for individual blocks. It becomes tough to keep track of
the updates in different portions of the testbench. This utility generates a log file to keep track of
the updates made to any testbench. The log file keeps track of three things, the executed
command, generated file names after execution of any command and time of command
execution. This log file can be used for proper management of any generated testbench.
Executing scripts from the terminal can often be a difficult task and is not always the fastest
option for user. Hence, a graphical user interface option was created for the script utility. New
UVM users can use it to create and manage testbench easily. User can choose any one of the two
methods for generating codes. The GUI was developed using the open source QT Creator [5] in
Linux. Before using the GUI, Qt must be installed on the Linux operating system.
Bash scripts are created to automate UVM based testbench code generation. 40+ scripts are
created to generate different classes, add new instances and automate connections. All scripts are
written in Bash Shell language. The hierarchy of working scripts is shown in figure 2.
Depending on executed commands, specific scripts run for automating tasks. To add new classes
or connections appropriate script has to be chosen from this hierarchy. Different scripts are
generating different portions of testbench.
Scripts are working based on common bash commands such as: cat, echo, touch etc. SED is used
in order to add codes in specific locations [5]. Some of these scripts are shown in figure 3-6.
common=${1:-auto}
top_file=${2:-top.sv}
destination=${3:-mydir}
base_test_file=${4:-base_test.sv}
test_name=${5:-base_test}
$DIR/create_interface $interface_class
>$destination/$interface_file
$DIR/create_top $interface_file > $destination/$top_file
$DIR/create_test_base $test_name >
$destination/$base_test_file
$DIR/env_generate $common $base_test_file $destination
$active
Figure 5 - Script for creating instance of environment class inside base test file
Scripts are written for creating and connecting other classes also. Testbench generation using
these scripts from terminal and GUI are discussed in the following sections.
The proposed script based utility can be used in different ways to generate whole or different
parts of testbench. User has to run specific scripts from terminal to generate codes.
Three different types of commands can be executed for generating testbench. They are
commands for (1) creating new class or component, (2) creating instance of any class inside
another class and (3) creating interconnections between classes. Code is generated following
UVM class structure.
After creating initial testbench structure any number of new classes can be added to the existing
testbench. A bash script is created that executes other necessary scripts to create necessary
classes depending on the command. Table 1 shows these commands which can be used for initial
structure generation and creating new classes. Each command requires specific arguments to
create the testbench properly. There are 11 commands to create new class/es. Each command is
created for different purposes.
In UVM, classes are organized in a very systematic way [1]. Objects of some classes are
instantiated in other classes. Objects of any class can be instantiated inside other classes
automatically using this utility. Currently seven commands can be executed for creating
instances of necessary classes. These commands are shown in Table 2.
Codes are generated depending on the command executed on linux terminal. The main script in
this utility is “rtg” . The terminal commands discussed earlier follow this script on terminal.
For example, executing “rtg tb XYZ XYZ_top.sv XYZ_base_test.sv
XYZ_base_test XYZ_intf.sv XYZ_intf” on terminal, the basic UVM testbench
structure is generated. In this generated testbench, all file names have a common prefix “XYZ”.
Testbench files are created inside the destination folder “/home/ius/XYZ_test”. The basic
testbench structure includes the following files.
Inside the top file, UVM package and generated package files are imported automatically.
Interface file is included for creating connection between classes in lower level of hierarchy.
`include "XYZ_pkg.sv";
`include "XYZ_intf.sv"
module top;
import uvm_pkg::*
`include "uvm_macros.svh"
import XYZ_pkg::*;
initial
begin
run_test();
// Run Test Function
end
endmodule
Base test file is one of the most important portions of testbench. All other tests added to the
existing testbench have to be extended from this base class. Generated codes for this base test
class includes instantiation of environments and declaration of virtual sequence.
In any UVM testbench, usually environment represents a complete module. All agents,
sequences, drivers and monitors related to a certain block belongs to single environment. In this
testbench generation process, each environment is assumed to be representing individual blocks
in a large SoC. The following example shows generated code for XYZ environment.
XYZ_scb XYZ_scb_ins ;
XYZ_sbr XYZ_sub_ins ;
XYZ_agent XYZ_agent_ins ;
XYZ_vsequencer XYZ_vsequencer_ins ;
`uvm_component_utils_begin(XYZ_env)
`uvm_component_utils_end
.
.
endfunction : build_phase
Connections among lower level classes such as agent, scoreboard and subscriber are done in
connect phase of generated environment class.
XYZ_vsequencer_ins.XYZ_sequencer_ins=XYZ_agent_ins.XYZ_seq
uencer_ins;
if(XYZ_agent_ins.is_active == UVM_ACTIVE)begin
.
.
XYZ_agent_ins.XYZ_monitor_ins.XYZ_monitor_port.connect(XYZ
_scb_ins.port_XYZ_sent_pkt);
XYZ_agent_ins.XYZ_a_port.connect(XYZ_sub_ins.analysis_expo
rt);
end
else if(XYZ_agent_ins.is_active == UVM_PASSIVE)begin
.
.
XYZ_agent_ins.XYZ_monitor_ins.XYZ_monitor_port.connect(XY
Z_scb_ins.port_XYZ_sent_pkt);
XYZ_agent_ins.XYZ_a_port.connect(XYZ_sub_ins.analysis_exp
ort);
end
endfunction : connect_phase
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
factory.print();
endtask: run_phase
endclass : XYZ_env
Along with environment, base test classes, all other commonly used classes are generated from
“rtb tb” command execution. Some of them are shown below.
task body();
fork
`uvm_do_on(XYZ_sequence_ins,p_sequencer.XYZ_sequencer_ins)
join
endtask: body
endclass : XYZ_vsequence
endclass: XYZ_vsequencer
Driver, monitor and sequencer classes include port and task declarations. Design specific codes
have to be manually added to the testbench.
To add a new agent to the existing testbench, “rtg agent XYZ_2 XYZ_env.sv XYZ”
command is executed. The following files are generated in the testbench working directory.
The new agent class is named XYZ_2_agent. Driver, monitor and other classes related to this
agent class is also created. All of these classes have the same prefix XYZ_2.
`uvm_component_utils(XYZ_2_monitor)
uvm_analysis_port#(XYZ_2_trans) XYZ_2_monitor_port;
XYZ_2_trans XYZ_2_trans_ins;
function new(string name,uvm_component parent);
.
.
endfunction:new
endclass:XYZ_2_monitor
Figure 17 - Created monitor file for new agent
endclass : XYZ_2_driver
`uvm_component_utils_begin(XYZ_env)
Instance of the new agent class is created inside build phase of specified environment and gets
connected to scoreboard, subscribers in the connect phase.
XYZ_2_agent_ins=XYZ_2_agent::type_id::create("XYZ_2_agent_
ins",this);
XYZ_2_agent_ins.is_active=UVM_ACTIVE;
.
.
endfunction : build_phase
The following code shows the connect phase of environment class. In connect phase no
scoreboard or subscriber is connected to this agent. This agent can be connected to any
scoreboard or subscriber using connection scripts.
All generated files are included inside package file for compiling total testbench structure.
package XYZ_pkg;
import uvm_pkg::*;
`include "uvm_macros.svh"
`include "XYZ_2_sequence_item.sv"
.
.
`include "XYZ_2_sequencer.sv"
`include "XYZ_2_driver.sv"
`include "XYZ_2_sequence.sv"
.
.
`include "XYZ_2_monitor.sv"
`include "XYZ_2_agent.sv"
.
.
endpackage
Large SoCs contain many blocks. Different environment classes can be modelled for each block.
To connect a new block to the existing XYZ_test testbench
“rtg env ABC XYZ_base_test.sv” command is used. Generated new files include:
All the codes are generated in the same way as mentioned in previous sections. The following
example codes shows the generated environment file for this new ABC block.
endclass : XYZ_base_test
package XYZ_pkg;
import uvm_pkg::*;
`include "uvm_macros.svh"
.
.
.
`include "ABC_sequencer.sv"
`include "ABC_driver.sv"
`include "ABC_sequence.sv"
`include "ABC_subscriber.sv"
`include "ABC_scb.sv"
`include "ABC_monitor.sv"
`include "ABC_agent.sv"
`include "ABC_vsequencer.sv"
`include "ABC_env.sv"
`include "ABC_vsequence.sv"
`include "XYZ_base_test.sv"
endpackage
Testbench generation options are also available via a graphical user interface which has been
developed using QT Creator in Linux. The GUI incorporates options provided by the automation
scripts discussed earlier. Figure 28 shows the home window of the GUI.
This window contains options for testbench generation available for user. Clicking on any option
will bring out its respective window where user can pass necessary input arguments. Some
examples of generating testbench structure using the GUI are described below.
Figure 29 shows the “Create whole Testbench” window that appears when the “Create entire
testbench from top down” option is selected form the home window. The input arguments have
been filled in the respective boxes.
Arguments for generating initial testbench structure are on the left. The “Create Testbench”
option will take the three arguments Prefix, Top level filename and Destination and generate
testbench files. The generated folder window shown in Figure 30 is automatically brought up
upon button click.
Now the second option is selected from the home window in Figure 28 i.e. “Add env”. Choosing
that option brings up the “Create/Add Env” window as shown in Figure 31, where the necessary
arguments have been provided.
This option requires four arguments, Prefix, testFileName, Destination and agent type. This can
be used to add a new environment to the previously created testbench. The previous test filename
and destination has been provided as arguments and a new prefix for the new environment
components has been given. Clicking on the “create” button will generate the new environment
files in the destination. A screenshot of the destination folder with the added files is shown in
Figure 32.
Third option in the home window is “Add Agent”. Clicking on the corresponding button brings
up the “Create/Add Agent” window, shown in Figure 33. Input arguments have been provided.
“Prefix of new Agent” is used to identify the new agent and its subcomponents. “Prefix of env”
and “envFileName” is used to identify the environment class in which the new agent will be
instantiated. There is also an input that specifies the active or passive nature of the monitor
instantiated inside new agent. Clicking the “create” button will execute scripts and the new
agent will be generated and added to the destination folder. The new generated files are shown in
Figure 34.
7. Simulation Results
To check if generated code represents correct testbench structure and is free of syntax errors, we
have run a simulation of a UVM based testbench generated using this utility.
In figure 36 shows the end of simulation report. There are no UVM errors or fatal errors,
indicating correct compilation and simulation of the testbench. A command log keeps record of
script executions and generated files. Figure 37 shows the command log entry recorded for the
above simulation.
This utility can be updated in many ways. New scripts can be added to the existing tool for
enabling more options for users.
UVM is a highly accepted and used methodology for developing testbench for verifying RTL
models. It is being developed regularly. New features are being added to the existing
methodology. This utility can be improved by adding more features of UVM to the generated
codes. It will make generated testbench more robust and reusable.
Currently this tools generates testbench following a single structure. Depending on the RTL
model or protocol, engineers may use different structures for developing testbenches. So
enabling this feature to this utility will make it more efficient and useful.
This tool’s testbench management feature can be enhanced to make it a better management tool.
Engineers may need to create some files manually. In that case monitoring manual changes in
working directory can be very helpful to engineers. So testbench management features can
enhance its performance in different ways.
9. Conclusion
Script based testbench code generation makes it really easy to start a new SoC verification
project. Verification engineers do not need to write the common structure each time they start a
new project. As a result they can spend more time on testing design and finding bugs. Using
smart logging system, generated testbenches can be managed in a better way. Moreover
command logging system makes it possible to track advancement of generated testbench.
In conclusion, it can be expected that adding advanced UVM features, this utility will certainly
become a handy tool for automating testbench generation and management.
[2] B. Bailey, TLM-Driven Design and Verification Methodology, 1st ed. 2010.
[4] “Unix Sed Tutorial: Append, Insert, Replace, and Count File Lines.” [Online]. Available:
http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-append-insert-replace-and-count-file-
lines/. [Accessed: 08-Jul-2015].