使用excel 储存要进行回归的case 以及case 描述 回归结果
安装python3 + openpyxl后
基本步骤:
1. 指定好相关文件的路径
2. 指定回归时覆盖率的收集类型
3. 指定随机数
4. 指定随机次数
5. 运行每个case
6. 读取sim的log 在log中查找有无 TEST PASS 字符 。有就在excel中标绿,没有就在log中查找有无TEST FAIL 有就标红,没有就标黄。
7. 将标红或标黄时的log文件复制到另一处 ,并将文件名改为case_time_seed 的形式,即记录了case名称又记录了回归时的随机数和时间。
注意事项
本代码仅起到思路启发作用,实际应用需要考虑更多,比如,标黄之后不能标绿以提示某个回归没有跑成功,红黄都有该如何取舍等。
完整代码
import os
import openpyxl
import time
import random
from openpyxl.styles import PatternFill
simv = "/home/ubuntu/Desktop/work/10GE_MAC/uvm/sim/simv " # simv file location
COV = "-cm line+cond+fsm+tgl+branch+assert " # coverage
cm_name_cmd = "-cm_name "
cm_dir = "-cm_dir ./cov.vdb "
log_dir = "./log/"
seed_cmd = "+seed="
red_fill = PatternFill("solid", fgColor='FF0000')
green_fill = PatternFill("solid", fgColor='00FF00')
yellow_fill = PatternFill("solid", fgColor='FFFF00')
start_t = time.localtime() # start time
for i in range(1,100):
t = time.localtime() # tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec
timestamp = str(t.tm_year)+"_"+str(t.tm_mon)+"_"+str(t.tm_mday)+"_"+str(t.tm_hour)+"_"+str(t.tm_min)+"_"+str(t.tm_sec)
wb = openpyxl.load_workbook("test_case.xlsx")
sheet = wb.active
# print(sheet.dimensions) # 获取表格的尺寸大小
row_num = sheet.max_row # 行
line_num = sheet.max_column # 列
test_case_name = 'A' # test case line
result = 'C' # result line
# rand_num = random.randint(-2147483648, 2147483647)
# print(rand_num)
# loop for all case
for test in range(2,row_num+1):
# generate rand seed
rand_num = random.randint(-2147483648, 2147483647)
seed = seed_cmd + str(rand_num)+" "
# get test_case
test_case = sheet[test_case_name+str(test)].value
test_name = "+UVM_TESTNAME="+test_case+" "
# log file name
log_file = test_case+'_'+timestamp + str(rand_num)
log_name = "-l "+log_dir+ log_file + " "
# coverage vdb name
cm_name = cm_name_cmd + test_case + timestamp + " "
# print to termi and run
os.system(simv + test_name + log_name + COV + cm_name + seed)
# use with avoid resources overflows
# just store err log file
with open(log_dir+log_file,"r") as f_obj:
if (f_obj.read().find("TEST PASS")):
sheet[result+str(test)].fill = green_fill
pass_flag = 1
print("test pass")
elif(f_obj.read().find("TEST FAIL")):
sheet[result+str(test)].fill = red_fill
pass_flag = 0
else:
sheet[result+str(test)].fill = yellow_fill
print("NO INDICATE WORDS")
pass_flag = 0
wb.save("test_case.xlsx")
print("pass_flag = %d",pass_flag)
# remove pass log file
if (pass_flag):
os.remove(log_dir+log_file)
print("repeat times "+ str(i))