回归脚本代码(后续分析)

    技术2022-07-10  138

    回归脚本简要处理思路请参考:https://blog.csdn.net/weixin_39662684/article/details/107056147 #!/usr/bin/python 2 # -- coding: UTF-8 -- 3 import os 4 import re 5 import sys 6 import random 7 import shutil 8 import time 9 import threading 10 import queue 11 12 local_date = time.strftime("%Y%m%d%H%M",time.localtime()) 13 14 if(len(sys.argv) > 1): 15 rgs_mode = sys.argv[1] 16 else: 17 rgs_mode = “regress_mode” + “" + local_date 18 19 #this is for clean the regress dir 20 if(os.path.exists(rgs_mode)): 21 if(os.path.isfile(rgs_mode)): 22 print("{} is a file".format(rgs_mode)) 23 else: 24 #os.rmdir(rgs_mode) 25 shutil.rmtree(rgs_mode) 26 27 #first we make compile then we use make batch_run 28 29 val = os.system(“make compile mode={}”.format(rgs_mode)) 30 print(val) 31 32 #then we use make batch_run to regression 33 34 cmd = “make batch_run” 35 36 regress_list = [ 37 #maybe need adding tc_dir 38 “tc=vlan_base_test cfg=pkt_len_64B_dt_imat_omis_rand mode={} run_times=5”.format(rgs_mode), 39 “tc=vlan_base_test cfg=pkt_len_64B_dt_imis_omat_rand mode={} run_times=5”.format(rgs_mode), 59 “tc=vlan_base_test cfg=pkt_len_64B_ut_vt_dis_omat_add mode={} run_times=1”.format(rgs_mode) 60 ] 61 62 fo_reg = open("regress_cmd_info{}.log”.format(local_date),“w”) 63 max_queue_num = 6 64 cmp_queue_num = (max_queue_num - 4) 65 thread_q = queue.Queue(max_queue_num) 66 mylock = threading.Lock() 67 store_log = [] 68 store_cmd = [] 69 ###put_thread 70 class put_thread(threading.Thread): 71 def init(self,threadname,threadID,cmd,run_thd,run_name,run_id,log_name): 72 threading.Thread.init(self) 73 self.threadname = threadname 74 self.threadID = threadID 75 self.cmd = cmd 76 self.run_thd = run_thd 77 self.run_name = run_name 78 self.run_id = run_id 79 self.log_name = log_name 80 def run(self): 81 while(1): 82 mylock.acquire() 83 #if(not thread_q.full()): 84 if(thread_q.qsize() < cmp_queue_num): 85 thd_info = self.run_thd(self.run_name,self.run_id,self.cmd) 86 print(“put_thread info:{}”.format(self.cmd)) 87 fo_reg.write(“before put_thread info:{} {} thread.q.size is {}\n”.format(self.cmd,time.ctime(time.time()),thread_q.qsize())) 88 thd_info.start() 89 #thd_info.join() 90 fo_reg.write(“after put_thread info:{} {} thread.q.size is {}\n”.format(self.cmd,time.ctime(time.time()),thread_q.qsize())) 91 thread_q.put(thd_info) 92 store_log.append(self.log_name) 93 store_cmd.append(self.cmd) 94 time.sleep(1) 95 mylock.release() 96 break 97 mylock.release() 98 time.sleep(15) 99 100 101 ###first we need to create thread to run command 102 class run_thread(threading.Thread): 103 def init(self,threadname,threadID,cmd): 104 threading.Thread.init(self) 105 self.threadname = threadname 106 self.threadID = threadID 107 self.cmd = cmd 108 109 def run(self): 110 val = os.system(self.cmd) 111 print(val) 113 class get_thread(threading.Thread): 114 def init(self,threadname,threadID,timeout_cnt): 115 threading.Thread.init(self) 116 self.threadname = threadname 117 self.threadID = threadID 118 self.timeout_cnt = timeout_cnt 119 120 def run(self): 121 time_cnt = 0 122 while(1): 123 mylock.acquire() 124 act_thd = [] 125 if(not thread_q.empty()): 126 fo_reg.write(“enter not empty\n”) 127 time_cnt = 0 128 while(1): 129 time.sleep(0.1) 130 get_thd = thread_q.get() 131 if(get_thd.isAlive()): 132 act_thd.append(get_thd) 133 fo_reg.write("{} is still run {}\n".format(get_thd.getName(),time.ctime(time.time()))) 134 else: 135 fo_reg.write("{} has done {}\n".format(get_thd.getName(),time.ctime(time.time()))) 136 137 if(thread_q.empty()): 138 fo_reg.write("{} is empty {}\n".format(get_thd.getName(),time.ctime(time.time()))) 139 break 140 141 #this is for thd is still run back into the thread_q 142 fo_reg.write(“still alive thread_num is {}\n”.format(len(act_thd))) 143 for index in range(len(act_thd)): 144 #thread_q.put(act_thd[index]) 145 while(1): 146 if(not thread_q.full()): 147 thread_q.put(act_thd[index]) 148 time.sleep(0.5) 149 break 150 time.sleep(1) 151 mylock.release() 152 153 time.sleep(30) 154 time_cnt = (time_cnt + 1) 155 if(time_cnt >= self.timeout_cnt): 156 break 158 fo_reg.write(“start to put thd {}\n”.format(time.ctime(time.time()))) 159 put_thd = [] 160 total_index = 0 161 162 #this is for count the tc_num no matter run_times is 1 or more 163 run_tc_num = 0 164 165 for i in range(len(regress_list)): 166 #first get info of regress_list 167 match_list = re.search(r".*tc=(\w+)\s+cfg=(\w+)\s+mode=(\w+)\s+run_times=(\w+)",regress_list[i]) 168 if(match_list): 169 tc_info = “tc={} cfg={} mode={}”.format(match_list.group(1),match_list.group(2),match_list.group(3)) 170 run_tc_num = (run_tc_num + 1) 171 else: 172 print(“match fail”) 173 fo_reg.write(“match_list fail: {}\n”.format(regress_list[i])) 174 continue 175 176 for tc_index in range(int(match_list.group(4))): 177 tmp_seed = “” 178 for j in range(8): 179 tmp_seed = (tmp_seed + str(random.randint(0,9))) 180 seed = int(tmp_seed) 181 182 log_name = “{}{}{}.log”.format(match_list.group(1),match_list.group(2),seed) 183 184 cmd_info = “{} seed={} {}”.format(cmd,seed,tc_info) 185 fo_reg.write("{}\n".format(cmd_info)) 186 print(cmd_info) 187 put_thd.append(put_thread(“put_thd_{}”.format(total_index),total_index,cmd_info,run_thread,“run_thd_{}”.format(total_index),total_index,log_name)) 188 total_index = (total_index + 1) 189 190 for list in range(len(put_thd)): 191 put_thd[list].start() 192 193 print(“start to get thd”) 194 fo_reg.write(“start to get thd\n”) 195 local_get_thd = get_thread(“get_thd”,“get_thd1”,2) 196 local_get_thd.start() 197 local_get_thd.join() 198 print(“regression has done at {}\n”.format(time.ctime(time.time()))) 199 fo_reg.write(“regression has done at {}\n”.format(time.ctime(time.time()))) 200 fo_reg.close() 201 202 #regress_status.log is for summary info 203 #test_status 0:pass;1:fail;2:not complete 204 test_num = [0,0,0] 205 regress_info = [] 206 for i in range(len(store_log)): 207 log_name = store_log[i] 208 if(os.path.isfile("{}/log/{}".format(rgs_mode,log_name))): 209 #fo = open("{}/log/{}".format(rgs_mode,log_name),“r”) 210 with open("{}/log/{}".format(rgs_mode,log_name),“r”) as fo: 211 match_en = 0

    212 test_status = 0 213 for line in fo.readlines(): 214 #here is for assert check 215 match_log = re.search(r"\s+Offending",line,re.M|re.I) 216 if(match_log): 217 test_status = 1 218 219 ##this is for fail or fatal 220 #match_log = re.search(r".*UVM.*Report.Summary",line,re.M|re.I) 221 match_log = re.search(r"UVM Report Summary",line,re.M|re.I) 222 if(match_log): 223 match_en = 1 224 225 if(match_en == 1): 226 match_log = re.search(r"^UVM_ERROR|UVM_FATAL",line,re.M|re.I) 227 sp_data = line.split( ) 228 if(match_log): 229 if(int(sp_data[2]) > 0): 230 test_status = 1 231 232 #this is for not match 233 if(match_en == 0): 234 test_status = 1 235 236 #fo.close() 237 else: 238 test_status = 2 239 240 if(test_status == 0): 241 test_num[0] = (test_num[0] + 1) 242 regress_info.append("{}\n./{}/log/{} {:>15}\n".format(store_cmd[i],rgs_mode,log_name,“pass”)) 243 elif(test_status == 1): 244 test_num[1] = (test_num[1] + 1) 245 regress_info.append("{}\n./{}/log/{} {:>15}\n".format(store_cmd[i],rgs_mode,log_name,“fail”)) 246 elif(test_status == 2): 247 test_num[2] = (test_num[2] + 1) 248 regress_info.append("{}\n./{}/log/{} {:>15}\n".format(store_cmd[i],rgs_mode,log_name,“not_complete”)) 249 250 total_num = (test_num[0] + test_num[1] + test_num[2]) 251 pass_rate = “{:0.2%}”.format(float(test_num[0]/total_num)) 252 253 regress_info.insert(0,"{:>15}: {:>20}\n{:>15}: {:>20}\n{:>15}: {:>20}\n{:>15}: {:>20}\n{:>15}: {:>20}\n".format(“total_num”,total_num,“pass”,test_num[0],“fail”,test_num[1],“not_complete”,test_num[2],“pass_rate”,p ass_rate)) 254 regress_info.insert(0,"{:>15}: {:>20}\n{:>15}: {:>20}\n".format(“total_tc”,len(regress_list),“run_tc_num”,run_tc_num)) 255 regress_info.insert(0,"{}\n{:>25}\n{}\n".format("“50,“summary report”,"”*50)) 256 print(“summary has start at {}\n”.format(time.ctime(time.time()))) 257 #fw = open(“regress_status_{}.log”.format(local_date),“w”) 258 with open(“regress_status_{}.log”.format(local_date),“w”) as fw: 259 for i in range(len(regress_info)): 260 fw.write(regress_info[i]) 261 262 #fw.close() 263 print(“summary has done at {}\n”.format(time.ctime(time.time()))) 264 265 os.system(“vi regress_status_{}.log”.format(local_date))

    Processed: 0.010, SQL: 9