lds.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. #!/usr/bin/python
  2. #_*_ coding: utf-8 _*_
  3. from Tkinter import *
  4. import sys
  5. import os
  6. import subprocess
  7. import time
  8. import ttk
  9. import tkMessageBox
  10. import threading
  11. import csv
  12. import subprocess
  13. from datetime import datetime
  14. # declaring global variables
  15. script_ver='MXF301-B-C7-v1.1'
  16. log_file='./Logs/temp.txt'
  17. log1_buffer = ""
  18. step_status = ['x', 'ns', 'ns']
  19. result_msg = []
  20. # 'x' = don't care
  21. # 'ns' = not started
  22. # 'p' = passed
  23. # 'f' = failed
  24. # 'r' = running
  25. test_channel = ['1', '6', '11']
  26. device_info={}
  27. params_dict = {}
  28. params_dict['path_loss'] = '25'
  29. params_dict['wave_file'] = './11b_waveforms/wave11rc_1000.mod'
  30. params_dict['per_limit'] = '92'
  31. params_dict['SA_RSSI'] = '-80'
  32. params_dict['BTOn_RSSI']='-30'
  33. counter=0
  34. running=False
  35. ###########################################################################
  36. class IO_process:
  37. def __init__(self, log_file_path):
  38. # log_file_path is the absolute path of the log file
  39. self.log_file = log_file_path
  40. self.line_count = 0
  41. def read_file(self):
  42. try:
  43. f = open(self.log_file,'r') # open file to read
  44. flag = 0
  45. for i, line in enumerate(f):
  46. if i == self.line_count: # if reached the correct line
  47. self.line_count += 1
  48. flag = 1
  49. #print self.line_count
  50. break
  51. f.close()
  52. if flag == 1:
  53. return line.rstrip('\r') # get rid of the newline character
  54. else:
  55. return ""
  56. except:
  57. return ""
  58. def empty_file(self):
  59. f = open(self.log_file,'w')
  60. f.close()
  61. def reset_counter(self):
  62. self.line_count = 0
  63. ###########################################################################
  64. def write_log_to_file(content):
  65. curr_time=time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
  66. log_dir = "./Logs/"
  67. log_file = "log_" + curr_time + ".txt"
  68. log_file_location = log_dir + log_file
  69. file = open(log_file_location,'a') # open file to append
  70. file.write(str(content) + '\n')
  71. file.close()
  72. ###########################################################################
  73. def print1(string,newline=0):
  74. global log1_buffer
  75. if newline == 0: # if user doesn't want to insert a line feed
  76. log1_buffer += "\n" + str(string)
  77. elif newline == 1: # if user wants to insert a line feed
  78. log1_buffer += "\n" + str(string) + "\n"
  79. ###########################################################################
  80. def step1_routine():
  81. # bios_version
  82. global step_status
  83. global result_msg
  84. step_num = 1
  85. step_status[step_num] = 'r' # running
  86. print1("\nstep1----------------------------------------------------")
  87. print1("Step " + str(step_num) + " Started...")
  88. time.sleep(1)
  89. #a = subprocess.call(['./bios-ver.sh'])
  90. a = os.popen("ls").read()
  91. a = a.replace('\n','')
  92. a = a.replace('\r','')
  93. a = a.strip()
  94. if len(a) != 0:
  95. print1("Error! No Device found!")
  96. print1(a)
  97. step_status[step_num] = 'f' # failed
  98. else:
  99. print1("Success! Device found! Rsync completed!")
  100. print1(a)
  101. step_status[step_num] = 'p' # passed
  102. result_msg[step_num] = a
  103. def step2_routine():
  104. # bios_version
  105. global step_status
  106. global result_msg
  107. step_num = 2
  108. step_status[step_num] = 'r' # running
  109. print1("\nstep1----------------------------------------------------")
  110. print1("Step " + str(step_num) + " Started...")
  111. time.sleep(1)
  112. #a = subprocess.call(['./bios-ver.sh'])
  113. a = os.popen("ls").read()
  114. a = a.replace('\n','')
  115. a = a.replace('\r','')
  116. a = a.strip()
  117. if len(a) != 0:
  118. print1("Error! No Device found!")
  119. print1(a)
  120. step_status[step_num] = 'f' # failed
  121. else:
  122. print1("Success! Device found! Rsync completed!")
  123. print1(a)
  124. step_status[step_num] = 'p' # passed
  125. result_msg[step_num] = a
  126. #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  127. class GuiThread(object):
  128. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  129. def __init__(self):
  130. global log_file
  131. global result_msg
  132. self.thread_list = {}
  133. self.root = Tk()
  134. self.root.geometry("1800x1200")
  135. self.running=False
  136. self.counter=0
  137. self.root.protocol("WM_DELETE_WINDOW", self.destroy) # when user closes the window
  138. self.root.title("WiPER: DFU/SOC Simular Test")
  139. self.note1 = Label(self.root, text="Please press 'Start Test' to begin...", fg='blue')
  140. self.button1 = Button(self.root, text="Start Test", command=self.start) #lambda:
  141. self.lbl = Label(self.root, text="NOT STARTED", width=15, bg='gray')
  142. self.lbl2 = Label(self.root, text="Device: ",width=20,bg="#C6EBFF")
  143. self.nb = ttk.Notebook(self.root, name='notebook')
  144. self.textframe1 = Frame(self.root)
  145. self.text1 = Text(self.textframe1)
  146. self.scrollbar1 = Scrollbar(self.textframe1)
  147. self.paramframe = Frame(self.root)
  148. self.lblframe = Frame(self.root)
  149. #self.step1_lbl1 = Label(self.lblframe, text="Step1: Check BIOS Version ", width=50)
  150. self.step1_lbl1 = Label(self.lblframe, text="Step1: 检查BIOS版本号 ", width=50)
  151. self.step2_lbl1 = Label(self.lblframe, text="Step2: 检查BIOS版本号 ", width=50)
  152. self.step1_lbl2 = Label(self.lblframe, text="NOT STARTED", bg='gray', width=50)
  153. self.step2_lbl2 = Label(self.lblframe, text="NOT STARTED", bg='gray', width=50)
  154. self.step_lbl_list = []
  155. self.step_lbl_list.append('x') # don't care
  156. self.step_lbl_list.append(self.step1_lbl2)
  157. self.step_lbl_list.append(self.step2_lbl2)
  158. result_msg.append('P')
  159. result_msg.append('P')
  160. result_msg.append('P')
  161. self.my_io_process = IO_process(log_file)
  162. self.readLog1()
  163. self.set_param_frame()
  164. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  165. def destroy(self):
  166. if tkMessageBox.askokcancel("Quit?", "Are you sure you want to quit?"):
  167. self.root.quit()
  168. def counter_label(self):
  169. def count():
  170. if self.running:
  171. global counter
  172. # To manage the initial delay.
  173. if self.counter==0: #66600
  174. display="Starting..."
  175. else:
  176. tt=datetime.fromtimestamp(self.counter)
  177. string=tt.strftime("%H:%M:%S")
  178. display=string
  179. #display="kskjskdjd"
  180. #self.note1.config(text='RUNNING...'
  181. #self.note1['text']=display
  182. #self.lbl.config(text='RUNNING...')
  183. self.note1.config(text=display)
  184. #self.note1.config['text']=display
  185. self.note1.after(1000, count)
  186. self.counter+=1
  187. count()
  188. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  189. def run(self):
  190. self.note1.pack()
  191. self.button1.pack(side=TOP, padx = 10, pady = 3)
  192. self.lbl.pack()
  193. self.lbl2.pack(fill=BOTH,expand=Y)
  194. self.scrollbar1.config(command=self.text1.yview)
  195. self.text1.config(yscrollcommand=self.scrollbar1.set)
  196. self.text1.pack(side=LEFT, fill=Y)
  197. self.scrollbar1.pack(side=RIGHT, fill=Y)
  198. self.step1_lbl1.grid(row=0,column=0,sticky=W)
  199. self.step2_lbl1.grid(row=1,column=0,sticky=W)
  200. self.step1_lbl2.grid(row=0,column=1,sticky=W)
  201. self.step2_lbl2.grid(row=1,column=1,sticky=W)
  202. self.lblframe.pack()
  203. self.textframe1.pack()
  204. self.paramframe.pack()
  205. self.nb.add(self.lblframe, text='Status')
  206. self.nb.add(self.textframe1, text='Log')
  207. self.nb.add(self.paramframe, text='Parameters')
  208. self.nb.enable_traversal() # enable keyboard traversal using Ctrl+Tab
  209. self.nb.pack(fill=BOTH, expand="true", padx=5, pady=1)
  210. self.root.mainloop()
  211. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  212. def readLog1(self):
  213. # This function periodically reads and empties the log buffer
  214. global log1_buffer
  215. if log1_buffer != "":
  216. self.text1.insert(END, log1_buffer)
  217. text = self.my_io_process.read_file()
  218. if text != "":
  219. self.text1.insert(END, text)
  220. if log1_buffer != "" or text != "": # if log buffer was populated
  221. self.text1.yview_pickplace("end") # move the scrollbar to the bottom
  222. log1_buffer = "" # empty the log buffer
  223. self.root.update() # update the screen
  224. self.root.after(100, self.readLog1)
  225. ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  226. def set_param_frame(self):
  227. global params_dict
  228. self.L = []
  229. self.E = []
  230. count = 1
  231. for key,value in params_dict.iteritems():
  232. lbl = Label(self.paramframe, text=key)
  233. enty = Entry(self.paramframe, bd = 4)
  234. enty.delete(0, END)
  235. enty.insert(0,value)
  236. enty.config(state=DISABLED)
  237. lbl.grid(row=count, sticky=W)
  238. enty.grid(row=count, column=1)
  239. self.L.append(lbl)
  240. self.E.append(enty)
  241. count = count + 1
  242. ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  243. def start(self):
  244. global step_status
  245. #running=True
  246. #self.counter_label()
  247. #step_status = ['x', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns', 'ns'] #
  248. step_status = ['x', 'ns', 'ns'] #
  249. self.button1.config(state=DISABLED) # disable the start button
  250. self.text1.delete('1.0', 'end') # delete the log
  251. self.my_io_process.reset_counter()
  252. self.thread_list['thread'] = MasterThread(self)
  253. self.thread_list['thread'].start()
  254. self.manage()
  255. self.manage_lblframe()
  256. ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  257. def manage(self):
  258. # manage the pop-up dialog boxes
  259. global step_status
  260. total_no_of_steps = len(step_status) - 1
  261. flag = 0
  262. count = 0
  263. for i in range(1,total_no_of_steps+1):
  264. if step_status[i] == 'f': # if failed
  265. #tkMessageBox.showinfo("Message Box", "Error on Step " + str(i) + "! See Log for details.")
  266. print1("Error on Step " + str(i) + "! See Log for details.")
  267. flag = 1
  268. time.sleep(1)
  269. write_log_to_file(self.text1.get('1.0', 'end'))
  270. print1("Log written to the external txt file under ./Logs/")
  271. if step_status[i] == 'p' or step_status[i] == 'f': # if passed
  272. count = count + 1
  273. if count == total_no_of_steps: # if all the steps were successful
  274. flag = 1
  275. tkMessageBox.showinfo("Message Box", "Test succesfully done!") #Please safely remove the device from the chamber.
  276. print1("Test succesfully done! Please safely remove the device from the chamber.")
  277. time.sleep(1)
  278. write_log_to_file(self.text1.get('1.0', 'end'))
  279. print1("Log written to the external txt file under ./Logs/")
  280. self.running=False
  281. self.counter=0
  282. if flag == 0: # if not(any step failed or all steps passed)
  283. self.root.after(500, self.manage)
  284. else: # if any step has failed or if all the steps have passed
  285. self.button1.config(state=NORMAL) # enable the start button
  286. self.my_io_process.empty_file()
  287. return 0
  288. ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  289. def manage_lblframe(self):
  290. # manage the frame that displays the step-by-step status
  291. # manage the top-level status Label
  292. global step_status
  293. global device_info
  294. global result_msg
  295. total_no_of_steps = len(step_status) - 1
  296. try:
  297. SrNo = device_info['SrNo']
  298. string = "Device: " + SrNo
  299. self.lbl2.config(text=string)
  300. except:
  301. string = "Device: "
  302. self.lbl2.config(text=string)
  303. flag = 0
  304. count1 = 0
  305. count2 = 0
  306. count3 = 0
  307. for i in range (1,total_no_of_steps + 1):
  308. if step_status[i] == 'r': # if running
  309. self.step_lbl_list[i]["text"] = "RUNNING..."
  310. self.step_lbl_list[i]["bg"] = 'yellow'
  311. self.lbl.config(bg='yellow')
  312. self.lbl.config(text='RUNNING...')
  313. self.running=True
  314. self.counter_label()
  315. if step_status[i] == 'p': # if passed
  316. self.step_lbl_list[i]["text"] = result_msg[i]
  317. self.step_lbl_list[i]["bg"] = 'green'
  318. count2 = count2 + 1
  319. if step_status[i] == 'f': # if failed
  320. self.step_lbl_list[i]["text"] = "ERROR!"
  321. self.step_lbl_list[i]["bg"] = 'red'
  322. self.lbl.config(bg='red')
  323. self.lbl.config(text='ERROR!')
  324. #flag = 1
  325. count3 = count3 + 1
  326. if step_status[i] == 'ns': # if not started
  327. self.step_lbl_list[i]["text"] = "NOT STARTED"
  328. self.step_lbl_list[i]["bg"] = 'gray'
  329. count1 = count1 + 1
  330. if count1 == total_no_of_steps: # if none of the steps have started
  331. self.lbl.config(bg='gray')
  332. self.lbl.config(text='NOT STARTED')
  333. if count2 == total_no_of_steps: # if all the steps are done
  334. self.lbl.config(bg='green')
  335. self.lbl.config(text='DONE!')
  336. flag = 1
  337. if flag == 0: # if there is no error and all the steps aren't done yet
  338. self.root.after(200, self.manage_lblframe)
  339. else: # if there is an error or if all the steps are done already
  340. device_info['SrNo'] = ""
  341. return 0
  342. #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  343. class MasterThread(threading.Thread):
  344. def __init__(self, guiobj):
  345. super(MasterThread, self).__init__()
  346. def run(self):
  347. global step_status
  348. global script_ver
  349. print1("FT####################################################",1)
  350. print1(script_ver)
  351. step1_routine()
  352. if step_status[1] == 'p' or step_status[1] == 'f': # if step 1 passed
  353. step2_routine()
  354. print1("\n----------------------------------------------------")
  355. print1("Test concluded!")
  356. ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  357. if __name__ == "__main__":
  358. g = GuiThread()
  359. g.run()
  360. """
  361. print "123"
  362. print("\n----------------------------------------------------")
  363. tkMessageBox.showinfo("Message Box", "play video test! 视频测试,播放720p视频.")
  364. print("\n----------------------------------------------------")
  365. print("Step " + " Started...")
  366. print("Step " + " 开始播放720p视频")
  367. #a = os.popen("sh os-ver.sh 720p").read()
  368. #subprocess.run('sh os-ver.sh 720p',stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
  369. #os.system("sudo setenforce 0")
  370. time.sleep(1)
  371. os.system("sh os-ver.sh 720p &")
  372. time.sleep(1)
  373. #os.system("sudo setenforce 1")
  374. if not tkMessageBox.askokcancel("PASS?", "视频播放器不要关-确定测试机器播放720p视频正常吗?"):
  375. print("Error! No Device found!")
  376. print(a)
  377. #step_status[step_num] = 'f' # failed
  378. #return;
  379. os.system("sh os-ver.sh suspend")
  380. print "successful"
  381. os.system("sh os-ver.sh USB211 &")
  382. time.sleep(2)
  383. tkMessageBox.showinfo("Message Box", "USB2.0 test! 请插入U盘到usb2.0端口1指定位置.")
  384. a = os.popen("sh os-ver.sh USB21").read()
  385. print(a)
  386. a = a.replace('\n','')
  387. a = a.replace('\r','')
  388. #a = os.popen("sh os-ver.sh USB21").read()
  389. #print(a)
  390. a = a.replace('\n','')
  391. a = a.replace('\r','')
  392. a = a.strip()
  393. print(a)
  394. if a == "0":
  395. print "wrong"
  396. else:
  397. print "successful"
  398. """