美文网首页
二分法帮助定位

二分法帮助定位

作者: Poisson_Lee | 来源:发表于2019-11-05 23:37 被阅读0次

二分法找到第一个出错的地方

#!/usr/bin/python3

import sys
import os
import re

'''
Usage example
./auto_exe.py xys_alu_opy_imm:2459270413 '-sim_opts "+num=2000"'

'''

cmd_prefix = "tools/dv_run -t"
if(len(sys.argv)!=3):
  raise("pass-in parameter error!")
tc_seed = sys.argv[1]
sim_opts = sys.argv[2]
cmd_suffix = "|tee log"

num_match = re.findall('num=(\d+)', sim_opts)
num_str = num_match[0]

def run_num(num):
  global sim_opts
  num_match = re.findall('num=(\d+)', sim_opts)
  num_str = num_match[0]
  sim_opts = sim_opts.replace("num="+num_str, "num="+str(num))
  cmd_suffix = "|tee "+str(num)+"_log"
  cmd_seg = [cmd_prefix, tc_seed, sim_opts, cmd_suffix]
  exe_cmd = " ".join(cmd_seg)
  print("exe cmd is \n%s"%(exe_cmd))
  os.system("%s > /dev/null" %(exe_cmd))
  print("exe %d test done!"%num)
  return check_log(num)

def check_log(num):
  marker = True
  log_name = "./"+str(num)+"_log"
  with open(log_name, 'r') as rpt:
    rpt_str = rpt.read()
    if re.search('TEST FAILED', rpt_str):
      marker = False
    elif re.search('TEST PASSED', rpt_str):
      marker = True
    else:
      raise("log has no TEST FAILED/PASSED output marker!")
    return marker

if(run_num(2000)):
  print("This TC pass!")
elif(not run_num(1)):
  print("One ins can not pass!")
else:
  print("Begin to find the last error ins!")
  min_num = 1;
  max_num = 2000;
  while((max_num-min_num)>1):
    new_num = (min_num + max_num)//2
    if(run_num(new_num)):
      min_num = new_num
    else:
      max_num = new_num
  print(min_num, max_num)

相关文章

网友评论

      本文标题:二分法帮助定位

      本文链接:https://www.haomeiwen.com/subject/vsrybctx.html