-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer_script.py
202 lines (177 loc) · 8.43 KB
/
timer_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# Company: MICRO-ELECTRONICS RESEARCH LABORATORY //
# //
# Engineers: Auringzaib Sabir - Verification Engineer //
# //
# Additional contributions by: //
# //
# Create Date: 16-JAN-2022 //
# Design Name: Verification IP of timer //
# Module Name: script.py //
# Project Name: Verification of different peripheral devices //
# Language: Python //
# //
# Description: //
# This python script is used to automate the running of constraint random tests for the //
# timer(DUT) by timer's verification IP. This is used in run_test.py for running different number //
# of constraint random test by timer's VIP. //
# //
# How to run? //
# //
# Excecute the following command //
# >> python run_test.py 100 //
# Here 100 means 100 contraint random tests will be generated by the timer's VIP //
# NOTE: All test are running on a random seed value //
# //
# Log of each random test that is run with a random seed is stored in a output directory (default //
# output directory is out) //
# NOTE: All test results are dumped in test_results.txt //
# //
# Revision Date: //
# //
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# for x in range(5):
# print(os.environ.get("SEED"))
# print(os.environ.get("OUT"))
# print(os.environ.get("OUT-SEED"))
# print(os.environ.get("GEN_OPTS"))
# importing os module
import os
import shutil
import random
import sys
# Setting relative path (__file__)
ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), ""))
OUT = "out"
print("ROOT_DIR =", ROOT_DIR)
def make_directory(make_dir):
# Parent Directory path
parent_dir = ROOT_DIR
# Directory to create
directory = make_dir
# Create the directory
if make_dir == OUT:
# Complete of directory to be created
path = os.path.join(parent_dir, directory)
print("path of output directory =", path)
# Check if directory already exist
is_dir = os.path.isdir(path)
print(is_dir)
if is_dir == False:
print("Directory for output '% s' created" % directory)
os.mkdir(path)
else:
print("Directory for output '% s' already exist" % directory)
else:
# Complete of directory to be created
# path = parent_dir + "/out/" + directory
path = os.path.join(parent_dir, directory)
print("path=", path)
# Check if directory already exist
is_dir = os.path.isdir(path)
print(is_dir)
if is_dir == False:
print("Directory for Seed '% s' created" % directory)
os.makedirs(path)
else:
print("Directory for Seed '% s' already exist" % directory)
shutil.rmtree(path)
def run_test(randon_number):
# cmd = (
# "xrun -clean -sv -uvm -access rwc -linedebug -f ./compile_file/run.f -svseed "
# + os.environ.get("SEED")
# + " +UVM_TESTNAME=tx_test +UVM_VERBOSITY=UVM_LOW +define+UVM_REPORT_DISABLE_FILE_LINE +uvm_set_config_int=uvm_test_top,base_address,23 +UVM_CONFIG_DB_TRACE +UVM_OBJECTION_TRACE"
# )
cmd = (
"xrun -clean -sv -uvm -access rwc -linedebug -f ./compile_file/run.f -svseed "
+ str(randon_number)
+ " +UVM_TESTNAME=tx_test +UVM_VERBOSITY=UVM_LOW +define+UVM_REPORT_DISABLE_FILE_LINE +uvm_set_config_int=uvm_test_top,base_address,23 +UVM_CONFIG_DB_TRACE +UVM_OBJECTION_TRACE"
)
print("Command to run = ", cmd)
os.system(cmd)
def random_num():
# using sys.maxsize
long_int = sys.maxsize + 1
# The data type is represented as int
print("maxint + 1 :" + str(long_int) + " - " + str(type(long_int)))
# Generating a random number within a min and max range
rand = random.randint(1, 99999)
return rand
def run_make():
cmd = "make run_py"
print("Command to run = ", cmd)
os.system(cmd)
def find_latest_dir():
import os
import time
import operator
import shutil
alist = {}
now = time.time()
path = ROOT_DIR + "/" + OUT
print("path=", path)
directory = os.path.join("/home", path)
os.chdir(directory)
for file in os.listdir("."):
if os.path.isdir(file):
timestamp = os.path.getmtime(file)
# get timestamp and directory name and store to dictionary
alist[os.path.join(os.getcwd(), file)] = timestamp
# sort the timestamp
for i in sorted(alist.items(), key=operator.itemgetter(1)):
latest = "%s" % (i[0])
# latest=sorted(alist.iteritems(), key=operator.itemgetter(1))[-1]
print("newest directory is ", latest)
return latest
def copy_files(src_dir, dst_dir, copy_file):
# os.chdir(latest)
# For copying the all_args_rand_test.yaml in the latest out/seed directory made for specific test
src_file_path = src_dir + "/" + copy_file
dst_file_path = dst_dir + "/" + copy_file
print("src_file_path = ", src_file_path)
print("dst_file_path = ", dst_file_path)
shutil.copy(src_file_path, dst_file_path)
print("Copied file")
def find_string(string_to_find, in_file):
# opening a text file
file = open(in_file, "r")
# read file content
readfile = file.read()
# checking condition for string found or not
if string_to_find in readfile:
print("String", string_to_find, "Found In File")
return 1
else:
print("String", string_to_find, "Not Found")
return 0
# closing a file
file.close()
def main():
# make_directory(os.environ.get("OUT"))
# make_directory(os.environ.get("OUT-SEED"))
# Generating random seed
seed = random_num()
# Printing seed
print("Random seed = ", seed)
# Running test on random seed
run_test(seed)
# Creating output directory
make_directory(OUT)
# Creating directory for a running seed in output directory
dir_seed = OUT + "/seed-" + str(seed)
make_directory(dir_seed)
# Finding a latest directory in output directory
latest_dir = find_latest_dir()
# Copy log file in seed direcory
src_dir = ROOT_DIR
dst_dir = latest_dir
copy_file = "xrun.log"
print("src_dir=", src_dir)
print("dst_dir=", dst_dir)
print("copy_file=", copy_file)
copy_files(src_dir, dst_dir, copy_file)
# Find weather test pass or not by checking TEST PASSED IN xrun.log
test_passed = find_string("[TEST PASSED]", dst_dir + "/" + "xrun.log")
print("TEST PASSED = ", test_passed)
if __name__ == "__main__":
main()