uvm_tb_arch_doc_py
1
Table of contents:
1. Introduction
2. Overview of the Modules
3. Description of each Module
3.1 TB_arch_using_image_draw.py
3.2 component_name_finder.py
3.3 draw_rect_using_turtle.py
3.4 draw_rect_with_text_inside.py
3.5 pattern_finder_indir.py
3.6 tb_arch_img_draw.py
3.7 uvm_tb_arch_agent.py
3.8 uvm_tb_name_image_file_generator.py
2
1. Introduction
uvm_tb_arch_doc_py is a python project to automatically
generates the UVM testbench Architecture
The main aim of this project is, by using the Python Programming
language we have to generate the UVM testbench Architecture template.
For generating the UVM TB Architecture we have to write an example
testbench code (top, test, env, agent etc) in UVM Methodology.
For generating the UVM Testbench template, by using Python Programming
we can use either Python Turtle graphics or Python Image draw graphics
Python turtle Graphics is used to create shapes and patterns needs to
import python turtle from python library, by using Python turtle can
generate different shapes but before going to use this Turtle library
methods initially we have to define these methods it makes the Turtle
graphics as inefficient
The Image Draw module provides simple 2D graphics support for
Image Object. These graphics interface uses the same coordinate
system as [Link] is the Python Imaging Library which provides the
python interpreter with Image Editing Capabilities. It is simpler and
easier to understand it can be install by pip(pip install Pillow) . The
pillow color schemes we use is RGB. The color RGB representation
and support is provided by the module ImageColor.
3
How to Run python files
Step1: Download the latest python version in Desktop
Step2: Get Pycharm tool or can use command prompt window
Step3: Once the Pycharm tool installed in Desktop, go to file create a
project
Step4: PyCharm enables programmers to write high-quality Python
code in code editor. The editor enables programmers to read code
easily through color schemes. Write an example code in the code editor
and then save the file in the project
Step5: Right click on the file then select run option and execute the
code
4
2. Overview of the Modules
Module Description
In this folder, simple Memory testbench module code is
written in UVM Methodology.
dummy_tb Components that are used for building the Memory
testbench module are mem_seq_item, mem_wr_seq,
mem_rd_seq, mem_seqr, mem_drv, mem_mon,
mem_agent, mem_env, mem_test, mem_top.
TB_arch_using_image_draw.py This TB_arch_using_image_draw script module defines ,
How the TB Architecture Blocks (like top, test, env, dut,
scoreboard, interface, virtual interface, agent, monitor,
driver, seqr) should be generate in the image format
with respect to given input co-ordinates && colours
It also defines, how the connections are happened
between the Driver to Virtual Interface, Virtual
interface to Interface, Interface to DUT and Virtual
interface to Driver
component_name_finder.py This component_name_finder script modules defines,
When the user wants to find particular component in
the TB Architecture, first user have to enter the input as
the TB Directory path and then enter the Keyword of
the particular component name which want to search
Then the Output of this script generates the user
selected TB component class name and prints the
output in Normal && Table format
draw_rect_using_turtle.py This draw_rect_using_turtle script module defines
how to draw the rectangle shape by using Turtle
library
5
Module Description
draw_rect_with_text_inside.py This draw_rect_with_text_inside scripting module defines
How to write the text inside the rectangle shape by
using Image Draw module
This pattern_finder_indir Script defines,
How to find a pattern in all files of given directory i.e.,
pattern_finder_indir.py how to find the UVM components from the given test-
bench directory
Then it prints the filename and the path of the file. This
can be used to find all the different components of a
testbench.
This skeleton_component_search script defines
skeleton of component search How to find the generic word in TB components that
python can be searched to determine the presence of
component in TB
This tb_arch_img_draw script defines by using Image, Image
draw Module
tb_arch_img_draw.py
How to draw the agent components by reading the
tb_info.txt file, these file which contains the
information of agent i.e., no of agents
This uvm_tb_arch_agent script defines
uvm_tb_arch_agent.py
How to support number of agents upto 7 in the TB
Architecture
6
Module Description
This uvm_tb_name_image_file_generator script
defines
Here user enters the path of TB directory.
Setting the width and height according to the
screen size and Setting the canvas size, create
lookup table for uvm component and name.
Create file for writing component and
component name, also clean file before
writing the data.
uvm_tb_name_image_file_generator.py Drawing top level structure, set the co-
ordinates and set color for top as yellow color.
Drawing test level structure, set the co-
ordinates and set color for top as orange
color.
Drawing env level structure, set the co-
ordinates and set color for top as yellow color.
Drawing scoreboard level structure, set the
co-ordinates and set color for top as red.
Drawing agent level structure, set the co-
ordinates and set color for top as blue color
also set the image font.
Calling the rectangular creation function.
Here, user have to enter the input TB
directory path then it will create the block
diagram of component TB Architecture like-
top, test, env, agent, scoreboard
7
3. Description of each Module
3.1 TB_arch_using_image_draw.py
To draw TB Diagram aimed at 2 agentsTo draw Rectangle with
given co-ordinate & fill with given colour and write the text inside
rectangle
To draw top, test, env blocks write the value of n choosen height
of env block should be less , so we have to give proper dimensions
This “docx” module is to manipulate with docs like MS Word.
Used it to add TB diagram to the document, we have take handle
doc for docx
After we have to import tkinter & setting height & width to
measure whole screen size and then
Create 1st outer rectangle for top
Create 2nd inner rectangle for test
Create 3rd inner rectangle for env
Create 5th inner rectangle for scoreboard
Create 4th inner rectangle for sequences, DUT, Interface,
Virtual Interface
Check for No of agents user have to give
Start another rectangle MON inside agent
Start another rectangle DRV inside agent
Start another rectangle SEQR inside agent
Then draw the arrows between Driver to Virtual Interface, Virtual
Interface to Interface and Driver1 to Virtual Interface and then set
the start & end co-ordinates
By using arrowed line() method set the colour & thickness and
then add the picture & save the picture in docx
8
9
10
11
Results of TB_arch_using_image_draw script
12
3.2 component_name_finder.py
The component name finder script checks the particular keyword
in all files all lines and collects the class name of components here user
have to give the input directory path then it prints the output in
normal and table format for further processing
Import the os, re, prettytable modules enter the testbench
directory path, Open the doc file and then import the pretty table and
assign the Class names of the Testbench code as a Keyword
Then write the function for component search and then assign the
Input directory path to root directory path. Here we have to call the
component search function and checking the keyword of TB class
names and opening the docx file write the information in the file and
closing the file
13
14
Results of component_name_finder.py script
15
3.3 draw_rect_using_turtle.py
1)To draw the shapes using Turtle, the major shapes that are
needed to construct the Testbench architecture are square and
rectangle. Below is the Python script to draw square and rectangle
and also connectivity
Steps:
[Link] the turtle library
[Link] the Screen color
[Link] the object for Turtle
[Link] the pen color
[Link] function draw_square and draw_rect. Pass the co-
ordinates,length,width and color as the input to the function
[Link] to the desired location(co-ordinate) to draw the shape
[Link] begin_fill and end_fill to fill in the shape
16
Results of draw_rect_using_turtle.py script
17
3.4 draw_rect_with_text_inside.py(using Image draw
module)
To draw the shapes using Image draw module, the major shapes
that are needed to construct the Testbench architecture are square and
rectangle. Below is the Python script to draw square and rectangle and
also connectivity
Steps:
Created an empty image *.jpg file
Drew a rectangle in that image using ImageDraw module
Saved the image & using the Image Draw module, inserted
the text inside the rectangle (by changing the required
dimensions in trial and error manner)
Added that .jpg file into a .docx document & saved that.
(using docx module)
18
Results of draw_rect_with_text_inside.py script(using Image
draw module)
19
3.6 tb_arch_img_draw.py
To read the file which contains the information about
Testbench and to draw the agent components
Steps:
1. Read the file tb_info.txt which contains the agent information (Number of
agent). Read the first line and then using split method the words are stored in
a list form which the number can be retrieved.
2. Define the method top,test,env, agent, scoreboard, driver, sequencer and
monitor to draw the corresponding component
3. In the method definition, use the in-built function called rectangle from the
ImageDraw module to draw the components
4. The arguments to the functions are:
x0,y0 – Starting co-ordinate to draw the rectangle
x1,y1 - End co-ordinate
Outline – Outline color for the shape
[Link]-ordinates – where the text needs to be inserted
[Link] in the form of string
[Link] for the text
5. .Agents and its components are constructed based on the agent numbers.
From env() the scoreboard() and agent components are called
6. The text method in Image Draw module issued to include the text. The
parameters are: Coordinates, text, clour
7. The information collected from the testbench are written in a file. Here the
tb_info.txt file contains agent information (number of agents)
20
21
Results of tb_arch_img_draw.py script
22
3.7 uvm_tb_arch_agent.py
To draw TB Diagram aimed at 2 agentsTo draw Rectangle with
given co-ordinate & fill with given colour and write the text inside
rectangle
To draw top, test, env blocks write the value of n choosen height
of env block should be less , so we have to give proper dimensions
This “docx” module is to manipulate with docs like MS Word.
Used it to add TB diagram to the document, we have take handle
doc for docx
After we have to import tkinter & setting height & width to
measure whole screen size and then
Create 1st outer rectangle for top
Create 2nd inner rectangle for test
Create 3rd inner rectangle for env
Create 5th inner rectangle for scoreboard
Create 4th inner rectangle for sequences, DUT, Interface,
Virtual Interface
Check for No of agents user have to give
Start another rectangle MON inside agent
Start another rectangle DRV inside agent
Start another rectangle SEQR inside agent
Then draw the arrows between Driver to Virtual Interface, Virtual
Interface to Interface and Driver1 to Virtual Interface and then set
the start & end co-ordinates
By using arrowed line() method set the colour & thickness and
then add the picture & save the picture in docx
23
24
25
26
Results of uvm_tb_arch_agent.py
27
3.8 uvm_tb_name_image_file_generator.py
Firstly import the PIL(Python Imaging Library) which is Pillow, it adds
image processing capabilities to python interpreter.
This library provides extensive file format support, an efficient internal
representation, and fairly powerful image processing capabilities. Import
tkinter package (tk interface) is a standard python interface to the tk GUI
toolkit.
Now adding pillow and tkinter for image draw and canvas. The Canvas is a
rectangular area intended for drawing pictures or other complex layouts.
Import image , imagedraw and imagefont from pillow.
Then import OS library which is the module in python provides functions
for interacting with the operating [Link] module provides a portable
way of using operating system-dependent functionality.
Now user enters the path of TB directory. Set width and height according
to the screen size. Set canvas size, create lookup table for uvm component
and name. Create file for writing component and component name, also
clean file before writing the data.
Now drawing top level structure, set the co-ordinates and set color for top
as yellow color. Drawing test level structure, set the co-ordinates and set
color for top as orange color. Drawing env level structure, set the co-
ordinates and set color for top as yellow color.
Drawing scoreboard level structure, set the co-ordinates and set color for
top as red. Drawing agent level structure, set the co-ordinates and set
color for top as blue color also set the image font.
Call the rectangular creation function. So we are doing here, user enter
the input as TB directory and it will create block diagram of the
component like- top, test, env, agent, scoreboard
28
29
30
31
32
Results of Create uvm_tb_name_image_file_generator:
33
Results of Create uvm_tb_name_image_file_generator:
34