寄存器自动化测试说明及时使用
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.

85 lines
2.7 KiB

  1. import csv
  2. import os
  3. def deal_params(dev_list,fun):
  4. para_list=[]
  5. for i in dev_list:
  6. a=fun(i)
  7. dict1=demo(a)
  8. para_list.append(dict1)
  9. read_params_list=[]
  10. for i in para_list:
  11. if len(i)>0:
  12. for j,k in i.items():
  13. k.append(j)
  14. read_params_list.append(tuple(k))
  15. for l in range(len(k)):
  16. if isinstance(k[l],int):
  17. pass
  18. read_params_list=sort_list(read_params_list)
  19. return read_params_list
  20. def output_value_csv(data,header =["test_num","device_name","reg_name","offset","alter_value","expect_value"],file_name="data.csv"):
  21. if file_name=="data.csv":
  22. if os.path.exists(file_name):
  23. print("{}文件已存在".format(file_name))
  24. else:
  25. with open(file_name,"w",encoding="utf-8",newline='')as fq:
  26. writer=csv.writer(fq)
  27. writer.writerow(header)
  28. writer.writerows(data)
  29. else:
  30. if os.path.exists(file_name):
  31. print("{}已删除,重新生成".format(file_name))
  32. os.remove(file_name)
  33. with open(file_name,"w",encoding="utf-8",newline='')as fq:
  34. writer=csv.writer(fq)
  35. writer.writerow(header)
  36. writer.writerows(data)
  37. def out_put_test_reslut(data):
  38. file_name="testcase_result.csv"
  39. header=["tst_num","device_name","reg_name","offset","init_value","alter_value","expect_value","actual_value","test_result"]
  40. output_value_csv(data,header=header,file_name=file_name)
  41. def read_csv():
  42. try:
  43. reg_par_list=[]
  44. with open("data.csv") as f:
  45. f_csv=csv.reader(f)
  46. headers=next(f_csv)
  47. for row in f_csv:
  48. reg_params=(row[0],row[1],row[2],int(row[3],16),int(row[4],16),int(row[5],16))
  49. reg_par_list.append(reg_params)
  50. return reg_par_list
  51. except IndexError:
  52. print("请补充测试数据")
  53. except Exception as ep:
  54. print(ep)
  55. def demo(a):
  56. dict1={}
  57. for j,k in a.items():
  58. for i in range(len(k)):
  59. dict1[k[i]["name"]] = [j,k[i]["offset"]]
  60. return dict1
  61. def sort_list(a):
  62. for i in range(len(a)):
  63. for j in range(i+1,len(a)):
  64. if a[i][0] == a[j][0]:
  65. if a[i][1]>a[j][1]:
  66. a[i],a[j] = a[j],a[i]
  67. res=[]
  68. res1=[]
  69. for i in a:
  70. i=list(i)
  71. res.append(i)
  72. [res1.append(res[i][0]) for i in range(len(res)) if res[i][0] not in res1]
  73. for i in res1:
  74. a=1
  75. for k in res:
  76. if i in k:
  77. testcasenum="testcase{}_({})".format(str(a),i)
  78. k.insert(0,testcasenum)
  79. a+=1
  80. return res