寄存器自动化测试说明及时使用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

432 lines
11 KiB

  1. import os,sys,time
  2. import cli
  3. from conf import *
  4. from skyeye_common_module import *
  5. import se_system as ss
  6. import threading
  7. from fuzzywuzzy import fuzz
  8. import fault_inject as fi
  9. import se_func as sf
  10. import skyeye_autotest_command as sac
  11. import pytimer
  12. import skyeye_common_module as scm
  13. MO_READ = 1
  14. MO_WRITE = 2
  15. OP_CHAR_TYPE = 1
  16. OP_SHORT_TYPE = 2
  17. OP_WORD_TYPE = 4
  18. OP_DWORD_TYPE = 8
  19. TY_INT = "int"
  20. TY_FLOAT = "float"
  21. TY_DOUBLE = "double"
  22. def SE_define_conf(filename):
  23. try:
  24. Config = json_conf(parent = None, filename = filename)
  25. if Config.get_init_result() == False:
  26. print ("load_config error")
  27. return False
  28. Config.instance()
  29. SetGlobalConfig(Config)
  30. define_json_file[0] = os.path.join(os.getcwd(), filename)
  31. except:
  32. print ("load_config error")
  33. return False
  34. def SE_load_binary(cpuname,filename):
  35. if os.path.isfile(filename)==False:
  36. print ("No such binary file")
  37. return False
  38. if SkyEyeLoadBinary(cpuname,filename)!=1:
  39. print ("load_binary error")
  40. return False
  41. binary_l[cpuname] = os.path.join(os.getcwd(), filename)
  42. def SE_init_ok():
  43. SkyEyePrepareToRun()
  44. if ss.system ==None:
  45. ss.CreateClass()
  46. def SE_run_script(filename):
  47. fullfilename = os.path.realpath(filename)
  48. if not os.path.exists(fullfilename):
  49. print ("%s file does not exists!" % fullfilename)
  50. return False
  51. fp = open(fullfilename,'r')
  52. lines = fp.readlines()
  53. fp.close()
  54. cmd = cli.GetCommand("run-command")
  55. if cmd == None:
  56. SE_print("Can not find command: run-command")
  57. return False
  58. for line in lines:
  59. line = line.strip(' \n')
  60. if line == "" or line[0] == '#' or "run-pyfile" in line:
  61. continue
  62. try:
  63. ret=cmd.run(line)
  64. except Exception as e:
  65. SE_print(e)
  66. return False
  67. return True
  68. def SE_run():
  69. SkyEyeRun()
  70. def SE_stop():
  71. SkyEyeStop()
  72. def SE_stop_autotest():
  73. if sac.ac != None:
  74. sac.ac.autotest_run = False
  75. def SE_reset():
  76. SkyEyeReset()
  77. def SE_restart():
  78. SE_reset()
  79. SE_define_conf(define_json_file[0])
  80. for binary in binary_l.keys():
  81. SE_load_binary(binary,os.path.normpath(binary_l[binary]))
  82. SE_init_ok()
  83. def SE_running_status():
  84. return SkyEyeRunningStatus()
  85. def SE_pre_conf_obj(classname, objname):
  86. SkyEyePreConfObj(objname,classname)
  87. obj = ss.SkyEyeBaseClass(objname,classname,None)
  88. return obj
  89. def SE_sleep(s):
  90. time.sleep(s)
  91. log=None
  92. def SE_print(data):
  93. global log
  94. if log == None:
  95. return
  96. r_obj=ss.__redirection__()
  97. r_obj.set_out()
  98. print (data)
  99. r_obj.reset()
  100. log.WriteText(r_obj.buff)
  101. def SE_compare(actual_out,expect_out,accuracy):
  102. sj_output=actual_out
  103. try:
  104. fp1=open(sj_output,'r')
  105. except:
  106. SE_print('The actual output file was not found')
  107. return
  108. actual=fp1.read()
  109. fp1.close()
  110. rmlist=['\t','\r',' ','\n']
  111. for i in rmlist:
  112. actual=actual.replace(i,'')
  113. expect_out=expect_out.replace(i,'')
  114. if len(actual)==0:
  115. SE_print('The actual output file is empty')
  116. return
  117. if len(expect_out)==0:
  118. SE_print('The desired output is empty')
  119. return
  120. accuracy_list=[]
  121. accuracy_list.append(fuzz.ratio(actual,expect_out))
  122. accuracy_list.append(fuzz.partial_ratio(actual,expect_out))
  123. if accuracy!=100:
  124. accuracy_list.append(fuzz.token_set_ratio(actual,expect_out))
  125. max_accuracy = max(accuracy_list)
  126. if max_accuracy >= accuracy:
  127. SE_print("Proofreading success")
  128. return True
  129. else:
  130. SE_print('Check failure. expect accuracy: %d%% max actual accuracy: %d%%'%(accuracy,max_accuracy))
  131. return False
  132. def SE_set_fault_inject(machname,addr,bit,mode):
  133. return fi.skyeye_set_fj_by_aadr(machname,addr,bit,mode)
  134. def SE_get_fault_inject():
  135. return fi.skyeye_get_fj()
  136. def SE_clear_fault_injece(machname,addr,bit,mode):
  137. return fi.skyeye_clear_fj_by_addr(machname,addr,bit,mode)
  138. def SE_set_register_value(machname,addr,value):
  139. return sf.set_reg_value_by_addr(machname,addr,value)
  140. def SE_get_register_value(machname,addr):
  141. return sf.get_reg_value_by_addr(machname,addr)
  142. def SE_get_simulation_time(cpuname):
  143. return SkyEyeGetSimulationRunTime(cpuname)
  144. def SE_enable_parse_symbol(cpuname,binary):
  145. cmd = cli.GetCommand("parse-symbol")
  146. if cmd == None:
  147. SE_print("Can not find command: parse-symbol")
  148. return False
  149. try:
  150. ret=cmd.run([cpuname,binary])
  151. except Exception as e:
  152. SE_print(e)
  153. return False
  154. return ret
  155. def SE_get_global_variable_addr(cpuname,varname):
  156. return SkyEyeGetSymbolAddr(cpuname,varname)
  157. def SE_get_global_variable_value(cpuname,varname,value_bytes_number,value_type):
  158. if value_type == TY_INT:
  159. return SkyEyeGetSymbolValue(cpuname,varname,value_bytes_number)
  160. elif value_type == TY_FLOAT:
  161. return SkyEyeGetFloatSymbolValue(cpuname,varname,value_bytes_number)
  162. elif value_type == TY_DOUBLE:
  163. return SkyEyeGetDoubleSymbolValue(cpuname,varname,value_bytes_number)
  164. else:
  165. pass
  166. def SE_set_global_variable_value(cpuname,varname,value,value_bytes_number,value_type):
  167. if value_type == TY_INT:
  168. return SkyEyeSetSymbolValue(cpuname,varname,value,value_bytes_number)
  169. elif value_type == TY_FLOAT:
  170. return SkyEyeSetFloatSymbolValue(cpuname,varname,value,value_bytes_number)
  171. elif value_type == TY_DOUBLE:
  172. return SkyEyeSetDoubleSymbolValue(cpuname,varname,value,value_bytes_number)
  173. else:
  174. pass
  175. def SE_log_output(filename,content):
  176. now_time = time.strftime('%m%d%H%M%S',time.localtime(time.time()))
  177. new_filename = filename+"_"+now_time+".txt"
  178. try:
  179. fp = open(new_filename,"w")
  180. fp.write(content)
  181. fp.close()
  182. except:
  183. print ("Write file failed")
  184. def SE_out_error_log(log):
  185. if sac.ac != None:
  186. sac.ac.error_test.append([sac.ac.error_reset(sac.ac.test_info),log])
  187. def SE_run_to_time(cpuname,time_s):
  188. sf.run_to_time(cpuname,time_s)
  189. def SE_create_breakpoint(cpuname,addr):
  190. try:
  191. SkyEyeCreateBreakpoint(cpuname,addr)
  192. except Exception as e:
  193. SE_print(e)
  194. def SE_get_current_pc(cpuname):
  195. try:
  196. return SkyEyeGetPcByCoreName(cpuname)
  197. except Exception as e:
  198. SE_print(e)
  199. def SE_get_cpu_freq(cpuname):
  200. try:
  201. return SkyEyeGetCpuFreq(cpuname)
  202. except Exception as e:
  203. SE_print(e)
  204. def SE_read_byte(cpuname,addr):
  205. try:
  206. return SkyEyeReadByte(cpuname,addr)
  207. except Exception as e:
  208. SE_print(e)
  209. def SE_read_dword(cpuname,addr):
  210. try:
  211. return SkyEyeReadDWord(cpuname,addr)
  212. except Exception as e:
  213. SE_print(e)
  214. def SE_write_byte(cpuname,addr,value):
  215. try:
  216. return SkyEyeWriteByte(cpuname,addr,value)
  217. except Exception as e:
  218. SE_print(e)
  219. def SE_write_dword(cpuname,addr,value):
  220. try:
  221. return SkyEyeWriteDWord(cpuname,addr,value)
  222. except Exception as e:
  223. SE_print(e)
  224. def SE_sync_callback(cpuname,my_callback,argument):
  225. return pytimer.PyTmrCreate(cpuname,0,pytimer.TMR_ONE_SHOT,my_callback, argument)
  226. def SE_create_timer(cpuname,time_ms,my_callback,argument):
  227. return pytimer.PyTmrCreate(cpuname,time_ms,pytimer.TMR_ONE_SHOT,my_callback, argument)
  228. def SE_delete_timer(tmr):
  229. try:
  230. return pytimer.PyTmrDelete(tmr)
  231. except:
  232. return False
  233. def SE_set_watch_on_pc(cpuname,pc_addr,my_callback,argument):
  234. return pytimer.PySetWatchOnPc(cpuname,pc_addr,my_callback,argument)
  235. def SE_del_watch_on_pc(watch):
  236. try:
  237. return pytimer.PyUnWatchOnPc(watch)
  238. except:
  239. return False
  240. def SE_set_watch_on_mem(ms_name,mm_type,addr,data_type,length,my_callback,argument):
  241. return pytimer.PySetWatchOnMem(ms_name,mm_type,addr,data_type,length,my_callback,argument)
  242. def SE_del_watch_on_mem(watch):
  243. try:
  244. return pytimer.PyUnWatchOnMem(watch)
  245. except:
  246. return False
  247. def SE_get_func_addr(cpuname,funcname):
  248. try:
  249. return SkyEyeGetFuncAddr(cpuname,funcname)
  250. except Exception as e:
  251. SE_print(e)
  252. def SE_get_func_length(cpuname,funcname):
  253. try:
  254. return SkyEyeGetFuncLength(cpuname,funcname)
  255. except Exception as e:
  256. SE_print(e)
  257. def SE_load_file(memoryname, filename, pc_addr):
  258. if os.path.isfile(filename)==False:
  259. print ("No such binary file")
  260. return False
  261. if SkyEyeNewLoadFile(memoryname, filename, pc_addr) != 1:
  262. print ("load_file error")
  263. return False
  264. def SE_cpu_load_file(cpuname, filename, pc_addr):
  265. if os.path.isfile(filename)==False:
  266. print ("No such binary file")
  267. return False
  268. if SkyEyeLoadFile(cpuname, filename, pc_addr) != 1:
  269. print ("load_file error")
  270. return False
  271. def SE_term_wait_for_string(termname, string):
  272. return SkyEyeTermWaitForString(termname, string)
  273. def SE_term_write(termname, string):
  274. return SkyEyeTermWrite(termname, string)
  275. def SE_term_wait_then_write(termname, wait_string, write_string):
  276. return SkyEyeTermWaitThenWrite(termname, wait_string, write_string)
  277. def SE_get_device_register_list(machname, devicename):
  278. regs = []
  279. RegNum = SkyEyeGetDevRegNum(machname,devicename)
  280. for regid in range(0,RegNum):
  281. regs.append(SkyEyeGetDevRegNameById(machname,devicename,regid))
  282. return regs
  283. def SE_Device_skyEyeGetDevRegNum(machname,devicename):
  284. return SkyEyeGetDevRegNum(machname,devicename)
  285. def SE_SkyEyeGetModules():
  286. return SkyEyeGetModules()
  287. def SE_get_regs(machname,devname):
  288. return fi.get_device_register_info(machname,devname)
  289. def SE_get_registers(devicename):
  290. reg_list = []
  291. reg_list1=[]
  292. reg_attr_dic1 = {}
  293. try:
  294. num = scm.SkyEyeGetDevRegNum(None, devicename)
  295. except:
  296. return None
  297. for i in range(0, num):
  298. try:
  299. name = scm.SkyEyeGetDevRegNameById(None, devicename, i)
  300. if name == None:
  301. continue
  302. except:
  303. return None
  304. try:
  305. value = scm.SkyEyeGetDevRegValueById(None, devicename, i)
  306. except:
  307. return None
  308. try:
  309. offset = scm.SkyEyeGetDevRegOffsetById(None, devicename, i)
  310. except:
  311. return None
  312. if offset == 0xffffffff:
  313. offset = i * 4
  314. reg_attr_dic={}
  315. reg_attr_dic["offset"] = offset
  316. reg_attr_dic["size"] = 4
  317. reg_attr_dic["value"] = value
  318. reg_attr_dic["name"] = name
  319. reg_list.append(reg_attr_dic)
  320. reg_attr_dic1[devicename] = reg_list
  321. # reg_list1.append(reg_attr_dic1)
  322. return reg_attr_dic1
  323. def SE_ReadDevice4(device, offset):
  324. return SkyEyeReadDevice4(device, offset)
  325. def SE_WriteDevice4(device, offset,data):
  326. return SkyEyeWriteDevice4(device, offset,data)
  327. def SE_Test_regs_read_wirte(test_num,device,reg_name, offset,alter_value,expect):
  328. alter_value=int(alter_value)
  329. init_vaule= SkyEyeReadDWord(device,offset)
  330. a=SE_write_dword(device, offset,alter_value)
  331. actual_value = SkyEyeReadDWord(device,offset)
  332. if actual_value == expect:
  333. result = "true"
  334. else:
  335. result = "false"
  336. return [test_num,device,reg_name,hex(eval(str(offset))),hex(eval(str(init_vaule))),hex(eval(str(alter_value))),hex(eval(str(expect))),hex(eval(str(actual_value))),result]
  337. def SE_get_simulation_device_info():
  338. result='false'
  339. error=None
  340. device_info={}
  341. config = GetGlobalConfig()
  342. if config!=None:
  343. mach_list=config.get_mach_list()
  344. for machname in mach_list:
  345. device_info[machname]={}
  346. device_list = config.get_device_list_by_mach(machname)
  347. dev_list=[]
  348. if device_list != None:
  349. for device in device_list:
  350. cls = config.get_device_classname(machname, device)
  351. base=SkyEyeGetClassType(cls)
  352. if "image" in cls or "memory_space" in cls or "ram" in cls or "_core" in cls:
  353. pass
  354. else:
  355. dev_list.append(device)
  356. device_info[machname]=dev_list
  357. result=device_info
  358. device_list=[]
  359. for j,k in result.items():
  360. device_list.extend(k)
  361. else:
  362. error="The config is None"
  363. return device_list
  364. def SE_Quit():
  365. SkyEyeQuit()