test_function.py 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. #!/usr/bin/python
  2. # _*_ coding: utf-8 _*_
  3. try:
  4. from Tkinter import * # python2
  5. import ttk
  6. import tkMessageBox
  7. except Exception as e:
  8. from tkinter import * # python3
  9. from tkinter import ttk
  10. from tkinter import messagebox as tkMessageBox
  11. import time
  12. import os
  13. import threading
  14. import random
  15. from requests_offline import requests
  16. def ask_choice_with_timeout(title, message, timeout=5, default_choice=False):
  17. # 创建顶层弹窗窗口(Python 2 Tkinter语法)
  18. import Tkinter as tk
  19. top = tk.Toplevel()
  20. top.title(title)
  21. top.geometry("350x180") # 弹窗大小
  22. top.resizable(False, False) # 禁止调整大小
  23. # 设置模态窗口(阻塞主窗口操作)
  24. top.transient(top.master)
  25. top.grab_set()
  26. # 存储结果(用列表实现可变变量,Python 2中nonlocal仅在3.x支持)
  27. result = [default_choice]
  28. # 显示提示信息
  29. msg_label = tk.Label(top, text=message, padx=20, pady=20, font=("Arial", 10))
  30. msg_label.pack(fill=tk.X)
  31. # 显示倒计时提示
  32. timeout_text = "{}秒后自动{}...".format(timeout, "确认" if default_choice else "取消")
  33. timeout_label = tk.Label(top, text=timeout_text, fg="gray", font=("Arial", 9))
  34. timeout_label.pack()
  35. # 按钮回调函数
  36. def on_ok():
  37. result[0] = True
  38. top.destroy()
  39. def on_cancel():
  40. result[0] = False
  41. top.destroy()
  42. # 按钮布局
  43. btn_frame = tk.Frame(top)
  44. btn_frame.pack(pady=15)
  45. ok_btn = tk.Button(btn_frame, text="OK", command=on_ok, width=8)
  46. cancel_btn = tk.Button(btn_frame, text="Cancel", command=on_cancel, width=8)
  47. ok_btn.pack(side=tk.LEFT, padx=10)
  48. cancel_btn.pack(side=tk.LEFT, padx=10)
  49. # 倒计时线程(Python 2 threading语法)
  50. def countdown():
  51. current_timeout = timeout
  52. while current_timeout > 0:
  53. current_timeout -= 1
  54. # 更新倒计时文本
  55. new_text = "{}秒后自动{}...".format(current_timeout, "确认" if default_choice else "取消")
  56. print(new_text)
  57. timeout_label.config(text=new_text)
  58. top.update() # 刷新界面
  59. time.sleep(1) # 等待1秒
  60. top.destroy() # 超时关闭窗口
  61. # 启动守护线程(Python 2兼容)
  62. t = threading.Thread(target=countdown)
  63. t.setDaemon(True) # 守护线程,主程序退出时自动结束
  64. t.start()
  65. # 等待窗口关闭
  66. top.wait_window()
  67. return result[0]
  68. def step1_routine(context, *args):
  69. # bios_version
  70. context.print1("==SubTest: 检查BIOS版本号 - Titem_1")
  71. time.sleep(0.1)
  72. context.print1("-:) sh os-ver.sh bios")
  73. a = os.popen("sh os-ver.sh bios").read().replace('\n', '').replace('\r', '').strip()
  74. if len(a) == 0:
  75. return False, "Error! No Device found!\n" + a
  76. else:
  77. return True, 'PASS-{}'.format(a)
  78. def step2_routine(context):
  79. # bios release date # ec version
  80. context.print1("==SubTest: 检查EC版本号 - Titem_2")
  81. context.print1("-:) sh os-ver.sh ec")
  82. a = os.popen('sh os-ver.sh ec').read().replace('\n', '').replace('\r', '').strip()
  83. if len(a) == 0:
  84. return False, "Error! No Device found!\n" + a
  85. else:
  86. return True, 'PASS-{}'.format(a)
  87. def step3_routine(context):
  88. # CPU type
  89. context.print1("==SubTest: 检查CPU type - Titem_4")
  90. context.print1("-:) cat /proc/cpuinfo | grep \"model name\" | awk '{print $5}' | head -1")
  91. a = os.popen("cat /proc/cpuinfo").read().strip()
  92. context.print1("output: {}".format(a))
  93. a = os.popen("cat /proc/cpuinfo | grep \"model name\" | awk '{print $5}' | head -1").read().replace('\n','').replace('\r', '').strip()
  94. if len(a) == 0:
  95. return False, "Error! No Device found!\n" + a
  96. else:
  97. return True, 'PASS-{}'.format(a)
  98. def step4_routine(context):
  99. # memory_version
  100. context.print1("==SubTest: 检查Memory内存版本号 - Titem_5")
  101. context.print1("-:) sh mem-ver.sh")
  102. a = os.popen("sh mem-ver.sh").read().replace('\n', '').replace('\r', '').strip()
  103. if len(a) == 0:
  104. return False, "Error! No Device found!\n" + a
  105. else:
  106. return True, 'PASS-{}'.format(a)
  107. def step5_routine(context):
  108. # hdd_version
  109. context.print1("==SubTest: 检查HDD硬盘版本号 - Titem_6")
  110. context.print1("-:) sh hdd-ver.sh")
  111. b = os.popen("sh hdd-ver.sh").read().strip()
  112. a = os.popen("cat /sys/block/nvme0n1/device/firmware_rev").read().replace('\n', '').replace('\r', '').strip()
  113. context.print1("output: {}".format(a))
  114. if len(a) == 0:
  115. return False, "Error! No Device found! " + a
  116. else:
  117. return True, 'PASS-{}'.format(a)
  118. def step6_routine(context):
  119. # os_version
  120. context.print1("==SubTest: 检查OS操作系统版本号 - Titem_7")
  121. context.print1("-:) lsb_release -rs")
  122. string = "os"
  123. a = os.popen("lsb_release -rs").read().strip()
  124. context.print1("output: {}".format(a))
  125. if a == "22.04":
  126. return True, 'PASS-{}'.format(a)
  127. else:
  128. return False, "Error! No Device found! " + a
  129. def step7_routine(context):
  130. context.print1("==SubTest: RTC电池 - Titem_8")
  131. context.print1("-:) sh os-ver.sh RTCBATTERY")
  132. a = os.popen("sh os-ver.sh RTCBATTERY").read().replace('\n', '').replace('\r', '').strip()
  133. try:
  134. a_int = int(a)
  135. except ValueError:
  136. return False, "Invalid output: {}".format(a)
  137. if 2900 <= a_int <= 4000:
  138. return True, a_int
  139. else:
  140. return False, "FAIL " + a
  141. def step8_routine(context):
  142. # usb function
  143. context.print1("==SubTest: USB基本功能测试 - Titem_9")
  144. context.print1("-:) lsblk -d -o TRAN,NAME,SIZE")
  145. b = os.popen("lsblk -d -o TRAN,NAME,SIZE").read().replace('\n', '').replace('\r', '').strip()
  146. context.print1("output: {}".format(b))
  147. b = os.popen("lsusb").read().replace('\n', '').replace('\r', '').strip()
  148. context.print1("output: {}".format(b))
  149. context.print1("-:) lsblk -d -o TRAN,NAME,SIZE | grep usb | wc -l")
  150. a = os.popen("lsblk -d -o TRAN,NAME,SIZE | grep usb | wc -l").read().replace('\n', '').replace('\r', '').strip()
  151. try:
  152. a_int = int(a)
  153. except ValueError:
  154. return False, "Invalid output: {}".format(a)
  155. if a_int == 5:
  156. return True, a
  157. else:
  158. return False, "FAIL " + a
  159. def step9_routine(context):
  160. # network speed cli
  161. context.print1("==SubTest: 检查网络在线速度测试 - Titem_10")
  162. context.print1("-:) ip link show | grep -c 'BROADCAST,MULTICAST,UP,LOWER_UP'")
  163. c = os.popen("ip link show | grep -c \"BROADCAST,MULTICAST,UP,LOWER_UP\"").read().strip()
  164. context.print1("output: {}".format(c))
  165. try:
  166. c_int = int(c)
  167. except ValueError:
  168. return False, "Invalid output c: {}".format(c)
  169. if c_int != 1:
  170. return False, "FAIL " + "Error! No Device found!"
  171. if(context.device_info['offline_test']):
  172. context.print1("-:) ping -c 10 www.baidu.com | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'")
  173. b = os.popen("ping -c 10 www.baidu.com")
  174. context.print1("output: {}".format(b))
  175. b = os.popen("ping -c 10 www.baidu.com | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'").read().replace('\n', '').replace('\r', '').strip()
  176. else:
  177. context.print1("-:) ping -c 10 10.60.64.87 | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'")
  178. b = os.popen("ping -c 10 10.60.64.87")
  179. context.print1("output: {}".format(b))
  180. b = os.popen("ping -c 10 10.60.64.87 | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'").read().replace('\n', '').replace('\r', '').strip()
  181. try:
  182. b_int = int(b)
  183. except ValueError:
  184. return False, "Invalid output b: {}".format(b)
  185. if b_int == 10:
  186. return True, b
  187. else:
  188. return False, "FAIL " + "Error! No Device found! {}".format(b)
  189. def step10_routine(context):
  190. return True, 'AAPASS'
  191. #serialA
  192. context.print1("==SubTest: UartA_Test - Titem_9")
  193. context.print1("-:) sh pcie.sh")
  194. a = os.popen("sh pcie.sh").read().strip()
  195. context.print1("{}".format(a))
  196. context.print1("-:) sh serialport-test.sh /dev/ttyWCH0")
  197. time.sleep(1)
  198. ttyWCH0 = os.popen("sh serialport-test.sh /dev/ttyWCH0").read().strip()
  199. try:
  200. a_int = int(ttyWCH0)
  201. except ValueError:
  202. return False, "Invalid output ttyWCH0: {}".format(ttyWCH0)
  203. if a_int == 1:
  204. context.print1("output ttyWCH0: {}".format(ttyWCH0))
  205. context.print1("output A: {}".format("A1-2"))
  206. pass
  207. else:
  208. context.print1("output ttyWCH0: {}".format(ttyWCH0))
  209. context.print1("output A: {}".format("A1-2"))
  210. return False, "FAIL " + "Error! No Device found! A1-2"
  211. context.print1("-:) sh serialport-test.sh /dev/ttyWCH1")
  212. ttyWCH1 = os.popen("sh serialport-test.sh /dev/ttyWCH1").read().strip()
  213. try:
  214. a_int = int(ttyWCH1)
  215. except ValueError:
  216. return False, "Invalid output ttyWCH1: {}".format(ttyWCH1)
  217. if a_int == 1:
  218. context.print1("output ttyWCH1: {}".format(ttyWCH1))
  219. context.print1("output A: {}".format("A1-6"))
  220. pass
  221. else:
  222. context.print1("output ttyWCH1: {}".format(ttyWCH1))
  223. context.print1("output A: {}".format("A1-6"))
  224. return False, "FAIL " + "Error! No Device found! A1-6"
  225. context.print1("-:) sh serialport-test.sh /dev/ttyWCH2")
  226. ttyWCH2 = os.popen("sh serialport-test.sh /dev/ttyWCH2").read().strip()
  227. try:
  228. a_int = int(ttyWCH2)
  229. except ValueError:
  230. return False, "Invalid output ttyWCH2: {}".format(ttyWCH2)
  231. if a_int == 1:
  232. context.print1("output ttyWCH2: {}".format(ttyWCH2))
  233. context.print1("output A: {}".format("A1-1"))
  234. pass
  235. else:
  236. context.print1("output ttyWCH2: {}".format(ttyWCH2))
  237. context.print1("output A: {}".format("A1-1"))
  238. return False, "FAIL " + "Error! No Device found! A1-1"
  239. context.print1("-:) sh serialport-test.sh /dev/ttyWCH3")
  240. ttyWCH3 = os.popen("sh serialport-test.sh /dev/ttyWCH3").read().strip()
  241. try:
  242. a_int = int(ttyWCH3)
  243. except ValueError:
  244. return False, "Invalid output ttyWCH3: {}".format(ttyWCH3)
  245. if a_int == 1:
  246. context.print1("output ttyWCH3: {}".format(ttyWCH3))
  247. context.print1("output A: {}".format("A1-5"))
  248. pass
  249. else:
  250. context.print1("output ttyWCH3: {}".format(ttyWCH3))
  251. context.print1("output A: {}".format("A1-5"))
  252. return False, "FAIL " + "Error! No Device found! A1-5"
  253. context.print1("-:) sh serialport-test.sh /dev/ttyWCH4")
  254. ttyWCH4 = os.popen("sh serialport-test.sh /dev/ttyWCH4").read().strip()
  255. try:
  256. a_int = int(ttyWCH4)
  257. except ValueError:
  258. return False, "Invalid output ttyWCH4: {}".format(ttyWCH4)
  259. if a_int == 1:
  260. context.print1("output ttyWCH4: {}".format(ttyWCH4))
  261. context.print1("output A: {}".format("A1-4"))
  262. pass
  263. else:
  264. context.print1("output ttyWCH4: {}".format(ttyWCH4))
  265. context.print1("output A: {}".format("A1-4"))
  266. return False, "FAIL " + "Error! No Device found! A1-4"
  267. context.print1("-:) sh serialport-test.sh /dev/ttyWCH5")
  268. ttyWCH5 = os.popen("sh serialport-test.sh /dev/ttyWCH5").read().strip()
  269. try:
  270. a_int = int(ttyWCH5)
  271. except ValueError:
  272. return False, "Invalid output ttyWCH5: {}".format(ttyWCH5)
  273. if a_int == 1:
  274. context.print1("output ttyWCH5: {}".format(ttyWCH5))
  275. context.print1("output A: {}".format("A1-8"))
  276. pass
  277. else:
  278. context.print1("output ttyWCH5: {}".format(ttyWCH5))
  279. context.print1("output A: {}".format("A1-8"))
  280. return False, "FAIL " + "Error! No Device found! A1-8"
  281. context.print1("-:) sh serialport-test.sh /dev/ttyWCH6")
  282. ttyWCH6 = os.popen("sh serialport-test.sh /dev/ttyWCH6").read().strip()
  283. try:
  284. a_int = int(ttyWCH6)
  285. except ValueError:
  286. return False, "Invalid output ttyWCH6: {}".format(ttyWCH6)
  287. if a_int == 1:
  288. context.print1("output ttyWCH6: {}".format(ttyWCH6))
  289. context.print1("output A: {}".format("A1-3"))
  290. pass
  291. else:
  292. context.print1("output ttyWCH6: {}".format(ttyWCH6))
  293. context.print1("output A: {}".format("A1-3"))
  294. return False, "FAIL " + "Error! No Device found! A1-3"
  295. context.print1("-:) sh serialport-test.sh /dev/ttyWCH7")
  296. ttyWCH7 = os.popen("sh serialport-test.sh /dev/ttyWCH7").read().strip()
  297. try:
  298. a_int = int(ttyWCH7)
  299. except ValueError:
  300. return False, "Invalid output ttyWCH7: {}".format(ttyWCH7)
  301. if a_int == 1:
  302. context.print1("output ttyWCH7: {}".format(ttyWCH7))
  303. context.print1("output A: {}".format("A1-7"))
  304. pass
  305. else:
  306. context.print1("output ttyWCH7: {}".format(ttyWCH7))
  307. context.print1("output A: {}".format("A1-7"))
  308. return False, "FAIL " + "Error! No Device found! A1-7"
  309. return True, "PASS"
  310. def step11_routine(context):
  311. return True, 'AAPASS'
  312. #serialB
  313. context.print1("==SubTest: UartB_Test - Titem_10")
  314. a = os.popen("sh pcie.sh").read().strip()
  315. time.sleep(1)
  316. context.print1("-:) sh serialport-test.sh /dev/ttyWCH8")
  317. ttyWCH8 = os.popen("sh serialport-test.sh /dev/ttyWCH8").read().strip()
  318. try:
  319. a_int = int(ttyWCH8)
  320. except ValueError:
  321. return False, "Invalid output ttyWCH8: {}".format(ttyWCH8)
  322. if a_int == 1:
  323. context.print1("output ttyWCH8: {}".format(ttyWCH8))
  324. context.print1("output A: {}".format("A2-4"))
  325. pass
  326. else:
  327. context.print1("output ttyWCH8: {}".format(ttyWCH8))
  328. context.print1("output A: {}".format("A2-4"))
  329. return False, "FAIL " + "Error! No Device found! A2-4"
  330. context.print1("-:) sh serialport-test.sh /dev/ttyWCH9")
  331. ttyWCH9 = os.popen("sh serialport-test.sh /dev/ttyWCH9").read().strip()
  332. try:
  333. a_int = int(ttyWCH9)
  334. except ValueError:
  335. return False, "Invalid output ttyWCH9: {}".format(ttyWCH9)
  336. if a_int == 1:
  337. context.print1("output ttyWCH9: {}".format(ttyWCH9))
  338. context.print1("output A: {}".format("A2-8"))
  339. pass
  340. else:
  341. context.print1("output ttyWCH9: {}".format(ttyWCH9))
  342. context.print1("output A: {}".format("A2-8"))
  343. return False, "FAIL " + "Error! No Device found! A2-8"
  344. context.print1("-:) sh serialport-test.sh /dev/ttyWCH10")
  345. ttyWCH10 = os.popen("sh serialport-test.sh /dev/ttyWCH10").read().strip()
  346. try:
  347. a_int = int(ttyWCH10)
  348. except ValueError:
  349. return False, "Invalid output ttyWCH10: {}".format(ttyWCH10)
  350. if a_int == 1:
  351. context.print1("output ttyWCH10: {}".format(ttyWCH10))
  352. context.print1("output A: {}".format("A2-3"))
  353. pass
  354. else:
  355. context.print1("output ttyWCH10: {}".format(ttyWCH10))
  356. context.print1("output A: {}".format("A2-3"))
  357. return False, "FAIL " + "Error! No Device found! A2-3"
  358. context.print1("-:) sh serialport-test.sh /dev/ttyWCH11")
  359. ttyWCH11 = os.popen("sh serialport-test.sh /dev/ttyWCH11").read().strip()
  360. try:
  361. a_int = int(ttyWCH11)
  362. except ValueError:
  363. return False, "Invalid output ttyWCH11: {}".format(ttyWCH11)
  364. if a_int == 1:
  365. context.print1("output ttyWCH11: {}".format(ttyWCH11))
  366. context.print1("output A: {}".format("A2-7"))
  367. pass
  368. else:
  369. context.print1("output ttyWCH11: {}".format(ttyWCH11))
  370. context.print1("output A: {}".format("A2-7"))
  371. return False, "FAIL " + "Error! No Device found! A2-7"
  372. context.print1("-:) sh serialport-test.sh /dev/ttyWCH12")
  373. ttyWCH12 = os.popen("sh serialport-test.sh /dev/ttyWCH12").read().strip()
  374. try:
  375. a_int = int(ttyWCH12)
  376. except ValueError:
  377. return False, "Invalid output ttyWCH12: {}".format(ttyWCH12)
  378. if a_int == 1:
  379. context.print1("output ttyWCH12: {}".format(ttyWCH12))
  380. context.print1("output A: {}".format("A2-2"))
  381. pass
  382. else:
  383. context.print1("output ttyWCH12: {}".format(ttyWCH12))
  384. context.print1("output A: {}".format("A2-2"))
  385. return False, "FAIL " + "Error! No Device found! A2-2"
  386. context.print1("-:) sh serialport-test.sh /dev/ttyWCH13")
  387. ttyWCH13 = os.popen("sh serialport-test.sh /dev/ttyWCH13").read().strip()
  388. try:
  389. a_int = int(ttyWCH13)
  390. except ValueError:
  391. return False, "Invalid output ttyWCH13: {}".format(ttyWCH13)
  392. if a_int == 1:
  393. context.print1("output ttyWCH13: {}".format(ttyWCH13))
  394. context.print1("output A: {}".format("A2-6"))
  395. pass
  396. else:
  397. context.print1("output ttyWCH13: {}".format(ttyWCH13))
  398. context.print1("output A: {}".format("A2-6"))
  399. return False, "FAIL " + "Error! No Device found! A2-6"
  400. context.print1("-:) sh serialport-test.sh /dev/ttyWCH14")
  401. ttyWCH14 = os.popen("sh serialport-test.sh /dev/ttyWCH14").read().strip()
  402. try:
  403. a_int = int(ttyWCH14)
  404. except ValueError:
  405. return False, "Invalid output ttyWCH14: {}".format(ttyWCH14)
  406. if a_int == 1:
  407. context.print1("output ttyWCH14: {}".format(ttyWCH14))
  408. context.print1("output A: {}".format("A2-1"))
  409. pass
  410. else:
  411. context.print1("output ttyWCH14: {}".format(ttyWCH14))
  412. context.print1("output A: {}".format("A2-1"))
  413. return False, "FAIL " + "Error! No Device found! A2-1"
  414. context.print1("-:) sh serialport-test.sh /dev/ttyWCH15")
  415. ttyWCH15 = os.popen("sh serialport-test.sh /dev/ttyWCH15").read().strip()
  416. try:
  417. a_int = int(ttyWCH15)
  418. except ValueError:
  419. return False, "Invalid output ttyWCH15: {}".format(ttyWCH15)
  420. if a_int == 1:
  421. context.print1("output ttyWCH15: {}".format(ttyWCH15))
  422. context.print1("output A: {}".format("A2-5"))
  423. pass
  424. else:
  425. context.print1("output ttyWCH15: {}".format(ttyWCH15))
  426. context.print1("output A: {}".format("A2-5"))
  427. return False, "FAIL " + "Error! No Device found! A2-5"
  428. return True, "PASS"
  429. def step12_routine(context):
  430. #serialC
  431. context.print1("==SubTest: UartC_Test - Titem_11")
  432. context.print1("-:) sh serialport-test.sh /dev/ttyS0")
  433. ttyS0 = os.popen("sh serialport-test.sh /dev/ttyS0").read().strip()
  434. try:
  435. a_int = int(ttyS0)
  436. except ValueError:
  437. return False, "Invalid output ttyS0: {}".format(ttyS0)
  438. if a_int == 1:
  439. context.print1("output ttyS0: {}".format(ttyS0))
  440. context.print1("output COM: {}".format("COM2"))
  441. pass
  442. else:
  443. context.print1("output ttyS0: {}".format(ttyS0))
  444. context.print1("output COM: {}".format("COM2"))
  445. return False, "FAIL " + "Error! No Device found! COM2"
  446. context.print1("-:) sh serialport-test.sh /dev/ttyS1")
  447. ttyS1 = os.popen("sh serialport-test.sh /dev/ttyS1").read().strip()
  448. try:
  449. a_int = int(ttyS1)
  450. except ValueError:
  451. return False, "Invalid output ttyS1: {}".format(ttyS1)
  452. if a_int == 1:
  453. context.print1("output ttyS1: {}".format(ttyS1))
  454. context.print1("output COM: {}".format("COM5"))
  455. pass
  456. else:
  457. context.print1("output ttyS1: {}".format(ttyS1))
  458. context.print1("output COM: {}".format("COM5"))
  459. return False, "FAIL " + "Error! No Device found! COM5"
  460. context.print1("-:) sh serialport-test.sh /dev/ttyS2")
  461. ttyS2 = os.popen("sh serialport-test.sh /dev/ttyS2").read().strip()
  462. try:
  463. a_int = int(ttyS2)
  464. except ValueError:
  465. return False, "Invalid output ttyS2: {}".format(ttyS2)
  466. if a_int == 1:
  467. context.print1("output ttyS2: {}".format(ttyS2))
  468. context.print1("output COM: {}".format("COM1"))
  469. pass
  470. else:
  471. context.print1("output ttyS2: {}".format(ttyS2))
  472. context.print1("output COM: {}".format("COM1"))
  473. return False, "FAIL " + "Error! No Device found! COM1"
  474. context.print1("-:) sh serialport-test.sh /dev/ttyS3")
  475. ttyS3 = os.popen("sh serialport-test.sh /dev/ttyS3").read().strip()
  476. try:
  477. a_int = int(ttyS3)
  478. except ValueError:
  479. return False, "Invalid output ttyS3: {}".format(ttyS3)
  480. if a_int == 1:
  481. context.print1("output ttyS3: {}".format(ttyS3))
  482. context.print1("output COM: {}".format("COM4"))
  483. pass
  484. else:
  485. context.print1("output ttyS3: {}".format(ttyS3))
  486. context.print1("output COM: {}".format("COM4"))
  487. return False, "FAIL " + "Error! No Device found! COM4"
  488. # ttyS4 = os.popen("sh serialport-test.sh /dev/ttyS4").read().strip()
  489. # try:
  490. # a_int = int(ttyS4)
  491. # except ValueError:
  492. # return False, "Invalid output ttyS4: {}".format(ttyS4)
  493. # if a_int == 1:
  494. # pass
  495. # else:
  496. # return False, "FAIL " + "Error! No Device found! ttyS4"
  497. # ttyS5 = os.popen("sh serialport-test.sh /dev/ttyS5").read().strip()
  498. # try:
  499. # a_int = int(ttyS5)
  500. # except ValueError:
  501. # return False, "Invalid output ttyS5: {}".format(ttyS5)
  502. # if a_int == 1:
  503. # pass
  504. # else:
  505. # return False, "FAIL " + "Error! No Device found! ttyS5"
  506. context.print1("-:) sh serialport-test.sh /dev/ttyS6")
  507. ttyS6 = os.popen("sh serialport-test.sh /dev/ttyS6").read().strip()
  508. try:
  509. a_int = int(ttyS6)
  510. except ValueError:
  511. return False, "Invalid output ttyS6: {}".format(ttyS6)
  512. if a_int == 1:
  513. context.print1("output ttyS6: {}".format(ttyS6))
  514. context.print1("output COM: {}".format("COM3"))
  515. pass
  516. else:
  517. context.print1("output ttyS6: {}".format(ttyS6))
  518. context.print1("output COM: {}".format("COM3"))
  519. return False, "FAIL " + "Error! No Device found! COM3"
  520. context.print1("-:) sh serialport-test.sh /dev/ttyS7")
  521. ttyS7 = os.popen("sh serialport-test.sh /dev/ttyS7").read().strip()
  522. try:
  523. a_int = int(ttyS7)
  524. except ValueError:
  525. return False, "Invalid output ttyS7: {}".format(ttyS7)
  526. if a_int == 1:
  527. context.print1("output ttyS7: {}".format(ttyS7))
  528. context.print1("output COM: {}".format("COM6"))
  529. pass
  530. else:
  531. context.print1("output ttyS7: {}".format(ttyS7))
  532. context.print1("output COM: {}".format("COM6"))
  533. return False, "FAIL " + "Error! No Device found! COM6"
  534. return True, "PASS"
  535. def step13_routine(context):
  536. #LCD Test
  537. context.print1("==SubTest: lcd测试 - Titem_14")
  538. context.print1("-:) ./lcd/lcd/lcd_app | grep -c 'LCD test completed'")
  539. a = os.popen('./lcd/lcd/lcd_app').read().replace('\n', '').replace('\r', '').strip()
  540. context.print1("output: {}".format(a))
  541. a = os.popen('./lcd/lcd/lcd_app | grep -c "LCD test completed"').read().replace('\n', '').replace('\r', '').strip()
  542. try:
  543. a_int = int(a)
  544. except ValueError:
  545. return False, "Invalid output a: {}".format(a)
  546. if a_int == 1:
  547. return True, 'PASS-{}'.format(a)
  548. else:
  549. return False, "FAIL " + "Error! No Device found!"
  550. def step14_routine(context):
  551. #LED Test
  552. context.print1("==SubTest: led测试 - Titem_15")
  553. context.print1("-:) sh led-test.sh")
  554. a = os.popen("sh led-test.sh").read().replace('\n', '').replace('\r', '').strip()
  555. context.print1("output: {}".format(a))
  556. a = os.popen("sh led-test.sh | tail -1").read().replace('\n', '').replace('\r', '').strip()
  557. try:
  558. a_int = int(a)
  559. except ValueError:
  560. return False, "Invalid output: {}".format(a)
  561. if a_int == 1:
  562. return True, 'PASS-{}'.format(a)
  563. else:
  564. return False, "FAIL " + "Error! No Device found!"
  565. def step15_routine(context):
  566. context.print1("==SubTest: 检查电池健康指示灯功能测试 - Titem_16")
  567. context.print1("-:) sh led-test.sh")
  568. a = os.popen("sh led-test.sh | tail -1").read().replace('\n', '').replace('\r', '').strip()
  569. try:
  570. a_int = int(a)
  571. except ValueError:
  572. return False, "Invalid output: {}".format(a)
  573. if a_int == 1:
  574. return True, 'PASS-{}'.format(a)
  575. else:
  576. return False, "FAIL " + "Error! No Device found!"
  577. def step16_routine(context):
  578. context.print1("==SubTest: 检查拨码开关功能测试 - Titem_17")
  579. context.print1("-:) ls /dev/")
  580. return True, 'AAPASS'
  581. # a = os.popen("sh os-ver.sh USB394").read().replace('\n', '').replace('\r', '').strip()
  582. # if a == "0":
  583. # return False, "Error! No Device found!\n" + a
  584. # else:
  585. # return True, 'PASS-{}'.format(a)
  586. def step17_routine(context):
  587. context.print1("==SubTest: Console接口测试 - Titem_18")
  588. context.print1("-:) ls /dev/")
  589. return True, 'AAPASS'
  590. a = os.popen("sh os-ver.sh speedcliDownload").read().replace('\n', '').replace('\r', '').strip()
  591. if len(a) == 0:
  592. return False, "Error! No Device found!\n" + a
  593. elif a == "Download: Upload:":
  594. return False, "Error! no ethernet!\n" + a
  595. else:
  596. return True, 'PASS-{}'.format(a)
  597. def step18_routine(context):
  598. context.print1("==SubTest: Buzzer基本功能测试 - Titem_19")
  599. context.print1("-:) sh beep.sh")
  600. a = os.popen("sh beep.sh").read().replace('\n', '').replace('\r', '').strip()
  601. if tkMessageBox.askokcancel("PASS?", "测试蜂鸣器是否正常."):
  602. # if ask_choice_with_timeout("PASS?", "测试蜂鸣器是否正常.",30):
  603. return True, 'PASS'
  604. else:
  605. return False, "FAIL"
  606. def step19_routine(context):
  607. context.print1("==SubTest: SATA_SSD基本功能测试 - Titem_20")
  608. context.print1("-:) lsblk -o NAME,TYPE,MOUNTPOINT,MODEL")
  609. a = os.popen("lsblk -o NAME,TYPE,MOUNTPOINT,MODEL").read().strip()
  610. context.print1("output: {}".format(a))
  611. context.print1("-:) ls -l /dev/disk/by-id/ | grep ata-")
  612. b = os.popen("ls -l /dev/disk/by-id/ | grep -c ata-").read().strip()
  613. context.print1("output: {}".format(b))
  614. b = os.popen("ls -l /dev/disk/by-id/ | grep -c ata-").read().replace('\n', '').replace('\r', '').strip()
  615. if b == "1":
  616. return True, 'PASS-{}'.format(b)
  617. else:
  618. return False, "Error! No Device found! " + b
  619. def step20_routine(context):
  620. context.print1("==SubTest: HeadBest_Test - Titem_21")
  621. return True, 'AAPASS'
  622. def step21_routine(context):
  623. context.print1("==SubTest: 数码管测试 - Titem_22")
  624. context.print1("-:) sh seven_segment_display.sh")
  625. a = os.popen("sh seven_segment_display.sh").read().replace('\n', '').replace('\r', '').strip()
  626. if tkMessageBox.askokcancel("PASS?", "测试数码管是否正常."):
  627. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  628. return True, 'PASS'
  629. else:
  630. return False, "FAIL"
  631. def step22_routine(context):
  632. return True, 'AAPASS'
  633. def step23_routine(context):
  634. return True, 'AAPASS'
  635. def step24_routine(context):
  636. return True, 'AAPASS'
  637. def step25_routine(context):
  638. return True, 'AAPASS'
  639. def step26_routine(context):
  640. return True, 'AAPASS'
  641. def step27_routine(context):
  642. context.print1("==SubTest: 检查gsensor基本功能测试 - Titem_23")
  643. context.print1("-:) bash ./gsensor-SC7A20H/C180_gsensor_function_script.sh")
  644. context.print1("10s内手动转动屏幕,才能测试PASS!")
  645. tkMessageBox.showinfo("Prompt", "请人工向右转动屏幕检查横竖屏,判断重力传感器是否正常?"):
  646. a = os.popen("bash ./gsensor-SC7A20H/C180_gsensor_function_script.sh | grep -c \"pass\"").read().replace('\n', '').replace('\r', '').strip()
  647. try:
  648. a_int = int(a)
  649. except ValueError:
  650. return False, "Invalid output: {}".format(a)
  651. if a_int == 1:
  652. return True, 'PASS-{}'.format(a)
  653. else:
  654. return False, "FAIL " + "Error! No Device found!"
  655. def step28_routine(context):
  656. return True, 'AAPASS'
  657. def step29_routine(context):
  658. a = os.popen("sh display.sh 111111 | wc -l").read().replace('\n', '').replace('\r', '').strip()
  659. a = os.popen("find ./test_picture/ -name '*.jpg' | wc -l").read().strip()
  660. try:
  661. a_int = int(a)
  662. except ValueError:
  663. return False, "Invalid output: {}".format(a)
  664. if a_int >= 0:
  665. return True, 'PASS-{}'.format(a)
  666. else:
  667. return False, "FAIL " + "Error! No Device found!"
  668. def step30_routine(context):
  669. a = os.popen("sh fio.sh 111111 | wc -l").read().replace('\n', '').replace('\r', '').strip()
  670. try:
  671. a_int = int(a)
  672. except ValueError:
  673. return False, "Invalid output: {}".format(a)
  674. if a_int >= 0:
  675. return True, 'PASS-{}'.format(a)
  676. else:
  677. return False, "FAIL " + "Error! No Device found!"
  678. def step31_routine(context):
  679. a = os.popen("sh os-ver.sh speaker | wc -l").read().replace('\n', '').replace('\r', '').strip()
  680. try:
  681. a_int = int(a)
  682. except ValueError:
  683. return False, "Invalid output: {}".format(a)
  684. if a_int >= 0:
  685. return True, 'PASS-{}'.format(a)
  686. else:
  687. return False, "FAIL " + "Error! No Device found!"
  688. def step32_routine(context):
  689. a = os.popen("sh record_play.sh 111111 | wc -l").read().replace('\n', '').replace('\r', '').strip()
  690. a = os.popen("echo 111111 | sudo -S find /tmp/ -name 'my_recording.wav' 2>&1 | wc -l").read().strip()
  691. try:
  692. a_int = int(a)
  693. except ValueError:
  694. return False, "Invalid output: {}".format(a)
  695. if a_int >= 0:
  696. return True, 'PASS-{}'.format(a)
  697. else:
  698. return False, "FAIL " + "Error! No Device found!"
  699. def step33_routine(context):
  700. a = os.popen("sh led-test.sh | tail -1").read().replace('\n', '').replace('\r', '').strip()
  701. try:
  702. a_int = int(a)
  703. except ValueError:
  704. return False, "Invalid output: {}".format(a)
  705. if a_int == 1:
  706. return True, 'PASS-{}'.format(a)
  707. else:
  708. return False, "FAIL " + "Error! No Device found!"
  709. def step34_routine(context):
  710. #a = os.popen("/usr/bin/guvcview &").read().replace('\n', '').replace('\r', '').strip()
  711. os.system("/usr/bin/guvcview &")
  712. time.sleep(15)
  713. os.system("sh os-ver.sh exit &")
  714. return True, 'PASS'
  715. def step35_routine(context):
  716. context.print1("==SubTest: 外置键盘测试 - Titem_24")
  717. context.print1("-:) sh ./keyboard.sh 111111")
  718. a = os.popen("sh ./keyboard.sh 111111").read().replace('\n', '').replace('\r', '').strip()
  719. context.print1("output: {}".format(a))
  720. try:
  721. if len(a) == 1:
  722. return False, "FAIL " + "Error! No Device found! {}".format(a)
  723. elif a == "":
  724. return False, "FAIL " + "Error! no cashDrawer!"
  725. except ValueError:
  726. return False, "Invalid output: {}".format(a)
  727. if len(a) != 0:
  728. return True, 'PASS-{}'.format(a)
  729. else:
  730. return False, "FAIL " + "Error! No Device found!"
  731. def step36_routine(context):
  732. # network speed cli
  733. c = os.popen("ip link show | grep -c \"BROADCAST,MULTICAST,UP,LOWER_UP\"").read().strip()
  734. try:
  735. c_int = int(c)
  736. except ValueError:
  737. return False, "Invalid output c: {}".format(c)
  738. if c_int != 1:
  739. return False, "FAIL " + "Error! No Device found!"
  740. a = os.popen("sh os-ver.sh speedcliDownload").read().replace('\n', '').replace('\r', '').strip()
  741. if len(a) == 0:
  742. return False, "FAIL " + "Error! No Device found! {}".format(a)
  743. elif a == "Download: Upload:":
  744. return False, "FAIL " + "Error! no ethernet!"
  745. else:
  746. b = os.popen("ip link show | grep -c \"BROADCAST,MULTICAST,UP,LOWER_UP\"").read().strip()
  747. try:
  748. b_int = int(b)
  749. except ValueError:
  750. return False, "Invalid output b: {}".format(b)
  751. if b_int == 1:
  752. return True, a
  753. else:
  754. return False, "FAIL " + "Error! No Device found! {}".format(a)
  755. def step37_routine(context):
  756. a = os.popen("lsblk -d -o TRAN,NAME,SIZE | grep usb | wc -l").read().replace('\n', '').replace('\r', '').strip()
  757. try:
  758. a_int = int(a)
  759. except ValueError:
  760. return False, "Invalid output: {}".format(a)
  761. if a_int >= 6:
  762. return True, 'PASS-{}'.format(a)
  763. else:
  764. return False, "FAIL " + "Error! No Device found!"
  765. def step38_routine(context):
  766. time.sleep(1)
  767. os.system("sh os-ver.sh 1080p &")
  768. time.sleep(15)
  769. os.system("sh os-ver.sh exit &")
  770. return True, 'PASS'
  771. def step39_routine(context):
  772. context.print1("==SubTest: 钱箱基本功能测试 - Titem_27")
  773. context.print1("-:) sh ./cashDrawer_test.sh 111111 | tail -n 1")
  774. b = os.popen("sh ./cashDrawer_test.sh 111111").read().replace('\n', '').replace('\r', '').strip()
  775. context.print1("output: {}".format(b))
  776. a = os.popen("sh ./cashDrawer_test.sh 111111 | tail -n 1").read().replace('\n', '').replace('\r', '').strip()
  777. try:
  778. if len(a) == 0:
  779. return False, "FAIL " + "Error! No Device found! {}".format(a)
  780. elif a == "cashDrawer1: , cashDrawer2: ":
  781. return False, "FAIL " + "Error! no cashDrawer!"
  782. elif a == "cashDrawer1: 0, cashDrawer2: 0":
  783. return False, "FAIL " + "Error! no cashDrawer!"
  784. elif a == "cashDrawer1: 1, cashDrawer2: 0":
  785. return False, "FAIL " + "Error! no cashDrawer2!"
  786. elif a == "cashDrawer1: 0, cashDrawer2: 1":
  787. return False, "FAIL " + "Error! no cashDrawer1"
  788. except ValueError:
  789. return False, "Invalid output: {}".format(a)
  790. if len(a) > 0:
  791. return True, 'PASS-{}'.format(a)
  792. else:
  793. return False, "FAIL " + "Error! No Device found!"
  794. def step40_routine(context):
  795. #serialC
  796. ttyS0 = os.popen("sh serialport-test.sh /dev/ttyS0").read().strip()
  797. try:
  798. a_int = int(ttyS0)
  799. except ValueError:
  800. return False, "Invalid output ttyS0: {}".format(ttyS0)
  801. if a_int == 1:
  802. pass
  803. else:
  804. return False, "FAIL " + "Error! No Device found! ttyS0"
  805. ttyS1 = os.popen("sh serialport-test.sh /dev/ttyS1").read().strip()
  806. try:
  807. a_int = int(ttyS1)
  808. except ValueError:
  809. return False, "Invalid output ttyS1: {}".format(ttyS1)
  810. if a_int == 1:
  811. pass
  812. else:
  813. return False, "FAIL " + "Error! No Device found! ttyS1"
  814. ttyS2 = os.popen("sh serialport-test.sh /dev/ttyS2").read().strip()
  815. try:
  816. a_int = int(ttyS2)
  817. except ValueError:
  818. return False, "Invalid output ttyS2: {}".format(ttyS2)
  819. if a_int == 1:
  820. pass
  821. else:
  822. return False, "FAIL " + "Error! No Device found! ttyS2"
  823. ttyS3 = os.popen("sh serialport-test.sh /dev/ttyS3").read().strip()
  824. try:
  825. a_int = int(ttyS3)
  826. except ValueError:
  827. return False, "Invalid output ttyS3: {}".format(ttyS3)
  828. if a_int == 1:
  829. pass
  830. else:
  831. return False, "FAIL " + "Error! No Device found! ttyS3"
  832. ttyS6 = os.popen("sh serialport-test.sh /dev/ttyS6").read().strip()
  833. try:
  834. a_int = int(ttyS6)
  835. except ValueError:
  836. return False, "Invalid output ttyS6: {}".format(ttyS6)
  837. if a_int == 1:
  838. pass
  839. else:
  840. return False, "FAIL " + "Error! No Device found! ttyS6"
  841. ttyS7 = os.popen("sh serialport-test.sh /dev/ttyS7").read().strip()
  842. try:
  843. a_int = int(ttyS7)
  844. except ValueError:
  845. return False, "Invalid output ttyS7: {}".format(ttyS7)
  846. if a_int == 1:
  847. pass
  848. else:
  849. return False, "FAIL " + "Error! No Device found! ttyS7"
  850. return True, "PASS"
  851. def step41_routine(context):
  852. a = os.popen("bash usb_test.sh 111111 | grep -s 'PASSED' | wc -l").read().replace('\n', '').replace('\r', '').strip()
  853. #b = os.popen("bash usb_test.sh 111111").read().replace('\n', '').replace('\r', '').strip()
  854. try:
  855. a_int = int(a)
  856. except ValueError:
  857. return False, "Invalid output: {}".format(a)
  858. if a_int >= 1:
  859. return True, 'PASS-{}'.format(a)
  860. else:
  861. return False, "FAIL " + "Error! No Device found!"
  862. def step42_routine(context):
  863. a = os.popen("sh readsn.sh").read().replace('\n', '').replace('\r', '').strip()
  864. try:
  865. if len(a) == 0:
  866. return False, "Error! Serial Number is empty!\n" + a
  867. except ValueError:
  868. return False, "Invalid output: {}".format(a)
  869. if len(a) == 11:
  870. return True, 'PASS-{}'.format(a)
  871. else:
  872. return False, "FAIL " + "Error! No Device found!"
  873. def step43_routine(context):
  874. context.print1("==SubTest: 相机基本功能测试 - Titem_20")
  875. context.print1("-:) /usr/bin/guvcview &")
  876. a = os.popen("/usr/bin/guvcview &").read().replace('\n', '').replace('\r', '').strip()
  877. if tkMessageBox.askokcancel("PASS?", "测试相机是否正常."):
  878. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  879. return True, 'PASS'
  880. else:
  881. return False, "FAIL"
  882. def step44_routine(context):
  883. context.print1("==SubTest: 检查喇叭基本功能测试 - Titem_21")
  884. context.print1("-:) sh os-ver.sh speaker")
  885. a = os.popen("sh os-ver.sh speaker").read().replace('\n', '').replace('\r', '').strip()
  886. if tkMessageBox.askokcancel("PASS?", "测试喇叭是否正常."):
  887. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  888. return True, 'PASS'
  889. else:
  890. return False, "FAIL"
  891. def step45_routine(context):
  892. context.print1("==SubTest: 检查Microphone_Test基本功能测试 - Titem_22")
  893. context.print1("-:) sh os-ver.sh arecord")
  894. a = os.popen("sh os-ver.sh arecord").read().replace('\n', '').replace('\r', '').strip()
  895. if tkMessageBox.askokcancel("PASS?", "测试Microphone_Test是否正常."):
  896. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  897. return True, 'PASS'
  898. else:
  899. return False, "FAIL"
  900. def step46_routine(context):
  901. context.print1("==SubTest: 检查LEDBlinking基本功能测试 - Titem_26")
  902. context.print1("-:) sh lightRing.sh")
  903. a = os.popen("sh lightRing.sh").read().replace('\n', '').replace('\r', '').strip()
  904. if tkMessageBox.askokcancel("PASS?", "测试确定LEDBlinking是否正常?"):
  905. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  906. return True, 'PASS'
  907. else:
  908. return False, "FAIL"
  909. def step47_routine(context):
  910. context.print1("==SubTest: 触摸TP测试C180 - Titem_20")
  911. context.print1("-:) xinput --list | grep -c 'TouchScreen'")
  912. a = os.popen("xinput --list | grep -c 'TouchScreen'").read().replace('\n', '').replace('\r', '').strip()
  913. try:
  914. a_int = int(a)
  915. except ValueError:
  916. return False, "Invalid output: {}".format(a)
  917. if a_int >= 1:
  918. return True, 'PASS-{}'.format(a)
  919. else:
  920. return False, "FAIL " + "Error! No Device found!"