├── README.md ├── documents ├── basic.docx ├── tb_agent.docx ├── tb_arch_img_draw.docx ├── turtle_image_draw.docx └── uvm_tb_arch_doc.pdf ├── dummy_tb ├── dummy_agent_1.sv ├── dummy_drv_1.sv ├── dummy_mon_1.sv ├── dummy_seqr_1.sv ├── mem_agent.sv ├── mem_drv.sv ├── mem_model_env.sv ├── mem_model_test.sv ├── mem_monitor.sv ├── mem_rd_seq.sv ├── mem_scoreboard.sv ├── mem_seq_item.sv ├── mem_sequencer.sv ├── mem_wr_seq.sv └── tb_top.sv ├── example ├── magna_sim.log └── readme.txt ├── image_draw ├── TB_arch_using_image_draw.py ├── UVM_tb_arch_09_04.py ├── component_name_ finder.py ├── draw_rect_with_text_inside.py ├── pattern_finder_indir.py ├── plain_colour_font_size ├── tb_arch_img_draw.py ├── tlm_identifier.py ├── uvm_tb_arch_agent.py └── uvm_tb_name_image_file_generator.py ├── turtle_files ├── draw_rect_using_turtle.py ├── file creation and turtle library document.docx ├── pgm1.py ├── skeleton of component search python .py └── tb_arch.py ├── uvm_tb_arch_doc_py.py └── uvm_tb_arch_doc_py_diagram.pdf /README.md: -------------------------------------------------------------------------------- 1 | # UVM Testbench Flow diagram with Python 2 | 3 | ## Introduction 4 | uvm_tb_arch_doc_py is a python script to automatically generate the UVM testbench Architecture. 5 | 6 | It reads a UVM simulation log file and converts in to a JPEG diagram. 7 | 8 | ## What you Achieve 9 | A UVM Testbench Architecture Template using the PythonScript. 10 | 11 | Refer the pdf file attached in the main directory - uvm_tb_arch_doc_py_diagram.pdf 12 | 13 | ![image](https://user-images.githubusercontent.com/61039744/119836958-ca11fd00-bf1f-11eb-8781-8a30b02779b7.png) 14 | 15 | 16 | ## Requirements 17 | For generating the UVM TB Architecture we have to write an example testbench code (top, test, env, agent etc) in UVM Methodology. 18 | 19 | 1) UVM Testbench log file with extension .log format 20 | 21 | 2) Pycharm Editor (version 2021.1.1 x64) 22 | 23 | 3) Libraries required: 24 | 25 | - OpenCV ( To help with plotting the image and to also save the generated testbench image) 26 | 27 | - PIL (Includes functions like Image, ImageDraw. ImageFont) 28 | 29 | - Tkinter (Help with setting up the canvas for plotting the image) 30 | 31 | 4) Packages to be installed: 32 | 33 | - pip install pillow 34 | - pip install opencv-python 35 | - pip install python-docx 36 | 37 | 38 | # Usage 39 | The PyCharm Editor is suitable to run this project as it provides an environment to install packages within a terminal present in the editor. 40 | 41 | -- Youtube link to be provided how to use 42 | 43 | 1) open the Pycharm editor. 44 | 45 | 2) click File -> New Project. 46 | 47 | 3) Create the project in a specific directory. 48 | 49 | 4) Configure the base interpreter of python if it is already installed on the system. If python is not present in the system, install Pycharm and then there will be an option provided to set a base interpreter. 50 | 51 | 5) Create a virtual environment for your project. ( This setup will take 2-3 minutes). 52 | 53 | 6) Open the Pycharm terminal and install the packages one after another as mentioned in point 4) of the Requirements section. 54 | 55 | 7) Create a folder named 'log' in the project directory. 56 | 57 | 8) Copy all the files into the Project directory that has been created. (For example, the path I have created is C:\Users\Priya A\PycharmProjects\UVM_TB_ARCH) 58 | 59 | 9) Make sure to copy the log file into the log folder in the project.(For example, suppose the log file has a name testbench.log, then the file should be in the folder named 'log') 60 | 61 | 10) Execute the Python Script by clicking on the Run button in Pycharm 62 | 63 | 11) The output window will ask the user to enter the following: 64 | 65 | - Enter the name of the log directory (Enter 'log') 66 | 67 | - Enter the number of interfaces (for eg:4) 68 | 69 | - Enter the number of agents (for eg: 2) 70 | 71 | - Enter the number of tb connect to DUT (for eg: 3 it depends on how many interfaces you want to conenct with DUT) 72 | 73 | 74 | 12) The output testbench will then be displayed in the background as per ther various inputs provided. 75 | 76 | 77 | -------------------------------------------------------------------------------- /documents/basic.docx: -------------------------------------------------------------------------------- 1 | Task: 2 | 1)To draw the shapes using Turtle 3 | 4 | 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 5 | 6 | Steps: 7 | 1.Import the turtle library 8 | 2.Set the Screen color 9 | 3.Instantiate the object for Turtle 10 | 4.Set the pen color 11 | 5.Define function draw_square and draw_rect. Pass the co-ordinates,length,width and color as the input to the function 12 | 6.Move to the desired location(co-ordinate) to draw the shape 13 | 7.Use begin_fill and end_fill to fill in the shape 14 | 15 | Square and rectangle 16 | 17 | import turtle 18 | s=turtle.Screen() 19 | s.bgcolor("light blue") #Set the background color of the screen 20 | ptr = turtle.Turtle() 21 | ptr.pencolor("black") 22 | def draw_square(x,y,l,color): #To draw square 23 | ptr.fillcolor(color) 24 | ptr.penup() #Pen up before moving to the desired co-ordinate 25 | ptr.goto(x,y) #To move the turtle to the co-ordinate (x,y) 26 | ptr.pendown() #Pen down to start drawing 27 | ptr.begin_fill() #To start filling the color 28 | for i in range(4): #Repeat the below steps for 4 times to get the square 29 | ptr.forward(l) #length of the square 30 | ptr.left(90) #Turn toward the left by 90 degree 31 | ptr.end_fill() 32 | 33 | def draw_rect(x,y,l,w,color): #To draw rectangle 34 | ptr.fillcolor(color) 35 | ptr.penup() 36 | ptr.goto(x,y) #To move the turtle to the co-ordinate (x,y) 37 | ptr.pendown() #Pen down to start drawing 38 | ptr.begin_fill() #To start filling the color 39 | for i in range(2): #Repeat for 2 times to complete the rectangle 40 | ptr.forward(l) #Length of the rectangle 41 | ptr.left(90) #Turn left by 90 degree 42 | ptr.forward(w) #Width of the rectangle 43 | ptr.left(90) #Turn left by 90 degree 44 | ptr.end_fill() 45 | 46 | draw_square(-200,50,100,"red") #Call the method by passing the arguments (x-axis,y-axis,length,fll_color) 47 | draw_rect(200,50,100,200,"green") #Call the method by passing the arguments (x-axis,y-axis,length,width,fll_color) 48 | 49 | 50 | Square inside a square 51 | 52 | import turtle 53 | s=turtle.Screen() 54 | s.bgcolor("light blue") 55 | ptr = turtle.Turtle() 56 | ptr.pencolor("black") 57 | def draw_square(x,y,l,color): #Draw a square 58 | ptr.fillcolor(color) 59 | 60 | ptr.penup() #Pen up before moving to the desired co-ordinate 61 | 62 | ptr.goto(x,y) #To move the turtle to the co-ordinate (x,y) 63 | 64 | ptr.pendown() #Pen down to start drawing 65 | 66 | ptr.begin_fill() #To start filling the color 67 | 68 | for i in range(4): #Repeat the below steps for 4 times to get the square 69 | 70 | ptr.forward(l) #length of the square 71 | 72 | ptr.left(90) #Turn toward the left by 90 degree 73 | 74 | draw_square(-100,50,100,"red") #Call the method by passing the parameters(x axis,y axis,length,color) 75 | 76 | draw_square(-150,0,200,"red")#Call the method by passing the parameters(x axis,y axis,length,color) 77 | ptr.end_fill() #To end the color 78 | 79 | Task: 80 | 2)To draw the connection between 2 squares and to include text 81 | 82 | Steps: 83 | 1.Import the turtle library 84 | 2.Set the Screen color 85 | 3.Instantiate the object for Turtle 86 | 4.Set the pen color 87 | 5.Call the method draw_square by passing the co-ordinates, length and fill_color as parameters 88 | 6.After drawing 2 squares, call the method draw_arrow to draw the arrow head 89 | 7.Write the text at the centre of the turtle pointer by calling the method write_text by passing the co-ordinates and text 90 | 91 | 92 | Connecting 2 squares with an arrow head and including text 93 | 94 | import turtle 95 | s=turtle.Screen() #Set the background color of the screen 96 | s.bgcolor("light blue") 97 | ptr = turtle.Turtle() 98 | ptr.pencolor("black") 99 | def draw_square(x,y,l,color): #Draw the square 100 | ptr.fillcolor(color) 101 | 102 | ptr.penup() #Pen up before moving to the desired co-ordinate 103 | 104 | ptr.goto(x,y) #To move the turtle to the co-ordinate (x,y) 105 | 106 | ptr.pendown() #Pen down to start drawing 107 | 108 | ptr.begin_fill() #To start filling the color 109 | 110 | for i in range(4): #Repeat the below steps for 4 times to get the square 111 | 112 | ptr.forward(l) #length of the square 113 | 114 | ptr.left(90) #Turn toward the left by 90 degree 115 | 116 | ptr.end_fill() 117 | 118 | def draw_arrow(): #Draw the arrow head 119 | ptr.left(45) #Turn left by 45 degree 120 | ptr.backward(10) #move backward and then forward by same unit 121 | ptr.forward(10) 122 | ptr.right(90) #Turn right by 90 degree 123 | ptr.backward(10) #move backward and then forward by same unit 124 | ptr.forward(10) 125 | ptr.left(45) #Move again to the original turtle position 126 | def write_text(x,y,text): #Write the text 127 | ptr.penup() 128 | ptr.goto(x,y) #Move to the co-ordinate(x,y) 129 | ptr.pendown() 130 | ptr.write(text,align="center") #Write the text at the center of the turtle pointer 131 | 132 | draw_square(-200,0,100,"red") #Call the method by passing the arguments (x-axis,y-axis,length,fll_color) 133 | 134 | draw_square(100,0,100,"red") #Call the method by passing the arguments (x-axis,y-axis,length,fll_color) 135 | 136 | ptr.penup() 137 | ptr.goto(-100,50) #move to the centre of the sqaure 138 | ptr.pendown() 139 | ptr.forward(200) #Connect the 2 sqaures 140 | draw_arrow() #Call the method to draw an arrow head 141 | write_text(0,50,"connect") #Call the method by passing the text to be written as argument 142 | 143 | -------------------------------------------------------------------------------- /documents/tb_agent.docx: -------------------------------------------------------------------------------- 1 | Task: 2 | To read the file which contains the information about Testbench and to draw the agent components 3 | Steps: 4 | 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. 5 | 2.Define the method top,test,env ,agent,scoreboard,driver,sequencer and monitor to draw the corresponding component 6 | 3.In the method definition 7 | 1.Choose the desired color to fill 8 | 2.Move to the desired co-ordinates to draw the structure 9 | 3. Name the components by using the write method 10 | 4.From env() call the method sequencer() 11 | 5 .Agents and its components are constructed based on the agent numbers. From env() the agent components are called 12 | 6.Connectivty: 13 | 1.Draw the connecting arrow head from centre of the sequencer to the driver 14 | 2.Draw the connectivity between driver and the Interface 15 | 3.Draw the connectivity between monitor and the Interface 16 | 17 | The information collected from the testbench are written in a file. Here the tb_info.txt file contains agent information (number of agents) 18 | ***************** tb_info.txt********************* 19 | Agent = 2 20 | 21 | This file is taken as an input to draw the TB architecture. 22 | *********************tb_arch.py******************* 23 | import turtle 24 | f=open("tb_info.txt",'r') #The input file(tb_info.txt) is read and then the information is extracted 25 | content = f.readline() #Read the first line 26 | agent=content.split() #Split the words and store it in an array agent[] 27 | agent_number=agent[2] #The variable agen_number now contains the number of agent in the TB 28 | f.close() 29 | print(agent_number) 30 | screen = turtle.Screen() 31 | t = turtle.Turtle() 32 | t.speed(30) 33 | def top(): #Draw the top 34 | t.fillcolor("grey") #Filling the rectangle with the color 35 | t.penup() 36 | t.goto(-650,330) #To move the turtle to the co-ordinate(-650,330) 37 | t.pendown() 38 | for i in range(2): #Draw the Rectangle 39 | t.begin_fill() 40 | t.forward(1300) #Length of the rectangle 41 | t.right(90) #Turn right by 90 degree 42 | t.forward(480) #Widthof the rectangle 43 | t.right(90) 44 | t.end_fill() 45 | t.penup() 46 | t.goto(-630,310) #To move the turtle to the co-ordinate(-630,310) 47 | t.pendown() 48 | t.write("top",align="center",font=10) #Write the text to represent the “top” 49 | t.hideturtle() 50 | def test(): #Draw the test 51 | t.fillcolor("light blue") 52 | t.penup() 53 | t.goto(-630,300) #To move the turtle to the co-ordinate(-630,300) 54 | t.pendown() 55 | for i in range(2): #Draw the rectangle 56 | t.begin_fill() 57 | t.forward(1260) 58 | t.right(90) 59 | t.forward(420) 60 | t.right(90) 61 | t.end_fill() 62 | t.penup() 63 | t.goto(-600,280) #To move the turtle to the co-ordinate(-600,280) 64 | t.pendown() 65 | t.write("test",align="center",font=10) #Write the text to represent the “test” 66 | #t.hideturtle() 67 | def env(): #Draw the env 68 | t.fillcolor("light green") 69 | t.penup() 70 | t.goto(-600,270) #To move the turtle to the co-ordinate(-600,270) 71 | t.pendown() 72 | for i in range(2): #Draw the rectangle 73 | t.begin_fill() 74 | t.forward(1200) 75 | t.right(90) 76 | t.forward(360) 77 | t.right(90) 78 | t.end_fill() 79 | t.penup() 80 | t.goto(-580,250) 81 | t.pendown() 82 | t.write("env",align="center",font=10) #Write the text to represent the “env” 83 | scoreboard() #Call this method to draw the scoreboard 84 | for i in range(int(agent_number)): #Call this method to draw the agent and its components based on the number of agents 85 | agent(i) 86 | sequencer(i) 87 | driver(i) 88 | monitor(i) 89 | def scoreboard(): #Draw the scoreboard 90 | t.fillcolor("light yellow") 91 | t.penup() 92 | t.goto(-280,240) #To move the turtle to the co-ordinate(-280,240) 93 | t.pendown() 94 | for i in range(2): #Draw the rectangle 95 | t.begin_fill() 96 | t.forward(350) 97 | t.right(90) 98 | t.forward(50) 99 | t.right(90) 100 | t.end_fill() 101 | t.penup() 102 | t.goto(-105,215) 103 | t.pendown() 104 | t.write("Scoreboard",align="center",font=10) #Write the text to represent the “scoreboard” 105 | def agent(y): #Draw the agent 106 | t.fillcolor("pink") 107 | t.penup() 108 | print(y,int(agent_number)) 109 | x = y * ((1120/int(agent_number)) + 10) #Calculates where to start drawing the agents (The starting point of agent N+1 depends on where the agent N ends) 110 | t.goto(-560 + x,160) #Move the turtle to the co-ordinate based on the number of agents 111 | t.pendown() 112 | for i in range(2): #Draw the rectangle 113 | t.begin_fill() 114 | t.forward(1120/int(agent_number)) #Adjust the length of the rectangle based on agent number(If agent_number is 1 then move 1120 units forward) 115 | t.right(90) 116 | t.forward(220) 117 | t.right(90) 118 | t.end_fill() 119 | t.penup() 120 | t.goto(-500 + x,120) 121 | t.pendown() 122 | t.write("Agent"+ str(y+1),align="center",font=10) #Name the agents 123 | def sequencer(y): #Draw the sequencer 124 | t.penup() 125 | print(y,int(agent_number)) 126 | x = y * ((1120/int(agent_number)) + 10) #Calculates where to start drawing the sequencer 127 | t.goto(-550 + x,100) #Move the turtle to the co-ordinate based on the number of agents 128 | t.pendown() 129 | for i in range(2): 130 | t.forward(260/int(agent_number)) #decide the length of the rectangle based on the number of agents 131 | t.right(90) 132 | t.forward(80) 133 | t.right(90) 134 | t.penup() 135 | t.goto((-550 + 130/int(agent_number))+ x,60) 136 | t.pendown() 137 | t.write("Sequencer",align="center",font=10) #Name the sequencer 138 | #To draw arrow head between sequencer and driver 139 | t.penup() 140 | t.goto(-550 + x + (260/int(agent_number)) ,60) #Move to the centre of the sequencer 141 | t.pendown() 142 | z = (300/int(agent_number)) + 10 #Calculates the distance in units between the sequencer and driver 143 | t.goto((-540 + z + x),60) #Draw a line connecting the sequencer and driver 144 | #To draw the arrow head 145 | t.left(45) 146 | t.backward(10) 147 | t.forward(10) 148 | t.right(90) 149 | t.backward(10) 150 | t.forward(10) 151 | t.left(45) 152 | def driver(y): #Draw the driver 153 | t.penup() 154 | print(y,int(agent_number)) 155 | x = y * ((1120/int(agent_number)) + 10) #Calculates where to start drawing the sequencer 156 | z = (300/int(agent_number)) + 10 #Calculates the distance between the sequencer and driver so as to set the turtle pointer 157 | t.goto((-540 + z + x),100) #Move to the co-ordinates based on the number of agent 158 | t.pendown() 159 | for i in range(2): 160 | t.forward(300/int(agent_number)) #Decide the length of the rectangle based on the number of agents 161 | t.right(90) 162 | t.forward(80) 163 | t.right(90) 164 | t.penup() 165 | t.goto(-540 + z + x + 150/int(agent_number),60) 166 | t.pendown() 167 | t.write("Driver",align="center",font=10) #Name the driver 168 | t.penup() 169 | t.goto(-540 + z + x + 150/int(agent_number),20) #Move to the centre of the driver 170 | #Draw the connectivity between Driver and interface 171 | t.pendown() 172 | t.right(90) #Moves towards the right and draw the line 173 | t.pendown() 174 | t.forward(200) 175 | #To draw the arrow head 176 | t.left(45) 177 | t.backward(10) 178 | t.forward(10) 179 | t.right(90) 180 | t.backward(10) 181 | t.forward(10) 182 | t.left(45) 183 | t.left(90) 184 | def monitor(y): #Draw the monitor 185 | t.penup() 186 | print(y,int(agent_number)) 187 | x = y * ((1120/int(agent_number)) + 10) #Calculates where to start drawing the monitor 188 | z= 2 * (300/int(agent_number)) + 20 #Calculate the distance in units between driver and monitor 189 | t.goto((-540 + z + x),100) #Move to the co-ordinate based on the number of agents 190 | t.pendown() 191 | for i in range(2): #Draw the rectangle 192 | t.forward(300/int(agent_number)) 193 | t.right(90) 194 | t.forward(80) 195 | t.right(90) 196 | t.penup() 197 | t.goto(-540 + z + x + 150/int(agent_number),60) 198 | t.pendown() 199 | t.write("Monitor",align="center",font=10) #Name the monitor 200 | t.penup() 201 | t.goto(-540 + z + x + 150/int(agent_number),20) #Move to the centre of the monitor 202 | t.pendown() 203 | #Draw the connectivity between monitor and interface 204 | t.right(90) 205 | t.pendown() 206 | t.forward(200) 207 | t.backward(200) 208 | #Move the turtle pointer backward and draw the arrow head pointing the monitor 209 | t.left(180) 210 | t.left(45) 211 | t.backward(10) 212 | t.forward(10) 213 | t.right(90) 214 | t.backward(10) 215 | t.forward(10) 216 | t.left(45) 217 | t.right(90) 218 | #Call the below 3 methods to draw the top,test and env 219 | top() 220 | test() 221 | env() 222 | -------------------------------------------------------------------------------- /documents/tb_arch_img_draw.docx: -------------------------------------------------------------------------------- 1 | Task: (Using Image,ImageDraw module) 2 | To read the file which contains the information about Testbench and to draw the agent components 3 | Steps: 4 | 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. 5 | 2.Define the method top,test,env ,agent,scoreboard,driver,sequencer and monitor to draw the corresponding component 6 | 3.In the method definition, use the in-built function called rectangle from the ImageDraw module to draw the components 7 | The arguments to the functions are: 8 | 1.x0,y0 – Starting co-ordinate to draw the rectangle 9 | 2.x1,y1 - End co-ordinate 10 | 3.Fill color – Color to fill in the rectangle 11 | 4.Outline – Outline color for the shape 12 | 5 .Agents and its components are constructed based on the agent numbers. From env() the scoreboard() and agent components are called 13 | 6.The text method in Image Draw module issued to include the text. The parameters are: 14 | 1.Co-ordinates – where the text needs to be inserted 15 | 2.Text in the form of string 16 | 3.Color for the text 17 | The information collected from the testbench are written in a file. Here the tb_info.txt file contains agent information (number of agents) 18 | ***************** tb_info.txt********************* 19 | Agent = 2 20 | 21 | This file is taken as an input to draw the TB architecture. 22 | *********************tb_arch_imgdraw.py******************* 23 | from PIL import ImageDraw,Image # Import Image and ImageDraw module form PIL(Python Image Library) 24 | f=open("tb_info.txt",'r') #The input file(tb_info.txt) is read and then the information is extracted 25 | content = f.readline() #Read the first line 26 | agent=content.split() #Split the words and store it in an array agent[] 27 | agent_number=agent[2] #The variable agent_number now contains the number of agent in the TB 28 | f.close() 29 | print(agent_number) 30 | img=Image.new("RGB",(500,500),"white") #Create a new image with screen size as 500X500 and color as white 31 | draw=ImageDraw.Draw(img) #Get the pointer to draw on the image 32 | def top(): #Draw the top 33 | draw.rectangle((5,5,495,360),fill="blue",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 34 | draw.text((8,8),"top",fill="black") #Call the method text to insert the text ((x,y),text,fill_color) 35 | def test(): #Draw the test 36 | draw.rectangle((20,20,480,340),fill="green",outline="black") 37 | draw.text((22,22),"test",fill="black") #Call the method text to insert the text ((x,y),text,fill_color) 38 | def env(): #Draw the env 39 | draw.rectangle((35,35,465,320),fill="grey",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 40 | draw.text((38,38),"env",fill="black") #Call the method text to insert the text ((x,y),text,fill_color) 41 | 42 | scoreboard() #Call the scoreboard() 43 | for i in range(int(agent_number)): Call the agents and its components based on the number of agents 44 | agent(i) 45 | sequencer(i) 46 | driver(i) 47 | monitor(i) 48 | def scoreboard(): #Draw the scoreboard 49 | draw.rectangle((150,40,350,80),fill="yellow",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 50 | 51 | draw.text((225,50),"Scoreboard",fill="black") #Call the method text to insert the text ((x,y),text,fill_color) 52 | 53 | def agent(y): #Draw the agent 54 | #We need to determine the starting and ending co-ordinates based on the number of agents. So the calculations are made in such a way to determine the co-ordinates by diving the agent number 55 | x = y * ((380/int(agent_number)) + 10) #Determines the starting co-ordinate to draw the agent 56 | z=380/int(agent_number) #Determines the end co-ordinate 57 | draw.rectangle((50+x,90,z+50+x,300),fill="pink",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 58 | #If the agent number is 1 the co-ordinates are (50,90,430,300). Similarly, the total available units are divided by the agent number to accommodate in it 59 | draw.text((55+x,90),"agent",fill="black") 60 | def sequencer(y): 61 | x = y * ((380/int(agent_number)) + 10) #Determines the starting co-ordinate to draw the sequencer 62 | z=190/int(agent_number) #Determines the end co-ordinate 63 | draw.rectangle((60+x,100,z+60+x,140),fill="pink",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 64 | draw.text((60+x,115),"sequencer",fill="black") 65 | def driver(y): 66 | x = y * ((380/int(agent_number)) + 10) #Determines the starting co-ordinate to draw the driver 67 | z=160/int(agent_number) #Determines the end co-ordinate 68 | draw.rectangle((60+x,180,z+60+x,220),fill="pink",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 69 | draw.text((65+x,190),"driver",fill="black") 70 | def monitor(y): 71 | x = y * ((380/int(agent_number)) + 10) #Determines the starting co-ordinate to draw the monitor 72 | z=160/int(agent_number) #Determines the end co-ordinate 73 | draw.rectangle((60+x+z+10,180,((z*2)+60+x),220),fill="pink",outline="black") #Call the method rectangle with the desired parameters((x0,y0,x1,y1),fill_color,outline) 74 | draw.text((65+x+z,190),"monitor",fill="black") 75 | #Call the below methods 76 | top() 77 | test() 78 | env() 79 | img.show() #To display the resultant image 80 | -------------------------------------------------------------------------------- /documents/turtle_image_draw.docx: -------------------------------------------------------------------------------- 1 | Pre-requisites Done : 2 | • Read and understood basics of Python 3 | • Understood about installation and using python 4 | • Learnt what is module, how it is imported and can be used in the code 5 | • Drawing line, opening a jpeg file 6 | 7 | 8 | 02/02/2020 Draw a rectangle and write text inside it (Exploring Turtle & ImageDraw modules) • Analyzed the modules Image Draw & Turtle 9 | • Drawn a rectangle and wrote text inside it using required methods 10 | • Read about manipulating with documents like .docx file using docx module 11 | 12 | 13 | 1. Draw a rectangle and write text inside it (using Turtle & Image Draw modules) 14 | Analyzed the module ImageDraw module 15 | • Created an empty image *.jpg file 16 | • Drew a rectangle in that image using ImageDraw module 17 | • Saved the image & using the Image Draw module, inserted the text inside the rectangle (by changing the required dimensions in trial and error manner) 18 | • Added that .jpg file into a .docx document & saved that. (using docx module) 19 | Analyzed & tried with turtle 20 | • Created rectangle by traversing via directions and inserted text inside the rectangle 21 | 22 | Using ImageDraw Module 23 | import docx 24 | from PIL import Image,ImageDraw 25 | doc = docx.Document() 26 | img = Image.new("RGB", (500, 500),"white") 27 | # create a image draw handle 28 | img1 = ImageDraw.Draw(img) 29 | img1.rectangle((200,125,300,200),fill ="orange", outline = "black",width = 1) 30 | img1.text((210, 150), "CHECK TEXT", fill = "black",align = "center") 31 | img.show() 32 | img.save('C:\\Users\\path \\line.jpg'); 33 | doc.add_picture('C:\\path \\line.jpg'); 34 | doc.save('C:\\Users\\goushik\\Desktop\\New folder\\pattern_printing_ex.docx'); 35 | 36 | 37 | 38 | Using Turtle : 39 | from turtle import * 40 | # Choose Color for rectangle 41 | color("orange") 42 | begin_fill() # Enabling fill to color the shape 43 | # Traverse in directions, to draw rectangle 44 | forward(300); 45 | right(90) 46 | forward(150) 47 | right(90) 48 | forward(300); 49 | right(90) 50 | forward(150) 51 | right(90) 52 | # End the coloring 53 | end_fill() 54 | color("BLACK") # Choose Black color to write 55 | begin_fill() 56 | penup() 57 | forward (150) 58 | #right (45) 59 | left(65) 60 | backward (20) 61 | write("TEXT INSIDE RECTANGLE USING TURTLE", True, align="center") 62 | #write("TEXT", True, align="center") 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /documents/uvm_tb_arch_doc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muneeb-mbytes/uvm_tb_arch_doc_py/a32618aae4bb57e51211c6a1a2e59fa63140f2ac/documents/uvm_tb_arch_doc.pdf -------------------------------------------------------------------------------- /dummy_tb/dummy_agent_1.sv: -------------------------------------------------------------------------------- 1 | class mem_agent_1 extends uvm_agent; 2 | //declaring agent components 3 | mem_driver_1 driver; 4 | mem_sequencer_1 sequencer; 5 | mem_monitor_1 monitor; 6 | 7 | // UVM automation macros for general components 8 | `uvm_component_utils(mem_agent_1) 9 | 10 | // constructor 11 | function new (string name, uvm_component parent); 12 | super.new(name, parent); 13 | endfunction : new 14 | 15 | // build_phase 16 | function void build_phase(uvm_phase phase); 17 | super.build_phase(phase); 18 | 19 | //Creating driver and sequencer when the agent is active. 20 | if(get_is_active() == UVM_ACTIVE) begin 21 | driver = mem_driver_1::type_id::create("driver", this); 22 | sequencer = mem_sequencer_1::type_id::create("sequencer", this); 23 | end 24 | 25 | //Creating monitor. 26 | monitor = mem_monitor_1::type_id::create("monitor", this); 27 | endfunction : build_phase 28 | 29 | // connect_phase:TLM port connection between sequencer and driver. 30 | function void connect_phase(uvm_phase phase); 31 | if(get_is_active() == UVM_ACTIVE) begin 32 | driver.seq_item_port.connect(sequencer.seq_item_export); 33 | end 34 | endfunction : connect_phase 35 | 36 | endclass : mem_agent_1 37 | -------------------------------------------------------------------------------- /dummy_tb/dummy_drv_1.sv: -------------------------------------------------------------------------------- 1 | class mem_driver_1 extends uvm_driver #(mem_seq_item); 2 | 3 | // Virtual Interface 4 | virtual mem_if vif; 5 | 6 | `uvm_component_utils(mem_driver_1) 7 | 8 | // Constructor 9 | function new (string name, uvm_component parent); 10 | super.new(name, parent); 11 | endfunction : new 12 | 13 | function void build_phase(uvm_phase phase); 14 | super.build_phase(phase); 15 | if(!uvm_config_db#(virtual mem_if)::get(this, "", "vif", vif)) 16 | `uvm_fatal("NO_VIF",{"virtual interface must be set for: ",get_full_name(),".vif"}); 17 | endfunction: build_phase 18 | 19 | // run phase 20 | virtual task run_phase(uvm_phase phase); 21 | forever begin 22 | //Polling for transaction from the TLM fifo. 23 | seq_item_port.get_next_item(req); 24 | 25 | //Converting transaction level data to pin level data in this method and driving it on the virtual interface. 26 | drive(); 27 | 28 | //Indicating the transaction completion. 29 | seq_item_port.item_done(); 30 | end 31 | endtask : run_phase 32 | 33 | // drive 34 | virtual task drive(); 35 | req.print(); 36 | `DRIV_IF.wr_en <= 0; 37 | `DRIV_IF.rd_en <= 0; 38 | @(posedge vif.DRIVER.clk); 39 | `DRIV_IF.addr <= req.addr; 40 | if(req.wr_en) begin 41 | `DRIV_IF.wr_en <= req.wr_en; 42 | `DRIV_IF.wdata <= req.wdata; 43 | //$display("\tADDR = %0h \tWDATA = %0h",req.addr,trans.wdata); 44 | @(posedge vif.DRIVER.clk); 45 | end 46 | if(req.rd_en) begin 47 | `DRIV_IF.rd_en <= req.rd_en; 48 | @(posedge vif.DRIVER.clk); 49 | `DRIV_IF.rd_en <= 0; 50 | @(posedge vif.DRIVER.clk); 51 | req.rdata = `DRIV_IF.rdata; 52 | // $display("\tADDR = %0h \tRDATA = %0h",trans.addr,`DRIV_IF.rdata); 53 | end 54 | $display("-----------------------------------------"); 55 | endtask : drive 56 | 57 | endclass : mem_driver_1 58 | -------------------------------------------------------------------------------- /dummy_tb/dummy_mon_1.sv: -------------------------------------------------------------------------------- 1 | class mem_monitor_1 extends uvm_monitor; 2 | 3 | // Virtual Interface 4 | virtual mem_if vif; 5 | 6 | //Declaring analysis port for writing to the scoreboard 7 | uvm_analysis_port #(mem_seq_item) item_collected_port; 8 | 9 | // Placeholder to capture transaction information. 10 | mem_seq_item trans_collected; 11 | 12 | //Registering monitor class with the factory 13 | `uvm_component_utils(mem_monitor_1) 14 | 15 | // new - constructor 16 | function new (string name, uvm_component parent); 17 | super.new(name, parent); 18 | trans_collected = new(); 19 | item_collected_port = new("item_collected_port", this); 20 | endfunction : new 21 | 22 | function void build_phase(uvm_phase phase); 23 | super.build_phase(phase); 24 | if(!uvm_config_db#(virtual mem_if)::get(this, "", "vif", vif)) 25 | `uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"}); 26 | endfunction: build_phase 27 | 28 | // run phase 29 | virtual task run_phase(uvm_phase phase); 30 | forever begin 31 | @(posedge vif.MONITOR.clk); 32 | //Converting interface level data to transaction level data 33 | wait(vif.monitor_cb.wr_en || vif.monitor_cb.rd_en); 34 | trans_collected.addr = vif.monitor_cb.addr; 35 | if(vif.monitor_cb.wr_en) begin 36 | trans_collected.wr_en = vif.monitor_cb.wr_en; 37 | trans_collected.wdata = vif.monitor_cb.wdata; 38 | trans_collected.rd_en = 0; 39 | @(posedge vif.MONITOR.clk); 40 | end 41 | if(vif.monitor_cb.rd_en) begin 42 | trans_collected.rd_en = vif.monitor_cb.rd_en; 43 | trans_collected.wr_en = 0; 44 | @(posedge vif.MONITOR.clk); 45 | @(posedge vif.MONITOR.clk); 46 | trans_collected.rdata = vif.monitor_cb.rdata; 47 | end 48 | 49 | //Writing the transaction to the scoreboard 50 | item_collected_port.write(trans_collected); 51 | end 52 | endtask : run_phase 53 | 54 | endclass : mem_monitor_1 55 | -------------------------------------------------------------------------------- /dummy_tb/dummy_seqr_1.sv: -------------------------------------------------------------------------------- 1 | class mem_sequencer_1 extends uvm_sequencer#(mem_seq_item); 2 | 3 | //Registering sequencer class with uvm factory 4 | `uvm_component_utils(mem_sequencer_1) 5 | 6 | //constructor 7 | function new(string name, uvm_component parent); 8 | super.new(name,parent); 9 | endfunction 10 | 11 | endclass 12 | -------------------------------------------------------------------------------- /dummy_tb/mem_agent.sv: -------------------------------------------------------------------------------- 1 | class mem_agent extends uvm_agent; 2 | //declaring agent components 3 | mem_driver driver; 4 | mem_sequencer sequencer; 5 | mem_monitor monitor; 6 | 7 | // UVM automation macros for general components 8 | `uvm_component_utils(mem_agent) 9 | 10 | // constructor 11 | function new (string name, uvm_component parent); 12 | super.new(name, parent); 13 | endfunction : new 14 | 15 | // build_phase 16 | function void build_phase(uvm_phase phase); 17 | super.build_phase(phase); 18 | 19 | //Creating driver and sequencer when the agent is active. 20 | if(get_is_active() == UVM_ACTIVE) begin 21 | driver = mem_driver::type_id::create("driver", this); 22 | sequencer = mem_sequencer::type_id::create("sequencer", this); 23 | end 24 | 25 | //Creating monitor. 26 | monitor = mem_monitor::type_id::create("monitor", this); 27 | endfunction : build_phase 28 | 29 | // connect_phase:TLM port connection between sequencer and driver. 30 | function void connect_phase(uvm_phase phase); 31 | if(get_is_active() == UVM_ACTIVE) begin 32 | driver.seq_item_port.connect(sequencer.seq_item_export); 33 | end 34 | endfunction : connect_phase 35 | 36 | endclass : mem_agent 37 | -------------------------------------------------------------------------------- /dummy_tb/mem_drv.sv: -------------------------------------------------------------------------------- 1 | class mem_driver extends uvm_driver #(mem_seq_item); 2 | 3 | // Virtual Interface 4 | virtual mem_if vif; 5 | 6 | `uvm_component_utils(mem_driver) 7 | 8 | // Constructor 9 | function new (string name, uvm_component parent); 10 | super.new(name, parent); 11 | endfunction : new 12 | 13 | function void build_phase(uvm_phase phase); 14 | super.build_phase(phase); 15 | if(!uvm_config_db#(virtual mem_if)::get(this, "", "vif", vif)) 16 | `uvm_fatal("NO_VIF",{"virtual interface must be set for: ",get_full_name(),".vif"}); 17 | endfunction: build_phase 18 | 19 | // run phase 20 | virtual task run_phase(uvm_phase phase); 21 | forever begin 22 | //Polling for transaction from the TLM fifo. 23 | seq_item_port.get_next_item(req); 24 | 25 | //Converting transaction level data to pin level data in this method and driving it on the virtual interface. 26 | drive(); 27 | 28 | //Indicating the transaction completion. 29 | seq_item_port.item_done(); 30 | end 31 | endtask : run_phase 32 | 33 | // drive 34 | virtual task drive(); 35 | req.print(); 36 | `DRIV_IF.wr_en <= 0; 37 | `DRIV_IF.rd_en <= 0; 38 | @(posedge vif.DRIVER.clk); 39 | `DRIV_IF.addr <= req.addr; 40 | if(req.wr_en) begin 41 | `DRIV_IF.wr_en <= req.wr_en; 42 | `DRIV_IF.wdata <= req.wdata; 43 | //$display("\tADDR = %0h \tWDATA = %0h",req.addr,trans.wdata); 44 | @(posedge vif.DRIVER.clk); 45 | end 46 | if(req.rd_en) begin 47 | `DRIV_IF.rd_en <= req.rd_en; 48 | @(posedge vif.DRIVER.clk); 49 | `DRIV_IF.rd_en <= 0; 50 | @(posedge vif.DRIVER.clk); 51 | req.rdata = `DRIV_IF.rdata; 52 | // $display("\tADDR = %0h \tRDATA = %0h",trans.addr,`DRIV_IF.rdata); 53 | end 54 | $display("-----------------------------------------"); 55 | endtask : drive 56 | 57 | endclass : mem_driver 58 | -------------------------------------------------------------------------------- /dummy_tb/mem_model_env.sv: -------------------------------------------------------------------------------- 1 | class mem_model_env extends uvm_env; 2 | 3 | //--------------------------------------- 4 | // agent and scoreboard instance 5 | //--------------------------------------- 6 | 7 | //Taking 6 instances of mem_agent 8 | mem_agent mem_agnt_1; 9 | mem_agent mem_agnt_2; 10 | mem_agent mem_agnt_3; 11 | mem_agent mem_agnt_4; 12 | mem_agent mem_agnt_5; 13 | mem_agent mem_agnt_6; 14 | 15 | //Taking instance of mem_agent_1 16 | mem_agent_1 mem_agent_new; 17 | 18 | //Taking scoreboard instance 19 | mem_scoreboard mem_scb; 20 | 21 | //Registering the environment class with the factory 22 | `uvm_component_utils(mem_model_env) 23 | 24 | //--------------------------------------- 25 | // constructor 26 | //--------------------------------------- 27 | function new(string name, uvm_component parent); 28 | super.new(name, parent); 29 | endfunction : new 30 | 31 | //--------------------------------------- 32 | // build_phase - crate the components 33 | //--------------------------------------- 34 | function void build_phase(uvm_phase phase); 35 | super.build_phase(phase); 36 | 37 | //Creating agents and scoreboard 38 | mem_agent_new= mem_agent_1::type_id::create("mem_agent_new", this); 39 | 40 | 41 | mem_agnt_1= mem_agent::type_id::create("mem_agnt_1", this); 42 | mem_agnt_2= mem_agent::type_id::create("mem_agnt_2", this); 43 | mem_agnt_3= mem_agent::type_id::create("mem_agnt_3", this); 44 | mem_agnt_4= mem_agent::type_id::create("mem_agnt_4", this); 45 | mem_agnt_5= mem_agent::type_id::create("mem_agnt_5", this); 46 | mem_agnt_6= mem_agent::type_id::create("mem_agnt_6", this); 47 | mem_scb = mem_scoreboard::type_id::create("mem_scb", this); 48 | endfunction : build_phase 49 | 50 | //--------------------------------------- 51 | // connect_phase - connecting monitor and scoreboard port 52 | //--------------------------------------- 53 | function void connect_phase(uvm_phase phase); 54 | 55 | //Connecting the analysis port of monitor and scoreboard 56 | 57 | mem_agent_new.monitor.item_collected_port.connect(mem_scb.item_collected_export); 58 | 59 | mem_agnt_1.monitor.item_collected_port.connect(mem_scb.item_collected_export); 60 | mem_agnt_2.monitor.item_collected_port.connect(mem_scb.item_collected_export); 61 | mem_agnt_3.monitor.item_collected_port.connect(mem_scb.item_collected_export); 62 | mem_agnt_4.monitor.item_collected_port.connect(mem_scb.item_collected_export); 63 | mem_agnt_5.monitor.item_collected_port.connect(mem_scb.item_collected_export); 64 | mem_agnt_6.monitor.item_collected_port.connect(mem_scb.item_collected_export); 65 | 66 | 67 | 68 | endfunction : connect_phase 69 | 70 | endclass : mem_model_env 71 | -------------------------------------------------------------------------------- /dummy_tb/mem_model_test.sv: -------------------------------------------------------------------------------- 1 | class mem_model_test extends uvm_test; 2 | 3 | //Registering test class with uvm factory 4 | `uvm_component_utils(mem_model_test) 5 | 6 | //Handle of env and seq class 7 | mem_model_env env; 8 | mem_wr_seq seq; 9 | 10 | function new(string name = "mem_model_test",uvm_component parent=null); 11 | super.new(name,parent); 12 | endfunction : new 13 | 14 | virtual function void build_phase(uvm_phase phase); 15 | super.build_phase(phase); 16 | 17 | //Creating the snv and seq class 18 | env = mem_model_env ::type_id::create("env", this); 19 | seq = mem_wr_seq::type_id::create("seq"); 20 | endfunction : build_phase 21 | 22 | task run_phase(uvm_phase phase); 23 | phase.raise_objection(this); 24 | //Starting the seq 25 | seq.start(env.mem_agnt.sequencer); 26 | phase.drop_objection(this); 27 | endtask : run_phase 28 | 29 | endclass : mem_model_test 30 | -------------------------------------------------------------------------------- /dummy_tb/mem_monitor.sv: -------------------------------------------------------------------------------- 1 | class mem_monitor extends uvm_monitor; 2 | 3 | // Virtual Interface 4 | virtual mem_if vif; 5 | 6 | //Declaring analysis port for writing to the scoreboard 7 | uvm_analysis_port #(mem_seq_item) item_collected_port; 8 | 9 | // Placeholder to capture transaction information. 10 | mem_seq_item trans_collected; 11 | 12 | //Registering monitor class with the factory 13 | `uvm_component_utils(mem_monitor) 14 | 15 | // new - constructor 16 | function new (string name, uvm_component parent); 17 | super.new(name, parent); 18 | trans_collected = new(); 19 | item_collected_port = new("item_collected_port", this); 20 | endfunction : new 21 | 22 | function void build_phase(uvm_phase phase); 23 | super.build_phase(phase); 24 | if(!uvm_config_db#(virtual mem_if)::get(this, "", "vif", vif)) 25 | `uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"}); 26 | endfunction: build_phase 27 | 28 | // run phase 29 | virtual task run_phase(uvm_phase phase); 30 | forever begin 31 | @(posedge vif.MONITOR.clk); 32 | //Converting interface level data to transaction level data 33 | wait(vif.monitor_cb.wr_en || vif.monitor_cb.rd_en); 34 | trans_collected.addr = vif.monitor_cb.addr; 35 | if(vif.monitor_cb.wr_en) begin 36 | trans_collected.wr_en = vif.monitor_cb.wr_en; 37 | trans_collected.wdata = vif.monitor_cb.wdata; 38 | trans_collected.rd_en = 0; 39 | @(posedge vif.MONITOR.clk); 40 | end 41 | if(vif.monitor_cb.rd_en) begin 42 | trans_collected.rd_en = vif.monitor_cb.rd_en; 43 | trans_collected.wr_en = 0; 44 | @(posedge vif.MONITOR.clk); 45 | @(posedge vif.MONITOR.clk); 46 | trans_collected.rdata = vif.monitor_cb.rdata; 47 | end 48 | 49 | //Writing the transaction to the scoreboard 50 | item_collected_port.write(trans_collected); 51 | end 52 | endtask : run_phase 53 | 54 | endclass : mem_monitor 55 | -------------------------------------------------------------------------------- /dummy_tb/mem_rd_seq.sv: -------------------------------------------------------------------------------- 1 | class mem_rd_seq extends uvm_sequence#(mem_seq_item); 2 | 3 | //Registering sequence with uvm factory 4 | `uvm_object_utils(mem_rd_seq) 5 | 6 | //Constructor 7 | function new(string name = "mem_rd_seq"); 8 | super.new(name); 9 | endfunction 10 | 11 | virtual task body(); 12 | `uvm_do_with(req,{req.rd_en == 1;}) 13 | endtask 14 | 15 | endclass 16 | -------------------------------------------------------------------------------- /dummy_tb/mem_scoreboard.sv: -------------------------------------------------------------------------------- 1 | class mem_scoreboard extends uvm_scoreboard; 2 | 3 | //Registering scoreboard class with uvm factory 4 | `uvm_component_utils(mem_scoreboard) 5 | 6 | //Declaring analysis port which will be connected to the analysis port in the monitor 7 | uvm_analysis_imp#(mem_seq_item, mem_scoreboard) item_collected_export; 8 | 9 | // new - constructor 10 | function new (string name, uvm_component parent); 11 | super.new(name, parent); 12 | endfunction : new 13 | 14 | function void build_phase(uvm_phase phase); 15 | super.build_phase(phase); 16 | item_collected_export = new("item_collected_export", this); 17 | endfunction: build_phase 18 | 19 | // write method which will be triggered when a transaction is detected in the analysis port 20 | virtual function void write(mem_seq_item pkt); 21 | $display("SCB:: Pkt recived"); 22 | pkt.print(); 23 | endfunction : write 24 | 25 | // run phase 26 | virtual task run_phase(uvm_phase phase); 27 | --- comparision logic --- 28 | endtask : run_phase 29 | endclass : mem_scoreboard 30 | -------------------------------------------------------------------------------- /dummy_tb/mem_seq_item.sv: -------------------------------------------------------------------------------- 1 | class mem_seq_item extends uvm_sequence_item; 2 | //data and control fields 3 | rand bit [3:0] addr; 4 | rand bit wr_en; 5 | rand bit rd_en; 6 | rand bit [7:0] wdata; 7 | bit [7:0] rdata; 8 | 9 | //Utility and Field macros, 10 | `uvm_object_utils_begin(mem_seq_item) 11 | `uvm_field_int(addr,UVM_ALL_ON) 12 | `uvm_field_int(wr_en,UVM_ALL_ON) 13 | `uvm_field_int(rd_en,UVM_ALL_ON) 14 | `uvm_field_int(wdata,UVM_ALL_ON) 15 | `uvm_object_utils_end 16 | 17 | //Constructor 18 | function new(string name = "mem_seq_item"); 19 | super.new(name); 20 | endfunction 21 | 22 | //constaint, to generate any one among write and read 23 | constraint wr_rd_c { wr_en != rd_en; }; 24 | 25 | endclass 26 | -------------------------------------------------------------------------------- /dummy_tb/mem_sequencer.sv: -------------------------------------------------------------------------------- 1 | class mem_sequencer extends uvm_sequencer#(mem_seq_item); 2 | 3 | //Registering sequencer class with uvm factory 4 | `uvm_component_utils(mem_sequencer) 5 | 6 | //constructor 7 | function new(string name, uvm_component parent); 8 | super.new(name,parent); 9 | endfunction 10 | 11 | endclass 12 | -------------------------------------------------------------------------------- /dummy_tb/mem_wr_seq.sv: -------------------------------------------------------------------------------- 1 | class mem_wr_seq extends uvm_sequence#(mem_seq_item); 2 | 3 | `uvm_object_utils(mem_wr_seq) 4 | 5 | //Constructor 6 | function new(string name = "mem_wr_seq"); 7 | super.new(name); 8 | endfunction 9 | 10 | virtual task body(); 11 | `uvm_do_with(req,{req.wr_en == 1;}) 12 | endtask 13 | 14 | endclass 15 | -------------------------------------------------------------------------------- /dummy_tb/tb_top.sv: -------------------------------------------------------------------------------- 1 | module tbench_top; 2 | 3 | //clock and reset signal declaration 4 | bit clk; 5 | bit reset; 6 | 7 | //clock generation 8 | always #5 clk = ~clk; 9 | 10 | //reset Generation 11 | initial begin 12 | reset = 1; 13 | #5 reset =0; 14 | end 15 | 16 | //creatinng instance of interface, inorder to connect DUT and testcase 17 | mem_if intf(clk,reset); 18 | 19 | //DUT instance, interface signals are connected to the DUT ports 20 | memory DUT ( 21 | .clk(intf.clk), 22 | .reset(intf.reset), 23 | .addr(intf.addr), 24 | .wr_en(intf.wr_en), 25 | .rd_en(intf.rd_en), 26 | .wdata(intf.wdata), 27 | .rdata(intf.rdata) 28 | ); 29 | 30 | //enabling the wave dump 31 | initial begin 32 | uvm_config_db#(virtual mem_if)::set(uvm_root::get(),"*","vif",intf); 33 | $dumpfile("dump.vcd"); $dumpvars; 34 | end 35 | 36 | initial begin 37 | run_test(); 38 | end 39 | endmodule 40 | -------------------------------------------------------------------------------- /example/readme.txt: -------------------------------------------------------------------------------- 1 | this folder has an example of the log file to be used as in input to the script 2 | -------------------------------------------------------------------------------- /image_draw/TB_arch_using_image_draw.py: -------------------------------------------------------------------------------- 1 | 1. Script to draw basic Testbench Diagram aimed at 2 AGENTS can be scaled to n agents (needed few change in calculations) 2 | 3 | ##########METHOD TO DRAW RECTANGLE WITH THE GIVEN CO-ORDINATES AND FILL WITH THE GIVEN COLOR############## 4 | def draw_rect(image,coordinates,fill,color,width=1): 5 | rect_start = (coordinates[0][0],coordinates[0][1]); 6 | rect_end = (coordinates[1][0], coordinates [1][1]) 7 | image.rectangle((rect_start,rect_end),fill=fill,outline = color) 8 | #Method to write the text inside the rectangle 9 | def wr_text_in_rect(image,start_wr_w,start_wr_h,str,tfill): 10 | font = ImageFont.truetype("arial.ttf", 15) 11 | image.text((start_wr_w,start_wr_h),str, fill = tfill,font = font) 12 | #Method to draw the top,test,env blocks (w.r.t. the value of n chosen) 13 | def call_simple_rect(w,h,n,text,bfill,tfill,img1): 14 | w1 = w - (n*10); #end of x should be max 15 | if n != 5: 16 | h2 = h - (n*10); #end of 'y' should be max 17 | h1 = n*15 + 10; 18 | w2 = h1; 19 | elif n == 5: #The height of the env block should be less; So used like below dimensions 20 | h2 = h - (n*10*5) 21 | h1 = n*15 + 10 + 35; 22 | w2 = n*15 + 10; 23 | top_right = (w1,h1) 24 | bottom_left = (w2,h2) 25 | start_x = w1 - (50); 26 | start_y = h1 + (n*2); 27 | outline_width = 10 28 | outline_color = "black" 29 | draw_rect(img1,(top_right, bottom_left), fill=bfill ,color=outline_color, width=outline_width) 30 | wr_text_in_rect(img1,start_x,start_y,text,tfill) 31 | print ("Dimensions are %0d %0d %0d %0d",top_right, bottom_left) 32 | return w1; 33 | #This “docx” module is to manipulate with docs like MS Word. Used it to add TB diagram to the document 34 | import docx 35 | #This “opencv” module in python ease us to draw arrowed line in the image 36 | import cv2 37 | # This “pillow” module to import Image draw module 38 | from PIL import Image,ImageDraw,ImageFont 39 | #Taking the handle “doc” for docx 40 | doc = docx.Document() 41 | #This Module is used to measure the whole screen size 42 | import tkinter 43 | root = tkinter.Tk() 44 | width = root.winfo_screenwidth() 45 | height = root.winfo_screenheight() 46 | print ("Width & HEIGHT",width,height) 47 | # create line image of width and height 48 | w = width 49 | h = height 50 | img = Image.new("RGB", (w, h),"white") 51 | img1 = ImageDraw.Draw(img) 52 | #Create first outer rectangle top n=1 53 | n = 1; 54 | top_dim = call_simple_rect(w,h,n,"TOP","orange","black",img1); 55 | #Create second inner rectangle test n=3 56 | n = 3; 57 | test_dim = call_simple_rect(w,h,n,"TEST","pink","black",img1); 58 | #Create third inner rectangle env n=5 59 | n = 5; 60 | env_dim = call_simple_rect(w,h,n,"ENV","yellow","black",img1); 61 | #Create fifth inner rectangle SCOREBOARD 62 | top_right = (w-140,150) 63 | bottom_left = (400,230) 64 | start_x = ((w-140)+400)/2 + 12; 65 | start_y = 180; 66 | draw_rect(img1,(top_right, bottom_left), fill="gray" ,color="black", width=10) 67 | wr_text_in_rect(img1,start_x,start_y,"SCOREBOARD","BLACK") 68 | #Create fourth inner rectangle sequences DUT 69 | top_right = (90,h-80) 70 | bottom_left = (w-40,h-50) 71 | start_x_dut = (90 + (w-40))/2; 72 | start_y_dut = (((h - 80) + (h - 50))/2) - 12; 73 | draw_rect(img1,(top_right, bottom_left), fill="grey" ,color="black", width=10) 74 | wr_text_in_rect(img1,start_x_dut,start_y_dut,"DUT","BLACK") 75 | #Create fourth inner rectangle Interface 76 | top_right = (90,h-120) 77 | bottom_left = (w-40,h-150) 78 | start_x_if = (90 + (w-40))/2; 79 | start_y_if = ((h-120)+(h-150))/2 - 12; 80 | draw_rect(img1,(top_right, bottom_left), fill="green" ,color="black", width=10) 81 | wr_text_in_rect(img1,start_x_if,start_y_if,"INTERFACE","BLACK") 82 | #Create fourth inner rectangle VIF 83 | top_right = (90,h-190) 84 | bottom_left = (w-40,h-220) 85 | start_x_vif = (90 + (w-40))/2; 86 | start_y_vif = ((h-190)+(h-220))/2 - 12; 87 | draw_rect(img1,(top_right, bottom_left), fill="gray" ,color="black", width=10) 88 | wr_text_in_rect(img1,start_x_vif,start_y_vif,"VIF","BLACK") 89 | print(env_dim); 90 | #Check for number of agents 91 | n = 7; 92 | agnt_cnt = int(input("Enter no. of agents")) 93 | w1 = (env_dim/agnt_cnt) 94 | h1 = (env_dim/agnt_cnt) 95 | tx = 40; 96 | x0 = 0; 97 | diff = 0; 98 | m1 = 1; 99 | m2 = 0; 100 | #To draw the number of agents w.r.t. agent count 101 | for val in range(agnt_cnt): 102 | print("VALUE OF X0 IS",x0) 103 | x1 = tx + 55; 104 | print("VALUE OF X1 IS",x1) 105 | y0 = (n*4*10) 106 | if agnt_cnt == 1: 107 | x0 = (env_dim/agnt_cnt) - 20; 108 | elif agnt_cnt != 1: 109 | x0 = (m1*(env_dim/agnt_cnt))+(m2*(x1 + diff)); 110 | print("VALUE OF X0 LATER IS",x0) 111 | y1 = h - (4*n*10) 112 | tx = x0; 113 | diff = x0 - x1; 114 | top_right = (x0,y0); 115 | bottom_left = (x1,y1); 116 | start_x = x0 - 50; 117 | start_y = y0 + 5; 118 | outline_width = 10 119 | print(top_right); 120 | print(bottom_left); 121 | draw_rect(img1,(top_right, bottom_left), fill="cyan" ,color="black", width=outline_width) 122 | wr_text_in_rect(img1,start_x,start_y,"AGENT","BLACK") 123 | #Start another rectangle MONITOR inside the agent 124 | x3 = x1 + 10 125 | y3 = y0 + 20 126 | x2 = x0 - 350 127 | y2 = y0 + 100 128 | top_right = (x2,y2); 129 | bottom_left = (x3,y3); 130 | start_x_mon = (x2 + x3)/2; 131 | start_y_mon = y3 + 15; 132 | outline_width = 10 133 | draw_rect(img1,(top_right, bottom_left), fill="orange" ,color="black", width=outline_width) 134 | wr_text_in_rect(img1,start_x_mon,start_y_mon,"MONITOR","BLACK") 135 | #Start another rectangle DRIVER inside the agent 136 | x5 = x3 + 300 137 | y5 = y3 + 100 138 | x4 = x2 + 300 139 | y4 = y2 + 100 140 | top_right = (x4,y4); 141 | bottom_left = (x5,y5); 142 | start_x_drv = (x4 + x5)/2; 143 | start_y_drv = y5 + 5; 144 | outline_width = 10 145 | draw_rect(img1,(top_right, bottom_left), fill="green" ,color="black", width=outline_width) 146 | wr_text_in_rect(img1,start_x_drv,start_y_drv,"DRIVER","BLACK") 147 | m2 = 1; 148 | m1 = 0; 149 | print("DRIVER",start_x_drv,start_y_drv) 150 | #Start another rectangle SEQUENCER inside the agent 151 | x5 = x3 + 300 152 | y5 = y3 153 | x4 = x2 + 300 154 | y4 = y2 155 | top_right = (x4,y4); 156 | bottom_left = (x5,y5); 157 | start_x_sqr = (x4 + x5)/2; 158 | start_y_sqr = y5 + 5; 159 | outline_width = 10 160 | draw_rect(img1,(top_right, bottom_left), fill="grey" ,color="black", width=outline_width) 161 | wr_text_in_rect(img1,start_x_sqr,start_y_sqr,"SEQUENCER","BLACK") 162 | m2 = 1; 163 | m1 = 0; 164 | img.show() 165 | img.save('C:\\Users\\goushik\\Desktop\\New folder\\tb_arch.jpg'); 166 | # Arrow Drawing 167 | path = 'C:\\Users\\goushik\\Desktop\\New folder\\tb_arch.jpg' 168 | # Reading an image in default mode 169 | image = cv2.imread(path) 170 | # Window name in which image is displayed 171 | window_name = 'Image' 172 | ######################DRAW ARROW BETWEEN DRIVER AND VIF################################# 173 | start_point = (int(start_x_drv - 15),int(start_y_drv) + 75) 174 | # End coordinate 175 | end_point = (int(start_x_drv - 15),int(start_y_drv + 25) + 115) 176 | color = (0, 0, 0) 177 | thickness = 3 178 | # Using cv2.arrowedLine() method 179 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 180 | cv2.imshow(window_name, image) 181 | cv2.imwrite("C:\\Users\\goushik\\Desktop\\New folder\\tb_arch.jpg",image) 182 | ######################DRAW ARROW BETWEEN VIF AND INTERFACE################################### 183 | # Start coordinate 184 | start_point = (int(start_x_vif - 15),int(start_y_vif + 25)) 185 | # End coordinate 186 | end_point = (int(start_x_if - 15),int(start_y_if - 5)) 187 | color = (0, 0, 0) 188 | thickness = 3 189 | # Using cv2.arrowedLine() method 190 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 191 | cv2.imshow(window_name, image) 192 | ######################DRAW ARROW BETWEEN INTERFACE AND DUT################################# 193 | start_point = (int(start_x_if - 15),int(start_y_if + 25)) 194 | # End coordinate 195 | end_point = (int(start_x_dut - 15),int(start_y_dut - 5)) 196 | color = (0, 0, 0) 197 | thickness = 3 198 | # Using cv2.arrowedLine() method 199 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 200 | cv2.imshow(window_name, image) 201 | ######################DRAW ARROW BETWEEN DRIVER1 AND VIF################################# 202 | start_point = (506,482) 203 | # End coordinate 204 | end_point = (506,547) 205 | color = (0, 0, 0) 206 | thickness = 3 207 | # Using cv2.arrowedLine() method 208 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 209 | cv2.imshow(window_name, image) 210 | cv2.imwrite("C:\\Users\\goushik\\Desktop\\New folder\\tb_arch.jpg",image) 211 | doc.add_picture('C:\\Users\\goushik\\Desktop\\New folder\\tb_arch.jpg') 212 | doc.save('C:\\Users\\goushik\\Desktop\\New folder\\pattern_printing_ex.docx') 213 | -------------------------------------------------------------------------------- /image_draw/UVM_tb_arch_09_04.py: -------------------------------------------------------------------------------- 1 | import PIL, tkinter,cv2 # adding pillow and tkinter for image draw and canvas 2 | import tkinter as Tk # short name for tkinter 3 | from PIL import Image, ImageDraw, ImageFont # image , imagedraw and imagefont from pillow 4 | import os, re # search library 5 | path = input("enter path of TB directory: ") #user input for path of TB directory 6 | root = tkinter.Tk() #canvas size decider 7 | w = root.winfo_screenwidth() # depending on screen size set width and height 8 | h = root.winfo_screenheight() 9 | root.geometry(f'{w}x{h}') # set new canvas size 10 | print("Width & HEIGHT", w, h) # w and h for user refernce 11 | # create line image of width and height 12 | img = Image.new("RGB",[w,h],"white") 13 | tb = ImageDraw.Draw(img) 14 | lookup = {"keyword":"name"} #lookup table created for uvm component and name 15 | f = open("tree_data.txt","w") #create file for writing component and component name 16 | f.truncate(0) # clean file before writing data 17 | color_fill = "white" 18 | 19 | def top(): # drawing top level structure 20 | top_left = (0,0) # co-ordinate decider 21 | bottom_right = (w,h) # co-ordinate decider 22 | #color_fill = "orange" #color for block 23 | label = "top" #name of default block 24 | block(top_left,bottom_right,label,color_fill) #call the rectangle creater function 25 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 26 | tb.text((w / 2, 10), label, fill="black", font=font) 27 | # Interface 28 | intfs = int(input("enter the number of interfaces")) 29 | #intfs = 1 30 | for i in range(intfs): 31 | top_left = 100 + (i * (w - 200) / intfs), h - 220 # co-ordinate decider 32 | bottom_right = 100 + ((i + 1) * (w - 200) / intfs) - 10, h - 160 # co-ordinate decider '''(i+1)*(w-100)/intfs''' 33 | # color_fill = "green" #color for block 34 | label = "" 35 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 36 | font = ImageFont.truetype("arial.ttf", 20) 37 | #tb.text((w / 2 - 20, h - 250), "Interface", fill="black", font=font) # avoid taking default text coordinates''' 38 | tb.text((100 + (i * (w - 200) / intfs)+20, h - 200), "Interface "+str(i+1), fill="black", font=font) # avoid taking default text coordinates''' 39 | # DUT 40 | top_left = 50, h - 120 # co-ordinate decider 41 | bottom_right = w - 50, h - 20 # co-ordinate decider 42 | # color_fill = "blue" #color for block 43 | label = "" 44 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 45 | font = ImageFont.truetype("arial.ttf", 30) 46 | tb.text((w / 2, h - 100), "DUT", fill="black", font=font) # avoid taking default text coordinates''' 47 | def test(name): #drawing test level structure 48 | top_left = (50,40) # co-ordinate decider 49 | bottom_right = (w-50,h-300) # co-ordinate decider 50 | #color_fill = "lightgreen" #color for block 51 | label = name #"test" 52 | block(top_left,bottom_right,label,color_fill) #call the rectangle creater function 53 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 54 | tb.text((w / 2, 10+40), label, fill="black", font=font) 55 | def env(name): 56 | top_left = (100,70) # co-ordinate decider 57 | bottom_right = w-100,h -350 # co-ordinate decider 58 | #color_fill = "yellow" #color for block 59 | label = name #"env" 60 | block(top_left,bottom_right,label, color_fill) #call the rectangle creater function 61 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 62 | tb.text((w / 2, 10+70), label, fill="black", font=font) 63 | 64 | def scoreboard(name): 65 | top_left = 125,105 # co-ordinate decider 66 | bottom_right = w - 120,(h - 150)/4.4 # co-ordinate decider 67 | #color_fill = "cyan" #color for block 68 | label = name #"scoreboard" 69 | block(top_left,bottom_right,label, color_fill) #call the rectangle creater function 70 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 71 | tb.text((w / 2, 10+105), label, fill="black", font=font) 72 | 73 | def agent(a,i,name): 74 | if (10>a>5): 75 | x = 110+((i)*(w-200)/a) 76 | x1 = x+((w-200)/5)-200 77 | y = 180 # co-ordinate decider wrt to number of agents 78 | y1 = h - 360 # co-ordinate decider wrt to number of agents 79 | elif(a>9): 80 | x = 160 + ((i) * (w - 200) / a) # co-ordinate decider wrt to number of agents 81 | x1 = x + ((w - 200) / a) - 100 # co-ordinate decider wrt to number of agents 82 | #y = 180 # co-ordinate decider wrt to number of agents 83 | if((i+1)%2== 1): 84 | y =380 85 | y1 = h - 360 # co-ordinate decider wrt to number of agents 86 | else: 87 | y1 = h - 560 # co-ordinate decider wrt to number of agents 88 | y= 180 89 | 90 | else : 91 | x =200+((i)*(w-200)/a) # co-ordinate decider wrt to number of agents 92 | x1 = x + ((w - 200) / a) - 200 # co-ordinate decider wrt to number of agents 93 | y = 180 # co-ordinate decider wrt to number of agents 94 | y1 = h - 360 # co-ordinate decider wrt to number of agents 95 | 96 | top_left = (int(x),int(y)) # co-ordinate decider 97 | bottom_right = (int(x1),int(y1)) # co-ordinate decider 98 | #color_fill = "coral" #color for block 99 | label = "" 100 | block(top_left, bottom_right, label, color_fill) #call the rectangle creater function 101 | font = ImageFont.truetype("arial.ttf", 15) #text settings 102 | if (59): #if number of agents are greater than 10 draw sub-components small 128 | label = name #"AGT"+str(i+1) 129 | mark = x +10 130 | #port connection 131 | tb.line((((x + (x1 - x) / 2), y1 ), ((x + (x1 - x) / 2 ), h - 218)), "black", 5) # Agent to interface 132 | tb.polygon(((x -10+ (x1 - x) / 2, h - 238), (x + 10 + (x1 - x) / 2, h - 238), (x + (x1 - x) / 2, h - 218)),fill="white", outline="black") # port connection 133 | tb.polygon(((x -10+ (x1 - x) / 2, y1+20), (x + 10 + (x1 - x) / 2, y1+20), (x + (x1 - x) / 2, y1)),fill="white", outline="black") 134 | tb.line((x1-1, y, x1-1, 160), "black", 5) # monitor to scoreboard 135 | tb.ellipse((x1 -10, 160, x1 + 10, 180), fill="white", outline="black") # export connection 136 | # agent label 137 | font = ImageFont.truetype("arial.ttf", 12) # text settings 138 | tb.text((mark-10, y -15), "A "+str(i+1), fill="black", font=font) 139 | img1 = Image.new("RGB", [w, h], "white") 140 | tb1 = ImageDraw.Draw(img1) 141 | font = ImageFont.truetype("arial.ttf", 12) # text settings 142 | tb1.text((w/2,50), "AGENT " + str(i + 1), fill="black", font=font) 143 | #sequencer 144 | top_left=100,100 145 | bottom_right=700,200 146 | tb1.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 147 | tb1.text((110,110), "sequencer "+str(i+1), fill="black", font=font) # for sequencer 148 | #driver 149 | top_left=100,300 150 | bottom_right=700,400 151 | tb1.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 152 | tb1.text((110,310), "driver "+str(i+1), fill="black", font=font) # for driver 153 | #monitor 154 | top_left=800,300 155 | bottom_right=1400,400 156 | tb1.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 157 | tb1.text((910,310), "monitor "+str(i+1), fill="black", font=font) # for monitor 158 | img1.show() 159 | # edit this line and add path where you have created a agents folder,do not change \agent_"+str(i+1)+".jpg") 160 | path_filename = (r"C:\Users\ashik\Desktop\mirafra training\pythonProject2\agents\agent_"+str(i+1)+".jpg") 161 | print(path_filename) 162 | img1.save(path_filename) 163 | 164 | elif(a<=5): 165 | label = name #"agent"+str(i+1) 166 | mark = x + 10 167 | block( top_left=(x + (x1-x)/2,y + 30), bottom_right=(int(x1 -40/a), int(y1 - 180)), label=" ", color_fill="white")#"grey") #for sequencer 168 | block( top_left=(x + 40/a,y + 170), bottom_right=(-10+x + (x1-x)/2 , y1 - 40), label="", color_fill="white")#"violet") #for driver 169 | block( top_left=(x + (x1-x)/2,y + 170), bottom_right=(int(x1 -40/a), int(y1 - 40)), label="", color_fill= "white") #"skyblue") #for monitor 170 | tb.text(((x+(x1-x)/2)+35,y+40), "sequencer", fill="black", font=font) #for sequencer 171 | tb.text((x-50 + 40/a,y + 180), "driver", fill="black", font=font) #for driver 172 | tb.text(((x+(x1-x)/2)+35,y+180), "monitor", fill="black", font=font) #for monitor 173 | #connections 174 | 175 | tb.line((((x + 10 + 40 / a), (y1 - 40)), ((x + 10 + 40 / a), h - 218)), "black", 5) # driver to VIF 176 | tb.polygon(((x+10+40/a-10,h-238),(x+10+40/a+10,h-238),(x+10+40/a,h-218)), fill="white", outline="black") #port connection 177 | tb.line((((x + 10 + (x1 - x) / 2), (y1 - 40)), ((x + (x1 - x) / 2 + 10), h - 218)), "black",5) # VIF to monitor 178 | tb.polygon(((x + (x1-x)/2, y1-20), (x +20+ (x1-x)/2, y1-20), (x + 10+(x1-x)/2, y1-40)),fill="white", outline="black") #port connection 179 | tb.line((((x1 - 40/a), (y1 - 100)), ((x1 + 50), y1 - 100)), "black", 5) # monitor to scoreboard 180 | tb.polygon((x1-40/a+20, y1 - 100,x1-40/a+10,y1-90,x1-40/a, y1-100,x1-40/a+10,y1-110), fill="white", outline="black") #analysis connection 181 | tb.line((((x1 + 50), (y1 - 100)), ((x1 + 50), 160)), "black", 5) # monitor to scoreboard 182 | tb.ellipse((x1 +40, 160, x1 +60, 180), fill="white", outline="black") #export connection 183 | tb.line((((x+10+40/a),(y + 100)),( x+10+40/a, y + 170)), "black", 5) # sequencer to driver 184 | tb.rectangle((x+10+40/a-10, y +170, x+10+40/a+10, y+150), fill="white", outline="black") #port connection 185 | tb.line((((x+10++40/a), (y + 100)), (((x+(x1-x)/2)), y + 100)), "black", 5) # sequencer to driver 186 | tb.ellipse((x+(x1-x)/2-20,y+90,x+(x1-x)/2, y+110), fill="white", outline="black") #export connection 187 | #agent label 188 | tb.text((mark,y+10),label, fill="black", font=font) 189 | 190 | 191 | def block(top_left,bottom_right,label,color_fill): # draw rectangle block, fill color and label 192 | tb.rectangle([top_left,bottom_right],color_fill,"black",5) #default values for all instance 193 | 194 | #tb.text((w/2,10+(35*n)),label,fill="black", font=font) 195 | 196 | def component_search(keyword): # to search for keyword in all files of directory 197 | root_dir = path 198 | for root, dirs, files in os.walk(root_dir, onerror=None): # to loop inside all files of directory 199 | for filename in files: 200 | file_path = os.path.join(root, filename) 201 | with open(file_path, "rb") as f: # read file as binary 202 | for line in f: 203 | line = line.decode("utf-8") #decode to string for read 204 | if keyword in line: #keyword determines the word to be looked into in each of the file 205 | #print(filename) 206 | #print(file_path) # print the file path 207 | #print(line) 208 | if (keyword == "interface"): # to avoid psedo interface name error 209 | #print("yes interface") 210 | text =line.split() 211 | if len(text) != 2: 212 | #print("not match") 213 | break 214 | else: 215 | component_name_finder(keyword, line) 216 | else: 217 | component_name_finder(keyword,line) 218 | break 219 | def tb_comps(): #generic word in tb components that can be searched to determine presence of comp in TB 220 | component_search("uvm_test") 221 | component_search("uvm_env") 222 | component_search("uvm_scoreboard") 223 | component_search("uvm_agent") 224 | component_search("uvm_driver") 225 | component_search("uvm_monitor") 226 | component_search("uvm_sequencer") 227 | component_search("uvm_sequence ") 228 | component_search("uvm_sequence_item") 229 | component_search("interface") 230 | #component_search("package") 231 | 232 | for key, value in lookup.items(): #saving component names into lookup table 233 | print(key, ' : ', value) 234 | #all_keys = lookup.keys() 235 | #print (all_keys) 236 | 237 | def component_name_finder(keyword,line): 238 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 239 | text = line.split() #split line where text found 240 | name = text[1] # get name from split line 241 | if keyword+"_1" in lookup: #if keyword already exists in lookup 242 | for i in range(10): # take next count of lookup 243 | key = keyword+"_"+str(i+2) 244 | #print (key) 245 | lookup[key]=name 246 | f.write(keyword+"_"+str(i+2)+"\t\t\t\t"+name+"\n") 247 | break 248 | else:# keyword not in lookup: #if keyword does not exist in lookup 249 | if (keyword=="uvm_agent"): # make it first instance of agent 250 | key = keyword +"_1" 251 | lookup[key] = name 252 | f.write(keyword + "_1"+ "\t\t\t\t" + name + "\n") 253 | else: 254 | lookup[keyword] = name # add name to lookup table 255 | f.write(keyword + "\t\t\t\t" + name + "\n") 256 | f = open("tree_data.txt","a+") #add found name to file : open write and close 257 | f.close() 258 | def read_file_draw(): 259 | f = open("tree_data.txt","r") #read file written with names 260 | file = f.read() 261 | #print (file) 262 | if (re.search("uvm_test",file)): # find keyword in file 263 | top() # draw top 264 | test(lookup['uvm_test']) #draw test with found name 265 | env(lookup['uvm_env']) # draw env with found name 266 | scoreboard(lookup['uvm_scoreboard']) # draw scb with found name 267 | a =file.count("uvm_agent_") # find number of agents 268 | '''a= int(input ("number of Agents:")) # uncomment this to add number of agents manually 269 | #a = 15 #uncomment and add values for agents explicitly 270 | print("number of agents : " + str(a)) # print number of agents 271 | for i in range(a): 272 | agent(a,i,"uvm_agent_"+str(i+1)) # draw agent with agent names''' # comment this to add number of agents manually 273 | print("number of agents : " + str(a)) # print number of agents 274 | for i in range(a): 275 | agent(a,i,lookup["uvm_agent_"+str(i+1)]) # draw agent with agent names 276 | #agent(a,i,"uvm_agent_"+str(i+1)) # draw agent with agent names''' 277 | f.close() 278 | tb_comps() #to search for component name 279 | read_file_draw() #read file 280 | 281 | def connection_finder(keyword = ".connect("): # to search for keyword in all files of directory 282 | root_dir = path 283 | for root, dirs, files in os.walk(root_dir, onerror=None, topdown=True): # to loop inside all files of directory 284 | for filename in files: 285 | file_path = os.path.join(root, filename) 286 | with open(file_path, "rb") as f: # read file as binary 287 | for line in f: 288 | line = line.decode("utf-8") # decode to string for read 289 | if keyword in line: # keyword determines the word to be looked into in each of the file 290 | #print (keyword,line) 291 | text = line 292 | if (re.search("_port",text)): 293 | if(re.search("export",text)): 294 | print ("drawing port and export") 295 | print(line) 296 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 297 | f.write(str(line)+"\n") 298 | f.write("drawing port and export") 299 | f.close() 300 | else: 301 | print("drawing port") 302 | print(line) 303 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 304 | f.write(line + "\n") 305 | f.write("drawing port"+"\n") 306 | f.close() 307 | connection_finder() 308 | #block(top_left,bottom_right,color_fill) 309 | 310 | #img.show() #show image before save 311 | img.save(r"C:\Users\ashik\Desktop\mirafra training\pythonProject2\tb_arc.jpg") # saving image 312 | image = cv2.imread(r"C:\Users\ashik\Desktop\mirafra training\pythonProject2\tb_arc.jpg") #reading saved image to draw arrows using CV2 library 313 | image = cv2.arrowedLine(image, (int(w/4), h - 160), (int(w / 4), h - 120), (000), 2) #arrows from Interface to DUT 314 | image = cv2.arrowedLine(image, (int(w/2), h - 160), (int(w / 2), h - 120), (000), 2) #arrows from interface to DUT 315 | image = cv2.arrowedLine(image,(int(w*3/4),h-160),(int(w*3/4),h-120),(000),2) # arrows from interface to DUT 316 | cv2.imshow('abc',image) # name for python window showing final image 317 | cv2.waitKey(0) #waiting for click before closing image abc window 318 | cv2.destroyAllWindows() #close all image windows on click 319 | cv2.imwrite(r"C:\Users\ashik\Desktop\mirafra training\pythonProject2\tb_arc.jpg",image) #save final image 320 | -------------------------------------------------------------------------------- /image_draw/component_name_ finder.py: -------------------------------------------------------------------------------- 1 | import os, re, prettytable 2 | path = input("enter path of TB directory: ") #user input for path of TB directory 3 | open("tree_data.doc","w+") 4 | from prettytable import PrettyTable #to draw table of list 5 | x = PrettyTable() 6 | x.field_names = ["keyword", "class name"] 7 | def component_search(keyword): # to search for keyword in all files of directory 8 | root_dir = path 9 | for root, dirs, files in os.walk(root_dir, onerror=None, topdown=True): # to loop inside all files of directory 10 | for filename in files: 11 | file_path = os.path.join(root, filename) 12 | with open(file_path, "rb") as f: # read file as binary 13 | for line in f: 14 | line = line.decode("utf-8") #decode to string for read 15 | if keyword in line: # keyword determines the word to be looked into in each of the file 16 | #print(file_path,filename) 17 | #print(root) 18 | #print(root_dir) 19 | #print(files) 20 | component_name_finder(keyword, line) # call function to find class name 21 | break 22 | def tb_comps(): #generic word in tb components that can be searched to determine presence of comp in TB 23 | component_search("uvm_test") 24 | component_search("uvm_env") 25 | component_search("uvm_scoreboard") 26 | component_search("uvm_agent") 27 | component_search("uvm_driver") 28 | component_search("uvm_monitor") 29 | component_search("uvm_sequencer") 30 | component_search("uvm_sequence ") # added space to accommodate full word matching 31 | component_search("uvm_sequence_item") 32 | f = open("tree_data.doc", "a+") #opens document for append 33 | f.write("\nname list in table format\n") 34 | f.write(str(x)) #draws updated table data 35 | f.close() 36 | def component_name_finder(keyword,line): 37 | text = line.split() #to split line to get class name 38 | name = text[1] #class name 39 | print(keyword+"\t\t\t"+name+"\n") 40 | f=open("tree_data.doc","a+") #open and save in file tree data 41 | f.write(keyword+"\t\t"+name+"\n") 42 | x.add_row([keyword, name]) #adds new row to table 43 | f.close() 44 | tb_comps() 45 | -------------------------------------------------------------------------------- /image_draw/draw_rect_with_text_inside.py: -------------------------------------------------------------------------------- 1 | import docx 2 | from PIL import Image,ImageDraw 3 | doc = docx.Document() 4 | img = Image.new("RGB", (500, 500),"white") 5 | # create a image draw handle 6 | img1 = ImageDraw.Draw(img) 7 | img1.rectangle((200,125,300,200),fill ="orange", outline = "black",width = 1) 8 | img1.text((210, 150), "CHECK TEXT", fill = "black",align = "center") 9 | img.show() 10 | img.save('C:\\Users\\path \\line.jpg'); 11 | doc.add_picture('C:\\path \\line.jpg'); 12 | doc.save('C:\\path\\pattern_printing_ex.docx'); 13 | -------------------------------------------------------------------------------- /image_draw/pattern_finder_indir.py: -------------------------------------------------------------------------------- 1 | # A function to search and identify the name of uvm components 2 | #change the root directory name to use with respect to your files 3 | import os 4 | def component_search(keyword): 5 | root_dir = r"\Users\ashik\Desktop\VLSI docx\FIFO" 6 | for root, dirs, files in os.walk(root_dir, onerror=None): 7 | for filename in files: 8 | file_path = os.path.join(root, filename) 9 | try: 10 | with open(file_path, "rb") as f: # read the file line by line 11 | for line in f: 12 | try: 13 | line = line.decode("utf-8") 14 | except ValueError: 15 | continue 16 | if keyword in line: 17 | print(filename) 18 | print(file_path) # print the file path 19 | break # no need to iterate over the rest of the file 20 | except (IOError, OSError): 21 | pass 22 | def tb_comps(): #function to search the componenet names from log file 23 | component_search("uvm_test") 24 | component_search("uvm_env") 25 | component_search("uvm_scoreboard") 26 | component_search("uvm_agent") 27 | component_search("uvm_driver") 28 | component_search("uvm_monitor") 29 | component_search("uvm_sequencer") 30 | component_search("uvm_sequence") 31 | component_search("uvm_sequence_item") 32 | component_search("interface") 33 | tb_comps() 34 | -------------------------------------------------------------------------------- /image_draw/plain_colour_font_size: -------------------------------------------------------------------------------- 1 | ##########METHOD TO DRAW RECTANGLE WITH THE GIVEN CO-ORDINATES AND FILL WITH THE GIVEN COLOR############## 2 | path = input("enter path of TB directory: ") #user input for path of TB directory 3 | import tkinter 4 | import os,re #search library 5 | root = tkinter.Tk() 6 | lookup = {"keyword":"name"} #lookup table created for uvm component and name 7 | f = open("tree_data.txt","w") #create file for writing component and component name 8 | def component_search(keyword): # to search for keyword in all files of directory 9 | root_dir = path 10 | for root, dirs, files in os.walk(root_dir, onerror=None, topdown=True): # to loop inside all files of directory 11 | for filename in files: 12 | file_path = os.path.join(root, filename) 13 | with open(file_path, "rb") as f: # read file as binary 14 | for line in f: 15 | line = line.decode("utf-8") #decode to string for read 16 | if keyword in line: # keyword determines the word to be looked into in each of the file 17 | component_name_finder(keyword, line) # call function to find class name 18 | 19 | def read_file_draw(): 20 | f = open("tree_data.txt","r") #read file written with names 21 | file = f.read() 22 | global a 23 | #print (file) 24 | if (re.search("uvm_test",file)): # find keyword in file 25 | #top() # draw top 26 | #test(lookup['uvm_test']) #draw test with found name 27 | #env(lookup['uvm_env']) # draw env with found name 28 | #scoreboard(lookup['uvm_scoreboard']) # draw scb with found name 29 | a =file.count("uvm_agent") # find number of agents 30 | print(a) 31 | print ("number of agents : "+str(a)) #print number of agents 32 | # a=3 '''uncomment and add values for agents explicitly''' 33 | #for i in range(a): 34 | #agent(a,i,lookup['uvm_agent']) # draw agent with agent names 35 | f.close() 36 | def tb_comps(): #generic word in tb components that can be searched to determine presence of comp in TB 37 | component_search("uvm_test") 38 | component_search("uvm_env") 39 | component_search("uvm_scoreboard") 40 | component_search("uvm_agent") 41 | component_search("uvm_driver") 42 | component_search("uvm_monitor") 43 | component_search("uvm_sequencer") 44 | component_search("uvm_sequence ") 45 | component_search("uvm_sequence_item") 46 | component_search("interface") 47 | #component_search("package") 48 | 49 | for key, value in lookup.items(): #saving component names into lookup table 50 | print(key, ' : ', value) 51 | def component_name_finder(keyword,line): 52 | text = line.split() #split line where text found 53 | name = text[1] # get name from split line 54 | #print(keyword,name) 55 | lookup [keyword] = name #add name to lookup table 56 | f = open("tree_data.txt","a+") #add found name to file : open write and close 57 | f.write(keyword+"\t\t\t\t"+name+"\n") 58 | f.close() 59 | tb_comps() 60 | read_file_draw() 61 | font_value=input("enter a font_value:") 62 | font_size=int(font_value) 63 | print("value of font_sixe",font_size); 64 | def draw_rect(image,coordinates,fill,color,width=1): 65 | rect_start = (coordinates[0][0],coordinates[0][1]); 66 | rect_end = (coordinates[1][0], coordinates [1][1]); 67 | image.rectangle((rect_start,rect_end),fill=fill,outline = color) 68 | #Method to write the text inside the rectangle 69 | def wr_text_in_rect(image,start_wr_w,start_wr_h,str,tfill): 70 | font = ImageFont.truetype("arial.ttf",font_size) 71 | image.text((start_wr_w,start_wr_h),str, fill = tfill,font = font) 72 | #Method to draw the top,test,env blocks (w.r.t. the value of n chosen) 73 | def call_simple_rect(w,h,n,text,bfill,tfill,img1): 74 | w1 = w - (n*10); #end of x should be max 75 | if n != 5: 76 | h2 = h - (n*10); #end of 'y' should be max 77 | h1 = n*15 + 10; 78 | w2 = h1; 79 | elif n == 5: #The height of the env block should be less; So used like below dimensions 80 | h2 = h - (n*10*5) 81 | h1 = n*15 + 10 + 35; 82 | w2 = n*15 + 10; 83 | top_right = (w1,h1) 84 | bottom_left = (w2,h2) 85 | start_x = w1 - (50); 86 | start_y = h1 + (n*2); 87 | outline_width = 10 88 | outline_color = "black" 89 | draw_rect(img1,(top_right, bottom_left), fill=bfill ,color=outline_color, width=outline_width) 90 | wr_text_in_rect(img1,start_x,start_y,text,tfill) 91 | print ("Dimensions are %0d %0d %0d %0d",top_right, bottom_left) 92 | return w1; 93 | #This “docx” module is to manipulate with docs like MS Word. Used it to add TB diagram to the document 94 | import docx 95 | 96 | #This “opencv” module in python ease us to draw arrowed line in the image 97 | import cv2 98 | # This “pillow” module to import Image draw module 99 | from PIL import Image,ImageDraw,ImageFont 100 | #Taking the handle “doc” for docx 101 | doc = docx.Document() 102 | #This Module is used to measure the whole screen size 103 | 104 | #root = tkinter.Tk() 105 | #lookup = {"keyword":"name"} #lookup table created for uvm component and name 106 | 107 | width = root.winfo_screenwidth() 108 | height = root.winfo_screenheight() 109 | print ("Width & HEIGHT",width,height) 110 | # create line image of width and height 111 | w = width 112 | h = height 113 | img = Image.new("RGB", (w, h),"white") 114 | img1 = ImageDraw.Draw(img) 115 | #Create first outer rectangle top n=1 116 | #def top(): 117 | n = 1; 118 | top_dim = call_simple_rect(w,h,n,"TOP","white","black",img1);#orange 119 | #Create second inner rectangle test n=3 120 | #def test(name): 121 | n = 3; 122 | #label = name 123 | test_dim = call_simple_rect(w,h,n,"TEST","white","black",img1);#pink 124 | #Create third inner rectangle env n=5 125 | n = 5; 126 | env_dim = call_simple_rect(w,h,n,"ENV","white","black",img1);#yellow 127 | #Create fifth inner rectangle SCOREBOARD 128 | top_right = (w-140,150) 129 | bottom_left = (400,230) 130 | start_x = ((w-140)+400)/2 + 12; 131 | start_y = 180; 132 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=10)#gray 133 | wr_text_in_rect(img1,start_x,start_y,"SCOREBOARD","BLACK") 134 | #Create fourth inner rectangle sequences DUT 135 | top_right = (90,h-80) 136 | bottom_left = (w-40,h-50) 137 | start_x_dut = (90 + (w-40))/2; 138 | start_y_dut = (((h - 80) + (h - 50))/2) - 12; 139 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=10)#grey 140 | wr_text_in_rect(img1,start_x_dut,start_y_dut,"DUT","BLACK") 141 | #Create fourth inner rectangle Interface 142 | top_right = (90,h-120) 143 | bottom_left = (w-40,h-150) 144 | start_x_if = (90 + (w-40))/2; 145 | start_y_if = ((h-120)+(h-150))/2 - 12; 146 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=10)#green 147 | wr_text_in_rect(img1,start_x_if,start_y_if,"INTERFACE","BLACK") 148 | #Create fourth inner rectangle VIF 149 | top_right = (90,h-190) 150 | bottom_left = (w-40,h-220) 151 | start_x_vif = (90 + (w-40))/2; 152 | start_y_vif = ((h-190)+(h-220))/2 - 12; 153 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=10)#gray 154 | wr_text_in_rect(img1,start_x_vif,start_y_vif,"VIF","BLACK") 155 | print(env_dim); 156 | #Check for number of agents 157 | n = 7; 158 | agnt_cnt = 1 #int(input("Enter no. of agents")) 159 | print("Navn_ag_cnt") 160 | print(agnt_cnt) 161 | w1 = (env_dim/agnt_cnt) 162 | h1 = (env_dim/agnt_cnt) 163 | tx = 40; 164 | x0 = 0; 165 | diff = 0; 166 | m1 = 1; 167 | m2 = 0; 168 | #To draw the number of agents w.r.t. agent count 169 | for val in range(agnt_cnt): 170 | print("VALUE OF X0 IS",x0) 171 | x1 = tx + 55; 172 | print("VALUE OF X1 IS",x1) 173 | y0 = (n*4*10) 174 | if agnt_cnt == 1: 175 | x0 = (env_dim/agnt_cnt) - 20; 176 | print("VALUE OF X0 IS IF AGENT==1",x0) 177 | elif agnt_cnt != 1: 178 | x0 = (m1*(env_dim/agnt_cnt))+(m2*(x1 + diff)); 179 | print("VALUE OF X0 LATER IS",x0) 180 | y1 = h - (4*n*10) 181 | tx = x0; 182 | diff = x0 - x1; 183 | xdiff = x0 - x1; 184 | ydiff = y1 - y0; 185 | top_right = (x0,y0); 186 | bottom_left = (x1,y1); 187 | #start_x = x0 - 50; 188 | start_x = x0 - (19*xdiff/20); 189 | #start_y = y0 + 5; 190 | start_y = y0 + (ydiff/20); 191 | 192 | outline_width = 10 193 | print(top_right); 194 | print(bottom_left); 195 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=outline_width)#cyan 196 | wr_text_in_rect(img1,start_x,start_y,"AGENT","BLACK") 197 | #Start another rectangle MONITOR inside the agent 198 | 199 | x3 = x1 + (xdiff/20); 200 | #y3 = y0 + 20 201 | y3 = y1 - (ydiff/20); 202 | #x2 = x0 - 350 203 | x2 = x0 - (12*xdiff/20); 204 | #y2 = y0 + 100 205 | y2 = y0 + (12*ydiff/20); 206 | top_right = (x2,y2); 207 | bottom_left = (x3,y3); 208 | xdiff_mon = x2 - x3; 209 | ydiff_mon = y3 - y2; 210 | #start_x_mon = (x2 + x3)/2; 211 | start_x_mon = x3 + xdiff_mon/20; 212 | #start_y_mon = y3 + 15; 213 | start_y_mon = y2 + ydiff_mon/2; 214 | outline_width = 10 215 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=outline_width)#orange 216 | #wr_text_in_rect(img1,start_x_mon,start_y_mon,"MONITOR","BLACK") 217 | wr_text_in_rect(img1,start_x_mon,start_y_mon,"MON","BLACK") 218 | #Start another rectangle DRIVER inside the agent 219 | # x5 = x3 + 300 220 | x5 = x1 + (12*xdiff/20); 221 | # y5 = y3 + 100 222 | y5 = y1 - (ydiff/20); 223 | #x4 = x2 + 300 224 | x4 = x0 - (xdiff/20); 225 | #y4 = y2 + 100 226 | y4 = y0 + (12*ydiff/20); 227 | top_right = (x4,y4); 228 | bottom_left = (x5,y5); 229 | xdiff_drv = x4 - x5; 230 | ydiff_drv = y5 - y4; 231 | #start_x_drv = (x4 + x5)/2; 232 | #start_y_drv = y5 + 5; 233 | start_x_drv = x5 + xdiff_drv/20; 234 | start_y_drv = y4 + ydiff_drv/2; 235 | outline_width = 10 236 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=outline_width)#green 237 | #wr_text_in_rect(img1,start_x_drv,start_y_drv,"DRIVER","BLACK") 238 | wr_text_in_rect(img1,start_x_drv,start_y_drv,"DRV","BLACK") 239 | m2 = 1; 240 | m1 = 0; 241 | print("DRIVER",start_x_drv,start_y_drv); 242 | #Start another rectangle SEQUENCER inside the agen 243 | #x5 = x3 + 300 244 | x5 = x1 + (12*xdiff/20); 245 | #y5 = y3 246 | y5 = y1 - (12*ydiff/20); 247 | #x4 = x2 + 300 248 | x4 = x0 - (xdiff/20); 249 | #y4 = y2 250 | y4 = y0 + (ydiff/20); 251 | top_right = (x4,y4); 252 | bottom_left = (x5,y5); 253 | xdiff_sqr = x4 - x5; 254 | ydiff_sqr = y5 - y4; 255 | #start_x_sqr = (x4 + x5)/2; 256 | #start_y_sqr = y5 + 5; 257 | start_x_sqr = x5 + xdiff_sqr / 20; 258 | start_y_sqr = y4 + ydiff_sqr / 2; 259 | outline_width = 10 260 | draw_rect(img1,(top_right, bottom_left), fill="white" ,color="black", width=outline_width)#grey 261 | #wr_text_in_rect(img1,start_x_sqr,start_y_sqr,"SEQUENCER","BLACK") 262 | wr_text_in_rect(img1,start_x_sqr,start_y_sqr,"SQR","BLACK") 263 | m2 = 1; 264 | m1 = 0; 265 | img.show() 266 | img.save('D:\python\\tb_arch.jpg'); 267 | # Arrow Drawing 268 | path = 'D:\python\\tb_arch.jpg' 269 | # Reading an image in default mode 270 | image = cv2.imread(path) 271 | # Window name in which image is displayed 272 | window_name = 'Image' 273 | ######################DRAW ARROW BETWEEN DRIVER AND VIF################################# 274 | start_point = (int(start_x_drv - 25),int(start_y_drv) + 75) 275 | # End coordinate 276 | end_point = (int(start_x_drv - 25),int(start_y_drv + 25) + 115) 277 | color = (0, 0, 0) 278 | thickness = 3 279 | # Using cv2.arrowedLine() method 280 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 281 | cv2.imshow(window_name, image) 282 | cv2.imwrite("D:\python\\tb_arch.jpg",image) 283 | ######################DRAW ARROW BETWEEN VIF AND INTERFACE################################### 284 | # Start coordinate 285 | start_point = (int(start_x_vif - 15),int(start_y_vif + 25)) 286 | # End coordinate 287 | end_point = (int(start_x_if - 15),int(start_y_if - 5)) 288 | color = (0, 0, 0) 289 | thickness = 3 290 | # Using cv2.arrowedLine() method 291 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 292 | cv2.imshow(window_name, image) 293 | 294 | ######################DRAW ARROW BETWEEN INTERFACE AND DUT################################# 295 | start_point = (int(start_x_if - 15),int(start_y_if + 25)) 296 | # End coordinate 297 | end_point = (int(start_x_dut - 15),int(start_y_dut - 5)) 298 | color = (0, 0, 0) 299 | thickness = 3 300 | # Using cv2.arrowedLine() method 301 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 302 | cv2.imshow(window_name, image) 303 | #tb_comps() 304 | #read_file_draw() 305 | ######################DRAW ARROW BETWEEN DRIVER1 AND VIF################################# 306 | start_point = (506,482) 307 | # End coordinate 308 | end_point = (506,547) 309 | color = (0, 0, 0) 310 | thickness = 3 311 | # Using cv2.arrowedLine() method 312 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 313 | #tb_comps() 314 | #read_file_draw() 315 | cv2.imshow(window_name, image) 316 | ######################DRAW ARROW BETWEEN DRIVER2 AND VIF################################# 317 | start_point = (836,482) 318 | # End coordinate 319 | end_point = (836,547) 320 | color = (0, 0, 0) 321 | thickness = 3 322 | # Using cv2.arrowedLine() method 323 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 324 | #tb_comps() 325 | #read_file_draw() 326 | cv2.imshow(window_name, image) 327 | ######################DRAW ARROW BETWEEN DRIVER2 AND VIF################################# 328 | start_point = (236,482) 329 | # End coordinate 330 | end_point = (236,547) 331 | color = (0, 0, 0) 332 | thickness = 3 333 | # Using cv2.arrowedLine() method 334 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 335 | #tb_comps() 336 | #read_file_draw() 337 | cv2.imshow(window_name, image) 338 | cv2.imwrite("D:\python\\tb_arch.jpg",image) 339 | doc.add_picture('D:\python\\tb_arch.jpg') 340 | doc.save('D:\python\\pattern_printing_ex.docx') 341 | -------------------------------------------------------------------------------- /image_draw/tb_arch_img_draw.py: -------------------------------------------------------------------------------- 1 | # Refer tb_arch_img_draw.docx for detailed explanation 2 | from PIL import ImageDraw,Image 3 | f=open("tb_info.txt",'r') 4 | content = f.readline() 5 | agent=content.split() 6 | agent_number=agent[2] 7 | f.close() 8 | print(agent_number) 9 | img=Image.new("RGB",(500,500),"white") 10 | draw=ImageDraw.Draw(img) 11 | def top(): 12 | draw.rectangle((5,5,495,360),fill="blue",outline="black") 13 | draw.text((8,8),"top",fill="black") 14 | def test(): 15 | draw.rectangle((20,20,480,340),fill="green",outline="black") 16 | draw.text((22,22),"test",fill="black") 17 | def env(): 18 | draw.rectangle((35,35,465,320),fill="grey",outline="black") 19 | draw.text((38,38),"env",fill="black") 20 | scoreboard() 21 | for i in range(int(agent_number)): 22 | agent(i) 23 | sequencer(i) 24 | driver(i) 25 | monitor(i) 26 | def scoreboard(): 27 | draw.rectangle((150,40,350,80),fill="yellow",outline="black") 28 | draw.text((225,50),"Scoreboard",fill="black") 29 | def agent(y): 30 | x = y * ((380/int(agent_number)) + 10) 31 | z=380/int(agent_number) 32 | draw.rectangle((50+x,90,z+50+x,300),fill="pink",outline="black") 33 | draw.text((55+x,90),"agent",fill="black") 34 | def sequencer(y): 35 | x = y * ((380/int(agent_number)) + 10) 36 | z=200/int(agent_number) 37 | draw.rectangle((60+x,100,z+60+x,140),fill="pink",outline="black") 38 | draw.text((60+x,115),"sequencer",fill="black") 39 | def driver(y): 40 | x = y * ((380/int(agent_number)) + 10) 41 | z=160/int(agent_number) 42 | draw.rectangle((60+x,180,z+60+x,220),fill="pink",outline="black") 43 | draw.text((65+x,190),"driver",fill="black") 44 | def monitor(y): 45 | x = y * ((380/int(agent_number)) + 10) 46 | z=160/int(agent_number) 47 | draw.rectangle((60+x+z+10,180,((z*2)+60+x),220),fill="pink",outline="black") 48 | draw.text((65+x+z,190),"monitor",fill="black") 49 | top() 50 | test() 51 | env() 52 | img.show() 53 | -------------------------------------------------------------------------------- /image_draw/tlm_identifier.py: -------------------------------------------------------------------------------- 1 | 2 | def component_search(keyword): # to search for keyword in all files of directory 3 | root_dir = path 4 | for root, dirs, files in os.walk(root_dir, onerror=None, topdown=True): # to loop inside all files of directory 5 | for filename in files: 6 | file_path = os.path.join(root, filename) 7 | with open(file_path, "rb") as f: # read file as binary 8 | for line in f: 9 | line = line.decode("utf-8") #decode to string for read 10 | if keyword in line: # keyword determines the word to be looked into in each of the file 11 | component_name_finder(keyword, line) # call function to find class name 12 | 13 | def tb_comps(): #generic word in tb components that can be searched to determine presence of comp in TB 14 | component_search(".connect(") 15 | 16 | f = open("tree_data.doc", "a+") #opens document for append 17 | f.write("\nname list in table format\n") 18 | f.write(str(x)) #draws updated table data 19 | f.close() 20 | def component_name_finder(keyword,line): 21 | text = line.split() #to split line to get class name 22 | name = text[0] 23 | print(keyword+"\t\t\t"+name+"\n") 24 | f=open("tree_data.doc","a+") #open and save in file tree data 25 | f.write(keyword+"\t\t"+name+"\n") 26 | x.add_row([keyword, name]) #adds new row to table 27 | f.close() 28 | 29 | import os, re, prettytable 30 | n = input("Enter number of heirarchical testbench directories: ") #taking the number of directories which are to be searched, from the user. 31 | n = int(n) 32 | for x in range (n): #taking the path of the directories which are to be searched. 33 | #Output for one path is displayed then user is asked to enter the next path 34 | path = input("enter path of TB directory: ") #user input for path of TB directory 35 | open("tree_data.doc","w+") 36 | from prettytable import PrettyTable #to draw table of list 37 | x = PrettyTable() 38 | x.field_names = ["keyword", "class name"] 39 | tb_comps() 40 | -------------------------------------------------------------------------------- /image_draw/uvm_tb_arch_agent.py: -------------------------------------------------------------------------------- 1 | ##########METHOD TO DRAW RECTANGLE WITH THE GIVEN CO-ORDINATES AND FILL WITH THE GIVEN COLOR############## 2 | def draw_rect(image,coordinates,fill,color,width=1): 3 | rect_start = (coordinates[0][0],coordinates[0][1]); 4 | rect_end = (coordinates[1][0], coordinates [1][1]) 5 | image.rectangle((rect_start,rect_end),fill=fill,outline = color) 6 | #Method to write the text inside the rectangle 7 | def wr_text_in_rect(image,start_wr_w,start_wr_h,str,tfill): 8 | font = ImageFont.truetype("arial.ttf", 15) 9 | image.text((start_wr_w,start_wr_h),str, fill = tfill,font = font) 10 | #Method to draw the top,test,env blocks (w.r.t. the value of n chosen) 11 | def call_simple_rect(w,h,n,text,bfill,tfill,img1): 12 | w1 = w - (n*10); #end of x should be max 13 | if n != 5: 14 | h2 = h - (n*10); #end of 'y' should be max 15 | h1 = n*15 + 10; 16 | w2 = h1; 17 | elif n == 5: #The height of the env block should be less; So used like below dimensions 18 | h2 = h - (n*10*5) 19 | h1 = n*15 + 10 + 35; 20 | w2 = n*15 + 10; 21 | top_right = (w1,h1) 22 | bottom_left = (w2,h2) 23 | start_x = w1 - (50); 24 | start_y = h1 + (n*2); 25 | outline_width = 10 26 | outline_color = "black" 27 | draw_rect(img1,(top_right, bottom_left), fill=bfill ,color=outline_color, width=outline_width) 28 | wr_text_in_rect(img1,start_x,start_y,text,tfill) 29 | print ("Dimensions are %0d %0d %0d %0d",top_right, bottom_left) 30 | return w1; 31 | #This “docx” module is to manipulate with docs like MS Word. Used it to add TB diagram to the document 32 | import docx 33 | #This “opencv” module in python ease us to draw arrowed line in the image 34 | import cv2 35 | # This “pillow” module to import Image draw module 36 | from PIL import Image,ImageDraw,ImageFont 37 | #Taking the handle “doc” for docx 38 | doc = docx.Document() 39 | #This Module is used to measure the whole screen size 40 | import tkinter 41 | root = tkinter.Tk() 42 | width = root.winfo_screenwidth() 43 | height = root.winfo_screenheight() 44 | print ("Width & HEIGHT",width,height) 45 | # create line image of width and height 46 | w = width 47 | h = height 48 | img = Image.new("RGB", (w, h),"white") 49 | img1 = ImageDraw.Draw(img) 50 | #Create first outer rectangle top n=1 51 | n = 1; 52 | top_dim = call_simple_rect(w,h,n,"TOP","orange","black",img1); 53 | #Create second inner rectangle test n=3 54 | n = 3; 55 | test_dim = call_simple_rect(w,h,n,"TEST","pink","black",img1); 56 | #Create third inner rectangle env n=5 57 | n = 5; 58 | env_dim = call_simple_rect(w,h,n,"ENV","yellow","black",img1); 59 | #Create fifth inner rectangle SCOREBOARD 60 | top_right = (w-140,150) 61 | bottom_left = (400,230) 62 | start_x = ((w-140)+400)/2 + 12; 63 | start_y = 180; 64 | draw_rect(img1,(top_right, bottom_left), fill="gray" ,color="black", width=10) 65 | wr_text_in_rect(img1,start_x,start_y,"SCOREBOARD","BLACK") 66 | #Create fourth inner rectangle sequences DUT 67 | top_right = (90,h-80) 68 | bottom_left = (w-40,h-50) 69 | start_x_dut = (90 + (w-40))/2; 70 | start_y_dut = (((h - 80) + (h - 50))/2) - 12; 71 | draw_rect(img1,(top_right, bottom_left), fill="grey" ,color="black", width=10) 72 | wr_text_in_rect(img1,start_x_dut,start_y_dut,"DUT","BLACK") 73 | #Create fourth inner rectangle Interface 74 | top_right = (90,h-120) 75 | bottom_left = (w-40,h-150) 76 | start_x_if = (90 + (w-40))/2; 77 | start_y_if = ((h-120)+(h-150))/2 - 12; 78 | draw_rect(img1,(top_right, bottom_left), fill="green" ,color="black", width=10) 79 | wr_text_in_rect(img1,start_x_if,start_y_if,"INTERFACE","BLACK") 80 | #Create fourth inner rectangle VIF 81 | top_right = (90,h-190) 82 | bottom_left = (w-40,h-220) 83 | start_x_vif = (90 + (w-40))/2; 84 | start_y_vif = ((h-190)+(h-220))/2 - 12; 85 | draw_rect(img1,(top_right, bottom_left), fill="gray" ,color="black", width=10) 86 | wr_text_in_rect(img1,start_x_vif,start_y_vif,"VIF","BLACK") 87 | print(env_dim); 88 | #Check for number of agents 89 | n = 7; 90 | agnt_cnt = int(input("Enter no. of agents")) 91 | w1 = (env_dim/agnt_cnt) 92 | h1 = (env_dim/agnt_cnt) 93 | tx = 40; 94 | x0 = 0; 95 | diff = 0; 96 | m1 = 1; 97 | m2 = 0; 98 | #To draw the number of agents w.r.t. agent count 99 | for val in range(agnt_cnt): 100 | print("VALUE OF X0 IS",x0) 101 | x1 = tx + 55; 102 | print("VALUE OF X1 IS",x1) 103 | y0 = (n*4*10) 104 | if agnt_cnt == 1: 105 | x0 = (env_dim/agnt_cnt) - 20; 106 | elif agnt_cnt != 1: 107 | x0 = (m1*(env_dim/agnt_cnt))+(m2*(x1 + diff)); 108 | print("VALUE OF X0 LATER IS",x0) 109 | y1 = h - (4*n*10) 110 | tx = x0; 111 | diff = x0 - x1; 112 | xdiff = x0 - x1; 113 | ydiff = y1 - y0; 114 | top_right = (x0,y0); 115 | bottom_left = (x1,y1); 116 | start_x = x0 - (19*xdiff/20); 117 | start_y = y0 + (ydiff/20); 118 | 119 | outline_width = 10 120 | print(top_right); 121 | print(bottom_left); 122 | draw_rect(img1,(top_right, bottom_left), fill="cyan" ,color="black", width=outline_width) 123 | wr_text_in_rect(img1,start_x,start_y,"AGENT","BLACK") 124 | #Start another rectangle MONITOR inside the agent 125 | 126 | x3 = x1 + (xdiff/20); 127 | y3 = y1 - (ydiff/20); 128 | x2 = x0 - (12*xdiff/20); 129 | y2 = y0 + (12*ydiff/20); 130 | top_right = (x2,y2); 131 | bottom_left = (x3,y3); 132 | xdiff_mon = x2 - x3; 133 | ydiff_mon = y3 - y2; 134 | start_x_mon = x3 + xdiff_mon/20; 135 | start_y_mon = y2 + ydiff_mon/2; 136 | outline_width = 10 137 | draw_rect(img1,(top_right, bottom_left), fill="orange" ,color="black", width=outline_width) 138 | #wr_text_in_rect(img1,start_x_mon,start_y_mon,"MONITOR","BLACK") 139 | wr_text_in_rect(img1,start_x_mon,start_y_mon,"MON","BLACK") 140 | #Start another rectangle DRIVER inside the agent 141 | x5 = x1 + (12*xdiff/20); 142 | y5 = y1 - (ydiff/20); 143 | x4 = x0 - (xdiff/20); 144 | y4 = y0 + (12*ydiff/20); 145 | top_right = (x4,y4); 146 | bottom_left = (x5,y5); 147 | xdiff_drv = x4 - x5; 148 | ydiff_drv = y5 - y4; 149 | start_x_drv = x5 + xdiff_drv/20; 150 | start_y_drv = y4 + ydiff_drv/2; 151 | outline_width = 10 152 | draw_rect(img1,(top_right, bottom_left), fill="green" ,color="black", width=outline_width) 153 | wr_text_in_rect(img1,start_x_drv,start_y_drv,"DRV","BLACK") 154 | m2 = 1; 155 | m1 = 0; 156 | print("DRIVER",start_x_drv,start_y_drv) 157 | #Start another rectangle SEQUENCER inside the agent 158 | x5 = x1 + (12*xdiff/20); 159 | y5 = y1 - (12*ydiff/20); 160 | x4 = x0 - (xdiff/20); 161 | y4 = y0 + (ydiff/20); 162 | top_right = (x4,y4); 163 | bottom_left = (x5,y5); 164 | xdiff_sqr = x4 - x5; 165 | ydiff_sqr = y5 - y4; 166 | start_x_sqr = x5 + xdiff_sqr / 20; 167 | start_y_sqr = y4 + ydiff_sqr / 2; 168 | outline_width = 10 169 | draw_rect(img1,(top_right, bottom_left), fill="grey" ,color="black", width=outline_width) 170 | wr_text_in_rect(img1,start_x_sqr,start_y_sqr,"SQR","BLACK") 171 | m2 = 1; 172 | m1 = 0; 173 | img.show() 174 | img.save('D:\\pyth\\tb_arch.jpg'); 175 | # Arrow Drawing 176 | path = 'D:\\pyth\\tb_arch.jpg' 177 | # Reading an image in default mode 178 | image = cv2.imread(path) 179 | # Window name in which image is displayed 180 | window_name = 'Image' 181 | ######################DRAW ARROW BETWEEN DRIVER AND VIF################################# 182 | start_point = (int(start_x_drv - 15),int(start_y_drv) + 75) 183 | # End coordinate 184 | end_point = (int(start_x_drv - 15),int(start_y_drv + 25) + 115) 185 | color = (0, 0, 0) 186 | thickness = 3 187 | # Using cv2.arrowedLine() method 188 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 189 | cv2.imshow(window_name, image) 190 | cv2.imwrite("D:\\pyth\\tb_arch.jpg",image) 191 | ######################DRAW ARROW BETWEEN VIF AND INTERFACE################################### 192 | # Start coordinate 193 | start_point = (int(start_x_vif - 15),int(start_y_vif + 25)) 194 | # End coordinate 195 | end_point = (int(start_x_if - 15),int(start_y_if - 5)) 196 | color = (0, 0, 0) 197 | thickness = 3 198 | # Using cv2.arrowedLine() method 199 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 200 | cv2.imshow(window_name, image) 201 | ######################DRAW ARROW BETWEEN INTERFACE AND DUT################################# 202 | start_point = (int(start_x_if - 15),int(start_y_if + 25)) 203 | # End coordinate 204 | end_point = (int(start_x_dut - 15),int(start_y_dut - 5)) 205 | color = (0, 0, 0) 206 | thickness = 3 207 | # Using cv2.arrowedLine() method 208 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 209 | cv2.imshow(window_name, image) 210 | ######################DRAW ARROW BETWEEN DRIVER1 AND VIF################################# 211 | start_point = (506,482) 212 | # End coordinate 213 | end_point = (506,547) 214 | color = (0, 0, 0) 215 | thickness = 3 216 | # Using cv2.arrowedLine() method 217 | image = cv2.arrowedLine(image, start_point, end_point,color, thickness) 218 | cv2.imshow(window_name, image) 219 | cv2.imwrite("D:\\pyth\\tb_arch.jpg",image) 220 | doc.add_picture('D:\\pyth\\tb_arch.jpg') 221 | doc.save('D:\\pyth\\pattern_printing_ex.docx') 222 | -------------------------------------------------------------------------------- /image_draw/uvm_tb_name_image_file_generator.py: -------------------------------------------------------------------------------- 1 | import PIL, tkinter # adding pillow and tkinter for image draw and canvas 2 | import tkinter as Tk # short name for tkinter 3 | from PIL import Image, ImageDraw, ImageFont # image , imagedraw and imagefont from pillow 4 | import os, re # search library 5 | path = input("enter path of TB directory: ") #user input for path of TB directory 6 | root = tkinter.Tk() #canvas size decider 7 | w = root.winfo_screenwidth() # depending on screen size set width and height 8 | h = root.winfo_screenheight() 9 | root.geometry(f'{w}x{h}') # set new canvas size 10 | print("Width & HEIGHT", w, h) # w and h for user refernce 11 | # create line image of width and height 12 | img = Image.new("RGB",[w,h],"white") 13 | tb = ImageDraw.Draw(img) 14 | lookup = {"keyword":"name"} #lookup table created for uvm component and name 15 | f = open("tree_data.txt","w") #create file for writing component and component name 16 | f.truncate(0) # clean file before writing data 17 | def top(): # drawing top level structure 18 | n=0 # value to simplify calculations 19 | top_left = (n * 50, n * 50) # co-ordinate decider 20 | bottom_right = (w - (n * 50), h - (n * 50)) # co-ordinate decider 21 | color_fill = "yellow" #color for block 22 | label = "top" #name of default block 23 | block(n,top_left,bottom_right,label,color_fill) #call the rectangle creater function 24 | def test(name): #drawing test level structure 25 | n=1 #value to simplify calculations 26 | top_left = (n * 50, n * 50) # co-ordinate decider 27 | bottom_right = (w - (n * 50), h - (n * 50)) # co-ordinate decider 28 | color_fill = "orange" #color for block 29 | label = name #"test" 30 | block(n,top_left,bottom_right,label,color_fill) #call the rectangle creater function 31 | def env(name): 32 | n=2 # value to simplify calculations 33 | top_left = (n * 50, n * 50) # co-ordinate decider 34 | bottom_right = (w - (n * 50), h - (n * 90)) # co-ordinate decider 35 | color_fill = "yellow" #color for block 36 | label = name #"env" 37 | block(n,top_left,bottom_right,label, color_fill) #call the rectangle creater function 38 | #DUT 39 | top_left = (n*50, h - (n*90)+10) # co-ordinate decider 40 | bottom_right = (w - (n * 50), h - (n * 50)) # co-ordinate decider 41 | color_fill = "green" #color for block 42 | label = "" 43 | block(n,top_left,bottom_right,label, color_fill) #call the rectangle creater function 44 | font = ImageFont.truetype("arial.ttf", 20) 45 | tb.text((w/2,h - (n * 75) ), "DUT", fill="black", font=font) #avoid taking default text coordinates 46 | def scoreboard(name): 47 | n= 3 # value to simplify calculations 48 | top_left = (n * 50, n * 50) # co-ordinate decider 49 | bottom_right = (w - (n * 50), (h - (n * 50))/3) # co-ordinate decider 50 | color_fill = "red" #color for block 51 | label = name #"scoreboard" 52 | block(n,top_left,bottom_right,label, color_fill) #call the rectangle creater function 53 | def agent(a,i,name): 54 | n=4 # value to simplify calculations 55 | x =200+((i)*(w-200)/a) # co-ordinate decider wrt to number of agents 56 | y = (n * 75) # co-ordinate decider wrt to number of agents 57 | x1 =x+((w-200)/a)-200 # co-ordinate decider wrt to number of agents 58 | y1 = (h - (n * 50)) # co-ordinate decider wrt to number of agents 59 | top_left = (x, y) # co-ordinate decider 60 | bottom_right = (x1,y1) # co-ordinate decider 61 | color_fill = "blue" #color for block 62 | label = "" 63 | block(n, top_left, bottom_right, label, color_fill) #call the rectangle creater function 64 | font = ImageFont.truetype("arial.ttf", 15) #text settings 65 | if (a>5): #if number of agents are greater than 5 draw sub-components small 66 | label = name #"AGT"+str(i+1) 67 | mark = x - 50 68 | block(5, top_left=(x , y + 30), bottom_right=(x1 , y1 - 250), label=" ", color_fill="grey") #for sequencer 69 | block(6, top_left=(x , y + 140), bottom_right=(x1, y1 - 130), label="", color_fill="violet") #for driver 70 | block(7, top_left=(x , y + 260), bottom_right=(x1, y1 - 30), label="", color_fill="indigo") #for monitor 71 | tb.text((mark + 10, (4 * 75) + 35), "SQR", fill="black", font=font) #naming for Sqr 72 | tb.text((mark + 10, 145 + (4 * 75)), "DRV", fill="black", font=font) #naming for drv 73 | tb.text((mark + 10, 265 + (4 * 75)), "MON", fill="black", font=font) #naming for mon 74 | else: 75 | label = name #"agent"+str(i+1) 76 | mark = x + 5 77 | block(5, top_left=(x + 30, y + 30), bottom_right=(x1 - 20, y1 - 250), label=" ", color_fill="grey") #for sequencer 78 | block(6, top_left=(x + 30, y + 140), bottom_right=(x1 - 20, y1 - 130), label="", color_fill="violet") #for driver 79 | block(7, top_left=(x + 30, y + 260), bottom_right=(x1 - 20, y1 - 30), label="", color_fill="indigo") #for monitor 80 | tb.text((mark + 35, (4 * 75) + 35), "sequencer", fill="black", font=font) #for sequencer 81 | tb.text((mark + 35, 145 + (4 * 75)), "driver", fill="black", font=font) #for driver 82 | tb.text((mark + 35, 265 + (4 * 75)), "monitor", fill="black", font=font) #for monitor 83 | tb.text((mark,10+(n*75)),label, fill="black", font=font) 84 | def block(n,top_left,bottom_right,label,color_fill): # draw rectangle block, fill color and label 85 | tb.rectangle([top_left,bottom_right],color_fill,"black",5) #default values for all instance 86 | font = ImageFont.truetype("arial.ttf", 15) #basic settings for text 87 | tb.text((w/2,10+(50*n)),label,fill="black", font=font) 88 | 89 | def component_search(keyword): # to search for keyword in all files of directory 90 | root_dir = path 91 | for root, dirs, files in os.walk(root_dir, onerror=None): # to loop inside all files of directory 92 | for filename in files: 93 | file_path = os.path.join(root, filename) 94 | with open(file_path, "rb") as f: # read file as binary 95 | for line in f: 96 | line = line.decode("utf-8") #decode to string for read 97 | if keyword in line: #keyword determines the word to be looked into in each of the file 98 | #print(filename) 99 | #print(file_path) # print the file path 100 | #print(line) 101 | if (keyword == "interface"): # to avoid psedo interface name error 102 | #print("yes interface") 103 | text =line.split() 104 | if len(text) != 2: 105 | #print("not match") 106 | break 107 | else: 108 | component_name_finder(keyword, line) 109 | else: 110 | component_name_finder(keyword,line) 111 | break 112 | def tb_comps(): #generic word in tb components that can be searched to determine presence of comp in TB 113 | component_search("uvm_test") 114 | component_search("uvm_env") 115 | component_search("uvm_scoreboard") 116 | component_search("uvm_agent") 117 | component_search("uvm_driver") 118 | component_search("uvm_monitor") 119 | component_search("uvm_sequencer") 120 | component_search("uvm_sequence ") 121 | component_search("uvm_sequence_item") 122 | component_search("interface") 123 | #component_search("package") 124 | 125 | for key, value in lookup.items(): #saving component names into lookup table 126 | print(key, ' : ', value) 127 | 128 | def component_name_finder(keyword,line): 129 | text = line.split() #split line where text found 130 | name = text[1] # get name from split line 131 | #print(keyword,name) 132 | lookup [keyword] = name #add name to lookup table 133 | f = open("tree_data.txt","a+") #add found name to file : open write and close 134 | f.write(keyword+"\t\t\t\t"+name+"\n") 135 | f.close() 136 | def read_file_draw(): 137 | f = open("tree_data.txt","r") #read file written with names 138 | file = f.read() 139 | #print (file) 140 | if (re.search("uvm_test",file)): # find keyword in file 141 | top() # draw top 142 | test(lookup['uvm_test']) #draw test with found name 143 | env(lookup['uvm_env']) # draw env with found name 144 | scoreboard(lookup['uvm_scoreboard']) # draw scb with found name 145 | a =file.count("uvm_agent") # find number of agents 146 | print ("number of agents : "+str(a)) #print number of agents 147 | # a=3 '''uncomment and add values for agents explicitly''' 148 | for i in range(a): 149 | agent(a,i,lookup['uvm_agent']) # draw agent with agent names 150 | f.close() 151 | tb_comps() 152 | read_file_draw() 153 | #block(top_left,bottom_right,color_fill) 154 | 155 | img.show() #show image before save 156 | -------------------------------------------------------------------------------- /turtle_files/draw_rect_using_turtle.py: -------------------------------------------------------------------------------- 1 | #Choosing the “TURTLE” library 2 | from turtle import * 3 | # Choose Color for rectangle 4 | color("orange") 5 | # Enabling fill to color the shape 6 | begin_fill() 7 | # Traverse in directions, to draw rectangle 8 | #Move forward direction of 300 units (length of rectangle) 9 | forward(300); 10 | #Move right direction of 90 units (For starting the breadth of rectangle) 11 | right(90) 12 | forward(150) 13 | right(90) 14 | forward(300); 15 | right(90) 16 | forward(150) 17 | right(90) 18 | # End the coloring inside that rectangle 19 | end_fill() 20 | #Choose color to write inside rectangle 21 | color("BLACK") # Choose Black color to write 22 | #Enabling the text fill color 23 | begin_fill() 24 | #This penup feature is to enable the pointer 25 | penup() 26 | #Fixing the pointer location from where to start the text inside rectangle 27 | forward (150) 28 | #right (45) 29 | left(65) 30 | backward (20) 31 | #Write the desired text that needs to be written onto the rectangle 32 | write("TEXT INSIDE RECTANGLE USING TURTLE", True, align="center") 33 | -------------------------------------------------------------------------------- /turtle_files/file creation and turtle library document.docx: -------------------------------------------------------------------------------- 1 | • Download latest python into system in not present. 2 | • Get Pycharm tool or can use command prompt window, if working online you may use google colab. 3 | • Create function 4 | def function_name(): 5 | ------- 6 | • Calling function 7 | Function_name() 8 | • Open a file to read and close 9 | Variable_name = open(r”file_path”,”r”) 10 | Variable_name.close() 11 | • Open a file to write and append/create and close 12 | Variable_name = open(r”file_path”,”w+”) 13 | Variable_name.close() 14 | • Read contents of file 15 | Variable_name = open(r”file_path”,”r”) 16 | Contents = variable_name.read() 17 | To print 18 | Print(contents) 19 | • Turtle library importing. 20 | Import turtle 21 | • Move turtle forward and distance 22 | Turtle.forward(distance) 23 | • Make turtle turn and angle 24 | Turtle.right(angle) 25 | Turtle.left(angle) 26 | • Turtle move without writing and then start writing 27 | Turtle.penup() --- no write 28 | Turtle.pendown – starts writing 29 | • Move to non default position (0,0)[x-axis,y-axis] 30 | Turtle.goto(x-axis,y-axis) 31 | • Turtle drawing speed, color and pensize. 32 | Turtle.speed(10) 33 | Turtle.color(“magenta”) 34 | Turtle.pensize(5) 35 | • Writing text in turtle canvas 36 | Turtle.write(“text to be written”,align=”left”,font=(“Arial”,10,”Normal”)) 37 | Turtle.write(“text to be written”,align=”center”,font=(“Verdana”,20,”Italics”)) 38 | • Turtle screen auto closes after drawing to close only on click 39 | Turtle.exitonclick() 40 | • Regular expression library for pattern search 41 | Re.search(“abc”,file_name_to_be_searched) 42 | Before using import library 43 | Import re 44 | 45 | -------------------------------------------------------------------------------- /turtle_files/pgm1.py: -------------------------------------------------------------------------------- 1 | #Refer basic.docx for detailed explanation 2 | import turtle 3 | s=turtle.Screen() 4 | s.bgcolor("light blue") 5 | ptr = turtle.Turtle() 6 | ptr.pencolor("black") 7 | def draw_square(x,y,l,color): 8 | ptr.fillcolor(color) 9 | ptr.penup() 10 | ptr.goto(x,y) 11 | ptr.pendown() 12 | ptr.begin_fill() 13 | for i in range(4): 14 | ptr.forward(l) 15 | ptr.left(90) 16 | ptr.end_fill() 17 | def draw_rect(x,y,l,w,color): 18 | ptr.fillcolor(color) 19 | ptr.penup() 20 | ptr.goto(x,y) 21 | ptr.pendown() 22 | ptr.begin_fill() 23 | for i in range(2): 24 | ptr.forward(l) 25 | ptr.left(90) 26 | ptr.forward(w) 27 | ptr.left(90) 28 | ptr.end_fill() 29 | draw_square(-200,50,100,"red") 30 | draw_rect(200,50,100,200,"green") 31 | -------------------------------------------------------------------------------- /turtle_files/skeleton of component search python .py: -------------------------------------------------------------------------------- 1 | import os, turtle, re, tkinter, PIL 2 | from tkinter import * 3 | path = input("enter path of TB directory: ") #user input for path of TB directory 4 | import tkinter as tk 5 | from PIL import ImageGrab #pillow library Image grab will help to capture image drawn with turtle 6 | root = tk.Tk() 7 | canvas = tk.Canvas(root, width=1500, height=800) #width of Tkinter canvas 8 | canvas.pack() 9 | t = turtle.RawTurtle(canvas) #turtle to canvas pointer 10 | def component_search(keyword): # to search for keyword in all files of directory 11 | root_dir = path 12 | for root, dirs, files in os.walk(root_dir, onerror=None): # to loop inside all files of directory 13 | for filename in files: 14 | file_path = os.path.join(root, filename) 15 | with open(file_path, "rb") as f: # read file as binary 16 | for line in f: 17 | line = line.decode("utf-8") #decode to string for read 18 | if keyword in line: #keyword determines the word to be looked into in each of the file 19 | print(filename) 20 | print(file_path) # print the file path 21 | if keyword == "package": # add case statements to call shape w.r.t keyword 22 | uvm_tb(file_path) 23 | break 24 | else: break 25 | def tb_comps(): #generic word in tb components that can be searched to determine presence of comp in TB 26 | component_search("uvm_test") #search for keyword uvm_test 27 | component_search("uvm_env") #search for keyword uvm_env 28 | component_search("uvm_scoreboard") #search for keyword uvm_scoreboard 29 | component_search("uvm_agent") #search for keyword uvm_agent 30 | component_search("uvm_driver") #search for uvm_driver 31 | component_search("uvm_monitor") #search for uvm_monitor 32 | component_search("uvm_sequencer") #search for uvm_sequencer 33 | component_search("uvm_sequence") #search for uvm_sequence 34 | component_search("uvm_sequence_item") #search for uvm_sequence_item 35 | component_search("interface") #search for interface 36 | component_search("package") #search for package 37 | def rectangle(x,y,l,b,title): ## draw rectangle with inputs co-ordinates , dimentions text 38 | t.goto(x,y) #co-ordinates to go to 39 | t.penup() #pen movement without write 40 | t.speed(10) #pen speed setup 41 | t.color("black") #pen color 42 | t.pensize(5) #pen thickness 43 | t.pendown() #start draw 44 | for i in range(2): #draw rectangle with dimentions 45 | t.forward(l) # turtle move forward length 46 | t.right(90) #turtle turn right 90 47 | t.forward(b) #turtle forward breadth 48 | t.right(90) #turtle turn right 90 49 | t.penup() #stop writing 50 | t.goto(x+20, y-20) # new value for text 51 | t.pendown() #start writing 52 | t.write(title, align="left", font=("Arial", "10", "bold")) #text to be written , font size alignment type 53 | t.penup() #stop writing 54 | def top(): 55 | t.penup() 56 | rectangle(-700,380,1400,700,"top") #rectangle x,y co-ordinates, length, breadth, title name 57 | def test(): 58 | t.penup() 59 | rectangle(-670,350,1350,650,"test") #rectangle x,y co-ordinates, length, breadth, title name 60 | def env(): 61 | t.penup() 62 | rectangle(-640,320,1300,600,"env") #rectangle x,y co-ordinates, length, breadth, title name 63 | def scoreboard(): 64 | t.penup() 65 | rectangle(30,300,620,50,"scoreboard") #rectangle x,y co-ordinates, length, breadth, title name 66 | def agent(x,agent_number): 67 | y = (x) * 700*(2/agent_number) #y co-ordinates depends on number of agents 68 | t.goto(-620 + y, 200) # x y co-ordinates 69 | t.pendown() 70 | for i in range(2): # draw retangle 71 | t.forward(900/(agent_number)) 72 | t.right(90) 73 | t.forward(450) 74 | t.right(90) 75 | t.penup() 76 | t.goto(-630 + y, 210) #x y co-ordinates for title 77 | t.pendown() 78 | t.write("Agent " + str(x+1), align="left", font=("Arial", "10", "bold")) 79 | #t.color("white") 80 | t.penup() 81 | sequencer(x,agent_number) # call independent sequencer 82 | driver(x,agent_number) # call independent driver 83 | monitor(x,agent_number) #call independent monitor 84 | def sequencer(x,agent_number): 85 | y = (x) * 700 * (2 / agent_number) #y co-ordinates depends on number of agents 86 | t.goto(-610 + y, 160) 87 | t.pendown() 88 | for i in range(2): # draw retangle 89 | t.forward(800 / (agent_number)) 90 | t.right(90) 91 | t.forward(80) 92 | t.right(90) 93 | t.penup() 94 | t.goto(-610 + y, 170) #x y co-ordinates for title 95 | t.pendown() 96 | t.write("Sequencer " + str(x + 1), align="left", font=("Arial", "10", "bold")) 97 | #t.color("white") 98 | t.penup() 99 | def driver(x,agent_number): 100 | y = (x) * 700 * (2 / agent_number) #y co-ordinates depends on number of agents 101 | t.goto(-610 + y, 20) 102 | t.pendown() 103 | for i in range(2): # draw retangle 104 | t.forward(800 / (agent_number)) 105 | t.right(90) 106 | t.forward(80) 107 | t.right(90) 108 | t.penup() 109 | t.goto(-610 + y, 30) #x y co-ordinates for title 110 | t.pendown() 111 | t.write("Driver " + str(x + 1), align="left", font=("Arial", "10", "bold")) 112 | #t.color("white") 113 | t.penup() 114 | def monitor(x,agent_number): #y co-ordinates depends on number of agents 115 | y = (x) * 700 * (2 / agent_number) 116 | t.goto(-610 + y, -140) 117 | t.pendown() 118 | for i in range(2): # draw retangle 119 | t.forward(800 / (agent_number)) 120 | t.right(90) 121 | t.forward(80) 122 | t.right(90) 123 | t.penup() 124 | t.goto(-610 + y, -130) #x y co-ordinates for title 125 | t.pendown() 126 | t.write("Monitor " + str(x + 1), align="left", font=("Arial", "10", "bold")) 127 | #t.color("white") 128 | t.penup() 129 | def uvm_tb(file_path): 130 | #f = open((path)+str(r"\fifo_pkg.sv"),"r") 131 | #print(file_path) 132 | f = open(file_path, "r") #opens package 133 | if f.mode == "r": 134 | package = f.read() #reads the package file 135 | # print(package) 136 | if(re.search("..env.sv",package)): #searches for env in package 137 | #print("top test env") 138 | top() # calls function to draw top test env and scoreboard. 139 | test() 140 | env() 141 | scoreboard() 142 | if(re.search(".agent.sv",package)): 143 | agent_number =package.count("agent.sv") 144 | #print(agent_number) 145 | for i in range(agent_number): 146 | agent(i,agent_number) 147 | 148 | f.close() 149 | tb_comps() 150 | def dump_gui(): #image capture from canvas. 151 | print('...dumping gui window to png') 152 | x0 = root.winfo_rootx() #image capture size 153 | y0 = root.winfo_rooty() 154 | x1 = x0 + root.winfo_width()*1.27 155 | y1 = y0 + root.winfo_height()*1.2 156 | ImageGrab.grab().crop((x0, y0, x1, y1)).save("gui_image_grabbed.png") #image capture function and image naming 157 | dump_gui() 158 | t.exitonclick() 159 | ######### 160 | -------------------------------------------------------------------------------- /turtle_files/tb_arch.py: -------------------------------------------------------------------------------- 1 | #Refer tb_agent.docx for detailed explanation 2 | import turtle 3 | f=open("tb_info.txt",'r') 4 | content = f.readline() 5 | agent=content.split() 6 | agent_number=agent[2] 7 | f.close() 8 | print(agent_number) 9 | screen = turtle.Screen() 10 | t = turtle.Turtle() 11 | t.speed(30) 12 | def top(): 13 | t.fillcolor("grey") 14 | t.penup() 15 | t.goto(-650,330) 16 | t.pendown() 17 | for i in range(2): 18 | t.begin_fill() 19 | t.forward(1300) 20 | t.right(90) 21 | t.forward(480) 22 | t.right(90) 23 | t.end_fill() 24 | t.penup() 25 | t.goto(-630,310) 26 | t.pendown() 27 | t.write("top",align="center",font=10) 28 | t.hideturtle() 29 | def test(): 30 | t.fillcolor("light blue") 31 | t.penup() 32 | t.goto(-630,300) 33 | t.pendown() 34 | for i in range(2): 35 | t.begin_fill() 36 | t.forward(1260) 37 | t.right(90) 38 | t.forward(420) 39 | t.right(90) 40 | t.end_fill() 41 | t.penup() 42 | t.goto(-600,280) 43 | t.pendown() 44 | t.write("test",align="center",font=10) 45 | #t.hideturtle() 46 | def env(): 47 | t.fillcolor("light green") 48 | t.penup() 49 | t.goto(-600,270) 50 | t.pendown() 51 | for i in range(2): 52 | t.begin_fill() 53 | t.forward(1200) 54 | t.right(90) 55 | t.forward(360) 56 | t.right(90) 57 | t.end_fill() 58 | t.penup() 59 | t.goto(-580,250) 60 | t.pendown() 61 | t.write("env",align="center",font=10) 62 | scoreboard() 63 | for i in range(int(agent_number)): 64 | agent(i) 65 | sequencer(i) 66 | driver(i) 67 | monitor(i) 68 | def scoreboard(): 69 | t.fillcolor("light yellow") 70 | t.penup() 71 | t.goto(-280,240) 72 | t.pendown() 73 | for i in range(2): 74 | t.begin_fill() 75 | t.forward(350) 76 | t.right(90) 77 | t.forward(50) 78 | t.right(90) 79 | t.end_fill() 80 | t.penup() 81 | t.goto(-105,215) 82 | t.pendown() 83 | t.write("Scoreboard",align="center",font=10) 84 | def agent(y): 85 | t.fillcolor("pink") 86 | t.penup() 87 | print(y,int(agent_number)) 88 | x = y * ((1120/int(agent_number)) + 10) 89 | t.goto(-560 + x,160) 90 | t.pendown() 91 | for i in range(2): 92 | t.begin_fill() 93 | t.forward(1120/int(agent_number)) 94 | t.right(90) 95 | t.forward(220) 96 | t.right(90) 97 | t.end_fill() 98 | t.penup() 99 | t.goto(-500 + x,120) 100 | t.pendown() 101 | t.write("Agent"+ str(y+1),align="center",font=10) 102 | def sequencer(y): 103 | t.penup() 104 | print(y,int(agent_number)) 105 | x = y * ((1120/int(agent_number)) + 10) 106 | t.goto(-550 + x,100) 107 | t.pendown() 108 | for i in range(2): 109 | t.forward(260/int(agent_number)) 110 | t.right(90) 111 | t.forward(80) 112 | t.right(90) 113 | t.penup() 114 | t.goto((-550 + 130/int(agent_number))+ x,60) 115 | t.pendown() 116 | t.write("Sequencer",align="center",font=10) 117 | t.penup() 118 | t.goto(-550 + x + (260/int(agent_number)) ,60) 119 | t.pendown() 120 | z = (300/int(agent_number)) + 10 121 | t.goto((-540 + z + x),60) 122 | t.left(45) 123 | t.backward(10) 124 | t.forward(10) 125 | t.right(90) 126 | t.backward(10) 127 | t.forward(10) 128 | t.left(45) 129 | def driver(y): 130 | t.penup() 131 | print(y,int(agent_number)) 132 | x = y * ((1120/int(agent_number)) + 10) 133 | z = (300/int(agent_number)) + 10 134 | t.goto((-540 + z + x),100) 135 | t.pendown() 136 | for i in range(2): 137 | t.forward(300/int(agent_number)) 138 | t.right(90) 139 | t.forward(80) 140 | t.right(90) 141 | t.penup() 142 | t.goto(-540 + z + x + 150/int(agent_number),60) 143 | t.pendown() 144 | t.write("Driver",align="center",font=10) 145 | t.penup() 146 | t.goto(-540 + z + x + 150/int(agent_number),20) 147 | t.pendown() 148 | t.right(90) 149 | t.pendown() 150 | t.forward(200) 151 | t.left(45) 152 | t.backward(10) 153 | t.forward(10) 154 | t.right(90) 155 | t.backward(10) 156 | t.forward(10) 157 | t.left(45) 158 | t.left(90) 159 | def monitor(y): 160 | t.penup() 161 | print(y,int(agent_number)) 162 | x = y * ((1120/int(agent_number)) + 10) 163 | z= 2 * (300/int(agent_number)) + 20 164 | t.goto((-540 + z + x),100) 165 | t.pendown() 166 | for i in range(2): 167 | t.forward(300/int(agent_number)) 168 | t.right(90) 169 | t.forward(80) 170 | t.right(90) 171 | t.penup() 172 | t.goto(-540 + z + x + 150/int(agent_number),60) 173 | t.pendown() 174 | t.write("Monitor",align="center",font=10) 175 | t.penup() 176 | t.goto(-540 + z + x + 150/int(agent_number),20) 177 | t.pendown() 178 | t.right(90) 179 | t.pendown() 180 | t.forward(200) 181 | t.backward(200) 182 | t.left(180) 183 | t.left(45) 184 | t.backward(10) 185 | t.forward(10) 186 | t.right(90) 187 | t.backward(10) 188 | t.forward(10) 189 | t.left(45) 190 | t.right(90) 191 | 192 | top() 193 | test() 194 | env() 195 | -------------------------------------------------------------------------------- /uvm_tb_arch_doc_py.py: -------------------------------------------------------------------------------- 1 | ##################################################### 2 | import PIL, tkinter, cv2 # adding pillow and tkinter for image draw and canvas 3 | import tkinter as Tk # short name for tkinter 4 | from PIL import Image, ImageDraw, ImageFont # image , imagedraw and imagefont from pillow 5 | import os, re # search library 6 | 7 | path = input("enter path of TB directory: ") # user input for path of TB directory 8 | root = tkinter.Tk() # canvas size decider 9 | w = root.winfo_screenwidth() # depending on screen size set width and height 10 | h = root.winfo_screenheight() 11 | root.geometry(f'{w}x{h}') # set new canvas size 12 | print("Width & HEIGHT", w, h) # w and h for user refernce 13 | # create line image of width and height 14 | img = Image.new("RGB", [w, h], "white") 15 | tb = ImageDraw.Draw(img) 16 | lookup = {"keyword": "name"} # lookup table created for uvm component and name 17 | f = open("tree_data.txt", "w") # create file for writing component and component name 18 | f.truncate(0) # clean file before writing data 19 | color_fill = "white" 20 | 21 | 22 | def top(): # drawing top level structure 23 | top_left = (0, 0) # co-ordinate decider 24 | bottom_right = (w, h) # co-ordinate decider 25 | # color_fill = "orange" #color for block 26 | label = "top" # name of default block 27 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 28 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 29 | tb.text((w / 2, 10), label, fill="black", font=font) 30 | # Interface 31 | intfs = int(input("enter the number of interfaces")) 32 | # intfs = 2 33 | for i in range(intfs): 34 | top_left = 100 + (i * (w - 200) / intfs), h - 220 # co-ordinate decider 35 | bottom_right = 100 + ( 36 | (i + 1) * (w - 200) / intfs) - 10, h - 160 # co-ordinate decider '''(i+1)*(w-100)/intfs''' 37 | # color_fill = "green" #color for block 38 | label = "" 39 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 40 | font = ImageFont.truetype("arial.ttf", 20) 41 | # tb.text((w / 2 - 20, h - 250), "Interface", fill="black", font=font) # avoid taking default text coordinates''' 42 | tb.text((100 + (i * (w - 200) / intfs) + 20, h - 200), "Interface " + str(i + 1), fill="black", 43 | font=font) # avoid taking default text coordinates''' 44 | # DUT 45 | top_left = 50, h - 120 # co-ordinate decider 46 | bottom_right = w - 50, h - 20 # co-ordinate decider 47 | # color_fill = "blue" #color for block 48 | label = "" 49 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 50 | font = ImageFont.truetype("arial.ttf", 30) 51 | tb.text((w / 2, h - 100), "DUT", fill="black", font=font) # avoid taking default text coordinates''' 52 | 53 | 54 | def test(name): # drawing test level structure 55 | top_left = (50, 40) # co-ordinate decider 56 | bottom_right = (w - 50, h - 300) # co-ordinate decider 57 | # color_fill = "lightgreen" #color for block 58 | label = name # "test" 59 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 60 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 61 | tb.text((w / 2, 10 + 40), label, fill="black", font=font) 62 | 63 | 64 | def env(name): 65 | top_left = (100, 70) # co-ordinate decider 66 | bottom_right = w - 100, h - 350 # co-ordinate decider 67 | # color_fill = "yellow" #color for block 68 | label = name # "env" 69 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 70 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 71 | tb.text((w / 2, 10 + 70), label, fill="black", font=font) 72 | 73 | 74 | def scoreboard(name): 75 | top_left = 125, 105 # co-ordinate decider 76 | bottom_right = w - 120, (h - 150) / 4.4 # co-ordinate decider 77 | # color_fill = "cyan" #color for block 78 | label = name # "scoreboard" 79 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 80 | font = ImageFont.truetype("arial.ttf", 15) # basic settings for text 81 | tb.text((w / 2, 10 + 105), label, fill="black", font=font) 82 | 83 | 84 | def agent(a, i, name): 85 | if (10 > a > 5): 86 | x = 110 + ((i) * (w - 200) / a) 87 | x1 = x + ((w - 200) / 5) - 200 88 | y = 180 # co-ordinate decider wrt to number of agents 89 | y1 = h - 360 # co-ordinate decider wrt to number of agents 90 | elif (a > 9): 91 | x = 160 + ((i) * (w - 200) / a) # co-ordinate decider wrt to number of agents 92 | x1 = x + ((w - 200) / a) - 100 # co-ordinate decider wrt to number of agents 93 | # y = 180 # co-ordinate decider wrt to number of agents 94 | if ((i + 1) % 2 == 1): 95 | y = 380 96 | y1 = h - 360 # co-ordinate decider wrt to number of agents 97 | else: 98 | y1 = h - 560 # co-ordinate decider wrt to number of agents 99 | y = 180 100 | 101 | else: 102 | x = 200 + ((i) * (w - 200) / a) # co-ordinate decider wrt to number of agents 103 | x1 = x + ((w - 200) / a) - 200 # co-ordinate decider wrt to number of agents 104 | y = 180 # co-ordinate decider wrt to number of agents 105 | y1 = h - 360 # co-ordinate decider wrt to number of agents 106 | 107 | top_left = (int(x), int(y)) # co-ordinate decider 108 | bottom_right = (int(x1), int(y1)) # co-ordinate decider 109 | # color_fill = "coral" #color for block 110 | label = "" 111 | block(top_left, bottom_right, label, color_fill) # call the rectangle creater function 112 | font = ImageFont.truetype("arial.ttf", 15) # text settings 113 | if (a > 5 & a <= 9): # if number of agents are greater than 5 draw sub-components small 114 | label = name # "AGT"+str(i+1) 115 | tb.rectangle([x + (x1 - x) / 2, y + 30, (x1 - 40 / a), int(y1 - 180)], "white", "black", 116 | 5) # default values for all instance 117 | tb.rectangle([x + 40 / a, y + 170, -10 + x + (x1 - x) / 2, int(y1 - 40)], "white", "black", 118 | 5) # default values for all instance 119 | tb.rectangle([x + (x1 - x) / 2, y + 170, x1 - 40 / a, y1 - 40], "white", "black", 5) 120 | tb.text(((x + (x1 - x) / 2) + 40, y + 40), "SQR", fill="black", font=font) # for sequencer 121 | tb.text((x - 40 + 40 / a, y + 180), "DRV", fill="black", font=font) # for driver 122 | tb.text(((x + (x1 - x) / 2) + 40, y + 180), "MON", fill="black", font=font) # for monitor 123 | # connections 124 | 125 | tb.line((((x + 10 + 40 / a), (y1 - 40)), ((x + 10 + 40 / a), h - 218)), "black", 5) # driver to VIF 126 | tb.polygon(((x + 10 + 40 / a - 10, h - 238), (x + 10 + 40 / a + 10, h - 238), (x + 10 + 40 / a, h - 218)), 127 | fill="white", outline="black") # port connection 128 | tb.line((((x + 10 + (x1 - x) / 2), (y1 - 40)), ((x + (x1 - x) / 2 + 10), h - 218)), "black", 129 | 5) # VIF to monitor 130 | tb.polygon(((x + (x1 - x) / 2, y1 - 20), (x + 20 + (x1 - x) / 2, y1 - 20), (x + 10 + (x1 - x) / 2, y1 - 40)), 131 | fill="white", outline="black") # port connection 132 | tb.line((((x1 - 40 / a), (y1 - 100)), ((x1 + 50), y1 - 100)), "black", 5) # monitor to scoreboard 133 | tb.polygon( 134 | (x1 - 40 / a + 20, y1 - 100, x1 - 40 / a + 10, y1 - 90, x1 - 40 / a, y1 - 100, x1 - 40 / a + 10, y1 - 110), 135 | fill="white", outline="black") # analysis connection 136 | tb.line((((x1 + 50), (y1 - 100)), ((x1 + 50), 160)), "black", 5) # monitor to scoreboard 137 | tb.ellipse((x1 + 40, 160, x1 + 60, 180), fill="white", outline="black") # export connection 138 | tb.line((((x + 10 + 40 / a), (y + 100)), (x + 10 + 40 / a, y + 170)), "black", 5) # sequencer to driver 139 | tb.rectangle((x + 10 + 40 / a - 10, y + 170, x + 10 + 40 / a + 10, y + 150), fill="white", 140 | outline="black") # port connection 141 | tb.line((((x + 10 + +40 / a), (y + 100)), (((x + (x1 - x) / 2)), y + 100)), "black", 5) # sequencer to driver 142 | tb.ellipse((x + (x1 - x) / 2 - 20, y + 90, x + (x1 - x) / 2, y + 110), fill="white", 143 | outline="black") # export connection 144 | # agent label 145 | tb.text((x + 10, y + 10), label, fill="black", font=font) 146 | 147 | elif (a > 9): # if number of agents are greater than 10 draw sub-components small 148 | label = name # "AGT"+str(i+1) 149 | mark = x + 10 150 | # port connection 151 | tb.line((((x + (x1 - x) / 2), y1), ((x + (x1 - x) / 2), h - 218)), "black", 5) # Agent to interface 152 | tb.polygon(((x - 10 + (x1 - x) / 2, h - 238), (x + 10 + (x1 - x) / 2, h - 238), (x + (x1 - x) / 2, h - 218)), 153 | fill="white", outline="black") # port connection 154 | tb.polygon(((x - 10 + (x1 - x) / 2, y1 + 20), (x + 10 + (x1 - x) / 2, y1 + 20), (x + (x1 - x) / 2, y1)), 155 | fill="white", outline="black") 156 | tb.line((x1 - 1, y, x1 - 1, 160), "black", 5) # monitor to scoreboard 157 | tb.ellipse((x1 - 10, 160, x1 + 10, 180), fill="white", outline="black") # export connection 158 | # agent label 159 | font = ImageFont.truetype("arial.ttf", 12) # text settings 160 | tb.text((mark - 10, y - 15), "A " + str(i + 1), fill="black", font=font) 161 | img1 = Image.new("RGB", [w, h], "white") 162 | tb1 = ImageDraw.Draw(img1) 163 | font = ImageFont.truetype("arial.ttf", 12) # text settings 164 | tb1.text((w / 2, 50), "AGENT " + str(i + 1), fill="black", font=font) 165 | # sequencer 166 | top_left = 100, 100 167 | bottom_right = 700, 200 168 | tb1.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 169 | tb1.text((110, 110), "sequencer " + str(i + 1), fill="black", font=font) # for sequencer 170 | # driver 171 | top_left = 100, 300 172 | bottom_right = 700, 400 173 | tb1.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 174 | tb1.text((110, 310), "driver " + str(i + 1), fill="black", font=font) # for driver 175 | # monitor 176 | top_left = 800, 300 177 | bottom_right = 1400, 400 178 | tb1.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 179 | tb1.text((910, 310), "monitor " + str(i + 1), fill="black", font=font) # for monitor 180 | img1.show() 181 | path_filename = (r"C:\Python_new\agents" + str( 182 | i + 1) + ".jpg") # create agents folder before running code 183 | print(path_filename) 184 | img1.save(path_filename) 185 | 186 | elif (a <= 5): 187 | label = name # "agent"+str(i+1) 188 | mark = x + 10 189 | block(top_left=(x + (x1 - x) / 2, y + 30), bottom_right=(int(x1 - 40 / a), int(y1 - 180)), label=" ", 190 | color_fill="white") # "grey") #for sequencer 191 | block(top_left=(x + 40 / a, y + 170), bottom_right=(-10 + x + (x1 - x) / 2, y1 - 40), label="", 192 | color_fill="white") # "violet") #for driver 193 | block(top_left=(x + (x1 - x) / 2, y + 170), bottom_right=(int(x1 - 40 / a), int(y1 - 40)), label="", 194 | color_fill="white") # "skyblue") #for monitor 195 | tb.text(((x + (x1 - x) / 2) + 35, y + 40), "sequencer", fill="black", font=font) # for sequencer 196 | tb.text((x - 50 + 40 / a, y + 180), "driver", fill="black", font=font) # for driver 197 | tb.text(((x + (x1 - x) / 2) + 35, y + 180), "monitor", fill="black", font=font) # for monitor 198 | # connections 199 | 200 | tb.line((((x + 10 + 40 / a), (y1 - 40)), ((x + 10 + 40 / a), h - 218)), "black", 5) # driver to VIF 201 | tb.polygon(((x + 10 + 40 / a - 10, h - 238), (x + 10 + 40 / a + 10, h - 238), (x + 10 + 40 / a, h - 218)), 202 | fill="white", outline="black") # port connection 203 | tb.line((((x + 10 + (x1 - x) / 2), (y1 - 40)), ((x + (x1 - x) / 2 + 10), h - 218)), "black", 204 | 5) # VIF to monitor 205 | tb.polygon(((x + (x1 - x) / 2, y1 - 20), (x + 20 + (x1 - x) / 2, y1 - 20), (x + 10 + (x1 - x) / 2, y1 - 40)), 206 | fill="white", outline="black") # port connection 207 | tb.line((((x1 - 40 / a), (y1 - 100)), ((x1 + 50), y1 - 100)), "black", 5) # monitor to scoreboard 208 | tb.polygon( 209 | (x1 - 40 / a + 20, y1 - 100, x1 - 40 / a + 10, y1 - 90, x1 - 40 / a, y1 - 100, x1 - 40 / a + 10, y1 - 110), 210 | fill="white", outline="black") # analysis connection 211 | tb.line((((x1 + 50), (y1 - 100)), ((x1 + 50), 160)), "black", 5) # monitor to scoreboard 212 | tb.ellipse((x1 + 40, 160, x1 + 60, 180), fill="white", outline="black") # export connection 213 | tb.line((((x + 10 + 40 / a), (y + 100)), (x + 10 + 40 / a, y + 170)), "black", 5) # sequencer to driver 214 | tb.rectangle((x + 10 + 40 / a - 10, y + 170, x + 10 + 40 / a + 10, y + 150), fill="white", 215 | outline="black") # port connection 216 | tb.line((((x + 10 + +40 / a), (y + 100)), (((x + (x1 - x) / 2)), y + 100)), "black", 5) # sequencer to driver 217 | tb.ellipse((x + (x1 - x) / 2 - 20, y + 90, x + (x1 - x) / 2, y + 110), fill="white", 218 | outline="black") # export connection 219 | # agent label 220 | tb.text((mark, y + 10), label, fill="black", font=font) 221 | 222 | 223 | def block(top_left, bottom_right, label, color_fill): # draw rectangle block, fill color and label 224 | tb.rectangle([top_left, bottom_right], color_fill, "black", 5) # default values for all instance 225 | 226 | 227 | def component_search(keyword): # to search for keyword in all files of directory 228 | root_dir = path 229 | for root, dirs, files in os.walk(root_dir, onerror=None): # to loop inside all files of directory 230 | for filename in files: 231 | file_path = os.path.join(root, filename) 232 | with open(file_path, "rb") as f: # read file as binary 233 | for line in f: 234 | line = line.decode("ISO-8859-1 ") # decode to string for read 235 | if keyword in line: # keyword determines the word to be looked into in each of the file 236 | # print(filename) 237 | # print(file_path) # print the file path 238 | # print(line) 239 | if (keyword == "interface"): # to avoid psedo interface name error 240 | # print("yes interface") 241 | text = line.split() 242 | if len(text) != 2: 243 | # print("not match") 244 | break 245 | else: 246 | component_name_finder(keyword, line) 247 | else: 248 | component_name_finder(keyword, line) 249 | break 250 | 251 | 252 | def tb_comps(): # generic word in tb components that can be searched to determine presence of comp in TB 253 | #component_search("topology") 254 | component_search("uvm_test_top") 255 | component_search(" env") 256 | component_search("AS_AXI_Agent_") 257 | component_search("magna_scoreboard") 258 | #component_search("uvm_test_top") 259 | #component_search("uvm_env") 260 | #component_search("uvm_scoreboard") 261 | #component_search("uvm_agent") 262 | #component_search("uvm_driver") 263 | #component_search("uvm_monitor") 264 | #component_search("uvm_sequencer") 265 | #component_search("uvm_sequence ") 266 | #component_search("uvm_sequence_item") 267 | #component_search("interface") 268 | 269 | 270 | for key, value in lookup.items(): # saving component names into lookup table 271 | print(key, ' : ', value) 272 | 273 | 274 | def component_name_finder(keyword, line): 275 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 276 | text = line.split() # split line where text found 277 | name = text[1] # get name from split line 278 | if keyword + "_1" in lookup: # if keyword already exists in lookup 279 | for i in range(10): # take next count of lookup 280 | key = keyword + "_" + str(i + 2) 281 | # print (key) 282 | lookup[key] = name 283 | f.write(keyword + "_" + str(i + 2) + "\t\t\t\t" + name + "\n") 284 | break 285 | else: # keyword not in lookup: #if keyword does not exist in lookup 286 | if (keyword == "AS_AXI_Agent"): # make it first instance of agent 287 | key = keyword + "_1" 288 | lookup[key] = name 289 | f.write(keyword + "_1" + "\t\t\t\t" + name + "\n") 290 | else: 291 | lookup[keyword] = name # add name to lookup table 292 | f.write(keyword + "\t\t\t\t" + name + "\n") 293 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 294 | f.close() 295 | 296 | 297 | def read_file_draw(): 298 | f = open("tree_data.txt", "r") # read file written with names 299 | file = f.read() 300 | # print (file) 301 | if (re.search("uvm_test_top", file)): # find keyword in file 302 | top() # draw top 303 | test(lookup['uvm_test_top']) # draw test with found name 304 | env(lookup[' env']) # draw env with found name 305 | scoreboard(lookup['magna_scoreboard']) # draw scb with found name 306 | a = file.count("AS_AXI_Agent_") # find number of agents 307 | a= int(input ("number of Agents:")) 308 | '''#a = 6 #uncomment and add values for agents explicitly 309 | print("number of agents : " + str(a)) # print number of agents 310 | for i in range(a): 311 | agent(a,i,"uvm_agent_"+str(i+1)) # draw agent with agent names''' 312 | print("number of agents : " + str(a)) # print number of agents 313 | for i in range(a): 314 | #agent(a, i, lookup["uvm_agent_" + str(i + 1)]) # draw agent with agent names 315 | agent(a,i,"AS_AXI_Agent_"+str(i+1)) # draw agent with agent names''' 316 | f.close() 317 | 318 | 319 | tb_comps() # to search for component name 320 | read_file_draw() # read file 321 | 322 | 323 | def connection_finder(keyword=".connect("): # to search for keyword in all files of directory 324 | root_dir = path 325 | for root, dirs, files in os.walk(root_dir, onerror=None, topdown=True): # to loop inside all files of directory 326 | for filename in files: 327 | file_path = os.path.join(root, filename) 328 | with open(file_path, "rb") as f: # read file as binary 329 | for line in f: 330 | line = line.decode("ISO-8859-1") # decode to string for read 331 | if keyword in line: # keyword determines the word to be looked into in each of the file 332 | # print (keyword,line) 333 | text = line 334 | if (re.search("_port", text)): 335 | if (re.search("export", text)): 336 | print("drawing port and export") 337 | print(line) 338 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 339 | f.write(str(line) + "\n") 340 | f.write("drawing port and export") 341 | f.close() 342 | else: 343 | print("drawing port") 344 | print(line) 345 | f = open("tree_data.txt", "a+") # add found name to file : open write and close 346 | f.write(line + "\n") 347 | f.write("drawing port" + "\n") 348 | f.close() 349 | 350 | 351 | connection_finder() 352 | # block(top_left,bottom_right,color_fill) 353 | 354 | # img.show() #show image before save 355 | img.save(r"C:\Users\Priya A\PycharmProjects\UVM_ARCH_TB\log\tb_arch.jpg") 356 | image = cv2.imread(r"C:\Users\Priya A\PycharmProjects\UVM_ARCH_TB\log\tb_arch.jpg") 357 | intfs = int(input("enter the number of interfaces")) 358 | v = 0.1; 359 | for i in range(intfs): 360 | print("value of v", v) 361 | g = w * v; 362 | image = cv2.arrowedLine(image, (int(g), h - 160), (int(g), h - 120), (000), 2) 363 | v = v + (1/(intfs * 1.2)); 364 | print("value of v1", v) 365 | cv2.imshow('abc', image) 366 | cv2.imwrite(r"C:\Users\Priya A\PycharmProjects\UVM_ARCH_TB\log\tb_arch.jpg", image) 367 | cv2.waitKey(0) 368 | cv2.destroyAllWindows() 369 | 370 | ############################################################################### 371 | -------------------------------------------------------------------------------- /uvm_tb_arch_doc_py_diagram.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muneeb-mbytes/uvm_tb_arch_doc_py/a32618aae4bb57e51211c6a1a2e59fa63140f2ac/uvm_tb_arch_doc_py_diagram.pdf --------------------------------------------------------------------------------